snappymail/dev/Settings/User/Templates.js

76 lines
1.7 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';
2016-07-16 05:29:42 +08:00
import TemplateStore from 'Stores/User/Template';
import Remote from 'Remote/User/Ajax';
2019-07-05 03:19:24 +08:00
import { getApp } from 'Helper/Apps/User';
2019-07-05 03:19:24 +08:00
import { showScreenPopup } from 'Knoin/Knoin';
2019-07-05 03:19:24 +08:00
class TemplatesUserSettings {
2016-07-16 05:29:42 +08:00
constructor() {
this.templates = TemplateStore.templates;
2019-07-05 03:19:24 +08:00
this.processText = ko.computed(() =>
TemplateStore.templates.loading() ? i18n('SETTINGS_TEMPLETS/LOADING_PROCESS') : ''
);
2016-07-16 05:29:42 +08:00
this.visibility = ko.computed(() => ('' === this.processText() ? 'hidden' : 'visible'));
2016-07-16 05:29:42 +08:00
this.templateForDeletion = ko.observable(null).deleteAccessHelper();
}
2016-07-16 05:29:42 +08:00
scrollableOptions(sWrapper) {
return {
handle: '.drag-handle',
containment: sWrapper || 'parent',
axis: 'y'
};
2016-06-30 08:02:45 +08:00
}
2016-07-16 05:29:42 +08:00
addNewTemplate() {
showScreenPopup(require('View/Popup/Template'));
}
2016-07-16 05:29:42 +08:00
editTemplate(oTemplateItem) {
2019-07-05 03:19:24 +08:00
if (oTemplateItem) {
2016-07-16 05:29:42 +08:00
showScreenPopup(require('View/Popup/Template'), [oTemplateItem]);
}
}
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() {
getApp().templates();
2016-07-16 05:29:42 +08:00
}
2016-07-16 05:29:42 +08:00
onBuild(oDom) {
const self = this;
2019-07-05 03:19:24 +08:00
oDom.on('click', '.templates-list .template-item .e-action', function() {
// eslint-disable-line prefer-arrow-callback
const template = ko.dataFor(this); // eslint-disable-line no-invalid-this
if (template) {
self.editTemplate(template);
}
});
2016-07-16 05:29:42 +08:00
this.reloadTemplates();
}
}
2019-07-05 03:19:24 +08:00
export { TemplatesUserSettings, TemplatesUserSettings as default };