2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
'use strict';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
var
|
2014-08-25 23:49:01 +08:00
|
|
|
_ = require('_'),
|
|
|
|
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'),
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator = require('Common/Translator'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-23 00:35:17 +08:00
|
|
|
Remote = require('Remote/User/Ajax'),
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
|
|
|
AbstractView = require('Knoin/AbstractView')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
2014-09-06 05:44:29 +08:00
|
|
|
* @extends AbstractView
|
2014-08-21 23:08:34 +08:00
|
|
|
*/
|
2015-02-06 23:26:20 +08:00
|
|
|
function AccountPopupView()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-02-06 23:26:20 +08:00
|
|
|
AbstractView.call(this, 'Popups', 'PopupsAccount');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-10-22 00:49:15 +08:00
|
|
|
this.isNew = ko.observable(true);
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.email = ko.observable('');
|
|
|
|
this.password = ko.observable('');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.emailError = ko.observable(false);
|
|
|
|
this.passwordError = ko.observable(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.email.subscribe(function () {
|
|
|
|
this.emailError(false);
|
|
|
|
}, this);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.password.subscribe(function () {
|
|
|
|
this.passwordError(false);
|
|
|
|
}, this);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.submitRequest = ko.observable(false);
|
|
|
|
this.submitError = ko.observable('');
|
2015-02-25 23:29:34 +08:00
|
|
|
this.submitErrorAdditional = ko.observable('');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.emailFocus = ko.observable(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.addAccountCommand = Utils.createCommand(this, function () {
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.emailError('' === Utils.trim(this.email()));
|
|
|
|
this.passwordError('' === Utils.trim(this.password()));
|
|
|
|
|
|
|
|
if (this.emailError() || this.passwordError())
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.submitRequest(true);
|
|
|
|
|
2014-10-22 00:49:15 +08:00
|
|
|
Remote.accountSetup(_.bind(function (sResult, oData) {
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
this.submitRequest(false);
|
2015-02-25 23:29:34 +08:00
|
|
|
if (Enums.StorageResultType.Success === sResult && oData)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
if (oData.Result)
|
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
require('App/User').default.accountsAndIdentities();
|
2014-08-21 23:08:34 +08:00
|
|
|
this.cancelCommand();
|
|
|
|
}
|
2015-02-25 23:29:34 +08:00
|
|
|
else
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-02-25 23:29:34 +08:00
|
|
|
this.submitError(oData.ErrorCode ? Translator.getNotification(oData.ErrorCode) :
|
|
|
|
Translator.getNotification(Enums.Notification.UnknownError));
|
|
|
|
|
|
|
|
if (oData.ErrorMessageAdditional)
|
|
|
|
{
|
|
|
|
this.submitErrorAdditional(oData.ErrorMessageAdditional);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
else
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2015-01-26 07:09:22 +08:00
|
|
|
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
|
2015-02-25 23:29:34 +08:00
|
|
|
this.submitErrorAdditional('');
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 00:49:15 +08:00
|
|
|
}, this), this.email(), this.password(), this.isNew());
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
return true;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
}, function () {
|
|
|
|
return !this.submitRequest();
|
|
|
|
});
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-06 23:26:20 +08:00
|
|
|
kn.extendAsViewModel(['View/Popup/Account', 'View/Popup/AddAccount', 'PopupsAddAccountViewModel'], AccountPopupView);
|
|
|
|
_.extend(AccountPopupView.prototype, AbstractView.prototype);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-06 23:26:20 +08:00
|
|
|
AccountPopupView.prototype.clearPopup = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-10-22 00:49:15 +08:00
|
|
|
this.isNew(true);
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.email('');
|
|
|
|
this.password('');
|
|
|
|
|
|
|
|
this.emailError(false);
|
|
|
|
this.passwordError(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.submitRequest(false);
|
|
|
|
this.submitError('');
|
2015-02-25 23:29:34 +08:00
|
|
|
this.submitErrorAdditional('');
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-06 23:26:20 +08:00
|
|
|
AccountPopupView.prototype.onShow = function (oAccount)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.clearPopup();
|
2014-10-22 00:49:15 +08:00
|
|
|
if (oAccount && oAccount.canBeEdit())
|
|
|
|
{
|
|
|
|
this.isNew(false);
|
|
|
|
this.email(oAccount.email);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-16 05:55:59 +08:00
|
|
|
AccountPopupView.prototype.onShowWithDelay = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.emailFocus(true);
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-06 23:26:20 +08:00
|
|
|
module.exports = AccountPopupView;
|
2013-12-29 04:42:07 +08:00
|
|
|
|
2016-06-28 04:54:38 +08:00
|
|
|
}());
|