From 274548ff00a81a4662350037532f6d7d97984730 Mon Sep 17 00:00:00 2001 From: Magdalena Holczik Date: Mon, 8 Jul 2024 12:10:39 +0200 Subject: [PATCH] Grunted files --- amd/build/bookit.min.js | 2 +- amd/build/bookit.min.js.map | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/amd/build/bookit.min.js b/amd/build/bookit.min.js index 7968c6d1..a5f245ad 100644 --- a/amd/build/bookit.min.js +++ b/amd/build/bookit.min.js @@ -1,3 +1,3 @@ -define("mod_booking/bookit",["exports","core/ajax","core/templates","core/notification","local_wunderbyte_table/reload","mod_booking/bookingpage/prepageFooter"],(function(_exports,_ajax,_templates,_notification,_reload,_prepageFooter){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.SELECTORS=void 0,_exports.backToPreviousPage=function(optionid,userid){currentbookitpage[optionid]--,loadPreBookingPage(optionid,userid)},_exports.bookit=bookit,_exports.continueToNextPage=function(optionid,userid){console.log("continueToNextPage",optionid,userid,currentbookitpage[optionid],totalbookitpages[optionid]),currentbookitpage[optionid]{const initselector=SELECTORS.BOOKITBUTTON+"[data-itemid][data-area]";if(!itemid||!area){return void document.querySelectorAll(initselector).forEach((button=>{const inititemid=button.dataset.itemid,initarea=button.dataset.area;initbookitbutton(inititemid,initarea)}))}const selector=SELECTORS.BOOKITBUTTON+'[data-itemid="'+itemid+'"][data-area="'+area+'"]',buttons=document.querySelectorAll(selector);buttons&&buttons.forEach((button=>{if(!button.dataset.nojs&&!button.classList.contains("disabled")&&!button.dataset.initialized){button.dataset.initialized="true";const userid=button.dataset.userid;if(button.querySelector('[data-action="bookondetail"]'))return void console.log("bookondetail abort");button.addEventListener("click",(e=>{const data=button.dataset;e.target.classList.contains("shopping-cart-cancel-button")?("function"==typeof _systemImportTransformerGlobalIdentifier.define&&_systemImportTransformerGlobalIdentifier.define.amd?new Promise((function(resolve,reject){_systemImportTransformerGlobalIdentifier.require(["local_shopping_cart/shistory"],resolve,reject)})):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&_systemImportTransformerGlobalIdentifier.require&&"component"===_systemImportTransformerGlobalIdentifier.require.loader?Promise.resolve(require("local_shopping_cart/shistory")):Promise.resolve(_systemImportTransformerGlobalIdentifier["local_shopping_cart/shistory"])).then((shoppingcart=>{(0,shoppingcart.confirmCancelModal)(button,0)})).catch((err=>{console.log(err)})):e.target.classList.contains("btn")&&bookit(itemid,area,userid,data)}))}}))};function bookit(itemid,area,userid,data){console.log("run bookit"),_ajax.default.call([{methodname:"mod_booking_bookit",args:{itemid:itemid,area:area,userid:userid,data:JSON.stringify(data)},done:function(res){var skipreload=!1;document.querySelector(".booking-elective-component")&&window.location.reload();const jsonarray=JSON.parse(res.json),templates=res.template.split(","),buttons=document.querySelectorAll(SELECTORS.BOOKITBUTTON+"[data-itemid='"+itemid+"'][data-area='"+area+"']"),promises=[];buttons.forEach((button=>{if(console.log("bookit values",button.dataset.nojs,res.status),skipreload=!0,1==button.dataset.nojs&&0==res.status)console.log("bookit skip",button.dataset.nojs,res.status);else{const arraytoreduce=[...jsonarray];1==res.status&&(skipreload=!1),templates.forEach((template=>{const data=arraytoreduce.shift(),datatorender=data.data??data,promise=_templates.default.renderForPromise(template,datatorender).then((_ref=>{let{html:html,js:js}=_ref;return _templates.default.replaceNode(button,html,js),!0})).catch((ex=>{_notification.default.addNotification({message:"failed rendering "+ex,type:"danger"})}));promises.push(promise)}))}})),Promise.all(promises).then((()=>{const backdrop=document.querySelector(SELECTORS.STATICBACKDROP);return("subbooking"===area||currentbookitpage[itemid]{console.log(e)}))}}])}_exports.initbookitbutton=initbookitbutton;const initprepagemodal=(optionid,userid,totalnumberofpages,uniquid)=>{if(console.log("initprepagemodal",optionid,userid,totalnumberofpages,uniquid),optionid&&uniquid&&totalnumberofpages)currentbookitpage[optionid]=0,totalbookitpages[optionid]=totalnumberofpages,function(optionid,userid,uniquid,totalnumberofpages,callback){document.querySelectorAll("[id^="+SELECTORS.MODALID+optionid+"_"+uniquid+"]").forEach((element=>{if(element&&"true"!=element.dataset.initialized){element.dataset.initialized=!0;for(var observer=new MutationObserver((function(){isHidden(element)||element.classList.contains("show")&&callback(optionid,userid,uniquid,totalnumberofpages)}));null!==element;){if(isHidden(element)){if(element.dataset.observed)return;return observer.observe(element,{attributes:!0}),void(element.dataset.observed=!0)}element=element.parentElement}callback(optionid,userid,uniquid,totalnumberofpages)}}))}(optionid,userid,uniquid,totalnumberofpages,loadPreBookingPage);else{document.querySelectorAll("[id^="+SELECTORS.MODALID).forEach((element=>{element.querySelector('[data-action="bookondetail"]')?(optionid=element.dataset.optionid,uniquid=element.dataset.uniquid,userid=element.dataset.userid,totalnumberofpages=element.dataset.pages,optionid&&uniquid&&initprepagemodal(optionid,userid,totalnumberofpages,uniquid)):console.log("bookondetail abort")}))}};_exports.initprepagemodal=initprepagemodal;const initprepageinline=(optionid,userid,totalnumberofpages,uniquid)=>{if(console.log("initprepageinline",optionid,userid,totalnumberofpages,uniquid),!optionid||!uniquid||!totalnumberofpages){const elements=document.querySelectorAll("[id^="+SELECTORS.INLINEID);return console.log(elements),void elements.forEach((element=>{optionid=element.dataset.optionid,uniquid=element.dataset.uniquid,userid=element.dataset.userid,totalnumberofpages=element.dataset.pages,optionid&&uniquid&&initprepageinline(optionid,userid,totalnumberofpages,uniquid)}))}currentbookitpage[optionid]=0,totalbookitpages[optionid]=totalnumberofpages;document.querySelectorAll('[data-itemid="'+optionid+'"][data-area="option"]').forEach((button=>{button.dataset.initialized||(button.dataset.initialized=!0,console.log("add listener to button",button,button.dataset.action),button.querySelector('[data-action="bookondetail"]')?console.log("bookondetail abort"):button.addEventListener("click",(e=>{console.log("e.target",e.target);let rowcontainer=e.target.closest(".mod-booking-row");if(!rowcontainer.lastElementChild.classList.contains("inlineprepagearea")){let inlinediv=returnVisibleElement(optionid,uniquid,SELECTORS.INMODALDIV);rowcontainer.append(inlinediv.closest(".inlineprepagearea")),loadPreBookingPage(optionid,userid,uniquid)}})))}))};function isHidden(el){var style=window.getComputedStyle(el);return"none"===style.display||"hidden"===style.visibility}_exports.initprepageinline=initprepageinline;const loadPreBookingPage=function(optionid){let userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,uniquid=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";const element=returnVisibleElement(optionid,uniquid,SELECTORS.INMODALDIV);if(element)for(;element.firstChild;)element.removeChild(element.firstChild);else console.error("didnt find element");_ajax.default.call([{methodname:"mod_booking_allow_add_item_to_cart",args:{itemid:optionid,userid:userid},done:function(response){return 1==response.success||5==response.success||0==response.success?_ajax.default.call([{methodname:"mod_booking_load_pre_booking_page",args:{optionid:optionid,userid:userid,pagenumber:currentbookitpage[optionid]},done:function(res){currentbookitpage[optionid]===totalbookitpages[optionid]-1&&(currentbookitpage[optionid]=0);const jsonobject=JSON.parse(res.json);renderTemplatesOnPage(res.template.split(","),jsonobject,element)},fail:function(err){console.log(err)}}]):(console.log("closeModal"),(0,_prepageFooter.closeModal)(optionid,!1),(0,_prepageFooter.closeInline)(optionid,!1),("function"==typeof _systemImportTransformerGlobalIdentifier.define&&_systemImportTransformerGlobalIdentifier.define.amd?new Promise((function(resolve,reject){_systemImportTransformerGlobalIdentifier.require(["local_shopping_cart/cart"],resolve,reject)})):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&_systemImportTransformerGlobalIdentifier.require&&"component"===_systemImportTransformerGlobalIdentifier.require.loader?Promise.resolve(require("local_shopping_cart/cart")):Promise.resolve(_systemImportTransformerGlobalIdentifier["local_shopping_cart/cart"])).then((shoppingcart=>{const addItemShowNotification=shoppingcart.addItemShowNotification;response.userid=userid,addItemShowNotification(response)})).catch((err=>{console.log(err)}))),!0},fail:function(err){console.log(err)}}])};async function renderTemplatesOnPage(templates,dataarray,element){const modal=element.closest(".prepage-body");let elementid=modal.id;if(!elementid){const parent=modal.closest("[id]");elementid=parent.id}return console.log(modal,elementid),modal.querySelector(SELECTORS.MODALHEADER).innerHTML="",modal.querySelector(SELECTORS.INMODALDIV).innerHTML="",modal.querySelector(SELECTORS.MODALBUTTONAREA).innerHTML="",modal.querySelector(SELECTORS.MODALFOOTER).innerHTML="",templates.forEach((async template=>{const data=dataarray.shift();let targetelement=element;if(!data)return!0;switch(data.data.elementid=elementid,template){case"mod_booking/bookingpage/header":targetelement=modal.querySelector(SELECTORS.MODALHEADER);break;case"mod_booking/bookit_button":case"mod_booking/bookit_price":targetelement=modal.querySelector(SELECTORS.MODALBUTTONAREA);break;case"mod_booking/bookingpage/footer":targetelement=modal.querySelector(SELECTORS.MODALFOOTER);break;default:targetelement=modal.querySelector(SELECTORS.INMODALDIV)}return console.log(data.data),await _templates.default.renderForPromise(template,data.data).then((_ref2=>{let{html:html,js:js}=_ref2;return _templates.default.replaceNodeContents(targetelement,html,js),!0})).catch((ex=>{_notification.default.addNotification({message:"failed rendering "+JSON.stringify(ex),type:"danger"})})),!0})),!0}function returnVisibleElement(optionid,uniquid,appendedSelector){let selector='[id^="'+SELECTORS.MODALID+optionid+"_"+uniquid+'"] '+appendedSelector;uniquid&&0!==uniquid.length||(selector='[id^="'+SELECTORS.MODALID+optionid+'_"].show '+appendedSelector);let elements=document.querySelectorAll(selector);0===elements.length&&(selector='[id^="'+SELECTORS.INLINEID+optionid+'_"] '+appendedSelector,elements=document.querySelectorAll(selector));let visibleElement=null;return elements.forEach((element=>{for(var elementtocheck=element.parentElement.parentElement;null!==elementtocheck&&!isHidden(elementtocheck);)elementtocheck=elementtocheck.parentElement;elementtocheck||(visibleElement=element)})),visibleElement}_exports.loadPreBookingPage=loadPreBookingPage})); +define("mod_booking/bookit",["exports","core/ajax","core/templates","core/notification","local_wunderbyte_table/reload","mod_booking/bookingpage/prepageFooter"],(function(_exports,_ajax,_templates,_notification,_reload,_prepageFooter){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.SELECTORS=void 0,_exports.backToPreviousPage=function(optionid,userid){currentbookitpage[optionid]--,loadPreBookingPage(optionid,userid)},_exports.bookit=bookit,_exports.continueToNextPage=function(optionid,userid){console.log("continueToNextPage",optionid,userid,currentbookitpage[optionid],totalbookitpages[optionid]),currentbookitpage[optionid]{const initselector=SELECTORS.BOOKITBUTTON+"[data-itemid][data-area]";if(!itemid||!area){return void document.querySelectorAll(initselector).forEach((button=>{const inititemid=button.dataset.itemid,initarea=button.dataset.area;initbookitbutton(inititemid,initarea)}))}const selector=SELECTORS.BOOKITBUTTON+'[data-itemid="'+itemid+'"][data-area="'+area+'"]',buttons=document.querySelectorAll(selector);buttons&&buttons.forEach((button=>{if(!button.dataset.nojs&&!button.classList.contains("disabled")&&!button.dataset.initialized){button.dataset.initialized="true";const userid=button.dataset.userid;if(button.querySelector('[data-action="bookondetail"]'))return void console.log("bookondetail abort");button.addEventListener("click",(e=>{const data=button.dataset;e.target.classList.contains("shopping-cart-cancel-button")?("function"==typeof _systemImportTransformerGlobalIdentifier.define&&_systemImportTransformerGlobalIdentifier.define.amd?new Promise((function(resolve,reject){_systemImportTransformerGlobalIdentifier.require(["local_shopping_cart/shistory"],resolve,reject)})):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&_systemImportTransformerGlobalIdentifier.require&&"component"===_systemImportTransformerGlobalIdentifier.require.loader?Promise.resolve(require("local_shopping_cart/shistory")):Promise.resolve(_systemImportTransformerGlobalIdentifier["local_shopping_cart/shistory"])).then((shoppingcart=>{(0,shoppingcart.confirmCancelModal)(button,0)})).catch((err=>{console.log(err)})):e.target.classList.contains("btn")&&bookit(itemid,area,userid,data)}))}}))};function bookit(itemid,area,userid,data){console.log("run bookit"),_ajax.default.call([{methodname:"mod_booking_bookit",args:{itemid:itemid,area:area,userid:userid,data:JSON.stringify(data)},done:function(res){var skipreload=!1;document.querySelector(".booking-elective-component")&&window.location.reload();const jsonarray=JSON.parse(res.json),templates=res.template.split(","),buttons=document.querySelectorAll(SELECTORS.BOOKITBUTTON+"[data-itemid='"+itemid+"'][data-area='"+area+"']"),promises=[];buttons.forEach((button=>{if(console.log("bookit values",button.dataset.nojs,res.status),skipreload=!0,1==button.dataset.nojs&&0==res.status)console.log("bookit skip",button.dataset.nojs,res.status);else{const arraytoreduce=[...jsonarray];1==res.status&&(skipreload=!1),templates.forEach((template=>{var _data$data;const data=arraytoreduce.shift(),datatorender=null!==(_data$data=data.data)&&void 0!==_data$data?_data$data:data,promise=_templates.default.renderForPromise(template,datatorender).then((_ref=>{let{html:html,js:js}=_ref;return _templates.default.replaceNode(button,html,js),!0})).catch((ex=>{_notification.default.addNotification({message:"failed rendering "+ex,type:"danger"})}));promises.push(promise)}))}})),Promise.all(promises).then((()=>{const backdrop=document.querySelector(SELECTORS.STATICBACKDROP);return("subbooking"===area||currentbookitpage[itemid]{console.log(e)}))}}])}_exports.initbookitbutton=initbookitbutton;const initprepagemodal=(optionid,userid,totalnumberofpages,uniquid)=>{if(console.log("initprepagemodal",optionid,userid,totalnumberofpages,uniquid),optionid&&uniquid&&totalnumberofpages)currentbookitpage[optionid]=0,totalbookitpages[optionid]=totalnumberofpages,function(optionid,userid,uniquid,totalnumberofpages,callback){document.querySelectorAll("[id^="+SELECTORS.MODALID+optionid+"_"+uniquid+"]").forEach((element=>{if(element&&"true"!=element.dataset.initialized){element.dataset.initialized=!0;for(var observer=new MutationObserver((function(){isHidden(element)||element.classList.contains("show")&&callback(optionid,userid,uniquid,totalnumberofpages)}));null!==element;){if(isHidden(element)){if(element.dataset.observed)return;return observer.observe(element,{attributes:!0}),void(element.dataset.observed=!0)}element=element.parentElement}callback(optionid,userid,uniquid,totalnumberofpages)}}))}(optionid,userid,uniquid,totalnumberofpages,loadPreBookingPage);else{document.querySelectorAll("[id^="+SELECTORS.MODALID).forEach((element=>{element.querySelector('[data-action="bookondetail"]')?(optionid=element.dataset.optionid,uniquid=element.dataset.uniquid,userid=element.dataset.userid,totalnumberofpages=element.dataset.pages,optionid&&uniquid&&initprepagemodal(optionid,userid,totalnumberofpages,uniquid)):console.log("bookondetail abort")}))}};_exports.initprepagemodal=initprepagemodal;const initprepageinline=(optionid,userid,totalnumberofpages,uniquid)=>{if(console.log("initprepageinline",optionid,userid,totalnumberofpages,uniquid),!optionid||!uniquid||!totalnumberofpages){const elements=document.querySelectorAll("[id^="+SELECTORS.INLINEID);return console.log(elements),void elements.forEach((element=>{optionid=element.dataset.optionid,uniquid=element.dataset.uniquid,userid=element.dataset.userid,totalnumberofpages=element.dataset.pages,optionid&&uniquid&&initprepageinline(optionid,userid,totalnumberofpages,uniquid)}))}currentbookitpage[optionid]=0,totalbookitpages[optionid]=totalnumberofpages;document.querySelectorAll('[data-itemid="'+optionid+'"][data-area="option"]').forEach((button=>{button.dataset.initialized||(button.dataset.initialized=!0,console.log("add listener to button",button,button.dataset.action),button.querySelector('[data-action="bookondetail"]')?console.log("bookondetail abort"):button.addEventListener("click",(e=>{console.log("e.target",e.target);let rowcontainer=e.target.closest(".mod-booking-row");if(!rowcontainer.lastElementChild.classList.contains("inlineprepagearea")){let inlinediv=returnVisibleElement(optionid,uniquid,SELECTORS.INMODALDIV);rowcontainer.append(inlinediv.closest(".inlineprepagearea")),loadPreBookingPage(optionid,userid,uniquid)}})))}))};function isHidden(el){var style=window.getComputedStyle(el);return"none"===style.display||"hidden"===style.visibility}_exports.initprepageinline=initprepageinline;const loadPreBookingPage=function(optionid){let userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,uniquid=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";const element=returnVisibleElement(optionid,uniquid,SELECTORS.INMODALDIV);if(element)for(;element.firstChild;)element.removeChild(element.firstChild);else console.error("didnt find element");_ajax.default.call([{methodname:"mod_booking_allow_add_item_to_cart",args:{itemid:optionid,userid:userid},done:function(response){return 1==response.success||5==response.success||0==response.success?_ajax.default.call([{methodname:"mod_booking_load_pre_booking_page",args:{optionid:optionid,userid:userid,pagenumber:currentbookitpage[optionid]},done:function(res){currentbookitpage[optionid]===totalbookitpages[optionid]-1&&(currentbookitpage[optionid]=0);const jsonobject=JSON.parse(res.json);renderTemplatesOnPage(res.template.split(","),jsonobject,element)},fail:function(err){console.log(err)}}]):(console.log("closeModal"),(0,_prepageFooter.closeModal)(optionid,!1),(0,_prepageFooter.closeInline)(optionid,!1),("function"==typeof _systemImportTransformerGlobalIdentifier.define&&_systemImportTransformerGlobalIdentifier.define.amd?new Promise((function(resolve,reject){_systemImportTransformerGlobalIdentifier.require(["local_shopping_cart/cart"],resolve,reject)})):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&_systemImportTransformerGlobalIdentifier.require&&"component"===_systemImportTransformerGlobalIdentifier.require.loader?Promise.resolve(require("local_shopping_cart/cart")):Promise.resolve(_systemImportTransformerGlobalIdentifier["local_shopping_cart/cart"])).then((shoppingcart=>{const addItemShowNotification=shoppingcart.addItemShowNotification;response.userid=userid,addItemShowNotification(response)})).catch((err=>{console.log(err)}))),!0},fail:function(err){console.log(err)}}])};async function renderTemplatesOnPage(templates,dataarray,element){const modal=element.closest(".prepage-body");let elementid=modal.id;if(!elementid){const parent=modal.closest("[id]");elementid=parent.id}return console.log(modal,elementid),modal.querySelector(SELECTORS.MODALHEADER).innerHTML="",modal.querySelector(SELECTORS.INMODALDIV).innerHTML="",modal.querySelector(SELECTORS.MODALBUTTONAREA).innerHTML="",modal.querySelector(SELECTORS.MODALFOOTER).innerHTML="",templates.forEach((async template=>{const data=dataarray.shift();let targetelement=element;if(!data)return!0;switch(data.data.elementid=elementid,template){case"mod_booking/bookingpage/header":targetelement=modal.querySelector(SELECTORS.MODALHEADER);break;case"mod_booking/bookit_button":case"mod_booking/bookit_price":targetelement=modal.querySelector(SELECTORS.MODALBUTTONAREA);break;case"mod_booking/bookingpage/footer":targetelement=modal.querySelector(SELECTORS.MODALFOOTER);break;default:targetelement=modal.querySelector(SELECTORS.INMODALDIV)}return console.log(data.data),await _templates.default.renderForPromise(template,data.data).then((_ref2=>{let{html:html,js:js}=_ref2;return _templates.default.replaceNodeContents(targetelement,html,js),!0})).catch((ex=>{_notification.default.addNotification({message:"failed rendering "+JSON.stringify(ex),type:"danger"})})),!0})),!0}function returnVisibleElement(optionid,uniquid,appendedSelector){let selector='[id^="'+SELECTORS.MODALID+optionid+"_"+uniquid+'"] '+appendedSelector;uniquid&&0!==uniquid.length||(selector='[id^="'+SELECTORS.MODALID+optionid+'_"].show '+appendedSelector);let elements=document.querySelectorAll(selector);0===elements.length&&(selector='[id^="'+SELECTORS.INLINEID+optionid+'_"] '+appendedSelector,elements=document.querySelectorAll(selector));let visibleElement=null;return elements.forEach((element=>{for(var elementtocheck=element.parentElement.parentElement;null!==elementtocheck&&!isHidden(elementtocheck);)elementtocheck=elementtocheck.parentElement;elementtocheck||(visibleElement=element)})),visibleElement}_exports.loadPreBookingPage=loadPreBookingPage})); //# sourceMappingURL=bookit.min.js.map \ No newline at end of file diff --git a/amd/build/bookit.min.js.map b/amd/build/bookit.min.js.map index 44819fe0..2fd55acb 100644 --- a/amd/build/bookit.min.js.map +++ b/amd/build/bookit.min.js.map @@ -1 +1 @@ -{"version":3,"file":"bookit.min.js","sources":["../src/bookit.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * @module mod_booking/bookit\n * @copyright Wunderbyte GmbH \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport Templates from 'core/templates';\nimport Notification from 'core/notification';\nimport {reloadAllTables} from 'local_wunderbyte_table/reload';\n\nimport {closeModal, closeInline} from 'mod_booking/bookingpage/prepageFooter';\n\nvar currentbookitpage = {};\nvar totalbookitpages = {};\n\nexport var SELECTORS = {\n MODALID: 'sbPrePageModal_',\n INLINEID: 'sbPrePageInline_',\n INMODALDIV: ' div.modalMainContent',\n MODALHEADER: 'div.modalHeader',\n MODALBUTTONAREA: 'div.modalButtonArea',\n MODALFOOTER: 'div.modalFooter',\n CONTINUEBUTTON: 'a.continue-button', // Don't want to find button right now.\n BACKBUTTON: 'a.back-button', // Don't want to find button right now.\n BOOKITBUTTON: 'div.booking-button-area.noprice',\n INMODALBUTTON: 'div.in-modal-button',\n STATICBACKDROP: 'div.modal-backdrop',\n};\n\n/**\n * Initializes the bookit button for the normal bookit function.\n * @param {integer} itemid\n * @param {string} area\n */\nexport const initbookitbutton = (itemid, area) => {\n\n const initselector = SELECTORS.BOOKITBUTTON +\n '[data-itemid]' +\n '[data-area]';\n\n if (!itemid || !area) {\n const initbuttons = document.querySelectorAll(initselector);\n initbuttons.forEach(button => {\n const inititemid = button.dataset.itemid;\n const initarea = button.dataset.area;\n initbookitbutton(inititemid, initarea);\n });\n return;\n }\n\n const selector = SELECTORS.BOOKITBUTTON +\n '[data-itemid=\"' + itemid + '\"]' +\n '[data-area=\"' + area + '\"]';\n\n const buttons = document.querySelectorAll(selector);\n\n if (!buttons) {\n return;\n }\n\n // We support more than one booking button on the same page.\n buttons.forEach(button => {\n\n if (button.dataset.nojs) {\n return;\n }\n\n // We don't run code on disabled buttons.\n if (button.classList.contains('disabled')) {\n return;\n }\n\n if (!button.dataset.initialized) {\n button.dataset.initialized = 'true';\n\n const userid = button.dataset.userid;\n\n if (button.querySelector('[data-action=\"bookondetail\"]')) {\n // eslint-disable-next-line no-console\n console.log('bookondetail abort');\n return;\n }\n\n button.addEventListener('click', (e) => {\n\n // E.stopPropagation();\n\n const data = button.dataset;\n\n if (e.target.classList.contains('shopping-cart-cancel-button')) {\n\n import('local_shopping_cart/shistory')\n // eslint-disable-next-line promise/always-return\n .then(shoppingcart => {\n const confirmCancelModal = shoppingcart.confirmCancelModal;\n // Now you can use the specific function\n confirmCancelModal(button, 0);\n })\n .catch(err => {\n // Handle any errors, including if the module doesn't exist\n // eslint-disable-next-line no-console\n console.log(err);\n });\n\n\n } else if (e.target.classList.contains('btn')) {\n bookit(itemid, area, userid, data);\n }\n });\n }\n });\n};\n\n/**\n *\n * @param {int} itemid\n * @param {string} area\n * @param {int} userid\n * @param {object} data\n */\nexport function bookit(itemid, area, userid, data) {\n\n // eslint-disable-next-line no-console\n console.log('run bookit');\n\n Ajax.call([{\n methodname: \"mod_booking_bookit\",\n args: {\n 'itemid': itemid,\n 'area': area,\n 'userid': userid,\n 'data': JSON.stringify(data),\n },\n done: function(res) {\n\n var skipreload = false;\n\n if (document.querySelector('.booking-elective-component')) {\n window.location.reload();\n }\n\n const jsonarray = JSON.parse(res.json);\n\n // We might have more than one template to render.\n const templates = res.template.split(',');\n\n // There might be more than one button area.\n const buttons = document.querySelectorAll(SELECTORS.BOOKITBUTTON +\n '[data-itemid=\\'' + itemid + '\\']' +\n '[data-area=\\'' + area + '\\']');\n\n const promises = [];\n\n // We run through every button. and render the data.\n buttons.forEach(button => {\n\n // eslint-disable-next-line no-console\n console.log('bookit values', button.dataset.nojs, res.status);\n skipreload = true;\n if (button.dataset.nojs == 1\n && res.status == 0) {\n // eslint-disable-next-line no-console\n console.log('bookit skip', button.dataset.nojs, res.status);\n } else {\n // For every button, we need a new jsonarray.\n const arraytoreduce = [...jsonarray];\n if (res.status == 1) {\n skipreload = false;\n }\n templates.forEach(template => {\n\n const data = arraytoreduce.shift();\n\n const datatorender = data.data ?? data;\n\n const promise = Templates.renderForPromise(template, datatorender).then(({html, js}) => {\n\n Templates.replaceNode(button, html, js);\n\n return true;\n }).catch(ex => {\n Notification.addNotification({\n message: 'failed rendering ' + ex,\n type: \"danger\"\n });\n });\n\n promises.push(promise);\n });\n }\n });\n\n Promise.all(promises).then(() => {\n\n const backdrop = document.querySelector(SELECTORS.STATICBACKDROP);\n\n if (area === 'subbooking') {\n skipreload = true;\n } else {\n if (currentbookitpage[itemid] < totalbookitpages[itemid]) {\n skipreload = true;\n }\n }\n\n // eslint-disable-next-line no-console\n console.log('skipreload', skipreload, currentbookitpage[itemid], totalbookitpages[itemid]);\n\n if (!backdrop && !skipreload) {\n reloadAllTables();\n }\n\n // The actions on successful booking are executed elsewhere.\n return true;\n }).catch(e => {\n // eslint-disable-next-line no-console\n console.log(e);\n });\n }\n }]);\n}\n\n/**\n * Gets called from mustache template.\n * @param {integer} optionid\n * @param {integer} userid\n * @param {integer} totalnumberofpages\n * @param {string} uniquid\n */\nexport const initprepagemodal = (optionid, userid, totalnumberofpages, uniquid) => {\n\n // eslint-disable-next-line no-console\n console.log('initprepagemodal', optionid, userid, totalnumberofpages, uniquid);\n\n if (!optionid || !uniquid || !totalnumberofpages) {\n\n const elements = document.querySelectorAll(\"[id^=\" + SELECTORS.MODALID);\n\n elements.forEach(element => {\n\n if (!element.querySelector('[data-action=\"bookondetail\"]')) {\n // eslint-disable-next-line no-console\n console.log('bookondetail abort');\n return;\n }\n\n optionid = element.dataset.optionid;\n uniquid = element.dataset.uniquid;\n userid = element.dataset.userid;\n totalnumberofpages = element.dataset.pages;\n if (optionid && uniquid) {\n initprepagemodal(optionid, userid, totalnumberofpages, uniquid);\n }\n });\n return;\n }\n\n currentbookitpage[optionid] = 0;\n totalbookitpages[optionid] = totalnumberofpages;\n\n // We need to get all prepage modals on this site. Make sure they are initialized.\n respondToVisibility(optionid, userid, uniquid, totalnumberofpages, loadPreBookingPage);\n};\n\n/**\n * Gets called from mustache template.\n * @param {integer} optionid\n * @param {integer} userid\n * @param {integer} totalnumberofpages\n * @param {string} uniquid\n */\nexport const initprepageinline = (optionid, userid, totalnumberofpages, uniquid) => {\n\n // eslint-disable-next-line no-console\n console.log('initprepageinline', optionid, userid, totalnumberofpages, uniquid);\n\n if (!optionid || !uniquid || !totalnumberofpages) {\n\n const elements = document.querySelectorAll(\"[id^=\" + SELECTORS.INLINEID);\n\n // eslint-disable-next-line no-console\n console.log(elements);\n\n elements.forEach(element => {\n optionid = element.dataset.optionid;\n uniquid = element.dataset.uniquid;\n userid = element.dataset.userid;\n totalnumberofpages = element.dataset.pages;\n if (optionid && uniquid) {\n initprepageinline(optionid, userid, totalnumberofpages, uniquid);\n }\n });\n return;\n }\n\n currentbookitpage[optionid] = 0;\n totalbookitpages[optionid] = totalnumberofpages;\n\n // Retrieve the right button.\n const buttons = document.querySelectorAll(\n '[data-itemid=\"' + optionid + '\"]' +\n '[data-area=\"option\"]'\n );\n\n // Add the click listener to the button.\n\n buttons.forEach(button => {\n\n if (button.dataset.initialized) {\n return;\n }\n\n button.dataset.initialized = true;\n\n // eslint-disable-next-line no-console\n console.log('add listener to button', button, button.dataset.action);\n\n if (button.querySelector('[data-action=\"bookondetail\"]')) {\n // eslint-disable-next-line no-console\n console.log('bookondetail abort');\n return;\n }\n\n button.addEventListener('click', e => {\n\n // eslint-disable-next-line no-console\n console.log('e.target', e.target);\n\n // Get the row element.\n let rowcontainer = e.target.closest('.mod-booking-row');\n\n const transferarea = !rowcontainer.lastElementChild.classList.contains('inlineprepagearea');\n // We move the inlineprepagearea only if we need to.\n if (transferarea) {\n let inlinediv = returnVisibleElement(optionid, uniquid, SELECTORS.INMODALDIV);\n\n rowcontainer.append(inlinediv.closest('.inlineprepagearea'));\n // Inlinediv.remove();\n\n // We need to get all prepage modals on this site. Make sure they are initialized.\n loadPreBookingPage(optionid, userid, uniquid);\n }\n });\n });\n};\n\n/**\n * React on visibility change.\n * @param {integer} optionid\n * @param {integer} userid\n * @param {string} uniquid\n * @param {integer} totalnumberofpages\n * @param {function} callback\n */\nfunction respondToVisibility(optionid, userid, uniquid, totalnumberofpages, callback) {\n\n let elements = document.querySelectorAll(\"[id^=\" + SELECTORS.MODALID + optionid + \"_\" + uniquid + \"]\");\n\n elements.forEach(element => {\n\n if (!element || element.dataset.initialized == 'true') {\n return;\n }\n\n element.dataset.initialized = true;\n\n var observer = new MutationObserver(function() {\n\n if (!isHidden(element)) {\n\n // Because of the modal animation, \"isHIdden\" is also true on hiding modal.\n if (element.classList.contains('show')) {\n\n // Todo: Make sure it's not triggered on close.\n callback(optionid, userid, uniquid, totalnumberofpages);\n }\n }\n });\n\n // We look if we find a hidden parent. If not, we load right away.\n while (element !== null) {\n if (!isHidden(element)) {\n element = element.parentElement;\n } else {\n if (element.dataset.observed) {\n return;\n }\n\n observer.observe(element, {attributes: true});\n element.dataset.observed = true;\n return;\n }\n }\n callback(optionid, userid, uniquid, totalnumberofpages);\n });\n}\n\n/**\n * Function to check visibility of element.\n * @param {*} el\n * @returns {boolean}\n */\nfunction isHidden(el) {\n var style = window.getComputedStyle(el);\n return ((style.display === 'none') || (style.visibility === 'hidden'));\n}\n\n/**\n * Loads the (next) pre booking page.\n * @param {integer} optionid\n * @param {integer} userid\n * @param {string} uniquid\n */\nexport const loadPreBookingPage = (\n optionid, userid = 0, uniquid = '') => {\n\n const element = returnVisibleElement(optionid, uniquid, SELECTORS.INMODALDIV);\n\n if (element) {\n while (element.firstChild) {\n element.removeChild(element.firstChild);\n }\n } else {\n // eslint-disable-next-line no-console\n console.error('didnt find element');\n }\n\n Ajax.call([{\n methodname: \"mod_booking_allow_add_item_to_cart\",\n args: {\n 'itemid': optionid,\n 'userid': userid,\n },\n done: function(response) {\n // Will always be 1, if shopping cart is not installed!\n if (response.success == 1\n || response.success == 5 // Already booked, we need this for subbokings.\n || response.success == 0 // Already in cart, we need this for subbokings.\n ) {\n Ajax.call([{\n methodname: \"mod_booking_load_pre_booking_page\",\n args: {\n optionid,\n userid,\n 'pagenumber': currentbookitpage[optionid],\n },\n done: function(res) {\n // If we are on the last page, we reset it to 0.\n if (currentbookitpage[optionid] === totalbookitpages[optionid] - 1) {\n currentbookitpage[optionid] = 0;\n }\n\n const jsonobject = JSON.parse(res.json);\n\n // We support more than one template, they will be seperated by comma.\n // We have a data key in the json\n const templates = res.template.split(',');\n let dataarray = jsonobject;\n // Const buttontype = res.buttontype;\n\n renderTemplatesOnPage(templates, dataarray, element);\n },\n fail: function(err) {\n // eslint-disable-next-line no-console\n console.log(err);\n }\n }]);\n } else {\n\n // eslint-disable-next-line no-console\n console.log('closeModal');\n closeModal(optionid, false);\n closeInline(optionid, false);\n\n // Make sure that the prepage modal is actually closed.\n\n import('local_shopping_cart/cart')\n // eslint-disable-next-line promise/always-return\n .then(shoppingcart => {\n const addItemShowNotification = shoppingcart.addItemShowNotification;\n // Now you can use the specific function\n response.userid = userid;\n addItemShowNotification(response);\n })\n .catch(err => {\n // Handle any errors, including if the module doesn't exist\n // eslint-disable-next-line no-console\n console.log(err);\n });\n }\n\n return true;\n },\n fail: function(err) {\n // eslint-disable-next-line no-console\n console.log(err);\n }\n }]);\n};\n\n/**\n *\n * @param {string} templates\n * @param {object} dataarray\n * @param {HTMLElement} element\n */\nasync function renderTemplatesOnPage(templates, dataarray, element) {\n\n const modal = element.closest('.prepage-body');\n\n // We need to pass the id of our element to the templates to render.\n // If not, we might select the wrong modal or collapsible.\n let elementid = modal.id;\n\n if (!elementid) {\n const parent = modal.closest('[id]');\n elementid = parent.id;\n }\n\n // eslint-disable-next-line no-console\n console.log(modal, elementid);\n\n modal.querySelector(SELECTORS.MODALHEADER).innerHTML = '';\n modal.querySelector(SELECTORS.INMODALDIV).innerHTML = '';\n modal.querySelector(SELECTORS.MODALBUTTONAREA).innerHTML = '';\n modal.querySelector(SELECTORS.MODALFOOTER).innerHTML = '';\n\n templates.forEach(async template => {\n\n const data = dataarray.shift();\n\n let targetelement = element;\n\n if (!data) {\n return true;\n }\n\n data.data.elementid = elementid;\n\n switch (template) {\n case 'mod_booking/bookingpage/header':\n targetelement = modal.querySelector(SELECTORS.MODALHEADER);\n break;\n case 'mod_booking/bookit_button':\n case 'mod_booking/bookit_price':\n targetelement = modal.querySelector(SELECTORS.MODALBUTTONAREA);\n break;\n case 'mod_booking/bookingpage/footer':\n targetelement = modal.querySelector(SELECTORS.MODALFOOTER);\n break;\n default:\n targetelement = modal.querySelector(SELECTORS.INMODALDIV);\n break;\n }\n\n // eslint-disable-next-line no-console\n console.log(data.data);\n\n await Templates.renderForPromise(template, data.data).then(({html, js}) => {\n\n Templates.replaceNodeContents(targetelement, html, js);\n\n return true;\n }).catch(ex => {\n Notification.addNotification({\n message: 'failed rendering ' + JSON.stringify(ex),\n type: \"danger\"\n });\n });\n return true;\n });\n return true;\n}\n\n/**\n * We want to find out the visible modal\n * @param {integer} optionid\n * @param {string} uniquid\n * @param {string} appendedSelector\n * @returns {HTMLElement}\n */\nfunction returnVisibleElement(optionid, uniquid, appendedSelector) {\n\n // First, we get all the possbile Elements (we don't now the unique id appended to the element.)\n let selector = '[id^=\"' + SELECTORS.MODALID + optionid + '_' + uniquid + '\"] ' + appendedSelector;\n if (!uniquid || uniquid.length === 0) {\n selector = '[id^=\"' + SELECTORS.MODALID + optionid + '_\"].show ' + appendedSelector;\n }\n\n let elements = document.querySelectorAll(selector);\n\n // If the nodelist is empty, we we mgiht use inline.\n // If so, we need to have a different way of selecting elements.\n if (elements.length === 0) {\n\n selector = '[id^=\"' + SELECTORS.INLINEID + optionid + '_\"] ' + appendedSelector;\n elements = document.querySelectorAll(selector);\n\n }\n\n let visibleElement = null;\n\n elements.forEach(element => {\n\n var elementtocheck = element.parentElement.parentElement;\n\n // We look if we find a hidden parent. If not, we load right away.\n while (elementtocheck !== null) {\n if (!isHidden(elementtocheck)) {\n elementtocheck = elementtocheck.parentElement;\n\n } else {\n\n break;\n }\n }\n // If after the while, we have still an element, it's hidden.\n // So we only apply visible if it's null.\n if (!elementtocheck) {\n visibleElement = element;\n }\n });\n\n return visibleElement;\n}\n\n/**\n * Load next prepage booking page.\n * @param {int} optionid\n * @param {int} userid\n */\nexport function continueToNextPage(optionid, userid) {\n\n // eslint-disable-next-line no-console\n console.log('continueToNextPage', optionid, userid, currentbookitpage[optionid], totalbookitpages[optionid]);\n if (currentbookitpage[optionid] < totalbookitpages[optionid]) {\n currentbookitpage[optionid]++;\n loadPreBookingPage(optionid, userid);\n }\n}\n\n/**\n * Load previous prepage booking page.\n * @param {int} optionid\n * @param {int} userid\n */\nexport function backToPreviousPage(optionid, userid) {\n\n currentbookitpage[optionid]--;\n\n loadPreBookingPage(optionid, userid);\n}\n\n/**\n * Set back variables used in modal.\n * @param {int} optionid\n */\nexport function setBackModalVariables(optionid) {\n\n currentbookitpage[optionid] = 0;\n}\n"],"names":["optionid","userid","currentbookitpage","loadPreBookingPage","console","log","totalbookitpages","SELECTORS","MODALID","INLINEID","INMODALDIV","MODALHEADER","MODALBUTTONAREA","MODALFOOTER","CONTINUEBUTTON","BACKBUTTON","BOOKITBUTTON","INMODALBUTTON","STATICBACKDROP","initbookitbutton","itemid","area","initselector","document","querySelectorAll","forEach","button","inititemid","dataset","initarea","selector","buttons","nojs","classList","contains","initialized","querySelector","addEventListener","e","data","target","then","shoppingcart","confirmCancelModal","catch","err","bookit","call","methodname","args","JSON","stringify","done","res","skipreload","window","location","reload","jsonarray","parse","json","templates","template","split","promises","status","arraytoreduce","shift","datatorender","promise","Templates","renderForPromise","_ref","html","js","replaceNode","ex","addNotification","message","type","push","Promise","all","backdrop","initprepagemodal","totalnumberofpages","uniquid","callback","element","observer","MutationObserver","isHidden","observed","observe","attributes","parentElement","respondToVisibility","pages","initprepageinline","elements","action","rowcontainer","closest","lastElementChild","inlinediv","returnVisibleElement","append","el","style","getComputedStyle","display","visibility","firstChild","removeChild","error","response","success","jsonobject","renderTemplatesOnPage","fail","addItemShowNotification","dataarray","modal","elementid","id","parent","innerHTML","async","targetelement","_ref2","replaceNodeContents","appendedSelector","length","visibleElement","elementtocheck"],"mappings":"kWAqpBmCA,SAAUC,QAEzCC,kBAAkBF,YAElBG,mBAAmBH,SAAUC,qEAnBED,SAAUC,QAGzCG,QAAQC,IAAI,qBAAsBL,SAAUC,OAAQC,kBAAkBF,UAAWM,iBAAiBN,WAC9FE,kBAAkBF,UAAYM,iBAAiBN,YAC/CE,kBAAkBF,YAClBG,mBAAmBH,SAAUC,oKAoBCD,UA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B,KAAKC,UAAUyB,IAC9CG,KAAM,eAGP,MAEJ,WAUF0B,qBAAqBzG,SAAUsF,QAAS6C,sBAGzCrG,SAAW,SAAWvB,UAAUC,QAAUR,SAAW,IAAMsF,QAAU,MAAQ6C,iBAC5E7C,SAA8B,IAAnBA,QAAQ8C,SACpBtG,SAAW,SAAWvB,UAAUC,QAAUR,SAAW,YAAcmI,sBAGnEhC,SAAW5E,SAASC,iBAAiBM,UAIjB,IAApBqE,SAASiC,SAETtG,SAAW,SAAWvB,UAAUE,SAAWT,SAAW,OAASmI,iBAC/DhC,SAAW5E,SAASC,iBAAiBM,eAIrCuG,eAAiB,YAErBlC,SAAS1E,SAAQ+D,kBAET8C,eAAiB9C,QAAQO,cAAcA,cAGjB,OAAnBuC,iBACE3C,SAAS2C,iBACVA,eAAiBA,eAAevC,cASnCuC,iBACDD,eAAiB7C,YAIlB6C"} \ No newline at end of file +{"version":3,"file":"bookit.min.js","sources":["../src/bookit.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * @module mod_booking/bookit\n * @copyright Wunderbyte GmbH \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport Templates from 'core/templates';\nimport Notification from 'core/notification';\nimport {reloadAllTables} from 'local_wunderbyte_table/reload';\n\nimport {closeModal, closeInline} from 'mod_booking/bookingpage/prepageFooter';\n\nvar currentbookitpage = {};\nvar totalbookitpages = {};\n\nexport var SELECTORS = {\n MODALID: 'sbPrePageModal_',\n INLINEID: 'sbPrePageInline_',\n INMODALDIV: ' div.modalMainContent',\n MODALHEADER: 'div.modalHeader',\n MODALBUTTONAREA: 'div.modalButtonArea',\n MODALFOOTER: 'div.modalFooter',\n CONTINUEBUTTON: 'a.continue-button', // Don't want to find button right now.\n BACKBUTTON: 'a.back-button', // Don't want to find button right now.\n BOOKITBUTTON: 'div.booking-button-area.noprice',\n INMODALBUTTON: 'div.in-modal-button',\n STATICBACKDROP: 'div.modal-backdrop',\n};\n\n/**\n * Initializes the bookit button for the normal bookit function.\n * @param {integer} itemid\n * @param {string} area\n */\nexport const initbookitbutton = (itemid, area) => {\n\n const initselector = SELECTORS.BOOKITBUTTON +\n '[data-itemid]' +\n '[data-area]';\n\n if (!itemid || !area) {\n const initbuttons = document.querySelectorAll(initselector);\n initbuttons.forEach(button => {\n const inititemid = button.dataset.itemid;\n const initarea = button.dataset.area;\n initbookitbutton(inititemid, initarea);\n });\n return;\n }\n\n const selector = SELECTORS.BOOKITBUTTON +\n '[data-itemid=\"' + itemid + '\"]' +\n '[data-area=\"' + area + '\"]';\n\n const buttons = document.querySelectorAll(selector);\n\n if (!buttons) {\n return;\n }\n\n // We support more than one booking button on the same page.\n buttons.forEach(button => {\n\n if (button.dataset.nojs) {\n return;\n }\n\n // We don't run code on disabled buttons.\n if (button.classList.contains('disabled')) {\n return;\n }\n\n if (!button.dataset.initialized) {\n button.dataset.initialized = 'true';\n\n const userid = button.dataset.userid;\n\n if (button.querySelector('[data-action=\"bookondetail\"]')) {\n // eslint-disable-next-line no-console\n console.log('bookondetail abort');\n return;\n }\n\n button.addEventListener('click', (e) => {\n\n // E.stopPropagation();\n\n const data = button.dataset;\n\n if (e.target.classList.contains('shopping-cart-cancel-button')) {\n\n import('local_shopping_cart/shistory')\n // eslint-disable-next-line promise/always-return\n .then(shoppingcart => {\n const confirmCancelModal = shoppingcart.confirmCancelModal;\n // Now you can use the specific function\n confirmCancelModal(button, 0);\n })\n .catch(err => {\n // Handle any errors, including if the module doesn't exist\n // eslint-disable-next-line no-console\n console.log(err);\n });\n\n\n } else if (e.target.classList.contains('btn')) {\n bookit(itemid, area, userid, data);\n }\n });\n }\n });\n};\n\n/**\n *\n * @param {int} itemid\n * @param {string} area\n * @param {int} userid\n * @param {object} data\n */\nexport function bookit(itemid, area, userid, data) {\n\n // eslint-disable-next-line no-console\n console.log('run bookit');\n\n Ajax.call([{\n methodname: \"mod_booking_bookit\",\n args: {\n 'itemid': itemid,\n 'area': area,\n 'userid': userid,\n 'data': JSON.stringify(data),\n },\n done: function(res) {\n\n var skipreload = false;\n\n if (document.querySelector('.booking-elective-component')) {\n window.location.reload();\n }\n\n const jsonarray = JSON.parse(res.json);\n\n // We might have more than one template to render.\n const templates = res.template.split(',');\n\n // There might be more than one button area.\n const buttons = document.querySelectorAll(SELECTORS.BOOKITBUTTON +\n '[data-itemid=\\'' + itemid + '\\']' +\n '[data-area=\\'' + area + '\\']');\n\n const promises = [];\n\n // We run through every button. and render the data.\n buttons.forEach(button => {\n\n // eslint-disable-next-line no-console\n console.log('bookit values', button.dataset.nojs, res.status);\n skipreload = true;\n if (button.dataset.nojs == 1\n && res.status == 0) {\n // eslint-disable-next-line no-console\n console.log('bookit skip', button.dataset.nojs, res.status);\n } else {\n // For every button, we need a new jsonarray.\n const arraytoreduce = [...jsonarray];\n if (res.status == 1) {\n skipreload = false;\n }\n templates.forEach(template => {\n\n const data = arraytoreduce.shift();\n\n const datatorender = data.data ?? data;\n\n const promise = Templates.renderForPromise(template, datatorender).then(({html, js}) => {\n\n Templates.replaceNode(button, html, js);\n\n return true;\n }).catch(ex => {\n Notification.addNotification({\n message: 'failed rendering ' + ex,\n type: \"danger\"\n });\n });\n\n promises.push(promise);\n });\n }\n });\n\n Promise.all(promises).then(() => {\n\n const backdrop = document.querySelector(SELECTORS.STATICBACKDROP);\n\n if (area === 'subbooking') {\n skipreload = true;\n } else {\n if (currentbookitpage[itemid] < totalbookitpages[itemid]) {\n skipreload = true;\n }\n }\n\n // eslint-disable-next-line no-console\n console.log('skipreload', skipreload, currentbookitpage[itemid], totalbookitpages[itemid]);\n\n if (!backdrop && !skipreload) {\n reloadAllTables();\n }\n\n // The actions on successful booking are executed elsewhere.\n return true;\n }).catch(e => {\n // eslint-disable-next-line no-console\n console.log(e);\n });\n }\n }]);\n}\n\n/**\n * Gets called from mustache template.\n * @param {integer} optionid\n * @param {integer} userid\n * @param {integer} totalnumberofpages\n * @param {string} uniquid\n */\nexport const initprepagemodal = (optionid, userid, totalnumberofpages, uniquid) => {\n\n // eslint-disable-next-line no-console\n console.log('initprepagemodal', optionid, userid, totalnumberofpages, uniquid);\n\n if (!optionid || !uniquid || !totalnumberofpages) {\n\n const elements = document.querySelectorAll(\"[id^=\" + SELECTORS.MODALID);\n\n elements.forEach(element => {\n\n if (!element.querySelector('[data-action=\"bookondetail\"]')) {\n // eslint-disable-next-line no-console\n console.log('bookondetail abort');\n return;\n }\n\n optionid = element.dataset.optionid;\n uniquid = element.dataset.uniquid;\n userid = element.dataset.userid;\n totalnumberofpages = element.dataset.pages;\n if (optionid && uniquid) {\n initprepagemodal(optionid, userid, totalnumberofpages, uniquid);\n }\n });\n return;\n }\n\n currentbookitpage[optionid] = 0;\n totalbookitpages[optionid] = totalnumberofpages;\n\n // We need to get all prepage modals on this site. Make sure they are initialized.\n respondToVisibility(optionid, userid, uniquid, totalnumberofpages, loadPreBookingPage);\n};\n\n/**\n * Gets called from mustache template.\n * @param {integer} optionid\n * @param {integer} userid\n * @param {integer} totalnumberofpages\n * @param {string} uniquid\n */\nexport const initprepageinline = (optionid, userid, totalnumberofpages, uniquid) => {\n\n // eslint-disable-next-line no-console\n console.log('initprepageinline', optionid, userid, totalnumberofpages, uniquid);\n\n if (!optionid || !uniquid || !totalnumberofpages) {\n\n const elements = document.querySelectorAll(\"[id^=\" + SELECTORS.INLINEID);\n\n // eslint-disable-next-line no-console\n console.log(elements);\n\n elements.forEach(element => {\n optionid = element.dataset.optionid;\n uniquid = element.dataset.uniquid;\n userid = element.dataset.userid;\n totalnumberofpages = element.dataset.pages;\n if (optionid && uniquid) {\n initprepageinline(optionid, userid, totalnumberofpages, uniquid);\n }\n });\n return;\n }\n\n currentbookitpage[optionid] = 0;\n totalbookitpages[optionid] = totalnumberofpages;\n\n // Retrieve the right button.\n const buttons = document.querySelectorAll(\n '[data-itemid=\"' + optionid + '\"]' +\n '[data-area=\"option\"]'\n );\n\n // Add the click listener to the button.\n\n buttons.forEach(button => {\n\n if (button.dataset.initialized) {\n return;\n }\n\n button.dataset.initialized = true;\n\n // eslint-disable-next-line no-console\n console.log('add listener to button', button, button.dataset.action);\n\n if (button.querySelector('[data-action=\"bookondetail\"]')) {\n // eslint-disable-next-line no-console\n console.log('bookondetail abort');\n return;\n }\n\n button.addEventListener('click', e => {\n\n // eslint-disable-next-line no-console\n console.log('e.target', e.target);\n\n // Get the row element.\n let rowcontainer = e.target.closest('.mod-booking-row');\n\n const transferarea = !rowcontainer.lastElementChild.classList.contains('inlineprepagearea');\n // We move the inlineprepagearea only if we need to.\n if (transferarea) {\n let inlinediv = returnVisibleElement(optionid, uniquid, SELECTORS.INMODALDIV);\n\n rowcontainer.append(inlinediv.closest('.inlineprepagearea'));\n // Inlinediv.remove();\n\n // We need to get all prepage modals on this site. Make sure they are initialized.\n loadPreBookingPage(optionid, userid, uniquid);\n }\n });\n });\n};\n\n/**\n * React on visibility change.\n * @param {integer} optionid\n * @param {integer} userid\n * @param {string} uniquid\n * @param {integer} totalnumberofpages\n * @param {function} callback\n */\nfunction respondToVisibility(optionid, userid, uniquid, totalnumberofpages, callback) {\n\n let elements = document.querySelectorAll(\"[id^=\" + SELECTORS.MODALID + optionid + \"_\" + uniquid + \"]\");\n\n elements.forEach(element => {\n\n if (!element || element.dataset.initialized == 'true') {\n return;\n }\n\n element.dataset.initialized = true;\n\n var observer = new MutationObserver(function() {\n\n if (!isHidden(element)) {\n\n // Because of the modal animation, \"isHIdden\" is also true on hiding modal.\n if (element.classList.contains('show')) {\n\n // Todo: Make sure it's not triggered on close.\n callback(optionid, userid, uniquid, totalnumberofpages);\n }\n }\n });\n\n // We look if we find a hidden parent. If not, we load right away.\n while (element !== null) {\n if (!isHidden(element)) {\n element = element.parentElement;\n } else {\n if (element.dataset.observed) {\n return;\n }\n\n observer.observe(element, {attributes: true});\n element.dataset.observed = true;\n return;\n }\n }\n callback(optionid, userid, uniquid, totalnumberofpages);\n });\n}\n\n/**\n * Function to check visibility of element.\n * @param {*} el\n * @returns {boolean}\n */\nfunction isHidden(el) {\n var style = window.getComputedStyle(el);\n return ((style.display === 'none') || (style.visibility === 'hidden'));\n}\n\n/**\n * Loads the (next) pre booking page.\n * @param {integer} optionid\n * @param {integer} userid\n * @param {string} uniquid\n */\nexport const loadPreBookingPage = (\n optionid, userid = 0, uniquid = '') => {\n\n const element = returnVisibleElement(optionid, uniquid, SELECTORS.INMODALDIV);\n\n if (element) {\n while (element.firstChild) {\n element.removeChild(element.firstChild);\n }\n } else {\n // eslint-disable-next-line no-console\n console.error('didnt find element');\n }\n\n Ajax.call([{\n methodname: \"mod_booking_allow_add_item_to_cart\",\n args: {\n 'itemid': optionid,\n 'userid': userid,\n },\n done: function(response) {\n // Will always be 1, if shopping cart is not installed!\n if (response.success == 1\n || response.success == 5 // Already booked, we need this for subbokings.\n || response.success == 0 // Already in cart, we need this for subbokings.\n ) {\n Ajax.call([{\n methodname: \"mod_booking_load_pre_booking_page\",\n args: {\n optionid,\n userid,\n 'pagenumber': currentbookitpage[optionid],\n },\n done: function(res) {\n // If we are on the last page, we reset it to 0.\n if (currentbookitpage[optionid] === totalbookitpages[optionid] - 1) {\n currentbookitpage[optionid] = 0;\n }\n\n const jsonobject = JSON.parse(res.json);\n\n // We support more than one template, they will be seperated by comma.\n // We have a data key in the json\n const templates = res.template.split(',');\n let dataarray = jsonobject;\n // Const buttontype = res.buttontype;\n\n renderTemplatesOnPage(templates, dataarray, element);\n },\n fail: function(err) {\n // eslint-disable-next-line no-console\n console.log(err);\n }\n }]);\n } else {\n\n // eslint-disable-next-line no-console\n console.log('closeModal');\n closeModal(optionid, false);\n closeInline(optionid, false);\n\n // Make sure that the prepage modal is actually closed.\n\n import('local_shopping_cart/cart')\n // eslint-disable-next-line promise/always-return\n .then(shoppingcart => {\n const addItemShowNotification = shoppingcart.addItemShowNotification;\n // Now you can use the specific function\n response.userid = userid;\n addItemShowNotification(response);\n })\n .catch(err => {\n // Handle any errors, including if the module doesn't exist\n // eslint-disable-next-line no-console\n console.log(err);\n });\n }\n\n return true;\n },\n fail: function(err) {\n // eslint-disable-next-line no-console\n console.log(err);\n }\n }]);\n};\n\n/**\n *\n * @param {string} templates\n * @param {object} dataarray\n * @param {HTMLElement} element\n */\nasync function renderTemplatesOnPage(templates, dataarray, element) {\n\n const modal = element.closest('.prepage-body');\n\n // We need to pass the id of our element to the templates to render.\n // If not, we might select the wrong modal or collapsible.\n let elementid = modal.id;\n\n if (!elementid) {\n const parent = modal.closest('[id]');\n elementid = parent.id;\n }\n\n // eslint-disable-next-line no-console\n console.log(modal, elementid);\n\n modal.querySelector(SELECTORS.MODALHEADER).innerHTML = '';\n modal.querySelector(SELECTORS.INMODALDIV).innerHTML = '';\n modal.querySelector(SELECTORS.MODALBUTTONAREA).innerHTML = '';\n modal.querySelector(SELECTORS.MODALFOOTER).innerHTML = '';\n\n templates.forEach(async template => {\n\n const data = dataarray.shift();\n\n let targetelement = element;\n\n if (!data) {\n return true;\n }\n\n data.data.elementid = elementid;\n\n switch (template) {\n case 'mod_booking/bookingpage/header':\n targetelement = modal.querySelector(SELECTORS.MODALHEADER);\n break;\n case 'mod_booking/bookit_button':\n case 'mod_booking/bookit_price':\n targetelement = modal.querySelector(SELECTORS.MODALBUTTONAREA);\n break;\n case 'mod_booking/bookingpage/footer':\n targetelement = modal.querySelector(SELECTORS.MODALFOOTER);\n break;\n default:\n targetelement = modal.querySelector(SELECTORS.INMODALDIV);\n break;\n }\n\n // eslint-disable-next-line no-console\n console.log(data.data);\n\n await Templates.renderForPromise(template, data.data).then(({html, js}) => {\n\n Templates.replaceNodeContents(targetelement, html, js);\n\n return true;\n }).catch(ex => {\n Notification.addNotification({\n message: 'failed rendering ' + JSON.stringify(ex),\n type: \"danger\"\n });\n });\n return true;\n });\n return true;\n}\n\n/**\n * We want to find out the visible modal\n * @param {integer} optionid\n * @param {string} uniquid\n * @param {string} appendedSelector\n * @returns {HTMLElement}\n */\nfunction returnVisibleElement(optionid, uniquid, appendedSelector) {\n\n // First, we get all the possbile Elements (we don't now the unique id appended to the element.)\n let selector = '[id^=\"' + SELECTORS.MODALID + optionid + '_' + uniquid + '\"] ' + appendedSelector;\n if (!uniquid || uniquid.length === 0) {\n selector = '[id^=\"' + SELECTORS.MODALID + optionid + '_\"].show ' + appendedSelector;\n }\n\n let elements = document.querySelectorAll(selector);\n\n // If the nodelist is empty, we we mgiht use inline.\n // If so, we need to have a different way of selecting elements.\n if (elements.length === 0) {\n\n selector = '[id^=\"' + SELECTORS.INLINEID + optionid + '_\"] ' + appendedSelector;\n elements = document.querySelectorAll(selector);\n\n }\n\n let visibleElement = null;\n\n elements.forEach(element => {\n\n var elementtocheck = element.parentElement.parentElement;\n\n // We look if we find a hidden parent. If not, we load right away.\n while (elementtocheck !== null) {\n if (!isHidden(elementtocheck)) {\n elementtocheck = elementtocheck.parentElement;\n\n } else {\n\n break;\n }\n }\n // If after the while, we have still an element, it's hidden.\n // So we only apply visible if it's null.\n if (!elementtocheck) {\n visibleElement = element;\n }\n });\n\n return visibleElement;\n}\n\n/**\n * Load next prepage booking page.\n * @param {int} optionid\n * @param {int} userid\n */\nexport function continueToNextPage(optionid, userid) {\n\n // eslint-disable-next-line no-console\n console.log('continueToNextPage', optionid, userid, currentbookitpage[optionid], totalbookitpages[optionid]);\n if (currentbookitpage[optionid] < totalbookitpages[optionid]) {\n currentbookitpage[optionid]++;\n loadPreBookingPage(optionid, userid);\n }\n}\n\n/**\n * Load previous prepage booking page.\n * @param {int} optionid\n * @param {int} userid\n */\nexport function backToPreviousPage(optionid, userid) {\n\n currentbookitpage[optionid]--;\n\n loadPreBookingPage(optionid, userid);\n}\n\n/**\n * Set back variables used in modal.\n * @param {int} optionid\n */\nexport function setBackModalVariables(optionid) {\n\n currentbookitpage[optionid] = 0;\n}\n"],"names":["optionid","userid","currentbookitpage","loadPreBookingPage","console","log","totalbookitpages","SELECTORS","MODALID","INLINEID","INMODALDIV","MODALHEADER","MODALBUTTONAREA","MODALFOOTER","CONTINUEBUTTON","BACKBUTTON","BOOKITBUTTON","INMODALBUTTON","STATICBACKDROP","initbookitbutton","itemid","area","initselector","document","querySelectorAll","forEach","button","inititemid","dataset","initarea","selector","buttons","nojs","classList","contains","initialized","querySelector","addEventListener","e","data","target","then","shoppingcart","confirmCancelModal","catch","err","bookit","call","methodname","args","JSON","stringify","done","res","skipreload","window","location","reload","jsonarray","parse","json","templates","template","split","promises","status","arraytoreduce","shift","datatorender","promise","Templates","renderForPromise","_ref","html","js","replaceNode","ex","addNotification","message","type","push","Promise","all","backdrop","initprepagemodal","totalnumberofpages","uniquid","callback","element","observer","MutationObserver","isHidden","observed","observe","attributes","parentElement","respondToVisibility","pages","initprepageinline","elements","action","rowcontainer","closest","lastElementChild","inlinediv","returnVisibleElement","append","el","style","getComputedStyle","display","visibility","firstChild","removeChild","error","response","success","jsonobject","renderTemplatesOnPage","fail","addItemShowNotification","dataarray","modal","elementid","id","parent","innerHTML","async","targetelement","_ref2","replaceNodeContents","appendedSelector","length","visibleElement","elementtocheck"],"mappings":"kWAqpBmCA,SAAUC,QAEzCC,kBAAkBF,YAElBG,mBAAmBH,SAAUC,qEAnBED,SAAUC,QAGzCG,QAAQC,IAAI,qBAAsBL,SAAUC,OAAQC,kBAAkBF,UAAWM,iBAAiBN,WAC9FE,kBAAkBF,UAAYM,iBAAiBN,YAC/CE,kBAAkBF,YAClBG,mBAAmBH,SAAUC,oKAoBCD,UAElCE,kBAAkBF,UAAY,iXAtoB9BE,kBAAoB,GACpBI,iBAAmB,GAEZC,UAAY,CACnBC,QAAS,kBACTC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