MDL-57690 js: fix core modal uses in amd
[moodle.git] / lib / amd / src / permissionmanager.js
index 3cb6034..6c76ec4 100644 (file)
@@ -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();
     };