mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-15 12:15:20 +08:00
66 lines
1.3 KiB
JavaScript
66 lines
1.3 KiB
JavaScript
import { getNotification } from 'Common/Translator';
|
|
import { addObservablesTo, addComputablesTo } from 'External/ko';
|
|
|
|
import { DomainAdminStore } from 'Stores/Admin/Domain';
|
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
|
|
|
import { decorateKoCommands } from 'Knoin/Knoin';
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|
|
|
export class DomainAliasPopupView extends AbstractViewPopup {
|
|
constructor() {
|
|
super('DomainAlias');
|
|
|
|
addObservablesTo(this, {
|
|
saving: false,
|
|
savingError: '',
|
|
|
|
name: '',
|
|
|
|
alias: ''
|
|
});
|
|
|
|
addComputablesTo(this, {
|
|
domains: () => DomainAdminStore.filter(item => item && !item.alias),
|
|
|
|
domainsOptions: () => this.domains().map(item => ({ optValue: item.name, optText: item.name })),
|
|
|
|
canBeSaved: () => !this.saving() && this.name() && this.alias()
|
|
});
|
|
|
|
decorateKoCommands(this, {
|
|
createCommand: self => self.canBeSaved()
|
|
});
|
|
}
|
|
|
|
createCommand() {
|
|
this.saving(true);
|
|
Remote.request('AdminDomainAliasSave',
|
|
iError => {
|
|
this.saving(false);
|
|
if (iError) {
|
|
this.savingError(getNotification(iError));
|
|
} else {
|
|
DomainAdminStore.fetch();
|
|
this.close();
|
|
}
|
|
}, {
|
|
Name: this.name(),
|
|
Alias: this.alias()
|
|
});
|
|
}
|
|
|
|
onShow() {
|
|
this.clearForm();
|
|
}
|
|
|
|
clearForm() {
|
|
this.saving(false);
|
|
this.savingError('');
|
|
|
|
this.name('');
|
|
|
|
this.alias('');
|
|
}
|
|
}
|