]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Jun 2019 09:58:07 +0000 (11:58 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Jun 2019 09:58:07 +0000 (11:58 +0200)
src/app/Magic/Fields/SelectFromModel.php
src/resources/views/fields/dropzone_media.blade.php
src/resources/views/fields/select2_from_array.blade.php [new file with mode: 0644]

index e5a77f46f5d3f08de2c59812766da01b0487e392..1042893761028a926f8f133bd4d1022f9e7c56b0 100644 (file)
@@ -9,6 +9,7 @@ use Cubist\Backpack\CubistBackpackServiceProvider;
 class SelectFromModel extends Model
 {
     protected $_adminType = 'select2_from_array';
+    protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
 
     protected $_columnViewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::columns';
     protected $_columnType = 'select_from_array';
index 213106bd219e518662b9ed1b1b27119a2b1b4ed2..f75a5991b4a257d87c66d45f1dc8b09199c6b76b 100644 (file)
@@ -168,11 +168,9 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
                             if (files === undefined) {
                                 files = [];
                             }
-                            console.log(collection, files);
 
                             for (var i = 0; i < files.length; i++) {
                                 var file = files[i];
-                                console.log(file);
 
                                 this.emit('addedfile', file);
 
diff --git a/src/resources/views/fields/select2_from_array.blade.php b/src/resources/views/fields/select2_from_array.blade.php
new file mode 100644 (file)
index 0000000..8624cb7
--- /dev/null
@@ -0,0 +1,94 @@
+<!-- select2 from array -->
+<div @include('crud::inc.field_wrapper_attributes') >
+    <label>{!! $field['label'] !!}</label>
+    <select
+        name="{{ $field['name'] }}@if (isset($field['allows_multiple']) && $field['allows_multiple']==true)[]@endif"
+        style="width: 100%"
+        @include('crud::inc.field_attributes', ['default_class' =>  'form-control select2_from_array'])
+        @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)multiple @endif
+    >
+
+        @if (isset($field['allows_null']) && $field['allows_null']==true)
+            <option value="">-</option>
+        @endif
+
+        @if (count($field['options']))
+            @foreach ($field['options'] as $key => $value)
+                @if((old(square_brackets_to_dots($field['name'])) && (
+                        $key == old(square_brackets_to_dots($field['name'])) ||
+                        (is_array(old(square_brackets_to_dots($field['name']))) &&
+                        in_array($key, old(square_brackets_to_dots($field['name'])))))) ||
+                        (null === old(square_brackets_to_dots($field['name'])) &&
+                            ((isset($field['value']) && (
+                                        $key == $field['value'] || (
+                                                is_array($field['value']) &&
+                                                in_array($key, $field['value'])
+                                                )
+                                        )) ||
+                                (isset($field['default']) &&
+                                ($key == $field['default'] || (
+                                                is_array($field['default']) &&
+                                                in_array($key, $field['default'])
+                                            )
+                                        )
+                                ))
+                        ))
+                    <option value="{{ $key }}" selected>{{ $value }}</option>
+                @else
+                    <option value="{{ $key }}">{{ $value }}</option>
+                @endif
+            @endforeach
+        @endif
+    </select>
+
+    {{-- HINT --}}
+    @if (isset($field['hint']))
+        <p class="help-block">{!! $field['hint'] !!}</p>
+    @endif
+</div>
+
+{{-- ########################################## --}}
+{{-- Extra CSS and JS for this particular field --}}
+{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}}
+@if ($crud->checkIfFieldIsFirstOfItsType($field))
+
+    {{-- FIELD CSS - will be loaded in the after_styles section --}}
+    @push('crud_fields_styles')
+        <!-- include select2 css-->
+        <link href="{{ asset('vendor/adminlte/bower_components/select2/dist/css/select2.min.css') }}" rel="stylesheet"
+              type="text/css"/>
+        <link
+            href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-theme/0.1.0-beta.10/select2-bootstrap.min.css"
+            rel="stylesheet" type="text/css"/>
+    @endpush
+
+    {{-- FIELD JS - will be loaded in the after_scripts section --}}
+    @push('crud_fields_scripts')
+        <!-- include select2 js-->
+        <script src="{{ asset('vendor/adminlte/bower_components/select2/dist/js/select2.min.js') }}"></script>
+        <script>
+            jQuery(document).ready(function ($) {
+                $(document).on('cubist.bunchmultiple.added', function () {
+                    initUntriggeredSelectFromArray();
+                });
+                initUntriggeredSelectFromArray();
+
+                function initUntriggeredSelectFromArray() {
+                    console.log(':)))');
+                    // trigger select2 for each untriggered select2 box
+                    $('.select2_from_array').each(function (i, obj) {
+                        if (!$(obj).hasClass("select2-hidden-accessible")) {
+                            $(obj).select2({
+                                theme: "bootstrap"
+                            });
+                        }
+                    });
+                }
+            });
+
+        </script>
+    @endpush
+
+@endif
+{{-- End of Extra CSS and JS --}}
+{{-- ########################################## --}}