snappymail/dev/View/Popup/FolderClear.js

105 lines
2.3 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2014-08-25 23:49:01 +08:00
import {StorageResultType, Notification} from 'Common/Enums';
import {i18n, getNotification} from 'Common/Translator';
import {setFolderHash} from 'Common/Cache';
import MessageStore from 'Stores/User/Message';
2014-08-25 15:10:51 +08:00
import Remote from 'Remote/User/Ajax';
import {getApp} from 'Helper/Apps/User';
2015-02-23 00:35:17 +08:00
2016-09-10 06:38:16 +08:00
import {popup, command} from 'Knoin/Knoin';
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
2015-02-22 06:00:51 +08:00
2016-09-10 06:38:16 +08:00
@popup({
name: 'View/Popup/FolderClear',
templateID: 'PopupsFolderClear'
})
class FolderClearPopupView extends AbstractViewNext
2016-06-30 08:02:45 +08:00
{
constructor() {
super();
2014-08-21 23:08:34 +08:00
this.selectedFolder = ko.observable(null);
this.clearingProcess = ko.observable(false);
this.clearingError = ko.observable('');
2014-08-21 23:08:34 +08:00
this.folderFullNameForClear = ko.computed(() => {
const folder = this.selectedFolder();
return folder ? folder.printableFullName() : '';
});
2014-08-21 23:08:34 +08:00
this.folderNameForClear = ko.computed(() => {
const folder = this.selectedFolder();
return folder ? folder.localName() : '';
2016-06-30 08:02:45 +08:00
});
2014-08-21 23:08:34 +08:00
this.dangerDescHtml = ko.computed(
() => i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', {'FOLDER': this.folderNameForClear()})
);
2016-09-10 06:38:16 +08:00
}
@command((self) => {
const
folder = self.selectedFolder(),
isClearing = self.clearingProcess();
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
return !isClearing && null !== folder;
})
clearCommand() {
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
const folderToClear = this.selectedFolder();
if (folderToClear)
{
MessageStore.message(null);
MessageStore.messageList([]);
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
this.clearingProcess(true);
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
folderToClear.messageCountAll(0);
folderToClear.messageCountUnread(0);
2014-08-26 23:24:47 +08:00
2016-09-10 06:38:16 +08:00
setFolderHash(folderToClear.fullNameRaw, '');
2016-09-10 06:38:16 +08:00
Remote.folderClear((result, data) => {
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
this.clearingProcess(false);
if (StorageResultType.Success === result && data && data.Result)
{
getApp().reloadMessageList(true);
this.cancelCommand();
}
else
{
if (data && data.ErrorCode)
{
2016-09-10 06:38:16 +08:00
this.clearingError(getNotification(data.ErrorCode));
}
else
{
2016-09-10 06:38:16 +08:00
this.clearingError(getNotification(Notification.MailServerError));
}
2016-09-10 06:38:16 +08:00
}
}, folderToClear.fullNameRaw);
}
}
clearPopup() {
this.clearingProcess(false);
this.selectedFolder(null);
}
onShow(folder) {
this.clearPopup();
if (folder)
{
this.selectedFolder(folder);
}
2016-06-30 08:02:45 +08:00
}
}
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
export {FolderClearPopupView, FolderClearPopupView as default};