2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { i18n } from 'Common/Translator';
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { TemplateUserStore } from 'Stores/User/Template';
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { showScreenPopup } from 'Knoin/Knoin';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
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() {
|
2021-03-11 05:41:35 +08:00
|
|
|
this.templates = TemplateUserStore.templates;
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
this.processText = ko.computed(() =>
|
2021-03-11 05:41:35 +08:00
|
|
|
TemplateUserStore.templates.loading() ? i18n('SETTINGS_TEMPLETS/LOADING_PROCESS') : ''
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
2020-07-28 23:20:14 +08:00
|
|
|
this.visibility = ko.computed(() => this.processText() ? 'visible' : 'hidden');
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.templateForDeletion = ko.observable(null).deleteAccessHelper();
|
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
addNewTemplate() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(TemplatePopupView);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
editTemplate(oTemplateItem) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (oTemplateItem) {
|
2021-01-26 05:00:13 +08:00
|
|
|
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);
|
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-02-08 09:11:13 +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
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onBuild(oDom) {
|
2020-08-30 16:30:50 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|