diff --git a/javascript/PermissionCheckboxSetField.js b/javascript/PermissionCheckboxSetField.js new file mode 100644 index 000000000..b141eb9ae --- /dev/null +++ b/javascript/PermissionCheckboxSetField.js @@ -0,0 +1,34 @@ +(function($) { + Behaviour.register({ + /** + * Automatically check and disable all checkboxes if ADMIN permissions are selected. + * As they're disabled, any changes won't be submitted (which is intended behaviour), + * checking all boxes is purely presentational. + */ + '.permissioncheckboxset .valADMIN input': { + initialize: function() { + this.toggleCheckboxes(); + }, + onclick: function(e) { + this.toggleCheckboxes(); + }, + toggleCheckboxes: function() { + var checkboxes = $(this).parents('.field:eq(0)').find('.checkbox').not(this); + + if($(this).is(':checked')) { + checkboxes.each(function() { + $(this).data('SecurityAdmin.oldChecked', $(this).attr('checked')); + $(this).data('SecurityAdmin.oldDisabled', $(this).attr('disabled')); + $(this).attr('disabled', 'disabled'); + $(this).attr('checked', 'checked'); + }); + } else { + checkboxes.each(function() { + $(this).attr('checked', $(this).data('SecurityAdmin.oldChecked')); + $(this).attr('disabled', $(this).data('SecurityAdmin.oldDisabled')); + }); + } + } + } + }); +}(jQuery)); \ No newline at end of file diff --git a/security/PermissionCheckboxSetField.php b/security/PermissionCheckboxSetField.php index 53d4d0067..f93d94eb0 100644 --- a/security/PermissionCheckboxSetField.php +++ b/security/PermissionCheckboxSetField.php @@ -72,6 +72,7 @@ class PermissionCheckboxSetField extends FormField { function Field() { Requirements::css(SAPPHIRE_DIR . '/css/CheckboxSetField.css'); + Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js'); $uninheritedCodes = array(); $inheritedCodes = array();