snappymail/dev/View/Popup/TwoFactorTest.js

76 lines
1.5 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'),
Utils = require('Common/Utils'),
2014-08-21 23:08:34 +08:00
Remote = require('Storage/App/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);
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);
}, 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);
};
TwoFactorTestPopupView.prototype.onShow = function ()
2014-08-21 23:08:34 +08:00
{
this.clearPopup();
};
TwoFactorTestPopupView.prototype.onFocus = function ()
2014-08-21 23:08:34 +08:00
{
this.code.focused(true);
};
module.exports = TwoFactorTestPopupView;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());