mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-11-09 02:41:39 +08:00
Merge commit 'ef5f5b35db25bd532c1f22424a7f17576cc219a4' into develop
This commit is contained in:
commit
047b226426
@ -95,6 +95,15 @@ const TPL = `
|
||||
</div>`;
|
||||
|
||||
export default class SwitchWidget extends NoteContextAwareWidget {
|
||||
|
||||
protected $switchOn!: JQuery<HTMLElement>;
|
||||
protected $switchOnName!: JQuery<HTMLElement>;
|
||||
protected $switchOnButton!: JQuery<HTMLElement>;
|
||||
protected $switchOff!: JQuery<HTMLElement>;
|
||||
protected $switchOffName!: JQuery<HTMLElement>;
|
||||
protected $switchOffButton!: JQuery<HTMLElement>;
|
||||
protected $helpButton!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
|
||||
@ -113,7 +122,7 @@ export default class SwitchWidget extends NoteContextAwareWidget {
|
||||
this.$helpButton = this.$widget.find(".switch-help-button");
|
||||
}
|
||||
|
||||
toggle(state) {
|
||||
toggle(state: boolean) {
|
||||
if (state) {
|
||||
this.switchOn();
|
||||
} else {
|
||||
@ -1,13 +1,15 @@
|
||||
import SwitchWidget from "./switch.js";
|
||||
import attributeService from "../services/attributes.js";
|
||||
import { t } from "../services/i18n.js";
|
||||
import type FNote from "../entities/fnote.js";
|
||||
import type { EventData } from "../components/app_context.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 {
|
||||
isEnabled() {
|
||||
return super.isEnabled() && !this.noteId.startsWith("_options");
|
||||
return super.isEnabled() && !this.noteId?.startsWith("_options");
|
||||
}
|
||||
|
||||
doRender() {
|
||||
@ -16,29 +18,35 @@ export default class TemplateSwitchWidget extends SwitchWidget {
|
||||
this.$switchOnName.text(t("template_switch.template"));
|
||||
this.$switchOnButton.attr("title", t("template_switch.toggle-on-hint"));
|
||||
|
||||
this.$switchOffName.text("Template");
|
||||
this.$switchOffName.text(t("template_switch.template"));
|
||||
this.$switchOffButton.attr("title", t("template_switch.toggle-off-hint"));
|
||||
|
||||
this.$helpButton.attr("data-help-page", "template.html").show();
|
||||
}
|
||||
|
||||
async switchOn() {
|
||||
if (this.noteId) {
|
||||
await attributeService.setLabel(this.noteId, "template");
|
||||
}
|
||||
}
|
||||
|
||||
async switchOff() {
|
||||
if (!this.note || !this.noteId) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const templateAttr of this.note.getOwnedLabels("template")) {
|
||||
await attributeService.removeAttributeById(this.noteId, templateAttr.attributeId);
|
||||
}
|
||||
}
|
||||
|
||||
async refreshWithNote(note) {
|
||||
async refreshWithNote(note: FNote) {
|
||||
const isTemplate = note.hasLabel("template");
|
||||
this.$switchOn.toggle(!isTemplate);
|
||||
this.$switchOff.toggle(!!isTemplate);
|
||||
}
|
||||
|
||||
entitiesReloadedEvent({ loadResults }) {
|
||||
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||
if (loadResults.getAttributeRows().find((attr) => attr.type === "label" && attr.name === "template" && attr.noteId === this.noteId)) {
|
||||
this.refresh();
|
||||
}
|
||||
@ -4,6 +4,7 @@ import assetPath from "../services/asset_path.js";
|
||||
import shareRoot from "./share_root.js";
|
||||
import escapeHtml from "escape-html";
|
||||
import type SNote from "./shaca/entities/snote.js";
|
||||
import { t } from "i18next";
|
||||
|
||||
/**
|
||||
* Represents the output of the content renderer.
|
||||
@ -43,7 +44,7 @@ function getContent(note: SNote) {
|
||||
} else if (note.type === "book") {
|
||||
result.isEmpty = true;
|
||||
} else {
|
||||
result.content = "<p>This note type cannot be displayed.</p>";
|
||||
result.content = `<p>${t("content_renderer.note-cannot-be-displayed")}</p>`;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -250,5 +250,8 @@
|
||||
"backend_log": {
|
||||
"log-does-not-exist": "The backend log file '{{ fileName }}' does not exist (yet).",
|
||||
"reading-log-failed": "Reading the backend log file '{{ fileName }}' failed."
|
||||
},
|
||||
"content_renderer": {
|
||||
"note-cannot-be-displayed": "This note type cannot be displayed."
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,5 +251,8 @@
|
||||
},
|
||||
"geo-map": {
|
||||
"create-child-note-instruction": "Clic pe hartă pentru a crea o nouă notiță la acea poziție sau apăsați Escape pentru a renunța."
|
||||
},
|
||||
"content_renderer": {
|
||||
"note-cannot-be-displayed": "Acest tip de notiță nu poate fi afișat."
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user