Files
ACORE/static/assets/js/it-manager.js
T
lokses 0da9c13192 it_manager+reports: иерархия договоров, биллинг и месячные отчёты
Иерархия рамочных/дочерних договоров и платежей, интернет-биллинг,
месячные IT-отчёты (импорт, DOCX/PDF, шаблоны выводов).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-09 18:03:44 +03:00

267 lines
10 KiB
JavaScript

function itTabSwitch(tab) {
document.querySelectorAll('.it-panel').forEach(function (panel) {
panel.style.display = panel.id === 'it-panel-' + tab ? '' : 'none';
});
document.querySelectorAll('.it-tab-btn').forEach(function (btn) {
var active = btn.getAttribute('data-tab') === tab;
btn.classList.toggle('it-tab-active', active);
btn.style.background = active ? 'var(--color-card)' : 'transparent';
btn.style.color = active ? 'var(--color-card-foreground)' : 'var(--color-muted-foreground)';
btn.style.boxShadow = active ? '0 1px 2px rgb(0 0 0/0.08)' : '';
});
}
function itToggleRow(key) {
var row = document.getElementById('it-row-' + key);
var toggle = document.getElementById('it-toggle-' + key);
if (!row) return;
var opening = row.style.display === 'none';
row.style.display = opening ? 'table-row' : 'none';
if (toggle) toggle.style.transform = opening ? 'rotate(90deg)' : '';
}
function itPanelOpen(id) {
var panel = document.getElementById(id);
var overlay = document.getElementById(id + '-overlay');
if (overlay) overlay.style.display = 'block';
if (panel) panel.style.transform = 'translateX(0)';
document.body.style.overflow = 'hidden';
}
function itPanelClose(id) {
var panel = document.getElementById(id);
var overlay = document.getElementById(id + '-overlay');
if (overlay) overlay.style.display = 'none';
if (panel) panel.style.transform = 'translateX(100%)';
document.body.style.overflow = '';
}
function itContractServiceToggle(serviceTypeCode) {
var block = document.getElementById('it-contract-ip-block');
if (!block) return;
var show = serviceTypeCode === 'internet';
block.style.display = show ? '' : 'none';
if (!show) {
var checkbox = block.querySelector('input[name=dedicated_ip]');
var ipField = document.getElementById('it-contract-ip-field');
if (checkbox) checkbox.checked = false;
if (ipField) ipField.style.display = 'none';
}
}
function itContractFrameworkToggle(isFramework) {
var parentWrap = document.getElementById('it-contract-parent-wrap');
var locationWrap = document.getElementById('it-contract-location-wrap');
var locationSelect = document.getElementById('it-contract-location-select');
var locationRequired = document.getElementById('it-contract-location-required');
if (parentWrap) {
parentWrap.style.display = isFramework ? 'none' : '';
}
if (isFramework) {
var sel = document.getElementById('it-contract-parent-select');
if (sel) sel.value = '';
}
if (locationWrap) {
locationWrap.style.display = isFramework ? 'none' : '';
}
if (locationSelect) {
locationSelect.required = !isFramework;
if (isFramework) locationSelect.value = '';
}
if (locationRequired) {
locationRequired.style.display = isFramework ? 'none' : '';
}
}
function itContractFilterParents() {
var providerSelect = document.getElementById('it-contract-provider-select');
var parentSelect = document.getElementById('it-contract-parent-select');
if (!providerSelect || !parentSelect) return;
var providerId = providerSelect.value;
Array.prototype.forEach.call(parentSelect.options, function (opt) {
if (!opt.value) {
opt.hidden = false;
return;
}
opt.hidden = providerId && opt.getAttribute('data-provider') !== providerId;
});
if (parentSelect.selectedOptions[0] && parentSelect.selectedOptions[0].hidden) {
parentSelect.value = '';
}
}
// --- Масовий вибір екземплярів обладнання ---
// --- Выдача оборудования: тип → список ---
function itAssignTargetChanged(selectEl) {
var root = selectEl.closest('[data-assign-widget]');
if (!root) return;
var target = selectEl.value || '';
root.querySelectorAll('[data-assign-pick]').forEach(function (pick) {
var match = pick.getAttribute('data-assign-pick') === target;
pick.style.display = match ? '' : 'none';
pick.querySelectorAll('select').forEach(function (inp) {
inp.disabled = !match;
if (!match) {
inp.value = '';
// searchable-select слушает change
inp.dispatchEvent(new Event('change', { bubbles: true }));
}
});
});
}
function itBulkToggleAll(headerCheckbox) {
document.querySelectorAll('.it-equip-check').forEach(function (cb) {
cb.checked = headerCheckbox.checked;
});
itBulkUpdate();
}
function itBulkUpdate() {
var checked = Array.prototype.slice.call(document.querySelectorAll('.it-equip-check:checked'));
var panel = document.getElementById('it-equipment-bulk-assign');
var countEl = document.getElementById('it-bulk-assign-count');
var inputs = document.getElementById('it-bulk-assign-inputs');
if (!panel) return;
if (checked.length) {
panel.style.display = 'block';
if (countEl) countEl.textContent = checked.length;
if (inputs) {
// переносимо id відмічених у hidden-поля всередині форми видачі
inputs.innerHTML = '';
checked.forEach(function (cb) {
var hidden = document.createElement('input');
hidden.type = 'hidden';
hidden.name = 'equipment_ids';
hidden.value = cb.value;
inputs.appendChild(hidden);
});
}
} else {
panel.style.display = 'none';
}
}
function itBulkClearSelection() {
document.querySelectorAll('.it-equip-check').forEach(function (cb) { cb.checked = false; });
var headerAll = document.querySelector('th input[onclick^="itBulkToggleAll"]');
if (headerAll) headerAll.checked = false;
itBulkUpdate();
}
function itSetSearchableSelectValue(selectId, value) {
var select = document.getElementById(selectId);
if (!select) return;
select.value = value || '';
select.dispatchEvent(new Event('change', { bubbles: true }));
var widget = select.closest('.searchable-select');
if (widget && widget._search) {
var opt = select.options[select.selectedIndex];
widget._search.value = (opt && opt.value) ? opt.textContent : '';
if (typeof widget._updateClear === 'function') widget._updateClear();
else if (widget._clear) widget._clear.style.display = select.value ? 'flex' : 'none';
}
}
function itWorklogFromTicket(ticket) {
if (!ticket || !ticket.id) return;
itTabSwitch('worklog');
itPanelOpen('it-worklog-panel');
itSetSearchableSelectValue('it-worklog-ticket', String(ticket.id));
if (ticket.locationId) {
itSetSearchableSelectValue('it-worklog-location', String(ticket.locationId));
}
var equipment = document.getElementById('it-worklog-equipment');
if (equipment && ticket.equipmentId) {
equipment.value = String(ticket.equipmentId);
}
var description = document.getElementById('it-worklog-description');
if (description && !description.value) {
description.value = 'Работа по заявке ' + ticket.number + (ticket.title ? ': ' + ticket.title : '');
}
var hint = document.getElementById('it-worklog-ticket-hint');
if (hint) {
hint.style.display = '';
hint.textContent = 'Заявка ' + ticket.number + (ticket.title ? ' — ' + ticket.title : '');
}
var typeSelect = document.getElementById('it-worklog-type');
if (typeSelect) typeSelect.focus();
}
function itWorklogTicketChanged() {
var select = document.getElementById('it-worklog-ticket');
if (!select) return;
var opt = select.options[select.selectedIndex];
var hint = document.getElementById('it-worklog-ticket-hint');
if (!opt || !opt.value) {
if (hint) {
hint.style.display = 'none';
hint.textContent = '';
}
return;
}
var locationId = opt.getAttribute('data-location') || '';
var equipmentId = opt.getAttribute('data-equipment') || '';
if (locationId) itSetSearchableSelectValue('it-worklog-location', locationId);
var equipment = document.getElementById('it-worklog-equipment');
if (equipment && equipmentId) equipment.value = equipmentId;
if (hint) {
hint.style.display = '';
hint.textContent = opt.textContent.trim();
}
}
document.addEventListener('change', function (ev) {
if (ev.target && ev.target.id === 'it-worklog-ticket') {
itWorklogTicketChanged();
}
});
function itReportPreviewOpen(url, title) {
var overlay = document.getElementById('it-report-preview-overlay');
var modal = document.getElementById('it-report-preview-modal');
var frame = document.getElementById('it-report-preview-frame');
var subtitle = document.getElementById('it-report-preview-subtitle');
var openTab = document.getElementById('it-report-preview-open-tab');
if (!overlay || !modal || !frame) return;
if (subtitle) subtitle.textContent = title || '';
if (openTab) openTab.href = url;
frame.src = url;
overlay.style.display = 'block';
modal.style.display = 'flex';
document.body.style.overflow = 'hidden';
}
function itReportPreviewClose() {
var overlay = document.getElementById('it-report-preview-overlay');
var modal = document.getElementById('it-report-preview-modal');
var frame = document.getElementById('it-report-preview-frame');
if (overlay) overlay.style.display = 'none';
if (modal) modal.style.display = 'none';
if (frame) frame.src = 'about:blank';
document.body.style.overflow = '';
}
document.addEventListener('keydown', function (ev) {
if (ev.key !== 'Escape') return;
var modal = document.getElementById('it-report-preview-modal');
if (modal && modal.style.display === 'flex') itReportPreviewClose();
});
document.addEventListener('htmx:afterSwap', function (ev) {
var target = ev.detail && ev.detail.target;
if (!target || target.id !== 'main-content') return;
var root = target.querySelector('[data-it-active-tab]');
if (root && typeof itTabSwitch === 'function') {
itTabSwitch(root.getAttribute('data-it-active-tab') || 'equipment');
}
if (typeof initSearchableSelects === 'function') {
initSearchableSelects(target);
}
});