});
}
- $('.checkgroup').closest('ul').each(function(){
- var master = $(this),
- tools = $('<ul class="object-tools"><li><a href="#" class="checkall">Check All</a></li><li><a href="#">Uncheck All</a></li></ul>');
- master.before(tools).addClass('checkgroup_master');
- tools.find('a').click(function(){
- var check = $(this).hasClass('checkall');
- master.find('input').prop('checked', check);
+ $('.admincheckgroup').each(function(){
+ var group = $(this);
+ group.find('.object-tools .checkall').click(function(){
+ group.find('.checkgroup input').prop('checked', true);
+ return false;
+ });
+ group.find('.object-tools .uncheckall').click(function(){
+ group.find('.checkgroup input').prop('checked', false);
return false;
});
});
--- /dev/null
+<?php
+
+class IPF_Admin_Form_Field_MultipleChoice extends IPF_Form_Field_MultipleChoice
+{
+ public $widget = 'IPF_Admin_Form_Widget_SelectMultipleInputCheckbox';
+}
--- /dev/null
+<?php
+
+use \PFF\HtmlBuilder\Tag as Tag;
+
+class IPF_Admin_Form_Widget_SelectMultipleInputCheckbox extends IPF_Form_Widget_SelectMultipleInput
+{
+ public function render($name, $value, $extra_attrs=array())
+ {
+ if ($value === null || $value == '')
+ $value = array();
+
+ $wrapper = Tag::div()
+ ->attr('class', 'admincheckgroup');
+
+ $tools = Tag::ul(['class' => 'object-tools'],
+ Tag::li(null,
+ Tag::a(['href' => '#', 'class' => 'checkall'], 'Check All')
+ ),
+ Tag::li(null,
+ Tag::a(['href' => '#', 'class' => 'uncheckall'], 'Uncheck All')
+ )
+ );
+ $wrapper->append($tools);
+
+ $checkgroup = Tag::ul()
+ ->attrs($this->attrs)
+ ->attrs($extra_attrs)
+ ->attr('class', 'checkgroup checkgroup_master');
+ foreach ($this->choices as $option_label => $option_value) {
+ $checkgroup->append(Tag::li(null,
+ Tag::label(null,
+ Tag::input()
+ ->attr('type', 'checkbox')
+ ->attr('name', "{$name}[]")
+ ->attr('value', $option_value)
+ ->toggleAttr('checked', 'checked', in_array($option_value, $value)),
+ ' ',
+ $option_label)));
+ }
+ $wrapper->append($checkgroup);
+
+ return $wrapper->html();
+ }
+
+ public function idForLabel($id)
+ {
+ return null;
+ }
+}
$permissions[] = 'permissions';
$permissions[] = 'roles';
- $this->fields['permissions'] = new \IPF_Form_Field_MultipleChoice(array(
+ $this->fields['permissions'] = new \IPF_Admin_Form_Field_MultipleChoice(array(
'label' => __('Permissions'),
'choices' => $permissions_choices,
- 'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
- 'widget_attrs' => array('class' => 'checkgroup'),
));
- $this->fields['roles'] = new \IPF_Form_Field_MultipleChoice(array(
+ $this->fields['roles'] = new \IPF_Admin_Form_Field_MultipleChoice(array(
'label' => __('Groups'),
'help_text' => __('In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.'),
'choices' => array_column(Role::all(), 'id', 'name'),
- 'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
- 'widget_attrs' => array('class' => 'checkgroup'),
));
}
));
if ($auth_app->arePermissionsEnabled()) {
- $this->fields['permissions'] = new \IPF_Form_Field_MultipleChoice(array(
+ $this->fields['permissions'] = new \IPF_Admin_Form_Field_MultipleChoice(array(
'label' => __('Permissions'),
'choices' => $permissions_choices,
- 'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
- 'widget_attrs' => array('class' => 'checkgroup'),
));
}
}