2014-04-06 03:48:22 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2014-08-25 23:49:01 +08:00
|
|
|
|
|
|
|
'use strict';
|
2014-04-06 03:48:22 +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-09-05 06:49:03 +08:00
|
|
|
Enums = require('Common/Enums'),
|
2015-02-17 21:16:38 +08:00
|
|
|
Globals = require('Common/Globals'),
|
2014-09-05 06:49:03 +08:00
|
|
|
Utils = require('Common/Utils'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2015-02-23 00:35:17 +08:00
|
|
|
Remote = require('Remote/User/Ajax'),
|
2014-04-06 03:48:22 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
|
|
|
AbstractView = require('Knoin/AbstractView')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
2014-09-06 05:44:29 +08:00
|
|
|
* @extends AbstractView
|
2014-08-21 23:08:34 +08:00
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
function TwoFactorTestPopupView()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.call(this, 'Popups', 'PopupsTwoFactorTest');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.code = ko.observable('');
|
|
|
|
this.code.focused = ko.observable(false);
|
|
|
|
this.code.status = ko.observable(null);
|
|
|
|
|
2015-02-16 05:55:59 +08:00
|
|
|
this.koTestedTrigger = null;
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.testing = ko.observable(false);
|
|
|
|
|
|
|
|
// commands
|
|
|
|
this.testCode = Utils.createCommand(this, function () {
|
|
|
|
|
|
|
|
this.testing(true);
|
|
|
|
Remote.testTwoFactor(function (sResult, oData) {
|
|
|
|
|
|
|
|
self.testing(false);
|
|
|
|
self.code.status(Enums.StorageResultType.Success === sResult && oData && oData.Result ? true : false);
|
|
|
|
|
2015-02-16 05:55:59 +08:00
|
|
|
if (self.koTestedTrigger && self.code.status())
|
|
|
|
{
|
|
|
|
self.koTestedTrigger(true);
|
|
|
|
}
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
}, this.code());
|
|
|
|
|
|
|
|
}, function () {
|
|
|
|
return '' !== this.code() && !this.testing();
|
|
|
|
});
|
|
|
|
|
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn.extendAsViewModel(['View/Popup/TwoFactorTest', 'PopupsTwoFactorTestViewModel'], TwoFactorTestPopupView);
|
|
|
|
_.extend(TwoFactorTestPopupView.prototype, AbstractView.prototype);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
TwoFactorTestPopupView.prototype.clearPopup = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.code('');
|
|
|
|
this.code.focused(false);
|
|
|
|
this.code.status(null);
|
|
|
|
this.testing(false);
|
2015-02-16 05:55:59 +08:00
|
|
|
|
|
|
|
this.koTestedTrigger = null;
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2015-02-16 05:55:59 +08:00
|
|
|
TwoFactorTestPopupView.prototype.onShow = function (koTestedTrigger)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.clearPopup();
|
2015-02-16 05:55:59 +08:00
|
|
|
|
|
|
|
this.koTestedTrigger = koTestedTrigger;
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2015-02-16 05:55:59 +08:00
|
|
|
TwoFactorTestPopupView.prototype.onShowWithDelay = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-02-17 21:16:38 +08:00
|
|
|
if (!Globals.bMobile)
|
|
|
|
{
|
|
|
|
this.code.focused(true);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
module.exports = TwoFactorTestPopupView;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|