snappymail/dev/Settings/User/Templates.js

81 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
2016-07-16 05:29:42 +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';
import {getApp} from 'Helper/Apps/User';
import {showScreenPopup} from 'Knoin/Knoin';
2016-07-16 05:29:42 +08:00
class TemplatesUserSettings
2016-06-30 08:02:45 +08:00
{
2016-07-16 05:29:42 +08:00
constructor() {
this.templates = TemplateStore.templates;
2016-07-16 05:29:42 +08:00
this.processText = ko.computed(() => (TemplateStore.templates.loading() ? i18n('SETTINGS_TEMPLETS/LOADING_PROCESS') : ''));
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) {
if (oTemplateItem)
{
showScreenPopup(require('View/Popup/Template'), [oTemplateItem]);
}
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
deleteTemplate(templateToRemove) {
if (templateToRemove && templateToRemove.deleteAccess())
{
2016-07-16 05:29:42 +08:00
this.templateForDeletion(null);
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
if (templateToRemove)
{
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;
2016-07-16 05:29:42 +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
2016-07-16 05:29:42 +08:00
if (template)
{
self.editTemplate(template);
}
});
this.reloadTemplates();
}
}
2016-07-16 03:54:37 +08:00
export {TemplatesUserSettings, TemplatesUserSettings as default};