mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
client: Add a toggle to set template label (closes #348)
This commit is contained in:
parent
ca6b4c3497
commit
b0480e1667
@ -5,6 +5,7 @@ import EditabilitySelectWidget from "../editability_select.js";
|
||||
import BookmarkSwitchWidget from "../bookmark_switch.js";
|
||||
import SharedSwitchWidget from "../shared_switch.js";
|
||||
import { t } from "../../services/i18n.js";
|
||||
import TemplateSwitchWidget from "../template_switch.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="basic-properties-widget">
|
||||
@ -41,6 +42,8 @@ const TPL = `
|
||||
<div class="bookmark-switch-container"></div>
|
||||
|
||||
<div class="shared-switch-container"></div>
|
||||
|
||||
<div class="template-switch-container"></div>
|
||||
</div>`;
|
||||
|
||||
export default class BasicPropertiesWidget extends NoteContextAwareWidget {
|
||||
@ -52,13 +55,15 @@ export default class BasicPropertiesWidget extends NoteContextAwareWidget {
|
||||
this.editabilitySelectWidget = new EditabilitySelectWidget().contentSized();
|
||||
this.bookmarkSwitchWidget = new BookmarkSwitchWidget().contentSized();
|
||||
this.sharedSwitchWidget = new SharedSwitchWidget().contentSized();
|
||||
this.templateSwitchWidget = new TemplateSwitchWidget().contentSized();
|
||||
|
||||
this.child(
|
||||
this.noteTypeWidget,
|
||||
this.protectedNoteSwitchWidget,
|
||||
this.editabilitySelectWidget,
|
||||
this.bookmarkSwitchWidget,
|
||||
this.sharedSwitchWidget
|
||||
this.sharedSwitchWidget,
|
||||
this.templateSwitchWidget
|
||||
);
|
||||
}
|
||||
|
||||
@ -87,6 +92,7 @@ export default class BasicPropertiesWidget extends NoteContextAwareWidget {
|
||||
this.$widget.find(".editability-select-container").append(this.editabilitySelectWidget.render());
|
||||
this.$widget.find(".bookmark-switch-container").append(this.bookmarkSwitchWidget.render());
|
||||
this.$widget.find(".shared-switch-container").append(this.sharedSwitchWidget.render());
|
||||
this.$widget.find(".template-switch-container").append(this.templateSwitchWidget.render());
|
||||
}
|
||||
|
||||
async refreshWithNote(note) {
|
||||
|
44
src/public/app/widgets/template_switch.js
Normal file
44
src/public/app/widgets/template_switch.js
Normal file
@ -0,0 +1,44 @@
|
||||
import SwitchWidget from "./switch.js";
|
||||
import attributeService from "../services/attributes.js";
|
||||
|
||||
/**
|
||||
* Switch for the basic properties widget which allows the user to select whether the note is a template or not, which toggles the `#template` attribute.
|
||||
*/
|
||||
export default class TemplateSwitchWidget extends SwitchWidget {
|
||||
|
||||
doRender() {
|
||||
super.doRender();
|
||||
|
||||
this.$switchOnName.text("Template");
|
||||
this.$switchOnButton.attr("title", "Make the note a template");
|
||||
|
||||
this.$switchOffName.text("Template");
|
||||
this.$switchOffButton.attr("title", "Remove the note as a template");
|
||||
|
||||
this.$helpButton.attr("data-help-page", "template.html").show();
|
||||
this.$helpButton.on('click', e => utils.openHelp($(e.target)));
|
||||
}
|
||||
|
||||
async switchOn() {
|
||||
await attributeService.setLabel(this.noteId, 'template');
|
||||
}
|
||||
|
||||
async switchOff() {
|
||||
for (const templateAttr of this.note.getOwnedLabels('template')) {
|
||||
await attributeService.removeAttributeById(this.noteId, templateAttr.attributeId);
|
||||
}
|
||||
}
|
||||
|
||||
async refreshWithNote(note) {
|
||||
const isTemplate = note.hasLabel("template");
|
||||
this.$switchOn.toggle(!isTemplate);
|
||||
this.$switchOff.toggle(!!isTemplate);
|
||||
}
|
||||
|
||||
entitiesReloadedEvent({loadResults}) {
|
||||
if (loadResults.getAttributeRows().find(attr => attr.type === 'label' && attr.name === "template" && attr.noteId === this.noteId)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user