snappymail/dev/Settings/User/Templates.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
2019-07-05 03:19:24 +08:00
import { i18n } from 'Common/Translator';
import { TemplateUserStore } from 'Stores/User/Template';
import Remote from 'Remote/User/Fetch';
2019-07-05 03:19:24 +08:00
import { showScreenPopup } from 'Knoin/Knoin';
import { TemplatePopupView } from 'View/Popup/Template';
2021-01-22 23:32:08 +08:00
export class TemplatesUserSettings {
2016-07-16 05:29:42 +08:00
constructor() {
this.templates = TemplateUserStore.templates;
2019-07-05 03:19:24 +08:00
this.processText = ko.computed(() =>
TemplateUserStore.templates.loading() ? i18n('SETTINGS_TEMPLETS/LOADING_PROCESS') : ''
2019-07-05 03:19:24 +08:00
);
this.visibility = ko.computed(() => this.processText() ? 'visible' : 'hidden');
2016-07-16 05:29:42 +08:00
this.templateForDeletion = ko.observable(null).deleteAccessHelper();
}
2016-07-16 05:29:42 +08:00
addNewTemplate() {
showScreenPopup(TemplatePopupView);
2016-07-16 05:29:42 +08:00
}
2016-07-16 05:29:42 +08:00
editTemplate(oTemplateItem) {
2019-07-05 03:19:24 +08:00
if (oTemplateItem) {
showScreenPopup(TemplatePopupView, [oTemplateItem]);
2016-07-16 05:29:42 +08:00
}
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
deleteTemplate(templateToRemove) {
2019-07-05 03:19:24 +08:00
if (templateToRemove && templateToRemove.deleteAccess()) {
2016-07-16 05:29:42 +08:00
this.templateForDeletion(null);
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
if (templateToRemove) {
2016-07-16 05:29:42 +08:00
this.templates.remove((template) => templateToRemove === template);
Remote.templateDelete(() => {
this.reloadTemplates();
}, templateToRemove.id);
}
}
2016-06-30 08:02:45 +08:00
}
2016-07-16 05:29:42 +08:00
reloadTemplates() {
2020-09-15 15:29:25 +08:00
rl.app.templates();
2016-07-16 05:29:42 +08:00
}
2016-07-16 05:29:42 +08:00
onBuild(oDom) {
oDom.addEventListener('click', event => {
const el = event.target.closestWithin('.templates-list .template-item .e-action', oDom);
el && ko.dataFor(el) && this.editTemplate(ko.dataFor(el));
2019-07-05 03:19:24 +08:00
});
2016-07-16 05:29:42 +08:00
this.reloadTemplates();
}
}