From 90e48f300722d0f721bea381604e1a0fc0619f6b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 1 Jun 2022 18:50:35 +0200 Subject: [PATCH] wait #5285 @2 --- src/app/Magic/Fields/BunchOfFieldsMultiple.php | 3 ++- .../Fields/KeyValueBunchOfFieldsMultiple.php | 1 + src/public/bunchmultiple/bunchmultiple.js | 8 ++++---- .../fields/bunch_keyvalue_multiple.blade.php | 6 ++---- .../views/fields/bunch_multiple.blade.php | 2 +- .../views/track-non-default-values.blade.php | 16 ++++++++++++++++ 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/app/Magic/Fields/BunchOfFieldsMultiple.php b/src/app/Magic/Fields/BunchOfFieldsMultiple.php index 776538c..9a9505a 100644 --- a/src/app/Magic/Fields/BunchOfFieldsMultiple.php +++ b/src/app/Magic/Fields/BunchOfFieldsMultiple.php @@ -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() diff --git a/src/app/Magic/Fields/KeyValueBunchOfFieldsMultiple.php b/src/app/Magic/Fields/KeyValueBunchOfFieldsMultiple.php index 4bd3ce2..8410452 100644 --- a/src/app/Magic/Fields/KeyValueBunchOfFieldsMultiple.php +++ b/src/app/Magic/Fields/KeyValueBunchOfFieldsMultiple.php @@ -5,4 +5,5 @@ namespace Cubist\Backpack\Magic\Fields; class KeyValueBunchOfFieldsMultiple extends BunchOfFieldsMultiple { protected $_adminType = 'bunch_keyvalue_multiple'; + protected $_show_empty = false; } diff --git a/src/public/bunchmultiple/bunchmultiple.js b/src/public/bunchmultiple/bunchmultiple.js index dc8f432..ee83680 100644 --- a/src/public/bunchmultiple/bunchmultiple.js +++ b/src/public/bunchmultiple/bunchmultiple.js @@ -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) { @@ -106,7 +106,7 @@ 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}); }); }, @@ -188,8 +188,8 @@ 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; diff --git a/src/resources/views/fields/bunch_keyvalue_multiple.blade.php b/src/resources/views/fields/bunch_keyvalue_multiple.blade.php index 8622ec3..2258c98 100644 --- a/src/resources/views/fields/bunch_keyvalue_multiple.blade.php +++ b/src/resources/views/fields/bunch_keyvalue_multiple.blade.php @@ -24,7 +24,8 @@ if (!is_string($value)) { } ?> -
+
@@ -42,9 +43,6 @@ if (!is_string($value)) {
@include('cubist_back::inc.show_bunch_fields', array('bunchfields'=>$field['bunchfields'],'bmid'=>$field['rand'],'keyvalue'=>true))
- diff --git a/src/resources/views/fields/bunch_multiple.blade.php b/src/resources/views/fields/bunch_multiple.blade.php index 3ca1059..9bc3d09 100644 --- a/src/resources/views/fields/bunch_multiple.blade.php +++ b/src/resources/views/fields/bunch_multiple.blade.php @@ -12,7 +12,7 @@ if (!is_string($value)) { } ?> -
+
@include('crud::fields.inc.wrapper_start') diff --git a/src/resources/views/track-non-default-values.blade.php b/src/resources/views/track-non-default-values.blade.php index 88c46cd..23984bd 100644 --- a/src/resources/views/track-non-default-values.blade.php +++ b/src/resources/views/track-non-default-values.blade.php @@ -38,6 +38,14 @@ } }); + $('.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) { @@ -70,6 +78,14 @@ 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; -- 2.39.5