fix(rc): fiabiliser modal impact projet et bypass cache scripts
This commit is contained in:
parent
a8d0e69585
commit
47c70697d3
|
|
@ -1,5 +1,12 @@
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
var inputChanged = false
|
var inputChanged = false
|
||||||
|
let assetVersion = null;
|
||||||
|
|
||||||
|
function getAssetVersion() {
|
||||||
|
if (assetVersion) return assetVersion;
|
||||||
|
assetVersion = String(Date.now());
|
||||||
|
return assetVersion;
|
||||||
|
}
|
||||||
|
|
||||||
function openModalUpdate(selectedSubmenu, numParcours) {
|
function openModalUpdate(selectedSubmenu, numParcours) {
|
||||||
const elem = document.getElementById('modalUpdate');
|
const elem = document.getElementById('modalUpdate');
|
||||||
|
|
@ -113,7 +120,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
||||||
// Création et ajout du nouveau script correspondant au sous-menu
|
// Création et ajout du nouveau script correspondant au sous-menu
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.src = scriptSrc
|
script.src = `${scriptSrc}?v=${encodeURIComponent(getAssetVersion())}`;
|
||||||
script.className = 'dynamic-script';
|
script.className = 'dynamic-script';
|
||||||
script.onload = async function() {
|
script.onload = async function() {
|
||||||
if (submenu === "tarif" || submenu == "projet") {
|
if (submenu === "tarif" || submenu == "projet") {
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,9 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
|
|
||||||
function getLinkedTarifId() {
|
function getLinkedTarifId() {
|
||||||
if (tarif && typeof tarif === 'object' && tarif.id) return tarif.id;
|
if (tarif && typeof tarif === 'object' && tarif.id) return tarif.id;
|
||||||
|
if (typeof tarif === 'string' && tarif.trim()) return tarif;
|
||||||
|
if (rc && typeof rc.tarifRC === 'object' && rc.tarifRC.id) return rc.tarifRC.id;
|
||||||
|
if (rc && typeof rc.tarif === 'object' && rc.tarif.id) return rc.tarif.id;
|
||||||
if (typeof rc?.tarifRC === 'string' && rc.tarifRC.trim()) return rc.tarifRC;
|
if (typeof rc?.tarifRC === 'string' && rc.tarifRC.trim()) return rc.tarifRC;
|
||||||
if (typeof rc?.tarif === 'string' && rc.tarif.trim()) return rc.tarif;
|
if (typeof rc?.tarif === 'string' && rc.tarif.trim()) return rc.tarif;
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -76,6 +79,39 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
return Boolean(getLinkedTarifId());
|
return Boolean(getLinkedTarifId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function refreshTarifContextFromSession() {
|
||||||
|
try {
|
||||||
|
const sessionContrat = JSON.parse(sessionStorage.getItem('contrat') || 'null');
|
||||||
|
const sessionRC = sessionContrat?.["@expand"]?.enCours || null;
|
||||||
|
if (!sessionRC || typeof sessionRC !== 'object') return false;
|
||||||
|
|
||||||
|
rc = sessionRC;
|
||||||
|
projet = sessionRC?.["@expand"]?.projetRC || sessionRC?.["@expand"]?.projet || sessionRC?.projetRC || sessionRC?.projet || null;
|
||||||
|
tarif = sessionRC?.["@expand"]?.tarifRC || sessionRC?.["@expand"]?.tarif || sessionRC?.tarifRC || sessionRC?.tarif || null;
|
||||||
|
|
||||||
|
window.rc = rc;
|
||||||
|
window.projet = projet;
|
||||||
|
window.tarif = tarif;
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Impossible de recharger le contexte RC depuis la session:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureTarifImpactContext() {
|
||||||
|
if (hasTarifReference() && tarifOriginalData) return true;
|
||||||
|
|
||||||
|
refreshTarifContextFromSession();
|
||||||
|
if (!hasTarifReference()) return false;
|
||||||
|
|
||||||
|
if (!tarifOriginalData) {
|
||||||
|
saveOriginalTarifData();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean(tarifOriginalData);
|
||||||
|
}
|
||||||
|
|
||||||
async function loadModulateurs() {
|
async function loadModulateurs() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/rc/modulo/activiteRCC');
|
const response = await fetch('/rc/modulo/activiteRCC');
|
||||||
|
|
@ -121,18 +157,29 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
function saveOriginalTarifData() {
|
function saveOriginalTarifData() {
|
||||||
if (!hasTarifReference()) return;
|
if (!hasTarifReference()) return;
|
||||||
|
|
||||||
|
const readGarantiesFromProjet = () => {
|
||||||
|
const garanties = [];
|
||||||
|
if (!projet) return garanties;
|
||||||
|
if (projet.extRCCConfie) garanties.push('contenant-confie');
|
||||||
|
if (projet.extRCCTPPC) garanties.push('tppc');
|
||||||
|
if (projet.extRCCModifCalArrim) garanties.push('modif-calage-arrimage');
|
||||||
|
if (projet.extRCCFerroutage) garanties.push('ferroutage');
|
||||||
|
if (projet.extRCCFraisRecons) garanties.push('frais-reconstitution');
|
||||||
|
if (projet.extRCCRegie) garanties.push('regie');
|
||||||
|
if (projet.extRCCSansMontageDemontage) garanties.push('sans-montage-demontage');
|
||||||
|
return garanties;
|
||||||
|
};
|
||||||
|
|
||||||
|
const readGarantiesFromForm = () => {
|
||||||
const garantieRCCSelector = document.getElementById('garantieRCC-selector');
|
const garantieRCCSelector = document.getElementById('garantieRCC-selector');
|
||||||
let garantiesRCC = [];
|
if (!garantieRCCSelector) return [];
|
||||||
if (garantieRCCSelector) {
|
return Array.from(garantieRCCSelector.selectedOptions).map((opt) => opt.value);
|
||||||
garantiesRCC = Array.from(garantieRCCSelector.selectedOptions).map(opt => opt.value);
|
};
|
||||||
} else if (projet) {
|
|
||||||
if (projet.extRCCConfie) garantiesRCC.push('contenant-confie');
|
const garantiesRCC = readGarantiesFromProjet();
|
||||||
if (projet.extRCCTPPC) garantiesRCC.push('tppc');
|
if (garantiesRCC.length === 0) {
|
||||||
if (projet.extRCCModifCalArrim) garantiesRCC.push('modif-calage-arrimage');
|
const garantiesFromForm = readGarantiesFromForm();
|
||||||
if (projet.extRCCFerroutage) garantiesRCC.push('ferroutage');
|
garantiesRCC.push(...garantiesFromForm);
|
||||||
if (projet.extRCCFraisRecons) garantiesRCC.push('frais-reconstitution');
|
|
||||||
if (projet.extRCCRegie) garantiesRCC.push('regie');
|
|
||||||
if (projet.extRCCSansMontageDemontage) garantiesRCC.push('sans-montage-demontage');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseArray = (value) => {
|
const parseArray = (value) => {
|
||||||
|
|
@ -182,7 +229,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
garantiesRCC: garantiesRCC,
|
garantiesRCC: garantiesRCC,
|
||||||
ca: rc?.chiffreAffaires || tarif?.ca || '',
|
ca: rc?.chiffreAffaires || tarif?.ca || '',
|
||||||
pj: tarif?.checkPJ || false,
|
pj: tarif?.checkPJ || false,
|
||||||
typeExtConfies: getCurrentTypeExtConfies(),
|
typeExtConfies: projet?.typeExtConfies || rc?.typeExtConfies || getCurrentTypeExtConfies(),
|
||||||
grilleAdvalorem: collectEffectiveAdvaloremGrid(getCurrentZoneData())
|
grilleAdvalorem: collectEffectiveAdvaloremGrid(getCurrentZoneData())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -849,12 +896,12 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
logTarifImpactSkip('ignore car modal deja ouverte');
|
logTarifImpactSkip('ignore car modal deja ouverte');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!ensureTarifImpactContext()) {
|
||||||
if (!hasTarifReference()) {
|
if (!hasTarifReference()) {
|
||||||
logTarifImpactSkip('aucune reference tarif detectee', { tarif, rcTarifRC: rc?.tarifRC, rcTarif: rc?.tarif });
|
logTarifImpactSkip('aucune reference tarif detectee', { tarif, rcTarifRC: rc?.tarifRC, rcTarif: rc?.tarif });
|
||||||
return false;
|
} else {
|
||||||
}
|
|
||||||
if (!tarifOriginalData) {
|
|
||||||
logTarifImpactSkip('snapshot tarifOriginalData absent');
|
logTarifImpactSkip('snapshot tarifOriginalData absent');
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -888,14 +935,9 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupTarifImpactListeners() {
|
function setupTarifImpactListeners() {
|
||||||
if (!hasTarifReference()) {
|
ensureTarifImpactContext();
|
||||||
logTarifImpactSkip('listeners non actives: aucune reference tarif');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
saveOriginalTarifData();
|
if (!ensureTarifImpactContext()) {
|
||||||
if (!tarifOriginalData) {
|
|
||||||
logTarifImpactSkip('saveOriginalTarifData n a pas initialise de snapshot');
|
logTarifImpactSkip('saveOriginalTarifData n a pas initialise de snapshot');
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
@ -932,7 +974,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
const originalSelection = [...lastActivitySelection];
|
const originalSelection = [...lastActivitySelection];
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkActivityImpact(getCurrentActivityData()),
|
isImpacting: () => checkActivityImpact(getCurrentActivityData()),
|
||||||
|
|
@ -966,7 +1008,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
const originalSelection = lastMarchandiseSelection;
|
const originalSelection = lastMarchandiseSelection;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkMarchandiseImpact(getCurrentMarchandiseData()),
|
isImpacting: () => checkMarchandiseImpact(getCurrentMarchandiseData()),
|
||||||
restore: () => restoreChangedFieldValue(this, originalSelection),
|
restore: () => restoreChangedFieldValue(this, originalSelection),
|
||||||
|
|
@ -1004,7 +1046,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkZoneImpact(getCurrentZoneData()),
|
isImpacting: () => checkZoneImpact(getCurrentZoneData()),
|
||||||
restore: () => restoreZoneState(previousZones)
|
restore: () => restoreZoneState(previousZones)
|
||||||
|
|
@ -1030,7 +1072,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
if (isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
const originalSelection = [...lastGarantieRCCSelection];
|
const originalSelection = [...lastGarantieRCCSelection];
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkGarantieRCCImpact(getCurrentGarantieRCCData()),
|
isImpacting: () => checkGarantieRCCImpact(getCurrentGarantieRCCData()),
|
||||||
|
|
@ -1069,7 +1111,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
const originalChecked = this.dataset.tarifPrevChecked === 'true';
|
const originalChecked = this.dataset.tarifPrevChecked === 'true';
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkActiviteComplImpact(getCurrentActiviteComplData()),
|
isImpacting: () => checkActiviteComplImpact(getCurrentActiviteComplData()),
|
||||||
restore: () => restoreChangedFieldValue(this, originalChecked)
|
restore: () => restoreChangedFieldValue(this, originalChecked)
|
||||||
|
|
@ -1094,7 +1136,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
if (isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
const stateToRestore = previousCotisationState;
|
const stateToRestore = previousCotisationState;
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkCotisationImpact(),
|
isImpacting: () => checkCotisationImpact(),
|
||||||
|
|
@ -1129,7 +1171,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
if (isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkCapitalImpactByField(this.id, this.value),
|
isImpacting: () => checkCapitalImpactByField(this.id, this.value),
|
||||||
restore: () => restoreChangedFieldValue(this, originalValue),
|
restore: () => restoreChangedFieldValue(this, originalValue),
|
||||||
|
|
@ -1181,7 +1223,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkPJImpact(),
|
isImpacting: () => checkPJImpact(),
|
||||||
restore: () => restorePJState(stateToRestore),
|
restore: () => restorePJState(stateToRestore),
|
||||||
|
|
@ -1213,7 +1255,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkRCEImpact(),
|
isImpacting: () => checkRCEImpact(),
|
||||||
restore: () => restoreRCEState(stateToRestore),
|
restore: () => restoreRCEState(stateToRestore),
|
||||||
|
|
@ -1240,7 +1282,7 @@ window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollutio
|
||||||
if (isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasTarifReference() || !tarifOriginalData || isRestoringValue) return;
|
if (isRestoringValue) return;
|
||||||
const previousType = this.dataset.tarifPrevType || '';
|
const previousType = this.dataset.tarifPrevType || '';
|
||||||
if (promptTarifImpactIfNeeded({
|
if (promptTarifImpactIfNeeded({
|
||||||
isImpacting: () => checkTypeExtConfiesImpact(),
|
isImpacting: () => checkTypeExtConfiesImpact(),
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Script pour la page nav-parcours.js -->
|
<!-- Script pour la page nav-parcours.js -->
|
||||||
<script src="/js/nav-parcours.js"></script>
|
<script src="/js/nav-parcours.js?v=<%= Date.now() %>"></script>
|
||||||
<!-- Feuille de style globale : Styles CSS personnalisés pour les formulaires -->
|
<!-- Feuille de style globale : Styles CSS personnalisés pour les formulaires -->
|
||||||
<link rel="stylesheet" href="/css/parcoursform.css">
|
<link rel="stylesheet" href="/css/parcoursform.css">
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue