import AbstractSearchOption from "./abstract_search_option.js"; import noteAutocompleteService from "../../services/note_autocomplete.js"; import { t } from "../../services/i18n.js"; const TPL = `
${t("ancestor.label")}:
${t("ancestor.depth_label")}:
`; export default class Ancestor extends AbstractSearchOption { static get optionName() { return "ancestor"; } static get attributeType() { return "relation"; } static async create(noteId) { await AbstractSearchOption.setAttribute(noteId, "relation", "ancestor", "root"); } doRender() { const $option = $(TPL); const $ancestor = $option.find(".ancestor"); const $ancestorDepth = $option.find(".ancestor-depth"); noteAutocompleteService.initNoteAutocomplete($ancestor); $ancestor.on("autocomplete:closed", async () => { const ancestorNoteId = $ancestor.getSelectedNoteId(); if (ancestorNoteId) { await this.setAttribute("relation", "ancestor", ancestorNoteId); } }); $ancestorDepth.on("change", async () => { const ancestorDepth = $ancestorDepth.val(); if (ancestorDepth) { await this.setAttribute("label", "ancestorDepth", ancestorDepth); } else { await this.deleteAttribute("label", "ancestorDepth"); } }); const ancestorNoteId = this.note.getRelationValue("ancestor"); if (ancestorNoteId !== "root") { $ancestor.setNote(ancestorNoteId); } const ancestorDepth = this.note.getLabelValue("ancestorDepth"); if (ancestorDepth) { $ancestorDepth.val(ancestorDepth); } return $option; } async deleteOption() { await this.deleteAttribute("label", "ancestorDepth"); await super.deleteOption(); } }