2013-11-16 06:21:12 +08:00
|
|
|
|
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'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
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'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
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, '');
|
2014-09-02 08:15:31 +08:00
|
|
|
|
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)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
self.clearingError(Translator.getNotification(oData.ErrorCode));
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
self.clearingError(Translator.getNotification(Enums.Notification.MailServerError));
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
}, oFolderToClear.fullNameRaw);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
}, function() {
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
var
|
|
|
|
oFolder = this.selectedFolder(),
|
|
|
|
bIsClearing = this.clearingProcess();
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
return !bIsClearing && null !== oFolder;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
kn.extendAsViewModel(['View/Popup/FolderClear', 'PopupsFolderClearViewModel'], FolderClearPopupView);
|
|
|
|
_.extend(FolderClearPopupView.prototype, AbstractView.prototype);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
FolderClearPopupView.prototype.clearPopup = function()
|
|
|
|
{
|
|
|
|
this.clearingProcess(false);
|
|
|
|
this.selectedFolder(null);
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
FolderClearPopupView.prototype.onShow = function(oFolder)
|
|
|
|
{
|
|
|
|
this.clearPopup();
|
|
|
|
if (oFolder)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
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;
|