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