]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 4 Jul 2019 19:53:32 +0000 (21:53 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 4 Jul 2019 19:53:32 +0000 (21:53 +0200)
src/app/Magic/Fields/BunchOfFieldsMultiple.php
src/app/Magic/Fields/Files.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/public/bunchmultiple/bunchmultiple.js
src/resources/views/fields/dropzone_media.blade.php

index c81fbe3e852533a715d22ab280db596ee3a90f28..09d779da7c4b7d56aaf6bd2bd3780efc298d7b87 100644 (file)
@@ -28,7 +28,7 @@ class BunchOfFieldsMultiple extends BunchOfFields
             break;
         }
 
-        $this->setAttribute('edit_label', 'Éditer « %' . $first . ' »');
+        $this->setAttributeIfNotSet('edit_label', 'Éditer « %' . $first . ' »');
     }
 
     protected function _setBunchOfFields()
index 6f32e00c1a7cbfbe409d170e123053ab575fe466..0b2f5211a2834025d035bac4dfc77d65f53aa41b 100644 (file)
@@ -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,
index 5c420f004f531f73093683aff15cbfdc42ad2bd1..2dc95fbacfb35d3f531b624b40c9b5ca586dbb9b 100644 (file)
@@ -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;
+    }
+
 }
index cd07fc99eaf396b23f8edb6f5a4d22ad70e5a613..ecd03fef07f94e77634110880840ac731c5aacf0 100644 (file)
@@ -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;
             });
 
         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');
index f75a5991b4a257d87c66d45f1dc8b09199c6b76b..9d1a5e265a8b42a0c961fa5d7a071b38b964bf58 100644 (file)
@@ -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();
                         },
                     };