snappymail/dev/View/Popup/TwoFactorTest.js
RainLoop Team 17669b7be0 es5 -> es2015 (last stage)
Signature plugin fixes
Add view decorator
A large number of fixes
2016-08-20 20:30:16 +03:00

73 lines
1.4 KiB
JavaScript

import ko from 'ko';
import {StorageResultType} from 'Common/Enums';
import {bMobileDevice} from 'Common/Globals';
import {createCommand} from 'Common/Utils';
import Remote from 'Remote/User/Ajax';
import {view, ViewType} from 'Knoin/Knoin';
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
@view({
name: 'View/Popup/TwoFactorTest',
type: ViewType.Popup,
templateID: 'PopupsTwoFactorTest'
})
class TwoFactorTestPopupView extends AbstractViewNext
{
constructor() {
super();
this.code = ko.observable('');
this.code.focused = ko.observable(false);
this.code.status = ko.observable(null);
this.koTestedTrigger = null;
this.testing = ko.observable(false);
// commands
this.testCode = createCommand(() => {
this.testing(true);
Remote.testTwoFactor((result, data) => {
this.testing(false);
this.code.status(StorageResultType.Success === result && data && !!data.Result);
if (this.koTestedTrigger && this.code.status())
{
this.koTestedTrigger(true);
}
}, this.code());
}, () => '' !== this.code() && !this.testing());
}
clearPopup() {
this.code('');
this.code.focused(false);
this.code.status(null);
this.testing(false);
this.koTestedTrigger = null;
}
onShow(koTestedTrigger) {
this.clearPopup();
this.koTestedTrigger = koTestedTrigger;
}
onShowWithDelay() {
if (!bMobileDevice)
{
this.code.focused(true);
}
}
}
module.exports = TwoFactorTestPopupView;