From de75e7471dc55b72e236ebb154c1ee91145aff31 Mon Sep 17 00:00:00 2001 From: Mathew May Date: Wed, 12 Jun 2019 15:24:48 +0800 Subject: [PATCH 1/2] MDL-65788 tool_policy: Prevent two modals rendering for guests. With the Guest registration calling policyactions.js the [data-action="view"] was having two click handlers set on the inital policy modal trgger. With this commit we state what we want the click event to be set on. --- .../policy/amd/build/policyactions.min.js | 2 +- admin/tool/policy/amd/src/policyactions.js | 22 ++++++------------- .../policy/classes/form/accept_policy.php | 4 ++-- .../policy/templates/guestconsent.mustache | 4 ++-- .../policy/templates/page_agreedocs.mustache | 2 +- .../templates/page_nopermission.mustache | 2 +- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/admin/tool/policy/amd/build/policyactions.min.js b/admin/tool/policy/amd/build/policyactions.min.js index 2e547734159..2fcb6849eb6 100644 --- a/admin/tool/policy/amd/build/policyactions.min.js +++ b/admin/tool/policy/amd/build/policyactions.min.js @@ -1 +1 @@ -define(["jquery","core/ajax","core/notification","core/modal_factory","core/modal_events"],function(a,b,c,d,e){var f={VIEW_POLICY:'[data-action="view"]'},g=function(){this.registerEvents()};return g.prototype.registerEvents=function(){a(f.VIEW_POLICY).click(function(f){f.preventDefault();var g=a(this).data("versionid"),h=a(this).data("behalfid"),i={versionid:g,behalfid:h},j={methodname:"tool_policy_get_policy_version",args:i},k=a.Deferred(),l=a.Deferred(),m=d.create({title:k,body:l,large:!0}).then(function(a){return a.getRoot().on(e.hidden,function(){a.destroy()}),a}).then(function(a){return a.show(),a})["catch"](c.exception),n=b.call([j]);a.when(n[0]).then(function(a){if(a.result.policy)return k.resolve(a.result.policy.name),l.resolve(a.result.policy.content),a;throw new Error(a.warnings[0].message)})["catch"](function(a){return m.then(function(a){return a.hide(),a.destroy(),a})["catch"](c.exception),c.addNotification({message:a,type:"error"})})})},{init:function(){return new g}}}); \ No newline at end of file +define(["jquery","core/ajax","core/notification","core/modal_factory","core/modal_events"],function(a,b,c,d,e){var f=function(a){this.registerEvents(a)};return f.prototype.registerEvents=function(f){f.on("click",function(f){f.preventDefault();var g=a(this).data("versionid"),h=a(this).data("behalfid"),i={versionid:g,behalfid:h},j={methodname:"tool_policy_get_policy_version",args:i},k=a.Deferred(),l=a.Deferred(),m=d.create({title:k,body:l,large:!0}).then(function(a){return a.getRoot().on(e.hidden,function(){a.destroy()}),a}).then(function(a){return a.show(),a})["catch"](c.exception),n=b.call([j]);a.when(n[0]).then(function(a){if(a.result.policy)return k.resolve(a.result.policy.name),l.resolve(a.result.policy.content),a;throw new Error(a.warnings[0].message)})["catch"](function(a){return m.then(function(a){return a.hide(),a.destroy(),a})["catch"](c.exception),c.addNotification({message:a,type:"error"})})})},{init:function(b){return b=a(b),new f(b)}}}); \ No newline at end of file diff --git a/admin/tool/policy/amd/src/policyactions.js b/admin/tool/policy/amd/src/policyactions.js index b3de54a487c..d8cd0f2bd91 100644 --- a/admin/tool/policy/amd/src/policyactions.js +++ b/admin/tool/policy/amd/src/policyactions.js @@ -29,27 +29,18 @@ define([ 'core/modal_events'], function($, Ajax, Notification, ModalFactory, ModalEvents) { - /** - * List of action selectors. - * - * @type {{VIEW_POLICY: string}} - */ - var ACTIONS = { - VIEW_POLICY: '[data-action="view"]' - }; - /** * PolicyActions class. */ - var PolicyActions = function() { - this.registerEvents(); + var PolicyActions = function(root) { + this.registerEvents(root); }; /** * Register event listeners. */ - PolicyActions.prototype.registerEvents = function() { - $(ACTIONS.VIEW_POLICY).click(function(e) { + PolicyActions.prototype.registerEvents = function(root) { + root.on("click", function(e) { e.preventDefault(); var versionid = $(this).data('versionid'); @@ -127,8 +118,9 @@ function($, Ajax, Notification, ModalFactory, ModalEvents) { * @method init * @return {PolicyActions} */ - 'init': function() { - return new PolicyActions(); + 'init': function(root) { + root = $(root); + return new PolicyActions(root); } }; }); diff --git a/admin/tool/policy/classes/form/accept_policy.php b/admin/tool/policy/classes/form/accept_policy.php index 3ff0daf6edd..23cecddda42 100644 --- a/admin/tool/policy/classes/form/accept_policy.php +++ b/admin/tool/policy/classes/form/accept_policy.php @@ -97,7 +97,7 @@ class accept_policy extends \moodleform { } } - $PAGE->requires->js_call_amd('tool_policy/policyactions', 'init'); + $PAGE->requires->js_call_amd('tool_policy/policyactions', 'init', '[data-action="view"]'); } /** @@ -178,4 +178,4 @@ class accept_policy extends \moodleform { } } } -} \ No newline at end of file +} diff --git a/admin/tool/policy/templates/guestconsent.mustache b/admin/tool/policy/templates/guestconsent.mustache index 872757e085e..9595e6985c4 100644 --- a/admin/tool/policy/templates/guestconsent.mustache +++ b/admin/tool/policy/templates/guestconsent.mustache @@ -58,7 +58,7 @@ require(['jquery', 'tool_policy/jquery-eu-cookie-law-popup', 'tool_policy/policy "