snappymail/dev/Settings/Admin/Domains.js

62 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
import { StorageResultType } from 'Common/Enums';
import { showScreenPopup } from 'Knoin/Knoin';
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
import DomainStore from 'Stores/Admin/Domain';
import Remote from 'Remote/Admin/Ajax';
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
import { getApp } from 'Helper/Apps/Admin';
2019-07-05 03:19:24 +08:00
class DomainsAdminSettings {
2016-07-16 05:29:42 +08:00
constructor() {
this.domains = DomainStore.domains;
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.visibility = ko.computed(() => (this.domains.loading() ? 'visible' : 'hidden'));
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.domainForDeletion = ko.observable(null).deleteAccessHelper();
2016-06-30 08:02:45 +08:00
this.onDomainListChangeRequest = this.onDomainListChangeRequest.bind(this);
this.onDomainLoadRequest = this.onDomainLoadRequest.bind(this);
2016-07-16 05:29:42 +08:00
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
createDomain() {
showScreenPopup(require('View/Popup/Domain'));
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
createDomainAlias() {
showScreenPopup(require('View/Popup/DomainAlias'));
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
deleteDomain(domain) {
this.domains.remove(domain);
Remote.domainDelete(this.onDomainListChangeRequest, domain.name);
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
disableDomain(domain) {
domain.disabled(!domain.disabled());
Remote.domainDisable(this.onDomainListChangeRequest, domain.name, domain.disabled());
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
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);
2019-07-05 03:19:24 +08:00
});
2016-07-16 05:29:42 +08:00
getApp().reloadDomainList();
2014-08-21 23:08:34 +08:00
}
2016-07-16 05:29:42 +08:00
onDomainLoadRequest(sResult, oData) {
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === sResult && oData && oData.Result) {
2016-07-16 05:29:42 +08:00
showScreenPopup(require('View/Popup/Domain'), [oData.Result]);
}
}
onDomainListChangeRequest() {
getApp().reloadDomainList();
2016-07-16 05:29:42 +08:00
}
}
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
export { DomainsAdminSettings, DomainsAdminSettings as default };