From: Vincent Vanwaelscappel Date: Fri, 16 Jul 2021 17:42:00 +0000 (+0200) Subject: wait #4597 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=4be46bbbad538af6b062460cc4a32076071171f8;p=cubist_cms-back.git wait #4597 @1 --- diff --git a/src/app/Magic/Fields/Checkbox.php b/src/app/Magic/Fields/Checkbox.php index d67909b..a4a1b55 100644 --- a/src/app/Magic/Fields/Checkbox.php +++ b/src/app/Magic/Fields/Checkbox.php @@ -13,4 +13,9 @@ class Checkbox extends Field protected $_viewNamespace = 'toggle-field-for-backpack::fields'; protected $_filterType = 'simple'; + public function filterDefault($value) + { + return $value ? '1' : '0'; + } + } diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index 6c0fd97..bd9983e 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -309,13 +309,14 @@ class Field implements \ArrayAccess $this->setAttribute('store_in', $this->getAttribute('store_in') . "_translatable"); } } + $wrapperAttributes = $this->getAttribute('wrapperAttributes', []); + $wrapperAttributes['data-default'] = $this->filterDefault($this->getAttribute('default')); + $wrapperAttributes['data-name'] = $this->getAttribute('name'); if ($this->hasAttribute('when')) { - $wrapperAttributes = $this->getAttribute('wrapperAttributes', []); $wrapperAttributes['data-when'] = json_encode($this->getAttribute('when')); - $this->setAttribute('wrapperAttributes', $wrapperAttributes); } - + $this->setAttribute('wrapperAttributes', $wrapperAttributes); } public function setPermissions() @@ -356,6 +357,10 @@ class Field implements \ArrayAccess return $value; } + public function filterDefault($value){ + return $value; + } + public function filterColumn($value) { return $value; diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index f6be1af..097a720 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -58,6 +58,9 @@ class CubistMagicAbstractModel extends Model implements HasMedia protected $_enableRevisions = true; protected $_enableRevisionsButton = false; protected $_enableBulk = true; + + protected $_enableTrackNonDefaultValues = false; + protected static $_ownerAttribute = null; protected $_syncDbSchema = true; @@ -84,7 +87,7 @@ class CubistMagicAbstractModel extends Model implements HasMedia */ protected $fakeColumns = []; - protected $additionalEditViews=[]; + protected $additionalEditViews = []; /** @@ -861,11 +864,16 @@ class CubistMagicAbstractModel extends Model implements HasMedia */ public function getAdditionalEditViews(): array { - return $this->additionalEditViews; + $res = $this->additionalEditViews; + if ($this->_enableTrackNonDefaultValues) { + $res[] = 'cubist_back::track-non-default-values'; + } + return array_unique($res); } - public function addAdditionalEditView($view){ - $this->additionalEditViews[]=$view; + public function addAdditionalEditView($view) + { + $this->additionalEditViews[] = $view; } public function preCache() diff --git a/src/resources/views/edit.blade.php b/src/resources/views/edit.blade.php index 218c041..de54386 100644 --- a/src/resources/views/edit.blade.php +++ b/src/resources/views/edit.blade.php @@ -17,7 +17,6 @@ @endpush - @include('cubist_back::when') diff --git a/src/resources/views/track-non-default-values.blade.php b/src/resources/views/track-non-default-values.blade.php new file mode 100644 index 0000000..4c8dfd5 --- /dev/null +++ b/src/resources/views/track-non-default-values.blade.php @@ -0,0 +1,50 @@ +@push('crud_fields_scripts') + +@endpush + +@push('crud_fields_styles') + +@endpush