From 2b7c633e6ee740ca323741283f6281e74ec42d3f Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 16 Mar 2011 14:18:30 +1300 Subject: [PATCH] MINOR Rewrite of PermissionCheckboxSetField.js from Behaviour.js to jQuery.entwine --- javascript/PermissionCheckboxSetField.js | 21 ++++++++++++--------- security/Group.php | 2 ++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/javascript/PermissionCheckboxSetField.js b/javascript/PermissionCheckboxSetField.js index 2d6a6e72a..5fdcb210f 100644 --- a/javascript/PermissionCheckboxSetField.js +++ b/javascript/PermissionCheckboxSetField.js @@ -1,14 +1,13 @@ (function($) { - Behaviour.register({ + + $.entwine('ss', function($){ + /** * 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(); - }, + $('.permissioncheckboxset .valADMIN input').entwine({ onclick: function(e) { this.toggleCheckboxes(); }, @@ -32,20 +31,21 @@ }); } } - }, + }); + /** * Automatically check all "CMS section" checkboxes when "Access to all CMS interfaces" is ticked. * * @todo This should really be abstracted into a declarative dependency system * instead of custom logic. */ - '.permissioncheckboxset .valCMS_ACCESS_LeftAndMain input': { + $('.permissioncheckboxset .valCMS_ACCESS_LeftAndMain input').entwine({ getCheckboxesExceptThisOne: function() { return $(this).parents('.field:eq(0)').find('li').filter(function(i) { return ($(this).attr('class').match(/CMS_ACCESS_/)); }).find('.checkbox').not(this); }, - initialize: function() { + onmatch: function() { var checkboxes = this.getCheckboxesExceptThisOne(); if($(this).is(':checked')) { checkboxes.each(function() { @@ -53,6 +53,8 @@ $(this).attr('checked', 'checked'); }); } + + this._super(); }, onclick: function(e) { var checkboxes = this.getCheckboxesExceptThisOne(); @@ -68,6 +70,7 @@ }); } } - } + }); + }); }(jQuery)); \ No newline at end of file diff --git a/security/Group.php b/security/Group.php index 83db2c043..375225e81 100644 --- a/security/Group.php +++ b/security/Group.php @@ -60,6 +60,8 @@ class Group extends DataObject { * @return FieldSet */ public function getCMSFields() { + Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js'); + $fields = new FieldSet( new TabSet("Root", new Tab('Members', _t('SecurityAdmin.MEMBERS', 'Members'),