admin_menu.admin.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @file
  3. */
  4. (function ($) {
  5. /**
  6. * Live preview of Administration menu components.
  7. */
  8. Drupal.behaviors.adminMenuLivePreview = {
  9. attach: function (context, settings) {
  10. $('input[name^="admin_menu_components"]', context).once('admin-menu-live-preview')
  11. .change(function () {
  12. var target = $(this).attr('rel');
  13. $(target).toggle(this.checked);
  14. })
  15. .trigger('change');
  16. }
  17. };
  18. /**
  19. * Automatically enables required permissions on demand.
  20. *
  21. * Many users do not understand that two permissions are required for the
  22. * administration menu to appear. Since Drupal core provides no facility for
  23. * this, we implement a simple manual confirmation for automatically enabling
  24. * the "other" permission.
  25. */
  26. Drupal.behaviors.adminMenuPermissionsSetupHelp = {
  27. attach: function (context, settings) {
  28. $('#permissions', context).once('admin-menu-permissions-setup', function () {
  29. // Retrieve matrix/mapping - these need to use the same indexes for the
  30. // same permissions and roles.
  31. var $roles = $(this).find('th:not(:first)');
  32. var $admin = $(this).find('input[name$="[access administration pages]"]');
  33. var $menu = $(this).find('input[name$="[access administration menu]"]');
  34. // Retrieve the permission label - without description.
  35. var adminPermission = $.trim($admin.eq(0).parents('td').prev().children().get(0).firstChild.textContent);
  36. var menuPermission = $.trim($menu.eq(0).parents('td').prev().children().get(0).firstChild.textContent);
  37. $admin.each(function (index) {
  38. // Only proceed if both are not enabled already.
  39. if (!(this.checked && $menu[index].checked)) {
  40. // Stack both checkboxes and attach a click event handler to both.
  41. $(this).add($menu[index]).click(function () {
  42. // Do nothing when disabling a permission.
  43. if (this.checked) {
  44. // Figure out which is the other, check whether it still disabled,
  45. // and if so, ask whether to auto-enable it.
  46. var other = (this == $admin[index] ? $menu[index] : $admin[index]);
  47. if (!other.checked && confirm(Drupal.t('Also allow @name role to @permission?', {
  48. '@name': $roles[index].textContent,
  49. '@permission': (this == $admin[index] ? menuPermission : adminPermission)
  50. }))) {
  51. other.checked = 'checked';
  52. }
  53. }
  54. });
  55. }
  56. });
  57. });
  58. }
  59. };
  60. })(jQuery);