protected $_columnFormat = 'YYYY-MM-DD HH:mm';
protected $_filterType = 'date_range';
+ protected $_translatable=false;
+
public function _mutator($value)
{
return \Date::parse($value);
--- /dev/null
+<?php
+
+namespace Cubist\Backpack\Magic\Fields;
+
+use Cubist\Backpack\CubistBackpackServiceProvider;
+
+class GrapePageBuilder extends Textarea
+{
+ protected $_adminType = 'pagebuilder-grapejs';
+ protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+}
{
protected $_adminType = 'hidden';
protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+ protected $_translatable = false;
}
'singular' => 'page',
'plural' => 'pages'];
- protected $defaultFieldAttributes = ['translatable' => true];
+ //protected $defaultFieldAttributes = ['translatable' => true];
public function setFields()
{
public function onCreating(): bool
{
$this->useTemplateIfNotSet(request('template'));
- return $this->onCreating();
+ return parent::onCreating();
}
// public function onBeforeEdit($controller, $id)
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();
}
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);
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);
}
parent::copyTranslations($from, $to, $overwrite);
}
+
}
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
--- /dev/null
+@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')
@if (isset($field['hint']))
<p class="help-block">{!! $field['hint'] !!}</p>
@endif
-</div>
+@include('crud::fields.inc.wrapper_end')