%PDF- %PDF-
Direktori : /home1/dimen328/.trash/espace/verification/index/ |
Current File : //home1/dimen328/.trash/espace/verification/index/mediator.js.tВlВchargement |
/* * WCM Sitefactory Mediator * Used in IA component context * * author i30897 * */ Mediator = new function () { var debugMode = true; var registeredIa = new Array(); // store if IA post parameter exist this.init = function () { if (typeof console == "undefined") { debugMode = false; } else { this.logInfo("DeviceFeatures - debug mode enabled"); } if (typeof (sfIaParam) != "undefined" && typeof (sfIaParam.version) == "undefined") { this.store(sfIaParam.topic, sfIaParam); } this.subscribeToTopic("target.ia.**", function (topic, data) { Mediator.logInfo("Mediator - Target callback start"); if (topic && typeof (sfIaTargetList) != "undefined" && sfIaTargetList[sfSiteId][topic]) { Mediator.logInfo("Mediator - Target found for topic: " + topic); Mediator.sendData(topic, data, sfIaTargetList[sfSiteId][topic]); } else { Mediator.logInfo("Mediator - Target not found for topic: " + topic); } }); } // subscribe to topic this.subscribeToTopic = function (topicName, callback) { this.logInfo("Mediator - subscribe to topic: " + topicName); return window.PageBus.subscribe(topicName, null, callback, null); } // subscribe to array of topic this.subscribeToListOfTopic = function (topicNames, callback) { for (var index in topicNames) { this.logInfo("Mediator - subscribe to topic: " + topicName[index]); window.PageBus.subscribe(topicNames[index], null, callback, null); } } // store parameter this.store = function (topicName, parameter) { this.logInfo("Mediator - store parameter: topic=" + topicName + " parameter=" + parameter); window.PageBus.subscribe(topicName, function (topic, message, data) { return; }, null, { PageBus: { cache: true } }); window.PageBus.store(topicName, parameter); } // check if a topic stored this.checkQuery = function (topicName) { if (typeof window.PageBus.query(topicName)[0] != 'undefined'){ return true; } else { return false; } } // send data to server this.sendPostData = function (topic, data, url) { // Temp fix DTS starts if(typeof data != "undefined"){ if(data.Json && data.Json.listDts){ delete data.Json.eligibAugdma; delete data.Json.activeIA; var newList={}; newList.obdMdeco = data.Json.listDts.obdMdeco; newList.obdDfin = data.Json.listDts.obdDfin; newList.taeg = data.Json.listDts.taeg; newList.obdSmtodu = data.Json.listDts.obdSmtodu; newList.obdMtodu = data.Json.listDts.obdMtodu; newList.obdMmens = data.Json.listDts.obdMmens; newList.obdMensavenir = data.Json.listDts.obdMensavenir; newList.obdQuantprel = data.Json.listDts.obdQuantprel; newList.obdDurcred = data.Json.listDts.obdDurcred; //newList.obdLibfinanc = data.Json.listDts.obdLibfinanc; newList.obdCoptass = data.Json.listDts.obdCoptass; newList.remainingMonthly = data.Json.listDts.remainingMonthly; data.Json.listDts={}; data.Json.listDts =newList; } } // Temp fix DTS Ends this.logInfo("Mediator - send POST data: topic=" + topic + " data=" + data + " target=" + url); var form = document.createElement("form"); form.setAttribute("method", "POST"); form.setAttribute("action", url); if(typeof (data.openin) != "undefined"){ form.setAttribute("target", data.openin); } form.setAttribute('enctype', 'application/json'); var jsonData; try { var parseData = JSON.parse(data); parseData.topic = topic; jsonData = JSON.stringify(parseData); } catch (exception) { data.topic = topic; jsonData = JSON.stringify(data); } var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", "sfIaParam"); hiddenField.setAttribute("value", jsonData); form.appendChild(hiddenField); document.body.appendChild(form); form.submit(); } // send data to the target this.sendData = function (topic, data, url) { this.logInfo("Mediator - send data: topic=" + topic + " data=" + data + " target=" + url); var iaId = this.getIaIdFromTopic(topic); /* temp fix for post redirect for accuiel page AEM*/ if(topic == "target.ia.frpfpciaaape_fullAuthentication_redirect" ){ if (sfSiteId === 'cetelem'){ if(url ==="/fr/accueil"){ window.location.href= url; return; } } } if (iaId && (typeof registeredIa[iaId] != "undefined")) { this.logInfo("Mediator - IA " + iaId + " registered in the page, start process"); if (registeredIa[iaId] === true) { this.logInfo("Mediator - IA " + iaId + " must loaded"); this.store(topic, data); registeredIa[iaId] = false; window.PageBus.publish("mediator.load.ia." + iaId); } else { this.logInfo("Mediator - IA " + iaId + " already loaded"); } } else if (url) { this.logInfo("Mediator - IA " + iaId + " not registered in the page, go to " + url); if(data.ModuleName && (data.ModuleName === "newEpartnerResult" || data.ModuleName === "newEpartnerSlider")){ url = url + "?codevendeur="+ data.Json.URL_numberDuVendeur; if(typeof inSite != 'undefined' && inSite === "app") url= url + "&mpartnare"; } if((url ==="/fr/partner/partnare" || url ==="/fr/partner/mpartnare" || url ==="/fr/partner/cpartnere" || url ==="/fr/partner/fast-partnare") && data.ModuleName && (data.ModuleName === "resultBlock")) url = url + "?codevendeur="+ data.Json.URL_numberDuVendeur+"&codemateriel="+data.Json.URL_materialCode; if(data && data.Json && data.Json.vosFract === undefined) data.Json.vosFract ="-"; //if(window.location.href.includes("credit/credit-simulation"))data.resultUrl="target.ia.frpfsimulationpe_simulation_sim"; if(typeof sfIaParam != 'undefined' && sfIaParam.noAbTestCheck && url ==="/fr/credit/resultat-simulation" && data.ModuleName && (data.ModuleName === "simulationGeneric")) data.noAbTestCheck=sfIaParam.noAbTestCheck; this.sendPostData(topic, data, url); } } // regiter IA this.registerIa = function (iaId, status) { registeredIa[iaId] = status; } this.getregisteredIa=function(topic){ var iaId = this.getIaIdFromTopic(topic); return registeredIa[iaId]; } // get IA id from topic this.getIaIdFromTopic = function (topic) { var iaId = topic.split(".ia.")[1]; if (iaId.indexOf(".") != -1) { return iaId.substring(0, iaId.indexOf(".")); } return iaId; } // enable debug mode this.enableDebugMode = function () { debugMode = true; } // log info to the console this.logInfo = function (messageLog) { if (debugMode === true) { //console.log(messageLog); } } }; Mediator.init();