snappymail/dev/View/Popup/FolderClear.js

119 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-06-30 08:02:45 +08:00
var
_ = require('_'),
ko = require('ko'),
2014-08-25 23:49:01 +08:00
2016-06-30 08:02:45 +08:00
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
2016-06-30 08:02:45 +08:00
Cache = require('Common/Cache'),
2014-08-25 15:10:51 +08:00
2016-06-30 08:02:45 +08:00
MessageStore = require('Stores/User/Message'),
2016-06-30 08:02:45 +08:00
Remote = require('Remote/User/Ajax'),
2015-02-23 00:35:17 +08:00
2016-06-30 08:02:45 +08:00
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
2015-02-22 06:00:51 +08:00
2016-06-30 08:02:45 +08:00
/**
* @constructor
* @extends AbstractView
*/
function FolderClearPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsFolderClear');
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.selectedFolder = ko.observable(null);
this.clearingProcess = ko.observable(false);
this.clearingError = ko.observable('');
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.folderFullNameForClear = ko.computed(function() {
var oFolder = this.selectedFolder();
return oFolder ? oFolder.printableFullName() : '';
}, this);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.folderNameForClear = ko.computed(function() {
var oFolder = this.selectedFolder();
return oFolder ? oFolder.localName() : '';
}, this);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.dangerDescHtml = ko.computed(function() {
return Translator.i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', {
'FOLDER': this.folderNameForClear()
});
}, this);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.clearCommand = Utils.createCommand(this, function() {
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
var
self = this,
oFolderToClear = this.selectedFolder();
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
if (oFolderToClear)
{
MessageStore.message(null);
MessageStore.messageList([]);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.clearingProcess(true);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
oFolderToClear.messageCountAll(0);
oFolderToClear.messageCountUnread(0);
2014-08-26 23:24:47 +08:00
2016-06-30 08:02:45 +08:00
Cache.setFolderHash(oFolderToClear.fullNameRaw, '');
2016-06-30 08:02:45 +08:00
Remote.folderClear(function(sResult, oData) {
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
self.clearingProcess(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
require('App/User').default.reloadMessageList(true);
self.cancelCommand();
}
else
{
if (oData && oData.ErrorCode)
{
2016-06-30 08:02:45 +08:00
self.clearingError(Translator.getNotification(oData.ErrorCode));
}
else
{
2016-06-30 08:02:45 +08:00
self.clearingError(Translator.getNotification(Enums.Notification.MailServerError));
}
2016-06-30 08:02:45 +08:00
}
}, oFolderToClear.fullNameRaw);
}
2016-06-30 08:02:45 +08:00
}, function() {
2016-06-30 08:02:45 +08:00
var
oFolder = this.selectedFolder(),
bIsClearing = this.clearingProcess();
2016-06-30 08:02:45 +08:00
return !bIsClearing && null !== oFolder;
2016-06-30 08:02:45 +08:00
});
2016-06-30 08:02:45 +08:00
kn.constructorEnd(this);
}
2016-06-30 08:02:45 +08:00
kn.extendAsViewModel(['View/Popup/FolderClear', 'PopupsFolderClearViewModel'], FolderClearPopupView);
_.extend(FolderClearPopupView.prototype, AbstractView.prototype);
2016-06-30 08:02:45 +08:00
FolderClearPopupView.prototype.clearPopup = function()
{
this.clearingProcess(false);
this.selectedFolder(null);
};
2016-06-30 08:02:45 +08:00
FolderClearPopupView.prototype.onShow = function(oFolder)
{
this.clearPopup();
if (oFolder)
{
2016-06-30 08:02:45 +08:00
this.selectedFolder(oFolder);
}
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
module.exports = FolderClearPopupView;