2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
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';
|
2020-10-15 01:16:37 +08:00
|
|
|
import { defaultOptionsAfterRender } 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
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import FolderStore from 'Stores/User/Folder';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|
|
|
|
|
|
|
class FolderSystemPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('FolderSystem');
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
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(
|
|
|
|
[],
|
|
|
|
FolderStore.folderList(),
|
|
|
|
FolderStore.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,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
true
|
|
|
|
)
|
2016-08-17 06:01:20 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
this.sentFolder = FolderStore.sentFolder;
|
|
|
|
this.draftFolder = FolderStore.draftFolder;
|
|
|
|
this.spamFolder = FolderStore.spamFolder;
|
|
|
|
this.trashFolder = FolderStore.trashFolder;
|
|
|
|
this.archiveFolder = FolderStore.archiveFolder;
|
|
|
|
|
2021-03-10 18:44:48 +08:00
|
|
|
const settingsSet = Settings.set,
|
2020-09-04 18:05:17 +08:00
|
|
|
fSetSystemFolders = () => {
|
|
|
|
settingsSet('SentFolder', FolderStore.sentFolder());
|
|
|
|
settingsSet('DraftFolder', FolderStore.draftFolder());
|
|
|
|
settingsSet('SpamFolder', FolderStore.spamFolder());
|
|
|
|
settingsSet('TrashFolder', FolderStore.trashFolder());
|
|
|
|
settingsSet('ArchiveFolder', FolderStore.archiveFolder());
|
2017-08-07 23:09:14 +08:00
|
|
|
},
|
2020-08-19 02:24:17 +08:00
|
|
|
fSaveSystemFolders = (()=>{
|
|
|
|
fSetSystemFolders();
|
|
|
|
Remote.saveSystemFolders(()=>{}, {
|
|
|
|
SentFolder: FolderStore.sentFolder(),
|
|
|
|
DraftFolder: FolderStore.draftFolder(),
|
|
|
|
SpamFolder: FolderStore.spamFolder(),
|
|
|
|
TrashFolder: FolderStore.trashFolder(),
|
|
|
|
ArchiveFolder: FolderStore.archiveFolder(),
|
|
|
|
NullFolder: 'NullFolder'
|
|
|
|
});
|
|
|
|
}).debounce(1000),
|
2016-08-17 06:01:20 +08:00
|
|
|
fCallback = () => {
|
|
|
|
fSetSystemFolders();
|
|
|
|
fSaveSystemFolders();
|
|
|
|
};
|
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
ko.addSubscribablesTo(FolderStore, {
|
|
|
|
sentFolder: fCallback,
|
|
|
|
draftFolder: fCallback,
|
|
|
|
spamFolder: fCallback,
|
|
|
|
trashFolder: fCallback,
|
|
|
|
archiveFolder: fCallback
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-10-15 01:16:37 +08:00
|
|
|
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +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) {
|
2016-08-17 06:01:20 +08:00
|
|
|
case SetSystemFoldersNotification.Sent:
|
2021-01-26 18:46:30 +08:00
|
|
|
notification = i18n(prefix + 'SENT');
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
case SetSystemFoldersNotification.Draft:
|
2021-01-26 18:46:30 +08:00
|
|
|
notification = i18n(prefix + 'DRAFTS');
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
case SetSystemFoldersNotification.Spam:
|
2021-01-26 18:46:30 +08:00
|
|
|
notification = i18n(prefix + 'SPAM');
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
case SetSystemFoldersNotification.Trash:
|
2021-01-26 18:46:30 +08:00
|
|
|
notification = i18n(prefix + 'TRASH');
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
case SetSystemFoldersNotification.Archive:
|
2021-01-26 18:46:30 +08:00
|
|
|
notification = i18n(prefix + 'ARCHIVE');
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
// no default
|
|
|
|
}
|
|
|
|
|
|
|
|
this.notification(notification);
|
|
|
|
}
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { FolderSystemPopupView, FolderSystemPopupView as default };
|