2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2014-08-25 23:49:01 +08:00
|
|
|
|
2021-01-25 05:58:06 +08:00
|
|
|
import { Notification } from 'Common/Enums';
|
2021-12-08 21:08:25 +08:00
|
|
|
import { FolderMetadataKeys } from 'Common/EnumsUser';
|
2021-02-08 21:03:54 +08:00
|
|
|
import { getNotification } from 'Common/Translator';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-12-08 18:06:42 +08:00
|
|
|
import { setFolder, getFolderFromCacheList, removeFolderFromCacheList } from 'Common/Cache';
|
2021-10-15 17:58:06 +08:00
|
|
|
import { defaultOptionsAfterRender } from 'Common/Utils';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { sortFolders } from 'Common/Folders';
|
2021-10-15 17:58:06 +08:00
|
|
|
import { initOnStartOrLangChange, i18n } from 'Common/Translator';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { FolderUserStore } from 'Stores/User/Folder';
|
2021-03-29 18:08:52 +08:00
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
2015-02-23 00:35:17 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2015-04-26 06:01:56 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { showScreenPopup } from 'Knoin/Knoin';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
import { FolderCreatePopupView } from 'View/Popup/FolderCreate';
|
|
|
|
import { FolderSystemPopupView } from 'View/Popup/FolderSystem';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { loadFolders } from 'Model/FolderCollection';
|
2021-01-26 05:00:13 +08:00
|
|
|
|
2022-01-28 06:07:34 +08:00
|
|
|
const folderForDeletion = ko.observable(null).askDeleteHelper();
|
2021-10-26 21:43:27 +08:00
|
|
|
|
2022-03-08 07:51:32 +08:00
|
|
|
export class UserSettingsFolders /*extends AbstractViewSettings*/ {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2022-05-13 22:17:13 +08:00
|
|
|
this.showKolab = FolderUserStore.allowKolab();
|
2021-10-15 17:58:06 +08:00
|
|
|
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
|
2021-10-15 18:34:45 +08:00
|
|
|
this.kolabTypeOptions = ko.observableArray();
|
2021-10-15 17:58:06 +08:00
|
|
|
let i18nFilter = key => i18n('SETTINGS_FOLDERS/TYPE_' + key);
|
|
|
|
initOnStartOrLangChange(()=>{
|
|
|
|
this.kolabTypeOptions([
|
|
|
|
{ id: '', name: '' },
|
|
|
|
{ id: 'event', name: i18nFilter('CALENDAR') },
|
|
|
|
{ id: 'contact', name: i18nFilter('CONTACTS') },
|
|
|
|
{ id: 'task', name: i18nFilter('TASKS') },
|
|
|
|
{ id: 'note', name: i18nFilter('NOTES') },
|
|
|
|
{ id: 'file', name: i18nFilter('FILES') },
|
|
|
|
{ id: 'journal', name: i18nFilter('JOURNAL') },
|
|
|
|
{ id: 'configuration', name: i18nFilter('CONFIGURATION') }
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
this.displaySpecSetting = FolderUserStore.displaySpecSetting;
|
|
|
|
this.folderList = FolderUserStore.folderList;
|
|
|
|
this.folderListOptimized = FolderUserStore.folderListOptimized;
|
|
|
|
this.folderListError = FolderUserStore.folderListError;
|
2021-03-29 18:08:52 +08:00
|
|
|
this.hideUnsubscribed = SettingsUserStore.hideUnsubscribed;
|
2022-09-27 15:46:49 +08:00
|
|
|
this.unhideKolabFolders = SettingsUserStore.unhideKolabFolders;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-08-03 17:06:09 +08:00
|
|
|
this.loading = FolderUserStore.foldersChanging;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-10-26 21:43:27 +08:00
|
|
|
this.folderForDeletion = folderForDeletion;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-09-26 19:54:28 +08:00
|
|
|
this.folderForEdit = ko.observable(null).extend({ toggleSubscribeProperty: [this, 'editing'] });
|
2021-03-29 18:08:52 +08:00
|
|
|
|
2022-02-28 17:38:47 +08:00
|
|
|
SettingsUserStore.hideUnsubscribed.subscribe(value => Remote.saveSetting('HideUnsubscribed', value));
|
2022-09-27 15:46:49 +08:00
|
|
|
SettingsUserStore.unhideKolabFolders.subscribe(value => Remote.saveSetting('UnhideKolabFolders', value));
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
folderEditOnEnter(folder) {
|
2022-09-26 19:54:28 +08:00
|
|
|
const nameToEdit = folder?.nameForEdit().trim();
|
2020-07-28 23:20:14 +08:00
|
|
|
if (nameToEdit && folder.name() !== nameToEdit) {
|
2021-12-08 18:06:42 +08:00
|
|
|
Remote.abort('Folders').post('FolderRename', FolderUserStore.foldersRenaming, {
|
2021-12-03 06:15:24 +08:00
|
|
|
Folder: folder.fullName,
|
2022-01-12 18:55:41 +08:00
|
|
|
NewFolderName: nameToEdit,
|
2022-06-02 04:50:35 +08:00
|
|
|
Subscribe: folder.isSubscribed() ? 1 : 0
|
2021-12-07 21:03:30 +08:00
|
|
|
})
|
|
|
|
.then(data => {
|
|
|
|
folder.name(nameToEdit/*data.Name*/);
|
|
|
|
if (folder.subFolders.length) {
|
2021-12-08 18:06:42 +08:00
|
|
|
Remote.setTrigger(FolderUserStore.foldersLoading, true);
|
2021-12-08 19:17:45 +08:00
|
|
|
// clearTimeout(Remote.foldersTimeout);
|
2022-02-24 02:26:52 +08:00
|
|
|
// Remote.foldersTimeout = setTimeout(loadFolders, 500);
|
|
|
|
setTimeout(loadFolders, 500);
|
2021-12-08 18:06:42 +08:00
|
|
|
// TODO: rename all subfolders with folder.delimiter to prevent reload?
|
2021-12-07 21:03:30 +08:00
|
|
|
} else {
|
|
|
|
removeFolderFromCacheList(folder.fullName);
|
2021-12-09 18:24:30 +08:00
|
|
|
folder.fullName = data.Result.FullName;
|
2021-12-07 21:03:30 +08:00
|
|
|
setFolder(folder);
|
2021-12-09 18:24:30 +08:00
|
|
|
const parent = getFolderFromCacheList(folder.parentName);
|
|
|
|
sortFolders(parent ? parent.subFolders : FolderUserStore.folderList);
|
2021-12-07 21:03:30 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
FolderUserStore.folderListError(
|
|
|
|
getNotification(error.code, '', Notification.CantRenameFolder)
|
|
|
|
+ '.\n' + error.message);
|
|
|
|
});
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-09-26 19:54:28 +08:00
|
|
|
// this.folderForEdit(null);
|
|
|
|
folder.editing(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
folderEditOnEsc(folder) {
|
2022-09-26 19:54:28 +08:00
|
|
|
// this.folderForEdit(null);
|
|
|
|
folder?.editing(false);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onShow() {
|
2021-03-11 05:41:35 +08:00
|
|
|
FolderUserStore.folderListError('');
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2021-02-08 21:03:54 +08:00
|
|
|
/*
|
2016-07-16 05:29:42 +08:00
|
|
|
onBuild(oDom) {
|
|
|
|
}
|
2021-02-08 21:03:54 +08:00
|
|
|
*/
|
2016-07-16 05:29:42 +08:00
|
|
|
createFolder() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(FolderCreatePopupView);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
systemFolder() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(FolderSystemPopupView);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
deleteFolder(folderToRemove) {
|
2021-12-13 21:32:15 +08:00
|
|
|
if (folderToRemove
|
|
|
|
&& folderToRemove.canBeDeleted()
|
2022-01-28 06:07:34 +08:00
|
|
|
&& folderToRemove.askDelete()
|
2019-07-05 03:19:24 +08:00
|
|
|
) {
|
2022-06-03 19:47:04 +08:00
|
|
|
if (0 < folderToRemove.totalEmails()) {
|
2021-12-13 21:32:15 +08:00
|
|
|
// FolderUserStore.folderListError(getNotification(Notification.CantDeleteNonEmptyFolder));
|
|
|
|
folderToRemove.errorMsg(getNotification(Notification.CantDeleteNonEmptyFolder));
|
|
|
|
} else {
|
|
|
|
folderForDeletion(null);
|
|
|
|
|
|
|
|
if (folderToRemove) {
|
|
|
|
Remote.abort('Folders').post('FolderDelete', FolderUserStore.foldersDeleting, {
|
|
|
|
Folder: folderToRemove.fullName
|
|
|
|
}).then(
|
|
|
|
() => {
|
|
|
|
// folderToRemove.flags.push('\\nonexistent');
|
|
|
|
folderToRemove.selectable(false);
|
2022-06-02 04:50:35 +08:00
|
|
|
// folderToRemove.isSubscribed(false);
|
2021-12-13 21:32:15 +08:00
|
|
|
// folderToRemove.checkable(false);
|
|
|
|
if (!folderToRemove.subFolders.length) {
|
|
|
|
removeFolderFromCacheList(folderToRemove.fullName);
|
|
|
|
const folder = getFolderFromCacheList(folderToRemove.parentName);
|
|
|
|
(folder ? folder.subFolders : FolderUserStore.folderList).remove(folderToRemove);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
FolderUserStore.folderListError(
|
|
|
|
getNotification(error.code, '', Notification.CantDeleteFolder)
|
|
|
|
+ '.\n' + error.message
|
|
|
|
);
|
2021-12-08 18:06:42 +08:00
|
|
|
}
|
2021-12-13 21:32:15 +08:00
|
|
|
);
|
|
|
|
}
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-04-26 06:01:56 +08:00
|
|
|
|
2021-10-15 17:58:06 +08:00
|
|
|
toggleFolderKolabType(folder, event) {
|
|
|
|
let type = event.target.value;
|
2021-10-19 18:44:09 +08:00
|
|
|
// TODO: append '.default' ?
|
2022-02-24 06:11:12 +08:00
|
|
|
Remote.request('FolderSetMetadata', null, {
|
|
|
|
Folder: folder.fullName,
|
|
|
|
Key: FolderMetadataKeys.KolabFolderType,
|
|
|
|
Value: type
|
|
|
|
});
|
2021-10-15 17:58:06 +08:00
|
|
|
folder.kolabType(type);
|
|
|
|
}
|
|
|
|
|
2021-08-19 21:14:47 +08:00
|
|
|
toggleFolderSubscription(folder) {
|
2022-06-02 04:50:35 +08:00
|
|
|
let subscribe = !folder.isSubscribed();
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('FolderSubscribe', null, {
|
|
|
|
Folder: folder.fullName,
|
|
|
|
Subscribe: subscribe ? 1 : 0
|
|
|
|
});
|
2022-06-02 04:50:35 +08:00
|
|
|
folder.isSubscribed(subscribe);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2015-04-26 06:01:56 +08:00
|
|
|
|
2021-08-19 21:14:47 +08:00
|
|
|
toggleFolderCheckable(folder) {
|
|
|
|
let checkable = !folder.checkable();
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('FolderCheckable', null, {
|
|
|
|
Folder: folder.fullName,
|
|
|
|
Checkable: checkable ? 1 : 0
|
|
|
|
});
|
2021-08-19 21:14:47 +08:00
|
|
|
folder.checkable(checkable);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
}
|