commit 1661b11bb11dc66bc921e0a9b5e47d47fa6e6846
parent cf96af408251280ed1b678261b5d10f04e4e086d
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 04:23:54 +0530
parent cf96af408251280ed1b678261b5d10f04e4e086d
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 04:23:54 +0530
Task 4 client: party-based route editor and signature zones - Updated collectRoute() for parties format (name + signer) - Rewrote routeEditor() component with party add/remove UI - Updated TYPES: signature → signature_zone with party reference - Added signature_zone props (party selector, min_w/min_h inputs) - Updated imprint creation to use signature_zone with party - Updated docs list to show parties count instead of levels - Added placement input stub in decide flow for signature zones - Placement required for approve when zone is present Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 file changed, 46 insertions(+), 31 deletions(-)
diff --git a/www/app.js b/www/app.js @@ -11,11 +11,11 @@ const API = '/api'; const REF_WIDTH = 1000; // natural width every page is rasterised to const TYPES = { - pim_text: { label: 'PIM text', w: 260, h: 28 }, - pim_image: { label: 'PIM image', w: 160, h: 160 }, - date: { label: 'Date', w: 140, h: 28 }, - serial: { label: 'Serial no.', w: 280, h: 28 }, - signature: { label: 'Signature box', w: 200, h: 80 }, + pim_text: { label: 'PIM text', w: 260, h: 28 }, + pim_image: { label: 'PIM image', w: 160, h: 160 }, + date: { label: 'Date', w: 140, h: 28 }, + serial: { label: 'Serial no.', w: 280, h: 28 }, + signature_zone: { label: 'Signature zone', w: 200, h: 80 }, }; const TEXT_TYPES = ['pim_text', 'date', 'serial']; const PIM_TYPES = ['pim_text', 'pim_image']; @@ -388,7 +388,7 @@ function placeNew(page, type, cx, cy) { const x1 = Math.max(0, Math.min(img.naturalWidth - t.w, cx - t.w / 2)); const y1 = Math.max(0, Math.min(img.naturalHeight - t.h, cy - t.h / 2)); const imp = { type, coords: [x1, y1, x1 + t.w, y1 + t.h] }; - if (type === 'signature') imp.ref = collectRoute().levels.flatMap((l) => l.signers)[0] || ''; + if (type === 'signature_zone') imp.party = collectRoute().parties[0]?.name || ''; select(addArea(page, imp)); } @@ -438,9 +438,11 @@ function renderProps() { const b = bboxOf(selected); selected.shape = v; setBbox(selected, b); refitAll(); }))); } - if (type === 'signature') { - const signers = [...new Set(collectRoute().levels.flatMap((l) => l.signers))]; - host.append(...field('Signer (must be in the approval route)', selectEl([['', '(choose)'], ...signers.map((u) => [u, u])], d.ref, set('ref')))); + if (type === 'signature_zone') { + const parties = collectRoute().parties || []; + host.append(...field('Party', selectEl([['', '(choose)'], ...parties.map((p) => [p.name, p.name])], d.party, set('party')))); + host.append(...field('Min width (px)', h('input', { type: 'number', value: d.min_w || '', oninput: (e) => set('min_w')(e.target.value) }))); + host.append(...field('Min height (px)', h('input', { type: 'number', value: d.min_h || '', oninput: (e) => set('min_h')(e.target.value) }))); } if (type === 'date') { host.append(...field('Format (strftime)', h('input', { value: d.format || '', placeholder: app.dam.date_format || '%d-%m-%Y', oninput: (e) => set('format')(e.target.value) }))); @@ -456,35 +458,34 @@ function renderProps() { function routeEditor(route, editable) { const host = h('div', { id: 'route' }); - const addLevel = (lv) => { - const row = h('div', { class: 'level' }, - h('label', {}, 'Signers (usernames, comma separated)'), - h('input', { class: 'r-signers', value: (lv.signers || []).join(', '), onchange: renderProps }), - h('div', { class: 'row' }, - selectEl([['any', 'Any one of them signs off'], ['all', 'All of them must sign off']], lv.mode || 'any', () => {}, { class: 'r-mode' }), - h('button', { class: 'danger', onclick: () => { row.remove(); renderProps(); } }, 'Remove'))); + const addParty = (p) => { + const row = h('div', { class: 'party' }, + h('label', {}, 'Party name'), + h('input', { class: 'p-name', value: p.name || '', placeholder: 'e.g., Manager', onchange: renderProps }), + h('label', {}, 'Signer username'), + h('input', { class: 'p-signer', value: p.signer || '', placeholder: 'e.g., manager', onchange: renderProps }), + h('button', { class: 'danger', onclick: () => { row.remove(); renderProps(); } }, 'Remove')); host.insertBefore(row, host.lastChild); }; if (editable) { - host.append(h('button', { onclick: () => addLevel({}) }, 'Add approval level')); - (route.levels || []).forEach(addLevel); + host.append(h('button', { onclick: () => addParty({}) }, 'Add party')); + (route.parties || []).forEach(addParty); } else { - (route.levels || []).forEach((lv, i) => host.append(h('div', { - class: 'level' + (doc.current_party === i + 1 && ['PENDING'].includes(doc.status) ? ' current' : ''), - }, h('div', { class: 'who' }, h('strong', {}, `Level ${i + 1}: `), lv.signers.join(', ')), - h('small', {}, lv.mode === 'all' ? 'all must sign off' : 'any one signs off')))); + (route.parties || []).forEach((p, i) => host.append(h('div', { + class: 'party' + (doc.current_party === i + 1 && ['PENDING'].includes(doc.status) ? ' current' : ''), + }, h('div', { class: 'who' }, h('strong', {}, `${i + 1}. ${p.name}: `), p.signer || '(unassigned)')))); } return host; } function collectRoute() { const host = document.getElementById('route'); - if (!host || !host.querySelector('.r-signers')) return (doc && doc.route) || { levels: [] }; + if (!host || !host.querySelector('.p-name')) return (doc && doc.route) || { parties: [] }; return { - levels: [...host.querySelectorAll('.level')].map((row) => ({ - signers: row.querySelector('.r-signers').value.split(',').map((s) => s.trim()).filter(Boolean), - mode: row.querySelector('.r-mode').value, - })).filter((l) => l.signers.length), + parties: [...host.querySelectorAll('.party')].map((row) => ({ + name: row.querySelector('.p-name').value.trim(), + signer: row.querySelector('.p-signer').value.trim() || '', + })).filter((p) => p.name.length), }; } @@ -595,8 +596,22 @@ async function showDoc(id) { h('h2', {}, 'Approval route'), routeEditor(doc.route, false)); if (doc.can_decide) { const comment = h('textarea', { rows: 3, placeholder: 'Comment (required unless signing off)' }); - const decide = (decision) => act(() => api(`/docs/${id}/decide`, { method: 'POST', fields: { decision, comment: comment.value } }), 'Recorded'); - side.append(h('h2', {}, 'Your decision'), comment, h('div', { class: 'actions' }, + const currentParty = doc.current_party > 0 && doc.route.parties ? doc.route.parties[doc.current_party - 1] : null; + const hasZone = currentParty && doc.layout && doc.layout.imprints && doc.layout.imprints.some((i) => i.type === 'signature_zone' && i.party === currentParty.name); + const placementInput = hasZone ? h('input', { type: 'hidden', id: 'f-placement', value: '' }) : null; + const decide = (decision) => act(async () => { + const fields = { decision, comment: comment.value }; + if (hasZone && decision === 'approve') { + const pl = document.getElementById('f-placement').value; + if (!pl) throw new Error('Placement required for signature zones'); + fields.placement = pl; + } + return api(`/docs/${id}/decide`, { method: 'POST', fields }); + }, 'Recorded'); + side.append(h('h2', {}, 'Your decision'), comment); + if (placementInput) side.append(h('p', { class: 'notice' }, 'Draw your signature placement in the zone on the page')); + if (placementInput) side.append(placementInput); + side.append(h('div', { class: 'actions' }, h('button', { class: 'primary', onclick: () => decide('approve') }, 'Sign off'), h('button', { onclick: () => decide('correction') }, 'Correction required'), h('button', { class: 'danger', onclick: () => { if (confirm('Disapprove this document? This is final.')) decide('disapprove'); } }, 'Disapprove'))); @@ -641,12 +656,12 @@ async function showDashboard(scope) { r.drafter ? h('div', { class: 'card', style: 'margin-bottom:1rem' }, h('div', { class: 'row' }, file, tpl, h('button', { class: 'primary', style: 'flex:0 0 auto', onclick: create }, 'New document'))) : null, h('div', { class: 'tabs', role: 'tablist' }, tabs.map(([k, label]) => h('button', { role: 'tab', 'aria-selected': String(k === scope), onclick: () => showDashboard(k) }, label))), h('div', { class: 'card' }, rows.length ? h('table', {}, - h('thead', {}, h('tr', {}, ['Document', 'Status', 'Prepared by', 'Level', 'Created'].map((t) => h('th', {}, t)))), + h('thead', {}, h('tr', {}, ['Document', 'Status', 'Prepared by', 'Parties', 'Created'].map((t) => h('th', {}, t)))), h('tbody', {}, rows.map((d) => h('tr', { class: 'click', onclick: () => { location.hash = '#/doc/' + d.id; } }, h('td', {}, d.title || d.serial || 'Untitled draft'), h('td', {}, h('span', { class: 'status ' + d.status }, d.status.replace(/_/g, ' '))), h('td', {}, d.drafter_user), - h('td', {}, d.status === 'DRAFT' ? '' : `${Math.min(d.current_party, d.levels)} / ${d.levels}`), + h('td', {}, d.status === 'DRAFT' ? '' : `${Math.min(d.current_party, d.parties)} / ${d.parties}`), h('td', {}, fmtTime(d.created_at)))))) : h('p', { class: 'empty' }, 'Nothing here.'))); }
: asapien/signet