snappymail/dev/View/Popup/DomainAlias.js

74 lines
1.7 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2016-06-11 06:20:09 +08:00
2019-07-05 03:19:24 +08:00
import { StorageResultType, Notification } from 'Common/Enums';
import { i18n } from 'Common/Translator';
2016-06-11 06:20:09 +08:00
import DomainStore 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
2019-07-05 03:19:24 +08:00
import { popup, command } from 'Knoin/Knoin';
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
2016-06-11 06:20:09 +08:00
2016-09-10 06:38:16 +08:00
@popup({
name: 'View/Popup/DomainAlias',
templateID: 'PopupsDomainAlias'
})
2019-07-05 03:19:24 +08:00
class DomainAliasPopupView extends AbstractViewNext {
constructor() {
super();
2016-06-11 06:20:09 +08:00
this.saving = ko.observable(false);
this.savingError = ko.observable('');
2016-06-11 06:20:09 +08:00
this.name = ko.observable('');
2016-06-11 06:20:09 +08:00
this.alias = ko.observable('');
2016-06-11 06:20:09 +08:00
this.domains = DomainStore.domainsWithoutAliases;
2016-06-11 06:20:09 +08:00
2019-07-05 03:19:24 +08:00
this.domainsOptions = ko.computed(() =>
this.domains().map(item => ({ optValue: item.name, optText: item.name }))
2016-06-30 08:02:45 +08:00
);
2016-06-11 06:20:09 +08:00
this.canBeSaved = ko.computed(() => !this.saving() && this.name() && this.alias());
2016-06-11 06:20:09 +08:00
this.onDomainAliasCreateOrSaveResponse = this.onDomainAliasCreateOrSaveResponse.bind(this);
}
2016-09-10 06:38:16 +08:00
@command((self) => self.canBeSaved())
createCommand() {
this.saving(true);
2019-07-05 03:19:24 +08:00
Remote.createDomainAlias(this.onDomainAliasCreateOrSaveResponse, this.name(), this.alias());
2016-09-10 06:38:16 +08:00
}
onDomainAliasCreateOrSaveResponse(result, data) {
this.saving(false);
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data) {
if (data.Result) {
2020-09-15 15:29:25 +08:00
rl.app.reloadDomainList();
this.closeCommand();
2019-07-05 03:19:24 +08:00
} else if (Notification.DomainAlreadyExists === data.ErrorCode) {
this.savingError(i18n('ERRORS/DOMAIN_ALREADY_EXISTS'));
}
2019-07-05 03:19:24 +08:00
} else {
this.savingError(i18n('ERRORS/UNKNOWN_ERROR'));
2016-06-11 06:20:09 +08:00
}
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 };