<input type="hidden" value="{{$collection}}" name="{{$field['name']}}"/>
<div data-url="{{ url($crud->route . '/' . $entry->id . '/media') }}"
data-options='@json($field['options'])'
+ data-rename-on-change="{{$field['rename_collection_on_change']}}"
class="dropzone dz-clickable sortable">
<div class="dz-message">
{{__('Drop files here or click to upload')}}
{{-- FIELD JS - will be loaded in the after_scripts section --}}
@push('crud_fields_scripts')
- <?php
+ <?php
+ $files = [];
+ $filesrand = 'files_' . rand(1, 10000);
+ foreach ($entry->getAllMedia() as $media) {
+ $collection = $media->collection_name;
+ if (!isset($files[$collection])) {
+ $files[$collection] = [];
+ }
- $files = [];
- $filesrand = 'files_' . rand(1, 10000);
- foreach ($entry->getAllMedia() as $media) {
- $collection = $media->collection_name;
- if (!isset($files[$collection])) {
- $files[$collection] = [];
- }
-
- $full = null;
- $thumb_url = null;
-
- try {
- $full = $media->getUrl();
- } catch (Exception $e) {
- $full = '';
- }
-
- $e = explode('.', $full);
- $ext = mb_strtolower(array_pop($e));
+ $full = null;
+ $thumb_url = null;
- if (in_array($ext, $images)) {
try {
- $thumb_url = $media->getUrl($field['thumb_conversion'] ?? null);
+ $full = $media->getUrl();
} catch (Exception $e) {
+ $full = '';
+ }
+
+ $e = explode('.', $full);
+ $ext = mb_strtolower(array_pop($e));
+
+ if (in_array($ext, $images)) {
+ try {
+ $thumb_url = $media->getUrl($field['thumb_conversion'] ?? null);
+ } catch (Exception $e) {
+ }
+ }
+ if (!isset($thumb_url)) {
+ $thumb_url = $blank;
}
- }
- if (!isset($thumb_url)) {
- $thumb_url = $blank;
- }
- $files[$collection][] = [
- 'id' => $media->id,
- 'order_column' => $media->order_column,
- 'size' => $media->size,
- 'name' => $media->file_name,
- 'full_url' => $full,
- 'thumb_url' => $thumb_url
- ];
- }
+ $files[$collection][] = [
+ 'id' => $media->id,
+ 'order_column' => $media->order_column,
+ 'size' => $media->size,
+ 'name' => $media->file_name,
+ 'full_url' => $full,
+ 'thumb_url' => $thumb_url
+ ];
+ }
- ?>
- <!-- include dropzone js-->
+ ?>
+ <!-- include dropzone js-->
<script src="{{ vendor_asset('vendor/cubist/cms-back/dropzone/dropzone.js') }}"></script>
<script src="{{ vendor_asset('vendor/cubist/cms-back/sortable/sortable.js') }}"></script>
<script type="text/javascript">
});
}
+ function onDropzoneChange(el) {
+ if ($(el).attr('data-rename-on-change') === '1') {
+ var uid = uniqid();
+ $(el).prev('input').val(uid);
+ return uid;
+ }
+ return false;
+ }
+
function initOneDropzone(el) {
el = $(el);
var base_url = el.data('url');
},
sending: function (file, xhr, formData) {
formData.append('_token', $('meta[name="csrf-token"]').attr('content'));
+ var ncoll = onDropzoneChange(el);
+ if (ncoll !== false) {
+ collection = ncoll;
+ }
+
if (collection !== undefined && collection !== null && collection !== '') {
formData.append('collection', collection);
}
}
},
removedfile: function (file) {
+ var ncoll = onDropzoneChange(this.element);
+ if (ncoll !== false) {
+ collection = ncoll;
+ }
+
+
if (typeof file.media != 'undefined') {
$.ajax({
url: base_url + '/' + file.media.id,
}).show();
});
+
var dropzone_sortable = new Sortable(document.getElementById(el_id), {
handle: ".dz-preview",
draggable: ".dz-preview",
return dropzone;
}
+
initAllDropzones();
$(document).on('cubist.bunchmultiple.added', function () {
initAllDropzones();