snappymail/dev/ViewModels/Popups/PopupsTwoFactorTestViewModel.js

75 lines
1.6 KiB
JavaScript
Raw Normal View History

/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
2014-08-25 23:49:01 +08:00
(function (module, require) {
'use strict';
2014-08-21 23:08:34 +08:00
var
2014-08-25 23:49:01 +08:00
ko = require('ko'),
2014-08-25 15:10:51 +08:00
2014-08-25 23:49:01 +08:00
Enums = require('Enums'),
Utils = require('Utils'),
2014-08-21 23:08:34 +08:00
Remote = require('../../Storages/WebMailAjaxRemoteStorage.js'),
2014-08-25 23:49:01 +08:00
kn = require('kn'),
KnoinAbstractViewModel = require('KnoinAbstractViewModel')
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 KnoinAbstractViewModel
*/
function PopupsTwoFactorTestViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsTwoFactorTest');
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('PopupsTwoFactorTestViewModel', PopupsTwoFactorTestViewModel);
PopupsTwoFactorTestViewModel.prototype.clearPopup = function ()
{
this.code('');
this.code.focused(false);
this.code.status(null);
this.testing(false);
};
PopupsTwoFactorTestViewModel.prototype.onShow = function ()
{
this.clearPopup();
};
PopupsTwoFactorTestViewModel.prototype.onFocus = function ()
{
this.code.focused(true);
};
2014-08-22 23:08:56 +08:00
module.exports = PopupsTwoFactorTestViewModel;
2014-08-21 23:08:34 +08:00
2014-08-25 23:49:01 +08:00
}(module, require));