it: не дублировать списки аптек и сотрудников в каждом ряду оборудования.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -11,6 +11,39 @@ function itTabSwitch(tab) {
|
||||
});
|
||||
}
|
||||
|
||||
function itFillAssignOptions(root) {
|
||||
if (!root || root.getAttribute('data-it-options-filled') === '1') return;
|
||||
['pharmacy', 'office', 'employee'].forEach(function (kind) {
|
||||
var src = document.getElementById('it-options-' + kind);
|
||||
if (!src) return;
|
||||
root.querySelectorAll('select[data-it-options="' + kind + '"]').forEach(function (sel) {
|
||||
if (sel.getAttribute('data-it-options-ready') === '1') return;
|
||||
var current = sel.value;
|
||||
var currentLabel = '';
|
||||
var curOpt = sel.options[sel.selectedIndex];
|
||||
if (curOpt && curOpt.value) currentLabel = curOpt.textContent;
|
||||
var empty = sel.querySelector('option[value=""]');
|
||||
sel.innerHTML = '';
|
||||
if (empty) sel.appendChild(empty);
|
||||
Array.prototype.forEach.call(src.options, function (opt) {
|
||||
sel.appendChild(opt.cloneNode(true));
|
||||
});
|
||||
if (current) {
|
||||
sel.value = current;
|
||||
if (sel.value !== current) {
|
||||
var extra = document.createElement('option');
|
||||
extra.value = current;
|
||||
extra.textContent = currentLabel || current;
|
||||
extra.selected = true;
|
||||
sel.appendChild(extra);
|
||||
}
|
||||
}
|
||||
sel.setAttribute('data-it-options-ready', '1');
|
||||
});
|
||||
});
|
||||
root.setAttribute('data-it-options-filled', '1');
|
||||
}
|
||||
|
||||
function itToggleRow(key) {
|
||||
var row = document.getElementById('it-row-' + key);
|
||||
var toggle = document.getElementById('it-toggle-' + key);
|
||||
@@ -18,6 +51,10 @@ function itToggleRow(key) {
|
||||
var opening = row.style.display === 'none';
|
||||
row.style.display = opening ? 'table-row' : 'none';
|
||||
if (toggle) toggle.style.transform = opening ? 'rotate(90deg)' : '';
|
||||
if (opening) {
|
||||
itFillAssignOptions(row);
|
||||
if (typeof initSearchableSelects === 'function') initSearchableSelects(row);
|
||||
}
|
||||
}
|
||||
|
||||
function itIsModal(panel) {
|
||||
|
||||
@@ -196,6 +196,8 @@
|
||||
|
||||
window.initSearchableSelects = function (scope) {
|
||||
(scope || document).querySelectorAll('.searchable-select:not([data-searchable-init])').forEach(function (widget) {
|
||||
var hiddenRow = widget.closest('.it-detail-row');
|
||||
if (hiddenRow && hiddenRow.style.display === 'none') return;
|
||||
widget.setAttribute('data-searchable-init', '1');
|
||||
build(widget);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user