Sha256: 8a7e802e7ede545d6d217c0dc3babeae47e5692f9691be0d24c5db83c790bfb8
Contents?: true
Size: 1.67 KB
Versions: 10
Compression:
Stored size: 1.67 KB
Contents
// Choose a Proposal Answer template, get it by AJAX and add the Template in the Proposal Answer textarea document.addEventListener("DOMContentLoaded", () => { const proposalAnswerTemplateChooser = document.getElementById("proposal_answer_template_chooser"); if (proposalAnswerTemplateChooser) { proposalAnswerTemplateChooser.addEventListener("change", () => { const dropdown = document.getElementById("proposal_answer_template_chooser"); const url = dropdown.getAttribute("data-url"); const templateId = dropdown.value; const proposalId = dropdown.dataset.proposal; if (templateId === "") { return; } fetch(`${new URL(url).pathname}?${new URLSearchParams({ id: templateId, proposalId: proposalId })}`). then((response) => { if (response.ok) { return response.json(); } return Promise.reject(response); }). then((data) => { document.getElementById(`proposal_answer_internal_state_${data.state}`).click(); let editorContainer = null; for (const [key, value] of Object.entries(data.template)) { editorContainer = document.querySelector(`[name="proposal_answer[answer_${key}]"]`).nextElementSibling; let editor = editorContainer.querySelector(".ProseMirror").editor; editor.commands.setContent(value, true); } }). catch((response) => { response.json().then((data) => { const el = document.createElement("p"); el.classList.add("text-alert"); el.textContent = data.msg; dropdown.after(el); }); }); }); } });
Version data entries
10 entries across 10 versions & 1 rubygems