Files
zoneminder/tests/js
Isaac ConnorandClaude Opus 5 741de2d2e4 fix: finish the review items on the zone object size tool
The four points from the review on #5076 that the first round left open.

Persist a ratio as the number that will be read back. zone.php reloads these
cookies through validInt(), which strips everything that is not a digit, so 70.5
was stored and returned as 705 and 1e2 as 12, while the live calculation took
the same field through parseFloat and used it as typed. The ratio therefore
changed meaning on reload. Round and range-check before storing, and write the
result into the field so what is shown, what is calculated and what is stored
are one number.

Clear the tool when the page's Reset is pressed. Reset restores every field from
initialValues and redraws the polygon, so the measurement Undo would revert is
already gone, but undoSnapshot, lastBox, the highlighting and the rectangle all
survived it. The handler is wrapped rather than joined by a listener because
ours has to run first: resetChanges calls updateArea, which now re-derives.

Re-derive when the zone area changes. The thresholds are stored as percentages
of the zone, so moving, adding or removing a vertex changes what they mean in
pixels and the saved numbers stop describing the object that was measured.
updateArea is the one funnel those edits go through, so wrap it and re-run the
derivation from the box still on screen. apply() only reaches
updateAllPixelDisplays, so there is no way back into updateArea from there.

Draw with pointer events, and give the tool a keyboard-operable equivalent.
pointerdown/move/up with pointer capture replaces the mouse-only gesture, which
touch and pen could not drive at all, and touch-action is suppressed while armed
so the browser does not claim the drag for a scroll. pointercancel ends the drag
too, since a pointer taken away by the browser never sends pointerup. For the
keyboard there is now an object size in capture pixels beside the ratios: it
derives through the same path, draws the same box centred in the frame, and
raises the same filter warning. A finished drag writes its size back into those
fields, so the two ways in stay in step.

Also re-check measurability at pointerdown. The type listener added in the
first round covers the select, but applyPreset writes Type directly and fires
no change event, so a preset that makes the zone Inactive or Privacy left the
tool armed and apply() would re-enable the fields applyZoneType had disabled.

tests/js/zone-object-size.test.js covers the two new pure functions:
46 assertions pass. ESLint clean on the module and the test; php -l clean on
zone.php, zone.js.php and en_gb.php.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 12:14:44 -04:00
..