From 609976eb895ecc6d2188ee46f416c0a7eb62620a Mon Sep 17 00:00:00 2001 From: Prasanna LMSACE Date: Sun, 28 Apr 2024 21:00:53 +0530 Subject: [PATCH] BugFix: Spinner keeps spinning in preset modal - Fix PLS-747 --- amd/build/preset.min.js | 2 +- amd/build/preset.min.js.map | 2 +- amd/src/preset.js | 7 +++++-- classes/preset.php | 21 ++++++++++++++------- version.php | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/amd/build/preset.min.js b/amd/build/preset.min.js index 6b1dc58..7c229a3 100644 --- a/amd/build/preset.min.js +++ b/amd/build/preset.min.js @@ -1,3 +1,3 @@ -define("mod_pulse/preset",["jquery","core/modal_factory","mod_pulse/modal_preset","mod_pulse/events","core/str","core/fragment","core/ajax","core/templates","core/loadingicon","core/notification","core/modal_events","mod_pulse/presetmodal"],(function($,Modal,ModalPreset,PresetEvents,Str,Fragment,AJAX,Templates,Loadingicon,Notification,ModalEvents,PresetModal){var SELECTOR_presetAvailability=".preset-config-params .availability-field",Preset=function(contextId,courseid,section){this.contextId=contextId,this.courseid=courseid,this.section=section,this.loadPresetsList()};return Preset.prototype.listElement={selector:"pulse-presets-data",loaded:"data-listloaded"},Preset.prototype.contextId=0,Preset.prototype.courseid=0,Preset.prototype.section=0,Preset.prototype.pageparams=[],Preset.prototype.loadIconElement=".modal-footer #loader-icon",Preset.prototype.actionbuttons=".modal-footer button",Preset.prototype.setupmodal=function(){var THIS=this,triggerelement=document.querySelectorAll(".pulse-usepreset"),attachmentPoint=document.createElement("div");attachmentPoint.classList.add("modal-preset"),triggerelement.forEach((element=>element.addEventListener("click",(()=>{var presetid=element.getAttribute("data-presetid"),presettitle=element.getAttribute("data-presettitle"),params={presetid:presetid,courseid:THIS.courseid,section:THIS.section};document.body.prepend(attachmentPoint),(void 0===PresetModal.registerModalType?Modal.create({type:ModalPreset.TYPE,title:Str.get_string("presetmodaltitle","pulse",{title:presettitle}),body:Fragment.loadFragment("mod_pulse","get_preset_preview",THIS.contextId,params),large:!0}):PresetModal.create({title:Str.get_string("presetmodaltitle","pulse",{title:presettitle}),body:Fragment.loadFragment("mod_pulse","get_preset_preview",THIS.contextId,params),large:!0})).then((modal=>(modal.attachmentPoint=attachmentPoint,modal.show(),modal.getRoot().on(ModalEvents.bodyRendered,(function(){THIS.reinitAvailability(SELECTOR_presetAvailability),THIS.fieldChangedEvent()})),modal.getRoot().on(ModalEvents.hidden,(function(){modal.getRoot().get(0).querySelectorAll("form textarea").forEach((target=>{"undefined"!=typeof tinyMCE&&tinyMCE.EditorManager.get(target.id).remove()})),modal.destroy.bind(modal)})),modal.getRoot().on(PresetEvents.customize,(()=>{var modform=document.querySelector("#mod-pulse-form"),modformdata=new FormData(modform);modal.getRoot().get(0).querySelectorAll("form").forEach((form=>{var formdata=new FormData(form);formdata=new URLSearchParams(formdata).toString();var pageparams=new URLSearchParams(modformdata).toString();params={formdata:formdata,pageparams:pageparams},Loadingicon.addIconToContainer(this.loadIconElement),THIS.disableButtons(),THIS.applyCustomize(params,THIS.contextId,modal)}))})),modal.getRoot().on(PresetEvents.save,(e=>{e.preventDefault(),Loadingicon.addIconToContainer(this.loadIconElement),THIS.disableButtons();var formdata={};modal.getRoot().get(0).querySelectorAll("form").forEach((form=>{formdata=new FormData(form),this.restorePreset(formdata,THIS.contextId)}))})),!0))).catch(Notification.exception)}))))},Preset.prototype.fieldChangedEvent=()=>{var fieldName,changeinput,id,changeName,split,confParam=document.getElementById("preset-configurable-params"),methods=["fixed","relative"];confParam.querySelectorAll("input, select, textarea").forEach((field=>{field.addEventListener("change",(event=>{fieldName=event.target.getAttribute("name"),null!==confParam.querySelector('input[name="'+fieldName+'_changed"]')&&(confParam.querySelector('input[name="'+fieldName+'_changed"]').value=!0)}))})),["first","second","recurring"].forEach((reminder=>{confParam.querySelectorAll('[name="'+reminder+'_schedule"').forEach((schedule=>{schedule.addEventListener("change",(e=>{changeName=e.target.getAttribute("name"),changeinput='input[name="'+changeName+'_arr_changed"]',confParam.querySelector(changeinput).value=!0}))})),methods.forEach((method=>{id=reminder+"_"+method+"date",confParam.querySelectorAll('[name*="'+id+'"]').forEach((opt=>{opt.addEventListener("change",(e=>{split=e.target.getAttribute("name").split("["),changeName=split.hasOwnProperty(1)?split[0]:split,changeinput='input[name="'+changeName+'_changed"]',confParam.querySelector(changeinput).value=!0}))}))}))}))},Preset.prototype.reinitAvailability=function(){let selector=arguments.length>0&&void 0!==arguments[0]?arguments[0]:".availability-field";void 0!==M.core_availability.form&&null!==document.getElementById("id_availabilityconditionsjson")&&(this.resetRestrictPlugins(),document.querySelectorAll(selector).forEach((field=>field.parentNode.removeChild(field))),M.core_availability.form.init())},Preset.prototype.resetRestrictPlugins=function(){if(void 0!==M.core_availability.form&&null!==document.getElementById("id_availabilityconditionsjson")){M.core_availability.form.restrictByGroup=null;var availabilityPlugins=void 0!==M.core_availability.form.plugins?M.core_availability.form.plugins:{},plugin="";for(var i in availabilityPlugins)plugin="availability_"+i,M.hasOwnProperty(plugin)&&(M[plugin].form.addedEvents=!1)}},Preset.prototype.applyCustomize=function(params,contextID,modal){Fragment.loadFragment("mod_pulse","apply_preset",contextID,params).done(((html,js)=>{modal.destroy(),this.resetRestrictPlugins(),this.handleFormSubmissionResponse(html,js)}))},Preset.prototype.disableButtons=function(){var buttons=document.querySelectorAll(this.actionbuttons);for(let $i in buttons)buttons[$i].disabled=!0},Preset.prototype.handleFormSubmissionResponse=(data,js)=>{document.createElement("div").innerHTML=data,Templates.replaceNode('[action="modedit.php"]',data,js)},Preset.prototype.restorePreset=(formdata,contextid)=>{var formdatastr=new URLSearchParams(formdata).toString();AJAX.call([{methodname:"mod_pulse_apply_presets",args:{contextid:contextid,formdata:formdatastr}}])[0].done((response=>{void 0!==(response=JSON.parse(response)).url&&(window.location.href=response.url)}))},Preset.prototype.loadPresetsList=function(){var listParent=document.getElementById(this.listElement.selector);null!==listParent&&"false"==listParent.getAttribute(this.listElement.loaded)&&Fragment.loadFragment("mod_pulse","get_presetslist",this.contextId,{courseid:this.courseid}).done(((html,js)=>{Templates.replaceNodeContents(listParent,html,js),listParent.setAttribute(this.listElement.loaded,"true"),this.setupmodal()}))},{init:(contextId,courseid,section)=>{new Preset(contextId,courseid,section)}}})); +define("mod_pulse/preset",["jquery","core/modal_factory","mod_pulse/modal_preset","mod_pulse/events","core/str","core/fragment","core/ajax","core/templates","core/loadingicon","core/notification","core/modal_events","mod_pulse/presetmodal"],(function($,Modal,ModalPreset,PresetEvents,Str,Fragment,AJAX,Templates,Loadingicon,Notification,ModalEvents,PresetModal){var SELECTOR_presetAvailability=".preset-config-params .availability-field",Preset=function(contextId,courseid,section){this.contextId=contextId,this.courseid=courseid,this.section=section,this.loadPresetsList()};return Preset.prototype.listElement={selector:"pulse-presets-data",loaded:"data-listloaded"},Preset.prototype.contextId=0,Preset.prototype.courseid=0,Preset.prototype.section=0,Preset.prototype.pageparams=[],Preset.prototype.loadIconElement=".modal-footer #loader-icon",Preset.prototype.actionbuttons=".modal-footer button",Preset.prototype.setupmodal=function(){var THIS=this,triggerelement=document.querySelectorAll(".pulse-usepreset"),attachmentPoint=document.createElement("div");attachmentPoint.classList.add("modal-preset"),triggerelement.forEach((element=>element.addEventListener("click",(()=>{var presetid=element.getAttribute("data-presetid"),presettitle=element.getAttribute("data-presettitle"),params={presetid:presetid,courseid:THIS.courseid,section:THIS.section};document.body.prepend(attachmentPoint),(void 0===PresetModal.registerModalType?Modal.create({type:ModalPreset.TYPE,title:Str.get_string("presetmodaltitle","pulse",{title:presettitle}),body:Fragment.loadFragment("mod_pulse","get_preset_preview",THIS.contextId,params),large:!0}):PresetModal.create({title:Str.get_string("presetmodaltitle","pulse",{title:presettitle}),body:Fragment.loadFragment("mod_pulse","get_preset_preview",THIS.contextId,params),large:!0})).then((modal=>(modal.attachmentPoint=attachmentPoint,modal.show(),modal.getRoot().on(ModalEvents.bodyRendered,(function(){null!=modal.getRoot().get(0).querySelector("#id_availabilityconditionsjson")&&THIS.reinitAvailability(SELECTOR_presetAvailability),THIS.fieldChangedEvent()})),modal.getRoot().on(ModalEvents.hidden,(function(){modal.getRoot().get(0).querySelectorAll("form textarea").forEach((target=>{"undefined"!=typeof tinyMCE&&tinyMCE.EditorManager.get(target.id)&&tinyMCE.EditorManager.get(target.id).remove()})),modal.destroy.bind(modal)})),modal.getRoot().on(PresetEvents.customize,(()=>{var modform=document.querySelector("#mod-pulse-form"),modformdata=new FormData(modform);modal.getRoot().get(0).querySelectorAll("form").forEach((form=>{var formdata=new FormData(form);formdata=new URLSearchParams(formdata).toString();var pageparams=new URLSearchParams(modformdata).toString();params={formdata:formdata,pageparams:pageparams},Loadingicon.addIconToContainer(this.loadIconElement),THIS.disableButtons(),THIS.applyCustomize(params,THIS.contextId,modal)}))})),modal.getRoot().on(PresetEvents.save,(e=>{e.preventDefault(),Loadingicon.addIconToContainer(this.loadIconElement),THIS.disableButtons();var formdata={};modal.getRoot().get(0).querySelectorAll("form").forEach((form=>{formdata=new FormData(form),this.restorePreset(formdata,THIS.contextId)}))})),!0))).catch(Notification.exception)}))))},Preset.prototype.fieldChangedEvent=()=>{var fieldName,changeinput,id,changeName,split,confParam=document.getElementById("preset-configurable-params"),methods=["fixed","relative"];confParam.querySelectorAll("input, select, textarea").forEach((field=>{field.addEventListener("change",(event=>{fieldName=event.target.getAttribute("name"),null!==confParam.querySelector('input[name="'+fieldName+'_changed"]')&&(confParam.querySelector('input[name="'+fieldName+'_changed"]').value=!0)}))})),["first","second","recurring"].forEach((reminder=>{confParam.querySelectorAll('[name="'+reminder+'_schedule"').forEach((schedule=>{schedule.addEventListener("change",(e=>{changeName=e.target.getAttribute("name"),changeinput='input[name="'+changeName+'_arr_changed"]',confParam.querySelector(changeinput).value=!0}))})),methods.forEach((method=>{id=reminder+"_"+method+"date",confParam.querySelectorAll('[name*="'+id+'"]').forEach((opt=>{opt.addEventListener("change",(e=>{split=e.target.getAttribute("name").split("["),changeName=split.hasOwnProperty(1)?split[0]:split,changeinput='input[name="'+changeName+'_changed"]',confParam.querySelector(changeinput).value=!0}))}))}))}))},Preset.prototype.reinitAvailability=function(){let selector=arguments.length>0&&void 0!==arguments[0]?arguments[0]:".availability-field";void 0!==M.core_availability.form&&null!==document.getElementById("id_availabilityconditionsjson")&&(this.resetRestrictPlugins(),document.querySelectorAll(selector).forEach((field=>field.parentNode.removeChild(field))),M.core_availability.form.init())},Preset.prototype.resetRestrictPlugins=function(){if(void 0!==M.core_availability.form&&null!==document.getElementById("id_availabilityconditionsjson")){M.core_availability.form.restrictByGroup=null;var availabilityPlugins=void 0!==M.core_availability.form.plugins?M.core_availability.form.plugins:{},plugin="";for(var i in availabilityPlugins)plugin="availability_"+i,M.hasOwnProperty(plugin)&&(M[plugin].form.addedEvents=!1)}},Preset.prototype.applyCustomize=function(params,contextID,modal){Fragment.loadFragment("mod_pulse","apply_preset",contextID,params).done(((html,js)=>{modal.destroy(),this.resetRestrictPlugins(),this.handleFormSubmissionResponse(html,js)}))},Preset.prototype.disableButtons=function(){var buttons=document.querySelectorAll(this.actionbuttons);for(let $i in buttons)buttons[$i].disabled=!0},Preset.prototype.handleFormSubmissionResponse=(data,js)=>{document.createElement("div").innerHTML=data,Templates.replaceNode('[action="modedit.php"]',data,js)},Preset.prototype.restorePreset=(formdata,contextid)=>{var formdatastr=new URLSearchParams(formdata).toString();AJAX.call([{methodname:"mod_pulse_apply_presets",args:{contextid:contextid,formdata:formdatastr}}])[0].done((response=>{void 0!==(response=JSON.parse(response)).url&&(window.location.href=response.url)}))},Preset.prototype.loadPresetsList=function(){var listParent=document.getElementById(this.listElement.selector);null!==listParent&&"false"==listParent.getAttribute(this.listElement.loaded)&&Fragment.loadFragment("mod_pulse","get_presetslist",this.contextId,{courseid:this.courseid}).done(((html,js)=>{Templates.replaceNodeContents(listParent,html,js),listParent.setAttribute(this.listElement.loaded,"true"),this.setupmodal()}))},{init:(contextId,courseid,section)=>{new Preset(contextId,courseid,section)}}})); //# sourceMappingURL=preset.min.js.map \ No newline at end of file diff --git a/amd/build/preset.min.js.map b/amd/build/preset.min.js.map index f8080d3..b885d82 100644 --- a/amd/build/preset.min.js.map +++ b/amd/build/preset.min.js.map @@ -1 +1 @@ -{"version":3,"file":"preset.min.js","sources":["../src/preset.js"],"sourcesContent":["define(['jquery', 'core/modal_factory', 'mod_pulse/modal_preset', 'mod_pulse/events', 'core/str', 'core/fragment', 'core/ajax',\n 'core/templates', 'core/loadingicon', 'core/notification', 'core/modal_events', 'mod_pulse/presetmodal'],\n function($, Modal, ModalPreset, PresetEvents, Str, Fragment, AJAX, Templates, Loadingicon,\n Notification, ModalEvents, PresetModal) {\n\n var SELECTOR = {\n presetAvailability: '.preset-config-params .availability-field'\n };\n\n /**\n * Preset module declaration. Setup the global values.\n * @param {int} contextId\n * @param {int} courseid\n * @param {int} section\n */\n var Preset = function(contextId, courseid, section) {\n this.contextId = contextId;\n this.courseid = courseid;\n this.section = section;\n this.loadPresetsList();\n };\n\n Preset.prototype.listElement = {'selector': 'pulse-presets-data', \"loaded\": \"data-listloaded\"};\n\n Preset.prototype.contextId = 0;\n\n Preset.prototype.courseid = 0;\n\n Preset.prototype.section = 0;\n\n Preset.prototype.pageparams = [];\n\n Preset.prototype.loadIconElement = '.modal-footer #loader-icon';\n\n Preset.prototype.actionbuttons = '.modal-footer button';\n\n /**\n * Setup the presets modal event listeners.\n */\n Preset.prototype.setupmodal = function() {\n\n var THIS = this;\n\n var triggerelement = document.querySelectorAll('.pulse-usepreset');\n // Modal attachment point.\n var attachmentPoint = document.createElement('div');\n attachmentPoint.classList.add('modal-preset');\n triggerelement.forEach((element) => element.addEventListener('click', () => {\n var presetid = element.getAttribute('data-presetid');\n var presettitle = element.getAttribute('data-presettitle');\n var params = {'presetid': presetid, 'courseid': THIS.courseid, 'section': THIS.section};\n\n document.body.prepend(attachmentPoint);\n\n var modalFn;\n if (typeof PresetModal.registerModalType == 'undefined') {\n modalFn = Modal.create({\n type: ModalPreset.TYPE,\n title: Str.get_string('presetmodaltitle', 'pulse', {'title': presettitle}),\n body: Fragment.loadFragment('mod_pulse', 'get_preset_preview', THIS.contextId, params),\n large: true,\n });\n } else {\n modalFn = PresetModal.create({\n title: Str.get_string('presetmodaltitle', 'pulse', {'title': presettitle}),\n body: Fragment.loadFragment('mod_pulse', 'get_preset_preview', THIS.contextId, params),\n large: true,\n });\n }\n\n modalFn.then(modal => {\n // Make the modal attachment point to overcome the restriction access condition.\n modal.attachmentPoint = attachmentPoint;\n modal.show();\n modal.getRoot().on(ModalEvents.bodyRendered, function() {\n THIS.reinitAvailability(SELECTOR.presetAvailability);\n THIS.fieldChangedEvent();\n });\n // Destroy the modal on hidden to reload the editors.\n modal.getRoot().on(ModalEvents.hidden, function() {\n modal.getRoot().get(0).querySelectorAll('form textarea').forEach(target => {\n if (typeof tinyMCE !== 'undefined') {\n tinyMCE.EditorManager.get(target.id).remove(); // eslint-disable-line\n }\n });\n modal.destroy.bind(modal);\n // THIS.reinitAvailability();\n });\n\n // Apply and customize method.\n modal.getRoot().on(PresetEvents.customize, () => {\n var modform = document.querySelector('#mod-pulse-form');\n var modformdata = new FormData(modform);\n modal.getRoot().get(0).querySelectorAll('form').forEach(form => {\n var formdata = new FormData(form);\n formdata = new URLSearchParams(formdata).toString();\n var pageparams = new URLSearchParams(modformdata).toString();\n params = {formdata: formdata, pageparams: pageparams};\n\n Loadingicon.addIconToContainer(this.loadIconElement);\n THIS.disableButtons();\n THIS.applyCustomize(params, THIS.contextId, modal);\n });\n });\n // Apply and save method.\n modal.getRoot().on(PresetEvents.save, (e) => {\n e.preventDefault();\n Loadingicon.addIconToContainer(this.loadIconElement);\n THIS.disableButtons();\n var formdata = {};\n modal.getRoot().get(0).querySelectorAll('form').forEach(form => {\n formdata = new FormData(form);\n this.restorePreset(formdata, THIS.contextId);\n });\n });\n return true;\n }).catch(Notification.exception);\n }));\n };\n\n\n Preset.prototype.fieldChangedEvent = () => {\n var confParam = document.getElementById(\"preset-configurable-params\");\n var reminders = ['first', 'second', 'recurring'];\n var methods = ['fixed', 'relative'];\n var fieldName, changeinput, id, changeName, split;\n confParam.querySelectorAll('input, select, textarea').forEach(field => {\n field.addEventListener('change', (event) => {\n fieldName = event.target.getAttribute('name');\n if (confParam.querySelector('input[name=\"' + fieldName + '_changed\"]') !== null) {\n confParam.querySelector('input[name=\"' + fieldName + '_changed\"]').value = true;\n }\n });\n });\n\n reminders.forEach(reminder => {\n confParam.querySelectorAll('[name=\"' + reminder + '_schedule\"').forEach(schedule => {\n schedule.addEventListener('change', (e) => {\n changeName = e.target.getAttribute('name');\n changeinput = 'input[name=\"' + changeName + '_arr_changed\"]';\n confParam.querySelector(changeinput).value = true;\n });\n });\n methods.forEach(method => {\n id = reminder + \"_\" + method + \"date\";\n confParam.querySelectorAll('[name*=\"' + id + '\"]').forEach(opt => {\n opt.addEventListener('change', (e) => {\n split = e.target.getAttribute('name').split('[');\n changeName = (split.hasOwnProperty(1)) ? split[0] : split;\n changeinput = 'input[name=\"' + changeName + '_changed\"]';\n confParam.querySelector(changeinput).value = true;\n });\n });\n });\n });\n };\n\n /**\n * Reinitialize the availability javascript.\n * @param {string} selector\n */\n Preset.prototype.reinitAvailability = function(selector = '.availability-field') {\n if (typeof M.core_availability.form !== \"undefined\" &&\n document.getElementById('id_availabilityconditionsjson') !== null) {\n this.resetRestrictPlugins();\n document.querySelectorAll(selector).forEach((field) => field.parentNode.removeChild(field));\n M.core_availability.form.init();\n }\n };\n\n Preset.prototype.resetRestrictPlugins = function() {\n if (typeof M.core_availability.form !== \"undefined\" &&\n document.getElementById('id_availabilityconditionsjson') !== null) {\n M.core_availability.form.restrictByGroup = null;\n var availabilityPlugins = (typeof M.core_availability.form.plugins !== 'undefined')\n ? M.core_availability.form.plugins : {};\n var plugin = '';\n for (var i in availabilityPlugins) {\n plugin = \"availability_\" + i;\n if (M.hasOwnProperty(plugin)) {\n M[plugin].form.addedEvents = false;\n }\n }\n }\n };\n\n /**\n * Apply and customize triggered using fragment. Response will replaced with current mod form.\n * @param {string} params\n * @param {int} contextID\n * @param {object} modal\n */\n Preset.prototype.applyCustomize = function(params, contextID, modal) {\n Fragment.loadFragment('mod_pulse', 'apply_preset', contextID, params).done((html, js) => {\n modal.destroy();\n // Reset the availability to work for upcoming response html.\n this.resetRestrictPlugins();\n this.handleFormSubmissionResponse(html, js);\n });\n };\n\n /**\n * Disable the modal save and customize buttons to prevent reinit.\n */\n Preset.prototype.disableButtons = function() {\n var buttons = document.querySelectorAll(this.actionbuttons);\n for (let $i in buttons) {\n buttons[$i].disabled = true;\n }\n };\n\n /**\n * Handle the loaded fragment output of customize method pulse mod.\n * @param {html} data\n * @param {string} js\n */\n Preset.prototype.handleFormSubmissionResponse = (data, js) => {\n var newform = document.createElement('div');\n newform.innerHTML = data;\n Templates.replaceNode('[action=\"modedit.php\"]', data, js);\n\n };\n\n /**\n * Initiate the apply and save method to create the pulse module with custom daa.\n * @param {FormData} formdata\n * @param {int} contextid\n */\n Preset.prototype.restorePreset = (formdata, contextid) => {\n var formdatastr = new URLSearchParams(formdata).toString();\n var promises = AJAX.call([{\n methodname: 'mod_pulse_apply_presets',\n args: {contextid: contextid, formdata: formdatastr}\n }]);\n\n promises[0].done((response) => {\n response = JSON.parse(response);\n if (typeof response.url != 'undefined') {\n window.location.href = response.url;\n }\n });\n };\n\n /**\n * Load list of available presets.\n */\n Preset.prototype.loadPresetsList = function() {\n var listParent = document.getElementById(this.listElement.selector);\n\n if (listParent !== null) {\n if (listParent.getAttribute(this.listElement.loaded) == 'false') {\n Fragment.loadFragment('mod_pulse', 'get_presetslist', this.contextId, {'courseid': this.courseid})\n .done((html, js) => {\n Templates.replaceNodeContents(listParent, html, js);\n listParent.setAttribute(this.listElement.loaded, 'true');\n this.setupmodal();\n });\n }\n }\n };\n\n return {\n init: (contextId, courseid, section) => {\n new Preset(contextId, courseid, section);\n }\n };\n });\n"],"names":["define","$","Modal","ModalPreset","PresetEvents","Str","Fragment","AJAX","Templates","Loadingicon","Notification","ModalEvents","PresetModal","SELECTOR","Preset","contextId","courseid","section","loadPresetsList","prototype","listElement","pageparams","loadIconElement","actionbuttons","setupmodal","THIS","this","triggerelement","document","querySelectorAll","attachmentPoint","createElement","classList","add","forEach","element","addEventListener","presetid","getAttribute","presettitle","params","body","prepend","registerModalType","create","type","TYPE","title","get_string","loadFragment","large","then","modal","show","getRoot","on","bodyRendered","reinitAvailability","fieldChangedEvent","hidden","get","target","tinyMCE","EditorManager","id","remove","destroy","bind","customize","modform","querySelector","modformdata","FormData","form","formdata","URLSearchParams","toString","addIconToContainer","disableButtons","applyCustomize","save","e","preventDefault","restorePreset","catch","exception","fieldName","changeinput","changeName","split","confParam","getElementById","methods","field","event","value","reminder","schedule","method","opt","hasOwnProperty","selector","M","core_availability","resetRestrictPlugins","parentNode","removeChild","init","restrictByGroup","availabilityPlugins","plugins","plugin","i","addedEvents","contextID","done","html","js","handleFormSubmissionResponse","buttons","$i","disabled","data","innerHTML","replaceNode","contextid","formdatastr","call","methodname","args","response","JSON","parse","url","window","location","href","listParent","loaded","replaceNodeContents","setAttribute"],"mappings":"AAAAA,0BAAO,CAAC,SAAU,qBAAsB,yBAA0B,mBAAoB,WAAY,gBAAiB,YAC/G,iBAAkB,mBAAoB,oBAAqB,oBAAqB,0BAChF,SAASC,EAAGC,MAAOC,YAAaC,aAAcC,IAAKC,SAAUC,KAAMC,UAAWC,YAC1EC,aAAcC,YAAaC,iBAEvBC,4BACoB,4CASpBC,OAAS,SAASC,UAAWC,SAAUC,cAClCF,UAAYA,eACZC,SAAWA,cACXC,QAAUA,aACVC,0BAGTJ,OAAOK,UAAUC,YAAc,UAAa,4BAAgC,mBAE5EN,OAAOK,UAAUJ,UAAY,EAE7BD,OAAOK,UAAUH,SAAW,EAE5BF,OAAOK,UAAUF,QAAU,EAE3BH,OAAOK,UAAUE,WAAa,GAE9BP,OAAOK,UAAUG,gBAAkB,6BAEnCR,OAAOK,UAAUI,cAAgB,uBAKjCT,OAAOK,UAAUK,WAAa,eAEtBC,KAAOC,KAEPC,eAAiBC,SAAS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AAM,CAACJ,UAAWA,UAAWnD,SAAUoD,gBAGlC,GAAGX,MAAMe,gBAEa,KAD3BA,SAAWC,KAAKC,MAAMF,WACFG,MAChBC,OAAOC,SAASC,KAAON,SAASG,SAQ5CvH,OAAOK,UAAUD,gBAAkB,eAC3BuH,WAAa7G,SAAS+D,eAAejE,KAAKN,YAAYiF,UAEvC,OAAfoC,YACwD,SAApDA,WAAWnG,aAAaZ,KAAKN,YAAYsH,SACzCpI,SAAS2C,aAAa,YAAa,kBAAmBvB,KAAKX,UAAW,UAAaW,KAAKV,WACnFmG,MAAK,CAACC,KAAMC,MACT7G,UAAUmI,oBAAoBF,WAAYrB,KAAMC,IAChDoB,WAAWG,aAAalH,KAAKN,YAAYsH,OAAQ,aAC5ClH,iBAMlB,CACHmF,KAAM,CAAC5F,UAAWC,SAAUC,eACpBH,OAAOC,UAAWC,SAAUC"} \ No newline at end of file +{"version":3,"file":"preset.min.js","sources":["../src/preset.js"],"sourcesContent":["define(['jquery', 'core/modal_factory', 'mod_pulse/modal_preset', 'mod_pulse/events', 'core/str', 'core/fragment', 'core/ajax',\r\n 'core/templates', 'core/loadingicon', 'core/notification', 'core/modal_events', 'mod_pulse/presetmodal'],\r\n function($, Modal, ModalPreset, PresetEvents, Str, Fragment, AJAX, Templates, Loadingicon,\r\n Notification, ModalEvents, PresetModal) {\r\n\r\n var SELECTOR = {\r\n presetAvailability: '.preset-config-params .availability-field'\r\n };\r\n\r\n /**\r\n * Preset module declaration. Setup the global values.\r\n * @param {int} contextId\r\n * @param {int} courseid\r\n * @param {int} section\r\n */\r\n var Preset = function(contextId, courseid, section) {\r\n this.contextId = contextId;\r\n this.courseid = courseid;\r\n this.section = section;\r\n this.loadPresetsList();\r\n };\r\n\r\n Preset.prototype.listElement = {'selector': 'pulse-presets-data', \"loaded\": \"data-listloaded\"};\r\n\r\n Preset.prototype.contextId = 0;\r\n\r\n Preset.prototype.courseid = 0;\r\n\r\n Preset.prototype.section = 0;\r\n\r\n Preset.prototype.pageparams = [];\r\n\r\n Preset.prototype.loadIconElement = '.modal-footer #loader-icon';\r\n\r\n Preset.prototype.actionbuttons = '.modal-footer button';\r\n\r\n /**\r\n * Setup the presets modal event listeners.\r\n */\r\n Preset.prototype.setupmodal = function() {\r\n\r\n var THIS = this;\r\n\r\n var triggerelement = document.querySelectorAll('.pulse-usepreset');\r\n // Modal attachment point.\r\n var attachmentPoint = document.createElement('div');\r\n attachmentPoint.classList.add('modal-preset');\r\n triggerelement.forEach((element) => element.addEventListener('click', () => {\r\n var presetid = element.getAttribute('data-presetid');\r\n var presettitle = element.getAttribute('data-presettitle');\r\n var params = {'presetid': presetid, 'courseid': THIS.courseid, 'section': THIS.section};\r\n\r\n document.body.prepend(attachmentPoint);\r\n\r\n var modalFn;\r\n if (typeof PresetModal.registerModalType == 'undefined') {\r\n modalFn = Modal.create({\r\n type: ModalPreset.TYPE,\r\n title: Str.get_string('presetmodaltitle', 'pulse', {'title': presettitle}),\r\n body: Fragment.loadFragment('mod_pulse', 'get_preset_preview', THIS.contextId, params),\r\n large: true,\r\n });\r\n } else {\r\n modalFn = PresetModal.create({\r\n title: Str.get_string('presetmodaltitle', 'pulse', {'title': presettitle}),\r\n body: Fragment.loadFragment('mod_pulse', 'get_preset_preview', THIS.contextId, params),\r\n large: true,\r\n });\r\n }\r\n\r\n modalFn.then(modal => {\r\n // Make the modal attachment point to overcome the restriction access condition.\r\n modal.attachmentPoint = attachmentPoint;\r\n modal.show();\r\n modal.getRoot().on(ModalEvents.bodyRendered, function() {\r\n\r\n if (modal.getRoot().get(0).querySelector(\"#id_availabilityconditionsjson\") != null) {\r\n THIS.reinitAvailability(SELECTOR.presetAvailability);\r\n }\r\n THIS.fieldChangedEvent();\r\n });\r\n // Destroy the modal on hidden to reload the editors.\r\n modal.getRoot().on(ModalEvents.hidden, function() {\r\n modal.getRoot().get(0).querySelectorAll('form textarea').forEach(target => {\r\n if (typeof tinyMCE !== 'undefined' && tinyMCE.EditorManager.get(target.id)) { // eslint-disable-line\r\n tinyMCE.EditorManager.get(target.id).remove(); // eslint-disable-line\r\n }\r\n });\r\n modal.destroy.bind(modal);\r\n // THIS.reinitAvailability();\r\n });\r\n\r\n // Apply and customize method.\r\n modal.getRoot().on(PresetEvents.customize, () => {\r\n var modform = document.querySelector('#mod-pulse-form');\r\n var modformdata = new FormData(modform);\r\n modal.getRoot().get(0).querySelectorAll('form').forEach(form => {\r\n var formdata = new FormData(form);\r\n formdata = new URLSearchParams(formdata).toString();\r\n var pageparams = new URLSearchParams(modformdata).toString();\r\n params = {formdata: formdata, pageparams: pageparams};\r\n\r\n Loadingicon.addIconToContainer(this.loadIconElement);\r\n THIS.disableButtons();\r\n THIS.applyCustomize(params, THIS.contextId, modal);\r\n });\r\n });\r\n // Apply and save method.\r\n modal.getRoot().on(PresetEvents.save, (e) => {\r\n e.preventDefault();\r\n Loadingicon.addIconToContainer(this.loadIconElement);\r\n THIS.disableButtons();\r\n var formdata = {};\r\n modal.getRoot().get(0).querySelectorAll('form').forEach(form => {\r\n formdata = new FormData(form);\r\n this.restorePreset(formdata, THIS.contextId);\r\n });\r\n });\r\n return true;\r\n }).catch(Notification.exception);\r\n }));\r\n };\r\n\r\n\r\n Preset.prototype.fieldChangedEvent = () => {\r\n var confParam = document.getElementById(\"preset-configurable-params\");\r\n var reminders = ['first', 'second', 'recurring'];\r\n var methods = ['fixed', 'relative'];\r\n var fieldName, changeinput, id, changeName, split;\r\n confParam.querySelectorAll('input, select, textarea').forEach(field => {\r\n field.addEventListener('change', (event) => {\r\n fieldName = event.target.getAttribute('name');\r\n if (confParam.querySelector('input[name=\"' + fieldName + '_changed\"]') !== null) {\r\n confParam.querySelector('input[name=\"' + fieldName + '_changed\"]').value = true;\r\n }\r\n });\r\n });\r\n\r\n reminders.forEach(reminder => {\r\n confParam.querySelectorAll('[name=\"' + reminder + '_schedule\"').forEach(schedule => {\r\n schedule.addEventListener('change', (e) => {\r\n changeName = e.target.getAttribute('name');\r\n changeinput = 'input[name=\"' + changeName + '_arr_changed\"]';\r\n confParam.querySelector(changeinput).value = true;\r\n });\r\n });\r\n methods.forEach(method => {\r\n id = reminder + \"_\" + method + \"date\";\r\n confParam.querySelectorAll('[name*=\"' + id + '\"]').forEach(opt => {\r\n opt.addEventListener('change', (e) => {\r\n split = e.target.getAttribute('name').split('[');\r\n changeName = (split.hasOwnProperty(1)) ? split[0] : split;\r\n changeinput = 'input[name=\"' + changeName + '_changed\"]';\r\n confParam.querySelector(changeinput).value = true;\r\n });\r\n });\r\n });\r\n });\r\n };\r\n\r\n /**\r\n * Reinitialize the availability javascript.\r\n * @param {string} selector\r\n */\r\n Preset.prototype.reinitAvailability = function(selector = '.availability-field') {\r\n if (typeof M.core_availability.form !== \"undefined\" &&\r\n document.getElementById('id_availabilityconditionsjson') !== null) {\r\n this.resetRestrictPlugins();\r\n document.querySelectorAll(selector).forEach((field) => field.parentNode.removeChild(field));\r\n M.core_availability.form.init();\r\n }\r\n };\r\n\r\n Preset.prototype.resetRestrictPlugins = function() {\r\n if (typeof M.core_availability.form !== \"undefined\" &&\r\n document.getElementById('id_availabilityconditionsjson') !== null) {\r\n M.core_availability.form.restrictByGroup = null;\r\n var availabilityPlugins = (typeof M.core_availability.form.plugins !== 'undefined')\r\n ? M.core_availability.form.plugins : {};\r\n var plugin = '';\r\n for (var i in availabilityPlugins) {\r\n plugin = \"availability_\" + i;\r\n if (M.hasOwnProperty(plugin)) {\r\n M[plugin].form.addedEvents = false;\r\n }\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Apply and customize triggered using fragment. Response will replaced with current mod form.\r\n * @param {string} params\r\n * @param {int} contextID\r\n * @param {object} modal\r\n */\r\n Preset.prototype.applyCustomize = function(params, contextID, modal) {\r\n Fragment.loadFragment('mod_pulse', 'apply_preset', contextID, params).done((html, js) => {\r\n modal.destroy();\r\n // Reset the availability to work for upcoming response html.\r\n this.resetRestrictPlugins();\r\n this.handleFormSubmissionResponse(html, js);\r\n });\r\n };\r\n\r\n /**\r\n * Disable the modal save and customize buttons to prevent reinit.\r\n */\r\n Preset.prototype.disableButtons = function() {\r\n var buttons = document.querySelectorAll(this.actionbuttons);\r\n for (let $i in buttons) {\r\n buttons[$i].disabled = true;\r\n }\r\n };\r\n\r\n /**\r\n * Handle the loaded fragment output of customize method pulse mod.\r\n * @param {html} data\r\n * @param {string} js\r\n */\r\n Preset.prototype.handleFormSubmissionResponse = (data, js) => {\r\n var newform = document.createElement('div');\r\n newform.innerHTML = data;\r\n Templates.replaceNode('[action=\"modedit.php\"]', data, js);\r\n\r\n };\r\n\r\n /**\r\n * Initiate the apply and save method to create the pulse module with custom daa.\r\n * @param {FormData} formdata\r\n * @param {int} contextid\r\n */\r\n Preset.prototype.restorePreset = (formdata, contextid) => {\r\n var formdatastr = new URLSearchParams(formdata).toString();\r\n var promises = AJAX.call([{\r\n methodname: 'mod_pulse_apply_presets',\r\n args: {contextid: contextid, formdata: formdatastr}\r\n }]);\r\n\r\n promises[0].done((response) => {\r\n response = JSON.parse(response);\r\n if (typeof response.url != 'undefined') {\r\n window.location.href = response.url;\r\n }\r\n });\r\n };\r\n\r\n /**\r\n * Load list of available presets.\r\n */\r\n Preset.prototype.loadPresetsList = function() {\r\n var listParent = document.getElementById(this.listElement.selector);\r\n\r\n if (listParent !== null) {\r\n if (listParent.getAttribute(this.listElement.loaded) == 'false') {\r\n Fragment.loadFragment('mod_pulse', 'get_presetslist', this.contextId, {'courseid': this.courseid})\r\n .done((html, js) => {\r\n Templates.replaceNodeContents(listParent, html, js);\r\n listParent.setAttribute(this.listElement.loaded, 'true');\r\n this.setupmodal();\r\n });\r\n }\r\n }\r\n };\r\n\r\n return {\r\n init: (contextId, courseid, section) => {\r\n new Preset(contextId, courseid, section);\r\n }\r\n };\r\n });\r\n"],"names":["define","$","Modal","ModalPreset","PresetEvents","Str","Fragment","AJAX","Templates","Loadingicon","Notification","ModalEvents","PresetModal","SELECTOR","Preset","contextId","courseid","section","loadPresetsList","prototype","listElement","pageparams","loadIconElement","actionbuttons","setupmodal","THIS","this","triggerelement","document","querySelectorAll","attachmentPoint","createElement","classList","add","forEach","element","addEventListener","presetid","getAttribute","presettitle","params","body","prepend","registerModalType","create","type","TYPE","title","get_string","loadFragment","large","then","modal","show","getRoot","on","bodyRendered","get","querySelector","reinitAvailability","fieldChangedEvent","hidden","target","tinyMCE","EditorManager","id","remove","destroy","bind","customize","modform","modformdata","FormData","form","formdata","URLSearchParams","toString","addIconToContainer","disableButtons","applyCustomize","save","e","preventDefault","restorePreset","catch","exception","fieldName","changeinput","changeName","split","confParam","getElementById","methods","field","event","value","reminder","schedule","method","opt","hasOwnProperty","selector","M","core_availability","resetRestrictPlugins","parentNode","removeChild","init","restrictByGroup","availabilityPlugins","plugins","plugin","i","addedEvents","contextID","done","html","js","handleFormSubmissionResponse","buttons","$i","disabled","data","innerHTML","replaceNode","contextid","formdatastr","call","methodname","args","response","JSON","parse","url","window","location","href","listParent","loaded","replaceNodeContents","setAttribute"],"mappings":"AAAAA,0BAAO,CAAC,SAAU,qBAAsB,yBAA0B,mBAAoB,WAAY,gBAAiB,YAC/G,iBAAkB,mBAAoB,oBAAqB,oBAAqB,0BAChF,SAASC,EAAGC,MAAOC,YAAaC,aAAcC,IAAKC,SAAUC,KAAMC,UAAWC,YAC1EC,aAAcC,YAAaC,iBAEvBC,4BACoB,4CASpBC,OAAS,SAASC,UAAWC,SAAUC,cAClCF,UAAYA,eACZC,SAAWA,cACXC,QAAUA,aACVC,0BAGTJ,OAAOK,UAAUC,YAAc,UAAa,4BAAgC,mBAE5EN,OAAOK,UAAUJ,UAAY,EAE7BD,OAAOK,UAAUH,SAAW,EAE5BF,OAAOK,UAAUF,QAAU,EAE3BH,OAAOK,UAAUE,WAAa,GAE9BP,OAAOK,UAAUG,gBAAkB,6BAEnCR,OAAOK,UAAUI,cAAgB,uBAKjCT,OAAOK,UAAUK,WAAa,eAEtBC,KAAOC,KAEPC,eAAiBC,SAASC,iBAAiB,oBAE3CC,gBAAkBF,SAASG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BD,UAAUE,WACjCrE,KAAKwH,KAAK,CAAC,CACtBC,WAAY,0BACZC,KAAM,CAACJ,UAAWA,UAAWnD,SAAUoD,gBAGlC,GAAGX,MAAMe,gBAEa,KAD3BA,SAAWC,KAAKC,MAAMF,WACFG,MAChBC,OAAOC,SAASC,KAAON,SAASG,SAQ5CvH,OAAOK,UAAUD,gBAAkB,eAC3BuH,WAAa7G,SAAS+D,eAAejE,KAAKN,YAAYiF,UAEvC,OAAfoC,YACwD,SAApDA,WAAWnG,aAAaZ,KAAKN,YAAYsH,SACzCpI,SAAS2C,aAAa,YAAa,kBAAmBvB,KAAKX,UAAW,UAAaW,KAAKV,WACnFmG,MAAK,CAACC,KAAMC,MACT7G,UAAUmI,oBAAoBF,WAAYrB,KAAMC,IAChDoB,WAAWG,aAAalH,KAAKN,YAAYsH,OAAQ,aAC5ClH,iBAMlB,CACHmF,KAAM,CAAC5F,UAAWC,SAAUC,eACpBH,OAAOC,UAAWC,SAAUC"} \ No newline at end of file diff --git a/amd/src/preset.js b/amd/src/preset.js index 6f85cae..9155664 100644 --- a/amd/src/preset.js +++ b/amd/src/preset.js @@ -73,13 +73,16 @@ define(['jquery', 'core/modal_factory', 'mod_pulse/modal_preset', 'mod_pulse/eve modal.attachmentPoint = attachmentPoint; modal.show(); modal.getRoot().on(ModalEvents.bodyRendered, function() { - THIS.reinitAvailability(SELECTOR.presetAvailability); + + if (modal.getRoot().get(0).querySelector("#id_availabilityconditionsjson") != null) { + THIS.reinitAvailability(SELECTOR.presetAvailability); + } THIS.fieldChangedEvent(); }); // Destroy the modal on hidden to reload the editors. modal.getRoot().on(ModalEvents.hidden, function() { modal.getRoot().get(0).querySelectorAll('form textarea').forEach(target => { - if (typeof tinyMCE !== 'undefined') { + if (typeof tinyMCE !== 'undefined' && tinyMCE.EditorManager.get(target.id)) { // eslint-disable-line tinyMCE.EditorManager.get(target.id).remove(); // eslint-disable-line } }); diff --git a/classes/preset.php b/classes/preset.php index 2c434c2..b089f93 100644 --- a/classes/preset.php +++ b/classes/preset.php @@ -230,7 +230,7 @@ public function presetdata(): void { * @return void */ public function load_forms(): void { - global $OUTPUT; + global $OUTPUT, $CFG; $configparams = (isset($this->preset->configparams)) ? json_decode($this->preset->configparams, true) : []; self::js_collection_requirement(); // End js collection. @@ -271,14 +271,21 @@ public function load_forms(): void { $this->_form->addElement($elem); $this->_form->addElement('hidden', $attributename.'_changed', false); } + + if ($element->_name == 'availabilityconditionsjson' || isset($elementname) && $elementname == 'availabilityconditionsjson') { + $includeindicator = true; + } } + // Availability loading indicator. - $loadingcontainer = $OUTPUT->container( - $OUTPUT->render_from_template('core/loading', []), - 'd-flex justify-content-center py-5 icon-size-5', - 'availabilityconditions-loading' - ); - $this->_form->addElement('html', $loadingcontainer); + if (isset($includeindicator) && $includeindicator && $CFG->branch >= "403") { + $loadingcontainer = $OUTPUT->container( + $OUTPUT->render_from_template('core/loading', []), + 'd-flex justify-content-center py-5 icon-size-5', + 'availabilityconditions-loading' + ); + $this->_form->addElement('html', $loadingcontainer); + } $this->add_action_buttons(false, 's'); } diff --git a/version.php b/version.php index d08f7f3..c6d0056 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'mod_pulse'; -$plugin->version = 2024033005; +$plugin->version = 2024033006; $plugin->requires = 2022112800; // Requires Moodle 4.1. $plugin->release = 'v2.1'; $plugin->maturity = MATURITY_STABLE;