From a33b233239a70d3fe44808c5f62883057f8c83ad Mon Sep 17 00:00:00 2001 From: "raja.lmsace@gmail.com" Date: Thu, 11 Apr 2024 15:49:06 +0530 Subject: [PATCH] Instance override capability improved. - PLS-729 --- actions/notification/classes/schedule.php | 6 ++++-- amd/build/automation.min.js | 2 +- amd/build/automation.min.js.map | 2 +- amd/src/automation.js | 15 +++++++++++++-- conditions/activity/classes/conditionform.php | 2 +- conditions/cohort/classes/conditionform.php | 4 ++-- conditions/events/classes/conditionform.php | 6 ++++-- conditions/session/classes/conditionform.php | 2 +- 8 files changed, 27 insertions(+), 12 deletions(-) diff --git a/actions/notification/classes/schedule.php b/actions/notification/classes/schedule.php index 1df27ed..6135aaa 100644 --- a/actions/notification/classes/schedule.php +++ b/actions/notification/classes/schedule.php @@ -177,8 +177,10 @@ public function send_scheduled_notification($userid=null) { // Check the session condition are set for this notification. if its added then load the session data for placeholders. $sessionin = in_array('session', (array) $this->instancedata->template->triggerconditions); $sessionin = ($this->schedulerecord->con_isoverridden == 1) ? $this->schedulerecord->con_status : $sessionin; - if ($sessionin) { - $sessionconditiondata = (object) ['modules' => json_decode($this->schedulerecord->con_additional)->modules]; + if ($sessionin && $this->schedulerecord->con_additional) { + $sessionaddional = json_decode($this->schedulerecord->con_additional); + $sessionmodules = !empty($sessionaddional->modules) ? $sessionaddional->modules : []; + $sessionconditiondata = (object) ['modules' => $sessionmodules]; $this->include_session_data($mod, $sessionconditiondata, $this->user->id); } diff --git a/amd/build/automation.min.js b/amd/build/automation.min.js index 6aa5701..bca0798 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","core/notification"],(function($,Modal,Template,Str,notification){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(notification.exception)}}))}))}(),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"))}}})); +define("mod_pulse/automation",["jquery","core/modal_factory","core/templates","core/str","core/notification"],(function($,Modal,Template,Str,notification){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})),function(){if(null===document.querySelectorAll("input[type=checkbox].checkboxgroupautomation")||null===document.querySelectorAll('[data-fieldtype="autocomplete"], [data-fieldtype="tags"]'))return!0;var capinput=document.querySelector('input[name="hasinstanceeditcapability"]'),hasCapability=capinput&&capinput.value||null===capinput;document.querySelectorAll('[data-fieldtype="autocomplete"], [data-fieldtype="tags"]').forEach((element=>{if(null===element)return!0;var observer=new MutationObserver((function(mutations){mutations.forEach((mutation=>{var target=mutation.target;!hasCapability&&target.querySelector('input[data-fieldtype="autocomplete"]')&&(target.querySelector('input[data-fieldtype="autocomplete"]').disabled=!0);var overrideElement=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(notification.exception)}}))}))}(),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 7094e8f..c53fc9f 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', \"core/notification\"],\n function($, Modal, Template, Str, notification) {\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 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 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 var parent = overElement.parentNode;\n parent.innerHTML += '';\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(notification.exception);\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","notification","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","exception","overrideModal","removeAttribute","instanceMenuLink","navMenu","menu","forceintomoremenu","removeChild","insertBefore","children","window","dispatchEvent","Event","moveOutMoreMenu"],"mappings":"AAAAA,8BAA+B,CAAC,SAAU,qBAAsB,iBAAkB,WAAY,sBAC1F,SAASC,EAAGC,MAAOC,SAAUC,IAAKC,oBAkF5BC,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,MAGXI,OAASL,YAAYM,WACzBD,OAAOE,WAAa,iDAChBC,WAAaX,SAASY,cAAc,cACxCD,WAAWE,UAAUC,IAAI,iBAAkB,iBAC3CH,WAAWI,OAAOP,QAClBF,QAAQC,cAAc,aAAaQ,OAAOJ,aACnC,KApDH,OADJX,SAASC,iBAAiB,iDACmD,OAAjED,SAASC,iBAAiB,oCAI1CD,SAASC,iBAAiB,mCA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pE,aAAaqE,kBAkB9BC,GACArE,uBAZgD,OAAhDE,SAAS4B,MAAM,+BAGnB5B,SAAS4B,MAAM,6BAA6BC,SACxC,IAAM7B,SAASO,cAAc,kBAAkB6D,gBAAgB,cAYnEC,iBAAkB,WAlLGC,CAAAA,aAEL,OAAZA,aAIAC,KAAOD,QAAQ/D,cAAc,0BAEpB,OAATgE,QAIJA,KAAOA,KAAK9D,YACPmC,QAAQ4B,mBAAoB,EACjCD,KAAKhE,cAAc,KAAKM,UAAUuB,OAAO,iBACzCmC,KAAKhE,cAAc,KAAKM,UAAUC,IAAI,YACtCyD,KAAK9D,WAAWgE,YAAYF,MAG5BD,QAAQI,aAAaH,KAAMD,QAAQK,SAAS,IAC5CC,OAAOC,cAAc,IAAIC,MAAM,cAgK3BC,CADiB/E,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', \"core/notification\"],\n function($, Modal, Template, Str, notification) {\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\"], [data-fieldtype=\"tags\"]') === null) {\n return true;\n }\n\n\n var capinput = document.querySelector('input[name=\"hasinstanceeditcapability\"]');\n var hasCapability = (capinput && capinput.value) || capinput === null;\n\n // Observer the autocomplete.\n document.querySelectorAll('[data-fieldtype=\"autocomplete\"], [data-fieldtype=\"tags\"]').forEach((element) => {\n\n if (element === null) {\n return true;\n }\n\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach((mutation) => {\n var target = mutation.target;\n\n // Not has capability to edit instance, then hide the autocomplete input text.\n if (!hasCapability && target.querySelector('input[data-fieldtype=\"autocomplete\"]')) {\n target.querySelector('input[data-fieldtype=\"autocomplete\"]').disabled = true;\n }\n\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 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 var parent = overElement.parentNode;\n parent.innerHTML += '';\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(notification.exception);\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","notification","moveOverRidePosition","group","document","querySelectorAll","forEach","overElement","id","replace","element","querySelector","parent","parentNode","innerHTML","nodeToMove","createElement","classList","add","append","capinput","hasCapability","value","observer","MutationObserver","mutations","mutation","target","disabled","overrideElement","disconnect","observe","attributes","childList","subtree","updateAutoCompletionPositions","init","forms","onsubmit","e","invalidElement","hrefSelector","click","templateReference","instanceReference","remove","prepend","trigger","elem","nextSibling","addEventListener","preventDefault","data","dataset","instance","overrides","JSON","parse","map","url","M","cfg","wwwroot","sesskey","create","title","get_string","body","render","instances","then","modal","show","catch","exception","overrideModal","removeAttribute","instanceMenuLink","navMenu","menu","forceintomoremenu","removeChild","insertBefore","children","window","dispatchEvent","Event","moveOutMoreMenu"],"mappings":"AAAAA,8BAA+B,CAAC,SAAU,qBAAsB,iBAAkB,WAAY,sBAC1F,SAASC,EAAGC,MAAOC,SAAUC,IAAKC,oBA6F5BC,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,MAGXI,OAASL,YAAYM,WACzBD,OAAOE,WAAa,iDAChBC,WAAaX,SAASY,cAAc,cACxCD,WAAWE,UAAUC,IAAI,iBAAkB,iBAC3CH,WAAWI,OAAOP,QAClBF,QAAQC,cAAc,aAAaQ,OAAOJ,aACnC,KAnEuB,cAI1B,OADJX,SAASC,iBAAiB,iDAC4E,OAA1FD,SAASC,iBAAiB,mEAC/B,MAIPe,SAAWhB,SAASO,cAAc,2CAClCU,cAAiBD,UAAYA,SAASE,OAAuB,OAAbF,SAGpDhB,SAASC,iBAAiB,4DAA4DC,SAASI,aAE3E,OAAZA,eACO,MAGPa,SAAW,IAAIC,kBAAiB,SAASC,WACzCA,UAAUnB,SAASoB,eACXC,OAASD,SAASC,QAGjBN,eAAiBM,OAAOhB,cAAc,0CACvCgB,OAAOhB,cAAc,wCAAwCiB,UAAW,OAGxEC,gBAAkBF,OAAOhB,cAAc,kBACnB,OAApBkB,kBAGJA,gBAAgBhB,WAAWM,OAAOU,iBA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kB,WA7LGC,CAAAA,aAEL,OAAZA,aAIAC,KAAOD,QAAQnE,cAAc,0BAEpB,OAAToE,QAIJA,KAAOA,KAAKlE,YACPwC,QAAQ2B,mBAAoB,EACjCD,KAAKpE,cAAc,KAAKM,UAAU4B,OAAO,iBACzCkC,KAAKpE,cAAc,KAAKM,UAAUC,IAAI,YACtC6D,KAAKlE,WAAWoE,YAAYF,MAG5BD,QAAQI,aAAaH,KAAMD,QAAQK,SAAS,IAC5CC,OAAOC,cAAc,IAAIC,MAAM,cA2K3BC,CADiBnF,SAASO,cAAc"} \ No newline at end of file diff --git a/amd/src/automation.js b/amd/src/automation.js index c455af3..0d4a674 100644 --- a/amd/src/automation.js +++ b/amd/src/automation.js @@ -53,11 +53,16 @@ define("mod_pulse/automation", ['jquery', 'core/modal_factory', 'core/templates' var group = "checkboxgroupautomation"; if (document.querySelectorAll('input[type=checkbox].' + group) - === null || document.querySelectorAll('[data-fieldtype="autocomplete"]') === null) { + === null || document.querySelectorAll('[data-fieldtype="autocomplete"], [data-fieldtype="tags"]') === null) { return true; } - document.querySelectorAll('[data-fieldtype="autocomplete"]').forEach((element) => { + + var capinput = document.querySelector('input[name="hasinstanceeditcapability"]'); + var hasCapability = (capinput && capinput.value) || capinput === null; + + // Observer the autocomplete. + document.querySelectorAll('[data-fieldtype="autocomplete"], [data-fieldtype="tags"]').forEach((element) => { if (element === null) { return true; @@ -66,6 +71,12 @@ define("mod_pulse/automation", ['jquery', 'core/modal_factory', 'core/templates' var observer = new MutationObserver(function(mutations) { mutations.forEach((mutation) => { var target = mutation.target; + + // Not has capability to edit instance, then hide the autocomplete input text. + if (!hasCapability && target.querySelector('input[data-fieldtype="autocomplete"]')) { + target.querySelector('input[data-fieldtype="autocomplete"]').disabled = true; + } + var overrideElement = target.querySelector('.custom-switch'); if (overrideElement === null) { return; diff --git a/conditions/activity/classes/conditionform.php b/conditions/activity/classes/conditionform.php index 904ea8b..290ac20 100644 --- a/conditions/activity/classes/conditionform.php +++ b/conditions/activity/classes/conditionform.php @@ -112,7 +112,7 @@ public function is_user_completed($instancedata, $userid, \completion_info $comp } return false; } - return true; + return false; } /** diff --git a/conditions/cohort/classes/conditionform.php b/conditions/cohort/classes/conditionform.php index 0b30bff..aebd61d 100644 --- a/conditions/cohort/classes/conditionform.php +++ b/conditions/cohort/classes/conditionform.php @@ -55,7 +55,7 @@ public function load_instance_form(&$mform, $forminstance) { $mform->addElement('select', 'condition[cohort][status]', $completionstr, $this->get_options()); $mform->addHelpButton('condition[cohort][status]', 'condition', 'pulsecondition_cohort'); - $cohorts = cohort_get_all_cohorts(); + $cohorts = cohort_get_all_cohorts(0, 0); $cohorts = $cohorts['cohorts']; array_walk($cohorts, function(&$value) { @@ -98,7 +98,7 @@ public function is_user_completed($instancedata, $userid, \completion_info $comp } } // Cohorts are configured but not completed. - return !empty($cohorts) ? false : true; + return !empty($cohorts) ? true : false; } /** diff --git a/conditions/events/classes/conditionform.php b/conditions/events/classes/conditionform.php index 0f8e693..0738ffe 100644 --- a/conditions/events/classes/conditionform.php +++ b/conditions/events/classes/conditionform.php @@ -400,8 +400,10 @@ public function update_email_customvars($userid, $instancedata, $schedulerecord) $vars['context'] = ($context) ? $context->get_context_name(true) : get_string('other'); // Event_Contextlinked. - if ($url = $context->get_url()) { - $vars['contextlinked'] = \html_writer::link($url, $vars['context']); + if ($context instanceof \context) { + if ($url = $context->get_url()) { + $vars['contextlinked'] = \html_writer::link($url, $vars['context']); + } } } // Event_Affecteduserfullname. diff --git a/conditions/session/classes/conditionform.php b/conditions/session/classes/conditionform.php index ba7f46d..582f2a2 100644 --- a/conditions/session/classes/conditionform.php +++ b/conditions/session/classes/conditionform.php @@ -114,7 +114,7 @@ public function is_user_completed($instancedata, $userid, \completion_info $comp return ($existingsignup) ? true : false; } // Not configured any session modules. - return true; + return false; } /**