2021-03-18 19:33:13 +08:00
|
|
|
import { getNotification } from 'Common/Translator';
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
import { DomainAdminStore } from 'Stores/Admin/Domain';
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2016-06-11 06:20:09 +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 DomainAliasPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('DomainAlias');
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
saving: false,
|
|
|
|
savingError: '',
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
name: '',
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
alias: ''
|
|
|
|
});
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2021-09-03 22:37:20 +08:00
|
|
|
this.addComputables({
|
|
|
|
domains: () => DomainAdminStore.filter(item => item && !item.alias),
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2021-09-03 22:37:20 +08:00
|
|
|
domainsOptions: () => this.domains().map(item => ({ optValue: item.name, optText: item.name })),
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2021-09-03 22:37:20 +08:00
|
|
|
canBeSaved: () => !this.saving() && this.name() && this.alias()
|
|
|
|
});
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
decorateKoCommands(this, {
|
|
|
|
createCommand: self => self.canBeSaved()
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
createCommand() {
|
|
|
|
this.saving(true);
|
2021-03-18 19:33:13 +08:00
|
|
|
Remote.createDomainAlias(iError => {
|
|
|
|
this.saving(false);
|
|
|
|
if (iError) {
|
|
|
|
this.savingError(getNotification(iError));
|
|
|
|
} else {
|
2021-03-15 05:36:23 +08:00
|
|
|
DomainAdminStore.fetch();
|
2016-08-17 06:01:20 +08:00
|
|
|
this.closeCommand();
|
|
|
|
}
|
2021-03-18 19:33:13 +08:00
|
|
|
}, this.name(), this.alias());
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShow() {
|
|
|
|
this.clearForm();
|
|
|
|
}
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
clearForm() {
|
|
|
|
this.saving(false);
|
|
|
|
this.savingError('');
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.name('');
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.alias('');
|
|
|
|
}
|
|
|
|
}
|
2016-06-11 06:20:09 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { DomainAliasPopupView, DomainAliasPopupView as default };
|