81 lines
2.9 KiB
JavaScript
81 lines
2.9 KiB
JavaScript
(() => {
|
|
'use strict';
|
|
|
|
const PTA = window.PTA;
|
|
if (!PTA) return;
|
|
|
|
const page = window.PTA_PAGE_CONFIG || {};
|
|
const modules = Array.isArray(page.modules) ? page.modules : [];
|
|
const params = page.params || {};
|
|
|
|
modules.forEach((name) => PTA.modules[name]?.init?.());
|
|
|
|
async function initialisePlanning() {
|
|
const planning = PTA.modules.planning;
|
|
if (!planning) return;
|
|
|
|
const { structureSelect, agentSelect, weekInput, validateButton } = PTA.elements;
|
|
if (params.structureId && structureSelect) {
|
|
structureSelect.value = String(params.structureId);
|
|
await planning.loadAgents();
|
|
if (params.structureLocked) structureSelect.disabled = true;
|
|
}
|
|
if (params.agentId && agentSelect) {
|
|
agentSelect.value = String(params.agentId);
|
|
if (weekInput) weekInput.disabled = false;
|
|
}
|
|
if (params.week && weekInput) {
|
|
weekInput.disabled = !agentSelect?.value;
|
|
weekInput.value = params.week;
|
|
if (agentSelect?.value) await planning.handleWeekSelection();
|
|
}
|
|
if (params.notice) PTA.utils.showMessage(params.notice, 'info');
|
|
if (params.focus === 'validation') {
|
|
window.setTimeout(() => {
|
|
document.querySelector('#editor-view .actions-bar')?.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
validateButton?.focus({ preventScroll: true });
|
|
}, 150);
|
|
}
|
|
}
|
|
|
|
async function initialiseStructureOverview() {
|
|
if (!params.structureId) return;
|
|
const select = document.querySelector('#overview-structure');
|
|
if (select) {
|
|
select.value = String(params.structureId);
|
|
if (params.structureLocked) select.disabled = true;
|
|
}
|
|
await PTA.modules.structureOverview?.load?.();
|
|
}
|
|
|
|
async function initialiseAgentOverview() {
|
|
if (params.agentId) {
|
|
const select = document.querySelector('#overview-agent');
|
|
if (select) {
|
|
select.value = String(params.agentId);
|
|
if (params.agentLocked) select.disabled = true;
|
|
}
|
|
}
|
|
if (params.month) {
|
|
const input = document.querySelector('#agent-overview-month');
|
|
if (input) input.value = params.month;
|
|
}
|
|
if (params.agentId) await PTA.modules.agentOverview?.load?.();
|
|
}
|
|
|
|
function initialiseCoverage() {
|
|
if (!params.structureId) return;
|
|
const select = document.querySelector('#coverage-structure-filter');
|
|
if (select) {
|
|
select.value = String(params.structureId);
|
|
if (params.structureLocked) select.disabled = true;
|
|
PTA.modules.coverage?.refresh?.();
|
|
}
|
|
}
|
|
|
|
initialisePlanning();
|
|
initialiseStructureOverview();
|
|
initialiseAgentOverview();
|
|
initialiseCoverage();
|
|
})();
|