@floless/app 0.159.0 → 0.161.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/floless-server.cjs +76823 -65608
- package/dist/schemas/steel.model.v2.schema.json +24 -0
- package/dist/skills/floless-app-onboarding/SKILL.md +4 -3
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +1 -2
- package/dist/skills/floless-app-rfi/SKILL.md +44 -3
- package/dist/skills/floless-app-steel-model/SKILL.md +2 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +417 -261
- package/dist/templates/steel-model.flo +6 -2
- package/dist/templates/viewer-3d-demo.flo +8 -2
- package/dist/web/app.css +342 -160
- package/dist/web/app.js +17 -51
- package/dist/web/aware.js +656 -574
- package/dist/web/chat-question-card.js +27 -1
- package/dist/web/chat.css +185 -30
- package/dist/web/chat.js +2099 -255
- package/dist/web/commands-drawing-check.js +1 -0
- package/dist/web/commands-filter.js +11 -0
- package/dist/web/commands-shell.js +1118 -134
- package/dist/web/commands-steel.js +41 -38
- package/dist/web/drawing-check-editor.js +76 -3
- package/dist/web/guide.js +8 -0
- package/dist/web/index.html +68 -42
- package/dist/web/instructor.js +17 -6
- package/dist/web/pages.js +158 -30
- package/dist/web/panels.js +19 -1
- package/dist/web/project-history.js +349 -0
- package/dist/web/project-reconciliation.js +1 -0
- package/dist/web/project-rfis.js +954 -0
- package/dist/web/project-workflows.js +236 -4
- package/dist/web/run-history.js +198 -0
- package/dist/web/run-page-view.js +12 -2
- package/dist/web/startup-admission.js +53 -7
- package/dist/web/steel-3d-core.js +144 -7
- package/dist/web/steel-3d-view.js +61 -5
- package/dist/web/steel-editor.html +510 -128
- package/dist/web/steel-filter.html +139 -0
- package/dist/web/steel-model-v2-commands.js +3 -3
- package/dist/web/steel-model-v2-projection.js +139 -4
- package/dist/web/steel-plan-transform.js +78 -0
- package/dist/web/tool-updates.js +5 -0
- package/dist/web/workspaces.js +1438 -159
- package/launch.mjs +36 -5
- package/package.json +7 -4
|
@@ -0,0 +1,954 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A General project's RFIs step (#2470 R6.6): the project's questions for the engineer, client or architect. Each RFI
|
|
3
|
+
* may cite a page of this project's Knowledge or a saved sheet of a project linked on its Modules step; FloLess sends
|
|
4
|
+
* it through the connected Gmail account (R6.6b, the same delivery engine as Steel's) or gives the email text for the
|
|
5
|
+
* person to send, and keeps what was sent, answered and closed.
|
|
6
|
+
*
|
|
7
|
+
* It renders GET /api/projects/:id/correspondence-rfis and changes RFIs only through that route family. Every write
|
|
8
|
+
* names the Workspace and project it was shown (rootId + project uuid from the read). Specs:
|
|
9
|
+
* docs/superpowers/specs/2026-10-23-2470-r6-6-rfis-tab-PLAN.md and 2026-10-26-2470-r6-6b-general-rfis-gmail-PLAN.md (§6).
|
|
10
|
+
*/
|
|
11
|
+
(() => {
|
|
12
|
+
const bridge = () => window.flolessBridge || {};
|
|
13
|
+
const api = (path, init) => {
|
|
14
|
+
if (typeof bridge().api === 'function') return bridge().api(path, init);
|
|
15
|
+
return fetch(path, { headers: { 'Content-Type': 'application/json' }, ...init }).then(async (res) => {
|
|
16
|
+
const body = await res.json().catch(() => ({}));
|
|
17
|
+
if (!res.ok || body.ok === false) { const err = new Error(body.error || `HTTP ${res.status}`); err.status = res.status; err.body = body; throw err; }
|
|
18
|
+
return body;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
22
|
+
const toast = (msg, kind, options) => (typeof window.showToast === 'function' ? window.showToast(msg, kind, options) : null);
|
|
23
|
+
const said = (error, fallback) => (typeof error?.body?.error === 'string' && error.body.error ? error.body.error : fallback);
|
|
24
|
+
/** A refusal the server wrote (a 4xx with a sentence) — as opposed to an outcome nobody confirmed. */
|
|
25
|
+
const refused = (error) => !!error?.status && error.status >= 400 && error.status < 500 && typeof error?.body?.error === 'string';
|
|
26
|
+
const newKey = () => `rfi-${crypto.randomUUID()}`;
|
|
27
|
+
const MAX_CITES = 5;
|
|
28
|
+
const isAddress = (s) => /^[^\s@<>()",;:]+@[^\s@<>()",;:]+\.[^\s@<>()",;:]+$/.test(String(s || '').trim());
|
|
29
|
+
|
|
30
|
+
// ── Gmail (#2470 R6.6b): readiness, and what each send state says (Steel's meaning, the step's words) ──────────────
|
|
31
|
+
|
|
32
|
+
const READINESS_TEXT = {
|
|
33
|
+
'connect-google': 'Connect Google Workspace in Integrations before sending from FloLess.',
|
|
34
|
+
'update-aware': 'Update AWARE before sending from FloLess.',
|
|
35
|
+
'update-agent': 'Update the Google Workspace integration before sending from FloLess.',
|
|
36
|
+
'fix-google-access': 'Reconnect Google Workspace with Gmail send access in Integrations.',
|
|
37
|
+
busy: 'Gmail sending is busy with another request. Try again when it finishes.',
|
|
38
|
+
unavailable: 'FloLess couldn’t check the connected Google account just now.',
|
|
39
|
+
};
|
|
40
|
+
/** Readiness that a retry may fix: the person can still try to send beside the sentence. */
|
|
41
|
+
const TRANSIENT = new Set(['busy', 'unavailable']);
|
|
42
|
+
/** Readiness whose fix is in Integrations. */
|
|
43
|
+
const FIX_IN_INTEGRATIONS = new Set(['connect-google', 'fix-google-access', 'update-agent']);
|
|
44
|
+
const readinessText = (r) => (r?.status === 'loading' ? 'Checking the connected Google account…'
|
|
45
|
+
: r?.status === 'ready' ? '' : (r?.message || READINESS_TEXT[r?.status] || 'Gmail sending isn’t available just now.'));
|
|
46
|
+
const unresolved = (d) => d && (d.status === 'prepared' || d.status === 'outcome-unknown');
|
|
47
|
+
const HELD = 'Mark sent, Answer and Close are held back until this is settled, so the RFI’s history stays true.';
|
|
48
|
+
|
|
49
|
+
function ago(iso, now = Date.now()) {
|
|
50
|
+
const t = Date.parse(iso);
|
|
51
|
+
if (!Number.isFinite(t)) return '';
|
|
52
|
+
const m = Math.round(Math.max(0, now - t) / 60000);
|
|
53
|
+
if (m < 1) return 'just now';
|
|
54
|
+
if (m < 60) return `${m} min ago`;
|
|
55
|
+
const h = Math.round(m / 60);
|
|
56
|
+
if (h < 24) return `${h} h ago`;
|
|
57
|
+
const d = Math.round(h / 24);
|
|
58
|
+
return d === 1 ? 'yesterday' : `${d} days ago`;
|
|
59
|
+
}
|
|
60
|
+
const exact = (iso) => { const t = Date.parse(iso); return Number.isFinite(t) ? new Date(t).toLocaleString() : ''; };
|
|
61
|
+
|
|
62
|
+
const STATUS = { open: 'Open', sent: 'Sent', answered: 'Answered', closed: 'Closed' };
|
|
63
|
+
const DISPOSITIONS = [
|
|
64
|
+
{ key: 'answered', label: 'Answered', help: 'The question was answered.' },
|
|
65
|
+
{ key: 'withdrawn', label: 'Withdrawn', help: 'You no longer need an answer.' },
|
|
66
|
+
{ key: 'superseded', label: 'Superseded', help: 'A newer RFI replaces this one.' },
|
|
67
|
+
{ key: 'wont-fix', label: 'Won’t fix', help: 'It won’t be acted on.' },
|
|
68
|
+
];
|
|
69
|
+
const dispositionLabel = (key) => DISPOSITIONS.find((d) => d.key === key)?.label || key;
|
|
70
|
+
|
|
71
|
+
/** How a citation's state reads on its chip and in its tip (the server's reason first, when it gave one). */
|
|
72
|
+
const CITE_STATE = {
|
|
73
|
+
current: { word: '', tip: 'Still matches what was cited.' },
|
|
74
|
+
changed: { word: 'changed', tip: 'This page was re-published with other text. The RFI keeps the text as it was when you cited it.' },
|
|
75
|
+
unavailable: { word: 'unavailable', tip: 'That version of the page is gone, or it was cited in another project (this RFI was copied).' },
|
|
76
|
+
'link-removed': { word: 'link removed', tip: 'This project no longer links to that project. Link it again on the Modules step to check this sheet.' },
|
|
77
|
+
'project-unavailable': { word: 'project unavailable', tip: 'The linked project can’t be read just now.' },
|
|
78
|
+
'sheet-missing': { word: 'sheet not found', tip: 'The linked project has no saved sheet matching this one. It may have been re-saved or removed.' },
|
|
79
|
+
'sheet-ambiguous': { word: 'sheet unclear', tip: 'The linked project has two saved sheets that match, so FloLess can’t tell which was meant.' },
|
|
80
|
+
'sheet-unusable': { word: 'sheet unreadable', tip: 'FloLess couldn’t read this sheet just now.' },
|
|
81
|
+
detached: { word: 'from a copy', tip: 'This came with a copy of the project and is not checked against the current links. File it again to cite a sheet here.' },
|
|
82
|
+
'not-checked': { word: 'not checked', tip: 'Not looked at from this chat.' },
|
|
83
|
+
};
|
|
84
|
+
const citeLabel = (c) => (c.kind === 'knowledge-page' ? `Knowledge · ${c.title}` : `Drawing · ${c.sheet} · ${c.linkedProjectName}`);
|
|
85
|
+
function chipHtml(c) {
|
|
86
|
+
const st = CITE_STATE[c.state] || CITE_STATE.current;
|
|
87
|
+
const word = st.word ? ` · ${st.word}` : '';
|
|
88
|
+
return `<span class="pw-chip pr-cite${st.word ? ' is-muted' : ''}" role="listitem" tabindex="0" data-tip="${esc(c.reason || st.tip)}">${esc(citeLabel(c))}${esc(word)}</span>`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ── the step ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
92
|
+
|
|
93
|
+
let state = null; // { pane, project, generation, view, filter, form, drafts, inflight, again, focusAfter }
|
|
94
|
+
const ownChild = (pane, cls) => [...pane.children].find((el) => el.classList.contains(cls)) || null;
|
|
95
|
+
const announce = (text) => { const live = state && ownChild(state.pane, 'pr-live'); if (live) live.textContent = text; };
|
|
96
|
+
const target = () => {
|
|
97
|
+
const d = state?.view?.data;
|
|
98
|
+
return d ? { rootId: d.rootId, projectUuid: d.project.uuid, projectId: d.project.id, name: d.project.name } : null;
|
|
99
|
+
};
|
|
100
|
+
const identity = () => { const t = target(); return { expectedRootId: t.rootId, expectedProjectUuid: t.projectUuid }; };
|
|
101
|
+
|
|
102
|
+
const visible = (rfis, filter) => rfis.filter((r) => (filter === 'all' ? true : filter === 'closed' ? r.status === 'closed' : r.status !== 'closed'));
|
|
103
|
+
|
|
104
|
+
/** One inline verb form (one open at a time; its text survives a repaint). */
|
|
105
|
+
function formHtml(rfi, form) {
|
|
106
|
+
const id = esc(rfi.id);
|
|
107
|
+
const draft = form.draft || {};
|
|
108
|
+
const busy = form.busy ? ' disabled' : '';
|
|
109
|
+
// While FloLess can't confirm a save, the form is frozen: Try again resends exactly what was sent, and Edit makes it a new change.
|
|
110
|
+
const ro = form.uncertain ? ' readonly' : '';
|
|
111
|
+
const alert = form.error ? `<p class="pm-note pr-alert" role="alert">${esc(form.error)}</p>` : '';
|
|
112
|
+
const uncertain = form.uncertain ? '<p class="pm-note pr-alert" role="alert">FloLess couldn’t confirm that was saved. Try again sends the same thing again, and it can’t be saved twice. To change it, choose Edit.</p>' : '';
|
|
113
|
+
let fields = '';
|
|
114
|
+
let primary = '';
|
|
115
|
+
switch (form.verb) {
|
|
116
|
+
case 'mark-sent':
|
|
117
|
+
fields = `<label class="pr-field">Who did you send it to?<input type="email" class="pr-input" data-pr-input="to" value="${esc(draft.to || '')}" autocomplete="email"
|
|
118
|
+
data-command-id="shell.project-rfi-sent-to#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}${ro}></label>`;
|
|
119
|
+
primary = 'Mark as sent'; break;
|
|
120
|
+
case 'answer':
|
|
121
|
+
fields = `<label class="pr-field">What was the answer?<textarea class="pr-input pr-text" data-pr-input="text" rows="4" maxlength="4000"
|
|
122
|
+
data-command-id="shell.project-rfi-answer-text#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}${ro}>${esc(draft.text || '')}</textarea></label>
|
|
123
|
+
<p class="pg-row-meta">Paste or type what you were told.</p>`;
|
|
124
|
+
primary = 'Save answer'; break;
|
|
125
|
+
case 'close': {
|
|
126
|
+
const options = DISPOSITIONS.filter((d) => d.key !== 'answered' || rfi.status === 'answered');
|
|
127
|
+
const chosen = draft.disposition || (rfi.status === 'answered' ? 'answered' : '');
|
|
128
|
+
fields = `<div class="pr-radios" role="radiogroup" aria-label="Why is it closing?">${options.map((d, i) => {
|
|
129
|
+
const on = chosen === d.key;
|
|
130
|
+
return `<button type="button" class="pr-radio" role="radio" aria-checked="${on}" tabindex="${on || (!chosen && i === 0) ? 0 : -1}" data-pr-disposition="${esc(d.key)}"
|
|
131
|
+
data-command-id="shell.project-rfi-close-reason#${esc(d.key)}" data-command-instance-label="${esc(d.label)}"${busy || (form.uncertain ? ' disabled' : '')}><span class="pr-radio-dot" aria-hidden="true"></span>
|
|
132
|
+
<span><span class="pr-radio-label">${esc(d.label)}</span><span class="pg-row-meta">${esc(d.help)}</span></span></button>`;
|
|
133
|
+
}).join('')}</div>
|
|
134
|
+
<label class="pr-field">${chosen === 'answered' ? 'Note (optional)' : 'Note'}<textarea class="pr-input pr-text" data-pr-input="note" rows="2" maxlength="1000"
|
|
135
|
+
data-command-id="shell.project-rfi-close-note#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}${ro}>${esc(draft.note || '')}</textarea></label>`;
|
|
136
|
+
primary = 'Close RFI'; break;
|
|
137
|
+
}
|
|
138
|
+
case 'gmail': {
|
|
139
|
+
const readiness = state.readiness;
|
|
140
|
+
const notReady = readiness?.status !== 'ready';
|
|
141
|
+
const blocking = notReady && !TRANSIENT.has(readiness?.status) && readiness?.status !== 'loading';
|
|
142
|
+
const why = notReady ? `<p class="pm-note pr-readiness" role="status">${esc(readinessText(readiness))}</p>` : '';
|
|
143
|
+
if (blocking) {
|
|
144
|
+
// Not ready, and a send can't work until something is fixed: say what, and offer the other ways — never a dead control.
|
|
145
|
+
const fix = FIX_IN_INTEGRATIONS.has(readiness?.status)
|
|
146
|
+
? `<button type="button" class="primary" data-pr-gmail-integrations="1" data-command-id="shell.project-rfis-gmail-integrations">Open Integrations</button>` : '';
|
|
147
|
+
return `<div class="pr-form" role="group" aria-label="${esc(`Send ${rfi.id} with Gmail`)}">${why}
|
|
148
|
+
<div class="pm-strip-acts pr-form-acts">
|
|
149
|
+
${fix}
|
|
150
|
+
<button type="button" class="ghost" data-pr-gmail-recheck="1" data-command-id="shell.project-rfis-gmail-recheck">Check again</button>
|
|
151
|
+
<button type="button" class="ghost" data-pr-copy="${id}" data-command-id="shell.project-rfi-copy#${esc(rfi.id)}" data-command-instance-label="${id}">Copy email text</button>
|
|
152
|
+
${rfi.verbs.includes('mark-sent') ? `<button type="button" class="ghost" data-pr-verb="mark-sent" data-pr-rfi="${id}" data-command-id="shell.project-rfi-mark-sent#${esc(rfi.id)}" data-command-instance-label="${id}">Mark sent…</button>` : ''}
|
|
153
|
+
<button type="button" class="ghost" data-pr-form-cancel="1" data-command-id="shell.project-rfi-form-cancel#${esc(rfi.id)}" data-command-instance-label="${id}">Cancel</button>
|
|
154
|
+
</div></div>`;
|
|
155
|
+
}
|
|
156
|
+
const frozen = form.busy || form.uncertain ? ' readonly' : '';
|
|
157
|
+
const lineBusy = form.busy ? `<p class="pm-note" role="status">${form.slow ? 'Still waiting for Gmail…' : 'Sending through Gmail. Keep this open until it finishes.'}</p>` : '';
|
|
158
|
+
const lost = form.uncertain ? '<p class="pm-note pr-alert" role="alert">FloLess didn’t get an answer, so it can’t tell whether Gmail sent this. Try again won’t send it twice. Or check the list first.</p>' : '';
|
|
159
|
+
const err = form.error ? `<p class="pm-note pr-alert" role="alert">${esc(form.error)}</p>` : '';
|
|
160
|
+
const held = form.busy ? ' aria-disabled="true" data-blocked-reason="Sending through Gmail. Wait for it to finish."' : '';
|
|
161
|
+
return `<div class="pr-form" role="group" aria-label="${esc(`Send ${rfi.id} with Gmail`)}"${form.busy ? ' aria-busy="true"' : ''}>${why}
|
|
162
|
+
<label class="pr-field">Send to<input type="email" class="pr-input" data-pr-input="to" value="${esc(draft.to || '')}" autocomplete="email"
|
|
163
|
+
data-command-id="shell.project-rfi-gmail-to#${esc(rfi.id)}" data-command-instance-label="${id}"${frozen}></label>
|
|
164
|
+
<p class="pg-row-meta">Gmail sends this RFI’s email text from your connected Google account, with a reference line FloLess uses to find it later in Sent.</p>
|
|
165
|
+
${lineBusy}${err}${lost}
|
|
166
|
+
<div class="pm-strip-acts pr-form-acts">
|
|
167
|
+
${form.uncertain
|
|
168
|
+
? `<button type="button" class="ghost" data-pr-gmail-check="1" data-command-id="shell.project-rfi-gmail-check-list#${esc(rfi.id)}" data-command-instance-label="${id}">Check the list</button>`
|
|
169
|
+
: `<button type="button" class="ghost" data-pr-form-cancel="1" data-command-id="shell.project-rfi-form-cancel#${esc(rfi.id)}" data-command-instance-label="${id}"${held}${form.busy ? ' data-tip="A send in progress can’t be cancelled"' : ''}>Cancel</button>`}
|
|
170
|
+
<button type="button" class="primary" data-pr-form-submit="1" data-command-id="shell.project-rfi-gmail-submit#${esc(rfi.id)}" data-command-instance-label="${id}"
|
|
171
|
+
aria-label="${esc(`Send ${rfi.id} with Gmail`)}"${held}>${form.uncertain ? 'Try again' : form.busy ? 'Sending…' : 'Send email'}</button>
|
|
172
|
+
</div></div>`;
|
|
173
|
+
}
|
|
174
|
+
case 'reopen':
|
|
175
|
+
fields = `<label class="pr-field">Why is this open again?<textarea class="pr-input pr-text" data-pr-input="why" rows="2" maxlength="1000"
|
|
176
|
+
data-command-id="shell.project-rfi-reopen-why#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}${ro}>${esc(draft.why || '')}</textarea></label>`;
|
|
177
|
+
primary = 'Reopen'; break;
|
|
178
|
+
}
|
|
179
|
+
const verbName = { 'mark-sent': 'Mark sent', answer: 'Answer', close: 'Close', reopen: 'Reopen' }[form.verb];
|
|
180
|
+
return `<div class="pr-form" role="group" aria-label="${esc(`${verbName} ${rfi.id}`)}"${form.busy ? ' aria-busy="true"' : ''}>${fields}${alert}${uncertain}
|
|
181
|
+
<div class="pm-strip-acts pr-form-acts">
|
|
182
|
+
<button type="button" class="ghost" data-pr-form-cancel="1" data-command-id="shell.project-rfi-form-cancel#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}>Cancel</button>
|
|
183
|
+
${form.uncertain ? `<button type="button" class="ghost" data-pr-form-edit="1" data-command-id="shell.project-rfi-form-edit#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}>Edit</button>` : ''}
|
|
184
|
+
${form.stale ? `<button type="button" class="ghost" data-pr-form-again="1" data-command-id="shell.project-rfi-look-again#${esc(rfi.id)}" data-command-instance-label="${id}">Look again</button>` : ''}
|
|
185
|
+
<button type="button" class="primary" data-pr-form-submit="1" data-command-id="shell.project-rfi-form-submit#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}>${form.uncertain ? 'Try again' : form.busy ? 'Saving…' : esc(primary)}</button>
|
|
186
|
+
</div></div>`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function rowHtml(rfi, now) {
|
|
190
|
+
const id = esc(rfi.id);
|
|
191
|
+
const label = `data-command-instance-label="${id}"`;
|
|
192
|
+
const meta = [];
|
|
193
|
+
if (rfi.sent) meta.push(`<span data-tip="${esc(exact(rfi.sent.at))}">${rfi.sent.via === 'gmail' ? 'Sent with Gmail to' : 'Marked sent to'} ${esc(rfi.sent.to)} · ${esc(ago(rfi.sent.at, now))}</span>`);
|
|
194
|
+
else meta.push(`<span data-tip="${esc(exact(rfi.raisedAt))}">Filed ${esc(ago(rfi.raisedAt, now))}${rfi.raisedBy === 'ai' ? ' by AI Chat' : ''}</span>`);
|
|
195
|
+
if (rfi.reopens) meta.push(`Reopened ${rfi.reopens === 1 ? 'once' : `${rfi.reopens} times`}`);
|
|
196
|
+
const answer = rfi.answer ? `<blockquote class="pr-answer"><span class="pr-answer-label">Answer</span> ${esc(rfi.answer.text)}</blockquote>` : '';
|
|
197
|
+
const closed = rfi.closed ? `<p class="pg-row-meta">Closed: ${esc(dispositionLabel(rfi.closed.disposition))}${rfi.closed.note ? `. ${esc(rfi.closed.note)}` : '.'}</p>` : '';
|
|
198
|
+
const provenance = rfi.provenance ? `<p class="pm-note">${esc(rfi.provenance)}</p>` : '';
|
|
199
|
+
const cites = rfi.citations.length ? `<div class="pr-cites" role="list" aria-label="Cited in ${id}">${rfi.citations.map(chipHtml).join('')}</div>` : '';
|
|
200
|
+
const drifted = rfi.citations.some((c) => c.state !== 'current');
|
|
201
|
+
const driftNote = drifted ? '<p class="pg-row-meta">One cited item no longer matches. You can send the RFI as it was, or File again from this… with the current items.</p>' : '';
|
|
202
|
+
const form = state.form && state.form.rfiId === rfi.id ? formHtml(rfi, state.form) : '';
|
|
203
|
+
const d = rfi.delivery;
|
|
204
|
+
const pending = unresolved(d);
|
|
205
|
+
const recovering = state.recovering?.rfiId === rfi.id ? state.recovering.action : null;
|
|
206
|
+
// While a send is in flight on another row, its sends and records wait (one open form at a time).
|
|
207
|
+
const elsewhere = state.form?.busy && state.form.rfiId !== rfi.id ? ' aria-disabled="true" data-blocked-reason="A send is in progress"' : '';
|
|
208
|
+
let deliveryNote = '';
|
|
209
|
+
if (d && (d.status === 'recorded' || d.status === 'confirmed-sent' || d.status === 'failed' || pending)) {
|
|
210
|
+
const note = d.status === 'recorded' ? 'Gmail accepted it. That doesn’t prove it reached the inbox.'
|
|
211
|
+
: d.status === 'confirmed-sent' ? `You confirmed it in Sent on ${esc(exact(d.settledAt || ''))}.`
|
|
212
|
+
: d.status === 'failed' ? (rfi.status === 'open' ? 'Gmail didn’t receive this RFI, so nothing was sent. Send it again, or copy the email text and send it yourself.' : '')
|
|
213
|
+
: d.status === 'prepared' ? `FloLess began sending this with Gmail but didn’t finish recording it, so it can’t tell whether it went. Don’t send it again. Choose Finish sending. ${HELD}`
|
|
214
|
+
: `FloLess can’t tell whether Gmail accepted this RFI. Don’t send it again. Open the connected account’s Sent folder and search for <span class="pr-marker">${esc(d.reconciliationMarker || '')}</span>. If you find it, choose I found it in Sent. ${HELD}`;
|
|
215
|
+
const alert = state.alertFor === rfi.id ? ' role="alert"' : '';
|
|
216
|
+
if (note) deliveryNote = `<p class="pm-note${pending ? ' pr-delivery-held' : ''}" tabindex="-1" data-pr-delivery-note="${id}"${alert}>${note}</p>`;
|
|
217
|
+
}
|
|
218
|
+
const sendButton = rfi.status === 'open' && !pending && rfi.verbs.includes('mark-sent')
|
|
219
|
+
? `<button type="button" class="${state.readiness?.status === 'ready' ? 'primary' : 'ghost'}" data-pr-gmail="${id}" data-command-id="shell.project-rfis-gmail-send#${esc(rfi.id)}" ${label}
|
|
220
|
+
aria-label="${esc(`Send ${rfi.id} with Gmail`)}" data-tip="${esc(elsewhere ? 'A send is in progress' : 'Sends this RFI from your connected Google account')}"${elsewhere}>Send with Gmail…</button>` : '';
|
|
221
|
+
const recoverButtons = !pending ? '' : d.status === 'prepared'
|
|
222
|
+
? `<button type="button" class="primary" data-pr-gmail-continue="${id}" data-pr-attempt="${esc(d.attemptId)}" data-command-id="shell.project-rfis-gmail-continue#${esc(rfi.id)}" ${label}
|
|
223
|
+
aria-label="${esc(`Finish sending ${rfi.id} with Gmail`)}" data-tip="Finishes this one send. It never starts a second one."${recovering ? ' aria-busy="true" aria-disabled="true" data-blocked-reason="Finishing this send now."' : ''}>${recovering ? 'Finishing…' : 'Finish sending'}</button>`
|
|
224
|
+
: `<button type="button" class="primary" data-pr-gmail-confirm="${id}" data-pr-attempt="${esc(d.attemptId)}" data-command-id="shell.project-rfis-gmail-confirm#${esc(rfi.id)}" ${label}
|
|
225
|
+
aria-label="${esc(`I found ${rfi.id} in Sent`)}" data-tip="Use only after you found this exact send in the connected account’s Sent folder"${recovering ? ' aria-busy="true" aria-disabled="true" data-blocked-reason="Recording this now."' : ''}>${recovering ? 'Recording…' : 'I found it in Sent'}</button>
|
|
226
|
+
<button type="button" class="ghost" data-pr-gmail-marker="${id}" data-command-id="shell.project-rfis-gmail-marker#${esc(rfi.id)}" ${label}
|
|
227
|
+
aria-label="${esc(`Copy the search text for ${rfi.id}`)}" data-tip="Copies the reference line to search for in Sent">Copy search text</button>`;
|
|
228
|
+
const verbButtons = form ? '' : [
|
|
229
|
+
sendButton, recoverButtons,
|
|
230
|
+
rfi.status !== 'closed' ? `<button type="button" class="ghost" data-pr-copy="${id}" data-command-id="shell.project-rfi-copy#${esc(rfi.id)}" ${label} aria-label="Copy the email text of ${id}"
|
|
231
|
+
data-tip="Copies the subject and the question, with what it cites, to paste into your email">Copy email text</button>` : '',
|
|
232
|
+
...rfi.verbs.map((verb) => {
|
|
233
|
+
const text = { 'mark-sent': 'Mark sent…', answer: 'Answer…', close: 'Close…', reopen: 'Reopen…' }[verb];
|
|
234
|
+
const tip = { 'mark-sent': 'Records who you sent it to yourself. It sends nothing.', answer: 'Records the answer that came back',
|
|
235
|
+
close: 'Closes the RFI, with why', reopen: 'Opens the RFI again, with why' }[verb];
|
|
236
|
+
// Each command id is written whole; only the instance after "#" varies.
|
|
237
|
+
const carrier = verb === 'mark-sent' ? `data-command-id="shell.project-rfi-mark-sent#${esc(rfi.id)}"`
|
|
238
|
+
: verb === 'answer' ? `data-command-id="shell.project-rfi-answer#${esc(rfi.id)}"`
|
|
239
|
+
: verb === 'close' ? `data-command-id="shell.project-rfi-close#${esc(rfi.id)}"`
|
|
240
|
+
: `data-command-id="shell.project-rfi-reopen#${esc(rfi.id)}"`;
|
|
241
|
+
const wait = (verb === 'mark-sent' || verb === 'answer') && elsewhere;
|
|
242
|
+
return `<button type="button" class="ghost" data-pr-verb="${esc(verb)}" data-pr-rfi="${id}" ${carrier} ${label}
|
|
243
|
+
aria-label="${esc(`${text.replace('…', '')} ${rfi.id}`)}" data-tip="${esc(wait ? 'A send is in progress' : tip)}"${wait ? elsewhere : ''}>${esc(text)}</button>`;
|
|
244
|
+
}),
|
|
245
|
+
drifted ? `<button type="button" class="ghost" data-pr-again="${id}" data-command-id="shell.project-rfi-file-again#${esc(rfi.id)}" ${label}
|
|
246
|
+
data-tip="Opens New RFI with this title and question and the items that still match">File again from this…</button>` : '',
|
|
247
|
+
].join('');
|
|
248
|
+
return `<div class="pg-row pr-row" role="listitem"${(state.form?.busy && state.form.rfiId === rfi.id) || recovering ? ' aria-busy="true"' : ''}>
|
|
249
|
+
<div class="pg-row-line"><span class="pg-row-title" tabindex="-1" data-pr-title="${id}">${id} · ${esc(rfi.title)}</span>
|
|
250
|
+
<span class="pw-chip${rfi.status === 'closed' ? ' is-muted' : ''}">${esc(STATUS[rfi.status] || rfi.status)}</span>${pending ? `<span class="pw-chip is-muted">${d.status === 'prepared' ? 'Unfinished' : 'Not confirmed'}</span>` : ''}</div>
|
|
251
|
+
<span class="pg-row-meta">${meta.join(' · ')}</span>
|
|
252
|
+
<p class="pr-question">${esc(rfi.question)}</p>${answer}${closed}${provenance}${cites}${driftNote}${deliveryNote}
|
|
253
|
+
${form || `<div class="pm-strip-acts pr-acts">${verbButtons}</div>`}
|
|
254
|
+
${state.copied?.rfiId === rfi.id ? `<textarea class="pr-input pr-text pr-copied" data-pr-copied="1" readonly rows="6" data-command-id="shell.project-rfi-copied-text#${esc(rfi.id)}" data-command-instance-label="${id}" aria-label="${esc(`Email text of ${rfi.id}`)}">${esc(state.copied.text)}</textarea>` : ''}</div>`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const newButton = (cls) => `<button type="button" class="ghost ${cls}" data-pr-new="1" aria-haspopup="dialog" data-command-id="shell.project-rfis-new"
|
|
258
|
+
data-tip="File a question for the engineer, client or architect">New RFI…</button>`;
|
|
259
|
+
|
|
260
|
+
function html(view, now = Date.now()) {
|
|
261
|
+
const data = view.data;
|
|
262
|
+
const rfis = data?.rfis || [];
|
|
263
|
+
const ready = view.status === 'ready' && data?.store === 'ok';
|
|
264
|
+
const head = `<div class="step-head"><span tabindex="-1" data-pr-heading="1">RFIs</span>${ready && rfis.length ? newButton('pr-new') : ''}</div>
|
|
265
|
+
<p class="pg-sub">Questions for the engineer, client or architect. FloLess can send an RFI with Gmail once Google is connected, or give you the email text to send yourself, and keeps the answer.</p>`;
|
|
266
|
+
if (view.status === 'loading') return `${head}<p class="pg-loading-line">Loading this project’s RFIs…</p>`;
|
|
267
|
+
if (view.status === 'gone') return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">FloLess couldn’t find this project any more.</p><p>It may have been archived or removed. Go back to your projects to open it again.</p></div>`;
|
|
268
|
+
if (view.status === 'failed') {
|
|
269
|
+
return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">FloLess couldn’t load this project’s RFIs.</p><p>${esc(view.error)}</p>
|
|
270
|
+
<p><button type="button" class="ghost" data-pr-retry="1" data-command-id="shell.project-rfis-retry">Try again</button></p></div>`;
|
|
271
|
+
}
|
|
272
|
+
if (data.store === 'newer') {
|
|
273
|
+
return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">These RFIs were made by a newer FloLess.</p><p>Update FloLess to see and change them. Nothing has been changed or lost.</p></div>`;
|
|
274
|
+
}
|
|
275
|
+
if (data.store === 'quarantined') {
|
|
276
|
+
return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">FloLess can’t read this project’s RFI file.</p><p>${esc(data.message)}</p>
|
|
277
|
+
<p><button type="button" class="ghost" data-pr-repair="1" data-command-id="shell.project-rfis-repair">I restored it — check again</button></p>
|
|
278
|
+
${view.repairError ? `<p class="pm-note pr-alert" role="alert">${esc(view.repairError)}</p>` : ''}</div>`;
|
|
279
|
+
}
|
|
280
|
+
if (data.store === 'transport') {
|
|
281
|
+
return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">FloLess couldn’t load this project’s RFIs.</p><p>${esc(data.message)}</p>
|
|
282
|
+
<p><button type="button" class="ghost" data-pr-retry="1" data-command-id="shell.project-rfis-retry">Try again</button></p></div>`;
|
|
283
|
+
}
|
|
284
|
+
if (!rfis.length) {
|
|
285
|
+
return `${head}<div class="pg-empty pr-empty"><p class="pg-empty-title">No RFIs in this project yet</p>
|
|
286
|
+
<p>File a question for the engineer, client or architect. FloLess keeps it, sends it with Gmail or gives you the email text, and records the answer.</p><p>${newButton('pr-new-empty')}</p></div>`;
|
|
287
|
+
}
|
|
288
|
+
const counts = { open: visible(rfis, 'open').length, closed: visible(rfis, 'closed').length, all: rfis.length };
|
|
289
|
+
const filters = `<div class="pr-filters" role="group" aria-label="Show RFIs">${['open', 'closed', 'all'].map((f) => `<button type="button" class="ghost pr-filter"
|
|
290
|
+
aria-pressed="${state.filter === f}" data-pr-filter="${f}" data-command-id="shell.project-rfis-filter#${esc(f)}">${{ open: 'Open', closed: 'Closed', all: 'All' }[f]} ${counts[f]}</button>`).join('')}</div>`;
|
|
291
|
+
const shownRfis = visible(rfis, state.filter);
|
|
292
|
+
const list = shownRfis.length
|
|
293
|
+
? `<div class="pg-list pr-list" role="list" aria-label="RFIs in this project">${shownRfis.map((r) => rowHtml(r, now)).join('')}</div>`
|
|
294
|
+
: `<div class="pg-empty pr-empty"><p class="pg-empty-title">${state.filter === 'closed' ? 'No closed RFIs yet.' : 'No open RFIs.'}</p>
|
|
295
|
+
<p><button type="button" class="ghost" data-pr-filter="all" data-command-id="shell.project-rfis-filter#all">Show all</button></p></div>`;
|
|
296
|
+
return head + filters + list;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function paint() {
|
|
300
|
+
const { pane, view } = state;
|
|
301
|
+
const active = pane.contains(document.activeElement) && document.activeElement !== document.body ? document.activeElement : null;
|
|
302
|
+
const focusedId = active?.getAttribute('data-command-id') ?? null;
|
|
303
|
+
const focusedInput = active?.getAttribute('data-pr-input') ?? null;
|
|
304
|
+
let body = ownChild(pane, 'pr-body');
|
|
305
|
+
if (!body) {
|
|
306
|
+
pane.innerHTML = '<span class="sr-only pr-live" role="status" aria-live="polite"></span><div class="pr-body"></div>';
|
|
307
|
+
body = ownChild(pane, 'pr-body');
|
|
308
|
+
}
|
|
309
|
+
body.innerHTML = html(view);
|
|
310
|
+
const after = state.focusAfter; state.focusAfter = null;
|
|
311
|
+
const find = (sel) => body.querySelector(sel);
|
|
312
|
+
if (after) { (find(after) || find('[data-pr-heading]'))?.focus({ preventScroll: true }); return; }
|
|
313
|
+
if (focusedInput) { const el = find(`[data-pr-input="${focusedInput}"]`); if (el) { el.focus({ preventScroll: true }); return; } }
|
|
314
|
+
if (focusedId) [...body.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === focusedId)?.focus({ preventScroll: true });
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function load() {
|
|
318
|
+
if (!state) return;
|
|
319
|
+
if (state.inflight) { state.again = true; return; }
|
|
320
|
+
const mine = state;
|
|
321
|
+
const generation = mine.generation;
|
|
322
|
+
mine.inflight = true;
|
|
323
|
+
try {
|
|
324
|
+
const data = await api(`/api/projects/${encodeURIComponent(mine.project.id)}/correspondence-rfis`);
|
|
325
|
+
if (state !== mine || mine.generation !== generation) return;
|
|
326
|
+
mine.view = { status: 'ready', data, error: null };
|
|
327
|
+
if (mine.form && !data.rfis.some((r) => r.id === mine.form.rfiId)) mine.form = null;
|
|
328
|
+
paint();
|
|
329
|
+
if (data.store === 'ok') {
|
|
330
|
+
const n = data.rfis.length;
|
|
331
|
+
if (!mine.quietLoad) announce(n === 0 ? 'No RFIs in this project yet' : `${n} RFI${n === 1 ? '' : 's'}`);
|
|
332
|
+
} else announce(data.message || 'FloLess couldn’t load this project’s RFIs.');
|
|
333
|
+
mine.quietLoad = false;
|
|
334
|
+
} catch (error) {
|
|
335
|
+
if (state !== mine || mine.generation !== generation) return;
|
|
336
|
+
const gone = error?.status === 404;
|
|
337
|
+
mine.view = { status: gone ? 'gone' : 'failed', data: null,
|
|
338
|
+
error: said(error, 'FloLess couldn’t read them just now. Check that FloLess is still running, then try again.') };
|
|
339
|
+
paint();
|
|
340
|
+
announce(gone ? 'FloLess couldn’t find this project any more.' : 'FloLess couldn’t load this project’s RFIs.');
|
|
341
|
+
} finally {
|
|
342
|
+
mine.inflight = false;
|
|
343
|
+
if (state === mine && mine.again) { mine.again = false; void load(); }
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function render(pane, project) {
|
|
348
|
+
if (!pane || !project) return;
|
|
349
|
+
const same = state && state.pane === pane && state.project.id === project.id;
|
|
350
|
+
state = { pane, project, generation: (state?.generation || 0) + 1, view: { status: 'loading', data: null },
|
|
351
|
+
filter: same ? state.filter : 'open', form: null, inflight: false, again: false, focusAfter: null,
|
|
352
|
+
readiness: { status: 'loading' }, recovering: null, alertFor: null };
|
|
353
|
+
paint();
|
|
354
|
+
void load();
|
|
355
|
+
void checkReadiness();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Whether the connected Google account can send now (read when the step shows and on Check again). */
|
|
359
|
+
async function checkReadiness() {
|
|
360
|
+
const mine = state;
|
|
361
|
+
if (!mine) return;
|
|
362
|
+
const wasReady = mine.readiness?.status === 'ready';
|
|
363
|
+
mine.readiness = { status: 'loading' };
|
|
364
|
+
// Any open form keeps what was typed across the repaint (Codex review: an Answer draft was lost when readiness landed).
|
|
365
|
+
if (mine.form) { readDraft(); paint(); }
|
|
366
|
+
let readiness;
|
|
367
|
+
try {
|
|
368
|
+
const res = await api(`/api/projects/${encodeURIComponent(mine.project.id)}/correspondence-rfis/gmail-readiness`);
|
|
369
|
+
readiness = res.readiness && typeof res.readiness === 'object' ? res.readiness : { status: 'unavailable' };
|
|
370
|
+
} catch (error) {
|
|
371
|
+
readiness = { status: 'unavailable', message: said(error, '') || undefined };
|
|
372
|
+
}
|
|
373
|
+
if (state !== mine) return;
|
|
374
|
+
mine.readiness = readiness;
|
|
375
|
+
if (mine.form) readDraft();
|
|
376
|
+
if (mine.form?.verb === 'gmail' && !mine.form.busy) {
|
|
377
|
+
if (readiness.status === 'ready' && !wasReady) { mine.focusAfter = '.pr-form [data-pr-input="to"]'; paint(); announce('Gmail is ready.'); return; }
|
|
378
|
+
}
|
|
379
|
+
paint();
|
|
380
|
+
}
|
|
381
|
+
const shown = (pane) => !pane.hidden && (typeof pane.checkVisibility === 'function' ? pane.checkVisibility() : pane.offsetParent !== null);
|
|
382
|
+
/** Something changed elsewhere: re-read while shown — but never under an open form (its text would be lost). */
|
|
383
|
+
function refresh() { if (state && shown(state.pane) && !state.form && !sheet) void load(); }
|
|
384
|
+
|
|
385
|
+
// ── verbs ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
386
|
+
|
|
387
|
+
function openForm(rfiId, verb) {
|
|
388
|
+
const rfi = state.view.data?.rfis.find((r) => r.id === rfiId);
|
|
389
|
+
// A Gmail send starts from the last address this RFI went to, or was last tried with.
|
|
390
|
+
const draft = verb === 'gmail' ? { to: rfi?.delivery?.to || rfi?.sent?.to || '' } : {};
|
|
391
|
+
state.form = { rfiId, verb, key: newKey(), draft, error: null, busy: false, uncertain: false, stale: false };
|
|
392
|
+
state.focusAfter = verb === 'close' ? '.pr-form [data-pr-disposition]'
|
|
393
|
+
: verb === 'gmail' ? '.pr-form [data-pr-input="to"], .pr-form [data-pr-gmail-integrations], .pr-form [data-pr-gmail-recheck]' : '.pr-form [data-pr-input]';
|
|
394
|
+
paint();
|
|
395
|
+
}
|
|
396
|
+
function closeForm() {
|
|
397
|
+
const f = state.form;
|
|
398
|
+
state.form = null;
|
|
399
|
+
state.focusAfter = !f ? null : f.verb === 'gmail' ? `[data-pr-gmail="${CSS.escape(f.rfiId)}"]` : `[data-pr-verb="${f.verb}"][data-pr-rfi="${CSS.escape(f.rfiId)}"]`;
|
|
400
|
+
paint();
|
|
401
|
+
}
|
|
402
|
+
function readDraft() {
|
|
403
|
+
const f = state.form;
|
|
404
|
+
if (!f) return;
|
|
405
|
+
for (const el of state.pane.querySelectorAll('.pr-form [data-pr-input]')) f.draft[el.getAttribute('data-pr-input')] = el.value;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
async function submitForm() {
|
|
409
|
+
const mine = state;
|
|
410
|
+
const f = mine.form;
|
|
411
|
+
if (!f || f.busy) return;
|
|
412
|
+
if (f.verb === 'gmail') { void submitGmail(mine, f); return; }
|
|
413
|
+
if (f.uncertain) { void sendForm(mine, f, f.sent); return; }
|
|
414
|
+
readDraft();
|
|
415
|
+
const rfi = mine.view.data.rfis.find((r) => r.id === f.rfiId);
|
|
416
|
+
const d = f.draft;
|
|
417
|
+
// Asked, not refused: the button stays live and says what is missing.
|
|
418
|
+
const missing = f.verb === 'mark-sent' && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(d.to || '').trim()) ? 'Give one email address, like name@company.com.'
|
|
419
|
+
: f.verb === 'answer' && !String(d.text || '').trim() ? 'Write the answer that came back.'
|
|
420
|
+
: f.verb === 'close' && !d.disposition && rfi.status !== 'answered' ? 'Choose why it’s closing.'
|
|
421
|
+
: f.verb === 'close' && (d.disposition || 'answered') !== 'answered' && !String(d.note || '').trim() ? 'Say why it’s being closed.'
|
|
422
|
+
: f.verb === 'reopen' && !String(d.why || '').trim() ? 'Say why it’s open again.' : null;
|
|
423
|
+
if (missing) { f.error = missing; paint(); announce(missing); return; }
|
|
424
|
+
const body = { ...identity(), operationKey: f.key, recordRevision: rfi.recordRevision };
|
|
425
|
+
if (f.verb === 'mark-sent') body.to = String(d.to).trim();
|
|
426
|
+
if (f.verb === 'answer') body.text = String(d.text).trim();
|
|
427
|
+
if (f.verb === 'close') { body.disposition = d.disposition || 'answered'; if (String(d.note || '').trim()) body.note = String(d.note).trim(); }
|
|
428
|
+
if (f.verb === 'reopen') body.why = String(d.why).trim();
|
|
429
|
+
f.sent = body; // what Try again resends, unchanged, under the same key
|
|
430
|
+
await sendForm(mine, f, body);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async function sendForm(mine, f, body) {
|
|
434
|
+
f.busy = true; f.error = null; f.stale = false; paint();
|
|
435
|
+
try {
|
|
436
|
+
const res = await api(`/api/projects/${encodeURIComponent(target().projectId)}/correspondence-rfis/${encodeURIComponent(f.rfiId)}/${f.verb}`,
|
|
437
|
+
{ method: 'POST', body: JSON.stringify(body) });
|
|
438
|
+
if (state !== mine) return;
|
|
439
|
+
const status = res.rfi.status;
|
|
440
|
+
const msg = { 'mark-sent': `${f.rfiId} marked as sent to ${body.to}.`, answer: `Answer saved for ${f.rfiId}.`,
|
|
441
|
+
close: `${f.rfiId} closed as ${dispositionLabel(body.disposition)}.`, reopen: `${f.rfiId} is open again.` }[f.verb];
|
|
442
|
+
const hidden = mine.filter === 'open' && status === 'closed' || mine.filter === 'closed' && status !== 'closed';
|
|
443
|
+
toast(hidden ? `${msg} It’s under ${status === 'closed' ? 'Closed' : 'Open'}.` : msg, 'ok');
|
|
444
|
+
mine.form = null;
|
|
445
|
+
mine.quietLoad = true;
|
|
446
|
+
await load();
|
|
447
|
+
if (state !== mine) return;
|
|
448
|
+
// Focus: the row's title, or (when the filter now hides it) the next row's title, else the heading.
|
|
449
|
+
const titles = [...mine.pane.querySelectorAll('[data-pr-title]')];
|
|
450
|
+
const own = titles.find((t) => t.getAttribute('data-pr-title') === f.rfiId);
|
|
451
|
+
(own || titles[0] || mine.pane.querySelector('[data-pr-heading]'))?.focus({ preventScroll: true });
|
|
452
|
+
announce(hidden ? `${msg} Moved to ${status === 'closed' ? 'Closed' : 'Open'}.` : `${f.rfiId} is ${STATUS[status].toLowerCase()}.`);
|
|
453
|
+
} catch (error) {
|
|
454
|
+
if (state !== mine) return;
|
|
455
|
+
f.busy = false;
|
|
456
|
+
if (refused(error)) {
|
|
457
|
+
f.error = said(error, 'FloLess couldn’t do that just now. Try again.');
|
|
458
|
+
f.stale = error.body.code === 'rfi-revision-stale' || error.body.code === 'project-changed';
|
|
459
|
+
f.uncertain = false; f.sent = null;
|
|
460
|
+
f.key = newKey(); // a refusal: the next send is a new intent, from what the form now holds
|
|
461
|
+
} else {
|
|
462
|
+
f.uncertain = true; // keep the key and the exact payload: Try again resends it unchanged
|
|
463
|
+
}
|
|
464
|
+
paint();
|
|
465
|
+
announce(f.uncertain ? 'FloLess couldn’t confirm that was saved.' : f.error);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// ── Gmail send and its recovery (#2470 R6.6b) ──────────────────────────────────────────────────────────────────
|
|
470
|
+
|
|
471
|
+
async function submitGmail(mine, f) {
|
|
472
|
+
if (!f.uncertain) {
|
|
473
|
+
readDraft();
|
|
474
|
+
const to = String(f.draft.to || '').trim();
|
|
475
|
+
if (!isAddress(to)) { f.error = 'Give one email address, like name@company.com.'; mine.focusAfter = '.pr-form [data-pr-input="to"]'; paint(); announce(f.error); return; }
|
|
476
|
+
const rfi = mine.view.data.rfis.find((r) => r.id === f.rfiId);
|
|
477
|
+
f.sent = { ...identity(), operationKey: f.key, recordRevision: rfi.recordRevision, to };
|
|
478
|
+
}
|
|
479
|
+
f.busy = true; f.error = null; f.slow = false; mine.focusAfter = '.pr-form [data-pr-form-submit]'; paint();
|
|
480
|
+
const slow = setTimeout(() => { if (state === mine && mine.form === f && f.busy) { f.slow = true; mine.focusAfter = '.pr-form [data-pr-form-submit]'; paint(); } }, 10000);
|
|
481
|
+
try {
|
|
482
|
+
const res = await api(`/api/projects/${encodeURIComponent(target().projectId)}/correspondence-rfis/${encodeURIComponent(f.rfiId)}/deliver`,
|
|
483
|
+
{ method: 'POST', body: JSON.stringify(f.sent) });
|
|
484
|
+
if (state !== mine) return;
|
|
485
|
+
await settleGmail(mine, f.rfiId, res, f.sent.to);
|
|
486
|
+
} catch (error) {
|
|
487
|
+
if (state !== mine) return;
|
|
488
|
+
f.busy = false;
|
|
489
|
+
if (error?.body?.attempt) {
|
|
490
|
+
// The server answered about the attempt — not sent, can't tell, or (whatever the status) it could not record
|
|
491
|
+
// what Gmail did. Never a plain refusal: the row is re-read and shows what is durably true, Finish sending included.
|
|
492
|
+
await settleGmail(mine, f.rfiId, error.body, f.sent.to);
|
|
493
|
+
} else if (error?.body?.code === 'rfi-gmail-not-ready') {
|
|
494
|
+
// Nothing was prepared or sent: Gmail isn't ready. The form shows why and the other ways, from this answer.
|
|
495
|
+
if (error.body.readiness) mine.readiness = error.body.readiness;
|
|
496
|
+
f.error = null; f.uncertain = false; f.sent = null; f.key = newKey();
|
|
497
|
+
mine.focusAfter = '.pr-form [data-pr-gmail-integrations], .pr-form [data-pr-gmail-recheck], .pr-form [data-pr-form-submit]';
|
|
498
|
+
paint(); announce(readinessText(mine.readiness));
|
|
499
|
+
} else if (refused(error)) {
|
|
500
|
+
f.error = said(error, 'FloLess couldn’t send it just now. Try again.');
|
|
501
|
+
f.uncertain = false; f.sent = null; f.key = newKey(); // a refusal: the next send is a new intent
|
|
502
|
+
mine.focusAfter = /recipient|address/.test(error.body.code || '') ? '.pr-form [data-pr-input="to"]' : '.pr-form [data-pr-form-submit]';
|
|
503
|
+
paint(); announce(f.error);
|
|
504
|
+
} else {
|
|
505
|
+
f.uncertain = true; // no answer: same key and payload on Try again, and no Edit (a changed address could send twice)
|
|
506
|
+
mine.focusAfter = '.pr-form [data-pr-form-submit]';
|
|
507
|
+
paint(); announce('FloLess didn’t get an answer, so it can’t tell whether Gmail sent this.');
|
|
508
|
+
}
|
|
509
|
+
} finally { clearTimeout(slow); }
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** After a send or recovery answered: re-read, then say what is durably true — success only from a recorded result. */
|
|
513
|
+
async function settleGmail(mine, rfiId, res, to) {
|
|
514
|
+
const status = res?.attempt?.status;
|
|
515
|
+
mine.form = null;
|
|
516
|
+
mine.recovering = null;
|
|
517
|
+
mine.quietLoad = true;
|
|
518
|
+
if (status === 'recorded' || status === 'confirmed-sent') {
|
|
519
|
+
await load();
|
|
520
|
+
if (state !== mine) return;
|
|
521
|
+
toast(status === 'recorded' ? `${rfiId} sent with Gmail to ${to || res.attempt.to}.` : `Recorded that you found ${rfiId} in Sent.`, 'ok');
|
|
522
|
+
mine.pane.querySelector(`[data-pr-title="${CSS.escape(rfiId)}"]`)?.focus({ preventScroll: true });
|
|
523
|
+
announce(status === 'recorded' ? `${rfiId} sent with Gmail to ${to || res.attempt.to}.` : `${rfiId} is recorded as sent.`);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
// Not sent, or not known: the note says which, and focus goes to it so it is read before anything else.
|
|
527
|
+
mine.alertFor = status === 'failed' ? null : rfiId;
|
|
528
|
+
mine.focusAfter = `[data-pr-delivery-note="${CSS.escape(rfiId)}"], [data-pr-title="${CSS.escape(rfiId)}"]`;
|
|
529
|
+
await load();
|
|
530
|
+
if (state !== mine) return;
|
|
531
|
+
mine.alertFor = null;
|
|
532
|
+
if (status === 'failed') announce(`Gmail didn’t receive ${rfiId}, so nothing was sent.`);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
async function recoverGmail(rfiId, attemptId, action) {
|
|
536
|
+
const mine = state;
|
|
537
|
+
if (mine.recovering) return;
|
|
538
|
+
mine.recovering = { rfiId, action };
|
|
539
|
+
paint();
|
|
540
|
+
try {
|
|
541
|
+
// The server binds its own key for this attempt and action, so any retry — here, in another window or from chat —
|
|
542
|
+
// reaches the same one recovery and never sends twice (plan §4.4).
|
|
543
|
+
const res = await api(`/api/projects/${encodeURIComponent(target().projectId)}/correspondence-rfis/${encodeURIComponent(rfiId)}/delivery-attempts/${encodeURIComponent(attemptId)}/${action}`,
|
|
544
|
+
{ method: 'POST', body: JSON.stringify({ ...identity(), operationKey: newKey() }) });
|
|
545
|
+
if (state !== mine) return;
|
|
546
|
+
await settleGmail(mine, rfiId, res);
|
|
547
|
+
} catch (error) {
|
|
548
|
+
if (state !== mine) return;
|
|
549
|
+
if (error?.body?.attempt) {
|
|
550
|
+
// Say what the durable state is, in this step's words (the server's reason may be a code).
|
|
551
|
+
const status = error.body.attempt.status;
|
|
552
|
+
await settleGmail(mine, rfiId, error.body);
|
|
553
|
+
toast(status === 'failed' ? `Gmail didn’t receive ${rfiId}, so nothing was sent.`
|
|
554
|
+
: status === 'outcome-unknown' ? `FloLess still can’t tell whether Gmail accepted ${rfiId}. Don’t send it again; check Sent.`
|
|
555
|
+
: `FloLess couldn’t finish recording ${rfiId}’s send. Don’t send it again; choose Finish sending.`, 'warn');
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
mine.recovering = null;
|
|
559
|
+
const answered = refused(error);
|
|
560
|
+
// No answer: a Finish sending may already have reached Gmail, so nothing is claimed — the list is read again.
|
|
561
|
+
toast(answered ? said(error, 'FloLess couldn’t do that just now. Try again.')
|
|
562
|
+
: action === 'continue' ? 'FloLess didn’t get an answer, so it can’t tell whether Gmail sent this. Finishing again never sends twice.'
|
|
563
|
+
: 'FloLess didn’t get an answer, so it can’t tell whether that was recorded. Recording it again never records it twice.', 'warn');
|
|
564
|
+
mine.quietLoad = true;
|
|
565
|
+
await load();
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
async function copyMarker(rfiId) {
|
|
570
|
+
const rfi = state.view.data?.rfis.find((r) => r.id === rfiId);
|
|
571
|
+
const marker = rfi?.delivery?.reconciliationMarker;
|
|
572
|
+
if (!marker) return;
|
|
573
|
+
try { await navigator.clipboard.writeText(marker); toast('Search text copied. Paste it into the Sent folder’s search.', 'ok'); }
|
|
574
|
+
catch { toast('Select the reference line in the note and copy it.', 'info'); }
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
async function copyText(rfiId) {
|
|
578
|
+
try {
|
|
579
|
+
const text = await api(`/api/projects/${encodeURIComponent(target().projectId)}/correspondence-rfis/${encodeURIComponent(rfiId)}/text`);
|
|
580
|
+
const full = `${text.subject}\n\n${text.body}`;
|
|
581
|
+
try { await navigator.clipboard.writeText(full); toast('Email text copied. Paste it into your email.', 'ok'); }
|
|
582
|
+
catch {
|
|
583
|
+
// No clipboard here: the text is shown in the row, selected, to copy by hand.
|
|
584
|
+
if (!state) return;
|
|
585
|
+
state.copied = { rfiId, text: full };
|
|
586
|
+
state.focusAfter = '[data-pr-copied]';
|
|
587
|
+
paint();
|
|
588
|
+
const box = state.pane.querySelector('[data-pr-copied]');
|
|
589
|
+
box?.select?.();
|
|
590
|
+
toast('Select and copy this text.', 'info');
|
|
591
|
+
}
|
|
592
|
+
} catch (error) { toast(said(error, 'FloLess couldn’t put the email text together just now. Try again.'), 'warn'); }
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
async function repair() {
|
|
596
|
+
const mine = state;
|
|
597
|
+
try {
|
|
598
|
+
const res = await api(`/api/projects/${encodeURIComponent(target().projectId)}/correspondence-rfis/repair`, { method: 'POST', body: JSON.stringify(identity()) });
|
|
599
|
+
if (state !== mine) return;
|
|
600
|
+
if (res.outcome === 'still-quarantined') {
|
|
601
|
+
// Checked, and still not a file FloLess can read: say why, and keep it set aside.
|
|
602
|
+
mine.view = { ...mine.view, repairError: res.message || 'The file there still isn’t a valid RFI file.' };
|
|
603
|
+
mine.focusAfter = '[data-pr-repair]';
|
|
604
|
+
paint();
|
|
605
|
+
announce(mine.view.repairError);
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
toast('The RFI file reads correctly now.', 'ok');
|
|
609
|
+
mine.view.repairError = null;
|
|
610
|
+
mine.focusAfter = '[data-pr-heading]';
|
|
611
|
+
await load();
|
|
612
|
+
} catch (error) {
|
|
613
|
+
if (state !== mine) return;
|
|
614
|
+
mine.view = { ...mine.view, repairError: said(error, 'FloLess couldn’t check the file just now. Try again.') };
|
|
615
|
+
mine.focusAfter = '[data-pr-repair]';
|
|
616
|
+
paint();
|
|
617
|
+
announce(mine.view.repairError);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// ── New RFI (the sheet: the form, or the Cite picker in its place) ──────────────────────────────────────────────
|
|
622
|
+
|
|
623
|
+
const $sheet = document.getElementById('project-rfi-sheet');
|
|
624
|
+
const $panel = $sheet?.querySelector('.pa-sheet');
|
|
625
|
+
const $title = document.getElementById('pr-title');
|
|
626
|
+
const $sub = document.getElementById('pr-sub');
|
|
627
|
+
const $body = document.getElementById('pr-body');
|
|
628
|
+
const $foot = document.getElementById('pr-foot');
|
|
629
|
+
let sheet = null; // { returnFocus, mode, key, title, question, to, cites, error, uncertain, busy, citable, query, picks, pickerError }
|
|
630
|
+
|
|
631
|
+
function openSheet(returnFocus, prefill = null) {
|
|
632
|
+
if (!$sheet || !target()) return;
|
|
633
|
+
sheet = { returnFocus: returnFocus || document.activeElement, mode: 'form', key: newKey(), title: prefill?.title || '', question: prefill?.question || '',
|
|
634
|
+
to: '', cites: prefill?.cites || [], error: null, uncertain: false, busy: false, citable: null, query: '', picks: null };
|
|
635
|
+
paintSheet();
|
|
636
|
+
$sheet.classList.add('show');
|
|
637
|
+
requestAnimationFrame(() => $body?.querySelector('[data-pr-field="title"]')?.focus());
|
|
638
|
+
}
|
|
639
|
+
function closeSheet({ restoreFocus = true } = {}) {
|
|
640
|
+
if (!$sheet?.classList.contains('show')) return;
|
|
641
|
+
$sheet.classList.remove('show');
|
|
642
|
+
const back = sheet?.returnFocus;
|
|
643
|
+
sheet = null;
|
|
644
|
+
if (restoreFocus) {
|
|
645
|
+
const id = back?.getAttribute?.('data-command-id');
|
|
646
|
+
(back && document.contains(back) ? back : id ? [...document.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === id) : null)?.focus?.();
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
function readSheet() {
|
|
650
|
+
if (!sheet || sheet.mode !== 'form' || sheet.uncertain) return;
|
|
651
|
+
for (const el of $body.querySelectorAll('[data-pr-field]')) sheet[el.getAttribute('data-pr-field')] = el.value;
|
|
652
|
+
}
|
|
653
|
+
const citeKey = (c) => (c.kind === 'knowledge-page' ? `k:${c.slug}` : `d:${c.linkedProjectUuid}:${c.pageId}:${c.sourceHash}`);
|
|
654
|
+
|
|
655
|
+
function paintSheet() {
|
|
656
|
+
const t = target();
|
|
657
|
+
if (!sheet || !t) return;
|
|
658
|
+
if (sheet.mode === 'pick') { paintPicker(); return; }
|
|
659
|
+
$title.textContent = 'New RFI';
|
|
660
|
+
$sub.textContent = `A question from “${t.name}”. FloLess keeps it; after filing you can send it with Gmail or copy its email text.`;
|
|
661
|
+
const ro = sheet.uncertain || sheet.busy ? ' readonly' : '';
|
|
662
|
+
const chips = sheet.cites.map((c, i) => `<span class="pw-chip pr-cite${c.changed ? ' is-muted' : ''}" role="listitem">${esc(citeLabel(c))}${c.changed ? ' · changed' : ''}
|
|
663
|
+
<button type="button" class="pr-chip-x" data-pr-uncite="${i}" aria-label="${esc(`Remove ${citeLabel(c)}`)}" data-command-id="shell.project-rfi-cite-remove#${esc(citeKey(c))}"
|
|
664
|
+
data-command-instance-label="${esc(citeLabel(c))}"${sheet.uncertain ? ' disabled' : ''}>✕</button></span>`).join('');
|
|
665
|
+
const full = sheet.cites.length >= MAX_CITES;
|
|
666
|
+
const banner = sheet.uncertain
|
|
667
|
+
? `<div class="pm-note pr-alert" role="alert">FloLess couldn’t confirm it was filed. It may already be in the list. To change something, choose Edit; FloLess will treat it as a new RFI.</div>`
|
|
668
|
+
: sheet.error ? `<div class="pm-note pr-alert" role="alert">${esc(sheet.error)}</div>` : '';
|
|
669
|
+
$body.innerHTML = `${banner}
|
|
670
|
+
<label class="pr-field">Title<input class="pr-input" data-pr-field="title" maxlength="120" value="${esc(sheet.title)}" data-command-id="shell.project-rfi-title"${ro}></label>
|
|
671
|
+
<label class="pr-field">Question<textarea class="pr-input pr-text" data-pr-field="question" rows="6" maxlength="4000" data-command-id="shell.project-rfi-question"${ro}>${esc(sheet.question)}</textarea></label>
|
|
672
|
+
<div class="pr-field"><span>Cited</span>
|
|
673
|
+
<div class="pr-cites" role="list" aria-label="Cited items">${chips || '<span class="pg-row-meta">Nothing cited yet. You can cite up to 5 items.</span>'}</div>
|
|
674
|
+
<p><button type="button" class="ghost" data-pr-cite="1" aria-haspopup="listbox" data-command-id="shell.project-rfi-cite"
|
|
675
|
+
data-tip="${full ? 'You can cite up to 5 items. Remove one to cite another.' : 'Cite a page of this project’s Knowledge or a saved sheet of a linked project'}"${full || sheet.uncertain ? ' aria-disabled="true"' : ''}>Cite…</button></p></div>
|
|
676
|
+
<label class="pr-field">To (optional)<input type="email" class="pr-input" data-pr-field="to" value="${esc(sheet.to)}" autocomplete="email" data-command-id="shell.project-rfi-to"${ro}>
|
|
677
|
+
<span class="pg-row-meta">Only needed to record who you sent it to.</span></label>`;
|
|
678
|
+
$foot.innerHTML = sheet.uncertain
|
|
679
|
+
? `<button type="button" class="ghost" data-pr-sheet-edit="1" data-command-id="shell.project-rfi-edit">Edit</button>
|
|
680
|
+
<button type="button" class="ghost" data-pr-sheet-check="1" data-command-id="shell.project-rfi-check-list">Check the list</button>
|
|
681
|
+
<button type="button" class="primary" data-pr-sheet-retry="1" data-command-id="shell.project-rfi-retry">Try again</button>`
|
|
682
|
+
: `<button type="button" class="ghost" data-pr-sheet-cancel="1" data-command-id="shell.project-rfi-cancel">Cancel</button>
|
|
683
|
+
<button type="button" class="ghost" data-pr-sheet-file="sent" data-command-id="shell.project-rfi-file-and-mark-sent"
|
|
684
|
+
data-tip="Files the RFI and records that you’ve already sent it to this person yourself. It sends nothing."${sheet.busy ? ' disabled' : ''}>File and mark sent</button>
|
|
685
|
+
<button type="button" class="primary" data-pr-sheet-file="file" data-command-id="shell.project-rfi-file"${sheet.busy ? ' disabled' : ''}>${sheet.busy ? 'Filing…' : 'File'}</button>`;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
async function loadCitable() {
|
|
689
|
+
const mine = sheet;
|
|
690
|
+
const t = target();
|
|
691
|
+
if (!mine || !t) return;
|
|
692
|
+
const generation = (mine.pickGeneration = (mine.pickGeneration || 0) + 1);
|
|
693
|
+
try {
|
|
694
|
+
const q = mine.query ? `?q=${encodeURIComponent(mine.query)}` : '';
|
|
695
|
+
const data = await api(`/api/projects/${encodeURIComponent(t.projectId)}/correspondence-rfis/citable${q}`);
|
|
696
|
+
if (sheet !== mine || mine.pickGeneration !== generation) return;
|
|
697
|
+
mine.citable = data; mine.pickerError = null;
|
|
698
|
+
} catch (error) {
|
|
699
|
+
if (sheet !== mine || mine.pickGeneration !== generation) return;
|
|
700
|
+
mine.pickerError = said(error, 'FloLess couldn’t list what can be cited just now. Try again.');
|
|
701
|
+
}
|
|
702
|
+
if (sheet === mine && mine.mode === 'pick') paintPicker();
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function optionHtml(c, picked) {
|
|
706
|
+
const k = citeKey(c);
|
|
707
|
+
return `<button type="button" class="pr-option" role="option" aria-selected="${picked}" data-pr-option="${esc(k)}"
|
|
708
|
+
data-command-id="shell.project-rfi-cite-option#${esc(k)}" data-command-instance-label="${esc(citeLabel(c))}">
|
|
709
|
+
<span class="pr-check" aria-hidden="true">${picked ? '✓' : ''}</span><span class="pg-row-title">${esc(c.kind === 'knowledge-page' ? c.title : c.sheet)}</span>
|
|
710
|
+
${c.kind === 'linked-drawing' && c.pageNumber ? `<span class="pg-row-meta">page ${esc(c.pageNumber)}</span>` : ''}</button>`;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function paintPicker() {
|
|
714
|
+
const mine = sheet;
|
|
715
|
+
$title.textContent = 'Cite';
|
|
716
|
+
$sub.textContent = 'A page of this project’s Knowledge, or a saved sheet of a project linked on its Modules step.';
|
|
717
|
+
const picks = mine.picks;
|
|
718
|
+
const search = `<input type="search" class="ws-landing-search pr-search" data-pr-search="1" placeholder="Filter" aria-label="Filter what can be cited" value="${esc(mine.query)}" data-command-id="shell.project-rfi-cite-search">`;
|
|
719
|
+
let groups = '';
|
|
720
|
+
if (mine.pickerError) groups = `<p class="pm-note pr-alert" role="alert">${esc(mine.pickerError)}</p>`;
|
|
721
|
+
else if (!mine.citable) groups = '<p class="pg-loading-line">Loading…</p>';
|
|
722
|
+
else {
|
|
723
|
+
const k = mine.citable.knowledge;
|
|
724
|
+
const kOptions = k.state === 'ok' ? k.pages.map((p) => ({ kind: 'knowledge-page', generationId: k.generationId, slug: p.slug, title: p.title })) : [];
|
|
725
|
+
const kBody = k.state === 'ok' ? (kOptions.length ? kOptions.map((c) => optionHtml(c, picks.has(citeKey(c)))).join('') : '<p class="pm-note">No page matches.</p>')
|
|
726
|
+
: k.state === 'none' ? '<p class="pm-note">This project has no published Knowledge pages yet.</p>'
|
|
727
|
+
: '<p class="pm-note">FloLess couldn’t list this project’s Knowledge just now.</p>';
|
|
728
|
+
groups = `<div role="group" aria-labelledby="pr-g-k"><p class="pr-group" id="pr-g-k">This project’s Knowledge</p>${kBody}</div>`;
|
|
729
|
+
mine.citable.linked.forEach((l, i) => {
|
|
730
|
+
const options = (l.sheets || []).map((s) => ({ kind: 'linked-drawing', linkedProjectUuid: l.projectUuid, linkedProjectName: l.name, pageId: s.pageId, sourceHash: s.sourceHash, sheet: s.sheet, pageNumber: s.pageNumber }));
|
|
731
|
+
const body = l.state === 'ok' ? (options.length ? options.map((c) => optionHtml(c, picks.has(citeKey(c)))).join('') : '<p class="pm-note">No sheet matches.</p>')
|
|
732
|
+
: l.state === 'empty' ? '<p class="pm-note">No saved sheets to cite yet. Open it and save its Drawing Filter.</p>'
|
|
733
|
+
: `<p class="pm-note">${esc(l.reason || 'Its sheets can’t be read just now.')}</p>${l.state === 'unavailable' ? `<p><button type="button" class="ghost" data-pr-cite-retry="1"
|
|
734
|
+
data-command-id="shell.project-rfi-cite-retry#${esc(l.projectUuid)}" data-command-instance-label="${esc(l.name)}">Try again</button></p>` : ''}`;
|
|
735
|
+
groups += `<div role="group" aria-labelledby="pr-g-${i}"><p class="pr-group" id="pr-g-${i}">Saved sheets in ${esc(l.name)}</p>${body}</div>`;
|
|
736
|
+
});
|
|
737
|
+
mine.options = new Map([...kOptions, ...mine.citable.linked.flatMap((l) => (l.sheets || []).map((s) => ({ kind: 'linked-drawing', linkedProjectUuid: l.projectUuid, linkedProjectName: l.name, pageId: s.pageId, sourceHash: s.sourceHash, sheet: s.sheet, pageNumber: s.pageNumber })))].map((c) => [citeKey(c), c]));
|
|
738
|
+
}
|
|
739
|
+
const hadFocus = document.activeElement?.hasAttribute?.('data-pr-search');
|
|
740
|
+
$body.innerHTML = `${search}<p class="sr-only pr-pick-live" role="status" aria-live="polite"></p><div class="pr-options" role="listbox" aria-multiselectable="true" aria-label="What can be cited">${groups}</div>`;
|
|
741
|
+
if (hadFocus) { const input = $body.querySelector('[data-pr-search]'); input?.focus(); input?.setSelectionRange?.(mine.query.length, mine.query.length); }
|
|
742
|
+
$foot.innerHTML = `<button type="button" class="ghost" data-pr-pick-back="1" data-command-id="shell.project-rfi-cite-back">← Back to the RFI</button>
|
|
743
|
+
<button type="button" class="primary" data-pr-pick-done="1" data-command-id="shell.project-rfi-cite-done">${picks.size ? `Cite ${picks.size}` : 'Cite none'}</button>`;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
function openPicker() {
|
|
747
|
+
readSheet();
|
|
748
|
+
sheet.mode = 'pick';
|
|
749
|
+
sheet.picks = new Map(sheet.cites.map((c) => [citeKey(c), c]));
|
|
750
|
+
paintPicker();
|
|
751
|
+
requestAnimationFrame(() => $body.querySelector('[data-pr-search]')?.focus());
|
|
752
|
+
void loadCitable();
|
|
753
|
+
}
|
|
754
|
+
function closePicker(apply) {
|
|
755
|
+
if (apply) sheet.cites = [...sheet.picks.values()].map((c) => ({ ...c, changed: false }));
|
|
756
|
+
sheet.mode = 'form';
|
|
757
|
+
paintSheet();
|
|
758
|
+
requestAnimationFrame(() => $body.querySelector('[data-pr-cite]')?.focus());
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
async function fileRfi(markSent) {
|
|
762
|
+
const mine = sheet;
|
|
763
|
+
const t = target();
|
|
764
|
+
if (!mine || mine.busy || !t) return;
|
|
765
|
+
readSheet();
|
|
766
|
+
const title = mine.title.trim(), question = mine.question.trim(), to = mine.to.trim();
|
|
767
|
+
const problem = !title ? ['title', 'Give the RFI a title.'] : !question ? ['question', 'Write the question.']
|
|
768
|
+
: markSent && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(to) ? ['to', 'Add who you sent it to, or use File.'] : null;
|
|
769
|
+
if (problem) {
|
|
770
|
+
mine.error = problem[1]; paintSheet();
|
|
771
|
+
const field = $body.querySelector(`[data-pr-field="${problem[0]}"]`);
|
|
772
|
+
field?.setAttribute('aria-invalid', 'true'); field?.focus();
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (!mine.uncertain) mine.payload = { ...identity(), operationKey: mine.key, title, question,
|
|
776
|
+
citations: mine.cites.map((c) => (c.kind === 'knowledge-page' ? { kind: c.kind, generationId: c.generationId, slug: c.slug }
|
|
777
|
+
: { kind: c.kind, linkedProjectUuid: c.linkedProjectUuid, pageId: c.pageId, sourceHash: c.sourceHash })),
|
|
778
|
+
...(markSent ? { markSentTo: to } : {}) };
|
|
779
|
+
mine.busy = true; mine.error = null; paintSheet();
|
|
780
|
+
try {
|
|
781
|
+
const res = await api(`/api/projects/${encodeURIComponent(t.projectId)}/correspondence-rfis`, { method: 'POST', body: JSON.stringify(mine.payload) });
|
|
782
|
+
if (sheet !== mine) return;
|
|
783
|
+
const id = res.rfi.id;
|
|
784
|
+
closeSheet({ restoreFocus: false });
|
|
785
|
+
toast(mine.payload.markSentTo ? `${id} filed and marked as sent to ${mine.payload.markSentTo}. FloLess hasn’t sent anything itself.` : `${id} filed. Send it with Gmail or copy its email text.`, 'ok');
|
|
786
|
+
if (state) {
|
|
787
|
+
if (state.filter === 'closed') state.filter = 'open';
|
|
788
|
+
state.quietLoad = true;
|
|
789
|
+
state.focusAfter = `[data-pr-title="${id}"]`;
|
|
790
|
+
await load();
|
|
791
|
+
announce(`${id} filed.`);
|
|
792
|
+
}
|
|
793
|
+
} catch (error) {
|
|
794
|
+
if (sheet !== mine) return;
|
|
795
|
+
mine.busy = false;
|
|
796
|
+
if (refused(error)) {
|
|
797
|
+
mine.error = said(error, 'FloLess couldn’t file it just now. Try again.');
|
|
798
|
+
mine.uncertain = false;
|
|
799
|
+
mine.key = newKey(); // the next send after a refusal is a new intent
|
|
800
|
+
if (/^citation-/.test(error.body.code || '')) mine.cites = mine.cites.map((c) => ({ ...c, changed: true }));
|
|
801
|
+
} else {
|
|
802
|
+
mine.uncertain = true; // same key, same payload on Try again
|
|
803
|
+
}
|
|
804
|
+
paintSheet();
|
|
805
|
+
($foot.querySelector(mine.uncertain ? '[data-pr-sheet-retry]' : '[data-pr-sheet-file="file"]'))?.focus();
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// ── events ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
810
|
+
|
|
811
|
+
document.addEventListener('click', (event) => {
|
|
812
|
+
const t = event.target;
|
|
813
|
+
if (sheet && $sheet?.contains(t)) {
|
|
814
|
+
if (t.closest('#pr-close') || t.closest('[data-pr-sheet-cancel]')) { closeSheet(); return; }
|
|
815
|
+
if (t === $sheet) { closeSheet(); return; }
|
|
816
|
+
const file = t.closest('[data-pr-sheet-file]');
|
|
817
|
+
if (file) { void fileRfi(file.getAttribute('data-pr-sheet-file') === 'sent'); return; }
|
|
818
|
+
if (t.closest('[data-pr-sheet-retry]')) { void fileRfi(!!sheet.payload?.markSentTo); return; }
|
|
819
|
+
if (t.closest('[data-pr-sheet-edit]')) { sheet.uncertain = false; sheet.key = newKey(); paintSheet(); $body.querySelector('[data-pr-field="title"]')?.focus(); return; }
|
|
820
|
+
if (t.closest('[data-pr-sheet-check]')) { closeSheet(); if (state) void load(); return; }
|
|
821
|
+
const cite = t.closest('[data-pr-cite]');
|
|
822
|
+
if (cite) { if (cite.getAttribute('aria-disabled') === 'true') { toast('You can cite up to 5 items. Remove one to cite another.', 'info'); return; } openPicker(); return; }
|
|
823
|
+
const uncite = t.closest('[data-pr-uncite]');
|
|
824
|
+
if (uncite) { readSheet(); sheet.cites.splice(Number(uncite.getAttribute('data-pr-uncite')), 1); paintSheet(); $body.querySelector('[data-pr-cite]')?.focus(); return; }
|
|
825
|
+
const option = t.closest('[data-pr-option]');
|
|
826
|
+
if (option) {
|
|
827
|
+
const k = option.getAttribute('data-pr-option');
|
|
828
|
+
if (sheet.picks.has(k)) sheet.picks.delete(k);
|
|
829
|
+
else if (sheet.picks.size >= MAX_CITES) { const live = $body.querySelector('.pr-pick-live'); if (live) live.textContent = 'You can cite up to 5 items.'; return; }
|
|
830
|
+
else sheet.picks.set(k, sheet.options.get(k));
|
|
831
|
+
paintPicker();
|
|
832
|
+
$body.querySelector(`[data-pr-option="${CSS.escape(k)}"]`)?.focus();
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
if (t.closest('[data-pr-cite-retry]')) { sheet.citable = null; paintPicker(); void loadCitable(); return; }
|
|
836
|
+
if (t.closest('[data-pr-pick-back]')) { closePicker(false); return; }
|
|
837
|
+
if (t.closest('[data-pr-pick-done]')) { closePicker(true); return; }
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
if (!state || !state.pane.contains(t)) return;
|
|
841
|
+
if (t.closest('[data-pr-new]')) { event.preventDefault(); openSheet(t.closest('[data-pr-new]')); return; }
|
|
842
|
+
const filter = t.closest('[data-pr-filter]');
|
|
843
|
+
if (filter) {
|
|
844
|
+
readDraft(); // an open form keeps what was typed across the repaint
|
|
845
|
+
state.filter = filter.getAttribute('data-pr-filter');
|
|
846
|
+
state.focusAfter = `[data-pr-filter="${state.filter}"][aria-pressed]`;
|
|
847
|
+
paint();
|
|
848
|
+
const n = visible(state.view.data.rfis, state.filter).length;
|
|
849
|
+
announce(`Showing ${n} ${state.filter === 'all' ? '' : `${state.filter} `}RFI${n === 1 ? '' : 's'}`);
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
const held = t.closest('[data-blocked-reason][aria-disabled="true"]');
|
|
853
|
+
if (held) { toast(held.getAttribute('data-blocked-reason'), 'info'); return; }
|
|
854
|
+
const gmail = t.closest('[data-pr-gmail]');
|
|
855
|
+
if (gmail) { openForm(gmail.getAttribute('data-pr-gmail'), 'gmail'); return; }
|
|
856
|
+
if (t.closest('[data-pr-gmail-integrations]')) { readDraft(); if (typeof window.openIntegrations === 'function') window.openIntegrations('google-workspace'); return; }
|
|
857
|
+
if (t.closest('[data-pr-gmail-recheck]')) { void checkReadiness(); return; }
|
|
858
|
+
if (t.closest('[data-pr-gmail-check]')) { state.form = null; state.quietLoad = true; void load(); return; }
|
|
859
|
+
const cont = t.closest('[data-pr-gmail-continue]');
|
|
860
|
+
if (cont) { if (cont.getAttribute('aria-disabled') !== 'true') void recoverGmail(cont.getAttribute('data-pr-gmail-continue'), cont.getAttribute('data-pr-attempt'), 'continue'); return; }
|
|
861
|
+
const confirm = t.closest('[data-pr-gmail-confirm]');
|
|
862
|
+
if (confirm) { if (confirm.getAttribute('aria-disabled') !== 'true') void recoverGmail(confirm.getAttribute('data-pr-gmail-confirm'), confirm.getAttribute('data-pr-attempt'), 'confirm-sent'); return; }
|
|
863
|
+
const marker = t.closest('[data-pr-gmail-marker]');
|
|
864
|
+
if (marker) { void copyMarker(marker.getAttribute('data-pr-gmail-marker')); return; }
|
|
865
|
+
const verb = t.closest('[data-pr-verb]');
|
|
866
|
+
if (verb) { openForm(verb.getAttribute('data-pr-rfi'), verb.getAttribute('data-pr-verb')); return; }
|
|
867
|
+
if (t.closest('[data-pr-form-cancel]')) { if (state.form?.busy) return; closeForm(); return; }
|
|
868
|
+
if (t.closest('[data-pr-form-submit]')) { void submitForm(); return; }
|
|
869
|
+
if (t.closest('[data-pr-form-edit]')) { const f = state.form; f.uncertain = false; f.sent = null; f.key = newKey(); f.error = null;
|
|
870
|
+
state.focusAfter = f.verb === 'close' ? '.pr-form [data-pr-disposition]' : '.pr-form [data-pr-input]'; paint(); return; }
|
|
871
|
+
if (t.closest('[data-pr-form-again]')) { readDraft(); const f = state.form; f.stale = false; f.error = null; void load().then(() => { if (state?.form === f) paint(); }); return; }
|
|
872
|
+
const radio = t.closest('[data-pr-disposition]');
|
|
873
|
+
if (radio) { if (state.form.uncertain || radio.disabled) return; readDraft(); state.form.draft.disposition = radio.getAttribute('data-pr-disposition'); state.form.error = null;
|
|
874
|
+
state.focusAfter = `[data-pr-disposition="${state.form.draft.disposition}"]`; paint(); return; }
|
|
875
|
+
const copy = t.closest('[data-pr-copy]');
|
|
876
|
+
if (copy) { void copyText(copy.getAttribute('data-pr-copy')); return; }
|
|
877
|
+
const again = t.closest('[data-pr-again]');
|
|
878
|
+
if (again) {
|
|
879
|
+
const rfi = state.view.data.rfis.find((r) => r.id === again.getAttribute('data-pr-again'));
|
|
880
|
+
if (rfi) openSheet(again, { title: rfi.title, question: rfi.question,
|
|
881
|
+
// A page that reads current in a newer Knowledge version is cited there: a filing names the version published now.
|
|
882
|
+
cites: rfi.citations.filter((c) => c.state === 'current').map(({ state: _s, reason: _r, refileGenerationId, ...c }) => (
|
|
883
|
+
c.kind === 'knowledge-page' && refileGenerationId ? { ...c, generationId: refileGenerationId } : c)) });
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
if (t.closest('[data-pr-retry]')) { state.view = { status: 'loading', data: null }; paint(); void load(); return; }
|
|
887
|
+
if (t.closest('[data-pr-repair]')) { void repair(); }
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
document.addEventListener('input', (event) => {
|
|
891
|
+
const search = event.target.closest?.('[data-pr-search]');
|
|
892
|
+
if (search && sheet) {
|
|
893
|
+
sheet.query = search.value;
|
|
894
|
+
clearTimeout(sheet.timer);
|
|
895
|
+
sheet.timer = setTimeout(() => void loadCitable(), 200);
|
|
896
|
+
}
|
|
897
|
+
if (sheet && event.target.closest?.('[data-pr-field]')) event.target.removeAttribute('aria-invalid');
|
|
898
|
+
});
|
|
899
|
+
|
|
900
|
+
document.addEventListener('keydown', (event) => {
|
|
901
|
+
if (sheet && $sheet?.classList.contains('show')) {
|
|
902
|
+
if (event.key === 'Escape') { event.preventDefault(); if (sheet.mode === 'pick') closePicker(false); else closeSheet(); return; }
|
|
903
|
+
if (event.key === 'Tab' && $panel) {
|
|
904
|
+
// Keep the keyboard inside the sheet.
|
|
905
|
+
const focusables = [...$panel.querySelectorAll('button:not([disabled]), input, textarea, [tabindex="0"]')].filter((el) => el.offsetParent !== null || el === document.activeElement);
|
|
906
|
+
if (!focusables.length) return;
|
|
907
|
+
const first = focusables[0], last = focusables[focusables.length - 1];
|
|
908
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
909
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
910
|
+
}
|
|
911
|
+
if ((event.key === 'ArrowDown' || event.key === 'ArrowUp') && event.target.closest?.('[data-pr-option], [data-pr-search]')) {
|
|
912
|
+
const options = [...$body.querySelectorAll('[data-pr-option]')];
|
|
913
|
+
const i = options.indexOf(document.activeElement);
|
|
914
|
+
const next = event.key === 'ArrowDown' ? options[Math.min(options.length - 1, i + 1)] : options[Math.max(0, i - 1)];
|
|
915
|
+
if (next) { event.preventDefault(); next.focus(); }
|
|
916
|
+
}
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
if (!state || !state.pane.contains(event.target)) return;
|
|
920
|
+
if (event.key === 'Escape' && state.form && event.target.closest('.pr-form')) { event.preventDefault(); if (!state.form.busy) closeForm(); return; }
|
|
921
|
+
if (event.key === 'Enter' && state.form?.verb === 'gmail' && event.target.matches?.('[data-pr-input="to"]')) { event.preventDefault(); void submitForm(); return; }
|
|
922
|
+
// The disposition choice is a radio group: arrows move and choose.
|
|
923
|
+
const radio = event.target.closest?.('[data-pr-disposition]');
|
|
924
|
+
if (radio && ['ArrowDown', 'ArrowRight', 'ArrowUp', 'ArrowLeft'].includes(event.key)) {
|
|
925
|
+
const radios = [...state.pane.querySelectorAll('[data-pr-disposition]')];
|
|
926
|
+
const i = radios.indexOf(radio);
|
|
927
|
+
const next = radios[(i + (event.key === 'ArrowDown' || event.key === 'ArrowRight' ? 1 : radios.length - 1)) % radios.length];
|
|
928
|
+
event.preventDefault();
|
|
929
|
+
next.click();
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* The sentence a Duplicate or Import adds about a General project's RFIs (#2470 R6.6). Null when there is nothing to
|
|
935
|
+
* say. A source that could not be carried is said, never turned into silence.
|
|
936
|
+
*/
|
|
937
|
+
function transferNote(raw, operation = 'duplicate') {
|
|
938
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
939
|
+
if (raw.outcome === 'complete' && raw.carried > 0) {
|
|
940
|
+
return { text: `${raw.carried} RFI${raw.carried === 1 ? '' : 's'} came with it, open again; ${raw.carried === 1 ? 'its' : 'their'} sends and answers stay with the original.`, warn: false };
|
|
941
|
+
}
|
|
942
|
+
if (raw.outcome === 'refused') {
|
|
943
|
+
const where = operation === 'import' ? 'They are still in the archive.' : 'The original keeps them.';
|
|
944
|
+
const why = raw.reason === 'newer-version' ? 'they were saved by a newer FloLess' : raw.reason === 'poisoned' ? 'the RFI file was set aside as unreadable' : 'the RFI file couldn’t be read';
|
|
945
|
+
return { text: `Its RFIs didn’t come with it: ${why}. ${where}`, warn: true };
|
|
946
|
+
}
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
window.addEventListener('floless:projects-changed', refresh);
|
|
951
|
+
// Back from Integrations (or any window): a send that waited on Google may be possible now.
|
|
952
|
+
window.addEventListener('focus', () => { if (state && shown(state.pane) && state.readiness?.status !== 'ready' && !state.form?.busy) void checkReadiness(); });
|
|
953
|
+
window.flolessProjectRfis = { render, refresh, html, transferNote };
|
|
954
|
+
})();
|