MINOR Rewrite of PermissionCheckboxSetField.js from Behaviour.js to jQuery.entwine

This commit is contained in:
Ingo Schommer 2011-03-16 14:18:30 +13:00
parent efe710e2d3
commit 2b7c633e6e
2 changed files with 14 additions and 9 deletions

View File

@ -1,14 +1,13 @@
(function($) { (function($) {
Behaviour.register({
$.entwine('ss', function($){
/** /**
* Automatically check and disable all checkboxes if ADMIN permissions are selected. * 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), * As they're disabled, any changes won't be submitted (which is intended behaviour),
* checking all boxes is purely presentational. * checking all boxes is purely presentational.
*/ */
'.permissioncheckboxset .valADMIN input': { $('.permissioncheckboxset .valADMIN input').entwine({
initialize: function() {
this.toggleCheckboxes();
},
onclick: function(e) { onclick: function(e) {
this.toggleCheckboxes(); this.toggleCheckboxes();
}, },
@ -32,20 +31,21 @@
}); });
} }
} }
}, });
/** /**
* Automatically check all "CMS section" checkboxes when "Access to all CMS interfaces" is ticked. * 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 * @todo This should really be abstracted into a declarative dependency system
* instead of custom logic. * instead of custom logic.
*/ */
'.permissioncheckboxset .valCMS_ACCESS_LeftAndMain input': { $('.permissioncheckboxset .valCMS_ACCESS_LeftAndMain input').entwine({
getCheckboxesExceptThisOne: function() { getCheckboxesExceptThisOne: function() {
return $(this).parents('.field:eq(0)').find('li').filter(function(i) { return $(this).parents('.field:eq(0)').find('li').filter(function(i) {
return ($(this).attr('class').match(/CMS_ACCESS_/)); return ($(this).attr('class').match(/CMS_ACCESS_/));
}).find('.checkbox').not(this); }).find('.checkbox').not(this);
}, },
initialize: function() { onmatch: function() {
var checkboxes = this.getCheckboxesExceptThisOne(); var checkboxes = this.getCheckboxesExceptThisOne();
if($(this).is(':checked')) { if($(this).is(':checked')) {
checkboxes.each(function() { checkboxes.each(function() {
@ -53,6 +53,8 @@
$(this).attr('checked', 'checked'); $(this).attr('checked', 'checked');
}); });
} }
this._super();
}, },
onclick: function(e) { onclick: function(e) {
var checkboxes = this.getCheckboxesExceptThisOne(); var checkboxes = this.getCheckboxesExceptThisOne();
@ -68,6 +70,7 @@
}); });
} }
} }
} });
}); });
}(jQuery)); }(jQuery));

View File

@ -60,6 +60,8 @@ class Group extends DataObject {
* @return FieldSet * @return FieldSet
*/ */
public function getCMSFields() { public function getCMSFields() {
Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js');
$fields = new FieldSet( $fields = new FieldSet(
new TabSet("Root", new TabSet("Root",
new Tab('Members', _t('SecurityAdmin.MEMBERS', 'Members'), new Tab('Members', _t('SecurityAdmin.MEMBERS', 'Members'),