]> _ Git - cubist_cms-back.git/commitdiff
wait #4597 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 16 Jul 2021 17:42:00 +0000 (19:42 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 16 Jul 2021 17:42:00 +0000 (19:42 +0200)
src/app/Magic/Fields/Checkbox.php
src/app/Magic/Fields/Field.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/resources/views/edit.blade.php
src/resources/views/track-non-default-values.blade.php [new file with mode: 0644]

index d67909b8e94d1dde525b4f70bb8048a963ea3d63..a4a1b553e42ecfafb321721d4dea61de41cb379e 100644 (file)
@@ -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';
+    }
+
 }
index 6c0fd9770b5a1a3247bd91d956ad6918fb34760f..bd9983ec383ff4c2fb55623cc702b068a8f65431 100644 (file)
@@ -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;
index f6be1afcc4fd0b74b5f9beada687b6de80e1b49b..097a720ed86e399dfc34f79dd40905d81c14f2ae 100644 (file)
@@ -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()
index 218c041289cd809bf938c709547faba2af0fc041..de543865fadd4b82c76efbd4853393c84ed398c1 100644 (file)
@@ -17,7 +17,6 @@
     </script>
 @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 (file)
index 0000000..4c8dfd5
--- /dev/null
@@ -0,0 +1,50 @@
+@push('crud_fields_scripts')
+    <script type="text/javascript">
+        jQuery('document').ready(function ($) {
+            $(document).on('change', 'select,input,textarea', function () {
+                markChangedFields();
+            });
+            markChangedFields();
+        });
+
+        function markChangedFields() {
+            $('[data-default]').each(function () {
+                var v = '';
+                $(this).find('[name="' + $(this).data('name') + '"]').each(function () {
+                    if ($(this).is(':checkbox') && !$(this).prop('checked')) {
+                        return false;
+                    }
+                    v = $(this).val();
+                });
+
+                if (v == $(this).data('default')) {
+                    $(this).removeClass('non-default');
+                } else {
+                    $(this).addClass('non-default');
+                }
+            });
+        }
+
+    </script>
+@endpush
+
+@push('crud_fields_styles')
+    <style type="text/css">
+        .non-default {
+            position: relative;
+        }
+
+        .non-default::after {
+            content: '';
+
+            position: absolute;
+            display: block;
+            background-color: crimson;
+            width: 3px;
+
+            right: -5px;
+            top: -8px;
+            bottom: -8px;
+        }
+    </style>
+@endpush