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'),
|
|
|
|
Consts = require('Common/Consts'),
|
|
|
|
Translator = require('Common/Translator'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
Settings = require('Storage/Settings'),
|
|
|
|
Remote = require('Remote/Admin/Ajax'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
LicenseStore = require('Stores/Admin/License'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
|
|
|
AbstractView = require('Knoin/AbstractView');
|
2015-02-03 18:42:06 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends AbstractView
|
|
|
|
*/
|
|
|
|
function ActivatePopupView()
|
|
|
|
{
|
|
|
|
AbstractView.call(this, 'Popups', 'PopupsActivate');
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
var self = this;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.domain = ko.observable('');
|
|
|
|
this.key = ko.observable('');
|
|
|
|
this.key.focus = ko.observable(false);
|
|
|
|
this.activationSuccessed = ko.observable(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.licenseTrigger = LicenseStore.licenseTrigger;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.activateProcess = ko.observable(false);
|
|
|
|
this.activateText = ko.observable('');
|
|
|
|
this.activateText.isError = ko.observable(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.htmlDescription = ko.computed(function() {
|
|
|
|
return Translator.i18n('POPUPS_ACTIVATE/HTML_DESC', {'DOMAIN': this.domain()});
|
|
|
|
}, this);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.key.subscribe(function() {
|
|
|
|
this.activateText('');
|
|
|
|
this.activateText.isError(false);
|
|
|
|
}, this);
|
2015-03-28 06:06:56 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.activationSuccessed.subscribe(function(bValue) {
|
|
|
|
if (bValue)
|
|
|
|
{
|
|
|
|
this.licenseTrigger(!this.licenseTrigger());
|
|
|
|
}
|
|
|
|
}, this);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.activateCommand = Utils.createCommand(this, function() {
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.activateProcess(true);
|
|
|
|
if (this.validateSubscriptionKey())
|
|
|
|
{
|
|
|
|
Remote.licensingActivate(function(sResult, oData) {
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
self.activateProcess(false);
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData.Result)
|
|
|
|
{
|
|
|
|
if (true === oData.Result)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
self.activationSuccessed(true);
|
|
|
|
self.activateText(Translator.i18n('POPUPS_ACTIVATE/SUBS_KEY_ACTIVATED'));
|
|
|
|
self.activateText.isError(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
self.activateText(oData.Result);
|
2013-11-16 06:21:12 +08:00
|
|
|
self.activateText.isError(true);
|
|
|
|
self.key.focus(true);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
else if (oData.ErrorCode)
|
|
|
|
{
|
|
|
|
self.activateText(Translator.getNotification(oData.ErrorCode));
|
|
|
|
self.activateText.isError(true);
|
|
|
|
self.key.focus(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.activateText(Translator.getNotification(Enums.Notification.UnknownError));
|
|
|
|
self.activateText.isError(true);
|
|
|
|
self.key.focus(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}, this.domain(), this.key());
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
else
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.activateProcess(false);
|
|
|
|
this.activateText(Translator.i18n('POPUPS_ACTIVATE/ERROR_INVALID_SUBS_KEY'));
|
|
|
|
this.activateText.isError(true);
|
2014-08-21 23:08:34 +08:00
|
|
|
this.key.focus(true);
|
|
|
|
}
|
2013-12-29 04:42:07 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
}, function() {
|
|
|
|
return !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed();
|
|
|
|
});
|
|
|
|
|
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
kn.extendAsViewModel(['View/Popup/Activate', 'PopupsActivateViewModel'], ActivatePopupView);
|
|
|
|
_.extend(ActivatePopupView.prototype, AbstractView.prototype);
|
|
|
|
|
|
|
|
ActivatePopupView.prototype.onShow = function(bTrial)
|
|
|
|
{
|
|
|
|
this.domain(Settings.settingsGet('AdminDomain'));
|
|
|
|
if (!this.activateProcess())
|
2013-12-29 04:42:07 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
bTrial = Utils.isUnd(bTrial) ? false : !!bTrial;
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.key(bTrial ? Consts.RAINLOOP_TRIAL_KEY : '');
|
|
|
|
this.activateText('');
|
|
|
|
this.activateText.isError(false);
|
|
|
|
this.activationSuccessed(false);
|
|
|
|
}
|
|
|
|
};
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
ActivatePopupView.prototype.onShowWithDelay = function()
|
|
|
|
{
|
|
|
|
if (!this.activateProcess())
|
|
|
|
{
|
|
|
|
this.key.focus(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
ActivatePopupView.prototype.validateSubscriptionKey = function()
|
|
|
|
{
|
|
|
|
var sValue = this.key();
|
|
|
|
return '' === sValue || Consts.RAINLOOP_TRIAL_KEY === sValue || !!(/^RL[\d]+-[A-Z0-9\-]+Z$/).test(Utils.trim(sValue));
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ActivatePopupView;
|