oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1// The Housekeeping view without reloads. It is a live region:
2// nav-stream.js hears housekeeping, task and card events and
3// work-stream.js renders the view again and swaps it in place. Its forms
4// (Undo, a detector's switch) post in the background; the event their
5// change writes brings the new view. Without scripts they post as usual.
6(function () {
7 "use strict";
8 if (!document.querySelector("[data-housekeeping]") || !window.fetch || !window.FormData || !window.URLSearchParams) return;
9 function work() {
10 document.dispatchEvent(new CustomEvent("equipo:work", { detail: { type: "housekeeping" } }));
11 }
12 document.addEventListener("submit", function (e) {
13 var form = e.target;
14 if (!form.closest || !form.closest("[data-housekeeping]")) return;
15 e.preventDefault();
16 var button = form.querySelector("button");
17 if (button) button.disabled = true;
18 fetch(form.action, { method: "POST", credentials: "same-origin", headers: { "Accept": "application/json" }, body: new URLSearchParams(new FormData(form)) })
19 .then(function (r) { if (!r.ok) throw new Error("post"); })
20 .then(function () {
21 // Out of the form, so the swap is not held for it.
22 if (document.activeElement && document.activeElement.blur) document.activeElement.blur();
23 work();
24 })
25 .catch(function () { form.submit(); });
26 });
27})();
28