Add permissions field (don't merge yet) (#850)

* Add permissions field

* Add new PERMISSIONS string, compile SCSS
This commit is contained in:
Flavio Copes
2016-11-28 19:01:01 +01:00
committed by GitHub
parent 0a06dbf1a0
commit 5966ed99e5
9 changed files with 84 additions and 12 deletions

View File

@@ -833,6 +833,10 @@ class AdminPlugin extends Plugin
'admin.login' => 'boolean',
'admin.cache' => 'boolean',
'admin.configuration' => 'boolean',
'admin.configuration_system' => 'boolean',
'admin.configuration_site' => 'boolean',
'admin.configuration_media' => 'boolean',
'admin.configuration_info' => 'boolean',
'admin.settings' => 'boolean',
'admin.pages' => 'boolean',
'admin.maintenance' => 'boolean',

View File

@@ -623,4 +623,6 @@ PLUGIN_ADMIN:
IMAGES_AUTO_FIX_ORIENTATION: "Fix orientation automatically"
IMAGES_AUTO_FIX_ORIENTATION_HELP: "Automatically fix the image orientation based on the Exif data"
REDIS_SOCKET: "Redis socket"
REDIS_SOCKET_HELP: "The Redis socket"
REDIS_SOCKET_HELP: "The Redis socket"
NOT_SET: "Not set"
PERMISSIONS: "Permissions"

View File

@@ -1,3 +1 @@
@import url("//fonts.googleapis.com/css?family=Montserrat:400|Lato:300,400,700|Inconsolata:400,700");body,h5,h6,.badge,.note,.grav-mdeditor-preview,input,select,textarea,button,.selectize-input{font-family:"Lato","Helvetica","Tahoma","Geneva","Arial",sans-serif}h1,h2,h3,h4,#admin-menu li,.form-tabs>label,.label{font-family:"Montserrat","Helvetica","Tahoma","Geneva","Arial",sans-serif}code,kbd,pre,samp,body .CodeMirror{font-family:"Inconsolata","Monaco","Consolas","Lucida Console",monospace !important}
/*# sourceMappingURL=fonts.css.map */

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +1 @@
body,h5,h6,.badge,.note,.grav-mdeditor-preview,input,select,textarea,button,.selectize-input,h1,h2,h3,h4,#admin-menu li,.form-tabs>label,.label{font-family:"Helvetica Neue", "Helvetica", "Tahoma", "Geneva", "Arial", sans-serif}code,kbd,pre,samp,body .CodeMirror{font-family:"Monaco", "Consolas", "Lucida Console", monospace}
/*# sourceMappingURL=simple-fonts.css.map */

File diff suppressed because one or more lines are too long

View File

@@ -584,4 +584,17 @@ textarea.frontmatter {
.filepicker-field-name {
vertical-align: middle;
}
.permissions-container {
.permission-value {
width: 50%;
float: left;
margin: 0 5px 5px 0;
height: 39px;
}
.switch-toggle label {
white-space: nowrap;
}
}

View File

@@ -0,0 +1,63 @@
{% extends "forms/field.html.twig" %}
{% set value = (value is null ? field.default : value) %}
{% set value = (value is same as(false) ? 0 : value) %}
{% block global_attributes %}
data-grav-disabled="{{ originalValue is null ? 'true' : 'false' }}"
data-grav-default="{{ field.default|json_encode()|e('html_attr') }}"
{% endblock %}
{% macro spanToggle(input, length) %}
{% set space = repeat('  ', (length - input|length) / 2) %}
{{ (space ~ input ~ space)|raw }}
{% endmacro %}
{% block input %}
<div class="permissions-container">
{% set permissions = admin.getPermissions %}
{% for index_existing_permission, value_existing_permission in value %}
{% for index_segment1, value_segment1 in value_existing_permission %}
{% set permissions = permissions|merge({ (index_existing_permission ~ "." ~ index_segment1): "boolean"}) %}
{% endfor %}
{% endfor %}
{% for permission, type in permissions %}
{% set permission_segments = permission|split('.') %}
{% set permission_value = value[permission_segments[0]][permission_segments[1]] %}
<input type="text" class="medium permission-value" value="{{ permission }}" />
<div class="switch-toggle switch-grav medium switch-3">
{% set options = { true: 'PLUGIN_ADMIN.YES', false: 'PLUGIN_ADMIN.NO', '': 'PLUGIN_ADMIN.NOT_SET' } %}
{% set maxLen = 0 %}
{% for value, text in options %}
{% set translation = grav.twig.twig.filters['tu'] is defined ? text|tu : text|t %}
{% set maxLen = max(translation|length, maxLen) %}
{% endfor %}
{% for key, text in options %}
{% set id = "toggle_" ~ field.name ~ "." ~ permission ~ key %}
{% set translation = (grav.twig.twig.filters['tu'] is defined ? text|tu : text|t)|trim %}
<input type="radio"
value="{{ key }}"
id="{{ id }}"
name="{{ (scope ~ field.name ~ "." ~ permission)|fieldName }}"
class="{{ 'true' == '' ~ key ? 'highlight' : '' }}"
{% if key|fieldName == '' ~ permission_value|fieldName %}
checked="checked"
{% endif %}
{% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
/>
<label for="{{ id }}">{{ (_self.spanToggle(translation, maxLen)|trim)|raw }}</label>
{% endfor %}
<a></a>
</div>
{% endfor %}
</div>
{% endblock %}