Agreements the client signs on the link (task 7.6)
CI / secret scan (push) Successful in 6s
CI / fmt, clippy, tests (push) Successful in 1m0s
CI / release (push) Skipped

Built into the app rather than a separate signing service: any number of
agreements (the processing of the client's data first, legal services
and consultations later), each in versions whose text never changes.

- Staff (Agreements in the sidebar, src/web/agreements.rs): paste the
  lawyers' text (empty line = paragraph, "# " heading, "- " list item),
  preview it as the client reads it, publish version 1; a changed text is
  the next version, the same text again is refused, and the database
  refuses any change to a published one (migrations/0007, trigger).
  Switch an agreement off and links stop asking for it.
- Client: every active agreement is the first step of every link. The
  client reads it, ticks that they accept, types their name and signs
  with a finger or the mouse (static/signature.js; a PNG of the pad). A
  text changed while they read it is refused. A new version is asked for
  again at the next link.
- The signed copy (src/agreements/pdf.rs, Sarabun so Thai prints, long
  Thai words cut without parting marks from their letter): the text, the
  name, the record, the time, the drawing, the link, the forwarded
  address, the browser and the text's SHA-256; kept as the person's
  encrypted document of kind "agreement", all in one transaction with the
  signature and the audit rows (actor link N).
- The person's page shows each agreement's state (signed, not signed, to
  sign again) and every signed copy.
- Phones: the section row now scrolls sideways instead of wrapping, so it
  keeps one height with five sections and Sign out.
- Demo data: an invented agreement with a Thai paragraph.

Checks: fmt, clippy; 105 unit and 56 integration tests (tests/agreements.rs:
versions that never change, signing with a drawing, address and browser
recorded, the PDF, signing again after a change, a stale version refused,
switched off); layout check light/dark desk/phone on the agreement pages,
the client's agreement page, the person page and the people list: no
problems; a drawn signature in Edge at 390x844 signed and printed.
This commit is contained in:
grabowski committed 2026-11-20 20:18:59 +07:00
1 parent 43ed75d81b
commit d0e13dffd2
28 files changed
+2469 -57

No files matched your search

+93 -2
View File
@@ -1237,13 +1237,24 @@ textarea.mrz {
border-right: 0;
border-bottom: 1px solid var(--line);
}
/* one row that scrolls sideways when the sections do not fit, so it
keeps its height and place on every page */
.nav {
flex-direction: row;
flex-wrap: wrap;
flex-wrap: nowrap;
flex: 1 1 auto;
min-width: 0;
overflow-x: auto;
scrollbar-width: none;
}
.nav::-webkit-scrollbar {
display: none;
}
.nav a {
padding: 6px 9px;
padding: 6px 8px;
font-size: 14px;
white-space: nowrap;
flex: 0 0 auto;
}
.who {
margin: 0 0 0 auto;
@@ -1501,3 +1512,83 @@ textarea.mrz {
.cmain .upload .drop {
margin-bottom: 4px;
}
/* ---- agreements: the text as clients read it, the signature pad */
.agtext h3 {
margin: 16px 0 6px;
font-size: 16px;
color: var(--hd);
}
.agtext h3:first-child {
margin-top: 0;
}
.agtext p,
.agtext li {
line-height: 1.55;
}
.agtext p {
margin: 0 0 10px;
}
.agtext ul {
margin: 0 0 10px;
padding-left: 22px;
}
.agcard {
max-height: 60vh;
overflow-y: auto;
}
.agcols {
grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}
@media (max-width: 1060px) {
.agcols {
grid-template-columns: minmax(0, 1fr);
}
}
.agrow {
flex-wrap: wrap;
margin-bottom: 8px;
}
label.check {
display: flex;
gap: 10px;
align-items: flex-start;
font-weight: 600;
}
label.check input {
width: auto;
margin-top: 3px;
flex: 0 0 auto;
}
.sigpad {
display: block;
width: 100%;
height: 170px;
border: 1px dashed var(--stroke);
border-radius: 8px;
background: #ffffff;
touch-action: none;
cursor: crosshair;
}
.sigbar {
display: flex;
gap: 12px;
align-items: center;
margin-top: 6px;
}
#sign-form h2 {
margin-top: 0;
}
#sign-form .field {
margin-bottom: 14px;
}
/* a version's SHA-256 breaks anywhere rather than widening the page */
#versions .mono {
overflow-wrap: anywhere;
}
@media (max-width: 420px) {
.nav a {
padding: 6px 6px;
font-size: 13px;
}
}
+9
View File
@@ -18,6 +18,15 @@
}
});
// ---- on phones the sections scroll sideways: the current one in view
document.addEventListener("DOMContentLoaded", function () {
var nav = document.querySelector(".nav");
var on = nav && nav.querySelector("a.on");
if (on && nav.scrollWidth > nav.clientWidth) {
nav.scrollLeft = Math.max(0, on.offsetLeft - nav.offsetLeft - 24);
}
});
// ---- a button with data-copy="#input" copies that input's text (the
// client link); a field with data-select-all selects itself when focused
document.addEventListener("click", function (ev) {
+92
View File
@@ -0,0 +1,92 @@
// The signature pad of an agreement on the client's link: drawn with a
// finger, a pen or the mouse, sent as a PNG in the hidden field `drawing`.
// Without JavaScript the pad stays hidden and the typed name signs alone.
(function () {
"use strict";
function setup(form) {
var wrap = form.querySelector("[data-sign-wrap]");
var pad = form.querySelector("[data-sign-pad]");
var out = form.querySelector("[data-sign-out]");
var msg = form.querySelector("[data-sign-msg]");
if (!wrap || !pad || !out || !pad.getContext) return;
wrap.hidden = false;
var ctx = pad.getContext("2d");
var drawn = false;
var last = null;
// the canvas in device pixels; a resize clears it, as the strokes no
// longer fit
function size() {
var r = pad.getBoundingClientRect();
var dpr = Math.min(window.devicePixelRatio || 1, 3);
pad.width = Math.max(1, Math.round(r.width * dpr));
pad.height = Math.max(1, Math.round(r.height * dpr));
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.lineWidth = 2.4;
ctx.strokeStyle = "#071323";
drawn = false;
out.value = "";
}
function at(ev) {
var r = pad.getBoundingClientRect();
return { x: ev.clientX - r.left, y: ev.clientY - r.top };
}
pad.addEventListener("pointerdown", function (ev) {
ev.preventDefault();
pad.setPointerCapture(ev.pointerId);
last = at(ev);
ctx.beginPath();
ctx.arc(last.x, last.y, 1.1, 0, 2 * Math.PI);
ctx.fillStyle = "#071323";
ctx.fill();
drawn = true;
if (msg) msg.hidden = true;
});
pad.addEventListener("pointermove", function (ev) {
if (!last) return;
ev.preventDefault();
var p = at(ev);
ctx.beginPath();
ctx.moveTo(last.x, last.y);
ctx.lineTo(p.x, p.y);
ctx.stroke();
last = p;
});
function end() {
last = null;
}
pad.addEventListener("pointerup", end);
pad.addEventListener("pointercancel", end);
form.querySelector("[data-sign-clear]").addEventListener("click", function () {
ctx.clearRect(0, 0, pad.width, pad.height);
drawn = false;
out.value = "";
});
form.addEventListener("submit", function (ev) {
if (!drawn) {
ev.preventDefault();
if (msg) msg.hidden = false;
pad.scrollIntoView({ block: "center" });
return;
}
out.value = pad.toDataURL("image/png");
});
var width = 0;
window.addEventListener("resize", function () {
var w = pad.getBoundingClientRect().width;
if (Math.abs(w - width) > 2) {
width = w;
size();
}
});
width = pad.getBoundingClientRect().width;
size();
}
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll("form[data-sign-form]").forEach(setup);
});
})();