]> _ Git - cubist_cms-back.git/commitdiff
wip #2835 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 14 Jun 2019 13:28:26 +0000 (15:28 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 14 Jun 2019 13:28:26 +0000 (15:28 +0200)
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/Tags.php [new file with mode: 0644]
src/resources/views/fields/tags.blade.php [new file with mode: 0644]

index 49e7737be7f16b7ac6477e87a0323ddac719615c..6e9225b460abbf0200d082407dbaa9959475812e 100644 (file)
@@ -88,7 +88,7 @@ class Field
         if (class_exists(__NAMESPACE__ . '\\' . $type)) {
             return __NAMESPACE__ . '\\' . $type;
         }
-        return self::class;
+        throw new Exception('Field ' . $type . ' not available');
     }
 
     public function getDefaultAttributes()
diff --git a/src/app/Magic/Fields/Tags.php b/src/app/Magic/Fields/Tags.php
new file mode 100644 (file)
index 0000000..0f73d1c
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace Cubist\Backpack\app\Magic\Fields;
+
+use Cubist\Backpack\CubistBackpackServiceProvider;
+
+class Tags extends Field
+{
+    protected $_adminType = 'tags';
+    protected $_cast = 'array';
+    protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+}
diff --git a/src/resources/views/fields/tags.blade.php b/src/resources/views/fields/tags.blade.php
new file mode 100644 (file)
index 0000000..fc2a10e
--- /dev/null
@@ -0,0 +1,71 @@
+<!-- select2 tags -->
+<div @include('crud::inc.field_wrapper_attributes') >
+    <label>{!! $field['label'] !!}</label>
+    @include('crud::inc.field_translatable_icon')
+    <select
+        name="{{ $field['name'] }}[]"
+        style="width: 100%"
+        @include('crud::inc.field_attributes', ['default_class' =>  'form-control select2_tags'])
+        multiple>
+    </select>
+
+    @if(isset($field['select_all']) && $field['select_all'])
+        <a class="btn btn-xs btn-default select_all" style="margin-top: 5px;"><i
+                class="fa fa-check-square-o"></i> {{ trans('backpack::crud.select_all') }}</a>
+        <a class="btn btn-xs btn-default clear" style="margin-top: 5px;"><i
+                class="fa fa-times"></i> {{ trans('backpack::crud.clear') }}</a>
+    @endif
+
+    {{-- 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 ($) {
+                // trigger select2 for each untriggered select2_multiple box
+                $('.select2_tags').each(function (i, obj) {
+                    if (!$(obj).hasClass("select2-hidden-accessible")) {
+                        var $obj = $(obj).select2({
+                            theme: "bootstrap",
+                            tags: true
+                        });
+
+                        @if(isset($field['select_all']) && $field['select_all'])
+                        $(obj).parent().find('.clear').on("click", function () {
+                            $obj.val([]).trigger("change");
+                        });
+                        $(obj).parent().find('.select_all').on("click", function () {
+                            $obj.val(options).trigger("change");
+                        });
+                        @endif
+                    }
+                });
+            });
+        </script>
+    @endpush
+
+@endif
+{{-- End of Extra CSS and JS --}}
+{{-- ########################################## --}}