MDL-57690 js: fix core modal uses in amd
Converting the uses to the AMD modules is a bit risky for now, instead just require the YUI depdency.
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
define(["jquery","core/config","core/notification","core/templates"],function(a,b,c,d){var e,f,g,h,i={ADDROLE:"a.allowlink, a.prohibitlink",REMOVEROLE:"a.preventlink, a.unprohibitlink",UNPROHIBIT:"a.unprohibitlink"},j=a.Event("rolesloaded"),k=null,l=function(){var d={contextid:e,getroles:1,sesskey:b.sesskey};a.post(g+"roles/ajax.php",d,null,"json").done(function(b){try{h=b,l=function(){a("body").trigger(j)},l()}catch(d){c.exception(d)}}).fail(function(a,b,d){c.exception(d)})},m=function(b,f,i){var j={contextid:e,roleid:f,sesskey:M.cfg.sesskey,action:i,capability:b.data("name")};a.post(g+"roles/ajax.php",j,null,"json").done(function(e){var i=e;try{var j={rolename:h[f],roleid:f,adminurl:g,imageurl:M.util.image_url("t/delete","moodle")};switch(i){case"allow":j.spanclass="allowed",j.linkclass="preventlink",j.action="prevent";break;case"prohibit":j.spanclass="forbidden",j.linkclass="unprohibitlink",j.action="unprohibit";break;case"prevent":return void b.find('a[data-role-id="'+f+'"]').first().closest(".allowed").remove();case"unprohibit":return void b.find('a[data-role-id="'+f+'"]').first().closest(".forbidden").remove();default:return}d.render("core/permissionmanager_role",j).done(function(c){if("allow"==i)a(c).insertBefore(b.find(".allowmore:first"));else if("prohibit"==i){a(c).insertBefore(b.find(".prohibitmore:first"));var d=b.find(".allowedroles").first().find('a[data-role-id="'+f+'"]');d&&d.first().closest(".allowed").remove()}k.hide()}).fail(c.exception)}catch(l){c.exception(l)}}).fail(function(a,b,d){c.exception(d)})},n=function(b){b.preventDefault(),a("body").one("rolesloaded",function(){var e=a(b.currentTarget),g=e.data("action"),j=e.closest("tr.rolecap"),l={cap:j.data("humanname"),context:f},n=M.util.get_string("role"+g+"info","core_role",l);null===k&&(k=new M.core.dialogue({draggable:!0,modal:!0,closeButton:!0,width:"450px"})),k.set("headerContent",M.util.get_string("role"+g+"header","core_role"));var o,p,q=[];switch(g){case"allow":p=j.find(i.REMOVEROLE);break;case"prohibit":p=j.find(i.UNPROHIBIT)}for(o in h){var r="",s=p.filter("[data-role-id='"+o+"']").length;s&&(r="disabled");var t={roleid:o,rolename:h[o],disabled:r};q.push(t)}d.render("core/permissionmanager_panelcontent",{message:n,roles:q}).done(function(b){k.set("bodyContent",b),k.show(),a("div.role_buttons").delegate("input","click",function(b){var c=a(b.currentTarget).data("role-id");m(j,c,g)})}).fail(c.exception)}),l()},o=function(b){b.preventDefault(),a("body").one("rolesloaded",function(){var d=a(b.currentTarget),e=d.data("action"),g=d.data("role-id"),i=d.closest("tr.rolecap"),j={role:h[g],cap:i.data("humanname"),context:f};c.confirm(M.util.get_string("confirmunassigntitle","core_role"),M.util.get_string("confirmrole"+e,"core_role",j),M.util.get_string("confirmunassignyes","core_role"),M.util.get_string("confirmunassignno","core_role"),function(){m(i,g,e)})}),l()};return{initialize:function(b){e=b.contextid,f=b.contextname,g=b.adminurl;var c=a("body");c.delegate(i.ADDROLE,"click",n),c.delegate(i.REMOVEROLE,"click",o)}}});
|
||||
define(["jquery","core/config","core/notification","core/templates","core/yui"],function(a,b,c,d,e){var f,g,h,i,j={ADDROLE:"a.allowlink, a.prohibitlink",REMOVEROLE:"a.preventlink, a.unprohibitlink",UNPROHIBIT:"a.unprohibitlink"},k=a.Event("rolesloaded"),l=null,m=function(){var d={contextid:f,getroles:1,sesskey:b.sesskey};a.post(h+"roles/ajax.php",d,null,"json").done(function(b){try{i=b,m=function(){a("body").trigger(k)},m()}catch(d){c.exception(d)}}).fail(function(a,b,d){c.exception(d)})},n=function(b,e,g){var j={contextid:f,roleid:e,sesskey:M.cfg.sesskey,action:g,capability:b.data("name")};a.post(h+"roles/ajax.php",j,null,"json").done(function(f){var g=f;try{var j={rolename:i[e],roleid:e,adminurl:h,imageurl:M.util.image_url("t/delete","moodle")};switch(g){case"allow":j.spanclass="allowed",j.linkclass="preventlink",j.action="prevent";break;case"prohibit":j.spanclass="forbidden",j.linkclass="unprohibitlink",j.action="unprohibit";break;case"prevent":return void b.find('a[data-role-id="'+e+'"]').first().closest(".allowed").remove();case"unprohibit":return void b.find('a[data-role-id="'+e+'"]').first().closest(".forbidden").remove();default:return}d.render("core/permissionmanager_role",j).done(function(c){if("allow"==g)a(c).insertBefore(b.find(".allowmore:first"));else if("prohibit"==g){a(c).insertBefore(b.find(".prohibitmore:first"));var d=b.find(".allowedroles").first().find('a[data-role-id="'+e+'"]');d&&d.first().closest(".allowed").remove()}l.hide()}).fail(c.exception)}catch(k){c.exception(k)}}).fail(function(a,b,d){c.exception(d)})},o=function(b){b.preventDefault(),e.use("moodle-core-notification-dialogue",function(){a("body").one("rolesloaded",function(){var e=a(b.currentTarget),f=e.data("action"),h=e.closest("tr.rolecap"),k={cap:h.data("humanname"),context:g},m=M.util.get_string("role"+f+"info","core_role",k);null===l&&(l=new M.core.dialogue({draggable:!0,modal:!0,closeButton:!0,width:"450px"})),l.set("headerContent",M.util.get_string("role"+f+"header","core_role"));var o,p,q=[];switch(f){case"allow":p=h.find(j.REMOVEROLE);break;case"prohibit":p=h.find(j.UNPROHIBIT)}for(o in i){var r="",s=p.filter("[data-role-id='"+o+"']").length;s&&(r="disabled");var t={roleid:o,rolename:i[o],disabled:r};q.push(t)}d.render("core/permissionmanager_panelcontent",{message:m,roles:q}).done(function(b){l.set("bodyContent",b),l.show(),a("div.role_buttons").delegate("input","click",function(b){var c=a(b.currentTarget).data("role-id");n(h,c,f)})}).fail(c.exception)})}),m()},p=function(b){b.preventDefault(),a("body").one("rolesloaded",function(){var d=a(b.currentTarget),e=d.data("action"),f=d.data("role-id"),h=d.closest("tr.rolecap"),j={role:i[f],cap:h.data("humanname"),context:g};c.confirm(M.util.get_string("confirmunassigntitle","core_role"),M.util.get_string("confirmrole"+e,"core_role",j),M.util.get_string("confirmunassignyes","core_role"),M.util.get_string("confirmunassignno","core_role"),function(){n(h,f,e)})}),m()};return{initialize:function(b){f=b.contextid,g=b.contextname,h=b.adminurl;var c=a("body");c.delegate(j.ADDROLE,"click",o),c.delegate(j.REMOVEROLE,"click",p)}}});
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -23,7 +23,8 @@
|
||||
/**
|
||||
* @module admin/permissionmanager
|
||||
*/
|
||||
define(['jquery', 'core/config', 'core/notification', 'core/templates'], function($, config, notification, templates) {
|
||||
define(['jquery', 'core/config', 'core/notification', 'core/templates', 'core/yui'],
|
||||
function($, config, notification, templates, Y) {
|
||||
|
||||
/**
|
||||
* Used CSS selectors
|
||||
@@ -152,57 +153,60 @@ define(['jquery', 'core/config', 'core/notification', 'core/templates'], functio
|
||||
var handleAddRole = function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$('body').one('rolesloaded', function() {
|
||||
var link = $(e.currentTarget);
|
||||
var action = link.data('action');
|
||||
var row = link.closest('tr.rolecap');
|
||||
var confirmationDetails = {
|
||||
cap: row.data('humanname'),
|
||||
context: contextname
|
||||
};
|
||||
var message = M.util.get_string('role' + action + 'info', 'core_role', confirmationDetails);
|
||||
if (panel === null) {
|
||||
panel = new M.core.dialogue({
|
||||
draggable: true,
|
||||
modal: true,
|
||||
closeButton: true,
|
||||
width: '450px'
|
||||
});
|
||||
}
|
||||
panel.set('headerContent', M.util.get_string('role' + action + 'header', 'core_role'));
|
||||
|
||||
var i, existingrolelinks;
|
||||
|
||||
var roles = [];
|
||||
switch (action) {
|
||||
case 'allow':
|
||||
existingrolelinks = row.find(SELECTORS.REMOVEROLE);
|
||||
break;
|
||||
case 'prohibit':
|
||||
existingrolelinks = row.find(SELECTORS.UNPROHIBIT);
|
||||
break;
|
||||
}
|
||||
for (i in overideableroles) {
|
||||
var disabled = '';
|
||||
var disable = existingrolelinks.filter("[data-role-id='" + i + "']").length;
|
||||
if (disable) {
|
||||
disabled = 'disabled';
|
||||
// TODO: MDL-57778 Convert to core/modal.
|
||||
Y.use('moodle-core-notification-dialogue', function() {
|
||||
$('body').one('rolesloaded', function() {
|
||||
var link = $(e.currentTarget);
|
||||
var action = link.data('action');
|
||||
var row = link.closest('tr.rolecap');
|
||||
var confirmationDetails = {
|
||||
cap: row.data('humanname'),
|
||||
context: contextname
|
||||
};
|
||||
var message = M.util.get_string('role' + action + 'info', 'core_role', confirmationDetails);
|
||||
if (panel === null) {
|
||||
panel = new M.core.dialogue({
|
||||
draggable: true,
|
||||
modal: true,
|
||||
closeButton: true,
|
||||
width: '450px'
|
||||
});
|
||||
}
|
||||
var roledetails = {roleid: i, rolename: overideableroles[i], disabled: disabled};
|
||||
roles.push(roledetails);
|
||||
}
|
||||
panel.set('headerContent', M.util.get_string('role' + action + 'header', 'core_role'));
|
||||
|
||||
templates.render('core/permissionmanager_panelcontent', {message: message, roles: roles})
|
||||
.done(function(content) {
|
||||
panel.set('bodyContent', content);
|
||||
panel.show();
|
||||
$('div.role_buttons').delegate('input', 'click', function(e) {
|
||||
var roleid = $(e.currentTarget).data('role-id');
|
||||
changePermissions(row, roleid, action);
|
||||
});
|
||||
})
|
||||
.fail(notification.exception);
|
||||
var i, existingrolelinks;
|
||||
|
||||
var roles = [];
|
||||
switch (action) {
|
||||
case 'allow':
|
||||
existingrolelinks = row.find(SELECTORS.REMOVEROLE);
|
||||
break;
|
||||
case 'prohibit':
|
||||
existingrolelinks = row.find(SELECTORS.UNPROHIBIT);
|
||||
break;
|
||||
}
|
||||
for (i in overideableroles) {
|
||||
var disabled = '';
|
||||
var disable = existingrolelinks.filter("[data-role-id='" + i + "']").length;
|
||||
if (disable) {
|
||||
disabled = 'disabled';
|
||||
}
|
||||
var roledetails = {roleid: i, rolename: overideableroles[i], disabled: disabled};
|
||||
roles.push(roledetails);
|
||||
}
|
||||
|
||||
templates.render('core/permissionmanager_panelcontent', {message: message, roles: roles})
|
||||
.done(function(content) {
|
||||
panel.set('bodyContent', content);
|
||||
panel.show();
|
||||
$('div.role_buttons').delegate('input', 'click', function(e) {
|
||||
var roleid = $(e.currentTarget).data('role-id');
|
||||
changePermissions(row, roleid, action);
|
||||
});
|
||||
})
|
||||
.fail(notification.exception);
|
||||
|
||||
});
|
||||
});
|
||||
loadOverideableRoles();
|
||||
};
|
||||
|
||||
+59
-50
@@ -22,8 +22,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 3.0
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'],
|
||||
function($, ajax, templates, notification, str) {
|
||||
define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str', 'core/yui'],
|
||||
function($, ajax, templates, notification, str, Y) {
|
||||
return /** @alias module:core/tag */ {
|
||||
|
||||
/**
|
||||
@@ -158,24 +158,27 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
|
||||
fldset.append($('<input type="radio" name="maintag" id="combinetags_maintag_' + tagid + '" value="' +
|
||||
tagid + '"/><label for="combinetags_maintag_' + tagid + '">' + tagname + '</label><br>'));
|
||||
});
|
||||
var panel = new M.core.dialogue({
|
||||
draggable: true,
|
||||
modal: true,
|
||||
closeButton: true,
|
||||
headerContent: s[0],
|
||||
bodyContent: el.html()
|
||||
});
|
||||
panel.show();
|
||||
$('#combinetags_form input[type=radio]').first().focus().prop('checked', true);
|
||||
$('#combinetags_form #combinetags_cancel').on('click', function() {
|
||||
panel.destroy();
|
||||
});
|
||||
$('#combinetags_form').on('submit', function() {
|
||||
tempElement.appendTo(form);
|
||||
var maintag = $('input[name=maintag]:checked', '#combinetags_form').val();
|
||||
$("<input type='hidden'/>").attr('name', 'maintag').attr('value', maintag).appendTo(form);
|
||||
form.submit();
|
||||
return false;
|
||||
// TODO: MDL-57778 Convert to core/modal.
|
||||
Y.use('moodle-core-notification-dialogue', function() {
|
||||
var panel = new M.core.dialogue({
|
||||
draggable: true,
|
||||
modal: true,
|
||||
closeButton: true,
|
||||
headerContent: s[0],
|
||||
bodyContent: el.html()
|
||||
});
|
||||
panel.show();
|
||||
$('#combinetags_form input[type=radio]').first().focus().prop('checked', true);
|
||||
$('#combinetags_form #combinetags_cancel').on('click', function() {
|
||||
panel.destroy();
|
||||
});
|
||||
$('#combinetags_form').on('submit', function() {
|
||||
tempElement.appendTo(form);
|
||||
var maintag = $('input[name=maintag]:checked', '#combinetags_form').val();
|
||||
$("<input type='hidden'/>").attr('name', 'maintag').attr('value', maintag).appendTo(form);
|
||||
form.submit();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -221,17 +224,20 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
|
||||
el.find('#addtags_form').attr('action', window.location.href);
|
||||
el.find('#addtags_submit').attr('value', s[2]);
|
||||
el.find('#addtags_cancel').attr('value', s[3]);
|
||||
var panel = new M.core.dialogue({
|
||||
draggable: true,
|
||||
modal: true,
|
||||
closeButton: true,
|
||||
headerContent: s[0],
|
||||
bodyContent: el.html()
|
||||
});
|
||||
panel.show();
|
||||
$('#addtags_form input[type=text]').focus();
|
||||
$('#addtags_form #addtags_cancel').on('click', function() {
|
||||
panel.destroy();
|
||||
// TODO: MDL-57778 Convert to core/modal.
|
||||
Y.use('moodle-core-notification-dialogue', function() {
|
||||
var panel = new M.core.dialogue({
|
||||
draggable: true,
|
||||
modal: true,
|
||||
closeButton: true,
|
||||
headerContent: s[0],
|
||||
bodyContent: el.html()
|
||||
});
|
||||
panel.show();
|
||||
$('#addtags_form input[type=text]').focus();
|
||||
$('#addtags_form #addtags_cancel').on('click', function() {
|
||||
panel.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -291,25 +297,28 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
|
||||
el.find('label[for="addtagcoll_searchable"]').html(s[2]);
|
||||
el.find('#addtagcoll_submit').attr('value', s[3]);
|
||||
el.find('#addtagcoll_cancel').attr('value', s[4]);
|
||||
var panel = new M.core.dialogue({
|
||||
draggable: true,
|
||||
modal: true,
|
||||
closeButton: true,
|
||||
headerContent: s[0],
|
||||
bodyContent: el.html()
|
||||
});
|
||||
panel.show();
|
||||
$('#addtagcoll_form #addtagcoll_name').focus();
|
||||
$('#addtagcoll_form #addtagcoll_cancel').on('click', function() {
|
||||
panel.destroy();
|
||||
});
|
||||
$('#addtagcoll_form').on('submit', function() {
|
||||
var name = $('#addtagcoll_form #addtagcoll_name').val();
|
||||
var searchable = $('#addtagcoll_form #addtagcoll_searchable').prop('checked') ? 1 : 0;
|
||||
if (String(name).length > 0) {
|
||||
window.location.href = href + "&name=" + encodeURIComponent(name) + "&searchable=" + searchable;
|
||||
}
|
||||
return false;
|
||||
// TODO: MDL-57778 Convert to core/modal.
|
||||
Y.use('moodle-core-notification-dialogue', function() {
|
||||
var panel = new M.core.dialogue({
|
||||
draggable: true,
|
||||
modal: true,
|
||||
closeButton: true,
|
||||
headerContent: s[0],
|
||||
bodyContent: el.html()
|
||||
});
|
||||
panel.show();
|
||||
$('#addtagcoll_form #addtagcoll_name').focus();
|
||||
$('#addtagcoll_form #addtagcoll_cancel').on('click', function() {
|
||||
panel.destroy();
|
||||
});
|
||||
$('#addtagcoll_form').on('submit', function() {
|
||||
var name = $('#addtagcoll_form #addtagcoll_name').val();
|
||||
var searchable = $('#addtagcoll_form #addtagcoll_searchable').prop('checked') ? 1 : 0;
|
||||
if (String(name).length > 0) {
|
||||
window.location.href = href + "&name=" + encodeURIComponent(name) + "&searchable=" + searchable;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -15,6 +15,9 @@ information provided here is intended especially for developers.
|
||||
* Some outdated global JS functions have been removed and should be replaced with calls to jquery or alternative approaches:
|
||||
checkall, checknone, select_all_in_element_with_id, select_all_in, deselect_all_in, confirm_if, findParentNode,
|
||||
filterByParent, stripHTML
|
||||
* The mcore YUI rollup which included various YUI modules such as moodle-core-notification is no longer included on every
|
||||
page. Missing YUI depdencies may be exposed by this change (e.g. missing a requirement on moodle-core-notification when
|
||||
using M.core.dialogue).
|
||||
|
||||
=== 3.2 ===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user