snappymail/dev/Settings/Admin/Domains.js
djmaze ad8fd8879b This version uses Rollup instead of WebPack.
Due to that the code is smaller and has changes to prevent Circular Dependencies
2021-01-25 22:00:13 +01:00

60 lines
1.6 KiB
JavaScript

import ko from 'ko';
import { StorageResultType } from 'Common/Enums';
import { showScreenPopup } from 'Knoin/Knoin';
import DomainStore from 'Stores/Admin/Domain';
import Remote from 'Remote/Admin/Fetch';
import { DomainPopupView } from 'View/Popup/Domain';
import { DomainAliasPopupView } from 'View/Popup/DomainAlias';
export class DomainsAdminSettings {
constructor() {
this.domains = DomainStore.domains;
this.visibility = ko.computed(() => (this.domains.loading() ? 'visible' : 'hidden'));
this.domainForDeletion = ko.observable(null).deleteAccessHelper();
this.onDomainListChangeRequest = this.onDomainListChangeRequest.bind(this);
this.onDomainLoadRequest = this.onDomainLoadRequest.bind(this);
}
createDomain() {
showScreenPopup(DomainPopupView);
}
createDomainAlias() {
showScreenPopup(DomainAliasPopupView);
}
deleteDomain(domain) {
this.domains.remove(domain);
Remote.domainDelete(this.onDomainListChangeRequest, domain.name);
}
disableDomain(domain) {
domain.disabled(!domain.disabled());
Remote.domainDisable(this.onDomainListChangeRequest, domain.name, domain.disabled());
}
onBuild(oDom) {
oDom.addEventListener('click', event => {
let el = event.target.closestWithin('.b-admin-domains-list-table .e-item .e-action', oDom);
el && ko.dataFor(el) && Remote.domain(this.onDomainLoadRequest, ko.dataFor(el).name);
});
rl.app.reloadDomainList();
}
onDomainLoadRequest(sResult, oData) {
if (StorageResultType.Success === sResult && oData && oData.Result) {
showScreenPopup(DomainPopupView, [oData.Result]);
}
}
onDomainListChangeRequest() {
rl.app.reloadDomainList();
}
}