html-ui.commit-script
As of snapshot FWBeS680eO. See the latest
- description
- The JS of the edit page: shows the diff from the part as it was (html-ui.line-diff-script), checks the change with the type checker without committing (check: true, also Ctrl/Cmd+Enter) and commits it with POST /api/commit
- type
String
- expression
"const out = document.getElementById(\"out\");\nconst show = (text, error) => {\n out.textContent = text;\n out.className = error ? \"error\" : \"\";\n};\nconst form = document.getElementById(\"edit-form\");\nconst field = (name) => form.elements.namedItem(name);\nconst languages = [\"en\", \"ja\", \"eo\"];\nconst snapshot = () =>\n [\n \"visibility: \" + field(\"visibility\").value,\n ...languages.map((l) => \"description (\" + l + \"): \" + field(\"description_\" + l).value.trim()),\n \"\",\n \"type:\",\n field(\"type\").value,\n \"\",\n \"expression:\",\n field(\"expression\").value,\n ].join(\"\\n\");\nconst original = form.dataset.exists === \"1\" ? snapshot() : \"\";\nconst diff = document.getElementById(\"diff\");\nconst updateDiff = () => renderLineDiff(diff, original, snapshot());\nlet timer;\nform.addEventListener(\"input\", () => {\n clearTimeout(timer);\n timer = setTimeout(updateDiff, 300);\n});\nupdateDiff();\nconst send = async (check, button) => {\n button.disabled = true;\n try {\n const d = form.dataset;\n const name = field(\"part_name\").value.trim() || d.part;\n const renamed = name !== d.part && d.exists === \"1\";\n const descriptions = {};\n for (const l of languages) descriptions[l] = field(\"description_\" + l).value.trim();\n const change = {\n part: name,\n type: field(\"type\").value,\n expression: field(\"expression\").value,\n visibility: field(\"visibility\").value,\n descriptions,\n };\n const changes = renamed ? [change, { part: d.part, delete: true }] : [change];\n show(document.documentElement.dataset.busy);\n const response = await fetch(\"/api/commit\", {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n project: d.project,\n branch: d.branch,\n message: field(\"message\").value || (renamed ? \"Rename \" + d.part + \" to \" + name : \"Change \" + name),\n changes,\n check,\n }),\n });\n const text = await response.text();\n if (!response.ok) {\n let message = text;\n try {\n message = JSON.parse(text).message ?? text;\n } catch {}\n throw new Error(message);\n }\n if (check) {\n show(d.checkOk);\n return;\n }\n show(text);\n location.href = \"/p/\" + encodeURIComponent(d.project) + \"/\" + encodeURIComponent(d.branch) + \"/\" + encodeURIComponent(name);\n } catch (err) {\n show(String(err.message ?? err), true);\n } finally {\n button.disabled = false;\n }\n};\nform.addEventListener(\"submit\", (e) => {\n e.preventDefault();\n send(false, form.querySelector(\"button[type=submit]\"));\n});\ndocument.getElementById(\"check-button\").addEventListener(\"click\", (e) => send(true, e.currentTarget));\ndocument.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Enter\" && (e.ctrlKey || e.metaKey) && form.contains(document.activeElement)) {\n e.preventDefault();\n send(true, document.getElementById(\"check-button\"));\n }\n});\n"- visibility
- public
html-ui.commit-script (project html-ui, branch edit-check, snapshot FWBeS680eOlm6c2NOnWcarkR0iM2Jt6ap5-Rv0zDiXk) id: __r9EoTNkA2kljbVYGBmBTs1u9AQZ2N8o_49zzw3I5g content hash: OoV4RuMik7MAFB69FWovb3QxFFLdFiz5xWXKDebOWZY