--- title: Repository Definition of Integrated (DoI) --- ```js import {API} from "../components/config.js"; ``` ```js import {marked} from "npm:marked"; const _resp = await fetch(`${API}/policy/repo-doi`); if (!_resp.ok) throw new Error(`Failed to load policy: ${_resp.status}`); const _policy = await _resp.json(); ``` ```js let _content = _policy.content; let _editing = false; const _root = display(html`
`); async function _save(text) { const r = await fetch(`${API}/policy/repo-doi`, { method: "PUT", headers: {"Content-Type": "application/json"}, body: JSON.stringify({content: text}), }); if (!r.ok) throw new Error(`Save failed: ${r.status}`); _content = text; } function _toolbar(...nodes) { return html`
${nodes}
`; } function _btn(label, primary = false) { return html``; } function _render() { _root.innerHTML = ""; if (_editing) { const area = html``; const saveBtn = _btn("Save", true); const cancelBtn = _btn("Cancel"); saveBtn.onclick = async () => { saveBtn.disabled = true; saveBtn.textContent = "Saving…"; try { await _save(area.value); _editing = false; _render(); } catch (e) { saveBtn.disabled = false; saveBtn.textContent = "Save"; alert(e.message); } }; cancelBtn.onclick = () => { _editing = false; _render(); }; _root.append(_toolbar(saveBtn, cancelBtn), area); } else { const editBtn = _btn("Edit"); editBtn.onclick = () => { _editing = true; _render(); }; const body = html`
`; body.innerHTML = marked.parse(_content); _root.append(_toolbar(editBtn), body); } } _render(); ```