/** * Сводная таблица доступа: вкл/выкл CUD при смене «Просмотр». */ (function () { 'use strict'; function bindMatrix() { document.querySelectorAll('.access-matrix-row').forEach(function (row) { if (row.getAttribute('data-bound') === '1') return; var sel = row.querySelector('.access-view-select'); var cud = row.querySelector('.access-cud'); if (!sel || !cud) return; row.setAttribute('data-bound', '1'); function sync(fromChange) { var on = sel.value === '1'; cud.style.opacity = on ? '1' : '0.45'; cud.style.pointerEvents = on ? '' : 'none'; if (on && fromChange) { cud.querySelectorAll('input[type=checkbox]').forEach(function (cb) { if (!cb.dataset.touched) cb.checked = true; }); } } cud.querySelectorAll('input[type=checkbox]').forEach(function (cb) { cb.addEventListener('change', function () { cb.dataset.touched = '1'; }); }); sel.addEventListener('change', function () { sync(true); }); sync(false); }); } document.addEventListener('DOMContentLoaded', bindMatrix); document.addEventListener('htmx:afterSwap', bindMatrix); document.addEventListener('htmx:afterSettle', bindMatrix); })();