snappymail/dev/View/Popup/FolderClear.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-07-05 03:19:24 +08:00
import { i18n, getNotification } from 'Common/Translator';
import { MessageUserStore } from 'Stores/User/Message';
import { MessagelistUserStore } from 'Stores/User/Messagelist';
2014-08-25 15:10:51 +08:00
import Remote from 'Remote/User/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
2022-02-24 21:01:41 +08:00
export class FolderClearPopupView extends AbstractViewPopup {
constructor() {
super('FolderClear');
2014-08-21 23:08:34 +08:00
this.addObservables({
selectedFolder: null,
clearingProcess: false,
clearingError: ''
});
2014-08-21 23:08:34 +08:00
this.addComputables({
2022-02-21 22:36:34 +08:00
dangerDescHtml: () => {
const folder = this.selectedFolder();
2022-02-21 22:36:34 +08:00
// return i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', { FOLDER: folder ? folder.fullName.replace(folder.delimiter, ' / ') : '' });
return i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', { FOLDER: folder ? folder.localName() : '' });
}
});
2016-09-10 06:38:16 +08:00
decorateKoCommands(this, {
clearCommand: self => {
const folder = self.selectedFolder();
return !self.clearingProcess() && null !== folder;
}
});
}
2014-08-21 23:08:34 +08:00
2016-09-10 06:38:16 +08:00
clearCommand() {
const folderToClear = this.selectedFolder();
2019-07-05 03:19:24 +08:00
if (folderToClear) {
MessageUserStore.message(null);
MessagelistUserStore([]);
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
2022-06-03 19:47:04 +08:00
folderToClear.totalEmails(0);
folderToClear.unreadEmails(0);
folderToClear.hash = '';
Remote.request('FolderClear', iError => {
2016-09-10 06:38:16 +08:00
this.clearingProcess(false);
if (iError) {
this.clearingError(getNotification(iError));
} else {
MessagelistUserStore.reload(true);
this.close();
2016-09-10 06:38:16 +08:00
}
}, {
Folder: folderToClear.fullName
});
2016-09-10 06:38:16 +08:00
}
}
onShow(folder) {
2021-11-03 21:58:34 +08:00
this.clearingProcess(false);
this.selectedFolder(folder || null);
2016-06-30 08:02:45 +08:00
}
}