snappymail/dev/View/Popup/FolderSystem.js

85 lines
2.5 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';
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 { 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.folderListSystemNames(),
2019-12-25 03:05:46 +08:00
[
['', this.sChooseOnText],
[UNUSED_OPTION_VALUE, this.sUnuseText]
2021-08-19 21:14:47 +08:00
]
2019-07-05 03:19:24 +08:00
)
);
this.sentFolder = FolderUserStore.sentFolder;
2021-12-01 20:54:35 +08:00
this.draftsFolder = FolderUserStore.draftsFolder;
this.spamFolder = FolderUserStore.spamFolder;
this.trashFolder = FolderUserStore.trashFolder;
this.archiveFolder = FolderUserStore.archiveFolder;
const fSaveSystemFolders = (()=>FolderUserStore.saveSystemFolders()).debounce(1000);
addSubscribablesTo(FolderUserStore, {
sentFolder: fSaveSystemFolders,
2021-12-01 20:54:35 +08:00
draftsFolder: fSaveSystemFolders,
spamFolder: fSaveSystemFolders,
trashFolder: fSaveSystemFolders,
archiveFolder: fSaveSystemFolders
});
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 };