Files
grabowski 1f526f17f9
CI / secret scan (push) Successful in 6s
CI / fmt, clippy, tests (push) Successful in 43s
CI / release (push) Skipped
Pack print: A4 upright pages, small pictures at their size, card sides on one sheet
Every page of the pack is now A4 upright, so it prints as one stack. A
PDF page or a whole-page picture that lies wider than tall is turned
onto the page (a small one that fits as it is stays as it is), and a
PDF page is only made smaller, never larger.

A picture never prints larger than its resolution allows (the JFIF or
PNG dpi, else 150 dpi), nor larger than its kind's box: passport pages,
visas and stamps 180 x 128 mm, cards 130 x 90 mm, and a phone's
screenshot (the TDAC, or any picture about twice as tall as wide)
150 x 75 mm. These print at the top of the page.

Cards: a new kind "ID card", and the work permit, take two pictures in
one upload as front and back (migration 0008 documents.back_of). The
Documents tab marks them front/back, lists them together and offers
"Print both sides" (.../documents/{id}/sides.pdf); the pack prints both
on one sheet. The client link takes ID cards too. The demo seeds a TDAC
screenshot and an ID card's two sides.

Checks: fmt, clippy, 108 unit and 57 integration tests (print sizes,
dpi reading, the back following its front, the paired upload, its
audit and the sides PDF); the demo pack's pages checked as images.
The Documents tab's actions stack on a phone, so none is cut off.
2026-11-21 18:30:43 +07:00

86 lines
4.8 KiB
HTML

{#- Documents: the upload with what the files are, and the list. A person's
Documents tab and a company's page use them. -#}
{% import "_fields.html" as fm %}
{#- The record a person's document belongs to, by kind of record. -#}
{% macro belongs(value, groups, err="") -%}
<div class="field{% if err %} has-err{% endif %}">
<label for="f-link">Belongs to</label>
<select id="f-link" name="link"{% if err %} aria-invalid="true" aria-describedby="e-link"{% endif %}>
<option value="">The person, no record</option>
{%- for g in groups %}
<optgroup label="{{ g.title }}">
{%- for o in g.options %}
<option value="{{ o[0] }}"{% if o[0] == value %} selected{% endif %}>{{ o[1] }}</option>
{%- endfor %}
</optgroup>
{%- endfor %}
</select>
{%- if err %}
<p class="err" id="e-link">{{ err }}</p>
{%- endif %}
</div>
{%- endmacro %}
{#- The upload: a one-line strip that takes dropped files (the file input
covers it) and the fields that say what they are. The form token comes
first: the server checks it before it reads any file. -#}
{% macro upload(u, csrf, person=true) -%}
{%- if u.files_on %}
<form method="post" action="{{ u.action }}" enctype="multipart/form-data" class="upload" id="upload">
<input type="hidden" name="csrf" value="{{ csrf }}">
{%- if u.errors %}
<div class="notice warn">Nothing was uploaded. Correct what is marked and choose the files again.</div>
{%- endif %}
<div class="drop{% if u.errors.file %} has-err{% endif %}" data-max="{{ u.file_limit }}">
<input type="file" id="f-file" name="file" multiple required accept="application/pdf,image/jpeg,image/png,image/webp" aria-describedby="h-file{% if u.errors.file %} e-file{% endif %}">
<span class="drop-icon" aria-hidden="true">+</span>
<label for="f-file"><b>Choose files</b> or drop them here</label>
<span class="drop-names" data-drop-names></span>
<span class="hint" id="h-file">PDF, JPEG, PNG or WebP, up to {{ u.file_limit_mb }} MB each, {{ u.max_files }} at once. A card's front and back chosen together print on one page.</span>
</div>
{%- if u.errors.file %}
<p class="err" id="e-file">{{ u.errors.file }}</p>
{%- endif %}
<div class="upload-row{% if not person %} company{% endif %}">
{{ fm.select("kind", "What it is", u.values.kind, u.kinds, err=u.errors.kind, blank="Choose", req=true) }}
{%- if person %}
{{ belongs(u.values.link, u.groups, err=u.errors.link) }}
{%- endif %}
{{ fm.text("dated_on", "Date on the document", u.values.dated_on, err=u.errors.dated_on, type="date") }}
{{ fm.text("note", "Note", u.values.note, err=u.errors.note, ph="page 2, certified copy") }}
<div class="upload-go"><button type="submit" class="btn pri" id="upload-btn">Upload</button></div>
</div>
</form>
{%- else %}
<div class="notice warn">Documents are switched off on this server: it has no files directory and file key (VISA_FILES_DIR and VISA_FILES_KEY_FILE).</div>
{%- endif %}
{%- endmacro %}
{#- The list. On phones the date, type and size move under the name. -#}
{% macro table(docs, person=true) -%}
<div class="tblwrap bleed">
<table class="tbl docs" id="doc-list">
<thead><tr><th>Document</th>{% if person %}<th class="hs">Belongs to</th>{% endif %}<th class="hs">Dated</th><th class="hs">File</th><th class="hs">Added</th><th><span class="vh">Actions</span></th></tr></thead>
<tbody>
{%- for d in docs %}
<tr id="doc-{{ d.id }}">
<td class="docname">
<a class="strong" href="{{ d.href }}" target="_blank" rel="noopener">{{ d.kind_label }}</a>{% if d.side == "front" %} <span class="tag plain">front</span>{% elif d.side == "back" %} <span class="tag plain">back</span>{% endif %}
{%- if d.note %}<div class="muted small">{{ d.note }}</div>{% endif %}
<div class="muted small ps">{% if d.dated_on %}{{ d.dated_on }} · {% endif %}{{ d.type_label }}, {{ d.size }}</div>
</td>
{%- if person %}
<td class="hs">{% if d.link_label %}<a href="{{ d.link_href }}">{{ d.link_label }}</a>{% else %}<span class="muted">the person</span>{% endif %}</td>
{%- endif %}
<td class="hs nowrap">{{ d.dated_on }}</td>
<td class="hs"><span class="ftype">{{ d.type_label }}</span> <span class="muted">{{ d.size }}</span><div class="muted small fname" title="{{ d.file_name }}">{{ d.file_name }}</div></td>
<td class="hs nowrap">{{ d.uploaded }}<div class="muted small">{{ d.uploaded_by }}</div></td>
<td class="acts"><a href="{{ d.href }}" target="_blank" rel="noopener">View</a><a href="{{ d.href }}?download=1">Download</a>{% if d.side == "front" %}<a href="{{ d.edit|replace("/edit", "/sides.pdf") }}" target="_blank" rel="noopener">Print both sides</a>{% endif %}<a href="{{ d.edit }}">Edit</a></td>
</tr>
{%- endfor %}
</tbody>
</table>
</div>
{%- endmacro %}