MDL-65788 tool_policy: Prevent two modals rendering for guests.
authorMathew May <mathewm@hotmail.co.nz>
Wed, 12 Jun 2019 07:24:48 +0000 (15:24 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Sun, 14 Jul 2019 10:52:27 +0000 (18:52 +0800)
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.

admin/tool/policy/amd/build/policyactions.min.js
admin/tool/policy/amd/src/policyactions.js
admin/tool/policy/classes/form/accept_policy.php
admin/tool/policy/templates/guestconsent.mustache
admin/tool/policy/templates/page_agreedocs.mustache
admin/tool/policy/templates/page_nopermission.mustache

index 2e54773..2fcb684 100644 (file)
Binary files a/admin/tool/policy/amd/build/policyactions.min.js and b/admin/tool/policy/amd/build/policyactions.min.js differ
index b3de54a..d8cd0f2 100644 (file)
@@ -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);
         }
     };
 });
index e7bcec4..20e358f 100644 (file)
@@ -111,7 +111,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"]');
     }
 
     /**
@@ -197,4 +197,4 @@ class accept_policy extends \moodleform {
             }
         }
     }
-}
\ No newline at end of file
+}
index 872757e..9595e69 100644 (file)
@@ -58,7 +58,7 @@ require(['jquery', 'tool_policy/jquery-eu-cookie-law-popup', 'tool_policy/policy
                    "<ul>{{#policies}}" +
                    "<li>" +
                    "<a href=\"{{pluginbaseurl}}/view.php?versionid={{id}}{{#returnurl}}&amp;returnurl={{.}}{{/returnurl}}\" " +
-                   "   data-action=\"view\" data-versionid=\"{{id}}\" data-behalfid=\"1\" >" +
+                   "   data-action=\"view-guest\" data-versionid=\"{{id}}\" data-behalfid=\"1\" >" +
                    "{{{name}}}" +
                    "</a>" +
                    "</li>" +
@@ -81,7 +81,7 @@ require(['jquery', 'tool_policy/jquery-eu-cookie-law-popup', 'tool_policy/policy
             {{/haspolicies}}
 
             // Initialise the JS for the modal window which displays the policy versions.
-            ActionsMod.init();
+            ActionsMod.init('[data-action="view-guest"]');
         });
 });
 
index 40512ad..60efaa6 100644 (file)
 {{#js}}
 // Initialise the JS for the modal window which displays the policy versions.
 require(['tool_policy/policyactions'], function(ActionsMod) {
-    ActionsMod.init();
+    ActionsMod.init('[data-action="view"]');
 });
 {{/js}}
index 93b8296..81f66f0 100644 (file)
@@ -73,6 +73,6 @@
 {{#js}}
 // Initialise the JS for the modal window which displays the policy versions.
 require(['tool_policy/policyactions'], function(ActionsMod) {
-    ActionsMod.init();
+    ActionsMod.init('[data-action="view"]');
 });
 {{/js}}