protected $_viewNamespace = 'toggle-field-for-backpack::fields';
protected $_filterType = 'simple';
+ public function filterDefault($value)
+ {
+ return $value ? '1' : '0';
+ }
+
}
$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()
return $value;
}
+ public function filterDefault($value){
+ return $value;
+ }
+
public function filterColumn($value)
{
return $value;
protected $_enableRevisions = true;
protected $_enableRevisionsButton = false;
protected $_enableBulk = true;
+
+ protected $_enableTrackNonDefaultValues = false;
+
protected static $_ownerAttribute = null;
protected $_syncDbSchema = true;
*/
protected $fakeColumns = [];
- protected $additionalEditViews=[];
+ protected $additionalEditViews = [];
/**
*/
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()
</script>
@endpush
-
@include('cubist_back::when')
--- /dev/null
+@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