131cb27d16
Django project: employees, locations, visit_manager, it_manager, mattermost_connector and stub connectors (ad, mail, portal).
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
var EMP_PHARMACIES_BY_ORG = {};
|
|
|
|
function empInit() {
|
|
var el = document.getElementById('emp-pharmacies-data');
|
|
if (!el) return;
|
|
EMP_PHARMACIES_BY_ORG = JSON.parse(el.textContent || '{}');
|
|
}
|
|
|
|
function empOrgChange() {
|
|
var orgSel = document.getElementById('emp-org-select');
|
|
var pharmSel = document.getElementById('emp-pharma-select');
|
|
if (!orgSel || !pharmSel) return;
|
|
|
|
var orgId = orgSel.value;
|
|
|
|
pharmSel.innerHTML = '<option value="">Всі аптеки</option>';
|
|
var list = orgId
|
|
? (EMP_PHARMACIES_BY_ORG[String(orgId)] || [])
|
|
: Object.values(EMP_PHARMACIES_BY_ORG).reduce(function(a, b) { return a.concat(b); }, []);
|
|
|
|
list.forEach(function(ph) {
|
|
var opt = document.createElement('option');
|
|
opt.value = ph.id;
|
|
opt.textContent = ph.label;
|
|
pharmSel.appendChild(opt);
|
|
});
|
|
|
|
empSubmitFilter(orgId, '');
|
|
}
|
|
|
|
function empPharmaChange() {
|
|
var orgSel = document.getElementById('emp-org-select');
|
|
var pharmSel = document.getElementById('emp-pharma-select');
|
|
empSubmitFilter(
|
|
orgSel ? orgSel.value : '',
|
|
pharmSel ? pharmSel.value : ''
|
|
);
|
|
}
|
|
|
|
function empSubmitFilter(orgId, pharmId) {
|
|
var url = '/employees/?location_type=pharmacy';
|
|
if (orgId) url += '&organization_id=' + encodeURIComponent(orgId);
|
|
if (pharmId) url += '&pharmacy_id=' + encodeURIComponent(pharmId);
|
|
|
|
htmx.ajax('GET', url, {
|
|
target: '#main-content',
|
|
swap: 'innerHTML',
|
|
pushUrl: url,
|
|
});
|
|
}
|