From f6202531614a896ae010b7b4a66237acface6467 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 30 Aug 2022 19:41:57 +0200 Subject: [PATCH] wip #4216 @1 --- src/app/Magic/Fields/Files.php | 2 + .../views/fields/dropzone_media.blade.php | 96 ++++++++++++------- 2 files changed, 61 insertions(+), 37 deletions(-) diff --git a/src/app/Magic/Fields/Files.php b/src/app/Magic/Fields/Files.php index 85eb2d9..7a3c227 100644 --- a/src/app/Magic/Fields/Files.php +++ b/src/app/Magic/Fields/Files.php @@ -14,6 +14,7 @@ class Files extends Field protected $_databaseType = 'text'; protected $_thumbConversion = 'backpack_thumb'; protected $_nameAsCollection = false; + protected $_renameCollectionOnChange = false; protected $_maxFiles = 1; protected $_cast = 'string'; @@ -22,6 +23,7 @@ class Files extends Field $collection = '_TBD_'; return array_merge(parent::getDefaultAttributes(), [ 'name_as_collection' => $this->_nameAsCollection, + 'rename_collection_on_change' => $this->_renameCollectionOnChange, 'form' => 'update', 'collection' => $collection, 'thumb_conversion' => $this->_thumbConversion, diff --git a/src/resources/views/fields/dropzone_media.blade.php b/src/resources/views/fields/dropzone_media.blade.php index 0d072ea..6ea4d07 100644 --- a/src/resources/views/fields/dropzone_media.blade.php +++ b/src/resources/views/fields/dropzone_media.blade.php @@ -16,6 +16,7 @@ $blank = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAA
{{__('Drop files here or click to upload')}} @@ -158,54 +159,53 @@ $blank = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAA {{-- FIELD JS - will be loaded in the after_scripts section --}} @push('crud_fields_scripts') - 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 + ]; + } - ?> - + ?> +