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
{
}
$this->crud->addField($field->getDefinition(), $field->getCRUDForm());
- $this->crud->orderFields(['id','variant']);
+ $this->crud->orderFields(['id', 'variant']);
$this->_fields[$field->getAttribute('name')] = $field;
}
$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'
+ ]);
+ }
}
<?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">
<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>
height: 26px;
border-radius: 3px 3px 0 0;
background: #b50005;
- z-index:21;
+ z-index: 21;
cursor: pointer;
}
font-weight: 700;
font-size: 24px;
line-height: 1em;
+ cursor: pointer;
}
+
.dropzone .dz-preview [data-dz-download] {
position: absolute;
right: -13px;
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;
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;
}
$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] = [];
'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'] ?? ''),
];
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) {