From 232112dee1ad4a5dd7b03070d248ebedefd12eba Mon Sep 17 00:00:00 2001 From: Prasanna LMSACE Date: Mon, 25 Sep 2023 14:49:26 +0530 Subject: [PATCH] Fixed behat and js compiled --- actions/notification/amd/build/chaptersource.min.js | 2 +- actions/notification/amd/build/chaptersource.min.js.map | 2 +- .../tests/behat/pulse_notification_template.feature | 1 + amd/build/automation.min.js | 2 +- amd/build/automation.min.js.map | 2 +- amd/build/completion.min.js.map | 2 +- amd/build/events.min.js.map | 2 +- amd/build/modal_preset.min.js.map | 2 +- amd/build/module.min.js | 2 +- amd/build/module.min.js.map | 2 +- amd/build/preset.min.js.map | 2 +- .../session/tests/behat/trigger_pulsecondition_session.feature | 2 -- tests/behat/pulse_automation_template.feature | 2 +- 13 files changed, 12 insertions(+), 13 deletions(-) diff --git a/actions/notification/amd/build/chaptersource.min.js b/actions/notification/amd/build/chaptersource.min.js index 8735c41..c232b0f 100644 --- a/actions/notification/amd/build/chaptersource.min.js +++ b/actions/notification/amd/build/chaptersource.min.js @@ -7,6 +7,6 @@ * @copyright 2016 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("pulseaction_notification/chaptersource",["jquery","core/ajax","core/notification","core/modal_factory","core/fragment","core/str","core/modal_events"],(function($,Ajax,Notification,ModalFactory,Fragment,Str,ModalEvents){const previewModalBody=function(contextID){let userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(void 0!==window.tinyMCE)var params={contentheader:window.tinyMCE.get("id_pulsenotification_headercontent_editor").getContent(),contentstatic:window.tinyMCE.get("id_pulsenotification_staticcontent_editor").getContent(),contentfooter:window.tinyMCE.get("id_pulsenotification_footercontent_editor").getContent(),userid:userid};else params={contentheader:document.querySelector("#id_pulsenotification_headercontent_editoreditable").innerHTML,contentstatic:document.querySelector("#id_pulsenotification_staticcontent_editoreditable").innerHTML,contentfooter:document.querySelector("#id_pulsenotification_footercontent_editoreditable").innerHTML,userid:userid};var dynamicparams={};if(null!==document.querySelector("[name=pulsenotification_dynamiccontent]")){dynamicparams={contentdynamic:document.querySelector("[name=pulsenotification_dynamiccontent]").value,contenttype:document.querySelector("[name=pulsenotification_contenttype]").value,chapterid:document.querySelector("[name=pulsenotification_chapterid]").value,contentlength:document.querySelector("[name=pulsenotification_contentlength]").value};var form=document.forms["pulse-automation-template"],formdata=new FormData(form),formData={formdata:formdata=new URLSearchParams(formdata).toString()}}return Fragment.loadFragment("pulseaction_notification","preview_content",contextID,{...params,...dynamicparams,...formData})};return{processResults:function(selector,modules){return modules},transport:function(selector,query,success,failure){var mod=document.querySelector("#id_pulsenotification_dynamiccontent");Ajax.call([{methodname:"pulseaction_notification_get_chapters",args:{mod:mod.value}}])[0].then((function(result){success(result)})).fail(failure)},updateChapter:function(){const SELECTORS_chaperType="#id_pulsenotification_contenttype",SELECTORS_mod="#id_pulsenotification_dynamiccontent";document.querySelector(SELECTORS_chaperType).addEventListener("change",(e=>resetChapter())),document.querySelector(SELECTORS_mod).addEventListener("change",(e=>resetChapter()));var chapter=document.querySelector("#id_pulsenotification_chapterid");function resetChapter(){chapter.innerHTML="",chapter.value="";var event=new Event("change");chapter.dispatchEvent(event)}},previewNotification:function(contextid){var btn=document.querySelector('[name="pulsenotification_preview"]');null!==btn&&btn.addEventListener("click",(function(){var contextID;contextID=contextid,ModalFactory.create({title:Str.get_string("preview","pulseaction_notification"),body:previewModalBody(contextID),large:!0}).then((modal=>{modal.show(),modal.getRoot().on(ModalEvents.bodyRendered,(function(){modal.getRoot().get(0).querySelector("[name=userselector]").addEventListener("change",(e=>{e.preventDefault();var target=e.target;modal.setBody(previewModalBody(contextID,target.value))}))}))}))}))},reportModal:function(contextID){var btn=document.querySelectorAll('[data-target="view-content"]');null!==btn&&btn.forEach((element=>{element.addEventListener("click",(function(e){var target=e.target.closest("a"),instance=target.dataset.instanceid,userid=target.dataset.userid;!function(contextID,instance,userid){var params={instanceid:instance,userid:userid};ModalFactory.create({title:Str.get_string("preview","pulseaction_notification"),body:Fragment.loadFragment("pulseaction_notification","preview_instance_content",contextID,params),large:!0}).then((modal=>{modal.show()}))}(contextID,instance,userid)}))}))}}})); +define("pulseaction_notification/chaptersource",["jquery","core/ajax","core/notification","core/modal_factory","core/fragment","core/str","core/modal_events"],(function($,Ajax,Notification,ModalFactory,Fragment,Str,ModalEvents){const previewModalBody=function(contextID){let userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;var params;params=void 0!==window.tinyMCE?{contentheader:window.tinyMCE.get("id_pulsenotification_headercontent_editor").getContent(),contentstatic:window.tinyMCE.get("id_pulsenotification_staticcontent_editor").getContent(),contentfooter:window.tinyMCE.get("id_pulsenotification_footercontent_editor").getContent(),userid:userid}:{contentheader:document.querySelector("#id_pulsenotification_headercontent_editoreditable").innerHTML,contentstatic:document.querySelector("#id_pulsenotification_staticcontent_editoreditable").innerHTML,contentfooter:document.querySelector("#id_pulsenotification_footercontent_editoreditable").innerHTML,userid:userid};var formData,dynamicparams={};if(null!==document.querySelector("[name=pulsenotification_dynamiccontent]")){dynamicparams={contentdynamic:document.querySelector("[name=pulsenotification_dynamiccontent]").value,contenttype:document.querySelector("[name=pulsenotification_contenttype]").value,chapterid:document.querySelector("[name=pulsenotification_chapterid]").value,contentlength:document.querySelector("[name=pulsenotification_contentlength]").value};var form=document.forms["pulse-automation-template"],formdata=new FormData(form);formData={formdata:formdata=new URLSearchParams(formdata).toString()}}var finalParams={...params,...dynamicparams,...formData};return Fragment.loadFragment("pulseaction_notification","preview_content",contextID,finalParams)};return{processResults:function(selector,modules){return modules},transport:function(selector,query,success,failure){var mod=document.querySelector("#id_pulsenotification_dynamiccontent");Ajax.call([{methodname:"pulseaction_notification_get_chapters",args:{mod:mod.value}}])[0].then((function(result){success(result)})).fail(failure)},updateChapter:function(){const SELECTORS_chaperType="#id_pulsenotification_contenttype",SELECTORS_mod="#id_pulsenotification_dynamiccontent";document.querySelector(SELECTORS_chaperType).addEventListener("change",(()=>resetChapter())),document.querySelector(SELECTORS_mod).addEventListener("change",(()=>resetChapter()));var chapter=document.querySelector("#id_pulsenotification_chapterid");function resetChapter(){chapter.innerHTML="",chapter.value="";var event=new Event("change");chapter.dispatchEvent(event)}},previewNotification:function(contextid){var btn=document.querySelector('[name="pulsenotification_preview"]');null!==btn&&btn.addEventListener("click",(function(){var contextID;contextID=contextid,ModalFactory.create({title:Str.get_string("preview","pulseaction_notification"),body:previewModalBody(contextID),large:!0}).then((modal=>{modal.show(),modal.getRoot().on(ModalEvents.bodyRendered,(function(){modal.getRoot().get(0).querySelector("[name=userselector]").addEventListener("change",(e=>{e.preventDefault();var target=e.target;modal.setBody(previewModalBody(contextID,target.value))}))}))})).catch()}))},reportModal:function(contextID){var btn=document.querySelectorAll('[data-target="view-content"]');null!==btn&&btn.forEach((element=>{element.addEventListener("click",(function(e){var target=e.target.closest("a"),instance=target.dataset.instanceid,userid=target.dataset.userid;!function(contextID,instance,userid){var params={instanceid:instance,userid:userid};ModalFactory.create({title:Str.get_string("preview","pulseaction_notification"),body:Fragment.loadFragment("pulseaction_notification","preview_instance_content",contextID,params),large:!0}).then((modal=>{modal.show()})).catch()}(contextID,instance,userid)}))}))}}})); //# sourceMappingURL=chaptersource.min.js.map \ No newline at end of file diff --git a/actions/notification/amd/build/chaptersource.min.js.map b/actions/notification/amd/build/chaptersource.min.js.map index 9da4c17..00405cc 100644 --- a/actions/notification/amd/build/chaptersource.min.js.map +++ b/actions/notification/amd/build/chaptersource.min.js.map @@ -1 +1 @@ -{"version":3,"file":"chaptersource.min.js","sources":["../src/chaptersource.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\r\n//\r\n// Moodle is free software: you can redistribute it and/or modify\r\n// it under the terms of the GNU General Public License as published by\r\n// the Free Software Foundation, either version 3 of the License, or\r\n// (at your option) any later version.\r\n//\r\n// Moodle is distributed in the hope that it will be useful,\r\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n// GNU General Public License for more details.\r\n//\r\n// You should have received a copy of the GNU General Public License\r\n// along with Moodle. If not, see .\r\n\r\n/**\r\n * Frameworks datasource.\r\n *\r\n * This module is compatible with core/form-autocomplete.\r\n *\r\n * @module tool_lp/frameworks_datasource\r\n * @copyright 2016 Frédéric Massart - FMCorz.net\r\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r\n */\r\n\r\ndefine(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/fragment', 'core/str', 'core/modal_events'],\r\n function($, Ajax, Notification, ModalFactory, Fragment, Str, ModalEvents) {\r\n\r\n\r\n const previewModalBody = function(contextID, userid=null) {\r\n\r\n if (window.tinyMCE !== undefined) {\r\n // editorPlugin = window.tinyMCE;\r\n var params = {\r\n contentheader: window.tinyMCE.get('id_pulsenotification_headercontent_editor').getContent(),\r\n contentstatic: window.tinyMCE.get('id_pulsenotification_staticcontent_editor').getContent(),\r\n contentfooter: window.tinyMCE.get('id_pulsenotification_footercontent_editor').getContent(),\r\n userid: userid\r\n };\r\n } else {\r\n // editorPlugin = document;\r\n var params = {\r\n contentheader: document.querySelector('#id_pulsenotification_headercontent_editoreditable').innerHTML,\r\n contentstatic: document.querySelector('#id_pulsenotification_staticcontent_editoreditable').innerHTML,\r\n contentfooter: document.querySelector('#id_pulsenotification_footercontent_editoreditable').innerHTML,\r\n userid: userid\r\n };\r\n }\r\n\r\n var dynamicparams = {};\r\n if (document.querySelector('[name=pulsenotification_dynamiccontent]') !== null) {\r\n dynamicparams = {\r\n contentdynamic: document.querySelector('[name=pulsenotification_dynamiccontent]').value,\r\n contenttype: document.querySelector('[name=pulsenotification_contenttype]').value,\r\n chapterid: document.querySelector('[name=pulsenotification_chapterid]').value,\r\n contentlength: document.querySelector('[name=pulsenotification_contentlength]').value,\r\n };\r\n\r\n // Get the form data.\r\n var form = document.forms['pulse-automation-template'];\r\n var formdata = new FormData(form);\r\n formdata = new URLSearchParams(formdata).toString();\r\n var formData = {\r\n formdata: formdata\r\n }\r\n }\r\n\r\n return Fragment.loadFragment('pulseaction_notification', 'preview_content', contextID, {...params, ...dynamicparams, ...formData});\r\n }\r\n\r\n const previewModal = function(contextID) {\r\n\r\n ModalFactory.create({\r\n title: Str.get_string('preview', 'pulseaction_notification'),\r\n body: previewModalBody(contextID),\r\n large: true,\r\n }).then((modal) => {\r\n modal.show();\r\n\r\n modal.getRoot().on(ModalEvents.bodyRendered, function() {\r\n modal.getRoot().get(0).querySelector('[name=userselector]').addEventListener('change', (e) => {\r\n e.preventDefault();\r\n var target = e.target;\r\n modal.setBody(previewModalBody(contextID, target.value));\r\n })\r\n })\r\n });\r\n };\r\n\r\n const notificationModal = function(contextID, instance, userid) {\r\n\r\n var params = {\r\n instanceid: instance,\r\n userid: userid\r\n };\r\n\r\n ModalFactory.create({\r\n title: Str.get_string('preview', 'pulseaction_notification'),\r\n body: Fragment.loadFragment('pulseaction_notification', 'preview_instance_content', contextID, params),\r\n large: true,\r\n }).then((modal) => {\r\n modal.show();\r\n\r\n /* modal.getRoot().on(ModalEvents.bodyRendered, function() {\r\n modal.getRoot().get(0).querySelector('[name=userselector]').addEventListener('change', (e) => {\r\n e.preventDefault();\r\n var target = e.target;\r\n modal.setBody(previewModalBody(contextID, target.value));\r\n })\r\n }) */\r\n });\r\n };\r\n\r\n return {\r\n\r\n processResults: function(selector, modules) {\r\n return modules;\r\n },\r\n\r\n transport: function(selector, query, success, failure) {\r\n\r\n var mod = document.querySelector(\"#id_pulsenotification_dynamiccontent\");\r\n\r\n var promise = Ajax.call([{\r\n methodname: 'pulseaction_notification_get_chapters',\r\n args: {mod: mod.value}\r\n }]);\r\n\r\n promise[0].then(function(result) {\r\n success(result);\r\n return;\r\n }).fail(failure);\r\n },\r\n\r\n updateChapter: function() {\r\n\r\n const SELECTORS = {\r\n chaperType : \"#id_pulsenotification_contenttype\",\r\n mod: \"#id_pulsenotification_dynamiccontent\"\r\n };\r\n\r\n document.querySelector(SELECTORS.chaperType).addEventListener(\"change\", (e) => resetChapter());\r\n document.querySelector(SELECTORS.mod).addEventListener(\"change\", (e) => resetChapter());\r\n var chapter = document.querySelector(\"#id_pulsenotification_chapterid\");\r\n\r\n function resetChapter() {\r\n chapter.innerHTML = '';\r\n chapter.value = '';\r\n var event = new Event('change');\r\n chapter.dispatchEvent(event);\r\n }\r\n },\r\n\r\n previewNotification: function(contextid) {\r\n var btn = document.querySelector('[name=\"pulsenotification_preview\"]');\r\n\r\n if (btn === null) {\r\n return;\r\n }\r\n\r\n btn.addEventListener('click', function() {\r\n previewModal(contextid);\r\n })\r\n },\r\n\r\n reportModal: function(contextID) {\r\n // View content.\r\n var btn = document.querySelectorAll('[data-target=\"view-content\"]');\r\n\r\n if (btn === null) {\r\n return;\r\n }\r\n\r\n btn.forEach((element) => {\r\n element.addEventListener('click', function(e) {\r\n\r\n var target = e.target.closest('a');\r\n\r\n var instance = target.dataset.instanceid;\r\n var userid = target.dataset.userid;\r\n\r\n notificationModal(contextID, instance, userid); // Notification modal.\r\n });\r\n });\r\n }\r\n };\r\n\r\n});\r\n"],"names":["define","$","Ajax","Notification","ModalFactory","Fragment","Str","ModalEvents","previewModalBody","contextID","userid","undefined","window","tinyMCE","params","contentheader","get","getContent","contentstatic","contentfooter","document","querySelector","innerHTML","dynamicparams","contentdynamic","value","contenttype","chapterid","contentlength","form","forms","formdata","FormData","formData","URLSearchParams","toString","loadFragment","processResults","selector","modules","transport","query","success","failure","mod","call","methodname","args","then","result","fail","updateChapter","SELECTORS","addEventListener","e","resetChapter","chapter","event","Event","dispatchEvent","previewNotification","contextid","btn","create","title","get_string","body","large","modal","show","getRoot","on","bodyRendered","preventDefault","target","setBody","reportModal","querySelectorAll","forEach","element","closest","instance","dataset","instanceid","notificationModal"],"mappings":";;;;;;;;;AAyBAA,gDAAO,CAAC,SAAU,YAAa,oBAAqB,qBAAsB,gBAAiB,WAAY,sBACnG,SAASC,EAAGC,KAAMC,aAAcC,aAAcC,SAAUC,IAAKC,mBAGvD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/B,MAAQ,OACZgC,MAAQ,IAAIC,MAAM,UACtBF,QAAQG,cAAcF,SAI9BG,oBAAqB,SAASC,eACtBC,IAAM1C,SAASC,cAAc,sCAErB,OAARyC,KAIJA,IAAIT,iBAAiB,SAAS,WA1FjB,IAAS5C,UAAAA,UA2FLoD,UAzFrBzD,aAAa2D,OAAO,CAChBC,MAAO1D,IAAI2D,WAAW,UAAW,4BACjCC,KAAM1D,iBAAiBC,WACvB0D,OAAO,IACRnB,MAAMoB,QACLA,MAAMC,OAEND,MAAME,UAAUC,GAAGhE,YAAYiE,cAAc,WACzCJ,MAAME,UAAUtD,IAAI,GAAGK,cAAc,uBAAuBgC,iBAAiB,UAAWC,IACpFA,EAAEmB,qBACEC,OAASpB,EAAEoB,OACfN,MAAMO,QAAQnE,iBAAiBC,UAAWiE,OAAOjD,qBAkF7DmD,YAAa,SAASnE,eAEdqD,IAAM1C,SAASyD,iBAAiB,gCAExB,OAARf,KAIJA,IAAIgB,SAASC,UACTA,QAAQ1B,iBAAiB,SAAS,SAASC,OAEnCoB,OAASpB,EAAEoB,OAAOM,QAAQ,KAE1BC,SAAWP,OAAOQ,QAAQC,WAC1BzE,OAASgE,OAAOQ,QAAQxE,QA1FlB,SAASD,UAAWwE,SAAUvE,YAEhDI,OAAS,CACTqE,WAAYF,SACZvE,OAAQA,QAGZN,aAAa2D,OAAO,CAChBC,MAAO1D,IAAI2D,WAAW,UAAW,4BACjCC,KAAM7D,SAAS+B,aAAa,2BAA4B,2BAA4B3B,UAAWK,QAC/FqD,OAAO,IACRnB,MAAMoB,QACLA,MAAMC,UAgFEe,CAAkB3E,UAAWwE,SAAUvE"} \ No newline at end of file +{"version":3,"file":"chaptersource.min.js","sources":["../src/chaptersource.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 * Frameworks datasource.\n *\n * This module is compatible with core/form-autocomplete.\n *\n * @module tool_lp/frameworks_datasource\n * @copyright 2016 Frédéric Massart - FMCorz.net\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/fragment', 'core/str', 'core/modal_events'],\n function($, Ajax, Notification, ModalFactory, Fragment, Str, ModalEvents) {\n\n const previewModalBody = function(contextID, userid = null) {\n\n var params;\n if (window.tinyMCE !== undefined) {\n // EditorPlugin = window.tinyMCE;\n params = {\n contentheader: window.tinyMCE.get('id_pulsenotification_headercontent_editor').getContent(),\n contentstatic: window.tinyMCE.get('id_pulsenotification_staticcontent_editor').getContent(),\n contentfooter: window.tinyMCE.get('id_pulsenotification_footercontent_editor').getContent(),\n userid: userid\n };\n } else {\n // EditorPlugin = document;\n params = {\n contentheader: document.querySelector('#id_pulsenotification_headercontent_editoreditable').innerHTML,\n contentstatic: document.querySelector('#id_pulsenotification_staticcontent_editoreditable').innerHTML,\n contentfooter: document.querySelector('#id_pulsenotification_footercontent_editoreditable').innerHTML,\n userid: userid\n };\n }\n\n var dynamicparams = {};\n var formData;\n if (document.querySelector('[name=pulsenotification_dynamiccontent]') !== null) {\n dynamicparams = {\n contentdynamic: document.querySelector('[name=pulsenotification_dynamiccontent]').value,\n contenttype: document.querySelector('[name=pulsenotification_contenttype]').value,\n chapterid: document.querySelector('[name=pulsenotification_chapterid]').value,\n contentlength: document.querySelector('[name=pulsenotification_contentlength]').value,\n };\n\n // Get the form data.\n var form = document.forms['pulse-automation-template'];\n var formdata = new FormData(form);\n formdata = new URLSearchParams(formdata).toString();\n formData = {\n formdata: formdata\n };\n }\n var finalParams = {...params, ...dynamicparams, ...formData};\n\n return Fragment.loadFragment('pulseaction_notification', 'preview_content', contextID, finalParams);\n };\n\n const previewModal = function(contextID) {\n\n ModalFactory.create({\n title: Str.get_string('preview', 'pulseaction_notification'),\n body: previewModalBody(contextID),\n large: true,\n }).then((modal) => {\n modal.show();\n\n modal.getRoot().on(ModalEvents.bodyRendered, function() {\n modal.getRoot().get(0).querySelector('[name=userselector]').addEventListener('change', (e) => {\n e.preventDefault();\n var target = e.target;\n modal.setBody(previewModalBody(contextID, target.value));\n });\n });\n\n return;\n }).catch();\n };\n\n const notificationModal = function(contextID, instance, userid) {\n\n var params = {\n instanceid: instance,\n userid: userid\n };\n\n ModalFactory.create({\n title: Str.get_string('preview', 'pulseaction_notification'),\n body: Fragment.loadFragment('pulseaction_notification', 'preview_instance_content', contextID, params),\n large: true,\n }).then((modal) => {\n modal.show();\n return;\n }).catch();\n };\n\n return {\n\n processResults: function(selector, modules) {\n return modules;\n },\n\n transport: function(selector, query, success, failure) {\n\n var mod = document.querySelector(\"#id_pulsenotification_dynamiccontent\");\n\n var promise = Ajax.call([{\n methodname: 'pulseaction_notification_get_chapters',\n args: {mod: mod.value}\n }]);\n\n promise[0].then(function(result) {\n success(result);\n return;\n }).fail(failure);\n },\n\n updateChapter: function() {\n\n const SELECTORS = {\n chaperType: \"#id_pulsenotification_contenttype\",\n mod: \"#id_pulsenotification_dynamiccontent\"\n };\n\n document.querySelector(SELECTORS.chaperType).addEventListener(\"change\", () => resetChapter());\n document.querySelector(SELECTORS.mod).addEventListener(\"change\", () => resetChapter());\n var chapter = document.querySelector(\"#id_pulsenotification_chapterid\");\n\n /**\n *\n */\n function resetChapter() {\n chapter.innerHTML = '';\n chapter.value = '';\n var event = new Event('change');\n chapter.dispatchEvent(event);\n }\n },\n\n previewNotification: function(contextid) {\n var btn = document.querySelector('[name=\"pulsenotification_preview\"]');\n\n if (btn === null) {\n return;\n }\n\n btn.addEventListener('click', function() {\n previewModal(contextid);\n });\n },\n\n reportModal: function(contextID) {\n // View content.\n var btn = document.querySelectorAll('[data-target=\"view-content\"]');\n\n if (btn === null) {\n return;\n }\n\n btn.forEach((element) => {\n element.addEventListener('click', function(e) {\n\n var target = e.target.closest('a');\n\n var instance = target.dataset.instanceid;\n var userid = target.dataset.userid;\n\n notificationModal(contextID, instance, userid); // Notification modal.\n });\n });\n }\n };\n\n});\n"],"names":["define","$","Ajax","Notification","ModalFactory","Fragment","Str","ModalEvents","previewModalBody","contextID","userid","params","undefined","window","tinyMCE","contentheader","get","getContent","contentstatic","contentfooter","document","querySelector","innerHTML","formData","dynamicparams","contentdynamic","value","contenttype","chapterid","contentlength","form","forms","formdata","FormData","URLSearchParams","toString","finalParams","loadFragment","processResults","selector","modules","transport","query","success","failure","mod","call","methodname","args","then","result","fail","updateChapter","SELECTORS","addEventListener","resetChapter","chapter","event","Event","dispatchEvent","previewNotification","contextid","btn","create","title","get_string","body","large","modal","show","getRoot","on","bodyRendered","e","preventDefault","target","setBody","catch","reportModal","querySelectorAll","forEach","element","closest","instance","dataset","instanceid","notificationModal"],"mappings":";;;;;;;;;AAyBAA,gDAAO,CAAC,SAAU,YAAa,oBAAqB,qBAAsB,gBAAiB,WAAY,sBACnG,SAASC,EAAGC,KAAMC,aAAcC,aAAcC,SAAUC,IAAKC,mBAEvDC,iBAAmB,SAASC,eAAWC,8DAAS,SAE9CC,OAGAA,YAFmBC,IAAnBC,OAAOC,QAEE,CACLC,cAAeF,OAAOC,QAAQE,IAAI,6CAA6CC,aAC/EC,cAAeL,OAAOC,QAAQE,IAAI,6CAA6CC,aAC/EE,cAAeN,OAAOC,QAAQE,IAAI,6CAA6CC,aAC/EP,OAAQA,QAIH,CACLK,cAAeK,SAASC,cAAc,sDAAsDC,UAC5FJ,cAAeE,SAASC,cAAc,sDAAsDC,UAC5FH,cAAeC,SAASC,cAAc,sDAAsDC,UAC5FZ,OAAQA,YAKZa,SADAC,cAAgB,MAEsD,OAAtEJ,SAASC,cAAc,2CAAqD,CAC5EG,cAA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uBAAuBiC,iBAAiB,UAAWmB,IACpFA,EAAEC,qBACEC,OAASF,EAAEE,OACfP,MAAMQ,QAAQpE,iBAAiBC,UAAWkE,OAAOjD,iBAK1DmD,YA2EHC,YAAa,SAASrE,eAEdqD,IAAM1C,SAAS2D,iBAAiB,gCAExB,OAARjB,KAIJA,IAAIkB,SAASC,UACTA,QAAQ3B,iBAAiB,SAAS,SAASmB,OAEnCE,OAASF,EAAEE,OAAOO,QAAQ,KAE1BC,SAAWR,OAAOS,QAAQC,WAC1B3E,OAASiE,OAAOS,QAAQ1E,QAtFlB,SAASD,UAAW0E,SAAUzE,YAEhDC,OAAS,CACT0E,WAAYF,SACZzE,OAAQA,QAGZN,aAAa2D,OAAO,CAChBC,MAAO1D,IAAI2D,WAAW,UAAW,4BACjCC,KAAM7D,SAASgC,aAAa,2BAA4B,2BAA4B5B,UAAWE,QAC/FwD,OAAO,IACRlB,MAAMmB,QACLA,MAAMC,UAEPQ,QA0ESS,CAAkB7E,UAAW0E,SAAUzE"} \ No newline at end of file diff --git a/actions/notification/tests/behat/pulse_notification_template.feature b/actions/notification/tests/behat/pulse_notification_template.feature index 0fe5fd0..62e43cd 100644 --- a/actions/notification/tests/behat/pulse_notification_template.feature +++ b/actions/notification/tests/behat/pulse_notification_template.feature @@ -60,6 +60,7 @@ Feature: Configuring the pulseaction_notification plugin on the "Automation temp And I should see "WELCOMEMESSAGE_COURSE_1" in the "pulse_automation_template" "table" And I click on ".action-report" "css_element" in the "WELCOMEMESSAGE_COURSE_1" "table_row" And I switch to a second window + Then ".reportbuilder-report" "css_element" should exist And the following should exist in the "reportbuilder-table" table: | Full name | Subject | Status | | student User 1 | Welcome to learning portal Acceptance test site | Queued | diff --git a/amd/build/automation.min.js b/amd/build/automation.min.js index e791951..259af9c 100644 --- a/amd/build/automation.min.js +++ b/amd/build/automation.min.js @@ -1,3 +1,3 @@ -define("mod_pulse/automation",["jquery","core/modal_factory","core/templates","core/str"],(function($,Modal,Template,Str){const moveOverRidePosition=function(){var group="checkboxgroupautomation";if(null===document.querySelectorAll("input[type=checkbox]."+group))return!0;document.querySelectorAll("input[type=checkbox]."+group).forEach((overElement=>{var id=overElement.id;id=id.replace("id_override_","");var element=document.querySelector("div#fitem_id_"+id);if(null===element&&null===(element=document.querySelector("div#fgroup_id_"+id)))return!0;var parent=overElement.parentNode;parent.innerHTML+='';var nodeToMove=document.createElement("div");nodeToMove.classList.add("custom-control","custom-switch"),nodeToMove.append(parent),element.querySelector(".felement").append(nodeToMove)})),function(){if(null===document.querySelectorAll("input[type=checkbox].checkboxgroupautomation")||null===document.querySelectorAll('[data-fieldtype="autocomplete"]'))return!0;document.querySelectorAll('[data-fieldtype="autocomplete"]').forEach((element=>{if(null===element)return!0;var observer=new MutationObserver((function(mutations){mutations.forEach((mutation=>{console.log(mutation),target=mutation.target;var overrideElement=target.querySelector(".custom-switch");null!==overrideElement&&(overrideElement.parentNode.append(overrideElement),observer.disconnect())}))}));observer.observe(element,{attributes:!0,childList:!0,subtree:!0})}))}()};return{init:function(){(()=>{if(null===document.forms["pulse-automation-template"])return!1;document.forms["pulse-automation-template"].onsubmit=e=>{var invalidElement=e.target.querySelector(".is-invalid");if(null===invalidElement)return!0;var hrefSelector='[href="#'+invalidElement.parentNode.parentNode.parentNode.id+'"]';document.querySelector(hrefSelector).click()}})(),function(){var templateReference=document.querySelector("#pulse-template-reference"),instanceReference=document.querySelector("#fitem_id_insreference .felement");templateReference&&instanceReference&&(templateReference.classList.remove("hide"),instanceReference.prepend(templateReference));const trigger=document.querySelectorAll('[data-target="overridemodal"]');null!==trigger&&trigger.forEach((elem=>{elem.nextSibling.querySelector(".felement").append(elem),elem.addEventListener("click",(function(e){e.preventDefault();var data=e.target.dataset,instance=document.querySelector("[name=overinstance_"+data.element+"]");if(null!==instance){var overrides=JSON.parse(instance.value);overrides.map((value=>(value.url=M.cfg.wwwroot+"/mod/pulse/automation/instances/edit.php?instanceid="+value.id+"&sesskey="+M.cfg.sesskey,value))),Modal.create({title:Str.get_string("instanceoverrides","pulse"),body:Template.render("mod_pulse/overrides",{instances:overrides})}).then((modal=>{modal.show()}))}}))}))}(),moveOverRidePosition(),null!==document.forms["pulse-automation-template"]&&(document.forms["pulse-automation-template"].onsubmit=e=>document.querySelector('[name="title"]').removeAttribute("disabled"))},instanceMenuLink:function(){(navMenu=>{if(null!==navMenu){var menu=navMenu.querySelector("a.automation-templates");null!==menu&&((menu=menu.parentNode).dataset.forceintomoremenu=!1,menu.querySelector("a").classList.remove("dropdown-item"),menu.querySelector("a").classList.add("nav-link"),menu.parentNode.removeChild(menu),navMenu.insertBefore(menu,navMenu.children[1]),window.dispatchEvent(new Event("resize")))}})(document.querySelector(".secondary-navigation ul.more-nav"))}}})); +define("mod_pulse/automation",["jquery","core/modal_factory","core/templates","core/str"],(function($,Modal,Template,Str){const moveOverRidePosition=function(){var group="checkboxgroupautomation";return null===document.querySelectorAll("input[type=checkbox]."+group)||(document.querySelectorAll("input[type=checkbox]."+group).forEach((overElement=>{var id=overElement.id;id=id.replace("id_override_","");var element=document.querySelector("div#fitem_id_"+id);if(null===element&&null===(element=document.querySelector("div#fgroup_id_"+id)))return!0;var parent=overElement.parentNode;parent.innerHTML+='';var nodeToMove=document.createElement("div");return nodeToMove.classList.add("custom-control","custom-switch"),nodeToMove.append(parent),element.querySelector(".felement").append(nodeToMove),!0})),null===document.querySelectorAll("input[type=checkbox].checkboxgroupautomation")||null===document.querySelectorAll('[data-fieldtype="autocomplete"]')||document.querySelectorAll('[data-fieldtype="autocomplete"]').forEach((element=>{if(null===element)return!0;var observer=new MutationObserver((function(mutations){mutations.forEach((mutation=>{var overrideElement=mutation.target.querySelector(".custom-switch");null!==overrideElement&&(overrideElement.parentNode.append(overrideElement),observer.disconnect())}))}));return observer.observe(element,{attributes:!0,childList:!0,subtree:!0}),!0}))),!0};return{init:function(){null!==document.forms["pulse-automation-template"]&&(document.forms["pulse-automation-template"].onsubmit=e=>{var invalidElement=e.target.querySelector(".is-invalid");if(null===invalidElement)return!0;var hrefSelector='[href="#'+invalidElement.parentNode.parentNode.parentNode.id+'"]';return document.querySelector(hrefSelector).click(),!0}),function(){var templateReference=document.querySelector("#pulse-template-reference"),instanceReference=document.querySelector("#fitem_id_insreference .felement");templateReference&&instanceReference&&(templateReference.classList.remove("hide"),instanceReference.prepend(templateReference));const trigger=document.querySelectorAll('[data-target="overridemodal"]');null!==trigger&&trigger.forEach((elem=>{elem.nextSibling.querySelector(".felement").append(elem),elem.addEventListener("click",(function(e){e.preventDefault();var data=e.target.dataset,instance=document.querySelector("[name=overinstance_"+data.element+"]");if(null!==instance){var overrides=JSON.parse(instance.value);overrides.map((value=>(value.url=M.cfg.wwwroot+"/mod/pulse/automation/instances/edit.php?instanceid="+value.id+"&sesskey="+M.cfg.sesskey,value))),Modal.create({title:Str.get_string("instanceoverrides","pulse"),body:Template.render("mod_pulse/overrides",{instances:overrides})}).then((modal=>(modal.show(),!0))).catch()}}))}))}(),moveOverRidePosition(),null!==document.forms["pulse-automation-template"]&&(document.forms["pulse-automation-template"].onsubmit=()=>document.querySelector('[name="title"]').removeAttribute("disabled"))},instanceMenuLink:function(){(navMenu=>{if(null!==navMenu){var menu=navMenu.querySelector("a.automation-templates");null!==menu&&((menu=menu.parentNode).dataset.forceintomoremenu=!1,menu.querySelector("a").classList.remove("dropdown-item"),menu.querySelector("a").classList.add("nav-link"),menu.parentNode.removeChild(menu),navMenu.insertBefore(menu,navMenu.children[1]),window.dispatchEvent(new Event("resize")))}})(document.querySelector(".secondary-navigation ul.more-nav"))}}})); //# sourceMappingURL=automation.min.js.map \ No newline at end of file diff --git a/amd/build/automation.min.js.map b/amd/build/automation.min.js.map index 655c82c..698a069 100644 --- a/amd/build/automation.min.js.map +++ b/amd/build/automation.min.js.map @@ -1 +1 @@ -{"version":3,"file":"automation.min.js","sources":["../src/automation.js"],"sourcesContent":["define(\"mod_pulse/automation\", ['jquery', 'core/modal_factory', 'core/templates', 'core/str'], function($, Modal, Template, Str) {\r\n\r\n const moveOutMoreMenu = (navMenu) => {\r\n\r\n if (navMenu === null) {\r\n return;\r\n }\r\n\r\n var menu = navMenu.querySelector('a.automation-templates');\r\n\r\n if (menu === null) {\r\n return;\r\n }\r\n\r\n menu = menu.parentNode;\r\n menu.dataset.forceintomoremenu = false,\r\n menu.querySelector('a').classList.remove('dropdown-item');\r\n menu.querySelector('a').classList.add('nav-link');\r\n menu.parentNode.removeChild(menu);\r\n\r\n // Insert the stored menus before the more menu.\r\n navMenu.insertBefore(menu, navMenu.children[1]);\r\n window.dispatchEvent(new Event('resize')); // Dispatch the resize event to create more menu.\r\n };\r\n\r\n const returnToFailedTab = () => {\r\n\r\n if (document.forms['pulse-automation-template'] === null) {\r\n return false;\r\n }\r\n\r\n document.forms['pulse-automation-template'].onsubmit = (e) => {\r\n var form = e.target;\r\n var invalidElement = form.querySelector('.is-invalid');\r\n if (invalidElement === null) {\r\n return true;\r\n }\r\n\r\n var tabid = invalidElement.parentNode.parentNode.parentNode.id;\r\n var hrefSelector = '[href=\"#'+tabid+'\"]';\r\n\r\n document.querySelector(hrefSelector).click();\r\n }\r\n };\r\n\r\n // No need.\r\n const updateAutoCompletionPositions = function() {\r\n var group = \"checkboxgroupautomation\";\r\n\r\n if (document.querySelectorAll('input[type=checkbox].'+group) === null || document.querySelectorAll('[data-fieldtype=\"autocomplete\"]') === null) {\r\n return true;\r\n }\r\n\r\n document.querySelectorAll('[data-fieldtype=\"autocomplete\"]').forEach((element) => {\r\n\r\n if (element === null) {\r\n return true;\r\n }\r\n\r\n var observer = new MutationObserver(function(mutations) {\r\n mutations.forEach((mutation) => {\r\n console.log(mutation);\r\n // if(mutation.type === 'attributes') {\r\n target = mutation.target;\r\n var overrideElement = target.querySelector('.custom-switch');\r\n if (overrideElement === null) {\r\n return;\r\n }\r\n overrideElement.parentNode.append(overrideElement);\r\n observer.disconnect();\r\n })\r\n });\r\n observer.observe(element, { attributes: true, childList: true, subtree: true, });\r\n // observer.disconnect();\r\n })\r\n }\r\n\r\n const moveOverRidePosition = function() {\r\n\r\n var group = \"checkboxgroupautomation\";\r\n\r\n if (document.querySelectorAll('input[type=checkbox].'+group) === null) {\r\n return true;\r\n }\r\n\r\n document.querySelectorAll('input[type=checkbox].'+group).forEach((overElement) => {\r\n var id = overElement.id;\r\n id = id.replace('id_override_', '');\r\n var element = document.querySelector('div#fitem_id_'+id);\r\n if (element === null) {\r\n element = document.querySelector('div#fgroup_id_'+id);\r\n if (element === null) {\r\n return true;\r\n }\r\n }\r\n\r\n var parent = overElement.parentNode;\r\n parent.innerHTML += '';\r\n\r\n var nodeToMove = document.createElement('div');\r\n nodeToMove.classList.add('custom-control', 'custom-switch');\r\n nodeToMove.append(parent);\r\n element.querySelector(\".felement\").append(nodeToMove);\r\n });\r\n // Move the override button for autocompletion fields after the autocomplete nodes are created.\r\n updateAutoCompletionPositions();\r\n }\r\n\r\n /**\r\n * Create a modal to display the list of instances which is overriden the template setting.\r\n *\r\n * @returns {void}\r\n */\r\n const overrideModal = function() {\r\n\r\n // Add the template reference as prefix of the instance reference.\r\n var templateReference = document.querySelector('#pulse-template-reference');\r\n var instanceReference = document.querySelector('#fitem_id_insreference .felement');\r\n if (templateReference && instanceReference) {\r\n templateReference.classList.remove('hide');\r\n instanceReference.prepend(templateReference);\r\n }\r\n\r\n const trigger = document.querySelectorAll('[data-target=\"overridemodal\"]');\r\n\r\n if (trigger === null) {\r\n return;\r\n }\r\n\r\n trigger.forEach((elem) => {\r\n\r\n elem.nextSibling.querySelector('.felement').append(elem);\r\n\r\n elem.addEventListener('click', function(e) {\r\n e.preventDefault();\r\n var element = e.target;\r\n var data = element.dataset;\r\n var instance = document.querySelector('[name=overinstance_'+data.element+']');\r\n if (instance !== null) {\r\n var overrides = JSON.parse(instance.value);\r\n overrides.map((value) => {\r\n value.url = M.cfg.wwwroot+'/mod/pulse/automation/instances/edit.php?instanceid='+value.id+'&sesskey='+M.cfg.sesskey\r\n return value;\r\n })\r\n Modal.create({\r\n title: Str.get_string('instanceoverrides', 'pulse'),\r\n body: Template.render('mod_pulse/overrides', {instances: overrides})\r\n }).then((modal) => {\r\n modal.show();\r\n });\r\n }\r\n })\r\n })\r\n };\r\n\r\n const enableTitleOnSubmit = function() {\r\n if (document.forms['pulse-automation-template'] === null) {\r\n return;\r\n }\r\n document.forms['pulse-automation-template'].onsubmit = (e) => document.querySelector('[name=\"title\"]').removeAttribute(\"disabled\");\r\n }\r\n\r\n return {\r\n\r\n init: function() {\r\n returnToFailedTab();\r\n overrideModal();\r\n moveOverRidePosition();\r\n enableTitleOnSubmit();\r\n },\r\n\r\n instanceMenuLink: function() {\r\n var primaryNav = document.querySelector('.secondary-navigation ul.more-nav');\r\n moveOutMoreMenu(primaryNav);\r\n },\r\n\r\n }\r\n})\r\n"],"names":["define","$","Modal","Template","Str","moveOverRidePosition","group","document","querySelectorAll","forEach","overElement","id","replace","element","querySelector","parent","parentNode","innerHTML","nodeToMove","createElement","classList","add","append","observer","MutationObserver","mutations","mutation","console","log","target","overrideElement","disconnect","observe","attributes","childList","subtree","updateAutoCompletionPositions","init","forms","onsubmit","e","invalidElement","hrefSelector","click","returnToFailedTab","templateReference","instanceReference","remove","prepend","trigger","elem","nextSibling","addEventListener","preventDefault","data","dataset","instance","overrides","JSON","parse","value","map","url","M","cfg","wwwroot","sesskey","create","title","get_string","body","render","instances","then","modal","show","overrideModal","removeAttribute","instanceMenuLink","navMenu","menu","forceintomoremenu","removeChild","insertBefore","children","window","dispatchEvent","Event","moveOutMoreMenu"],"mappings":"AAAAA,8BAA+B,CAAC,SAAU,qBAAsB,iBAAkB,aAAa,SAASC,EAAGC,MAAOC,SAAUC,WA6ElHC,qBAAuB,eAErBC,MAAQ,6BAEqD,OAA7DC,SAASC,iBAAiB,wBAAwBF,cAC3C,EAGXC,SAASC,iBAAiB,wBAAwBF,OAAOG,SAASC,kBAC1DC,GAAKD,YAAYC,GACrBA,GAAKA,GAAGC,QAAQ,eAAgB,QAC5BC,QAAUN,SAASO,cAAc,gBA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AEX,OACG0B,QACfC,SAAWjD,SAASO,cAAc,sBAAsBwC,KAAKzC,QAAQ,QACxD,OAAb2C,SAAmB,KACfC,UAAYC,KAAKC,MAAMH,SAASI,OACpCH,UAAUI,KAAKD,QACXA,MAAME,IAAMC,EAAEC,IAAIC,QAAQ,uDAAuDL,MAAMjD,GAAG,YAAYoD,EAAEC,IAAIE,QACrGN,SAEX1D,MAAMiE,OAAO,CACTC,MAAOhE,IAAIiE,WAAW,oBAAqB,SAC3CC,KAAMnE,SAASoE,OAAO,sBAAuB,CAACC,UAAWf,cAC1DgB,MAAMC,QACLA,MAAMC,iBAkBlBC,GACAvE,uBAXgD,OAAhDE,SAAS+B,MAAM,+BAGnB/B,SAAS+B,MAAM,6BAA6BC,SAAYC,GAAMjC,SAASO,cAAc,kBAAkB+D,gBAAgB,cAYvHC,iBAAkB,WAzKGC,CAAAA,aAEL,OAAZA,aAIAC,KAAOD,QAAQjE,cAAc,0BAEpB,OAATkE,QAIJA,KAAOA,KAAKhE,YACPuC,QAAQ0B,mBAAoB,EACjCD,KAAKlE,cAAc,KAAKM,UAAU2B,OAAO,iBACzCiC,KAAKlE,cAAc,KAAKM,UAAUC,IAAI,YACtC2D,KAAKhE,WAAWkE,YAAYF,MAG5BD,QAAQI,aAAaH,KAAMD,QAAQK,SAAS,IAC5CC,OAAOC,cAAc,IAAIC,MAAM,cAuJ3BC,CADiBjF,SAASO,cAAc"} \ No newline at end of file +{"version":3,"file":"automation.min.js","sources":["../src/automation.js"],"sourcesContent":["define(\"mod_pulse/automation\", ['jquery', 'core/modal_factory', 'core/templates', 'core/str'], function($, Modal, Template, Str) {\n\n const moveOutMoreMenu = (navMenu) => {\n\n if (navMenu === null) {\n return;\n }\n\n var menu = navMenu.querySelector('a.automation-templates');\n\n if (menu === null) {\n return;\n }\n\n menu = menu.parentNode;\n menu.dataset.forceintomoremenu = false;\n menu.querySelector('a').classList.remove('dropdown-item');\n menu.querySelector('a').classList.add('nav-link');\n menu.parentNode.removeChild(menu);\n\n // Insert the stored menus before the more menu.\n navMenu.insertBefore(menu, navMenu.children[1]);\n window.dispatchEvent(new Event('resize')); // Dispatch the resize event to create more menu.\n };\n\n const returnToFailedTab = () => {\n\n if (document.forms['pulse-automation-template'] === null) {\n return false;\n }\n\n document.forms['pulse-automation-template'].onsubmit = (e) => {\n var form = e.target;\n var invalidElement = form.querySelector('.is-invalid');\n if (invalidElement === null) {\n return true;\n }\n\n var tabid = invalidElement.parentNode.parentNode.parentNode.id;\n var hrefSelector = '[href=\"#' + tabid + '\"]';\n\n document.querySelector(hrefSelector).click();\n\n return true;\n };\n\n return true;\n };\n\n // No need.\n const updateAutoCompletionPositions = function() {\n var group = \"checkboxgroupautomation\";\n\n if (document.querySelectorAll('input[type=checkbox].' + group)\n === null || document.querySelectorAll('[data-fieldtype=\"autocomplete\"]') === null) {\n return true;\n }\n\n document.querySelectorAll('[data-fieldtype=\"autocomplete\"]').forEach((element) => {\n\n if (element === null) {\n return true;\n }\n\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach((mutation) => {\n // Console.log(mutation);\n // If(mutation.type === 'attributes') {\n var target = mutation.target;\n var overrideElement = target.querySelector('.custom-switch');\n if (overrideElement === null) {\n return;\n }\n overrideElement.parentNode.append(overrideElement);\n observer.disconnect();\n });\n });\n observer.observe(element, {attributes: true, childList: true, subtree: true});\n // Observer.disconnect();\n return true;\n });\n\n return true;\n };\n\n const moveOverRidePosition = function() {\n\n var group = \"checkboxgroupautomation\";\n\n if (document.querySelectorAll('input[type=checkbox].' + group) === null) {\n return true;\n }\n\n document.querySelectorAll('input[type=checkbox].' + group).forEach((overElement) => {\n var id = overElement.id;\n id = id.replace('id_override_', '');\n var element = document.querySelector('div#fitem_id_' + id);\n if (element === null) {\n element = document.querySelector('div#fgroup_id_' + id);\n if (element === null) {\n return true;\n }\n }\n\n var parent = overElement.parentNode;\n parent.innerHTML += '';\n\n var nodeToMove = document.createElement('div');\n nodeToMove.classList.add('custom-control', 'custom-switch');\n nodeToMove.append(parent);\n element.querySelector(\".felement\").append(nodeToMove);\n return true;\n });\n // Move the override button for autocompletion fields after the autocomplete nodes are created.\n updateAutoCompletionPositions();\n\n return true;\n };\n\n /**\n * Create a modal to display the list of instances which is overriden the template setting.\n *\n * @returns {void}\n */\n const overrideModal = function() {\n\n // Add the template reference as prefix of the instance reference.\n var templateReference = document.querySelector('#pulse-template-reference');\n var instanceReference = document.querySelector('#fitem_id_insreference .felement');\n if (templateReference && instanceReference) {\n templateReference.classList.remove('hide');\n instanceReference.prepend(templateReference);\n }\n\n const trigger = document.querySelectorAll('[data-target=\"overridemodal\"]');\n\n if (trigger === null) {\n return;\n }\n\n trigger.forEach((elem) => {\n\n elem.nextSibling.querySelector('.felement').append(elem);\n\n elem.addEventListener('click', function(e) {\n e.preventDefault();\n var element = e.target;\n var data = element.dataset;\n var instance = document.querySelector('[name=overinstance_' + data.element + ']');\n if (instance !== null) {\n var overrides = JSON.parse(instance.value);\n overrides.map((value) => {\n var path = '/mod/pulse/automation/instances/edit.php?instanceid=';\n value.url = M.cfg.wwwroot + path + value.id + '&sesskey=' + M.cfg.sesskey;\n return value;\n });\n Modal.create({\n title: Str.get_string('instanceoverrides', 'pulse'),\n body: Template.render('mod_pulse/overrides', {instances: overrides})\n }).then((modal) => {\n modal.show();\n return true;\n }).catch();\n }\n });\n });\n };\n\n const enableTitleOnSubmit = function() {\n if (document.forms['pulse-automation-template'] === null) {\n return;\n }\n document.forms['pulse-automation-template'].onsubmit =\n () => document.querySelector('[name=\"title\"]').removeAttribute(\"disabled\");\n };\n\n return {\n\n init: function() {\n returnToFailedTab();\n overrideModal();\n moveOverRidePosition();\n enableTitleOnSubmit();\n },\n\n instanceMenuLink: function() {\n var primaryNav = document.querySelector('.secondary-navigation ul.more-nav');\n moveOutMoreMenu(primaryNav);\n },\n\n };\n});\n"],"names":["define","$","Modal","Template","Str","moveOverRidePosition","group","document","querySelectorAll","forEach","overElement","id","replace","element","querySelector","parent","parentNode","innerHTML","nodeToMove","createElement","classList","add","append","observer","MutationObserver","mutations","mutation","overrideElement","target","disconnect","observe","attributes","childList","subtree","init","forms","onsubmit","e","invalidElement","hrefSelector","click","templateReference","instanceReference","remove","prepend","trigger","elem","nextSibling","addEventListener","preventDefault","data","dataset","instance","overrides","JSON","parse","value","map","url","M","cfg","wwwroot","sesskey","create","title","get_string","body","render","instances","then","modal","show","catch","overrideModal","removeAttribute","instanceMenuLink","navMenu","menu","forceintomoremenu","removeChild","insertBefore","children","window","dispatchEvent","Event","moveOutMoreMenu"],"mappings":"AAAAA,8BAA+B,CAAC,SAAU,qBAAsB,iBAAkB,aAAa,SAASC,EAAGC,MAAOC,SAAUC,WAqFlHC,qBAAuB,eAErBC,MAAQ,iCAEuD,OAA/DC,SAASC,iBAAiB,wBAA0BF,SAIxDC,SAASC,iBAAiB,wBAA0BF,OAAOG,SAASC,kBAC5DC,GAAKD,YAAYC,GACrBA,GAAKA,GAAGC,QAAQ,eAAgB,QAC5BC,QAAUN,SAASO,cAAc,gBAAkBH,OACvC,OAAZE,SAEgB,QADhBA,QAAUN,SAASO,cAAc,iBAAmBH,YAEzC,MAIXI,OAASL,YAAYM,WACzBD,OAAOE,WAAa,iDAEhBC,WAAaX,SAASY,cAAc,cACxCD,WAAWE,UAAUC,IAAI,iBAAkB,iBAC3CH,WAAWI,OAAOP,QAClBF,QAAQC,cAAc,aAAaQ,OAAOJ,aACnC,KAzDH,OADJX,SAASC,iBAAiB,iDACmD,OAAjED,SAASC,iBAAiB,oCAI1CD,SAASC,iBAAiB,mCAAmCC,SAASI,aAElD,OAAZA,eACO,MAGPU,SAAW,IAAIC,kBAAiB,SAASC,WACzCA,UAAUhB,SAASiB,eAIXC,gBADSD,SAASE,OACOd,cAAc,kBACnB,OAApBa,kBAGJA,gBAAgBX,WAAWM,OAAOK,iBAClCJ,SAASM,2BAGjBN,SAASO,QAAQjB,QAAS,CAACkB,YAAY,EAAMC,WAAW,EAAMC,SAAS,KAEhE,OAWA,SAsFR,CA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/D,cAAc,KAAKM,UAAUuB,OAAO,iBACzCkC,KAAK/D,cAAc,KAAKM,UAAUC,IAAI,YACtCwD,KAAK7D,WAAW+D,YAAYF,MAG5BD,QAAQI,aAAaH,KAAMD,QAAQK,SAAS,IAC5CC,OAAOC,cAAc,IAAIC,MAAM,cAqK3BC,CADiB9E,SAASO,cAAc"} \ No newline at end of file diff --git a/amd/build/completion.min.js.map b/amd/build/completion.min.js.map index 774cc0c..6c0af2b 100644 --- a/amd/build/completion.min.js.map +++ b/amd/build/completion.min.js.map @@ -1 +1 @@ -{"version":3,"file":"completion.min.js","sources":["../src/completion.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\r\n//\r\n// Moodle is free software: you can redistribute it and/or modify\r\n// it under the terms of the GNU General Public License as published by\r\n// the Free Software Foundation, either version 3 of the License, or\r\n// (at your option) any later version.\r\n//\r\n// Moodle is distributed in the hope that it will be useful,\r\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n// GNU General Public License for more details.\r\n//\r\n// You should have received a copy of the GNU General Public License\r\n// along with Moodle. If not, see .\r\n\r\n/**\r\n * Module javascript to place the placeholders.\r\n * Modified version of IOMAD Email template emailvars.\r\n *\r\n * @module mod_pulse/completion\r\n * @category Classes - autoloading\r\n * @copyright 2021, bdecent gmbh bdecent.de\r\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r\n */\r\n\r\ndefine(['core/fragment'], function(Fragment) {\r\n\r\n return {\r\n\r\n /**\r\n * Update completion buttons for each activity based on user role.\r\n * This will load the template using fragment.\r\n */\r\n updatecompletionbuttons: function() {\r\n var instances = document.getElementsByClassName('modtype_pulse');\r\n var modules = []; var moduleid;\r\n for (var i = 0; i < instances.length; i++) {\r\n var instance = instances[i];\r\n var id = instance.getAttribute('id');\r\n moduleid = parseInt(id.replace('module-', ''));\r\n modules.push(moduleid);\r\n }\r\n var params = {modules: JSON.stringify(modules)};\r\n if (modules.length > 0) {\r\n let completionbuttons = Fragment.loadFragment('mod_pulse', 'completionbuttons', 1, params);\r\n var approvebtn, element, referenceNode, completioncontent;\r\n completionbuttons.then((data) => {\r\n data = JSON.parse(data);\r\n for (var k in data) {\r\n approvebtn = data[k];\r\n element = document.getElementById('module-' + k);\r\n referenceNode = element.getElementsByClassName('contentwithoutlink')[0];\r\n completioncontent = document.createElement('div');\r\n completioncontent.innerHTML = approvebtn;\r\n completioncontent.classList.add('pulse-completion-btn');\r\n referenceNode.parentNode.insertBefore(completioncontent, referenceNode.nextSibling);\r\n }\r\n return true;\r\n }).fail();\r\n }\r\n },\r\n\r\n /**\r\n * If the page is course view page then call the completion buttons to insert.\r\n */\r\n init: function() {\r\n if (document.body.classList.contains('path-course-view')) {\r\n this.updatecompletionbuttons();\r\n }\r\n },\r\n\r\n };\r\n});\r\n"],"names":["define","Fragment","updatecompletionbuttons","moduleid","instances","document","getElementsByClassName","modules","i","length","id","getAttribute","parseInt","replace","push","params","JSON","stringify","approvebtn","element","referenceNode","completioncontent","loadFragment","then","data","k","parse","getElementById","createElement","innerHTML","classList","add","parentNode","insertBefore","nextSibling","fail","init","body","contains"],"mappings":";;;;;;;;;AAyBAA,8BAAO,CAAC,kBAAkB,SAASC,gBAExB,CAMHC,wBAAyB,mBAECC,SADlBC,UAAYC,SAASC,uBAAuB,iBAC5CC,QAAU,GACLC,EAAI,EAAGA,EAAIJ,UAAUK,OAAQD,IAAK,KAEnCE,GADWN,UAAUI,GACPG,aAAa,MAC/BR,SAAWS,SAASF,GAAGG,QAAQ,UAAW,KAC1CN,QAAQO,KAAKX,cAEbY,OAAS,CAACR,QAAUS,KAAKC,UAAUV,aACnCA,QAAQE,OAAS,EAAG,KAEhBS,WAAYC,QAASC,cAAeC,kBADhBpB,SAASqB,aAAa,YAAa,oBAAqB,EAAGP,QAEjEQ,MAAMC,WAEf,IAAIC,KADTD,KAAOR,KAAKU,MAAMF,MAEdN,WAAaM,KAAKC,GAClBN,QAAUd,SAASsB,eAAe,UAAYF,GAC9CL,cAAgBD,QAAQb,uBAAuB,sBAAsB,IACrEe,kBAAoBhB,SAASuB,cAAc,QACzBC,UAAYX,WAC9BG,kBAAkBS,UAAUC,IAAI,wBAChCX,cAAcY,WAAWC,aAAaZ,kBAAmBD,cAAcc,oBAEpE,KACRC,SAOXC,KAAM,WACE/B,SAASgC,KAAKP,UAAUQ,SAAS,0BAC5BpC"} \ No newline at end of file +{"version":3,"file":"completion.min.js","sources":["../src/completion.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 javascript to place the placeholders.\n * Modified version of IOMAD Email template emailvars.\n *\n * @module mod_pulse/completion\n * @category Classes - autoloading\n * @copyright 2021, bdecent gmbh bdecent.de\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['core/fragment'], function(Fragment) {\n\n return {\n\n /**\n * Update completion buttons for each activity based on user role.\n * This will load the template using fragment.\n */\n updatecompletionbuttons: function() {\n var instances = document.getElementsByClassName('modtype_pulse');\n var modules = []; var moduleid;\n for (var i = 0; i < instances.length; i++) {\n var instance = instances[i];\n var id = instance.getAttribute('id');\n moduleid = parseInt(id.replace('module-', ''));\n modules.push(moduleid);\n }\n var params = {modules: JSON.stringify(modules)};\n if (modules.length > 0) {\n let completionbuttons = Fragment.loadFragment('mod_pulse', 'completionbuttons', 1, params);\n var approvebtn, element, referenceNode, completioncontent;\n completionbuttons.then((data) => {\n data = JSON.parse(data);\n for (var k in data) {\n approvebtn = data[k];\n element = document.getElementById('module-' + k);\n referenceNode = element.getElementsByClassName('contentwithoutlink')[0];\n completioncontent = document.createElement('div');\n completioncontent.innerHTML = approvebtn;\n completioncontent.classList.add('pulse-completion-btn');\n referenceNode.parentNode.insertBefore(completioncontent, referenceNode.nextSibling);\n }\n return true;\n }).fail();\n }\n },\n\n /**\n * If the page is course view page then call the completion buttons to insert.\n */\n init: function() {\n if (document.body.classList.contains('path-course-view')) {\n this.updatecompletionbuttons();\n }\n },\n\n };\n});\n"],"names":["define","Fragment","updatecompletionbuttons","moduleid","instances","document","getElementsByClassName","modules","i","length","id","getAttribute","parseInt","replace","push","params","JSON","stringify","approvebtn","element","referenceNode","completioncontent","loadFragment","then","data","k","parse","getElementById","createElement","innerHTML","classList","add","parentNode","insertBefore","nextSibling","fail","init","body","contains"],"mappings":";;;;;;;;;AAyBAA,8BAAO,CAAC,kBAAkB,SAASC,gBAExB,CAMHC,wBAAyB,mBAECC,SADlBC,UAAYC,SAASC,uBAAuB,iBAC5CC,QAAU,GACLC,EAAI,EAAGA,EAAIJ,UAAUK,OAAQD,IAAK,KAEnCE,GADWN,UAAUI,GACPG,aAAa,MAC/BR,SAAWS,SAASF,GAAGG,QAAQ,UAAW,KAC1CN,QAAQO,KAAKX,cAEbY,OAAS,CAACR,QAAUS,KAAKC,UAAUV,aACnCA,QAAQE,OAAS,EAAG,KAEhBS,WAAYC,QAASC,cAAeC,kBADhBpB,SAASqB,aAAa,YAAa,oBAAqB,EAAGP,QAEjEQ,MAAMC,WAEf,IAAIC,KADTD,KAAOR,KAAKU,MAAMF,MAEdN,WAAaM,KAAKC,GAClBN,QAAUd,SAASsB,eAAe,UAAYF,GAC9CL,cAAgBD,QAAQb,uBAAuB,sBAAsB,IACrEe,kBAAoBhB,SAASuB,cAAc,QACzBC,UAAYX,WAC9BG,kBAAkBS,UAAUC,IAAI,wBAChCX,cAAcY,WAAWC,aAAaZ,kBAAmBD,cAAcc,oBAEpE,KACRC,SAOXC,KAAM,WACE/B,SAASgC,KAAKP,UAAUQ,SAAS,0BAC5BpC"} \ No newline at end of file diff --git a/amd/build/events.min.js.map b/amd/build/events.min.js.map index 0073203..42c6014 100644 --- a/amd/build/events.min.js.map +++ b/amd/build/events.min.js.map @@ -1 +1 @@ -{"version":3,"file":"events.min.js","sources":["../src/events.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\r\n//\r\n// Moodle is free software: you can redistribute it and/or modify\r\n// it under the terms of the GNU General Public License as published by\r\n// the Free Software Foundation, either version 3 of the License, or\r\n// (at your option) any later version.\r\n//\r\n// Moodle is distributed in the hope that it will be useful,\r\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n// GNU General Public License for more details.\r\n//\r\n// You should have received a copy of the GNU General Public License\r\n// along with Moodle. If not, see .\r\n\r\n/**\r\n * Contain the events the data privacy tool can fire.\r\n *\r\n * @module mod_pulse/events\r\n * @category Classes - autoloading\r\n * @copyright 2021, bdecent gmbh bdecent.de\r\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r\n */\r\n\r\n define([], function() {\r\n return {\r\n save: 'mod_pulse-preset:save',\r\n customize: 'mod_pulse-preset:customize',\r\n };\r\n});\r\n"],"names":["define","save","customize"],"mappings":";;;;;;;;AAwBCA,0BAAO,IAAI,iBACD,CACHC,KAAM,wBACNC,UAAW"} \ No newline at end of file +{"version":3,"file":"events.min.js","sources":["../src/events.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 * Contain the events the data privacy tool can fire.\n *\n * @module mod_pulse/events\n * @category Classes - autoloading\n * @copyright 2021, bdecent gmbh bdecent.de\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n define([], function() {\n return {\n save: 'mod_pulse-preset:save',\n customize: 'mod_pulse-preset:customize',\n };\n});\n"],"names":["define","save","customize"],"mappings":";;;;;;;;AAwBCA,0BAAO,IAAI,iBACD,CACHC,KAAM,wBACNC,UAAW"} \ No newline at end of file diff --git a/amd/build/modal_preset.min.js.map b/amd/build/modal_preset.min.js.map index d27113b..a9bf78a 100644 --- a/amd/build/modal_preset.min.js.map +++ b/amd/build/modal_preset.min.js.map @@ -1 +1 @@ -{"version":3,"file":"modal_preset.min.js","sources":["../src/modal_preset.js"],"sourcesContent":["define(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/modal', 'core/modal_registry', 'mod_pulse/events'],\r\n function($, Notification, CustomEvents, Modal, ModalRegistry, PresetEvents) {\r\n\r\n var registered = false;\r\n var SELECTORS = {\r\n SAVE_BUTTON: '[data-action=\"save\"]',\r\n CUSTOMIZE_BUTTON: '[data-action=\"customize\"]',\r\n CANCEL_BUTTON: '[data-action=\"cancel\"]',\r\n };\r\n\r\n /**\r\n * Constructor for the Modal.\r\n *\r\n * @param {object} root The root jQuery element for the modal\r\n */\r\n var ModalPreset = function(root) {\r\n Modal.call(this, root);\r\n\r\n if (!this.getFooter().find(SELECTORS.SAVE_BUTTON).length) {\r\n Notification.exception({message: 'No \"Apply and save\" button found'});\r\n }\r\n\r\n if (!this.getFooter().find(SELECTORS.CUSTOMIZE_BUTTON).length) {\r\n Notification.exception({message: 'No \"Apply and customize\" button found'});\r\n }\r\n\r\n if (!this.getFooter().find(SELECTORS.CANCEL_BUTTON).length) {\r\n Notification.exception({message: 'No cancel button found'});\r\n }\r\n };\r\n\r\n ModalPreset.TYPE = 'PresetModal';\r\n ModalPreset.prototype = Object.create(Modal.prototype);\r\n ModalPreset.prototype.constructor = ModalPreset;\r\n ModalPreset.prototype.formData = '';\r\n\r\n /**\r\n * Set up all of the event handling for the modal.\r\n *\r\n * @method registerEventListeners\r\n */\r\n ModalPreset.prototype.registerEventListeners = function() {\r\n // Apply parent event listeners.\r\n Modal.prototype.registerEventListeners.call(this);\r\n\r\n this.getModal().on(CustomEvents.events.activate, SELECTORS.SAVE_BUTTON, function(event, data) {\r\n // Load the backupfile.\r\n document.querySelectorAll('.preset-config-params form.mform').forEach(form => {\r\n form.importmethod.value = 'save';\r\n form.addEventListener('submit', function(e) {\r\n e.preventDefault();\r\n });\r\n });\r\n\r\n if (document.querySelectorAll('.preset-config-params [data-fieldtype=\"submit\"] input').length != 0) {\r\n document.querySelectorAll('.preset-config-params [data-fieldtype=\"submit\"] input')[0].click();\r\n }\r\n\r\n var approveEvent = $.Event(PresetEvents.save);\r\n this.getRoot().trigger(approveEvent, this);\r\n\r\n if (!approveEvent.isDefaultPrevented()) {\r\n this.destroy();\r\n data.originalEvent.preventDefault();\r\n }\r\n event.preventDefault();\r\n }.bind(this));\r\n\r\n\r\n this.getModal().on(CustomEvents.events.activate, SELECTORS.CUSTOMIZE_BUTTON, function(event, data) {\r\n // Add your logic for when the login button is clicked. This could include the form validation,\r\n document.querySelectorAll('.preset-config-params form.mform').forEach(form => {\r\n form.importmethod.value = 'customize';\r\n });\r\n\r\n var customizeEvent = $.Event(PresetEvents.customize);\r\n this.getRoot().trigger(customizeEvent, this);\r\n\r\n if (!customizeEvent.isDefaultPrevented()) {\r\n data.originalEvent.preventDefault();\r\n }\r\n event.preventDefault();\r\n\r\n }.bind(this));\r\n\r\n this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, function() {\r\n this.destroy();\r\n }.bind(this));\r\n };\r\n\r\n // Automatically register with the modal registry the first time this module is imported so that you can create modals\r\n // of this type using the modal factory.\r\n if (!registered) {\r\n ModalRegistry.register(ModalPreset.TYPE, ModalPreset, 'mod_pulse/modal_preset');\r\n registered = true;\r\n }\r\n\r\n return ModalPreset;\r\n});\r\n"],"names":["define","$","Notification","CustomEvents","Modal","ModalRegistry","PresetEvents","registered","SELECTORS","ModalPreset","root","call","this","getFooter","find","length","exception","message","TYPE","prototype","Object","create","constructor","formData","registerEventListeners","getModal","on","events","activate","event","data","document","querySelectorAll","forEach","form","importmethod","value","addEventListener","e","preventDefault","click","approveEvent","Event","save","getRoot","trigger","isDefaultPrevented","destroy","originalEvent","bind","customizeEvent","customize","register"],"mappings":"AAAAA,gCAAO,CAAC,SAAU,oBAAqB,iCAAkC,aAAc,sBAAuB,qBACtG,SAASC,EAAGC,aAAcC,aAAcC,MAAOC,cAAeC,kBAE9DC,YAAa,EACbC,sBACa,uBADbA,2BAEkB,4BAFlBA,wBAGe,yBAQfC,YAAc,SAASC,MACvBN,MAAMO,KAAKC,KAAMF,MAEZE,KAAKC,YAAYC,KAAKN,uBAAuBO,QAC9Cb,aAAac,UAAU,CAACC,QAAS,qCAGhCL,KAAKC,YAAYC,KAAKN,4BAA4BO,QACnDb,aAAac,UAAU,CAACC,QAAS,0CAGhCL,KAAKC,YAAYC,KAAKN,yBAAyBO,QAChDb,aAAac,UAAU,CAACC,QAAS,mCAIzCR,YAAYS,KAAO,eACnBT,YAAYU,UAAYC,OAAOC,OAAOjB,MAAMe,YACtBG,YAAcb,YACpCA,YAAYU,UAAUI,SAAW,GAOjCd,YAAYU,UAAUK,uBAAyB,WAE3CpB,MAAMe,UAAUK,uBAAuBb,KAAKC,WAEvCa,WAAWC,GAAGvB,aAAawB,OAAOC,SAAUpB,sBAAuB,SAASqB,MAAOC,MAEpFC,SAASC,iBAAiB,oCAAoCC,SAAQC,OAClEA,KAAKC,aAAaC,MAAQ,OAC1BF,KAAKG,iBAAiB,UAAU,SAASC,GACrCA,EAAEC,uBAIuF,GAA7FR,SAASC,iBAAiB,yDAAyDjB,QACnFgB,SAASC,iBAAiB,yDAAyD,GAAGQ,YAGtFC,aAAexC,EAAEyC,MAAMpC,aAAaqC,WACnCC,UAAUC,QAAQJ,aAAc7B,MAEhC6B,aAAaK,4BACTC,UACLjB,KAAKkB,cAAcT,kBAEvBV,MAAMU,kBACRU,KAAKrC,YAGFa,WAAWC,GAAGvB,aAAawB,OAAOC,SAAUpB,2BAA4B,SAASqB,MAAOC,MAEzFC,SAASC,iBAAiB,oCAAoCC,SAAQC,OAClEA,KAAKC,aAAaC,MAAQ,mBAG1Bc,eAAiBjD,EAAEyC,MAAMpC,aAAa6C,gBACrCP,UAAUC,QAAQK,eAAgBtC,MAElCsC,eAAeJ,sBAChBhB,KAAKkB,cAAcT,iBAEvBV,MAAMU,kBAERU,KAAKrC,YAEFa,WAAWC,GAAGvB,aAAawB,OAAOC,SAAUpB,wBAAyB,gBACjEuC,WACPE,KAAKrC,QAKNL,aACDF,cAAc+C,SAAS3C,YAAYS,KAAMT,YAAa,0BACtDF,YAAa,GAGVE"} \ No newline at end of file +{"version":3,"file":"modal_preset.min.js","sources":["../src/modal_preset.js"],"sourcesContent":["define(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/modal', 'core/modal_registry', 'mod_pulse/events'],\n function($, Notification, CustomEvents, Modal, ModalRegistry, PresetEvents) {\n\n var registered = false;\n var SELECTORS = {\n SAVE_BUTTON: '[data-action=\"save\"]',\n CUSTOMIZE_BUTTON: '[data-action=\"customize\"]',\n CANCEL_BUTTON: '[data-action=\"cancel\"]',\n };\n\n /**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n */\n var ModalPreset = function(root) {\n Modal.call(this, root);\n\n if (!this.getFooter().find(SELECTORS.SAVE_BUTTON).length) {\n Notification.exception({message: 'No \"Apply and save\" button found'});\n }\n\n if (!this.getFooter().find(SELECTORS.CUSTOMIZE_BUTTON).length) {\n Notification.exception({message: 'No \"Apply and customize\" button found'});\n }\n\n if (!this.getFooter().find(SELECTORS.CANCEL_BUTTON).length) {\n Notification.exception({message: 'No cancel button found'});\n }\n };\n\n ModalPreset.TYPE = 'PresetModal';\n ModalPreset.prototype = Object.create(Modal.prototype);\n ModalPreset.prototype.constructor = ModalPreset;\n ModalPreset.prototype.formData = '';\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n ModalPreset.prototype.registerEventListeners = function() {\n // Apply parent event listeners.\n Modal.prototype.registerEventListeners.call(this);\n\n this.getModal().on(CustomEvents.events.activate, SELECTORS.SAVE_BUTTON, function(event, data) {\n // Load the backupfile.\n document.querySelectorAll('.preset-config-params form.mform').forEach(form => {\n form.importmethod.value = 'save';\n form.addEventListener('submit', function(e) {\n e.preventDefault();\n });\n });\n\n if (document.querySelectorAll('.preset-config-params [data-fieldtype=\"submit\"] input').length != 0) {\n document.querySelectorAll('.preset-config-params [data-fieldtype=\"submit\"] input')[0].click();\n }\n\n var approveEvent = $.Event(PresetEvents.save);\n this.getRoot().trigger(approveEvent, this);\n\n if (!approveEvent.isDefaultPrevented()) {\n this.destroy();\n data.originalEvent.preventDefault();\n }\n event.preventDefault();\n }.bind(this));\n\n\n this.getModal().on(CustomEvents.events.activate, SELECTORS.CUSTOMIZE_BUTTON, function(event, data) {\n // Add your logic for when the login button is clicked. This could include the form validation,\n document.querySelectorAll('.preset-config-params form.mform').forEach(form => {\n form.importmethod.value = 'customize';\n });\n\n var customizeEvent = $.Event(PresetEvents.customize);\n this.getRoot().trigger(customizeEvent, this);\n\n if (!customizeEvent.isDefaultPrevented()) {\n data.originalEvent.preventDefault();\n }\n event.preventDefault();\n\n }.bind(this));\n\n this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, function() {\n this.destroy();\n }.bind(this));\n };\n\n // Automatically register with the modal registry the first time this module is imported so that you can create modals\n // of this type using the modal factory.\n if (!registered) {\n ModalRegistry.register(ModalPreset.TYPE, ModalPreset, 'mod_pulse/modal_preset');\n registered = true;\n }\n\n return ModalPreset;\n});\n"],"names":["define","$","Notification","CustomEvents","Modal","ModalRegistry","PresetEvents","registered","SELECTORS","ModalPreset","root","call","this","getFooter","find","length","exception","message","TYPE","prototype","Object","create","constructor","formData","registerEventListeners","getModal","on","events","activate","event","data","document","querySelectorAll","forEach","form","importmethod","value","addEventListener","e","preventDefault","click","approveEvent","Event","save","getRoot","trigger","isDefaultPrevented","destroy","originalEvent","bind","customizeEvent","customize","register"],"mappings":"AAAAA,gCAAO,CAAC,SAAU,oBAAqB,iCAAkC,aAAc,sBAAuB,qBACtG,SAASC,EAAGC,aAAcC,aAAcC,MAAOC,cAAeC,kBAE9DC,YAAa,EACbC,sBACa,uBADbA,2BAEkB,4BAFlBA,wBAGe,yBAQfC,YAAc,SAASC,MACvBN,MAAMO,KAAKC,KAAMF,MAEZE,KAAKC,YAAYC,KAAKN,uBAAuBO,QAC9Cb,aAAac,UAAU,CAACC,QAAS,qCAGhCL,KAAKC,YAAYC,KAAKN,4BAA4BO,QACnDb,aAAac,UAAU,CAACC,QAAS,0CAGhCL,KAAKC,YAAYC,KAAKN,yBAAyBO,QAChDb,aAAac,UAAU,CAACC,QAAS,mCAIzCR,YAAYS,KAAO,eACnBT,YAAYU,UAAYC,OAAOC,OAAOjB,MAAMe,YACtBG,YAAcb,YACpCA,YAAYU,UAAUI,SAAW,GAOjCd,YAAYU,UAAUK,uBAAyB,WAE3CpB,MAAMe,UAAUK,uBAAuBb,KAAKC,WAEvCa,WAAWC,GAAGvB,aAAawB,OAAOC,SAAUpB,sBAAuB,SAASqB,MAAOC,MAEpFC,SAASC,iBAAiB,oCAAoCC,SAAQC,OAClEA,KAAKC,aAAaC,MAAQ,OAC1BF,KAAKG,iBAAiB,UAAU,SAASC,GACrCA,EAAEC,uBAIuF,GAA7FR,SAASC,iBAAiB,yDAAyDjB,QACnFgB,SAASC,iBAAiB,yDAAyD,GAAGQ,YAGtFC,aAAexC,EAAEyC,MAAMpC,aAAaqC,WACnCC,UAAUC,QAAQJ,aAAc7B,MAEhC6B,aAAaK,4BACTC,UACLjB,KAAKkB,cAAcT,kBAEvBV,MAAMU,kBACRU,KAAKrC,YAGFa,WAAWC,GAAGvB,aAAawB,OAAOC,SAAUpB,2BAA4B,SAASqB,MAAOC,MAEzFC,SAASC,iBAAiB,oCAAoCC,SAAQC,OAClEA,KAAKC,aAAaC,MAAQ,mBAG1Bc,eAAiBjD,EAAEyC,MAAMpC,aAAa6C,gBACrCP,UAAUC,QAAQK,eAAgBtC,MAElCsC,eAAeJ,sBAChBhB,KAAKkB,cAAcT,iBAEvBV,MAAMU,kBAERU,KAAKrC,YAEFa,WAAWC,GAAGvB,aAAawB,OAAOC,SAAUpB,wBAAyB,gBACjEuC,WACPE,KAAKrC,QAKNL,aACDF,cAAc+C,SAAS3C,YAAYS,KAAMT,YAAa,0BACtDF,YAAa,GAGVE"} \ No newline at end of file diff --git a/amd/build/module.min.js b/amd/build/module.min.js index abd48fa..3edffe8 100644 --- a/amd/build/module.min.js +++ b/amd/build/module.min.js @@ -7,6 +7,6 @@ * @copyright 2021, bdecent gmbh bdecent.de * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("mod_pulse/module",["core_editor/events"],(function(events){var tinyEditor=!1;return{init:function(){for(var module=this,templatevars=document.getElementsByClassName("fitem_id_templatevars_editor"),l=0;l{elem.addEventListener("click",(function(e){var EditorInput=e.currentTarget.querySelector('[id*="_editoreditable"]');module.insertCaretActive(EditorInput)}))}));var targetNode=document.querySelector("textarea[id$=_editor]");null!==targetNode&&new MutationObserver((function(){"none"==targetNode.style.display&&setTimeout(initIframeListeners,100)})).observe(targetNode,{attributes:!0,childList:!0});const initIframeListeners=()=>{var iframes=document.querySelectorAll('[data-fieldtype="editor"] iframe');if(null===iframes||!iframes.length)return!1;iframes.forEach((iframe=>{iframe.contentDocument.addEventListener("click",(function(e){var currentFrame=e.target;iframes.forEach((frame=>{var frameElem=frame.contentDocument.querySelector(".insertatcaretactive");null!=frameElem&&frameElem.classList.remove("insertatcaretactive")}));var contentBody=currentFrame.querySelector("body");if(null!==contentBody){contentBody.classList.add("insertatcaretactive");var id=contentBody.dataset.id,editor=window.tinyMCE.get(id);tinyEditor=editor}}))}))};for(var clickforword=document.getElementsByClassName("clickforword"),i=0;i{const span=document.createElement("span");span.classList="badge badge-info pulse-completion-roles",node.after(span),span.appendChild(node)}))}},insertCaretActive:function(EditorInput){if(null!==EditorInput){tinyEditor=!1;for(var caret=document.getElementsByClassName("insertatcaretactive"),j=0;j3===node.nodeType&&node.textContent.trim().length>1))},isSelectionInsideDiv:div=>{const selection=window.getSelection();if(0===selection.rangeCount)return!1;const startNode=selection.getRangeAt(0).startContainer,endNode=selection.getRangeAt(0).endContainer;return div.contains(startNode)&&div.contains(endNode)},insertAtCaret:function(myValue){for(var sel,range,caretelements=document.getElementsByClassName("insertatcaretactive"),n=0;n{elem.addEventListener("click",(function(e){var EditorInput=e.currentTarget.querySelector('[id*="_editoreditable"]');module.insertCaretActive(EditorInput)}))}));var targetNode=document.querySelector("textarea[id$=_editor]");null!==targetNode&&new MutationObserver((function(){"none"==targetNode.style.display&&setTimeout(initIframeListeners,100)})).observe(targetNode,{attributes:!0,childList:!0});const initIframeListeners=()=>{var iframes=document.querySelectorAll('[data-fieldtype="editor"] iframe');return!(null===iframes||!iframes.length)&&(iframes.forEach((iframe=>{iframe.contentDocument.addEventListener("click",(function(e){var currentFrame=e.target;iframes.forEach((frame=>{var frameElem=frame.contentDocument.querySelector(".insertatcaretactive");null!==frameElem&&frameElem.classList.remove("insertatcaretactive")}));var contentBody=currentFrame.querySelector("body");null!==contentBody&&contentBody.classList.add("insertatcaretactive")}))})),!0)};for(var clickforword=document.getElementsByClassName("clickforword"),i=0;i{if(null!==frame.contentDocument.querySelector(".insertatcaretactive")){var contentBody=frame.contentDocument.querySelector("body");if(null!==contentBody){contentBody.classList.add("insertatcaretactive");var id=contentBody.dataset.id,editor=window.tinyMCE.get(id);tinyEditor=editor}}return!1})),tinyEditor?tinyEditor.selection.setContent(content):module.insertAtCaret(content),!0)}));if(null!==document.getElementById("page-mod-pulse-mod")&&null!==document.getElementById("page-mod-pulse-mod").querySelector("#fgroup_id_completionrequireapproval [data-fieldtype='autocomplete']")){this.getAllTextNodes(document.getElementById("page-mod-pulse-mod").querySelector("#fgroup_id_completionrequireapproval [data-fieldtype='autocomplete']")).forEach((node=>{const span=document.createElement("span");span.classList="badge badge-info pulse-completion-roles",node.after(span),span.appendChild(node)}))}},insertCaretActive:function(EditorInput){if(null!==EditorInput){for(var caret=document.getElementsByClassName("insertatcaretactive"),j=0;j3===node.nodeType&&node.textContent.trim().length>1))},isSelectionInsideDiv:div=>{const selection=window.getSelection();if(0===selection.rangeCount)return!1;const startNode=selection.getRangeAt(0).startContainer,endNode=selection.getRangeAt(0).endContainer;return div.contains(startNode)&&div.contains(endNode)},insertAtCaret:function(myValue){for(var sel,range,caretelements=document.getElementsByClassName("insertatcaretactive"),n=0;n.\r\n\r\n/**\r\n * Module javascript to place the placeholders.\r\n * Modified version of IOMAD Email template emailvars.\r\n *\r\n * @module mod_pulse/module\r\n * @category Classes - autoloading\r\n * @copyright 2021, bdecent gmbh bdecent.de\r\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r\n */\r\n\r\ndefine(['core_editor/events'], function(events) {\r\n\r\n var tinyEditor = false;\r\n\r\n return {\r\n /**\r\n * Setup the classes to editors works with placeholders.\r\n */\r\n init: function() {\r\n var module = this;\r\n\r\n var templatevars = document.getElementsByClassName(\"fitem_id_templatevars_editor\");\r\n for (var l = 0; l < templatevars.length; l++) {\r\n templatevars[l].addEventListener('click', function() {\r\n var EditorInput = document.getElementById('id_pulse_content_editoreditable');\r\n if (EditorInput !== null) {\r\n module.insertCaretActive(EditorInput);\r\n }\r\n });\r\n }\r\n\r\n var notificationheader = document.getElementById('admin-notificationheader');\r\n if (notificationheader !== null) {\r\n notificationheader.addEventListener('click', function() {\r\n var EditorInput = document.getElementById('id_s_mod_pulse_notificationheadereditable');\r\n module.insertCaretActive(EditorInput);\r\n });\r\n }\r\n\r\n var notificationfooter = document.getElementById('admin-notificationfooter');\r\n if (notificationfooter !== null) {\r\n notificationfooter.addEventListener('click', function() {\r\n var EditorInput = document.getElementById('id_s_mod_pulse_notificationfootereditable');\r\n module.insertCaretActive(EditorInput);\r\n });\r\n }\r\n\r\n var templatevars = document.getElementsByClassName(\"fitem_id_templatevars_editor\");\r\n if (templatevars) {\r\n templatevars.forEach((elem) => {\r\n elem.addEventListener('click', function(e) {\r\n var target = e.currentTarget;\r\n var EditorInput = target.querySelector('[id*=\"_editoreditable\"]');\r\n module.insertCaretActive(EditorInput);\r\n });\r\n })\r\n }\r\n\r\n // console.log(window.tinyMCE.get());\r\n var targetNode = document.querySelector('textarea[id$=_editor]');\r\n if (targetNode !== null) {\r\n var observer = new MutationObserver(function() {\r\n if (targetNode.style.display == 'none') {\r\n setTimeout(initIframeListeners, 100);\r\n }\r\n });\r\n observer.observe(targetNode, { attributes: true, childList: true });\r\n }\r\n\r\n const initIframeListeners = () => {\r\n\r\n var iframes = document.querySelectorAll('[data-fieldtype=\"editor\"] iframe');\r\n if (iframes === null || !iframes.length) {\r\n return false;\r\n }\r\n\r\n iframes.forEach((iframe) => {\r\n iframe.contentDocument.addEventListener('click', function(e) {\r\n\r\n var currentFrame = e.target;\r\n iframes.forEach((frame) => {\r\n var frameElem = frame.contentDocument.querySelector(\".insertatcaretactive\");\r\n if (frameElem != null) {\r\n frameElem.classList.remove(\"insertatcaretactive\");\r\n }\r\n });\r\n\r\n var contentBody = currentFrame.querySelector('body');\r\n if (contentBody !== null) {\r\n contentBody.classList.add(\"insertatcaretactive\");\r\n var id = contentBody.dataset.id;\r\n var editor = window.tinyMCE.get(id);\r\n tinyEditor = editor;\r\n }\r\n });\r\n });\r\n }\r\n\r\n\r\n var clickforword = document.getElementsByClassName('clickforword');\r\n for (var i = 0; i < clickforword.length; i++) {\r\n clickforword[i].addEventListener('click', function(e) {\r\n e.preventDefault(); // To prevent the default behaviour of a tag.\r\n\r\n var content = \"{\" + this.getAttribute('data-text') + \"}\";\r\n if (tinyEditor) {\r\n tinyEditor.selection.setContent(content);\r\n } else {\r\n module.insertAtCaret(content);\r\n }\r\n });\r\n }\r\n\r\n // Make selected roles as badges in module edit form page.\r\n if (document.getElementById('page-mod-pulse-mod') !== null && document.getElementById('page-mod-pulse-mod')\r\n .querySelector(\"#fgroup_id_completionrequireapproval [data-fieldtype='autocomplete']\") !== null) {\r\n const textNodes = this.getAllTextNodes(\r\n document.getElementById('page-mod-pulse-mod')\r\n .querySelector(\"#fgroup_id_completionrequireapproval [data-fieldtype='autocomplete']\")\r\n );\r\n textNodes.forEach(node => {\r\n const span = document.createElement('span');\r\n span.classList = 'badge badge-info pulse-completion-roles';\r\n node.after(span);\r\n span.appendChild(node);\r\n });\r\n }\r\n },\r\n\r\n insertCaretActive: function(EditorInput) {\r\n if (EditorInput === null) {\r\n return;\r\n }\r\n tinyEditor = false;\r\n var caret = document.getElementsByClassName(\"insertatcaretactive\");\r\n for (var j = 0; j < caret.length; j++) {\r\n caret[j].classList.remove(\"insertatcaretactive\");\r\n }\r\n EditorInput.classList.add(\"insertatcaretactive\");\r\n },\r\n\r\n /**\r\n * Filter text from node.\r\n * @param {string} element\r\n * @returns {array} list of childNodes.\r\n */\r\n getAllTextNodes: function(element) {\r\n return Array.from(element.childNodes)\r\n .filter(node => node.nodeType === 3 && node.textContent.trim().length > 1);\r\n },\r\n\r\n /**\r\n * Find the selection is inside the editor\r\n *\r\n * @param {string} div\r\n * @returns\r\n */\r\n isSelectionInsideDiv: (div) => {\r\n const selection = window.getSelection();\r\n if (selection.rangeCount === 0) {\r\n return false;\r\n }\r\n\r\n // Get the start and end nodes of the selection.\r\n const startNode = selection.getRangeAt(0).startContainer;\r\n const endNode = selection.getRangeAt(0).endContainer;\r\n\r\n // Check if the start and end nodes are both descendants of the editor div.\r\n return div.contains(startNode) && div.contains(endNode);\r\n },\r\n\r\n /**\r\n * Insert the placeholder in selected caret place.\r\n * @param {string} myValue\r\n */\r\n insertAtCaret: function(myValue) {\r\n var caretelements = document.getElementsByClassName(\"insertatcaretactive\");\r\n var sel, range;\r\n for (var n = 0; n < caretelements.length; n++) {\r\n var thiselem = caretelements[n];\r\n\r\n if (typeof thiselem.value === 'undefined' && window.getSelection && this.isSelectionInsideDiv(thiselem)) {\r\n sel = window.getSelection();\r\n if (sel.getRangeAt && sel.rangeCount) {\r\n range = sel.getRangeAt(0);\r\n range.deleteContents();\r\n range.insertNode(document.createTextNode(myValue));\r\n\r\n for (let position = 0; position != (myValue.length + 1); position++) {\r\n sel.modify(\"move\", \"right\", \"character\");\r\n }\r\n }\r\n } else if (typeof thiselem.value === 'undefined' && document.selection && document.selection.createRange) {\r\n range = document.selection.createRange();\r\n range.text = myValue;\r\n }\r\n\r\n if (typeof thiselem.value !== 'undefined') {\r\n if (document.selection) {\r\n // For browsers like Internet Explorer.\r\n thiselem.focus();\r\n sel = document.selection.createRange();\r\n sel.text = myValue;\r\n thiselem.focus();\r\n } else if (thiselem.selectionStart || thiselem.selectionStart == '0') {\r\n // For browsers like Firefox and Webkit based.\r\n var startPos = thiselem.selectionStart;\r\n var endPos = thiselem.selectionEnd;\r\n thiselem.value = thiselem.value.substring(0, startPos)\r\n + myValue + thiselem.value.substring(endPos, thiselem.value.length);\r\n thiselem.focus();\r\n thiselem.selectionStart = startPos + myValue.length;\r\n thiselem.selectionEnd = startPos + myValue.length;\r\n thiselem.focus();\r\n } else {\r\n thiselem.value += myValue;\r\n thiselem.focus();\r\n }\r\n }\r\n }\r\n },\r\n };\r\n});\r\n"],"names":["define","events","tinyEditor","init","module","this","templatevars","document","getElementsByClassName","l","length","addEventListener","EditorInput","getElementById","insertCaretActive","notificationheader","notificationfooter","forEach","elem","e","currentTarget","querySelector","targetNode","MutationObserver","style","display","setTimeout","initIframeListeners","observe","attributes","childList","iframes","querySelectorAll","iframe","contentDocument","currentFrame","target","frame","frameElem","classList","remove","contentBody","add","id","dataset","editor","window","tinyMCE","get","clickforword","i","preventDefault","content","getAttribute","selection","setContent","insertAtCaret","getAllTextNodes","node","span","createElement","after","appendChild","caret","j","element","Array","from","childNodes","filter","nodeType","textContent","trim","isSelectionInsideDiv","div","getSelection","rangeCount","startNode","getRangeAt","startContainer","endNode","endContainer","contains","myValue","sel","range","caretelements","n","thiselem","value","deleteContents","insertNode","createTextNode","position","modify","createRange","text","focus","selectionStart","startPos","endPos","selectionEnd","substring"],"mappings":";;;;;;;;;AAyBAA,0BAAO,CAAC,uBAAuB,SAASC,YAEhCC,YAAa,QAEV,CAIHC,KAAM,mBACEC,OAASC,KAETC,aAAeC,SAASC,uBAAuB,gCAC1CC,EAAI,EAAGA,EAAIH,aAAaI,OAAQD,IACrCH,aAAaG,GAAGE,iBAAiB,SAAS,eAClCC,YAAcL,SAASM,eAAe,mCACtB,OAAhBD,aACAR,OAAOU,kBAAkBF,oBAKjCG,mBAAqBR,SAASM,eAAe,4BACtB,OAAvBE,oBACAA,mBAAmBJ,iBAAiB,SAAS,eACrCC,YAAcL,SAASM,eAAe,6CAC1CT,OAAOU,kBAAkBF,oBAI7BI,mBAAqBT,SAASM,eAAe,4BACtB,OAAvBG,oBACAA,mBAAmBL,iBAAiB,SAAS,eACrCC,YAAcL,SAASM,eAAe,6CAC1CT,OAAOU,kBAAkBF,iBAI7BN,aAAeC,SAASC,uBAAuB,kCAE/CF,aAAaW,SAASC,OAClBA,KAAKP,iBAAiB,SAAS,SAASQ,OAEhCP,YADSO,EAAEC,cACWC,cAAc,2BACxCjB,OAAOU,kBAAkBF,uBAMjCU,WAAaf,SAASc,cAAc,yBACrB,OAAfC,YACe,IAAIC,kBAAiB,WACA,QAA5BD,WAAWE,MAAMC,SACjBC,WAAWC,oBAAqB,QAG/BC,QAAQN,WAAY,CAAEO,YAAY,EAAMC,WAAW,UAG1DH,oBAAsB,SAEpBI,QAAUxB,SAASyB,iBAAiB,uCACxB,OAAZD,UAAqBA,QAAQrB,cACtB,EAGXqB,QAAQd,SAASgB,SACbA,OAAOC,gBAAgBvB,iBAAiB,SAAS,SAASQ,OAElDgB,aAAehB,EAAEiB,OACrBL,QAAQd,SAASoB,YACTC,UAAYD,MAAMH,gBA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OnDxB,cAAe,SAAS2B,iBAEhBC,IAAKC,MADLC,cAAgB/E,SAASC,uBAAuB,uBAE3C+E,EAAI,EAAGA,EAAID,cAAc5E,OAAQ6E,IAAK,KACvCC,SAAWF,cAAcC,WAEC,IAAnBC,SAASC,OAAyB3C,OAAO6B,cAAgBtE,KAAKoE,qBAAqBe,eAC1FJ,IAAMtC,OAAO6B,gBACLG,YAAcM,IAAIR,WAAY,EAClCS,MAAQD,IAAIN,WAAW,IACjBY,iBACNL,MAAMM,WAAWpF,SAASqF,eAAeT,cAEpC,IAAIU,SAAW,EAAGA,UAAaV,QAAQzE,OAAS,EAAImF,WACrDT,IAAIU,OAAO,OAAQ,QAAS,wBAGH,IAAnBN,SAASC,OAAyBlF,SAAS+C,WAAa/C,SAAS+C,UAAUyC,eACzFV,MAAQ9E,SAAS+C,UAAUyC,eACrBC,KAAOb,iBAGa,IAAnBK,SAASC,SACZlF,SAAS+C,UAETkC,SAASS,SACTb,IAAM7E,SAAS+C,UAAUyC,eACrBC,KAAOb,QACXK,SAASS,aACN,GAAIT,SAASU,gBAA6C,KAA3BV,SAASU,eAAuB,KAE9DC,SAAWX,SAASU,eACpBE,OAASZ,SAASa,aACtBb,SAASC,MAAQD,SAASC,MAAMa,UAAU,EAAGH,UACvChB,QAAUK,SAASC,MAAMa,UAAUF,OAAQZ,SAASC,MAAM/E,QAChE8E,SAASS,QACTT,SAASU,eAAiBC,SAAWhB,QAAQzE,OAC7C8E,SAASa,aAAeF,SAAWhB,QAAQzE,OAC3C8E,SAASS,aAETT,SAASC,OAASN,QAClBK,SAASS"} \ No newline at end of file +{"version":3,"file":"module.min.js","sources":["../src/module.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 javascript to place the placeholders.\n * Modified version of IOMAD Email template emailvars.\n *\n * @module mod_pulse/module\n * @category Classes - autoloading\n * @copyright 2021, bdecent gmbh bdecent.de\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['core_editor/events'], function() {\n\n return {\n /**\n * Setup the classes to editors works with placeholders.\n */\n init: function() {\n var module = this;\n\n var templatevars = document.getElementsByClassName(\"fitem_id_templatevars_editor\");\n for (var l = 0; l < templatevars.length; l++) {\n templatevars[l].addEventListener('click', function() {\n var EditorInput = document.getElementById('id_pulse_content_editoreditable');\n if (EditorInput !== null) {\n module.insertCaretActive(EditorInput);\n }\n });\n }\n\n var notificationheader = document.getElementById('admin-notificationheader');\n if (notificationheader !== null) {\n notificationheader.addEventListener('click', function() {\n var EditorInput = document.getElementById('id_s_mod_pulse_notificationheadereditable');\n module.insertCaretActive(EditorInput);\n });\n }\n\n var notificationfooter = document.getElementById('admin-notificationfooter');\n if (notificationfooter !== null) {\n notificationfooter.addEventListener('click', function() {\n var EditorInput = document.getElementById('id_s_mod_pulse_notificationfootereditable');\n module.insertCaretActive(EditorInput);\n });\n }\n\n templatevars = document.getElementsByClassName(\"fitem_id_templatevars_editor\");\n if (templatevars) {\n templatevars.forEach((elem) => {\n elem.addEventListener('click', function(e) {\n var target = e.currentTarget;\n var EditorInput = target.querySelector('[id*=\"_editoreditable\"]');\n module.insertCaretActive(EditorInput);\n });\n });\n }\n\n // Console.log(window.tinyMCE.get());\n var targetNode = document.querySelector('textarea[id$=_editor]');\n if (targetNode !== null) {\n var observer = new MutationObserver(function() {\n if (targetNode.style.display == 'none') {\n setTimeout(initIframeListeners, 100);\n }\n });\n observer.observe(targetNode, {attributes: true, childList: true});\n }\n\n const initIframeListeners = () => {\n\n var iframes = document.querySelectorAll('[data-fieldtype=\"editor\"] iframe');\n if (iframes === null || !iframes.length) {\n return false;\n }\n\n iframes.forEach((iframe) => {\n iframe.contentDocument.addEventListener('click', function(e) {\n\n var currentFrame = e.target;\n iframes.forEach((frame) => {\n var frameElem = frame.contentDocument.querySelector(\".insertatcaretactive\");\n if (frameElem !== null) {\n frameElem.classList.remove(\"insertatcaretactive\");\n }\n });\n\n var contentBody = currentFrame.querySelector('body');\n if (contentBody !== null) {\n contentBody.classList.add(\"insertatcaretactive\");\n }\n });\n });\n\n return true;\n };\n\n\n var clickforword = document.getElementsByClassName('clickforword');\n for (var i = 0; i < clickforword.length; i++) {\n clickforword[i].addEventListener('click', function(e) {\n e.preventDefault(); // To prevent the default behaviour of a tag.\n\n var content = \"{\" + this.getAttribute('data-text') + \"}\";\n var iframes = document.querySelectorAll('[data-fieldtype=\"editor\"] iframe');\n if (iframes === null || !iframes.length) {\n return false;\n }\n var tinyEditor;\n iframes.forEach((frame) => {\n var frameElem = frame.contentDocument.querySelector(\".insertatcaretactive\");\n if (frameElem !== null) {\n var contentBody = frame.contentDocument.querySelector('body');\n if (contentBody !== null) {\n contentBody.classList.add(\"insertatcaretactive\");\n var id = contentBody.dataset.id;\n var editor = window.tinyMCE.get(id);\n tinyEditor = editor;\n }\n }\n return false;\n });\n\n if (tinyEditor) {\n tinyEditor.selection.setContent(content);\n } else {\n module.insertAtCaret(content);\n }\n\n return true;\n });\n }\n\n // Make selected roles as badges in module edit form page.\n if (document.getElementById('page-mod-pulse-mod') !== null && document.getElementById('page-mod-pulse-mod')\n .querySelector(\"#fgroup_id_completionrequireapproval [data-fieldtype='autocomplete']\") !== null) {\n const textNodes = this.getAllTextNodes(\n document.getElementById('page-mod-pulse-mod')\n .querySelector(\"#fgroup_id_completionrequireapproval [data-fieldtype='autocomplete']\")\n );\n textNodes.forEach(node => {\n const span = document.createElement('span');\n span.classList = 'badge badge-info pulse-completion-roles';\n node.after(span);\n span.appendChild(node);\n });\n }\n },\n\n insertCaretActive: function(EditorInput) {\n if (EditorInput === null) {\n return;\n }\n var caret = document.getElementsByClassName(\"insertatcaretactive\");\n for (var j = 0; j < caret.length; j++) {\n caret[j].classList.remove(\"insertatcaretactive\");\n }\n EditorInput.classList.add(\"insertatcaretactive\");\n },\n\n /**\n * Filter text from node.\n * @param {string} element\n * @returns {array} list of childNodes.\n */\n getAllTextNodes: function(element) {\n return Array.from(element.childNodes)\n .filter(node => node.nodeType === 3 && node.textContent.trim().length > 1);\n },\n\n /**\n * Find the selection is inside the editor\n *\n * @param {string} div\n * @returns {bool}\n */\n isSelectionInsideDiv: (div) => {\n const selection = window.getSelection();\n if (selection.rangeCount === 0) {\n return false;\n }\n\n // Get the start and end nodes of the selection.\n const startNode = selection.getRangeAt(0).startContainer;\n const endNode = selection.getRangeAt(0).endContainer;\n\n // Check if the start and end nodes are both descendants of the editor div.\n return div.contains(startNode) && div.contains(endNode);\n },\n\n /**\n * Insert the placeholder in selected caret place.\n * @param {string} myValue\n */\n insertAtCaret: function(myValue) {\n var caretelements = document.getElementsByClassName(\"insertatcaretactive\");\n var sel, range;\n for (var n = 0; n < caretelements.length; n++) {\n var thiselem = caretelements[n];\n\n if (typeof thiselem.value === 'undefined' && window.getSelection && this.isSelectionInsideDiv(thiselem)) {\n sel = window.getSelection();\n if (sel.getRangeAt && sel.rangeCount) {\n range = sel.getRangeAt(0);\n range.deleteContents();\n range.insertNode(document.createTextNode(myValue));\n\n for (let position = 0; position != (myValue.length + 1); position++) {\n sel.modify(\"move\", \"right\", \"character\");\n }\n }\n } else if (typeof thiselem.value === 'undefined' && document.selection && document.selection.createRange) {\n range = document.selection.createRange();\n range.text = myValue;\n }\n\n if (typeof thiselem.value !== 'undefined') {\n if (document.selection) {\n // For browsers like Internet Explorer.\n thiselem.focus();\n sel = document.selection.createRange();\n sel.text = myValue;\n thiselem.focus();\n } else if (thiselem.selectionStart || thiselem.selectionStart == '0') {\n // For browsers like Firefox and Webkit based.\n var startPos = thiselem.selectionStart;\n var endPos = thiselem.selectionEnd;\n thiselem.value = thiselem.value.substring(0, startPos)\n + myValue + thiselem.value.substring(endPos, thiselem.value.length);\n thiselem.focus();\n thiselem.selectionStart = startPos + myValue.length;\n thiselem.selectionEnd = startPos + myValue.length;\n thiselem.focus();\n } else {\n thiselem.value += myValue;\n thiselem.focus();\n }\n }\n }\n },\n };\n});\n"],"names":["define","init","module","this","templatevars","document","getElementsByClassName","l","length","addEventListener","EditorInput","getElementById","insertCaretActive","notificationheader","notificationfooter","forEach","elem","e","currentTarget","querySelector","targetNode","MutationObserver","style","display","setTimeout","initIframeListeners","observe","attributes","childList","iframes","querySelectorAll","iframe","contentDocument","currentFrame","target","frame","frameElem","classList","remove","contentBody","add","clickforword","i","preventDefault","tinyEditor","content","getAttribute","id","dataset","editor","window","tinyMCE","get","selection","setContent","insertAtCaret","getAllTextNodes","node","span","createElement","after","appendChild","caret","j","element","Array","from","childNodes","filter","nodeType","textContent","trim","isSelectionInsideDiv","div","getSelection","rangeCount","startNode","getRangeAt","startContainer","endNode","endContainer","contains","myValue","sel","range","caretelements","n","thiselem","value","deleteContents","insertNode","createTextNode","position","modify","createRange","text","focus","selectionStart","startPos","endPos","selectionEnd","substring"],"mappings":";;;;;;;;;AAyBAA,0BAAO,CAAC,uBAAuB,iBAEpB,CAIHC,KAAM,mBACEC,OAASC,KAETC,aAAeC,SAASC,uBAAuB,gCAC1CC,EAAI,EAAGA,EAAIH,aAAaI,OAAQD,IACrCH,aAAaG,GAAGE,iBAAiB,SAAS,eAClCC,YAAcL,SAASM,eAAe,mCACtB,OAAhBD,aACAR,OAAOU,kBAAkBF,oBAKjCG,mBAAqBR,SAASM,eAAe,4BACtB,OAAvBE,oBACAA,mBAAmBJ,iBAAiB,SAAS,eACrCC,YAAcL,SAASM,eAAe,6CAC1CT,OAAOU,kBAAkBF,oBAI7BI,mBAAqBT,SAASM,eAAe,4BACtB,OAAvBG,oBACAA,mBAAmBL,iBAAiB,SAAS,eACrCC,YAAcL,SAASM,eAAe,6CAC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yBnF,SAASgD,WAAahD,SAASgD,UAAUyC,eACzFV,MAAQ/E,SAASgD,UAAUyC,eACrBC,KAAOb,iBAGa,IAAnBK,SAASC,SACZnF,SAASgD,UAETkC,SAASS,SACTb,IAAM9E,SAASgD,UAAUyC,eACrBC,KAAOb,QACXK,SAASS,aACN,GAAIT,SAASU,gBAA6C,KAA3BV,SAASU,eAAuB,KAE9DC,SAAWX,SAASU,eACpBE,OAASZ,SAASa,aACtBb,SAASC,MAAQD,SAASC,MAAMa,UAAU,EAAGH,UACvChB,QAAUK,SAASC,MAAMa,UAAUF,OAAQZ,SAASC,MAAMhF,QAChE+E,SAASS,QACTT,SAASU,eAAiBC,SAAWhB,QAAQ1E,OAC7C+E,SAASa,aAAeF,SAAWhB,QAAQ1E,OAC3C+E,SAASS,aAETT,SAASC,OAASN,QAClBK,SAASS"} \ No newline at end of file diff --git a/amd/build/preset.min.js.map b/amd/build/preset.min.js.map index 43d097f..f974c90 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',\r\n'core/fragment', 'core/ajax', 'core/templates', 'core/loadingicon', 'core/notification', 'core/modal_events'],\r\n function($, Modal, ModalPreset, PresetEvents, Str, Fragment, AJAX, Templates, Loadingicon, Notification, ModalEvents) {\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 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 }).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 THIS.reinitAvailability(SELECTOR.presetAvailability);\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.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 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\" && 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","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","create","type","TYPE","title","get_string","loadFragment","large","then","modal","show","getRoot","on","bodyRendered","reinitAvailability","fieldChangedEvent","hidden","destroy","bind","customize","modform","querySelector","modformdata","FormData","get","form","formdata","URLSearchParams","toString","addIconToContainer","disableButtons","applyCustomize","save","e","preventDefault","restorePreset","catch","exception","fieldName","changeinput","id","changeName","split","confParam","getElementById","methods","field","event","target","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,WACtF,gBAAiB,YAAa,iBAAkB,mBAAoB,oBAAqB,sBACrF,SAASC,EAAGC,MAAOC,YAAaC,aAAcC,IAAKC,SAAUC,KAAMC,UAAWC,YAAaC,aAAcC,iBAErGC,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,cAAc,OAC7CD,gBAAgBE,UAAUC,IAAI,gBAC9BN,eAAeO,SAASC,SAAYA,QAAQC,iBAAiB,SAAS,SAC9DC,SAAWF,QAAQG,aAAa,iBAChCC,YAAcJ,QAAQG,aAAa,oBACnCE,OAAS,UAAaH,kBAAsBZ,KAAKT,iBAAqBS,KAAKR,SAE/EW,SAASa,KAAKC,QAAQZ,iBACtB3B,MAAMwC,OAAO,CACTC,KAAMxC,YAAYyC,KAClBC,MAAOxC,IAAIyC,WAAW,mBAAoB,QAAS,OAAUR,cAC7DE,KAAMlC,SAASyC,aAAa,YAAa,qBAAsBvB,KAAKV,UAAWyB,QAC/ES,OAAO,IACRC,MAAKC,QAEJA,MAAMrB,gBAAkBA,gBACxBqB,MAAMC,OACND,MAAME,U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6BF,KAAMC,QAOhDnG,OAAOK,UAAUqD,eAAiB,eAC1B2C,QAAUvF,SAASC,iBAAiBH,KAAKH,mBACxC,IAAI6F,MAAMD,QACXA,QAAQC,IAAIC,UAAW,GAS/BvG,OAAOK,UAAU+F,6BAA+B,CAACI,KAAML,MACrCrF,SAASG,cAAc,OAC7BwF,UAAYD,KACpB7G,UAAU+G,YAAY,yBAA0BF,KAAML,KAS1DnG,OAAOK,UAAU0D,cAAgB,CAACT,SAAUqD,iBACpCC,YAAc,IAAIrD,gBAAgBD,UAAUE,WACjC9D,KAAKmH,KAAK,CAAC,CACtBC,WAAY,0BACZC,KAAM,CAACJ,UAAWA,UAAWrD,SAAUsD,gBAGlC,GAAGX,MAAMe,gBAEa,KAD3BA,SAAWC,KAAKC,MAAMF,WACFG,MAChBC,OAAOC,SAASC,KAAON,SAASG,SAQ5CnH,OAAOK,UAAUD,gBAAkB,eAC3BmH,WAAazG,SAAS0D,eAAe5D,KAAKN,YAAY6E,UAEvC,OAAfoC,YACwD,SAApDA,WAAW/F,aAAaZ,KAAKN,YAAYkH,SACzC/H,SAASyC,aAAa,YAAa,kBAAmBtB,KAAKX,UAAW,UAAaW,KAAKV,WACvF+F,MAAK,CAACC,KAAMC,MACTxG,UAAU8H,oBAAoBF,WAAYrB,KAAMC,IAChDoB,WAAWG,aAAa9G,KAAKN,YAAYkH,OAAQ,aAC5C9G,iBAMd,CACH+E,KAAM,CAACxF,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',\n'core/fragment', 'core/ajax', 'core/templates', 'core/loadingicon', 'core/notification', 'core/modal_events'],\n function($, Modal, ModalPreset, PresetEvents, Str, Fragment, AJAX, Templates, Loadingicon, Notification, ModalEvents) {\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 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 }).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.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 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\" && 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","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","create","type","TYPE","title","get_string","loadFragment","large","then","modal","show","getRoot","on","bodyRendered","reinitAvailability","fieldChangedEvent","hidden","destroy","bind","customize","modform","querySelector","modformdata","FormData","get","form","formdata","URLSearchParams","toString","addIconToContainer","disableButtons","applyCustomize","save","e","preventDefault","restorePreset","catch","exception","fieldName","changeinput","id","changeName","split","confParam","getElementById","methods","field","event","target","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,WACtF,gBAAiB,YAAa,iBAAkB,mBAAoB,oBAAqB,sBACrF,SAASC,EAAGC,MAAOC,YAAaC,aAAcC,IAAKC,SAAU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qD,iBACpCC,YAAc,IAAIrD,gBAAgBD,UAAUE,WACjC9D,KAAKmH,KAAK,CAAC,CACtBC,WAAY,0BACZC,KAAM,CAACJ,UAAWA,UAAWrD,SAAUsD,gBAGlC,GAAGX,MAAMe,gBAEa,KAD3BA,SAAWC,KAAKC,MAAMF,WACFG,MAChBC,OAAOC,SAASC,KAAON,SAASG,SAQ5CnH,OAAOK,UAAUD,gBAAkB,eAC3BmH,WAAazG,SAAS0D,eAAe5D,KAAKN,YAAY6E,UAEvC,OAAfoC,YACwD,SAApDA,WAAW/F,aAAaZ,KAAKN,YAAYkH,SACzC/H,SAASyC,aAAa,YAAa,kBAAmBtB,KAAKX,UAAW,UAAaW,KAAKV,WACvF+F,MAAK,CAACC,KAAMC,MACTxG,UAAU8H,oBAAoBF,WAAYrB,KAAMC,IAChDoB,WAAWG,aAAa9G,KAAKN,YAAYkH,OAAQ,aAC5C9G,iBAMd,CACH+E,KAAM,CAACxF,UAAWC,SAAUC,eACpBH,OAAOC,UAAWC,SAAUC"} \ No newline at end of file diff --git a/conditions/session/tests/behat/trigger_pulsecondition_session.feature b/conditions/session/tests/behat/trigger_pulsecondition_session.feature index 0ef66f3..51cc550 100644 --- a/conditions/session/tests/behat/trigger_pulsecondition_session.feature +++ b/conditions/session/tests/behat/trigger_pulsecondition_session.feature @@ -50,9 +50,7 @@ Feature: Session trigger event. Then I should see "Session booking" Then the field "Session booking" matches value "All" And I should see "Session module" - Then I click on "#fitem_id_condition_session_modules .form-autocomplete-downarrow" "css_element" Then I should see "FaceFace 01" in the "#fitem_id_condition_session_modules" "css_element" - Then I should see "FaceFace 02" in the "#fitem_id_condition_session_modules .form-autocomplete-suggestions" "css_element" And I press "Save changes" And I set the field "templateid" to "WELCOME MESSAGE 02" Then I press "Add automation instance" diff --git a/tests/behat/pulse_automation_template.feature b/tests/behat/pulse_automation_template.feature index 4cc72d5..c3d0b2b 100644 --- a/tests/behat/pulse_automation_template.feature +++ b/tests/behat/pulse_automation_template.feature @@ -70,7 +70,7 @@ Feature: Pulse automation templates Then I press "Save changes" Then I should see "Template updated successfully" And I should see "Triggers" in the "#pulse_automation_template tbody tr:nth-child(1)" "css_element" - And I should see "Condition triggers" in the "#pulse_automation_template tbody tr:nth-child(1) .template-reference" "css_element" + And I should see "Conditiontriggers" in the "#pulse_automation_template tbody tr:nth-child(1) .template-reference" "css_element" @javascript Scenario: Check Visibility of automation template