2019-07-05 03:19:24 +08:00
|
|
|
import { getNotification } from 'Common/Translator';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
import { decorateKoCommands } from 'Knoin/Knoin';
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|
|
|
|
|
|
|
class AccountPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('Account');
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
isNew: true,
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
email: '',
|
|
|
|
password: '',
|
2014-10-22 00:49:15 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
emailError: false,
|
|
|
|
passwordError: false,
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
submitRequest: false,
|
|
|
|
submitError: '',
|
2021-03-24 05:57:40 +08:00
|
|
|
submitErrorAdditional: ''
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.email.subscribe(() => this.emailError(false));
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.password.subscribe(() => this.passwordError(false));
|
2021-02-19 19:09:20 +08:00
|
|
|
|
|
|
|
decorateKoCommands(this, {
|
|
|
|
addAccountCommand: self => !self.submitRequest()
|
|
|
|
});
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
addAccountCommand() {
|
2020-08-07 00:24:46 +08:00
|
|
|
this.emailError(!this.email().trim());
|
|
|
|
this.passwordError(!this.password().trim());
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (this.emailError() || this.passwordError()) {
|
2016-09-10 06:38:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
this.submitRequest(true);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
Remote.accountSetup(
|
2021-03-16 16:46:23 +08:00
|
|
|
(iError, data) => {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.submitRequest(false);
|
2021-03-18 19:33:13 +08:00
|
|
|
if (iError) {
|
|
|
|
this.submitError(getNotification(iError));
|
|
|
|
this.submitErrorAdditional((data && data.ErrorMessageAdditional) || '');
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-03-18 19:33:13 +08:00
|
|
|
rl.app.accountsAndIdentities();
|
|
|
|
this.cancelCommand();
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
this.email(),
|
|
|
|
this.password(),
|
|
|
|
this.isNew()
|
|
|
|
);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
return true;
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
clearPopup() {
|
|
|
|
this.isNew(true);
|
2014-10-22 00:49:15 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.email('');
|
|
|
|
this.password('');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.emailError(false);
|
|
|
|
this.passwordError(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.submitRequest(false);
|
|
|
|
this.submitError('');
|
|
|
|
this.submitErrorAdditional('');
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShow(account) {
|
|
|
|
this.clearPopup();
|
2019-07-05 03:19:24 +08:00
|
|
|
if (account && account.canBeEdit()) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.isNew(false);
|
|
|
|
this.email(account.email);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-12-29 04:42:07 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { AccountPopupView, AccountPopupView as default };
|