]> _ Git - cubist_cms-back.git/commitdiff
wip #5285 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 1 Jun 2022 15:45:32 +0000 (17:45 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 1 Jun 2022 15:45:32 +0000 (17:45 +0200)
src/app/CubistBackpackServiceProvider.php
src/app/Magic/Fields/SelectFromArray.php
src/resources/views/fields/bunch_keyvalue_multiple.blade.php
src/resources/views/fields/bunch_multiple.blade.php
src/resources/views/fields/select2_from_array.blade.php

index 1e610cd0c0bfdd2e24a798a1e0c17ebbb6896fb7..6be34f8fb831d09d91f8f81f894ceecc02268ea0 100644 (file)
@@ -32,8 +32,6 @@ class CubistBackpackServiceProvider extends ServiceProvider
      */
     public function boot()
     {
-
-
         $base = realpath(__DIR__ . "/..");
         $resourcesDir = $base . '/resources';
 
@@ -52,7 +50,6 @@ class CubistBackpackServiceProvider extends ServiceProvider
             return "<?php echo \$__env->make('" . self::NAMESPACE . "::favicon', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>";
         });
 
-
         $this->app->extend('crud', function () {
             return new CubistCrudPanel();
         });
@@ -69,14 +66,12 @@ class CubistBackpackServiceProvider extends ServiceProvider
         $base = realpath(__DIR__ . "/..");
         $resourcesDir = $base . '/resources';
 
-
         $configs = ['app', 'cubist'];
 
         foreach ($configs as $config) {
             $this->mergeConfigFrom($resourcesDir . '/config/' . $config . '.php', $config);
         }
 
-
         $this->commands([
             InstallCommand::class,
             UpdateCommand::class,
index 6fe96bf77b147134abdb47450f24040cb9781c87..0f26d549099a8a7120a8b1da62b6754f4dc6c054 100644 (file)
@@ -22,10 +22,11 @@ class SelectFromArray extends Field
     protected $_options_aliases = [];
     protected $_filterType = 'dropdown';
     protected $_ajax = true;
+    protected $_allowsHTML = false;
 
     public function getDefaultAttributes()
     {
-        return array_merge(parent::getDefaultAttributes(), ['options' => $this->getOptions(), 'options_aliases' => $this->_options_aliases, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple, 'ajax' => $this->_ajax]);
+        return array_merge(parent::getDefaultAttributes(), ['options' => $this->getOptions(), 'options_aliases' => $this->_options_aliases, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple, 'ajax' => $this->_ajax, 'allows_html' => $this->_allowsHTML]);
     }
 
     protected function _postSetAttributes()
index ff7e73548d0d36977d99555555854f7c6a0f389a..8622ec34b4855c1cd02614ddcfb1f1067f7b38da 100644 (file)
@@ -24,7 +24,7 @@ if (!is_string($value)) {
 }
 
 ?>
-<div class="bunchmultiple bunchmultiple_keyvalue" id="{!! $field['rand'] !!}" data-values="{{ $value }}">
+<div class="bunchmultiple bunchmultiple_keyvalue" id="{!! $field['rand'] !!}" data-bunch-name="{{$field['name']}}" data-values="{{ $value }}">
     <input type="hidden" class="hiddenfield" name="{{$field['name']}}" value="{{ $value }}"
            data-bmid="{!! $field['rand'] !!}"/>
     <div class="bunchmultiple__wrapper" data-bmid="{!! $field['rand'] !!}">
index 5d1a5ec0568af9899a4d57bf8c2ae65bef3dd42d..3ca10597bfcae23ae8002b74e0bd14d0d3f804fd 100644 (file)
@@ -12,7 +12,7 @@ if (!is_string($value)) {
 }
 
 ?>
-<div class="bunchmultiple" id="{!! $field['rand'] !!}" data-values="{{ $value }}">
+<div class="bunchmultiple" id="{!! $field['rand'] !!}" data-bunch-name="{{$field['name']}}" data-values="{{ $value }}">
     <input type="hidden" class="hiddenfield" name="{{$field['name']}}" value="{{ $value }}" data-bmid="{!! $field['rand'] !!}"/>
     <div class="bunchmultiple__wrapper" data-bmid="{!! $field['rand'] !!}">
         @include('crud::fields.inc.wrapper_start')
index a34b3c4c2fd84709e37e4c1c43b8d993b9c15b0b..c1a31e50ce3a2ad32516f6d0ae0404631e20d928 100644 (file)
     }
 
     $ajax=isset($field['ajax']) && $field['ajax'];
+    $allows_html=isset($field['allows_html']) && $field['allows_html'];
 
 if($ajax){
     $field['ajax']=\Cubist\Backpack\Magic\Fields\SelectFromArray::hashOptions($field['options']);
 }
 @endphp
 
-<!-- select2 from array -->
+    <!-- select2 from array -->
 @include('crud::fields.inc.wrapper_start')
 <label>{!! $field['label'] !!}</label>
 @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)
@@ -36,6 +37,7 @@ if($ajax){
     @include('crud::fields.inc.attributes', ['default_class' =>  'form-control select2_from_array'])
     @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)multiple @endif
     @if($ajax) data-ajax="{{$field['ajax']}}" @endif
+    @if($allows_html) data-allow-html="1" @endif
 >
     @if (isset($field['allows_null']) && $field['allows_null']==true)
         @if($is_null)
@@ -52,8 +54,8 @@ if($ajax){
             @endphp
             @if($selected)
                 <option value="{{ $key }}" selected>{{ $value }}</option>
-            @else if(!$ajax)
-            <option value="{{ $key }}">{{ $value }}</option>
+            @elseif(!$ajax)
+                <option value="{{ $key }}">{{ $value }}</option>
             @endif
         @endforeach
     @endif
@@ -87,31 +89,35 @@ if($ajax){
         <script>
             jQuery(document).ready(function ($) {
                 $(document).on('cubist.bunchmultiple.added', function () {
-                    initUntriggeredSelectFromArray();
+                    initUntriggeredSelectFromArray($);
                 });
-                initUntriggeredSelectFromArray();
+                initUntriggeredSelectFromArray($);
+            });
 
-                function initUntriggeredSelectFromArray() {
-                    // trigger select2 for each untriggered select2 box
-                    $('.select2_from_array:not(.select2-hidden-accessible)').each(function (i, obj) {
-                        if ($(obj).closest('.item.sample').length > 0) {
-                            return;
-                        }
-                        var options = {
-                            theme: "bootstrap",
+            function initUntriggeredSelectFromArray($) {
+                // trigger select2 for each untriggered select2 box
+                $('.select2_from_array:not(.select2-hidden-accessible)').each(function (i, obj) {
+                    if ($(obj).closest('.item.sample').length > 0) {
+                        return;
+                    }
+                    var options = {
+                        theme: "bootstrap",
+                    };
+                    if ($(this).is('[data-ajax]')) {
+                        options.ajax = {
+                            url: '{{backpack_url('select2')}}' + '/' + $(this).data('ajax'),
+                            dataType: 'json',
+                            delay: 250,
                         };
-                        if ($(this).is('[data-ajax]')) {
-                            options.ajax = {
-                                url: '{{backpack_url('select2')}}' + '/' + $(this).data('ajax'),
-                                dataType: 'json',
-                                delay: 250,
-                            };
+                    }
+                    if ($(this).is('[data-allow-html="1"]')) {
+                        options.escapeMarkup = function (m) {
+                            return m;
                         }
-                        $(obj).addClass('init').select2(options);
-                    });
-                }
-            });
-
+                    }
+                    $(obj).addClass('init').select2(options);
+                });
+            }
         </script>
     @endpush