Commit e7ecb4a9 authored by Dan Poltawski's avatar Dan Poltawski

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.
parent 0053c77d
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
......@@ -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'));
// 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'
});
}
panel.set('headerContent', M.util.get_string('role' + action + 'header', 'core_role'));
var i, existingrolelinks;
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 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);
}
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);
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();
};
......
......@@ -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 ===
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment