Index: modules/user/access_control.js =================================================================== RCS file: modules/user/access_control.js diff -N modules/user/access_control.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/user/access_control.js 20 Oct 2006 12:36:39 -0000 @@ -0,0 +1,65 @@ +// $Id$ + +// Initialize the variables +Drupal.extend({ settings: { user: { accessControl: { } } } }); + +/** + * Callback function that is attached to a change of a checkbox of the "authenticated user" column. + * It changes the state of all custom roles to either checked or the previous state. + */ +Drupal.accessControlToggle = function() { + var matches = this.id.match(/^edit-(\d+?)-(.*)$/i), roles = Drupal.settings.user.accessControl[matches[2]]; + + for (var i in roles) { + var checkbox = document.getElementById('edit-' + i + '-' + matches[2]); + checkbox.disabled = this.checked; + checkbox.checked = this.checked ? true : roles[i]; + } +}; + +/** + * Updates the status of a role in the array when the user changes the checkbox. + */ +Drupal.accessControlUpdate = function() { + var matches = this.id.match(/^edit-(\d+?)-(.*)$/i); + Drupal.settings.user.accessControl[matches[2]][matches[1]] = this.checked; +} + +/** + * Stores the state of each checkbox before applying onchange handlers to each + * checkbox. + */ +Drupal.accessControlAttach = function() { + var settings = Drupal.settings.user.accessControl; + + $('#permissions input').each(function() { + var matches = this.id.match(/^edit-(\d+?)-(.*)$/i); + + if (matches[1] > 2) { // all custom roles + if (!settings[matches[2]]) settings[matches[2]] = {}; + settings[matches[2]][matches[1]] = this.checked; + $(this).change(Drupal.accessControlUpdate); + } + }); + + $('#permissions input[@id^="edit-2-"]').each(function() { + $(this).change(Drupal.accessControlToggle); + Drupal.accessControlToggle.apply(this); + }); + + $('#user_admin_perm').submit(function() { + for (var role in settings) { + for (var i in settings[role]) { + var checkbox = document.getElementById('edit-' + i + '-' + role); + checkbox.checked = settings[role][i]; + checkbox.disabled = false; + } + } + }); +}; + + +if (Drupal.jsEnabled) { + $(document).ready(Drupal.accessControlAttach); +} + Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.692 diff -u -d -F^\s*function -r1.692 user.module --- modules/user/user.module 18 Oct 2006 11:46:18 -0000 1.692 +++ modules/user/user.module 20 Oct 2006 12:36:45 -0000 @@ -1798,6 +1798,8 @@ function user_admin_perm($rid = NULL) { } $form['submit'] = array('#type' => 'submit', '#value' => t('Save permissions')); + drupal_add_js(drupal_get_path('module', 'user') .'/access_control.js', 'module'); + return $form; }