let sJson = []; let sJson21 = []; let sJsonClients = []; let counter = 4; superuser = document.querySelector("#super-user-set").value||""; // console.log("superuser") // console.log(superuser) function getClientsInMunicipality(sessionId) { for (let c in sJsonClients) { } return 0; } function getAlreadyRegisteredCount(sessionId) { for (let e in sJson21) { if (sJson21[e].sessionid == sessionId) { return sJson21[e].totalredistered; } } return 0; } function getSuperuser() { if (superuser == 1) return 1; return 0; } function addPreloader() { if (!document.querySelector('#preloader')) { const preloader = document.createElement("div"); preloader.id = "cover-spin"; document.querySelector('#inscrit').append(preloader); } } function removePreloader() { const preloader = document.querySelector('#cover-spin'); if (preloader) { preloader.remove(); } } function addToWL(id) { let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { window.location.href = "/site/portal/lms/waiting_list" } }; xhttp.open("GET", "/entity/instance/add_to_waiting_list/view.html?entityInstanceId=" + id + "&add_to_waiting_list=true", true); xhttp.send(); } const addTaddToWLByMunicipality = (sid, mid, opt, choices) => { console.clear() Swal.fire({ title: "", text: 'Ajouter réellement l\'utilisateur à la liste d\'attente', icon: "warning", showCancelButton: true }).then(function(result) { if (result.isConfirmed) { let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { choices.clearChoices(); choices.removeActiveItems(); choices.setChoices(async () => { try { let xmlhttpSessionsHardSessionData = new XMLHttpRequest(); xmlhttpSessionsHardSessionData.overrideMimeType('text/xml'); xmlhttpSessionsHardSessionData.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { let sessionsHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); sessionsHtmlList.querySelectorAll("body div[role='sdata']").forEach(el => { console.log("123 el ", el) console.log("123 el ", sJson21) for (let i in sJson21){ let e = sJson21[i]; console.log("321 e ", e) if (e.sessionid == el.dataset.sessionid){ e.totalredistered = el.dataset.totalredistered; sJson21[i] = e; console.log('sJson21 updated ', sJson21) document.getElementById('maximum_registrants_container_' + sid).innerHTML = e.totalredistered + '/'; console.log("updating element ", 'maximum_registrants_container_' + sid) } } }) } } xmlhttpSessionsHardSessionData.open("GET", "/entity/roster/entityRosterView.html?entityRosterId=21&no_header=true&entityInstanceForm.entityInstanceId=" + sid, true); xmlhttpSessionsHardSessionData.send(); let reformattedArray = []; const url = "/client/relation_roster/clientRelationRosterView.html?clientRelationRosterId=299&no_header=true&clientRelationForm.clientFilter.v[587854]="+mid+"&clientRelationForm.clientRelationFilter.instanceFilter.v[592696]="+sid; await fetch(url).then(function (response) { return response.text(); }).then(function (html) { let sJsonClientsWL = []; var parser = new DOMParser().parseFromString(html, 'text/html'); parser.querySelectorAll("body div[role='client']").forEach(el => { sJsonClientsWL.push({"cid": el.dataset.id}); }); // const arrRes = sJsonClients.filter(elem=>sJsonClientsWL.every(item=>item.cid !== elem.cid)); let arrRes = []; // arrRes.push({"cid": "", "name" : ""}); arrRes = arrRes.concat(sJsonClients.filter(elem=>sJsonClientsWL.every(item=>item.cid !== elem.cid))) reformattedArray = arrRes.map((el) => { return { value: el.cid, label: el.name}; }); }).catch(function (err) { console.warn('Something went wrong.', err); }); // console.log("reformattedArray") // console.log(reformattedArray) return reformattedArray||[]; } catch (err) { console.error(err); } }); Swal.fire({ title: "Utilisateur ajouté à la liste d'attente", text: "", icon: "success", timer: 1000 }); } }; xhttp.open("GET", "/entity/instance/add_to_waiting_list/view.html?entityInstanceId="+sid+"&add_to_waiting_list=true&CLIENT_ID="+opt.value, true); xhttp.send(); } else { choices.removeActiveItems(); } }); } function isPurchased(sessionId) { for (let e in sJson) { if (sJson[e].session == sessionId) { return true; // sJson[e].purchased == 'Yes'; } } return false; } function showBtnPurchased(btn) { console.log("showBtnPurchased") btn.innerText = "Session achetée"; btn.style.background = "rgb(204 202 204)"; btn.addEventListener('click', e => {e.preventDefault()}); } function showBtnCompleted(btn) { console.log("showBtnCompleted") btn.innerText = "Session complète"; btn.style.background = "rgb(204 202 204)"; btn.addEventListener('click', e => {e.preventDefault()}); return btn } function showBtnApprove(btn, sid) { // console.log("showBtnApprove") btn.innerText = "COMPLET\n Inscrivez-moi\n à la liste d’attente"; btn.style.background = "#blue (9, 66, 128)"; btn.addEventListener('click', e => { e.preventDefault(); addToWL(sid); }); } function showBtnApproveForSuperUser(btn, sid) { // console.log("showBtnApproveForSuperUser") if(!!sid){ /*Get client from SuperUser municipality in Waiting List*/ if(superuser == "1"){ const sessionWrapper = document.querySelector("#inscrit")||""; const mid = sessionWrapper.dataset.mid||""; if(mid){ const spin ="Loading"; btn.innerHTML = spin; const xmlhttClientDataMunicipality = new XMLHttpRequest(); xmlhttClientDataMunicipality.overrideMimeType('text/xml'); xmlhttClientDataMunicipality.onreadystatechange = function () { // всего 5 профилей, а зарегались только 5 должен остаться только один if (this.readyState == 4 && this.status == 200) { // console.log("************************************************") let sJsonClientsWL = []; // sJsonClients; let sessionsHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); // console.log('el ', sessionsHtmlList); sessionsHtmlList.querySelectorAll("div[role='client']").forEach(el => { // console.log('el ', el); sJsonClientsWL.push({"cid": el.dataset.id}); }); let arrRes = []; // arrRes.push({"cid": "", "name" : ""}); arrRes = arrRes.concat(sJsonClients.filter(elem=>sJsonClientsWL.every(item=>item.cid !== elem.cid))) /**render button**/ // console.log("sid", sid); // console.log("sJsonClients", sJsonClients) // console.log("sJsonClientsWL", sJsonClientsWL) // console.log("arrRes", arrRes) // console.log("************************************************") btn.innerHTML = ''; if(arrRes.length > 0){ btn.innerText = "Ajouter des utilisateurs à la liste d'attente"; btn.style.background = "#blue (9, 66, 128)"; const btnDivWrap = document.createElement("div"); const btnSelect = document.createElement("select"); const btnOption = document.createElement("option"); for(let i in arrRes){ btnOption.textContent = arrRes[i].name; btnOption.value = arrRes[i].cid; let cloneBtnOption = btnOption.cloneNode(true) btnSelect.appendChild(cloneBtnOption); } btnDivWrap.appendChild(btnSelect); const choices = new Choices(btnSelect, {}); choices.removeActiveItems(); btnSelect.addEventListener('change', (event) => { const option = btnSelect.options[btnSelect.selectedIndex]; addTaddToWLByMunicipality(sid,mid,option,choices) } ) btn.addEventListener('click', e => { e.preventDefault(); //addToWL(sid); const parentContainerTop = btn.closest('div.row'); const parentContainer = btn.parentNode; const gridElementsList = parentContainerTop.children; if(!btn.classList.contains("show")){ btnDivWrap.style.display = ""; btn.classList.add("show"); if(gridElementsList.length > 0){ btn.style.marginRight = "10px" parentContainer.classList.remove("col-md-2"); parentContainer.classList.add("col-md-6"); parentContainer.style.display = "flex" parentContainer.style.alignItems = "center" btnDivWrap.style.width = "100%" gridElementsList[2].classList.add("item-grid-session-hidden"); gridElementsList[3].classList.add("item-grid-session-hidden"); } btn.after(btnDivWrap) }else{ btnDivWrap.style.display = "none"; btn.classList.remove("show"); if(gridElementsList.length > 0){ btn.style.marginRight = "10px" parentContainer.classList.remove("col-md-6"); parentContainer.classList.add("col-md-2"); parentContainer.style.display = "" parentContainer.style.alignItems = "" btnDivWrap.style.width = "" gridElementsList[2].classList.remove("item-grid-session-hidden"); gridElementsList[3].classList.remove("item-grid-session-hidden"); } } }); }else { btn.innerText = "Tous les utilisateurs ont été ajoutés à la liste d'attente"; btn.style.background = "rgb(204 202 204)"; btn.addEventListener('click', e => {e.preventDefault()}); } /***/ } } xmlhttClientDataMunicipality.open("GET", "/client/relation_roster/clientRelationRosterView.html?clientRelationRosterId=299&no_header=true&clientRelationForm.clientFilter.v[587854]="+mid+"&clientRelationForm.clientRelationFilter.instanceFilter.v[592696]="+sid, true); xmlhttClientDataMunicipality.send(); } } /*-End- Get client from SuperUser municipality in Waiting List*/ } } function showBtnBuy(btn, approve, pid) { console.log("showBtnBuy") btn.innerHTML = " Ajouter au panier "; btn.removeAttribute("style"); if (btn.parentElement.parentElement.querySelector('[rel^="productPriceTotal_"]')!=null) { console.log("has price") addToShoppingCartEvent = function(event) { event.preventDefault(); addToShoppingCart2(pid, 1, 'false'); } } else { console.log("has no price") addToShoppingCartEvent = function(event) { event.preventDefault(); Swal.fire({ title: "", html: "Nous sommes désolés, vous ne pouvez pas vous inscrire à cette activité, car votre profil ne répond pas à certains critères. Pour plus d’information, veuillez écrire à formation@umq.qc.ca", icon: "error" }); } } btn.addEventListener('click', addToShoppingCartEvent); } function placeData() { console.log('placeData'); document.querySelectorAll('[role="item-session"]').forEach((item) => { let btnBuy = item.querySelector(".btn2"); let btnBuyAnon = item.querySelector(".btn_anon"); // horires query let moduleIds = item.dataset.moduleids; if (moduleIds != null) { console.log('moduleids:', moduleIds); item.querySelector("a[role=\"button\"]").addEventListener("click",e=>{ let addedModules = ""; /*added Webinars*/ let xmlhttpSessionsRoster11 = new XMLHttpRequest(); xmlhttpSessionsRoster11.overrideMimeType('text/xml'); xmlhttpSessionsRoster11.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { let webinarsHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); webinarsHtmlList.querySelectorAll("[data-roster-column]").forEach((el) => { addedModules += el.innerHTML; }) /*added Live Events*/ let xmlhttpSessionsRoster12 = new XMLHttpRequest(); xmlhttpSessionsRoster12.overrideMimeType('text/xml'); xmlhttpSessionsRoster12.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { let liveEventsHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); liveEventsHtmlList.querySelectorAll("[data-roster-column]").forEach((el) => { addedModules += el.innerHTML; }) // console.log(addedModules) if(addedModules.length > 0){ console.log('e.target', e.target); $(e.target).popover({ html : true, content: addedModules, trigger: 'click' }).popover('toggle'); } } } xmlhttpSessionsRoster12.open("GET", "/entity/roster/entityRosterView.html?course=view&entityRosterId=12&no_header=true&entityInstanceForm.entityInstanceIds=" + moduleIds, true); xmlhttpSessionsRoster12.send(); } } xmlhttpSessionsRoster11.open("GET", "/entity/roster/entityRosterView.html?course=view&entityRosterId=11&no_header=true&entityInstanceForm.entityInstanceIds=" + moduleIds, true); xmlhttpSessionsRoster11.send(); e.stopImmediatePropagation(); }) } // end if if (btnBuy != null && true) { let btnBuyRel = btnBuy.getAttribute('rel') if (btnBuyRel != 'program:' && false){ // console.log('rel2:' + btnBuy.getAttribute('rel')) // btnBuy.style.display = 'none'; }else{ btnBuy.style.display = 'block'; let sessionId = item.dataset.sessionid; let startDateField = item.dataset.startdate; let approve = item.dataset.approve; let waitlist = item.dataset.waitlist; let pid = item.dataset.pid; let countOfReg = getAlreadyRegisteredCount(sessionId); let maxReg = item.dataset.maxreg; if (maxReg == "" || maxReg == 0) { document.querySelector("#maximum_registrants_container_" + sessionId).innerHTML = "S/O"; } else { let placedNumber = Math.min(maxReg, countOfReg); document.querySelector("#maximum_registrants_container_" + sessionId).innerHTML = placedNumber + "/"; } if (startDateField == "") { document.querySelector("#start_date_field_" + sessionId).textContent = "S/O"; } var countReg = {}; countReg.countOfReg = new Object(countOfReg); countReg.maxReg = new Object(maxReg); countReg.expression = new Object(countOfReg < maxReg || maxReg.length == 0); countReg.maxRegLength = new Object(maxReg.length); countReg.expression2 = new Object(countOfReg < maxReg); if (btnBuyAnon != null){ if (!isNaN(parseInt(maxReg))){ // есть ограничение // console.log('parseInt(countOfReg) < parseInt(maxReg)', parseInt(countOfReg) < parseInt(maxReg)); if (parseInt(countOfReg) < parseInt(maxReg)){ // нет овербукинга // console.log('approve', approve); } else { // овербукинг showBtnCompleted(btnBuy); } } } if(btnBuy != null && btnBuyAnon == null){ // console.log('sessionId:' + sessionId + 'superuser', superuser + ' maxReg: ' + maxReg + ' countOfReg: ' + countOfReg + ' isPurchased(sessionId): ' + isPurchased(sessionId)); // console.log('superuser', superuser); if (superuser == "1") { // console.log('parseInt(maxReg)', parseInt(maxReg)); if (!isNaN(parseInt(maxReg))){ // есть ограничение // console.log('parseInt(maxReg) really != Nan'); // console.log('parseInt(countOfReg) < parseInt(maxReg)', parseInt(countOfReg) < parseInt(maxReg)); if (parseInt(countOfReg) < parseInt(maxReg)){ // нет овербукинга // console.log('approve', approve); if (approve !== "No" && waitlist !== "Yes") { // принудительный аппрув // console.log("approve Yes and waitlist No"); // console.log('isPurchased(sessionId)', isPurchased(sessionId)); showBtnApproveForSuperUser(btnBuy, sessionId, sJsonClients) } else if (approve !== "No" && waitlist == "Yes") { // console.log("approve Yes and waitlist Yes"); // console.log('isPurchased(sessionId)', isPurchased(sessionId)); showBtnBuy(btnBuy, approve, pid); } else { // console.log("approve No, waitlist ANY"); showBtnBuy(btnBuy, approve, pid); } } else { // овербукинг if (approve !== "No" && waitlist !== "Yes") { // принудительный аппрув // console.log("approve Yes and waitlist No"); // console.log('isPurchased(sessionId)', isPurchased(sessionId)); showBtnApproveForSuperUser(btnBuy, sessionId, sJsonClients) } else if (approve !== "No" && waitlist == "Yes") { // console.log("approve Yes and waitlist Yes"); showBtnApproveForSuperUser(btnBuy, sessionId, sJsonClients) } else { // console.log("approve No, waitlist ANY"); showBtnCompleted(btnBuy); } } } else { // console.log('parseInt(maxReg) really is Nan'); if (approve !== "No") { // console.log("approve Yes and waitlist No"); showBtnApproveForSuperUser(btnBuy, sessionId, sJsonClients) } else { // console.log('isPurchased(sessionId)', isPurchased(sessionId)); showBtnBuy(btnBuy, approve, pid); } } } // not superuser part else { // console.log('parseInt(maxReg)', parseInt(maxReg)); if (!isNaN(parseInt(maxReg))){ // есть ограничение // console.log('parseInt(countOfReg) < parseInt(maxReg)', parseInt(countOfReg) < parseInt(maxReg)); if (parseInt(countOfReg) < parseInt(maxReg)){ // нет овербукинга // console.log('approve', approve); if (approve !== "No" && waitlist !== "Yes") { // включен принудительный аппрув // console.log('isPurchased(sessionId)', isPurchased(sessionId)); if (isPurchased(sessionId)) { // купил или инвойс ми showBtnPurchased(btnBuy); } else {// не купил showBtnApprove(btnBuy, sessionId) } } else { // console.log('isPurchased(sessionId)', isPurchased(sessionId)); if (isPurchased(sessionId)){ showBtnPurchased(btnBuy); } else { showBtnBuy(btnBuy, approve, pid); } } } else { // овербукинг if (approve !== "No" && waitlist !== "Yes") { // принудительный аппрув // console.log("approve Yes and waitlist No"); // console.log('isPurchased(sessionId)', isPurchased(sessionId)); if (isPurchased(sessionId)){ showBtnPurchased(btnBuy); } else { showBtnApprove(btnBuy, sessionId); } } else if (approve !== "No" && waitlist == "Yes") { // console.log("approve Yes and waitlist Yes"); // console.log('isPurchased(sessionId)', isPurchased(sessionId)); if (isPurchased(sessionId)) { showBtnCompleted(btnBuy); } else { showBtnApprove(btnBuy, sessionId) } } else { // console.log("approve No, waitlist ANY"); showBtnCompleted(btnBuy); } } } else { if (approve !== "No" && waitlist !== "Yes") { // console.log("approve Yes and waitlist No"); // console.log('isPurchased(sessionId)', isPurchased(sessionId)); if (isPurchased(sessionId)) { showBtnCompleted(btnBuy); } else { showBtnApprove(btnBuy, sessionId) } } else { // console.log('isPurchased(sessionId)', isPurchased(sessionId)); if (isPurchased(sessionId)){ showBtnPurchased(btnBuy); } else { showBtnBuy(btnBuy, approve, pid); } } } } // ------------------------- /*if((parseInt(maxReg) != "NaN" && parseInt(countOfReg) < parseInt(maxReg)) || maxReg.length == 0){ if (superuser != "1") { // no superuser if (isPurchased(sessionId)){ console.log("purchased 1"); showBtnPurchased(btnBuy); } } else { // superuser console.log("not purchased, needs approve?"); if (approve !== "No" && waitlist !== "Yes") { console.log("approve Yes and waitlist No"); showBtnApprove(btnBuy, sessionId) } else { console.log("approve No"); showBtnBuy(btnBuy, approve, pid); countReg.res = new Object("not BtnCompleted") } } }else{ // overbooking if (superuser != "1"){ // no superuser if (isPurchased(sessionId)) { console.log("purchased 2"); showBtnPurchased(btnBuy); } else { if (approve !== "No" && waitlist !== "Yes") { console.log("approve Yes and waitlist No"); showBtnApprove(btnBuy, sessionId) /* sJsonClients.filter(el => el.threat > 5) showBtnApproveForSuperUser(btnBuy, sessionId, sJsonClients) } else if (approve !== "No" && waitlist == "Yes") { console.log("approve Yes and waitlist Yes"); showBtnApprove(btnBuy, sessionId) // showBtnApproveForSuperUser(btnBuy, sessionId, sJsonClients) } else { console.log("approve No"); showBtnCompleted(btnBuy); } } } else { // superuser if (isPurchased(sessionId)) { console.log("purchased superuser"); showBtnBuy(btnBuy, approve, pid); } else { if (approve !== "No" && waitlist !== "Yes") { console.log("approve Yes and waitlist No"); sJsonClients.filter(el => el.threat > 5) showBtnApproveForSuperUser(btnBuy, sessionId, sJsonClients) } else if (approve !== "No" && waitlist == "Yes") { console.log("approve Yes and waitlist Yes"); // showBtnApprove(btnBuy, sessionId) showBtnApproveForSuperUser(btnBuy, sessionId, sJsonClients) } else { console.log("approve No"); showBtnCompleted(btnBuy); } } } countReg.res = new Object("showBtnCompleted"); }*/ } // console.table(countReg) // horaires } } }); } window.addEventListener('DOMContentLoaded', (event) => { addPreloader(); const ENTITY_INSTANCE_ID = document.querySelector("#course-detail").dataset.entity || ""; const mid = document.querySelector("#inscrit").dataset.mid||""; let xmlhttpSessionsClientData = new XMLHttpRequest(); xmlhttpSessionsClientData.overrideMimeType('text/xml'); xmlhttpSessionsClientData.onreadystatechange = function () { if (this.readyState == 4){ if (this.status == 200) { let sessionsHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); sessionsHtmlList.querySelectorAll("body div[role='sdata']").forEach(el => { sJson.push(JSON.parse(el.textContent)); }) } counter--; if (counter == 0) { placeData(); } } } xmlhttpSessionsClientData.open("GET", "/client/relation_roster/clientRelationRosterView.html?no_header=true&clientRelationRosterId=236", true); xmlhttpSessionsClientData.send(); /*Get clients from SuperUser municipality*/ if(mid){ // console.log('municipality id', mid); const xmlhttClientDataMunicipality = new XMLHttpRequest(); xmlhttClientDataMunicipality.overrideMimeType('text/xml'); xmlhttClientDataMunicipality.onreadystatechange = function () { if (this.readyState == 4){ if (this.status == 200) { let sessionsHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); sessionsHtmlList.querySelectorAll("body div[role='client']").forEach(el => { sJsonClients.push({"cid": el.dataset.id, "name": el.textContent}); }) // console.log('municipality id:', mid, ' with sJsonClients:', sJsonClients); } counter--; if (counter == 0) { placeData(); } } } xmlhttClientDataMunicipality.open("GET", "/client/roster/clientRosterView.html?clientRosterId=344&clientForm.clientFilter.v[587854]="+mid+"&no_header=true", true); xmlhttClientDataMunicipality.send(); // console.log("sJsonClients") // console.log(sJsonClients) } else { // console.log('municipality not found') counter--; } /*-End- Get client from SuperUser municipality*/ let xmlhttpSessionsHardSessionData = new XMLHttpRequest(); xmlhttpSessionsHardSessionData.overrideMimeType('text/xml'); xmlhttpSessionsHardSessionData.onreadystatechange = function () { if (this.readyState == 4){ if (this.status == 200) { let sessionsHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); sessionsHtmlList.querySelectorAll("body div[role='sdata']").forEach(el => { sJson21.push({"sessionid": el.dataset.sessionid, "totalredistered": el.dataset.totalredistered}); }) } counter--; if (counter == 0) { placeData(); } } } xmlhttpSessionsHardSessionData.open("GET", "/entity/roster/entityRosterView.html?entityRosterId=21&entityInstanceForm.parentEntityInstanceId=" + ENTITY_INSTANCE_ID + "&no_header=true", true); xmlhttpSessionsHardSessionData.send(); /*get Sessions Roster List*/ let xmlhttpSessionsRoster = new XMLHttpRequest(); xmlhttpSessionsRoster.overrideMimeType('text/xml'); xmlhttpSessionsRoster.onreadystatechange = function () { if (this.readyState == 4) { if (this.status == 200) { removePreloader(); let sessionsHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); let sessionsRoster = document.querySelector('[role="sessionsRoster"]'); sessionsHtmlList.querySelectorAll('body div[role="item-session"]').forEach(function (el, index) { if (el != null){ /*if (el.querySelector('[name="productPriceId_3352"]') != null ){ if (document.querySelector('[id="2147"]') == null) // anon condition el.querySelector('[name="productPriceId_3352"]').remove(); }*/ /*if (el.querySelector('[rel="productPriceTotal_0.00"]') != null ){ if (document.querySelector('[id="2147"]') == null) // anon condition el.querySelector('[rel="productPriceTotal_0.00"]').remove(); }*/ if (el.querySelector('[name="noRuleProductPriceId_8"]') != null ){ if (document.querySelector('[id="2147"]') == null) // anon condition el.querySelector('[name="noRuleProductPriceId_8"]').remove(); } } sessionsRoster.append(el); }) } counter--; if (counter == 0) { placeData(); } } } xmlhttpSessionsRoster.open("GET", "/entity/roster/entityRosterView.html?entityRosterId=20&entityInstanceForm.parentEntityInstanceId=" + ENTITY_INSTANCE_ID + "&no_header=true", true); xmlhttpSessionsRoster.send(); /*get program*/ let xmlhttp2 = new XMLHttpRequest(); xmlhttp2.overrideMimeType('text/xml'); xmlhttp2.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { let tabsTitleHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); let tabsTitleWrap = document.querySelector('#accordion'); let cnt = 0; tabsTitleHtmlList.querySelectorAll('body div.accordion-item').forEach(function (el, index) { tabsTitleWrap.append(el); cnt++ }) $('a[data-bs-toggle="tab"]').on('shown.bs.tab', function () { if (cnt === 1) { $('#accordion button.accordion-button').removeClass('collapsed'); $('#accordion div.accordion-collapse').addClass('show'); } }).first().trigger('shown.bs.tab'); } } xmlhttp2.open("GET", "/entity/course_program/program-content/body.html?entityInstanceId=" + ENTITY_INSTANCE_ID + "&orderByComp=Display%20Order:asc", true); xmlhttp2.send(); /*get traner*/ let xmlhttp = new XMLHttpRequest(); xmlhttp.overrideMimeType('text/xml'); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { let status = false; let smallThumbsHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); let smallThumbsWrap = document.querySelector('[role="small-thumbs"]'); if (smallThumbsHtmlList.querySelectorAll('body ul li').length > 1) { smallThumbsHtmlList.querySelectorAll('body ul li').forEach(function (el, index) { if (el.hasChildNodes()) { status = true; smallThumbsWrap.append(el); } }) } let xmlhttp1 = new XMLHttpRequest(); xmlhttp1.overrideMimeType('text/xml'); xmlhttp1.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { let expertsContentHtmlList = new DOMParser().parseFromString(this.responseText, 'text/html'); let expertsContentWrap = document.querySelector('[role="experts-content"]'); expertsContentHtmlList.querySelectorAll('body ul li[role="experts-content"]').forEach(function (el, index) { if (el.hasChildNodes()) { expertsContentWrap.append(el); } }) } } xmlhttp1.open("GET", "/entity/trainer/experts-content/body.html?entityInstanceId=" + ENTITY_INSTANCE_ID + "&orderByComp=Display%20Order:asc", true); xmlhttp1.send(); $('a[data-bs-toggle="tab"]').on('shown.bs.tab', function () { $($(this).attr('href')).find('.slickslide').slick({ dots: status, arrows: false, slide: 'li', slidesToShow: 1, responsive: [{ breakpoint: 800, settings: { arrows: false, centerMode: false, centerPadding: '40px', variableWidth: false, slidesToShow: 1, dots: true }, breakpoint: 1200, settings: { arrows: false, centerMode: false, centerPadding: '40px', variableWidth: false, slidesToShow: 1, dots: true } }], customPaging: function (slider, i) { if (!!status) return ''; else return false; } }) }).first().trigger('shown.bs.tab'); } } xmlhttp.open("GET", "/entity/trainer/small-thumbs/body.html?entityInstanceId=" + ENTITY_INSTANCE_ID + "&orderByComp=Display%20Order:asc", true); xmlhttp.send(); function removeItemAll(arr, value) { var i = 0; while (i < arr.length) { if (arr[i] === value) { arr.splice(i, 1); } else { ++i; } } return arr; } /*add to favorite course */ let favoriteArray = localStorage.getItem('favorite') ? JSON.parse(localStorage.getItem('favorite')) : []; console.log('favoriteArray on init:', favoriteArray); const favoriteLink = document.querySelector(".product-details-heart a.h"); if (favoriteLink != null) { let id = favoriteLink.dataset.value; if (id!=null && id > 0) { console.log('current id:', id); if (favoriteArray.includes(id)) { favoriteLink.classList.add("active"); } favoriteLink.addEventListener('click', event => { favoriteArray = localStorage.getItem('favorite') ? JSON.parse(localStorage.getItem('favorite')) : []; event.preventDefault() console.log('favoriteArray before click:', favoriteArray); let favorite = localStorage.getItem('favorite') ? JSON.parse(localStorage.getItem('favorite')) : []; if (!favorite.includes(id)) { favoriteArray.push(id); localStorage.setItem('favorite', JSON.stringify(favoriteArray)); favoriteLink.classList.add("active"); } else { favoriteArray = removeItemAll(favoriteArray, id); localStorage.setItem('favorite', JSON.stringify(favoriteArray)); favoriteLink.classList.remove("active"); } console.log('favoriteArray after click:', favoriteArray); }) } } })