Skip to content

Commit

Permalink
Add component to manage checkbox lists
Browse files Browse the repository at this point in the history
  • Loading branch information
stolman-digitpaint committed Apr 19, 2022
1 parent 0463c95 commit 7271f94
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 77 deletions.
47 changes: 47 additions & 0 deletions views/fields/checkbox_list.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[% IF ! hide_group %]
<div class="form-item">
[% END %]
<fieldset class="fieldset" data-name="[% fieldset_name %]">
<div class="fieldset__legend ">
<legend>[% INCLUDE fields/sub/filter.tt value=label; %]</legend>
[% IF popover_body; INCLUDE fields/sub/popover.tt popover_id=id popover_body=popover_body; END; %]
</div>
[% IF help_text %]
<p id="[% id %]-help" class="form-text">
[% help_text | html %]
</p>
[% END %]
<div class="list [% list_class %]">
<ul class="list__items" id="[% id %]">
[%
IF !message_empty OR items.size;
FOREACH item IN items;
%]
<li class="list__item">
[%
INCLUDE fields/sub/checkbox.tt
id = item.field_id
name = name
label = item.name
value = item.id
custom_classes = custom_classes
checked = item.is_checked
is_disabled = item.is_disabled
popover_body = "";
%]
</li>
[%
END;
ELSE;
%]
<li class="list__item">
[% message_empty %]
</li>
[%- END -%]
</ul>
</div>
</fieldset>
[% INCLUDE snippets/subfield.tt %]
[% IF ! hide_group %]
</div>
[% END %]
51 changes: 18 additions & 33 deletions views/snippets/user_column_groups.tt
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
[%- column_class = column_class ? column_class : 'col' -%]
<div class="[% column_class %]">
<fieldset class="fieldset" data-name="groups">
<div class="fieldset__legend ">
<legend>Add this user to the following groups</legend>
</div>

<div class="list [% list_class %]">
<ul class="list__items">
[% IF groups.size %]
[% FOREACH group IN groups %]
<li class="list__item">
[%-
key = group.id;

INCLUDE fields/sub/checkbox.tt
id = "group_" _ group.id
name = "groups"
label = group.name
value = group.id
checked = edituser.has_group.$key ? 1 : 0
is_disabled = ! user.permission.superadmin AND ! user.has_group.$key
filter = "html";
-%]
</li>
[%- END -%]
[%- ELSE -%]
<li class="list__item">
No groups have been created yet. Groups can be
created in the <a href="[% url.page %]/group_overview/">Manage Groups</a> menu.
</li>
[%- END -%]
</ul>
</div>
</fieldset>
[%
FOREACH group IN groups;
key = group.id;
group.field_id = "groups_" _ item.id
group.is_checked = edituser.has_group.$key ? 1 : 0;
group.is_disabled = ! user.permission.superadmin AND ! user.has_group.$key ? 1 : 0;
END;

INCLUDE fields/checkbox_list.tt
fieldset_name = "groups"
list_class = list_class
name = "groups"
label = "Add this user to the following groups"
items = groups
filter = "html"
message_empty = "No groups have been created yet. Groups can be created in the <a href='" _ url.page _ "/group_overview/'>Groups</a> menu."
hide_group = 1;
%]
</div>
72 changes: 28 additions & 44 deletions views/snippets/user_column_permissions.tt
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,32 @@
';
-%]
<div class="[% column_class %]">
<fieldset class="fieldset" data-name="permissions">
<div class="fieldset__legend ">
<legend>User' system wide permissions</legend>

[% INCLUDE fields/sub/popover.tt popover_id="permissions_popover" popover_title=permissions_help_title popover_body=permissions_help_body; %]
</div>

<div class="list [% list_class %]">
<ul class="list__items">
<li class="list__item">
[%-
INCLUDE fields/sub/checkbox.tt
id = "super_administrator"
name = "permission"
label = "Super-administrator"
value = "superadmin"
checked = edituser.permission.superadmin ? 1 : 0;
-%]
</li>

<li class="list__item">
[%-
INCLUDE fields/sub/checkbox.tt
id = "user_can_manage_other_accounts"
name = "permission"
label = "User can manage other user accounts"
value = "useradmin"
checked = edituser.permission.useradmin ? 1 : 0;
-%]
</li>

<li class="list__item">
[%-
INCLUDE fields/sub/checkbox.tt
id = "user_can_access_audit_data"
name = "permission"
label = "User can access audit data"
value = "audit"
checked = edituser.permission.audit ? 1 : 0;
-%]
</li>
</ul>
</div>
</fieldset>
[%
INCLUDE fields/checkbox_list.tt
fieldset_name = "permissions"
list_class = list_class
name = "permission"
label = "User' system wide permissions"
items = [{
id = "superadmin",
name = "Super-administrator",
field_id = "super_administrator",
is_checked = edituser.permission.superadmin ? 1 : 0
}, {
id = "superadmin",
name = "User can manage other user accounts",
field_id = "user_can_manage_other_accounts",
is_checked = edituser.permission.useradmin ? 1 : 0
}, {
id = "audit",
name = "User can access audit data",
field_id = "user_can_access_audit_data",
is_checked = edituser.permission.audit ? 1 : 0
}]
filter = "html"
popover_id = "permissions_popover"
popover_title = permissions_help_title
popover_body = permissions_help_body
hide_group = 1;
%]
</div>

0 comments on commit 7271f94

Please sign in to comment.