Allow to change the permissions for users.

This commit is contained in:
Jan Böhmer 2019-09-10 17:12:56 +02:00
parent 8e61b06abc
commit 7390f2eccd
18 changed files with 933 additions and 8 deletions

View file

@ -44,4 +44,68 @@
</div>
</div>
{{ form_errors(form.value) }}
{% endblock %}
{% endblock %}
{#######################################################################################
#
# Definitions for Tristate Checkbox Type (mostly based on bootstrap checkbox type)
#
#######################################################################################}
{% block tristate_label -%}
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
{%- if widget is defined -%}
{% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) %}
{% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class) %}
{%- if is_parent_custom or is_custom -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%}
{%- else %}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%}
{%- endif %}
{%- if not compound -%}
{% set label_attr = label_attr|merge({'for': id}) %}
{%- endif -%}
{%- if required -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
{%- endif -%}
{%- if parent_label_class is defined -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%}
{%- endif -%}
{%- if label is not same as(false) and label is empty -%}
{%- if label_format is not empty -%}
{%- set label = label_format|replace({
'%name%': name,
'%id%': id,
}) -%}
{%- else -%}
{%- set label = name|humanize -%}
{%- endif -%}
{%- endif -%}
{{ widget|raw }}
<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
{{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain)) -}}
{{- form_errors(form) -}}
</label>
{%- endif -%}
{%- endblock tristate_label %}
{%- block tr_parent -%}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}{% if indeterminate %} indeterminate="indeterminate"{% endif %} />
{%- endblock tr_parent -%}
{% block tristate_widget -%}
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
{%- if 'checkbox-custom' in parent_label_class -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
<div class="custom-control custom-checkbox{{ 'checkbox-inline' in parent_label_class ? ' custom-control-inline' }}">
{{- form_label(form, null, { widget: block('tr_parent') }) -}}
</div>
{%- else -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
<div class="form-check{{ 'checkbox-inline' in parent_label_class ? ' form-check-inline' }}">
{{- form_label(form, null, { widget: block('tr_parent') }) -}}
</div>
{%- endif -%}
{%- endblock tristate_widget %}

View file

@ -0,0 +1,52 @@
{% block permission_row %}
<tr>
<td>
<b>{{ form.vars.label | trans }}</b>
{{ form_errors(form) }}
</td>
<td>
{% for op in form %}
{{ form_widget(op) }}
{{ form_errors(op) }}
{% endfor %}
</td>
</tr>
{% endblock %}
{% block permission_group_row %}
{{ form_errors(form) }}
<table class="table table-bordered table-sm">
<thead>
<tr>
<th>{% trans %}permission.edit.permission{% endtrans %}</th>
<th>{% trans %}permission.edit.value{% endtrans %}</th>
</tr>
</thead>
<tbody>
{% for perm in form %}
{{ form_row(perm) }}
{% endfor %}
</tbody>
</table>
{% endblock %}
{% block permissions_row %}
<ul class="nav nav-tabs">
{% for group in form %}
<li class="nav-item">
<a class="nav-link {% if loop.first %}active{% endif %}"
data-toggle="tab" role="tab" href="#group_row_{{ group.vars.name }}">{{ group.vars.label | trans }}</a>
</li>
{% endfor %}
</ul>
<div class="tab-content mt-2">
{% for group in form %}
<div class="tab-pane {% if loop.first %}active{% endif %}" id="group_row_{{ group.vars.name }}">
{{ form_row(group) }}
</div>
{% endfor %}
</div>
{% endblock %}