it_manager: справочник типовых работ в журнале WorkLog.
Категория/работа/required_details вместо свободного work_type; seed Directory, отчёт и тесты. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -165,6 +165,84 @@ function itSetSearchableSelectValue(selectId, value) {
|
||||
}
|
||||
}
|
||||
|
||||
function itWorkCatalogData() {
|
||||
var el = document.getElementById('it-work-catalog-data');
|
||||
if (!el) return { categories: [], works: [], detail_labels: {} };
|
||||
try {
|
||||
return JSON.parse(el.textContent || '{}');
|
||||
} catch (e) {
|
||||
return { categories: [], works: [], detail_labels: {} };
|
||||
}
|
||||
}
|
||||
|
||||
function itWorklogCategoryChanged() {
|
||||
var cat = document.getElementById('it-worklog-category');
|
||||
var work = document.getElementById('it-worklog-work');
|
||||
if (!work) return;
|
||||
var catId = cat ? cat.value : '';
|
||||
var data = itWorkCatalogData();
|
||||
var works = (data.works || []).filter(function (w) {
|
||||
return !catId || String(w.category_id) === String(catId);
|
||||
});
|
||||
work.innerHTML = '';
|
||||
var empty = document.createElement('option');
|
||||
empty.value = '';
|
||||
empty.textContent = catId ? '— Выберите работу —' : '— Сначала выберите категорию —';
|
||||
work.appendChild(empty);
|
||||
works.forEach(function (w) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = String(w.id);
|
||||
opt.textContent = w.name;
|
||||
work.appendChild(opt);
|
||||
});
|
||||
itWorklogWorkChanged();
|
||||
}
|
||||
|
||||
function itWorklogWorkChanged() {
|
||||
var workSelect = document.getElementById('it-worklog-work');
|
||||
var detailsBox = document.getElementById('it-worklog-details');
|
||||
var notesEl = document.getElementById('it-worklog-work-notes');
|
||||
if (!detailsBox) return;
|
||||
var data = itWorkCatalogData();
|
||||
var labels = data.detail_labels || {};
|
||||
var workId = workSelect ? workSelect.value : '';
|
||||
var work = (data.works || []).find(function (w) { return String(w.id) === String(workId); });
|
||||
detailsBox.innerHTML = '';
|
||||
if (!work || !(work.required_details || []).length) {
|
||||
detailsBox.style.display = 'none';
|
||||
} else {
|
||||
detailsBox.style.display = 'flex';
|
||||
(work.required_details || []).forEach(function (key) {
|
||||
var wrap = document.createElement('div');
|
||||
var label = document.createElement('label');
|
||||
label.style.cssText = 'display:block;font-size:0.8125rem;font-weight:500;color:var(--color-foreground);margin-bottom:0.375rem;';
|
||||
label.textContent = labels[key] || key;
|
||||
var star = document.createElement('span');
|
||||
star.style.color = 'var(--color-destructive)';
|
||||
star.textContent = ' *';
|
||||
label.appendChild(star);
|
||||
var input = document.createElement('input');
|
||||
input.type = 'text';
|
||||
input.name = 'detail_' + key;
|
||||
input.required = true;
|
||||
input.className = 'input';
|
||||
input.style.width = '100%';
|
||||
wrap.appendChild(label);
|
||||
wrap.appendChild(input);
|
||||
detailsBox.appendChild(wrap);
|
||||
});
|
||||
}
|
||||
if (notesEl) {
|
||||
if (work && work.notes) {
|
||||
notesEl.style.display = '';
|
||||
notesEl.textContent = work.notes;
|
||||
} else {
|
||||
notesEl.style.display = 'none';
|
||||
notesEl.textContent = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function itWorklogFromTicket(ticket) {
|
||||
if (!ticket || !ticket.id) return;
|
||||
itTabSwitch('worklog');
|
||||
@@ -187,8 +265,8 @@ function itWorklogFromTicket(ticket) {
|
||||
hint.style.display = '';
|
||||
hint.textContent = 'Заявка ' + ticket.number + (ticket.title ? ' — ' + ticket.title : '');
|
||||
}
|
||||
var typeSelect = document.getElementById('it-worklog-type');
|
||||
if (typeSelect) typeSelect.focus();
|
||||
var catSelect = document.getElementById('it-worklog-category');
|
||||
if (catSelect) catSelect.focus();
|
||||
}
|
||||
|
||||
function itWorklogTicketChanged() {
|
||||
|
||||
Reference in New Issue
Block a user