import AbstractSearchOption from "./abstract_search_option.js"; import noteAutocompleteService from "../../services/note_autocomplete.js"; import { t } from "../../services/i18n.js"; const TPL = ` ${t('search_script.title')}
`; export default class SearchScript extends AbstractSearchOption { static get optionName() { return "searchScript" }; static get attributeType() { return "relation" }; static async create(noteId) { await AbstractSearchOption.setAttribute(noteId, 'relation', 'searchScript', 'root'); } doRender() { const $option = $(TPL); const $searchScript = $option.find('.search-script'); noteAutocompleteService.initNoteAutocomplete($searchScript, {allowCreatingNotes: true}); $searchScript.on('autocomplete:closed', async () => { const searchScriptNoteId = $searchScript.getSelectedNoteId(); if (searchScriptNoteId) { await this.setAttribute('relation', 'searchScript', searchScriptNoteId); } }); const searchScriptNoteId = this.note.getRelationValue('searchScript'); if (searchScriptNoteId !== 'root') { $searchScript.setNote(searchScriptNoteId); } return $option; } }