2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
(function (module, require) {
|
|
|
|
|
|
|
|
'use strict';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
var
|
2014-09-02 08:15:31 +08:00
|
|
|
_ = require('_'),
|
2014-08-25 23:49:01 +08:00
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
Enums = require('Enums'),
|
|
|
|
Utils = require('Utils'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
Data = require('Storage:RainLoop:Data'),
|
|
|
|
Cache = require('Storage:RainLoop:Cache'),
|
|
|
|
Remote = require('Storage:RainLoop:Remote'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
kn = require('App:Knoin'),
|
|
|
|
KnoinAbstractViewModel = require('Knoin:AbstractViewModel')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends KnoinAbstractViewModel
|
|
|
|
*/
|
|
|
|
function PopupsFolderClearViewModel()
|
|
|
|
{
|
|
|
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderClear');
|
|
|
|
|
|
|
|
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 Utils.i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', {
|
|
|
|
'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-09-02 08:15:31 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
Remote.folderClear(function (sResult, oData) {
|
|
|
|
|
|
|
|
self.clearingProcess(false);
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-27 23:59:44 +08:00
|
|
|
require('App:RainLoop').reloadMessageList(true);
|
2014-08-21 23:08:34 +08:00
|
|
|
self.cancelCommand();
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
if (oData && oData.ErrorCode)
|
|
|
|
{
|
|
|
|
self.clearingError(Utils.getNotification(oData.ErrorCode));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.clearingError(Utils.getNotification(Enums.Notification.MailServerError));
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
}, oFolderToClear.fullNameRaw);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
}, function () {
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
var
|
|
|
|
oFolder = this.selectedFolder(),
|
|
|
|
bIsClearing = this.clearingProcess()
|
|
|
|
;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
return !bIsClearing && null !== oFolder;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
});
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
kn.extendAsViewModel(['View:Popup:FolderClear', 'PopupsFolderClearViewModel'], PopupsFolderClearViewModel);
|
|
|
|
_.extend(PopupsFolderClearViewModel.prototype, KnoinAbstractViewModel.prototype);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsFolderClearViewModel.prototype.clearPopup = function ()
|
|
|
|
{
|
|
|
|
this.clearingProcess(false);
|
|
|
|
this.selectedFolder(null);
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsFolderClearViewModel.prototype.onShow = function (oFolder)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.clearPopup();
|
|
|
|
if (oFolder)
|
|
|
|
{
|
|
|
|
this.selectedFolder(oFolder);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
module.exports = PopupsFolderClearViewModel;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
}(module, require));
|