]> _ Git - extranet.git/commitdiff
wip #3546 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 1 Apr 2020 16:24:34 +0000 (18:24 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 1 Apr 2020 16:24:34 +0000 (18:24 +0200)
12 files changed:
app/Models/User.php
config/backpack/permissionmanager.php
database/migrations/2013_04_09_062329_create_revisions_table.php [new file with mode: 0644]
database/migrations/2020_04_01_150232_create_permission_tables.php [new file with mode: 0644]
resources/views/vendor/backpack/backupmanager/backup.blade.php [new file with mode: 0644]
resources/views/vendor/backpack/base/inc/sidebar_content.blade.php
resources/views/vendor/backpack/crud/buttons/quiz/download.blade.php [new file with mode: 0644]
resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php [new file with mode: 0644]
resources/views/vendor/backpack/crud/buttons/quiz/preview.blade.php [new file with mode: 0644]
resources/views/vendor/backpack/crud/fields/dropzone_media.blade.php [new file with mode: 0644]
routes/backpack/custom.php
routes/backpack/permissionmanager.php

index 1b23e1041f16946b45d2c35e9f5c29d4fc0d61e3..a77b969a613cbc5e84d7f43b92a06e805cd97915 100644 (file)
@@ -8,7 +8,7 @@ use Cubist\Backpack\app\Magic\Models\CubistMagicAuthenticatable;
 class User extends CubistMagicAuthenticatable
 {
     protected $table = 'user';
-    protected $_options = ['name' => 'user',
+    protected $_options = ['name' => 'users',
         'singular' => 'user',
         'plural' => 'users'];
 
index 1f0b4e75486b5f7d7c81aaf9da4168d05a2bcd04..6396f8d3be13a082a5d5340a81a55405dad8f08a 100644 (file)
@@ -3,9 +3,20 @@
 return [
 
     /*
-    | Backpack/PermissionManager configs.
+    |--------------------------------------------------------------------------
+    | Models
+    |--------------------------------------------------------------------------
+    |
+    | Models used in the User, Role and Permission CRUDs.
+    |
     */
 
+    'models' => [
+        'user'       => App\Models\User::class,
+        'permission' => Backpack\PermissionManager\app\Models\Permission::class,
+        'role'       => Backpack\PermissionManager\app\Models\Role::class,
+    ],
+
     /*
     |--------------------------------------------------------------------------
     | Disallow the user interface for creating/updating permissions or roles.
@@ -26,4 +37,12 @@ return [
     'allow_role_update'       => true,
     'allow_role_delete'       => true,
 
+    /*
+    |--------------------------------------------------------------------------
+    | Multiple-guards functionality
+    |--------------------------------------------------------------------------
+    |
+    */
+    'multiple_guards' => false,
+
 ];
diff --git a/database/migrations/2013_04_09_062329_create_revisions_table.php b/database/migrations/2013_04_09_062329_create_revisions_table.php
new file mode 100644 (file)
index 0000000..fdd5b1e
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+
+class CreateRevisionsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('revisions', function ($table) {
+            $table->increments('id');
+            $table->string('revisionable_type');
+            $table->integer('revisionable_id');
+            $table->integer('user_id')->nullable();
+            $table->string('key');
+            $table->text('old_value')->nullable();
+            $table->text('new_value')->nullable();
+            $table->timestamps();
+
+            $table->index(array('revisionable_id', 'revisionable_type'));
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('revisions');
+    }
+}
diff --git a/database/migrations/2020_04_01_150232_create_permission_tables.php b/database/migrations/2020_04_01_150232_create_permission_tables.php
new file mode 100644 (file)
index 0000000..8ad013b
--- /dev/null
@@ -0,0 +1,110 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreatePermissionTables extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        $tableNames = config('permission.table_names');
+        $columnNames = config('permission.column_names');
+
+        if (empty($tableNames)) {
+            throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding.');
+        }
+
+        Schema::create($tableNames['permissions'], function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->string('name');
+            $table->string('guard_name');
+            $table->timestamps();
+        });
+
+        Schema::create($tableNames['roles'], function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->string('name');
+            $table->string('guard_name');
+            $table->timestamps();
+        });
+
+        Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames) {
+            $table->unsignedBigInteger('permission_id');
+
+            $table->string('model_type');
+            $table->unsignedBigInteger($columnNames['model_morph_key']);
+            $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
+
+            $table->foreign('permission_id')
+                ->references('id')
+                ->on($tableNames['permissions'])
+                ->onDelete('cascade');
+
+            $table->primary(['permission_id', $columnNames['model_morph_key'], 'model_type'],
+                    'model_has_permissions_permission_model_type_primary');
+        });
+
+        Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) {
+            $table->unsignedBigInteger('role_id');
+
+            $table->string('model_type');
+            $table->unsignedBigInteger($columnNames['model_morph_key']);
+            $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
+
+            $table->foreign('role_id')
+                ->references('id')
+                ->on($tableNames['roles'])
+                ->onDelete('cascade');
+
+            $table->primary(['role_id', $columnNames['model_morph_key'], 'model_type'],
+                    'model_has_roles_role_model_type_primary');
+        });
+
+        Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {
+            $table->unsignedBigInteger('permission_id');
+            $table->unsignedBigInteger('role_id');
+
+            $table->foreign('permission_id')
+                ->references('id')
+                ->on($tableNames['permissions'])
+                ->onDelete('cascade');
+
+            $table->foreign('role_id')
+                ->references('id')
+                ->on($tableNames['roles'])
+                ->onDelete('cascade');
+
+            $table->primary(['permission_id', 'role_id'], 'role_has_permissions_permission_id_role_id_primary');
+        });
+
+        app('cache')
+            ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
+            ->forget(config('permission.cache.key'));
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        $tableNames = config('permission.table_names');
+
+        if (empty($tableNames)) {
+            throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
+        }
+
+        Schema::drop($tableNames['role_has_permissions']);
+        Schema::drop($tableNames['model_has_roles']);
+        Schema::drop($tableNames['model_has_permissions']);
+        Schema::drop($tableNames['roles']);
+        Schema::drop($tableNames['permissions']);
+    }
+}
diff --git a/resources/views/vendor/backpack/backupmanager/backup.blade.php b/resources/views/vendor/backpack/backupmanager/backup.blade.php
new file mode 100644 (file)
index 0000000..6484104
--- /dev/null
@@ -0,0 +1,134 @@
+@extends(backpack_view('layouts.top_left'))
+
+@php
+  $breadcrumbs = [
+    trans('backpack::crud.admin') => backpack_url('dashboard'),
+    trans('backpack::backup.backup') => false,
+  ];
+@endphp
+
+@section('header')
+    <section class="container-fluid">
+      <h2>
+        <span class="text-capitalize">{{ trans('backpack::backup.backup') }}</span>
+      </h2>
+    </section>
+@endsection
+
+@section('content')
+<!-- Default box -->
+  <button id="create-new-backup-button" href="{{ url(config('backpack.base.route_prefix', 'admin').'/backup/create') }}" class="btn btn-primary ladda-button mb-2" data-style="zoom-in"><span class="ladda-label"><i class="fa fa-plus"></i> {{ trans('backpack::backup.create_a_new_backup') }}</span></button>
+  <div class="card">
+    <div class="card-body p-0">
+      <table class="table table-hover pb-0 mb-0">
+        <thead>
+          <tr>
+            <th>#</th>
+            <th>{{ trans('backpack::backup.location') }}</th>
+            <th>{{ trans('backpack::backup.date') }}</th>
+            <th class="text-right">{{ trans('backpack::backup.file_size') }}</th>
+            <th class="text-right">{{ trans('backpack::backup.actions') }}</th>
+          </tr>
+        </thead>
+        <tbody>
+          @foreach ($backups as $k => $b)
+          <tr>
+            <th scope="row">{{ $k+1 }}</th>
+            <td>{{ $b['disk'] }}</td>
+            <td>{{ \Carbon\Carbon::createFromTimeStamp($b['last_modified'])->formatLocalized('%d %B %Y, %H:%M') }}</td>
+            <td class="text-right">{{ round((int)$b['file_size']/1048576, 2).' MB' }}</td>
+            <td class="text-right">
+                @if ($b['download'])
+                <a class="btn btn-sm btn-link" href="{{ url(config('backpack.base.route_prefix', 'admin').'/backup/download/') }}?disk={{ $b['disk'] }}&path={{ urlencode($b['file_path']) }}&file_name={{ urlencode($b['file_name']) }}"><i class="fa fa-cloud-download"></i> {{ trans('backpack::backup.download') }}</a>
+                @endif
+                <a class="btn btn-sm btn-link" data-button-type="delete" href="{{ url(config('backpack.base.route_prefix', 'admin').'/backup/delete/'.$b['file_name']) }}?disk={{ $b['disk'] }}"><i class="fa fa-trash-o"></i> {{ trans('backpack::backup.delete') }}</a>
+            </td>
+          </tr>
+          @endforeach
+        </tbody>
+      </table>
+
+    </div><!-- /.box-body -->
+  </div><!-- /.box -->
+
+@endsection
+
+@section('after_scripts')
+
+<script>
+  jQuery(document).ready(function($) {
+
+    // capture the Create new backup button
+    $("#create-new-backup-button").click(function(e) {
+        e.preventDefault();
+
+        var create_backup_url = $(this).attr('href');
+
+        // do the backup through ajax
+        $.ajax({
+            url: create_backup_url,
+            type: 'PUT',
+            success: function(result) {
+                // Show an alert with the result
+                if (result.indexOf('failed') >= 0) {
+                    new Noty({
+                        text: "<strong>{{ trans('backpack::backup.create_warning_title') }}</strong><br>{{ trans('backpack::backup.create_warning_message') }}",
+                        type: "warning"
+                    }).show();
+                }
+                else
+                {
+                    new Noty({
+                        text: "<strong>{{ trans('backpack::backup.create_confirmation_title') }}</strong><br>{{ trans('backpack::backup.create_confirmation_message') }}",
+                        type: "success"
+                    }).show();
+                }
+            },
+            error: function(result) {
+                // Show an alert with the result
+                new Noty({
+                    text: "<strong>{{ trans('backpack::backup.create_error_title') }}</strong><br>{{ trans('backpack::backup.create_error_message') }}",
+                    type: "warning"
+                }).show();
+            }
+        });
+    });
+
+    // capture the delete button
+    $("[data-button-type=delete]").click(function(e) {
+        e.preventDefault();
+        var delete_button = $(this);
+        var delete_url = $(this).attr('href');
+
+        if (confirm("{{ trans('backpack::backup.delete_confirm') }}") == true) {
+            $.ajax({
+                url: delete_url,
+                type: 'DELETE',
+                success: function(result) {
+                    // Show an alert with the result
+                    new Noty({
+                        text: "<strong>{{ trans('backpack::backup.delete_confirmation_title') }}</strong><br>{{ trans('backpack::backup.delete_confirmation_message') }}",
+                        type: "success"
+                    }).show();
+                    // delete the row from the table
+                    delete_button.parentsUntil('tr').parent().remove();
+                },
+                error: function(result) {
+                    // Show an alert with the result
+                    new Noty({
+                        text: "<strong>{{ trans('backpack::backup.delete_error_title') }}</strong><br>{{ trans('backpack::backup.delete_error_message') }}",
+                        type: "warning"
+                    }).show();
+                }
+            });
+        } else {
+            new Noty({
+                text: "<strong>{{ trans('backpack::backup.delete_cancel_title') }}</strong><br>{{ trans('backpack::backup.delete_cancel_message') }}",
+                type: "info"
+            }).show();
+        }
+      });
+
+  });
+</script>
+@endsection
index 80f09b34a0997a0b816d53360c19889172f19168..07fb54d4679d8292d161a1de3c4597fe06657643 100644 (file)
@@ -1,2 +1,49 @@
 <!-- This file is used to store sidebar items, starting with Backpack\Base 0.9.0 -->
-<li class="nav-item"><a class="nav-link" href="{{ backpack_url('dashboard') }}"><i class="fa fa-dashboard nav-icon"></i> {{ trans('backpack::base.dashboard') }}</a></li>
\ No newline at end of file
+<li class="nav-item"><a class="nav-link" href="{{ backpack_url('dashboard') }}"><i
+            class="fa fa-dashboard nav-icon"></i> {{ trans('backpack::base.dashboard') }}</a></li>
+
+
+<li class='nav-item nav-dropdown open'><a class='nav-link nav-dropdown-toggle' href='#'><i
+            class='nav-icon fa fa-question'></i>Quiz</a>
+    <ul class='nav-dropdown-items'>
+        <li class="nav-item"><a class="nav-link" href="{{ backpack_url('quiz') }}"><i
+                    class="fa fa-table nav-icon"></i> Quizzes</a></li>
+        <li class="nav-item"><a class="nav-link" href="{{ backpack_url('quiztranslation') }}"><i
+                    class="fa fa-language nav-icon"></i> Translations</a></li>
+    </ul>
+</li>
+@can('maintenance')
+    <li class='nav-item nav-dropdown'><a class='nav-link nav-dropdown-toggle' href='#'><i
+                class='nav-icon fa fa-cogs'></i>Maintenance</a>
+        <ul class='nav-dropdown-items'>
+            <li class="nav-item"><a class="nav-link" href='{{ backpack_url('backup') }}'><i class='fa fa-hdd-o'></i>
+                    <span>Backups</span></a>
+            </li>
+            <li class="nav-item"><a class="nav-link" href='{{ backpack_url('log') }}'><i class='fa fa-terminal'></i>
+                    <span>Logs</span></a>
+            </li>
+        </ul>
+    </li>
+@endcan
+{{--@can('manageusers')--}}
+    <li class='nav-item nav-dropdown'><a class='nav-link nav-dropdown-toggle' href='#'><i
+                class='nav-icon fa fa-group'></i>Clients</a>
+        <ul class='nav-dropdown-items'>
+            <li class='nav-item'><a class='nav-link' href='{{ backpack_url('users') }}'><i
+                        class='nav-icon fa fa-user'></i><span>Users</span></a></li>
+            <li class='nav-item'><a class='nav-link' href='{{ backpack_url('company') }}'><i
+                        class='nav-icon fa fa-building'></i>
+                    <span>Companies</span></a></li>
+        </ul>
+    </li>
+    <li class='nav-item nav-dropdown'><a class='nav-link nav-dropdown-toggle' href='#'><i
+                class='nav-icon fa fa-lock'></i>Authentication</a>
+        <ul class='nav-dropdown-items'>
+            <li class='nav-item'><a class='nav-link' href='{{ backpack_url('role') }}'><i
+                        class='nav-icon fa fa-group'></i>
+                    <span>Roles</span></a></li>
+            <li class='nav-item'><a class='nav-link' href='{{ backpack_url('permission') }}'><i
+                        class='nav-icon fa fa-key'></i><span>Permissions</span></a></li>
+        </ul>
+    </li>
+{{--@endcan--}}
diff --git a/resources/views/vendor/backpack/crud/buttons/quiz/download.blade.php b/resources/views/vendor/backpack/crud/buttons/quiz/download.blade.php
new file mode 100644 (file)
index 0000000..669e481
--- /dev/null
@@ -0,0 +1,2 @@
+<a class="btn btn-sm btn-link" href="{{$crud->route}}/{{$entry->getKey()}}/download" data-toggle="tooltip"
+   title="Download quiz"><i class="fa fa-arrow-circle-down"></i> Download</a>
diff --git a/resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php b/resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php
new file mode 100644 (file)
index 0000000..d642525
--- /dev/null
@@ -0,0 +1,25 @@
+<form method="post" enctype="multipart/form-data" action="{{$crud->route}}/import"
+      style="visibility:hidden;height:1px;position:absolute;top:0;" id="uploadimportform">
+    @csrf
+    <input type="file" name="file[]" multiple="multiple" id="uploadimport" accept="application/zip">
+</form>
+<a class="btn btn-primary" href="#" data-toggle="tooltip" title="Import" id="uploadimportbutton"><i
+        class="fa fa-upload"></i> Import</a>
+
+
+@push('after_scripts')
+    <script>
+        (function ($) {
+            $(function () {
+                $(document).on('click', "#uploadimportbutton", function () {
+                    $("#uploadimport").click();
+                    return false;
+                });
+
+                $(document).on('change', '#uploadimportform', function () {
+                    $("#uploadimportform").submit();
+                })
+            });
+        })(jQuery);
+    </script>
+@endpush
diff --git a/resources/views/vendor/backpack/crud/buttons/quiz/preview.blade.php b/resources/views/vendor/backpack/crud/buttons/quiz/preview.blade.php
new file mode 100644 (file)
index 0000000..87fa740
--- /dev/null
@@ -0,0 +1,3 @@
+<a class="btn btn-sm btn-link iframe" data-featherlight="iframe" data-featherlight-iframe-width="800"
+   data-featherlight-iframe-height="600" href="{{$crud->route}}/{{$entry->getKey()}}/preview/index.html"
+   data-toggle="tooltip" title="Preview quiz"><i class="fa fa-eye"></i> Preview</a>
diff --git a/resources/views/vendor/backpack/crud/fields/dropzone_media.blade.php b/resources/views/vendor/backpack/crud/fields/dropzone_media.blade.php
new file mode 100644 (file)
index 0000000..6aee771
--- /dev/null
@@ -0,0 +1,227 @@
+@section('previewTemplate')
+<div class="dz-preview dz-file-preview">
+       <div class="dz-image">
+               <img data-dz-thumbnail />
+       </div>
+       <div class="dz-details">
+               <div class="dz-size">
+                       <span data-dz-size></span>
+               </div>
+               <div class="dz-filename">
+                       <span data-dz-name></span>
+               </div>
+       </div>
+       <div class="dz-progress">
+               <span class="dz-upload" data-dz-uploadprogress></span>
+       </div>
+       <div class="dz-error-message">
+               <span data-dz-errormessage></span>
+       </div>
+       <div class="dz-success-mark">
+               <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
+                       <title>Check</title>
+                       <defs></defs>
+                       <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
+                               <path d="M23.5,31.8431458 L17.5852419,25.9283877 C16.0248253,24.3679711 13.4910294,24.366835 11.9289322,25.9289322 C10.3700136,27.4878508 10.3665912,30.0234455 11.9283877,31.5852419 L20.4147581,40.0716123 C20.5133999,40.1702541 20.6159315,40.2626649 20.7218615,40.3488435 C22.2835669,41.8725651 24.794234,41.8626202 26.3461564,40.3106978 L43.3106978,23.3461564 C44.8771021,21.7797521 44.8758057,19.2483887 43.3137085,17.6862915 C41.7547899,16.1273729 39.2176035,16.1255422 37.6538436,17.6893022 L23.5,31.8431458 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z" id="Oval-2" stroke-opacity="0.198794158" stroke="#747474" fill-opacity="0.816519475" fill="#FFFFFF" sketch:type="MSShapeGroup"></path>
+                       </g>
+               </svg>
+       </div>
+       <div class="dz-error-mark">
+               <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
+                       <title>Error</title>
+                       <defs></defs>
+                       <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
+                               <g id="Check-+-Oval-2" sketch:type="MSLayerGroup" stroke="#747474" stroke-opacity="0.198794158" fill="#FFFFFF" fill-opacity="0.816519475">
+                                       <path d="M32.6568542,29 L38.3106978,23.3461564 C39.8771021,21.7797521 39.8758057,19.2483887 38.3137085,17.6862915 C36.7547899,16.1273729 34.2176035,16.1255422 32.6538436,17.6893022 L27,23.3431458 L21.3461564,17.6893022 C19.7823965,16.1255422 17.2452101,16.1273729 15.6862915,17.6862915 C14.1241943,19.2483887 14.1228979,21.7797521 15.6893022,23.3461564 L21.3431458,29 L15.6893022,34.6538436 C14.1228979,36.2202479 14.1241943,38.7516113 15.6862915,40.3137085 C17.2452101,41.8726271 19.7823965,41.8744578 21.3461564,40.3106978 L27,34.6568542 L32.6538436,40.3106978 C34.2176035,41.8744578 36.7547899,41.8726271 38.3137085,40.3137085 C39.8758057,38.7516113 39.8771021,36.2202479 38.3106978,34.6538436 L32.6568542,29 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z" id="Oval-2" sketch:type="MSShapeGroup"></path>
+                               </g>
+                       </g>
+               </svg>
+       </div>
+</div>
+@endsection
+
+<div class="form-group col-md-12">
+       <strong>{{ $field['label'] }}</strong> <br>
+       <div id="dropzone_{{ $field['name'] }}" class="dropzone dz-clickable sortable">
+           <div class="dz-message">
+               Drop files here or click to upload.
+           </div>
+       </div>
+</div>
+
+{{-- ########################################## --}}
+{{-- Extra CSS and JS for this particular field --}}
+{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}}
+@if ($crud->checkIfFieldIsFirstOfItsType($field, $fields))
+    {{-- FIELD CSS - will be loaded in the after_styles section --}}
+    @push('crud_fields_styles')
+        <!-- include dropzone css-->
+        <link rel="stylesheet" href="{{ asset('vendor/gaspertrix/laravel-backpack-dropzone-field/dropzone/dropzone.min.css') }}" />
+    @endpush
+
+    {{-- FIELD JS - will be loaded in the after_scripts section --}}
+    @push('crud_fields_scripts')
+        <!-- include dropzone js-->
+        <script src="{{ asset('vendor/gaspertrix/laravel-backpack-dropzone-field/dropzone/dropzone.min.js') }}"></script>
+        <script src="{{ asset('vendor/gaspertrix/laravel-backpack-dropzone-field/sortable/Sortable.min.js') }}"></script>
+    @endpush
+
+@endif
+
+@push('crud_fields_scripts')
+       <script type="text/javascript">
+               jQuery(document).ready(function() {
+                       Dropzone.autoDiscover = false;
+
+                       var dOptions = {
+                               url: "{{ url($crud->route . '/' . $entry->id . '/media') }}",
+                               previewTemplate: '{!! str_replace(array("\r\n", "\r", "\n"), "", addslashes(View::getSection("previewTemplate"))); !!}',
+                               init: function() {
+                                       var files = [];
+
+                                       @foreach ($entry->getMedia($field['collection']) as $media)
+                                       files.push({id: {{ $media->id }}, order_column: {{ $media->order_column }}, size: "{{ $media->size }}", name: "{{ $media->file_name }}", full_url: "{{ $media->getUrl() }}", thumb_url: "{{ $media->getUrl($field['thumb_collection'] ?? '') }}"});
+                                       @endforeach
+
+                                       for (var i = 0; i < files.length; i++) {
+                                               var file = files[i];
+
+                                               this.emit('addedfile', file);
+
+                                               if (typeof file.full_url != 'undefined') {
+                                                       this.emit('thumbnail', file, file.full_url);
+                                               }
+
+                                               this.emit('success', file, {success:true, media: file});
+                                               this.emit('complete', file);
+                                       }
+
+                                       if (this.options.maxFiles !== null) {
+                                               this.options.maxFiles = this.options.maxFiles - files.length;
+                                       }
+                               },
+                               sending: function(file, xhr, formData) {
+                               formData.append('_token', $('meta[name="csrf-token"]').attr('content'));
+
+                               @if (isset($field['collection']) AND !empty($field['collection']))
+                               formData.append('collection', "{{ $field['collection'] }}");
+                               @endif
+                           },
+                           success: function(file, response) {
+                               if (typeof response != 'undefined' && response.success == true) {
+                                               file.media = response.media;
+                                               file.previewElement.setAttribute('data-id', response.media.id);
+                                               file.previewElement.setAttribute('data-position', response.media.order_column);
+                                       }
+
+                                       if (file.previewElement) {
+                                               return file.previewElement.classList.add("dz-success");
+                                       }
+                       },
+                       removedfile: function(file) {
+                               if (typeof file.media != 'undefined') {
+                                       $.ajax({
+                                                       url: "{{ url($crud->route . '/' . $entry->id . '/media') }}" + '/' + file.media.id,
+                                                       type: 'DELETE'
+                                               })
+                                               .done(function(response) {
+                                                       var notification_type;
+
+                                                       if (response.success == true) {
+                                                               notification_type = 'success';
+
+                                                               if (file.previewElement != null && file.previewElement.parentNode != null) {
+                                                               file.previewElement.parentNode.removeChild(file.previewElement);
+                                                       }
+                                                       }
+                                                       else {
+                                                               notification_type = 'error';
+                                                       }
+
+                                                       new Noty({
+                                                               text: response.message,
+                                                               type: notification_type,
+                                                               icon: false
+                                                       });
+                                               })
+                                               .fail(function (xhr) {
+                                                       var message = 'Deletion failed';
+
+                                                       if (xhr.responseJSON != 'undefined' && xhr.responseJSON.message != 'undefined') {
+                                                               message = xhr.responseJSON.message;
+                                                       }
+
+                                                       new Noty({
+                                                               text: message,
+                                                               type: 'error',
+                                                               icon: false
+                                                       });
+                                               });
+
+                                               return this._updateMaxFilesReachedClass();
+                               }
+
+                               if (file.previewElement != null && file.previewElement.parentNode != null) {
+                                       file.previewElement.parentNode.removeChild(file.previewElement);
+                               }
+
+                               return this._updateMaxFilesReachedClass();
+                       },
+                       };
+
+                       var cOptions = @json($field['options']);
+
+                       var dropzone_{{ $field['name'] }} = new Dropzone("#dropzone_{{ $field['name'] }}", jQuery.extend(dOptions, cOptions));
+
+                       var dropzone_{{ $field['name'] }}_sortable = new Sortable(document.getElementById("dropzone_{{ $field['name'] }}"), {
+                   handle: ".dz-preview",
+                   draggable: ".dz-preview",
+                   onEnd: function(evt) {
+                       var ids = this.toArray();
+
+                       if (ids.length > 0) {
+                               $.ajax({
+                                                       url: "{{ url($crud->route . '/' . $entry->id . '/media/reorder') }}",
+                                                       type: 'POST',
+                                                       data: {
+                                                               ids: ids
+                                                       }
+                                               })
+                                               .done(function(response) {
+                                                       var notification_type;
+
+                                                       if (response.success != true) {
+                                                               var message = 'Order failed';
+
+                                                               if (response.message != 'undefined') {
+                                                                       message = response.message;
+                                                               }
+
+                                                               new Noty({
+                                                                       text: message,
+                                                                       type: 'error',
+                                                                       icon: false
+                                                               });
+                                                       }
+
+                               
+                                               })
+                                               .fail(function (xhr) {
+                                                       var message = 'Order failed';
+
+                                                       if (xhr.responseJSON != 'undefined' && xhr.responseJSON.message != 'undefined') {
+                                                               message = xhr.responseJSON.message;
+                                                       }
+
+                                                       new Noty({
+                                                               text: message,
+                                                               type: 'error',
+                                                               icon: false
+                                                       });
+                                               });
+                       }
+                   }
+               });
+               });
+       </script>
+@endpush
\ No newline at end of file
index 687539b47bb40ca4166c74211f88617d96dba97b..7c43ebfc5a8e0742070804b22a91cc5da90b5076 100644 (file)
@@ -1,12 +1,16 @@
 <?php
 Route::group([
-    'prefix'     => config('backpack.base.route_prefix', 'admin'),
+    'prefix' => config('backpack.base.route_prefix', 'admin'),
     'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
-    'namespace'  => 'App\Http\Controllers\Admin',
+    'namespace' => 'App\Http\Controllers\Admin',
 ], function () { // custom admin routes
-     Route::crud('company', 'CompanyCrudController');
-     Route::crud('locale', 'LocaleCrudController');
-     Route::crud('page', 'PageCrudController');
-     Route::crud('settings', 'SettingsCrudController');
-     Route::crud('user', 'UserCrudController');
+    try {
+        Route::crud('locale', 'LocaleCrudController');
+        Route::crud('settings', 'SettingsCrudController');
+        Route::crud('page', 'PageCrudController');
+        Route::crud('company', 'CompanyCrudController');
+        Route::crud('users', 'UsersCrudController');
+    } catch (\Throwable $e) {
+
+    }
 });
index de224a8922a888257b4a9ead8ea19878da5cd142..4577d6da0436f83dd9547bbca46a6edad3cc2845 100644 (file)
@@ -13,7 +13,7 @@
 Route::group([
     'namespace' => 'Backpack\PermissionManager\app\Http\Controllers',
     'prefix' => config('backpack.base.route_prefix', 'admin'),
-    'middleware' => ['web', backpack_middleware(), 'can:manageusers'],
+    'middleware' => ['web', backpack_middleware()/*, 'can:manageusers'*/],
 ], function () {
     Route::crud('permission', 'PermissionCrudController');
     Route::crud('role', 'RoleCrudController');