snappymail/dev/View/Popup/TwoFactorTest.js

91 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-21 23:08:34 +08:00
var
_ = 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'),
Globals = require('Common/Globals'),
2014-09-05 06:49:03 +08:00
Utils = require('Common/Utils'),
2014-08-21 23:08:34 +08:00
2014-10-18 21:43:44 +08:00
Remote = require('Storage/User/Remote'),
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
* @extends AbstractView
2014-08-21 23:08:34 +08:00
*/
function TwoFactorTestPopupView()
2014-08-21 23:08:34 +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);
}
kn.extendAsViewModel(['View/Popup/TwoFactorTest', 'PopupsTwoFactorTestViewModel'], TwoFactorTestPopupView);
_.extend(TwoFactorTestPopupView.prototype, AbstractView.prototype);
2014-08-21 23:08:34 +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
{
if (!Globals.bMobile)
{
this.code.focused(true);
}
2014-08-21 23:08:34 +08:00
};
module.exports = TwoFactorTestPopupView;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());