From cdaa423a130de40e367d276b73a0fb14d3201811 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 4 Jul 2019 21:53:32 +0200 Subject: [PATCH] #2843 --- .../Magic/Fields/BunchOfFieldsMultiple.php | 2 +- src/app/Magic/Fields/Files.php | 2 +- .../Magic/Models/CubistMagicAbstractModel.php | 13 +++++++-- src/public/bunchmultiple/bunchmultiple.js | 7 ++++- .../views/fields/dropzone_media.blade.php | 29 ++++++++++++++----- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/app/Magic/Fields/BunchOfFieldsMultiple.php b/src/app/Magic/Fields/BunchOfFieldsMultiple.php index c81fbe3..09d779d 100644 --- a/src/app/Magic/Fields/BunchOfFieldsMultiple.php +++ b/src/app/Magic/Fields/BunchOfFieldsMultiple.php @@ -28,7 +28,7 @@ class BunchOfFieldsMultiple extends BunchOfFields break; } - $this->setAttribute('edit_label', 'Éditer « %' . $first . ' »'); + $this->setAttributeIfNotSet('edit_label', 'Éditer « %' . $first . ' »'); } protected function _setBunchOfFields() diff --git a/src/app/Magic/Fields/Files.php b/src/app/Magic/Fields/Files.php index 6f32e00..0b2f521 100644 --- a/src/app/Magic/Fields/Files.php +++ b/src/app/Magic/Fields/Files.php @@ -17,7 +17,7 @@ class Files extends Field public function getDefaultAttributes() { - $collection = hash('sha256', 'c_' . rand(1, 10000000000000)); + $collection = '_TBD_'; return array_merge(parent::getDefaultAttributes(), [ 'form' => 'update', 'mime_types' => $this->_mimeTypes, diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 5c420f0..2dc95fb 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -198,9 +198,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia if (!in_array($store_in, $this->translatable)) { $this->translatable[] = $store_in; } - if (!in_array($name, $this->translatable)) { - $this->translatable[] = $name; - } } if (!in_array($store_in, $this->fakeColumns)) { @@ -518,4 +515,14 @@ class CubistMagicAbstractModel extends Model implements HasMedia { } + + public function getDecodedAttributes(){ + $res=new \stdClass(); + foreach ($this->attributes as $key=>$value) { + $res->$key=Json::decodeRecursive($this->getAttribute($key),Json::TYPE_OBJECT); + } + $res->entity=$this; + return $res; + } + } diff --git a/src/public/bunchmultiple/bunchmultiple.js b/src/public/bunchmultiple/bunchmultiple.js index cd07fc9..ecd03fe 100644 --- a/src/public/bunchmultiple/bunchmultiple.js +++ b/src/public/bunchmultiple/bunchmultiple.js @@ -43,7 +43,7 @@ this.initSort(); - this.element.on('change', 'input,select,textarea', function () { + this.element.on('change', 'input,select,textarea,.dropzone', function () { $this.update(); return true; }); @@ -120,11 +120,16 @@ initItem: function (values) { var collapsed = true; + var isNew = false; if (values === undefined) { values = []; collapsed = false; + isNew = true; } var item = this.element.find('.sample').clone(false); + if (isNew) { + $(item).find('[data-reset-value]').val(''); + } $(item).removeClass('sample'); if (collapsed) { $(item).addClass('collapsed'); diff --git a/src/resources/views/fields/dropzone_media.blade.php b/src/resources/views/fields/dropzone_media.blade.php index f75a599..9d1a5e2 100644 --- a/src/resources/views/fields/dropzone_media.blade.php +++ b/src/resources/views/fields/dropzone_media.blade.php @@ -99,7 +99,7 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? font-weight: 700; font-size: 24px; line-height: 1em; - z-index:11; + z-index: 11; transform: rotate(45deg); cursor: pointer; } @@ -143,14 +143,24 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? jQuery(document).ready(function () { + var uniqid = function () { + return (new Date().getTime() + Math.floor((Math.random() * 10000) + 1)).toString(16); + }; + Dropzone.autoDiscover = false; var f_{{$filesrand}} = @json($files); function initAllDropzones() { - $(".dropzone").each(function () { - if ($(this).data('dropzone') === undefined) { - $(this).attr('id', 'dz-' + Math.round(Math.random() * 10000000)); - $(this).data('dropzone', initOneDropzone(this)); + $(".dropzone").each(function (){ + if($(this).closest('.sample').length===0) { + var collectionInput = $(this).prev('input'); + if (collectionInput.val() === '_TBD_') { + collectionInput.val(uniqid()); + } + if ($(this).data('dropzone') === undefined) { + $(this).attr('id', 'dz-' + Math.round(Math.random() * 10000000)); + $(this).data('dropzone', initOneDropzone(this)); + } } }); } @@ -163,6 +173,8 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? var dOptions = { url: base_url, previewTemplate: $("#dz-template-container").html(), + + init: function () { var files = f_{{$filesrand}}[collection]; if (files === undefined) { @@ -187,6 +199,7 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? } }, sending: function (file, xhr, formData) { + console.log(this); formData.append('_token', $('meta[name="csrf-token"]').attr('content')); if (collection !== undefined && collection !== null && collection !== '') { formData.append('collection', collection); @@ -198,7 +211,7 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? file.previewElement.setAttribute('data-id', response.media.id); file.previewElement.setAttribute('data-position', response.media.order_column); } - +$(this.element).trigger('change'); if (file.previewElement) { return file.previewElement.classList.add("dz-success"); } @@ -241,14 +254,14 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? icon: false }); }); - + $(this.element).trigger('change'); return this._updateMaxFilesReachedClass(); } if (file.previewElement != null && file.previewElement.parentNode != null) { file.previewElement.parentNode.removeChild(file.previewElement); } - + $(this.element).trigger('change'); return this._updateMaxFilesReachedClass(); }, }; -- 2.39.5