snappymail/dev/View/Popup/FolderSystem.js

115 lines
3.3 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2021-01-25 05:58:06 +08:00
import { SetSystemFoldersNotification } from 'Common/EnumsUser';
2019-07-05 03:19:24 +08:00
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
2021-03-10 18:44:48 +08:00
import { Settings } from 'Common/Globals';
import { defaultOptionsAfterRender, addSubscribablesTo } from 'Common/Utils';
import { folderListOptionsBuilder } from 'Common/UtilsUser';
2019-07-05 03:19:24 +08:00
import { initOnStartOrLangChange, i18n } from 'Common/Translator';
2016-06-30 08:02:45 +08:00
import { FolderUserStore } from 'Stores/User/Folder';
2016-06-30 08:02:45 +08:00
import Remote from 'Remote/User/Fetch';
2016-06-30 08:02:45 +08:00
import { AbstractViewPopup } from 'Knoin/AbstractViews';
class FolderSystemPopupView extends AbstractViewPopup {
constructor() {
super('FolderSystem');
this.sChooseOnText = '';
this.sUnuseText = '';
initOnStartOrLangChange(() => {
this.sChooseOnText = i18n('POPUPS_SYSTEM_FOLDERS/SELECT_CHOOSE_ONE');
this.sUnuseText = i18n('POPUPS_SYSTEM_FOLDERS/SELECT_UNUSE_NAME');
});
this.notification = ko.observable('');
2019-07-05 03:19:24 +08:00
this.folderSelectList = ko.computed(() =>
folderListOptionsBuilder(
[],
FolderUserStore.folderList(),
FolderUserStore.folderListSystemNames(),
2019-12-25 03:05:46 +08:00
[
['', this.sChooseOnText],
[UNUSED_OPTION_VALUE, this.sUnuseText]
],
2019-07-05 03:19:24 +08:00
null,
null,
null,
true
)
);
this.sentFolder = FolderUserStore.sentFolder;
this.draftFolder = FolderUserStore.draftFolder;
this.spamFolder = FolderUserStore.spamFolder;
this.trashFolder = FolderUserStore.trashFolder;
this.archiveFolder = FolderUserStore.archiveFolder;
2021-03-10 18:44:48 +08:00
const settingsSet = Settings.set,
fSetSystemFolders = () => {
settingsSet('SentFolder', FolderUserStore.sentFolder());
settingsSet('DraftFolder', FolderUserStore.draftFolder());
settingsSet('SpamFolder', FolderUserStore.spamFolder());
settingsSet('TrashFolder', FolderUserStore.trashFolder());
settingsSet('ArchiveFolder', FolderUserStore.archiveFolder());
2017-08-07 23:09:14 +08:00
},
fSaveSystemFolders = (()=>{
fSetSystemFolders();
2021-08-13 15:58:43 +08:00
Remote.saveSystemFolders(()=>0, {
SentFolder: FolderUserStore.sentFolder(),
DraftFolder: FolderUserStore.draftFolder(),
SpamFolder: FolderUserStore.spamFolder(),
TrashFolder: FolderUserStore.trashFolder(),
2021-03-29 15:38:18 +08:00
ArchiveFolder: FolderUserStore.archiveFolder()
});
}).debounce(1000),
fCallback = () => {
fSetSystemFolders();
fSaveSystemFolders();
};
addSubscribablesTo(FolderUserStore, {
sentFolder: fCallback,
draftFolder: fCallback,
spamFolder: fCallback,
trashFolder: fCallback,
archiveFolder: fCallback
});
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
2016-06-30 08:02:45 +08:00
}
/**
* @param {number=} notificationType = SetSystemFoldersNotification.None
*/
onShow(notificationType = SetSystemFoldersNotification.None) {
2021-01-26 18:46:30 +08:00
let notification = '', prefix = 'POPUPS_SYSTEM_FOLDERS/NOTIFICATION_';
2019-07-05 03:19:24 +08:00
switch (notificationType) {
case SetSystemFoldersNotification.Sent:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'SENT');
break;
case SetSystemFoldersNotification.Draft:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'DRAFTS');
break;
case SetSystemFoldersNotification.Spam:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'SPAM');
break;
case SetSystemFoldersNotification.Trash:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'TRASH');
break;
case SetSystemFoldersNotification.Archive:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'ARCHIVE');
break;
// no default
}
this.notification(notification);
}
}
2019-07-05 03:19:24 +08:00
export { FolderSystemPopupView, FolderSystemPopupView as default };