Филиалы: цвет при создании и редактировании
This commit is contained in:
@@ -39,6 +39,15 @@
|
||||
<input type="text" name="name" class="settings-input" required placeholder="Например: Центральный офис" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-row">
|
||||
<div class="settings-field" style="flex:1">
|
||||
<label>Цвет</label>
|
||||
<div style="display:flex;align-items:center;gap:8px">
|
||||
<input type="color" name="color" id="branchColor" class="settings-input branch-color-input" value="#2563eb">
|
||||
<button type="button" class="btn-primary ghost" id="branchColorRandom" style="padding:6px 10px">Случайный</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-row">
|
||||
<div class="settings-field" style="flex:1">
|
||||
<label>Адрес</label>
|
||||
@@ -100,6 +109,22 @@
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.branch-color-input {
|
||||
width: 72px;
|
||||
height: 34px;
|
||||
padding: 2px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.branch-color-swatch {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid rgba(127,127,127,.4);
|
||||
margin-right: 8px;
|
||||
vertical-align: middle;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.branch-badge {
|
||||
font-size: .7rem;
|
||||
font-weight: 600;
|
||||
|
||||
+18
-2
@@ -1,4 +1,14 @@
|
||||
let branches = [];
|
||||
const BRANCH_COLORS = ['#2563eb', '#7c3aed', '#db2777', '#dc2626', '#ea580c', '#d97706', '#16a34a', '#0d9488', '#0891b2', '#4f46e5', '#9333ea', '#475569'];
|
||||
|
||||
function branchColor(value) {
|
||||
const raw = String(value || '').trim();
|
||||
return /^#[0-9a-fA-F]{6}$/.test(raw) ? raw.toLowerCase() : BRANCH_COLORS[0];
|
||||
}
|
||||
|
||||
function randomBranchColor() {
|
||||
return BRANCH_COLORS[Math.floor(Math.random() * BRANCH_COLORS.length)];
|
||||
}
|
||||
|
||||
async function loadBranches() {
|
||||
const res = await fetch(`${API}/api/branches`, { headers: hdr() });
|
||||
@@ -16,7 +26,7 @@ function renderBranches() {
|
||||
el.innerHTML = branches.map(b => `
|
||||
<div class="branch-card" data-id="${b.id}">
|
||||
<div class="branch-header">
|
||||
<span class="branch-name">${esc(b.name)}</span>
|
||||
<span class="branch-name"><span class="branch-color-swatch" style="background:${branchColor(b.color)}" title="${branchColor(b.color)}"></span>${esc(b.name)}</span>
|
||||
<span class="branch-badge">${b.groups_count} ${plural(b.groups_count, 'группа', 'группы', 'групп')}</span>
|
||||
</div>
|
||||
${b.address ? `<div class="branch-meta">📍 ${esc(b.address)}</div>` : ''}
|
||||
@@ -52,10 +62,12 @@ function openBranchModal(id = null) {
|
||||
form.name.value = b.name;
|
||||
form.address.value = b.address || '';
|
||||
form.phone.value = b.phone || '';
|
||||
document.getElementById('branchColor').value = branchColor(b.color);
|
||||
document.getElementById('branchId').value = b.id;
|
||||
} else {
|
||||
title.textContent = 'Создать филиал';
|
||||
submitBtn.textContent = 'Создать';
|
||||
document.getElementById('branchColor').value = randomBranchColor();
|
||||
}
|
||||
modal.classList.add('open');
|
||||
setTimeout(() => form.name.focus(), 100);
|
||||
@@ -72,6 +84,7 @@ document.getElementById('branchForm').addEventListener('submit', async (e) => {
|
||||
const name = fd.get('name').trim();
|
||||
const address = fd.get('address').trim();
|
||||
const phone = fd.get('phone').trim();
|
||||
const color = branchColor(fd.get('color'));
|
||||
if (!name) { alert('Название обязательно'); return; }
|
||||
|
||||
const url = id ? `${API}/api/branches/${id}` : `${API}/api/branches`;
|
||||
@@ -79,7 +92,7 @@ document.getElementById('branchForm').addEventListener('submit', async (e) => {
|
||||
const res = await fetch(url, {
|
||||
method,
|
||||
headers: hdrJson(),
|
||||
body: JSON.stringify({ name, address: address || null, phone: phone || null })
|
||||
body: JSON.stringify({ name, address: address || null, phone: phone || null, color })
|
||||
});
|
||||
if (res.ok) {
|
||||
showToast(id ? 'Филиал обновлён' : 'Филиал создан');
|
||||
@@ -98,6 +111,9 @@ async function deleteBranch(id) {
|
||||
}
|
||||
|
||||
document.getElementById('addBranchBtn').addEventListener('click', () => openBranchModal());
|
||||
document.getElementById('branchColorRandom').addEventListener('click', () => {
|
||||
document.getElementById('branchColor').value = randomBranchColor();
|
||||
});
|
||||
document.getElementById('branchModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeBranchModal(); });
|
||||
document.getElementById('branchCancelBtn').addEventListener('click', closeBranchModal);
|
||||
document.getElementById('imgModal').addEventListener('click', e => e.currentTarget.classList.remove('open'));
|
||||
|
||||
Reference in New Issue
Block a user