]> _ Git - cubist_cms-back.git/commitdiff
wait #5082 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 10 Feb 2022 13:45:28 +0000 (14:45 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 10 Feb 2022 13:45:28 +0000 (14:45 +0100)
src/app/Magic/Fields/CMSTemplate.php
src/resources/views/fields/cms_template.blade.php [new file with mode: 0644]

index 98cf450df9f191623b23c470452bb0f6f28bc627..bea97315b958a7440a83f5d8d6e810ba75a70111 100644 (file)
@@ -5,6 +5,7 @@ namespace Cubist\Backpack\app\Magic\Fields;
 
 
 use Cubist\Backpack\app\Template\TemplateAbstract;
+use Cubist\Backpack\CubistBackpackServiceProvider;
 use Illuminate\Support\Str;
 
 class CMSTemplate extends SelectFromArray
@@ -12,6 +13,8 @@ class CMSTemplate extends SelectFromArray
 
     protected $_allowNull = false;
     protected $_translatable = false;
+    protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+    protected $_adminType = 'cms_template';
 
     protected function _postSetAttributes()
     {
diff --git a/src/resources/views/fields/cms_template.blade.php b/src/resources/views/fields/cms_template.blade.php
new file mode 100644 (file)
index 0000000..433dc34
--- /dev/null
@@ -0,0 +1,99 @@
+<!-- select from array -->
+<div @include('crud::inc.field_wrapper_attributes') >
+    <label>{!! $field['label'] !!}</label>
+    @include('crud::inc.field_translatable_icon')
+    <select
+        id="cms_template"
+        name="{{ $field['name'] }}@if (isset($field['allows_multiple']) && $field['allows_multiple']==true)[]@endif"
+        @include('crud::inc.field_attributes')
+        @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>
+@if ($crud->checkIfFieldIsFirstOfItsType($field))
+    @push('crud_fields_scripts')
+        <script src="https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.min.js"
+                integrity="sha512-lOrm9FgT1LKOJRUXF3tp6QaMorJftUjowOWiDcG5GFZ/q7ukof19V0HKx/GWzXCdt9zYju3/KhBNdCLzK8b90Q=="
+                crossorigin="anonymous" referrerpolicy="no-referrer"></script>
+        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.css"
+              integrity="sha512-NXUhxhkDgZYOMjaIgd89zF2w51Mub53Ru3zCNp5LTlEzMbNNAjTjDbpURYGS5Mop2cU4b7re1nOIucsVlrx9fA=="
+              crossorigin="anonymous" referrerpolicy="no-referrer"/>
+        <script>
+            jQuery(document).ready(function ($) {
+                $("#cms_template").on('change', function () {
+                    var select = $(this);
+                    var ovalue = $(this).find('option[selected]').attr('value');
+                    var form = $(this).closest('form');
+                    if ($(this).val() != ovalue) {
+                        var n = new Noty({
+                            modal: true,
+                            killer: true,
+                            layout: 'center',
+                            text: 'Vous êtes sur le point de modifier le template. Le formulaire va être rechargé. Veuillez confirmer votre choix.',
+                            buttons: [
+                                Noty.button('Confirmer', 'btn btn-success', function () {
+                                    $.ajax({
+                                        method: $(form).attr('method'),
+                                        url: $(form).attr('action'),
+                                        data: {
+                                            template: $(select).val(),
+                                            _token: $(form).find('input[name="_token"]').val(),
+                                            _method: $(form).find('input[name="_method"]').val(),
+                                            id: $(form).find('input[name="id"]').val(),
+                                        },
+                                        success: function () {
+                                            window.location.reload();
+                                        },
+                                    })
+                                }, {id: 'button1', 'data-status': 'ok'}),
+
+                                Noty.button('Annuler', 'btn btn-error', function () {
+                                    $(select).val(ovalue);
+                                    n.close();
+                                })
+                            ]
+                        });
+                    }
+                    n.show();
+                });
+            });
+        </script>
+    @endpush
+@endif