]> _ Git - cubist_cms-back.git/commitdiff
wip #3531 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 30 Mar 2020 18:35:53 +0000 (20:35 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 30 Mar 2020 18:35:53 +0000 (20:35 +0200)
composer.json
src/app/Console/Commands/MigrateCommand.php
src/public/bunchmultiple/bunchmultiple.js
src/resources/views/fields/dropzone_media.blade.php

index 25f53a0813c9e315d084f4b9f35099f5b82bdb9f..741a7db679a0a2ea6f663e810a4bd0523567d4d1 100644 (file)
@@ -20,7 +20,7 @@
         }
     ],
     "require": {
-        "php": ">=7.3.0",
+        "php": ">=7.4",
         "ext-dom": "*",
         "ext-libxml": "*",
         "ext-json": "*",
index 1d1469dfb4cd9d460d176561629669ed1ab786ba..5ccd8c702d184e73d95895c8e936cc55608de391 100644 (file)
@@ -6,6 +6,8 @@ use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
 use Doctrine\DBAL\DriverManager;
 use Doctrine\DBAL\Schema\Comparator;
 use Doctrine\DBAL\Schema\Schema;
+use Illuminate\Support\Str;
+use Spatie\MediaLibrary\MediaCollections\Models\Media;
 
 class MigrateCommand extends CubistMagicCommand
 {
@@ -59,6 +61,10 @@ class MigrateCommand extends CubistMagicCommand
         foreach ($queries as $q) {
             $connection->exec($q);
         }
+
+        Media::whereNull('uuid')->cursor()->each(
+            fn(Media $media) => $media->update(['uuid' => Str::uuid()])
+        );
     }
 
     /**
index ce87b9cb44c851c2747a69bdcf25fa8ba14a6ba2..bffcb84c52f73584531827f1770cdbe62ef64e5e 100644 (file)
@@ -10,6 +10,8 @@
             this.id = $(this.element).attr('id');
             this.bmidselector = '[data-bmid="' + this.id + '"]';
 
+            this.cleanTemplate();
+
             var initValues = this.element.data('values');
             $.each(initValues, function (k, v) {
                 $this.initItem(v);
             }
         },
 
+        cleanTemplate: function () {
+            this.element.find('.sample' + this.bmidselector).find('[data-init-function]').removeAttr('data-init-function');
+        },
+
         update: function () {
             this.serialize();
             this.updateLegends();
             var $this = this;
             var id = this.element.attr('id');
             $.each(this.element.find('.item' + this.bmidselector + ':not(.sample) .subform' + this.bmidselector), function () {
+
+                $(this).find('.bunchmultiple').each(function () {
+                    $(this).data('bunchmultiple').serialize();
+                });
+
                 var data = $(this).find(':input' + $this.bmidselector).serializeArray();
                 var filteredData = {};
                 $.each(data, function (k, v) {
 
             $(this.element).find(".bunchmultiple__items" + this.bmidselector).append($(item));
             this.setValues(item, values);
+
             $(item).find('.subform>.bunchmultiple').bunchmultiple();
 
             $(item).find('.form-group').find('input, select, .dropzone, textarea').each(function () {
                 $(this).attr('data-bmid', $this.id);
             });
 
-
-            $(document).trigger('cubist.bunchmultiple.added');
-            $(this).trigger('change');
+            setTimeout(function () {
+                $this.setValues(item, values);
+                $(document).trigger('cubist.bunchmultiple.added');
+                $($this).trigger('change');
+            }, 500);
         },
 
         setValues(item, values) {
                     var input = $(item).find('[name="' + id + '___' + k + '"]');
                     if (input.is('.hiddenfield')) {
                         $(input).parent().attr('data-values', JSON.stringify(v));
-                    } else if (input.filter('[type="checkbox"]').length > 0) {
-                        input.filter('[type="checkbox"]').prop('checked', v === '1');
+                    } else if ($(input).nextAll('[type="checkbox"]').length > 0) {
+                        var cb = $(input).nextAll('[type="checkbox"]');
+                        cb.attr('name', cb.prev('[type="hidden"]').attr('name')).attr('value', '1');
+                        cb.prop('checked', v === true || v === '1' || v === 1);
                     } else {
                         input.val(v);
                     }
                 });
             } catch (e) {
-
+                console.log(e);
             }
             this.updateLegends();
         },
index 8ff0d0b80995780ce2f3f6ea9e871e760e31f003..2283b851066b0ee70ca3a42f335e5192f8e7bb5c 100644 (file)
@@ -170,7 +170,7 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
                 }
 
                 try {
-                    $thumb_url = $media->getUrl($field['thumb_collection'] ?? '');
+                    $thumb_url = $media->getUrl($field['thumb_collection'] ?? null);
                 } catch (Exception $e) {
                     $thumb_url = '';
                 }