]> _ Git - cubist_cms-back.git/commitdiff
wait #5285 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 1 Jun 2022 16:50:35 +0000 (18:50 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 1 Jun 2022 16:50:35 +0000 (18:50 +0200)
src/app/Magic/Fields/BunchOfFieldsMultiple.php
src/app/Magic/Fields/KeyValueBunchOfFieldsMultiple.php
src/public/bunchmultiple/bunchmultiple.js
src/resources/views/fields/bunch_keyvalue_multiple.blade.php
src/resources/views/fields/bunch_multiple.blade.php
src/resources/views/track-non-default-values.blade.php

index 776538cf59ae5e6da7b90c5e373c8adfc1f8921e..9a9505a75d54496ae19a4dc38780bba8bdb9bbd2 100644 (file)
@@ -12,10 +12,11 @@ class BunchOfFieldsMultiple extends BunchOfFields
     protected $_adminType = 'bunch_multiple';
     protected $_cast = 'array';
     protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+    protected $_show_empty = true;
 
     public function getDefaultAttributes()
     {
-        return array_merge(parent::getDefaultAttributes(), ['bunch' => [], "add_label" => __('Add an item')]);
+        return array_merge(parent::getDefaultAttributes(), ['bunch' => [], "add_label" => __('Add an item'), 'show_empty' => $this->_show_empty]);
     }
 
     public function _postSetAttributes()
index 4bd3ce2cab8724ba8825916634de47773a388d7f..8410452dd38c10524d41b5ce2482e5a6dbbeae9d 100644 (file)
@@ -5,4 +5,5 @@ namespace Cubist\Backpack\Magic\Fields;
 class KeyValueBunchOfFieldsMultiple extends BunchOfFieldsMultiple
 {
     protected $_adminType = 'bunch_keyvalue_multiple';
+    protected $_show_empty = false;
 }
index dc8f4321fdf3cc9d6afdf327ded1cdff8d036ae8..ee836808f2a0fedf215cd20cfcc7ca2a568c81e4 100644 (file)
@@ -19,7 +19,7 @@
 
             var initValues = this.element.data('values');
 
-            if (initValues.length === 0) {
+            if (initValues.length === 0 && this.element.hasClass('showEmpty')) {
                 this.initItem();
             } else {
                 $.each(initValues, function (k, v) {
         resize: function () {
             this.element.find('.legendsize').each(function () {
                 var parent = $(this).closest('.legend');
-                var aw = $(parent).innerWidth() - 130;
+                var aw = $(parent).innerWidth() - 100;
                 $(this).css({width: aw, maxWidth: aw, minWidth: aw});
             });
         },
 
         removeItem: function (item) {
             $(item).remove();
-            if (this.element.find('.item' + this.bmidselector + ':not(.sample)').length === 0) {
-                this.initItem();
+            if(this.element.hasClass('showEmpty') && this.element.find('.item' + this.bmidselector + ':not(.sample)').length === 0) {
+                    this.initItem();
             }
 
             var $this = this;
index 8622ec34b4855c1cd02614ddcfb1f1067f7b38da..2258c9877e7aeb9c2baab28ca5577aeae4aa4ce9 100644 (file)
@@ -24,7 +24,8 @@ if (!is_string($value)) {
 }
 
 ?>
-<div class="bunchmultiple bunchmultiple_keyvalue" id="{!! $field['rand'] !!}" data-bunch-name="{{$field['name']}}" data-values="{{ $value }}">
+<div class="bunchmultiple bunchmultiple_keyvalue{{ ($field['show_empty']?' showEmpty':'') }}"
+     id="{!! $field['rand'] !!}" data-bunch-name="{{$field['name']}}" data-values="{{ $value }}">
     <input type="hidden" class="hiddenfield" name="{{$field['name']}}" value="{{ $value }}"
            data-bmid="{!! $field['rand'] !!}"/>
     <div class="bunchmultiple__wrapper" data-bmid="{!! $field['rand'] !!}">
@@ -42,9 +43,6 @@ if (!is_string($value)) {
                     <div class="legendsize">
                         @include('cubist_back::inc.show_bunch_fields', array('bunchfields'=>$field['bunchfields'],'bmid'=>$field['rand'],'keyvalue'=>true))
                     </div>
-                    <a href="#" class="action edit" data-bmid="{!! $field['rand'] !!}"><i class="la la-pencil"
-                                                                                          role="presentation"
-                                                                                          aria-hidden="true"></i></a>
                     <a href="#" class="action remove" data-bmid="{!! $field['rand'] !!}"><i class="la la-trash"
                                                                                             role="presentation"
                                                                                             aria-hidden="true"></i></a>
index 3ca10597bfcae23ae8002b74e0bd14d0d3f804fd..9bc3d099f2bc512b3f936af81f8cdc63c7afd1e9 100644 (file)
@@ -12,7 +12,7 @@ if (!is_string($value)) {
 }
 
 ?>
-<div class="bunchmultiple" id="{!! $field['rand'] !!}" data-bunch-name="{{$field['name']}}" data-values="{{ $value }}">
+<div class="bunchmultiple{{ ($field['show_empty']?' showEmpty':'') }}" id="{!! $field['rand'] !!}" data-bunch-name="{{$field['name']}}" data-values="{{ $value }}">
     <input type="hidden" class="hiddenfield" name="{{$field['name']}}" value="{{ $value }}" data-bmid="{!! $field['rand'] !!}"/>
     <div class="bunchmultiple__wrapper" data-bmid="{!! $field['rand'] !!}">
         @include('crud::fields.inc.wrapper_start')
index 88c46cd741412c93c17ca19707845fbf0854b802..23984bd89475542bf327a3ffbdceca4202f69fc4 100644 (file)
                 }
             });
 
+            $('.bunchmultiple__items').each(function () {
+                if ($(this).find('.item:not(.sample)').length > 0) {
+                    $(this).closest('.form-group').addClass('non-default');
+                } else {
+                    $(this).closest('.form-group').removeClass('non-default');
+                }
+            });
+
             $("#form_shortcuts nav a").each(function () {
                 var hasNonDefault = $($(this).attr('href')).closest('.card').find('.non-default').length > 0;
                 if (hasNonDefault) {
             bottom: -8px;
         }
 
+        .bunchfields .non-default::after, .bunchfields .live-change::after {
+            display: none;
+        }
+
+        .bunchmultiple__wrapper .non-default::after, .bunchmultiple__wrapper .live-change::after {
+            left: -20px;
+        }
+
         #form_shortcuts .non-default::after {
             left: -30px;
             top: -0px;