Explorer

html-ui.commit-script

description
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\");\nform.addEventListener(\"submit\", async (e) => {\n  e.preventDefault();\n  const button = form.querySelector(\"button\");\n  button.disabled = true;\n  try {\n    const d = form.dataset;\n    const name = form.elements.namedItem(\"part_name\").value.trim() || d.part;\n    const renamed = name !== d.part && d.exists === \"1\";\n    const change = { part: name, type: form.type.value, expression: form.expression.value };\n    if (form.description.value.trim() !== \"\") change.description = form.description.value;\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: form.message.value || (renamed ? \"Rename \" + d.part + \" to \" + name : \"Change \" + name),\n        changes,\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    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});\n"
visibility
public
html-ui.commit-script (project html-ui, branch markdown-project, snapshot 4WqgepyAqfURI69jsEEgbpnDsGuVnu6jnmIYuF_IYcs)
id: __r9EoTNkA2kljbVYGBmBTs1u9AQZ2N8o_49zzw3I5g
content hash: LS1ux6Ppk1yc0gBDm2Kmu10pkAWeurJJqk52EagBZmY