Merge branch 'MDL-65788' of git://github.com/Chocolate-lightning/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2019-07-22 21:38:20 +02:00
commit 9da4b1821f
7 changed files with 15 additions and 23 deletions

View File

@ -1,2 +1,2 @@
define ("tool_policy/policyactions",["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()};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=a.Deferred(),j=a.Deferred(),k=d.create({title:i,body:j,large:!0}).then(function(a){a.getRoot().on(e.hidden,function(){a.destroy()});return a}).then(function(a){a.show();return a}).catch(c.exception),l=b.call([{methodname:"tool_policy_get_policy_version",args:{versionid:g,behalfid:h}}]);a.when(l[0]).then(function(a){if(a.result.policy){i.resolve(a.result.policy.name);j.resolve(a.result.policy.content);return a}else{throw new Error(a.warnings[0].message)}}).catch(function(a){k.then(function(a){a.hide();a.destroy();return a}).catch(c.exception);return c.addNotification({message:a,type:"error"})})})};return{init:function init(){return new g}}});
define ("tool_policy/policyactions",["jquery","core/ajax","core/notification","core/modal_factory","core/modal_events"],function(a,b,c,d,e){var f=function(a){this.registerEvents(a)};f.prototype.registerEvents=function(f){f.on("click",function(f){f.preventDefault();var g=a(this).data("versionid"),h=a(this).data("behalfid"),i=a.Deferred(),j=a.Deferred(),k=d.create({title:i,body:j,large:!0}).then(function(a){a.getRoot().on(e.hidden,function(){a.destroy()});return a}).then(function(a){a.show();return a}).catch(c.exception),l=b.call([{methodname:"tool_policy_get_policy_version",args:{versionid:g,behalfid:h}}]);a.when(l[0]).then(function(a){if(a.result.policy){i.resolve(a.result.policy.name);j.resolve(a.result.policy.content);return a}else{throw new Error(a.warnings[0].message)}}).catch(function(a){k.then(function(a){a.hide();a.destroy();return a}).catch(c.exception);return c.addNotification({message:a,type:"error"})})})};return{init:function init(b){b=a(b);return new f(b)}}});
//# sourceMappingURL=policyactions.min.js.map

File diff suppressed because one or more lines are too long

View 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);
}
};
});

View 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 {
}
}
}
}
}

View 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"]');
});
});

View File

@ -143,6 +143,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}}

View 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}}