Small fixes and code refactoring

This commit is contained in:
RainLoop Team 2015-02-16 01:55:59 +04:00
parent e6c712862d
commit 1a85330770
67 changed files with 413 additions and 181 deletions

View file

@ -24,15 +24,60 @@
this.secreting = ko.observable(false);
this.viewUser = ko.observable('');
this.viewEnable = ko.observable(false);
this.viewEnable.subs = true;
this.twoFactorStatus = ko.observable(false);
this.twoFactorTested = ko.observable(false);
this.viewSecret = ko.observable('');
this.viewBackupCodes = ko.observable('');
this.viewUrl = ko.observable('');
this.bFirst = true;
this.viewEnable_ = ko.observable(false);
this.viewEnable = ko.computed({
'owner': this,
'read': this.viewEnable_,
'write': function (bValue) {
var self = this;
bValue = !!bValue;
if (bValue && this.twoFactorTested())
{
this.viewEnable_(bValue);
Remote.enableTwoFactor(function (sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
self.viewEnable_(false);
}
}, true);
}
else
{
if (!bValue)
{
this.viewEnable_(bValue);
}
Remote.enableTwoFactor(function (sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
self.viewEnable_(false);
}
}, false);
}
}
});
this.viewTwoFactorEnableTooltip = ko.computed(function () {
Translator.trigger();
return this.twoFactorTested() || this.viewEnable_() ? '' :
Translator.i18n('SETTINGS_SECURITY/TWO_FACTOR_SECRET_TEST_BEFORE_DESC');
}, this);
this.viewTwoFactorStatus = ko.computed(function () {
Translator.trigger();
@ -43,14 +88,18 @@
);
}, this);
this.twoFactorAllowedEnable = ko.computed(function () {
return this.viewEnable() || this.twoFactorTested();
}, this);
this.onResult = _.bind(this.onResult, this);
this.onSecretResult = _.bind(this.onSecretResult, this);
this.onShowSecretResult = _.bind(this.onShowSecretResult, this);
}
SecurityUserSettings.prototype.showSecret = function ()
{
this.secreting(true);
Remote.showTwoFactorSecret(this.onSecretResult);
Remote.showTwoFactorSecret(this.onShowSecretResult);
};
SecurityUserSettings.prototype.hideSecret = function ()
@ -68,7 +117,7 @@
SecurityUserSettings.prototype.testTwoFactor = function ()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/TwoFactorTest'));
require('Knoin/Knoin').showScreenPopup(require('View/Popup/TwoFactorTest'), [this.twoFactorTested]);
};
SecurityUserSettings.prototype.clearTwoFactor = function ()
@ -77,6 +126,8 @@
this.viewBackupCodes('');
this.viewUrl('');
this.twoFactorTested(false);
this.clearing(true);
Remote.clearTwoFactor(this.onResult);
};
@ -96,8 +147,9 @@
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
this.viewUser(Utils.pString(oData.Result.User));
this.viewEnable(!!oData.Result.Enable);
this.viewEnable_(!!oData.Result.Enable);
this.twoFactorStatus(!!oData.Result.IsSet);
this.twoFactorTested(!!oData.Result.Tested);
this.viewSecret(Utils.pString(oData.Result.Secret));
this.viewBackupCodes(Utils.pString(oData.Result.BackupCodes).replace(/[\s]+/g, ' '));
@ -106,36 +158,17 @@
else
{
this.viewUser('');
this.viewEnable(false);
this.viewEnable_(false);
this.twoFactorStatus(false);
this.twoFactorTested(false);
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrl('');
}
if (this.bFirst)
{
this.bFirst = false;
var self = this;
this.viewEnable.subscribe(function (bValue) {
if (this.viewEnable.subs)
{
Remote.enableTwoFactor(function (sResult, oData) {
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
self.viewEnable.subs = false;
self.viewEnable(false);
self.viewEnable.subs = true;
}
}, bValue);
}
}, this);
}
};
SecurityUserSettings.prototype.onSecretResult = function (sResult, oData)
SecurityUserSettings.prototype.onShowSecretResult = function (sResult, oData)
{
this.secreting(false);