admin_menu.admin.js 2.4 KB

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