snappymail/dev/View/Popup/FolderClear.js

126 lines
2.8 KiB
JavaScript
Raw Normal View History

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