]> _ Git - cubist_cms-back.git/commitdiff
wip #6693 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 2 Feb 2024 16:21:24 +0000 (17:21 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 2 Feb 2024 16:21:24 +0000 (17:21 +0100)
src/app/Magic/Fields/Datetime.php
src/app/Magic/Fields/GrapePageBuilder.php [new file with mode: 0644]
src/app/Magic/Fields/HiddenDatetime.php
src/app/Magic/Models/CMSPage.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/resources/views/fields/pagebuilder-grapejs.blade.php [new file with mode: 0644]
src/resources/views/fields/text.blade.php

index 427819338f2475a2c6b570f451a671661c148758..4d14b5a5d5933df6331266e7b429549c3802fd34 100644 (file)
@@ -18,6 +18,8 @@ class Datetime extends Field
     protected $_columnFormat = 'YYYY-MM-DD HH:mm';
     protected $_filterType = 'date_range';
 
+    protected $_translatable=false;
+
     public function _mutator($value)
     {
         return \Date::parse($value);
diff --git a/src/app/Magic/Fields/GrapePageBuilder.php b/src/app/Magic/Fields/GrapePageBuilder.php
new file mode 100644 (file)
index 0000000..bb391d9
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+namespace Cubist\Backpack\Magic\Fields;
+
+use Cubist\Backpack\CubistBackpackServiceProvider;
+
+class GrapePageBuilder extends Textarea
+{
+    protected $_adminType = 'pagebuilder-grapejs';
+    protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+}
index 298ca70c0509962b4a931628fcb8b65700066c83..96f52690531942f94319ce5a8b314c6fa79c9645 100644 (file)
@@ -8,4 +8,5 @@ class HiddenDatetime extends Datetime
 {
     protected $_adminType = 'hidden';
     protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+    protected $_translatable = false;
 }
index c78da5e00b42e353f45d1acc5d4a5ab8df3b61ca..5af3ba3ddf638073aff53739ca1ea8f8881be921 100644 (file)
@@ -32,7 +32,7 @@ class CMSPage extends CubistMagicNestedModel
         'singular' => 'page',
         'plural' => 'pages'];
 
-    protected $defaultFieldAttributes = ['translatable' => true];
+    //protected $defaultFieldAttributes = ['translatable' => true];
 
     public function setFields()
     {
@@ -83,7 +83,7 @@ class CMSPage extends CubistMagicNestedModel
     public function onCreating(): bool
     {
         $this->useTemplateIfNotSet(request('template'));
-        return $this->onCreating();
+        return parent::onCreating();
     }
 
 //    public function onBeforeEdit($controller, $id)
@@ -102,13 +102,13 @@ class CMSPage extends CubistMagicNestedModel
     public function onSaving(): bool
     {
         $this->useTemplateIfNotSet(request('template'));
-        return $this->onSaving();
+        return parent::onSaving();
     }
 
     public function onUpdating(): bool
     {
         $this->useTemplateIfNotSet(request('template'));
-        return $this->onUpdating();
+        return parent::onUpdating();
     }
 
 
@@ -201,7 +201,7 @@ class CMSPage extends CubistMagicNestedModel
     public function create(array $attributes = [])
     {
         if (!isset($attributes['template']) || !$attributes['template']) {
-            $attributes['template']='unset';
+            $attributes['template'] = 'unset';
         }
         $this->useTemplate($attributes['template']);
         return parent::create($attributes);
@@ -210,7 +210,7 @@ class CMSPage extends CubistMagicNestedModel
     public function update(array $attributes = [], array $options = [])
     {
         if (!isset($attributes['template']) || !$attributes['template']) {
-            $attributes['template']='unset';
+            $attributes['template'] = 'unset';
         }
         $this->useTemplate($attributes['template']);
         return parent::update($attributes, $options);
@@ -266,4 +266,5 @@ class CMSPage extends CubistMagicNestedModel
         }
         parent::copyTranslations($from, $to, $overwrite);
     }
+
 }
index d99f613f0d5b3b4a7e2a943f114854c18d9d0e37..c1ffece04f3bf8b311eb1bd04a21efff4e6ae9f6 100644 (file)
@@ -1143,49 +1143,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return null;
     }
 
-    public function save(array $options = [])
-    {
-        $this->mergeAttributesFromCachedCasts();
-
-        $query = $this->newModelQuery();
-
-        // If the "saving" event returns false we'll bail out of the save and return
-        // false, indicating that the save failed. This provides a chance for any
-        // listeners to cancel save operations if validations fail or whatever.
-        if ($this->fireModelEvent('saving') === false) {
-            return false;
-        }
-
-        // If the model already exists in the database we can just update our record
-        // that is already in this database using the current IDs in this "where"
-        // clause to only update this model. Otherwise, we'll just insert them.
-        if ($this->exists) {
-            $saved = $this->isDirty() ?
-                $this->performUpdate($query) : true;
-        }
-
-        // If the model is brand new, we'll insert it into our database and set the
-        // ID attribute on the model to the value of the newly inserted row's ID
-        // which is typically an auto-increment value managed by the database.
-        else {
-            $saved = $this->performInsert($query);
-
-            if (!$this->getConnectionName() &&
-                $connection = $query->getConnection()) {
-                $this->setConnection($connection->getName());
-            }
-        }
-
-        // If the model is successfully saved, we need to do a few more things once
-        // that is done. We will call the "saved" method here to run any actions
-        // we need to happen after a model gets successfully saved right here.
-        if ($saved) {
-            $this->finishSave($options);
-        }
-
-        return $saved;
-    }
-
     /**
      * @param $uploadedFile UploadedFile|\SplFileInfo
      * @param $attribute string
diff --git a/src/resources/views/fields/pagebuilder-grapejs.blade.php b/src/resources/views/fields/pagebuilder-grapejs.blade.php
new file mode 100644 (file)
index 0000000..ae7f809
--- /dev/null
@@ -0,0 +1,55 @@
+@php
+
+    @endphp
+
+    <!-- grapejs input -->
+@include('crud::fields.inc.wrapper_start')
+<label>{!! $field['label'] !!}</label>
+@include('crud::fields.inc.translatable_icon')
+
+@push('crud_fields_styles')
+    @basset('https://unpkg.com/grapesjs/dist/css/grapes.min.css')
+@endpush
+
+@push('crud_fields_scripts')
+    @basset('https://unpkg.com/grapesjs')
+@endpush
+
+<div class="grapejs"></div>
+
+@bassetBlock('cubist/grapejs-field.js')
+<script>
+    jQuery(document).ready(function ($) {
+        $(document).on('cubist.bunchmultiple.added', function () {
+            initUntriggeredGrapeJS($);
+        });
+        initUntriggeredGrapeJS($);
+    });
+
+    function initUntriggeredGrapeJS($) {
+        // trigger select2 for each untriggered select2 box
+        $('.grapejs:not(.grapejs-init)').each(function (i, obj) {
+            let id = 'gjs-' + (Math.round(Math.random() * 10000000));
+            $(obj).attr('id', id);
+
+            if ($(obj).closest('.item.sample').length > 0) {
+                return;
+            }
+            $(obj).addClass('grapejs-init');
+            let e = grapesjs.init({
+                container: '#' + id,
+                components: '<div class="txt-red">Hello world!</div>',
+                style: '.txt-red{color: red}',
+            });
+            $(obj).data('grapejs', e);
+        });
+    }
+</script>
+@endBassetBlock
+
+
+{{-- HINT --}}
+@if (isset($field['hint']))
+    <p class="help-block">{!! $field['hint'] !!}</p>
+@endif
+@include('crud::fields.inc.wrapper_end')
index cbc13341aff380274e34b13edcc598c395395296..1dda42bdfd9b3e6c680e263799b5b03b97d00635 100644 (file)
@@ -18,4 +18,4 @@
     @if (isset($field['hint']))
         <p class="help-block">{!! $field['hint'] !!}</p>
     @endif
-</div>
+@include('crud::fields.inc.wrapper_end')