snappymail/dev/View/Popup/FolderSystem.js

76 lines
2.1 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2022-02-17 16:36:29 +08:00
import { koComputable, addSubscribablesTo } from 'External/ko';
import { FolderType } from 'Common/EnumsUser';
2019-07-05 03:19:24 +08:00
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
2022-02-17 16:36:29 +08:00
import { defaultOptionsAfterRender } from 'Common/Utils';
import { folderListOptionsBuilder } from 'Common/Folders';
2022-02-24 21:01:41 +08:00
import { 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';
2022-02-24 21:01:41 +08:00
export class FolderSystemPopupView extends AbstractViewPopup {
constructor() {
super('FolderSystem');
this.notification = ko.observable('');
this.folderSelectList = koComputable(() =>
2019-07-05 03:19:24 +08:00
folderListOptionsBuilder(
2022-08-03 17:06:09 +08:00
FolderUserStore.systemFoldersNames(),
2019-12-25 03:05:46 +08:00
[
2022-02-24 21:01:41 +08:00
['', i18n('POPUPS_SYSTEM_FOLDERS/SELECT_CHOOSE_ONE')],
[UNUSED_OPTION_VALUE, i18n('POPUPS_SYSTEM_FOLDERS/SELECT_UNUSE_NAME')]
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 = 0
*/
onShow(notificationType = 0) {
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 FolderType.Sent:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'SENT');
break;
case FolderType.Drafts:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'DRAFTS');
break;
case FolderType.Junk:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'SPAM');
break;
case FolderType.Trash:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'TRASH');
break;
case FolderType.Archive:
2021-01-26 18:46:30 +08:00
notification = i18n(prefix + 'ARCHIVE');
break;
// no default
}
this.notification(notification);
}
}