| 1 |
// $Id$
|
| 2 |
(function ($) {
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Shows checked and disabled checkboxes for inherited permissions.
|
| 6 |
*/
|
| 7 |
Drupal.behaviors.permissions = {
|
| 8 |
attach: function (context) {
|
| 9 |
$('table#permissions:not(.permissions-processed)').each(function () {
|
| 10 |
// Create dummy checkboxes. We use dummy checkboxes instead of reusing
|
| 11 |
// the existing checkboxes here because new checkboxes don't alter the
|
| 12 |
// submitted form. If we'd automatically check existing checkboxes, the
|
| 13 |
// permission table would be polluted with redundant entries. This
|
| 14 |
// is deliberate, but desirable when we automatically check them.
|
| 15 |
$(':checkbox', this).not('[name^="2["]').not('[name^="1["]').each(function () {
|
| 16 |
$(this).addClass('real-checkbox');
|
| 17 |
$('<input type="checkbox" class="dummy-checkbox" disabled="disabled" checked="checked" />')
|
| 18 |
.attr('title', Drupal.t("This permission is inherited from the authenticated user role."))
|
| 19 |
.hide()
|
| 20 |
.insertAfter(this);
|
| 21 |
});
|
| 22 |
|
| 23 |
// Helper function toggles all dummy checkboxes based on the checkboxes'
|
| 24 |
// state. If the "authenticated user" checkbox is checked, the checked
|
| 25 |
// and disabled checkboxes are shown, the real checkboxes otherwise.
|
| 26 |
var toggle = function () {
|
| 27 |
$(this).closest('tr')
|
| 28 |
.find('.real-checkbox')[this.checked ? 'hide' : 'show']().end()
|
| 29 |
.find('.dummy-checkbox')[this.checked ? 'show' : 'hide']();
|
| 30 |
};
|
| 31 |
|
| 32 |
// Initialize the authenticated user checkbox.
|
| 33 |
$(':checkbox[name^="2["]', this)
|
| 34 |
.click(toggle)
|
| 35 |
.each(function () { toggle.call(this); });
|
| 36 |
}).addClass('permissions-processed');
|
| 37 |
}
|
| 38 |
};
|
| 39 |
|
| 40 |
})(jQuery);
|