CommonJS (research/2)

This commit is contained in:
RainLoop Team 2014-08-21 19:08:34 +04:00
parent 56607de87c
commit 586abbb802
115 changed files with 16201 additions and 9943 deletions

View file

@ -1,97 +1,120 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsFolderClearViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderClear');
this.selectedFolder = ko.observable(null);
this.clearingProcess = ko.observable(false);
this.clearingError = ko.observable('');
(function (module) {
this.folderFullNameForClear = ko.computed(function () {
var oFolder = this.selectedFolder();
return oFolder ? oFolder.printableFullName() : '';
}, this);
'use strict';
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);
var
ko = require('../../External/ko.js'),
Enums = require('../../Common/Enums.js'),
Utils = require('../../Common/Utils.js'),
this.clearCommand = Utils.createCommand(this, function () {
var
self = this,
oFolderToClear = this.selectedFolder()
;
Data = require('../../Storages/WebMailDataStorage.js'),
Cache = require('../../Storages/WebMailCacheStorage.js'),
Remote = require('../../Storages/WebMailAjaxRemoteStorage.js'),
if (oFolderToClear)
{
RL.data().message(null);
RL.data().messageList([]);
kn = require('../../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../../Knoin/KnoinAbstractViewModel.js')
;
this.clearingProcess(true);
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsFolderClearViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderClear');
RL.cache().setFolderHash(oFolderToClear.fullNameRaw, '');
RL.remote().folderClear(function (sResult, oData) {
self.clearingProcess(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
RL.reloadMessageList(true);
self.cancelCommand();
}
else
{
if (oData && oData.ErrorCode)
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);
Cache.setFolderHash(oFolderToClear.fullNameRaw, '');
Remote.folderClear(function (sResult, oData) {
self.clearingProcess(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
self.clearingError(Utils.getNotification(oData.ErrorCode));
RL.reloadMessageList(true);
self.cancelCommand();
}
else
{
self.clearingError(Utils.getNotification(Enums.Notification.MailServerError));
if (oData && oData.ErrorCode)
{
self.clearingError(Utils.getNotification(oData.ErrorCode));
}
else
{
self.clearingError(Utils.getNotification(Enums.Notification.MailServerError));
}
}
}
}, oFolderToClear.fullNameRaw);
}
}, oFolderToClear.fullNameRaw);
}
}, function () {
}, function () {
var
oFolder = this.selectedFolder(),
bIsClearing = this.clearingProcess()
;
var
oFolder = this.selectedFolder(),
bIsClearing = this.clearingProcess()
;
return !bIsClearing && null !== oFolder;
return !bIsClearing && null !== oFolder;
});
});
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsFolderClearViewModel', PopupsFolderClearViewModel);
PopupsFolderClearViewModel.prototype.clearPopup = function ()
{
this.clearingProcess(false);
this.selectedFolder(null);
};
PopupsFolderClearViewModel.prototype.onShow = function (oFolder)
{
this.clearPopup();
if (oFolder)
{
this.selectedFolder(oFolder);
kn.constructorEnd(this);
}
};
kn.extendAsViewModel('PopupsFolderClearViewModel', PopupsFolderClearViewModel);
PopupsFolderClearViewModel.prototype.clearPopup = function ()
{
this.clearingProcess(false);
this.selectedFolder(null);
};
PopupsFolderClearViewModel.prototype.onShow = function (oFolder)
{
this.clearPopup();
if (oFolder)
{
this.selectedFolder(oFolder);
}
};
module.exports = new PopupsFolderClearViewModel();
}(module));