{# _chips_prestatii.html — control unificat chips prestatii. UN singur container `.chips`: chips cod (legate de operatie sau libere), chips warning pentru operatii nemapate, chip `Nedeclarat` pentru itemi exclusi, si selectul unic `chips_pick` la final. Fara `.op-row`, fara butoane Adauga/+ — selectul adauga instant la `change` (POST /form-chips, chips_action=add). Diagrama starii per item (chips_state.items[i]): cod="" & exclus=0 -> chip warning (warn OP-X . fara cod), click = tinta cod="" & exclus=1 -> chip Nedeclarat (line-through), x -> readuce warning cod!="" (op="" sau op!="") -> chip cod (eticheta COD, tooltip = operatia sursa sau "cod adaugat manual") Stare persistata intr-UN SINGUR hidden `chips_state` (JSON versionat) + hidden `chips_target_index` (tinta curenta; comutata CLIENT-SIDE la click pe un chip warning, fara round-trip — indexul pleaca la server abia la urmatorul add) + hidden `chips_submission_id` (ecouat ca sa "salveaza ca regula" ramana disponibil dupa re-randari via /form-chips). Context vars (toate cu defaults): prestatii_chips — list of {cod_prestatie, cod_op_service, denumire, exclus} nomenclator_rar — list of {cod_prestatie, nume_prestatie} pentru select has_r_odo — True daca vreun chip e R-ODO/I-ODO (server-computed) chips_added_index — index-ul chip-ului tocmai adaugat (emfaza chip-nou) chips_target_index — index-ul operatiei tinta curente (sau none) chips_submission_id — id submission cand chips sunt in modalul de detaliu (activeaza butonul "salveaza ca regula") form_chips_url — URL pentru HTMX; default '/form-chips' chips_section_id — ID div (default 'chips-section') csrf_token — CSRF (trecut prin hx-include din form parinte) #} {% set _chips_url = form_chips_url or '/form-chips' %} {% set _sec_id = chips_section_id or 'chips-section' %} {% set _chips = prestatii_chips or [] %} {% set _sub_id = chips_submission_id if (chips_submission_id is defined and chips_submission_id) else '' %} {% set _target_idx = chips_target_index if (chips_target_index is defined and chips_target_index is not none) else none %} {% set _target_op = (_chips[_target_idx].cod_op_service or '') if (_target_idx is not none and _target_idx < _chips | length) else '' %}
{# ===== Stare: UN SINGUR hidden JSON versionat + tinta + submission id ===== #}
{% for chip in _chips %} {% set _idx = loop.index0 %} {% set _is_target = _target_idx is not none and _idx == _target_idx %} {% if chip.cod_op_service and not chip.cod_prestatie and not chip.exclus %} {# ===== Chip warning: operatie nemapata — click comuta tinta client-side ===== #} {% set _label = chip.cod_op_service %} {% set _label_scurt = (_label[:18] ~ '…') if _label | length > 18 else _label %} {% set _title = chip.cod_op_service ~ (' — ' ~ chip.denumire if chip.denumire and chip.denumire != chip.cod_op_service else '') %} {% elif chip.exclus %} {# ===== Chip Nedeclarat: vizibil (line-through), x readuce warning-ul ===== #} Nedeclarat {% elif chip.cod_prestatie %} {# ===== Chip cod: legat de operatie sau liber ===== #} {% set _is_warn = chip.cod_prestatie in ('R-ODO', 'I-ODO') %} {% set _e_nou = (chips_added_index is defined) and chips_added_index is not none and _idx == chips_added_index %} {% set _tooltip = (chip.cod_op_service ~ (' — ' ~ chip.denumire if chip.denumire and chip.denumire != chip.cod_op_service else '')) if chip.cod_op_service else 'cod adaugat manual' %} COD {{ chip.cod_prestatie }} {# "salveaza ca regula op->cod" — apare doar cand submission_id e cunoscut (modalul de detaliu, nu la re-randarea stateless via /form-chips fara ecou). #} {% if _sub_id and chip.cod_op_service and chip.cod_prestatie %} {% endif %} {% endif %} {% endfor %} {# ===== Selectul unic: adauga instant la schimbare, placeholder numeste tinta ===== #} {% if nomenclator_rar %} {% else %} {# T-D1/T-E5 (5.16): empty state cand nomenclatorul lipseste #}
Nomenclator indisponibil — adaugarea de coduri RAR nu e posibila.
{% endif %}
{# Rezultatul ultimei adaugari: refuz (rol=alert) sau confirmare. Clasa chips-extra-error pastrata pe eroare (selector stabil pentru teste/QA). #} {% if chips_error is defined and chips_error %} {% elif chips_ok is defined and chips_ok %}
{{ chips_ok }}
{% endif %}