import {Dialog} from "../dialog"; import {fetchPost} from "../util/fetch"; import {isMobile} from "../util/functions"; import {escapeHtml} from "../util/escape"; import {writeText} from "../protyle/util/compatibility"; import {showMessage} from "../dialog/message"; import {openModel} from "../mobile/menu/model"; declare interface INotebookConf { name: string, box: string, conf: { refCreateSavePath: string docCreateSavePath: string dailyNoteSavePath: string dailyNoteTemplatePath: string } } export const onGetnotebookconf = (data: INotebookConf) => { const titleHTML = `
${escapeHtml(data.name)}
`; const contentHTML = `
${window.siyuan.languages.fileTree12}
${window.siyuan.languages.fileTree13}
${window.siyuan.languages.fileTree5}
${window.siyuan.languages.fileTree6}
${window.siyuan.languages.fileTree11}
${window.siyuan.languages.fileTree14}
${window.siyuan.languages.fileTree15}
`; let contentElement; if (isMobile()) { openModel({ title: titleHTML, icon: "iconSettings", html: `
${contentHTML}
`, bindEvent() { bindSettingEvent(document.querySelector("#model"), data); } }); } else { const dialog = new Dialog({ width: "80vw", title: titleHTML, content: contentHTML }); contentElement = dialog.element; bindSettingEvent(contentElement, data); } }; const bindSettingEvent = (contentElement: Element, data: INotebookConf) => { contentElement.querySelector(".b3-button--small").addEventListener("click", () => { writeText(data.box); showMessage(window.siyuan.languages.copied); }); const dailyNoteSavePathElement = contentElement.querySelector("#dailyNoteSavePath") as HTMLInputElement; dailyNoteSavePathElement.value = data.conf.dailyNoteSavePath; const docCreateSavePathElement = contentElement.querySelector("#docCreateSavePath") as HTMLInputElement; docCreateSavePathElement.value = data.conf.docCreateSavePath; const refCreateSavePathElement = contentElement.querySelector("#refCreateSavePath") as HTMLInputElement; refCreateSavePathElement.value = data.conf.refCreateSavePath; const dailyNoteTemplatePathElement = contentElement.querySelector("#dailyNoteTemplatePath") as HTMLInputElement; dailyNoteTemplatePathElement.value = data.conf.dailyNoteTemplatePath; contentElement.querySelectorAll("input").forEach((item) => { item.addEventListener("change", () => { fetchPost("/api/notebook/setNotebookConf", { notebook: data.box, conf: { refCreateSavePath: refCreateSavePathElement.value, docCreateSavePath: docCreateSavePathElement.value, dailyNoteSavePath: dailyNoteSavePathElement.value, dailyNoteTemplatePath: dailyNoteTemplatePathElement.value, } }); }); }); };