snappymail/dev/Settings/User/Folders.js

187 lines
6 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
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';
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
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';
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
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
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';
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();
export class FoldersUserSettings /*extends AbstractViewSettings*/ {
2016-07-16 05:29:42 +08:00
constructor() {
this.showKolab = koComputable(() => FolderUserStore.hasCapability('METADATA') && Settings.capa(Capa.Kolab));
2021-10-15 17:58:06 +08:00
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
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') }
]);
});
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
this.loading = koComputable(() => {
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');
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) {
const nameToEdit = folder ? folder.nameForEdit().trim() : '';
2014-08-25 15:10:51 +08:00
if (nameToEdit && folder.name() !== nameToEdit) {
Remote.abort('Folders').post('FolderRename', FolderUserStore.foldersRenaming, {
Folder: folder.fullName,
NewFolderName: nameToEdit
})
.then(data => {
folder.name(nameToEdit/*data.Name*/);
if (folder.subFolders.length) {
Remote.setTrigger(FolderUserStore.foldersLoading, true);
// clearTimeout(Remote.foldersTimeout);
// Remote.foldersTimeout = setTimeout(() => Remote.foldersReload(), 500);
setTimeout(() => Remote.foldersReload(), 500);
// TODO: rename all subfolders with folder.delimiter to prevent reload?
} else {
removeFolderFromCacheList(folder.fullName);
folder.fullName = data.Result.FullName;
setFolder(folder);
const parent = getFolderFromCacheList(folder.parentName);
sortFolders(parent ? parent.subFolders : FolderUserStore.folderList);
}
})
.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() {
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() {
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() {
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) {
if (folderToRemove
&& folderToRemove.canBeDeleted()
&& folderToRemove.deleteAccess()
2019-07-05 03:19:24 +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
);
}
);
}
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;
// 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();
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();
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
}
}