From: Andrey Kutejko Date: Mon, 16 Apr 2018 07:45:27 +0000 (+0200) Subject: admin multiplechoice widget X-Git-Tag: 0.6~13 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=e0dacacfef0c51f9a3c4e74f750ed43043c093d9;p=ipf.git admin multiplechoice widget --- diff --git a/ipf/admin/assets/js/admin.js b/ipf/admin/assets/js/admin.js index 94432e7..7afafd5 100644 --- a/ipf/admin/assets/js/admin.js +++ b/ipf/admin/assets/js/admin.js @@ -51,13 +51,14 @@ $(function(){ }); } - $('.checkgroup').closest('ul').each(function(){ - var master = $(this), - tools = $(''); - 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; }); }); diff --git a/ipf/admin/form/fields/multiplechoice.php b/ipf/admin/form/fields/multiplechoice.php new file mode 100644 index 0000000..0b3cdd5 --- /dev/null +++ b/ipf/admin/form/fields/multiplechoice.php @@ -0,0 +1,6 @@ +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; + } +} diff --git a/ipf/auth/admin.php b/ipf/auth/admin.php index c8ad689..f60fd0b 100644 --- a/ipf/auth/admin.php +++ b/ipf/auth/admin.php @@ -70,19 +70,15 @@ class UserForm extends \IPF_ObjectForm $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'), )); } @@ -297,11 +293,9 @@ class RoleForm extends \IPF_ObjectForm )); 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'), )); } }