From 07adfb2ff166ce873bb6329f7a6a39f20e857fd8 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 13 Apr 2019 12:07:27 +0100 Subject: [PATCH] Added select-all helpers to permission tables --- resources/assets/js/components/index.js | 2 + .../assets/js/components/permissions-table.js | 39 ++++++++++++++++ resources/assets/sass/_components.scss | 7 +++ resources/lang/en/common.php | 1 + .../views/form/entity-permissions.blade.php | 14 ++++-- resources/views/settings/roles/form.blade.php | 46 ++++++++++++++----- 6 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 resources/assets/js/components/permissions-table.js diff --git a/resources/assets/js/components/index.js b/resources/assets/js/components/index.js index e2749797e..355b96473 100644 --- a/resources/assets/js/components/index.js +++ b/resources/assets/js/components/index.js @@ -22,6 +22,7 @@ import headerMobileToggle from "./header-mobile-toggle"; import listSortControl from "./list-sort-control"; import triLayout from "./tri-layout"; import breadcrumbListing from "./breadcrumb-listing"; +import permissionsTable from "./permissions-table"; const componentMapping = { 'dropdown': dropdown, @@ -48,6 +49,7 @@ const componentMapping = { 'list-sort-control': listSortControl, 'tri-layout': triLayout, 'breadcrumb-listing': breadcrumbListing, + 'permissions-table': permissionsTable, }; window.components = {}; diff --git a/resources/assets/js/components/permissions-table.js b/resources/assets/js/components/permissions-table.js new file mode 100644 index 000000000..96d95bb3d --- /dev/null +++ b/resources/assets/js/components/permissions-table.js @@ -0,0 +1,39 @@ + +class PermissionsTable { + + constructor(elem) { + this.container = elem; + + // Handle toggle all event + const toggleAll = elem.querySelector('[permissions-table-toggle-all]'); + toggleAll.addEventListener('click', this.toggleAllClick.bind(this)); + + // Handle toggle row event + const toggleRowElems = elem.querySelectorAll('[permissions-table-toggle-all-in-row]'); + for (let toggleRowElem of toggleRowElems) { + toggleRowElem.addEventListener('click', this.toggleRowClick.bind(this)); + } + } + + toggleAllClick(event) { + event.preventDefault(); + this.toggleAllInElement(this.container); + } + + toggleRowClick(event) { + event.preventDefault(); + this.toggleAllInElement(event.target.closest('tr')); + } + + toggleAllInElement(domElem) { + const inputsToSelect = domElem.querySelectorAll('input[type=checkbox]'); + const currentState = inputsToSelect.length > 0 ? inputsToSelect[0].checked : false; + for (let checkbox of inputsToSelect) { + checkbox.checked = !currentState; + checkbox.dispatchEvent(new Event('change')); + } + } + +} + +export default PermissionsTable; \ No newline at end of file diff --git a/resources/assets/sass/_components.scss b/resources/assets/sass/_components.scss index 044b8ec10..33bc5e71d 100644 --- a/resources/assets/sass/_components.scss +++ b/resources/assets/sass/_components.scss @@ -646,4 +646,11 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group { #tag-manager .drag-card { max-width: 500px; +} + +.permissions-table [permissions-table-toggle-all-in-row] { + display: none; +} +.permissions-table tr:hover [permissions-table-toggle-all-in-row] { + display: inline; } \ No newline at end of file diff --git a/resources/lang/en/common.php b/resources/lang/en/common.php index 332a9a6d9..c821ecc7e 100644 --- a/resources/lang/en/common.php +++ b/resources/lang/en/common.php @@ -11,6 +11,7 @@ return [ 'save' => 'Save', 'continue' => 'Continue', 'select' => 'Select', + 'toggle_all' => 'Toggle All', 'more' => 'More', // Form Labels diff --git a/resources/views/form/entity-permissions.blade.php b/resources/views/form/entity-permissions.blade.php index bb7d992f7..6bb4b51ad 100644 --- a/resources/views/form/entity-permissions.blade.php +++ b/resources/views/form/entity-permissions.blade.php @@ -11,16 +11,20 @@ ]) - {{--TODO - Add global and role "Select All" options--}} - - +
- + @foreach($roles as $role) - + @if(!$model->isA('page')) diff --git a/resources/views/settings/roles/form.blade.php b/resources/views/settings/roles/form.blade.php index 67b4ec058..d3c1d9070 100644 --- a/resources/views/settings/roles/form.blade.php +++ b/resources/views/settings/roles/form.blade.php @@ -1,7 +1,5 @@ {!! csrf_field() !!} -{{--TODO - Add select-all shortcuts--}} -

{{ $title }}

@@ -30,9 +28,10 @@
-
+
+ {{ trans('common.toggle_all') }}
@include('settings.roles.checkbox', ['permission' => 'users-manage', 'label' => trans('settings.role_manage_users')])
@@ -51,16 +50,21 @@

{{ trans('settings.role_asset_admins') }}

@endif -
{{ trans('common.role') }}isA('page')) colspan="3" @else colspan="4" @endif>{{ trans('common.actions') }}isA('page')) colspan="3" @else colspan="4" @endif> + {{ trans('common.actions') }} + {{ trans('common.toggle_all') }} +
{{ $role->display_name }} + {{ $role->display_name }} + {{ trans('common.toggle_all') }} + @include('form.restriction-checkbox', ['name'=>'restrictions', 'label' => trans('common.view'), 'action' => 'view'])@include('form.restriction-checkbox', ['name'=>'restrictions', 'label' => trans('common.create'), 'action' => 'create'])
+
- + - + @@ -81,7 +85,10 @@ - + @@ -102,7 +109,10 @@ - + - + - + - + - +
+ {{ trans('common.toggle_all') }} + {{ trans('common.create') }} {{ trans('common.view') }} {{ trans('common.edit') }} {{ trans('common.delete') }}
{{ trans('entities.shelves_long') }} +
{{ trans('entities.shelves_long') }}
+ {{ trans('common.toggle_all') }} +
@include('settings.roles.checkbox', ['permission' => 'bookshelf-create-all', 'label' => trans('settings.role_all')])
{{ trans('entities.books') }} +
{{ trans('entities.books') }}
+ {{ trans('common.toggle_all') }} +
@include('settings.roles.checkbox', ['permission' => 'book-create-all', 'label' => trans('settings.role_all')])
{{ trans('entities.chapters') }} +
{{ trans('entities.chapters') }}
+ {{ trans('common.toggle_all') }} +
@include('settings.roles.checkbox', ['permission' => 'chapter-create-own', 'label' => trans('settings.role_own')])
@@ -125,7 +135,10 @@
{{ trans('entities.pages') }} +
{{ trans('entities.pages') }}
+ {{ trans('common.toggle_all') }} +
@include('settings.roles.checkbox', ['permission' => 'page-create-own', 'label' => trans('settings.role_own')])
@@ -148,7 +161,10 @@
{{ trans('entities.images') }} +
{{ trans('entities.images') }}
+ {{ trans('common.toggle_all') }} +
@include('settings.roles.checkbox', ['permission' => 'image-create-all', 'label' => '']) {{ trans('settings.role_controlled_by_asset') }} @@ -163,7 +179,10 @@
{{ trans('entities.attachments') }} +
{{ trans('entities.attachments') }}
+ {{ trans('common.toggle_all') }} +
@include('settings.roles.checkbox', ['permission' => 'attachment-create-all', 'label' => '']) {{ trans('settings.role_controlled_by_asset') }} @@ -178,7 +197,10 @@
{{ trans('entities.comments') }} +
{{ trans('entities.comments') }}
+ {{ trans('common.toggle_all') }} +
@include('settings.roles.checkbox', ['permission' => 'comment-create-all', 'label' => '']) {{ trans('settings.role_controlled_by_asset') }}