]> _ Git - cubist_cms-back.git/commitdiff
wip #3511 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Mar 2020 17:14:58 +0000 (18:14 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Mar 2020 17:14:58 +0000 (18:14 +0100)
src/app/CubistCrudRouter.php
src/app/Magic/Controllers/CubistMagicController.php
src/public/dropzone/dropzone.js
src/resources/views/fields/dropzone_media.blade.php

index 212f462e64ea9986b7abf1a17b1de7b35280d867..2d7845220387edfde50b20d922a174be62a15037 100644 (file)
@@ -30,6 +30,7 @@ class CubistCrudRouter extends CrudRouter
 
         Route::match(['post'], $this->name . '/{id}/media', $this->controller . '@uploadMedia');
         Route::match(['delete'], $this->name . '/{id}/media/{mediaId}', $this->controller . '@deleteMedia');
+        Route::match(['post'], $this->name . '/{id}/media/{mediaId}/alt', $this->controller . '@altMedia');
         Route::match(['post'], $this->name . '/{id}/media/reorder', $this->controller . '@reorderMedia');
     }
 }
index b22fbf5b1934ab8f29cc4ae73839e51716c0151b..c488d0fc8178b8004cb3fcc595c252c0a183bad8 100644 (file)
@@ -15,10 +15,12 @@ use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest;
 use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
 use Cubist\Backpack\CubistBackpackServiceProvider;
 use Gaspertrix\Backpack\DropzoneField\Traits\HandleAjaxMedia;
+use Illuminate\Http\Request;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\App;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Redirect;
+use Spatie\MediaLibrary\Models\Media;
 
 class CubistMagicController extends CubistCrudController
 {
@@ -147,7 +149,7 @@ class CubistMagicController extends CubistCrudController
         }
         $this->crud->addField($field->getDefinition(), $field->getCRUDForm());
 
-        $this->crud->orderFields(['id','variant']);
+        $this->crud->orderFields(['id', 'variant']);
 
         $this->_fields[$field->getAttribute('name')] = $field;
     }
@@ -317,4 +319,25 @@ class CubistMagicController extends CubistCrudController
         $this->_forgetCache();
         parent::saveReorder();
     }
+
+    /**
+     * Delete file from the medialibrary
+     *
+     * @param Request $request [description]
+     * @param int $id [description]
+     * @param int $mediaId [description]
+     * @return [type]           [description]
+     */
+    public function altMedia(Request $request, $id, $mediaId)
+    {
+        /** @var Media $media */
+        $media = Media::findOrFail($mediaId);
+        $media->setCustomProperty('alt', $request->get('alt'));
+        $media->save();
+
+        return response()->json([
+            'success' => true,
+            'message' => 'Alternative text updated'
+        ]);
+    }
 }
index 0743dfd40ef9f1b02fdf854a7eeb5515ecddffed..877901ca7c9021c8dffba3d7ad440e87cbeac4ff 100644 (file)
@@ -791,6 +791,8 @@ var Dropzone = function (_Emitter) {
                         file.previewElement = Dropzone.createElement(this.options.previewTemplate.trim());
                         file.previewTemplate = file.previewElement; // Backwards compatibility
 
+                        file.previewElement.setAttribute('data-alt', file.alt);
+
                         this.previewsContainer.appendChild(file.previewElement);
                         for (var _iterator3 = file.previewElement.querySelectorAll("[data-dz-name]"), _isArray3 = true, _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator](); ;) {
                             var _ref3;
index bd33cedd2e013332f88e69c5f21fb48aba2b9e88..c48afcd81ed802a6fef06969136f5c61e0943b3a 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? [];
-
+$baseUrl = url($crud->route . '/' . $entry->id . '/media');
 ?>
 @if(isset($entry))
     <div class="form-group col-md-12">
         <strong>{{ $field['label'] }}</strong> <br>
         <input type="hidden" value="{{$collection}}" name="{{$field['name']}}"/>
-        <div data-url="{{ url($crud->route . '/' . $entry->id . '/media') }}"
+        <div data-url="{{ $baseUrl }}"
              data-options='@json($field['options'])'
              class="dropzone dz-clickable sortable">
             <div class="dz-message">
@@ -22,8 +22,9 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
 
         <div id="dz-template-container" style="display: none;">
             <div class="dz-preview dz-file-preview">
-                <div data-dz-remove><span>+</span></div>
-                <div data-dz-download><i class="fa fa-arrow-down"></i></div>
+                <div data-dz-remove title="Supprimer"><span>+</span></div>
+                <div data-dz-alt title="Editer le texte alteratif"><i class="fa fa-pencil-square-o"></i></div>
+                <div data-dz-download title="Télécharger le fichier d'origine"><i class="fa fa-arrow-down"></i></div>
                 <div class="dz-image">
                     <img data-dz-thumbnail/>
                 </div>
@@ -101,7 +102,7 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
                     height: 26px;
                     border-radius: 3px 3px 0 0;
                     background: #b50005;
-                    z-index:21;
+                    z-index: 21;
                     cursor: pointer;
                 }
 
@@ -115,8 +116,10 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
                     font-weight: 700;
                     font-size: 24px;
                     line-height: 1em;
+                    cursor: pointer;
                 }
 
+
                 .dropzone .dz-preview [data-dz-download] {
                     position: absolute;
                     right: -13px;
@@ -129,7 +132,7 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
                     cursor: pointer;
                 }
 
-                .dropzone .dz-preview [data-dz-download] i {
+                .dropzone .dz-preview [data-dz-download] i, .dropzone .dz-preview [data-dz-alt] i {
                     display: block;
                     width: 26px;
                     height: 26px;
@@ -142,6 +145,22 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
                     cursor: pointer;
                 }
 
+                .dropzone .dz-preview [data-dz-alt] {
+                    position: absolute;
+                    right: -13px;
+                    top: 13px;
+                    width: 26px;
+                    height: 26px;
+                    background: #3c8dbc;
+                    z-index: 21;
+                    cursor: pointer;
+                }
+
+                .dropzone .dz-preview [data-dz-alt] i {
+                    position: relative;
+                    left: 2px;
+                }
+
                 .dropzone .dz-preview .dz-image {
                     background-color: #eee;
                 }
@@ -155,6 +174,7 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
             $files = [];
             $filesrand = 'files_' . rand(1, 10000);
             foreach ($entry->getAllMedia() as $media) {
+                /** @var \Spatie\MediaLibrary\Models\Media $media */
                 $collection = $media->collection_name;
                 if (!isset($files[$collection])) {
                     $files[$collection] = [];
@@ -164,6 +184,7 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
                     'order_column' => $media->order_column,
                     'size' => $media->size,
                     'name' => $media->file_name,
+                    'alt' => $media->getCustomProperty('alt'),
                     'full_url' => $media->getUrl(),
                     'thumb_url' => $media->getUrl($field['thumb_collection'] ?? ''),
                 ];
@@ -184,6 +205,34 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
                     Dropzone.autoDiscover = false;
                     var f_{{$filesrand}} = @json($files);
 
+                    $(document).on('click', '[data-dz-alt]', function () {
+                        var baseUrl = $(this).closest('.dropzone').attr('data-url');
+                        var t = window.prompt($(this).attr('title'), $(this).closest('[data-alt]').attr('data-alt'));
+                        var mediaId = $(this).closest('[data-id]').attr('data-id');
+                        if (t) {
+                            $(this).closest('[data-alt]').attr('data-alt', t);
+                            $.ajax({
+                                data: {alt: t},
+                                url: baseUrl + '/' + mediaId + '/alt',
+                                type: 'POST'
+                            }).done(function (response) {
+                                var notification_type;
+                                if (response.success == true) {
+                                    notification_type = 'success';
+                                } else {
+                                    notification_type = 'error';
+                                }
+
+                                new PNotify({
+                                    text: response.message,
+                                    type: notification_type,
+                                    icon: false
+                                });
+                            })
+
+                        }
+                    });
+
                     function initAllDropzones() {
                         $(".dropzone").each(function () {
                             if ($(this).closest('.sample').length === 0) {