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,118 +1,138 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsActivateViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsActivate');
(function (module) {
var self = this;
'use strict';
this.domain = ko.observable('');
this.key = ko.observable('');
this.key.focus = ko.observable(false);
this.activationSuccessed = ko.observable(false);
var
ko = require('../../External/ko.js'),
Enums = require('../../Common/Enums.js'),
Utils = require('../../Common/Utils.js'),
this.licenseTrigger = RL.data().licenseTrigger;
this.activateProcess = ko.observable(false);
this.activateText = ko.observable('');
this.activateText.isError = ko.observable(false);
Data = require('../../Storages/AdminDataStorage.js'),
Remote = require('../../Storages/AdminAjaxRemoteStorage.js'),
kn = require('../../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../../Knoin/KnoinAbstractViewModel.js')
;
this.key.subscribe(function () {
this.activateText('');
this.activateText.isError(false);
}, this);
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsActivateViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsActivate');
this.activationSuccessed.subscribe(function (bValue) {
if (bValue)
{
this.licenseTrigger(!this.licenseTrigger());
}
}, this);
var self = this;
this.activateCommand = Utils.createCommand(this, function () {
this.domain = ko.observable('');
this.key = ko.observable('');
this.key.focus = ko.observable(false);
this.activationSuccessed = ko.observable(false);
this.activateProcess(true);
if (this.validateSubscriptionKey())
{
RL.remote().licensingActivate(function (sResult, oData) {
this.licenseTrigger = Data.licenseTrigger;
self.activateProcess(false);
if (Enums.StorageResultType.Success === sResult && oData.Result)
{
if (true === oData.Result)
this.activateProcess = ko.observable(false);
this.activateText = ko.observable('');
this.activateText.isError = ko.observable(false);
this.key.subscribe(function () {
this.activateText('');
this.activateText.isError(false);
}, this);
this.activationSuccessed.subscribe(function (bValue) {
if (bValue)
{
this.licenseTrigger(!this.licenseTrigger());
}
}, this);
this.activateCommand = Utils.createCommand(this, function () {
this.activateProcess(true);
if (this.validateSubscriptionKey())
{
Remote.licensingActivate(function (sResult, oData) {
self.activateProcess(false);
if (Enums.StorageResultType.Success === sResult && oData.Result)
{
self.activationSuccessed(true);
self.activateText('Subscription Key Activated Successfully');
self.activateText.isError(false);
if (true === oData.Result)
{
self.activationSuccessed(true);
self.activateText('Subscription Key Activated Successfully');
self.activateText.isError(false);
}
else
{
self.activateText(oData.Result);
self.activateText.isError(true);
self.key.focus(true);
}
}
else
else if (oData.ErrorCode)
{
self.activateText(oData.Result);
self.activateText(Utils.getNotification(oData.ErrorCode));
self.activateText.isError(true);
self.key.focus(true);
}
else
{
self.activateText(Utils.getNotification(Enums.Notification.UnknownError));
self.activateText.isError(true);
self.key.focus(true);
}
}
else if (oData.ErrorCode)
{
self.activateText(Utils.getNotification(oData.ErrorCode));
self.activateText.isError(true);
self.key.focus(true);
}
else
{
self.activateText(Utils.getNotification(Enums.Notification.UnknownError));
self.activateText.isError(true);
self.key.focus(true);
}
}, this.domain(), this.key());
}
else
}, this.domain(), this.key());
}
else
{
this.activateProcess(false);
this.activateText('Invalid Subscription Key');
this.activateText.isError(true);
this.key.focus(true);
}
}, function () {
return !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed();
});
kn.constructorEnd(this);
}
kn.extendAsViewModel('PopupsActivateViewModel', PopupsActivateViewModel);
PopupsActivateViewModel.prototype.onShow = function ()
{
this.domain(RL.settingsGet('AdminDomain'));
if (!this.activateProcess())
{
this.key('');
this.activateText('');
this.activateText.isError(false);
this.activationSuccessed(false);
}
};
PopupsActivateViewModel.prototype.onFocus = function ()
{
if (!this.activateProcess())
{
this.activateProcess(false);
this.activateText('Invalid Subscription Key');
this.activateText.isError(true);
this.key.focus(true);
}
};
}, function () {
return !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed();
});
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsActivateViewModel', PopupsActivateViewModel);
PopupsActivateViewModel.prototype.onShow = function ()
{
this.domain(RL.settingsGet('AdminDomain'));
if (!this.activateProcess())
/**
* @returns {boolean}
*/
PopupsActivateViewModel.prototype.validateSubscriptionKey = function ()
{
this.key('');
this.activateText('');
this.activateText.isError(false);
this.activationSuccessed(false);
}
};
var sValue = this.key();
return '' === sValue || !!/^RL[\d]+-[A-Z0-9\-]+Z$/.test(Utils.trim(sValue));
};
module.exports = new PopupsActivateViewModel();
PopupsActivateViewModel.prototype.onFocus = function ()
{
if (!this.activateProcess())
{
this.key.focus(true);
}
};
/**
* @returns {boolean}
*/
PopupsActivateViewModel.prototype.validateSubscriptionKey = function ()
{
var sValue = this.key();
return '' === sValue || !!/^RL[\d]+-[A-Z0-9\-]+Z$/.test(Utils.trim(sValue));
};
}(module));