2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2021-12-31 20:30:05 +08:00
|
|
|
import { koComputable } from 'External/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-03-29 18:08:52 +08:00
|
|
|
import { Settings } from 'Common/Globals';
|
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 { Capa } from 'Common/Enums';
|
|
|
|
import { defaultOptionsAfterRender } from 'Common/Utils';
|
2021-12-09 18:24:30 +08:00
|
|
|
import { sortFolders } from 'Common/UtilsUser';
|
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';
|
|
|
|
|
2021-10-26 21:43:27 +08:00
|
|
|
const folderForDeletion = ko.observable(null).deleteAccessHelper();
|
|
|
|
|
2021-09-23 02:17:44 +08:00
|
|
|
export class FoldersUserSettings /*extends AbstractViewSettings*/ {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2021-12-31 20:30:05 +08:00
|
|
|
this.showKolab = koComputable(() => FolderUserStore.hasCapability('METADATA') && Settings.capa(Capa.Kolab));
|
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;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-12-31 20:30:05 +08:00
|
|
|
this.loading = koComputable(() => {
|
2021-03-11 05:41:35 +08:00
|
|
|
const loading = FolderUserStore.foldersLoading(),
|
|
|
|
creating = FolderUserStore.foldersCreating(),
|
|
|
|
deleting = FolderUserStore.foldersDeleting(),
|
|
|
|
renaming = FolderUserStore.foldersRenaming();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-24 06:17:50 +08:00
|
|
|
return loading || creating || deleting || renaming;
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
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
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
this.folderForEdit = ko.observable(null).extend({ toggleSubscribeProperty: [this, 'edited'] });
|
2021-03-29 18:08:52 +08:00
|
|
|
|
|
|
|
this.useImapSubscribe = Settings.app('useImapSubscribe');
|
2021-08-25 00:23:17 +08:00
|
|
|
SettingsUserStore.hideUnsubscribed.subscribe(value => Remote.saveSetting('HideUnsubscribed', value ? 1 : 0));
|
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) {
|
2020-08-07 00:24:46 +08:00
|
|
|
const nameToEdit = folder ? folder.nameForEdit().trim() : '';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
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,
|
|
|
|
NewFolderName: nameToEdit
|
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);
|
|
|
|
// Remote.foldersTimeout = setTimeout(() => Remote.foldersReload(), 500);
|
|
|
|
setTimeout(() => Remote.foldersReload(), 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
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
folder.edited(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
folderEditOnEsc(folder) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (folder) {
|
2016-07-16 05:29:42 +08:00
|
|
|
folder.edited(false);
|
|
|
|
}
|
|
|
|
}
|
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()
|
|
|
|
&& folderToRemove.deleteAccess()
|
2019-07-05 03:19:24 +08:00
|
|
|
) {
|
2021-12-13 21:32:15 +08:00
|
|
|
if (0 < folderToRemove.privateMessageCountAll()) {
|
|
|
|
// 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);
|
|
|
|
// folderToRemove.subscribed(false);
|
|
|
|
// 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' ?
|
2021-11-23 04:01:30 +08:00
|
|
|
Remote.folderSetMetadata(null, folder.fullName, FolderMetadataKeys.KolabFolderType, type);
|
2021-10-15 17:58:06 +08:00
|
|
|
folder.kolabType(type);
|
|
|
|
}
|
|
|
|
|
2021-08-19 21:14:47 +08:00
|
|
|
toggleFolderSubscription(folder) {
|
|
|
|
let subscribe = !folder.subscribed();
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('FolderSubscribe', null, {
|
|
|
|
Folder: folder.fullName,
|
|
|
|
Subscribe: subscribe ? 1 : 0
|
|
|
|
});
|
2021-08-19 21:14:47 +08:00
|
|
|
folder.subscribed(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
|
|
|
}
|
|
|
|
}
|