2013-11-16 06:21:12 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
(function (module, require) {
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
'use strict';
|
|
|
|
|
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-08-25 23:49:01 +08:00
|
|
|
Enums = require('Enums'),
|
|
|
|
Utils = require('Utils'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
Remote = require('../../Storages/WebMailAjaxRemoteStorage.js'),
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
kn = require('kn'),
|
|
|
|
KnoinAbstractViewModel = require('KnoinAbstractViewModel')
|
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
|
|
|
|
* @extends KnoinAbstractViewModel
|
|
|
|
*/
|
|
|
|
function PopupsAddAccountViewModel()
|
|
|
|
{
|
|
|
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAddAccount');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-26 23:24:47 +08:00
|
|
|
var App = require('../../Apps/RainLoopApp.js');
|
2014-08-25 15:10:51 +08:00
|
|
|
|
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('');
|
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);
|
|
|
|
|
|
|
|
Remote.accountAdd(_.bind(function (sResult, oData) {
|
|
|
|
|
|
|
|
this.submitRequest(false);
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && 'AccountAdd' === oData.Action)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
if (oData.Result)
|
|
|
|
{
|
2014-08-26 23:24:47 +08:00
|
|
|
App.accountsAndIdentities();
|
2014-08-21 23:08:34 +08:00
|
|
|
this.cancelCommand();
|
|
|
|
}
|
|
|
|
else if (oData.ErrorCode)
|
|
|
|
{
|
|
|
|
this.submitError(Utils.getNotification(oData.ErrorCode));
|
|
|
|
}
|
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
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.submitError(Utils.getNotification(Enums.Notification.UnknownError));
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
}, this), this.email(), '', this.password());
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
kn.extendAsViewModel('PopupsAddAccountViewModel', PopupsAddAccountViewModel);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsAddAccountViewModel.prototype.clearPopup = function ()
|
|
|
|
{
|
|
|
|
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('');
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsAddAccountViewModel.prototype.onShow = function ()
|
|
|
|
{
|
|
|
|
this.clearPopup();
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsAddAccountViewModel.prototype.onFocus = function ()
|
|
|
|
{
|
|
|
|
this.emailFocus(true);
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
module.exports = PopupsAddAccountViewModel;
|
2013-12-29 04:42:07 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
}(module, require));
|