snappymail/dev/View/Popup/DomainAlias.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

import { getNotification } from 'Common/Translator';
2016-06-11 06:20:09 +08:00
import { DomainAdminStore } from 'Stores/Admin/Domain';
2016-06-11 06:20:09 +08:00
import Remote from 'Remote/Admin/Fetch';
2016-06-11 06:20:09 +08:00
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
class DomainAliasPopupView extends AbstractViewPopup {
constructor() {
super('DomainAlias');
2016-06-11 06:20:09 +08:00
this.addObservables({
saving: false,
savingError: '',
2016-06-11 06:20:09 +08:00
name: '',
2016-06-11 06:20:09 +08:00
alias: ''
});
2016-06-11 06:20:09 +08:00
this.addComputables({
domains: () => DomainAdminStore.filter(item => item && !item.alias),
2016-06-11 06:20:09 +08:00
domainsOptions: () => this.domains().map(item => ({ optValue: item.name, optText: item.name })),
2016-06-11 06:20:09 +08:00
canBeSaved: () => !this.saving() && this.name() && this.alias()
});
2016-06-11 06:20:09 +08:00
decorateKoCommands(this, {
createCommand: self => self.canBeSaved()
});
}
2016-09-10 06:38:16 +08:00
createCommand() {
this.saving(true);
Remote.createDomainAlias(iError => {
this.saving(false);
if (iError) {
this.savingError(getNotification(iError));
} else {
DomainAdminStore.fetch();
this.closeCommand();
}
}, this.name(), this.alias());
2016-06-30 08:02:45 +08:00
}
2016-06-11 06:20:09 +08:00
onShow() {
this.clearForm();
}
2016-06-11 06:20:09 +08:00
clearForm() {
this.saving(false);
this.savingError('');
2016-06-11 06:20:09 +08:00
this.name('');
2016-06-11 06:20:09 +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 };