33 lines
1.7 KiB
JavaScript
33 lines
1.7 KiB
JavaScript
/* Клиника раздела «Отчёты»: DANA или «Очевидно». У каждой свои звонки АТС, отчёты по каналам
|
||
и дашборд; сервер получает её в ?clinic= (без параметра — DANA). Выбор запоминается в браузере. */
|
||
const ReportClinic = {
|
||
titles: { dana: 'DANA', ochevidno: 'Очевидно' },
|
||
brands: { dana: 'DANA Medical', ochevidno: 'Очевидно' },
|
||
key: 'dana',
|
||
|
||
init() {
|
||
try {
|
||
const saved = localStorage.getItem('rp-clinic');
|
||
if (saved && ReportClinic.titles[saved]) ReportClinic.key = saved;
|
||
} catch { /* без хранилища — DANA */ }
|
||
for (const b of document.querySelectorAll('#rp-clinic button[data-clinic]')) b.onclick = () => ReportClinic.set(b.dataset.clinic);
|
||
const share = document.getElementById('rp-share');
|
||
if (share) share.onclick = () => Reports.shareDialog();
|
||
ReportClinic.sync();
|
||
},
|
||
get title() { return ReportClinic.titles[ReportClinic.key]; },
|
||
get brand() { return ReportClinic.brands[ReportClinic.key]; },
|
||
q(path) { return path + (path.includes('?') ? '&' : '?') + 'clinic=' + encodeURIComponent(ReportClinic.key); },
|
||
sync() {
|
||
for (const b of document.querySelectorAll('#rp-clinic button[data-clinic]')) b.setAttribute('aria-pressed', String(b.dataset.clinic === ReportClinic.key));
|
||
},
|
||
set(key) {
|
||
if (!ReportClinic.titles[key] || key === ReportClinic.key) return;
|
||
ReportClinic.key = key;
|
||
try { localStorage.setItem('rp-clinic', key); } catch { /* выбор действует до перезагрузки */ }
|
||
ReportClinic.sync();
|
||
Reports.onClinicChange();
|
||
},
|
||
};
|
||
ReportClinic.init();
|