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