]> _ Git - fluidbook-toolbox.git/commitdiff
wip #4210 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Jun 2022 16:27:50 +0000 (18:27 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Jun 2022 16:27:50 +0000 (18:27 +0200)
app/Fields/FluidbookTheme.php
app/Models/FluidbookTheme.php
public/packages/fluidbook/toolbox/css/style.less
resources/views/fields/fluidbook_theme_selector.blade.php
resources/views/fields/fluidbook_translation_overwrite.blade.php
resources/views/fluidbook_theme/preview.blade.php

index c4f0f48b1421c0fc1226ec8bc391245cce93a3d4..8ac7318aa4cfdd4650e13c1d728d8439cff4f074 100644 (file)
@@ -4,16 +4,24 @@
 namespace App\Fields;
 
 
-use Cubist\Backpack\Magic\Fields\SelectFromModel;
+use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
-class FluidbookTheme extends SelectFromModel
+class FluidbookTheme extends SelectFromArray
 {
     protected $_adminType = 'fluidbook_theme_selector';
-    protected $_viewNamespace='fields';
+    protected $_viewNamespace = 'fields';
 
-    public function __construct($attributes)
+    public function getOptions()
     {
-        $attributes['optionsmodel'] = \App\Models\FluidbookTheme::class;
-        parent::__construct($attributes);
+        return self::getThemeSelectorOptions();
+    }
+
+    public static function getThemeSelectorOptions()
+    {
+        $res = [];
+        foreach (\App\Models\FluidbookTheme::orderBy('id', 'DESC')->get() as $theme) {
+            $res[$theme['id']] = $theme->name . ' (#' . $theme->id . ')';
+        }
+        return $res;
     }
 }
index c22d5867d10cd7cbf1a702b0fc472b56f8143fdc..78d61f4133b9ea276935ce22b931e987ebabbcd5 100644 (file)
@@ -749,7 +749,7 @@ class FluidbookTheme extends ToolboxModel
 
     public static function getThemePreviewURL($id, $params = [], $page = 2)
     {
-        $defaultParams = ['shortLoading' => '1'];
+        $defaultParams = [/*'shortLoading' => '1'*/];
         $params = array_merge($defaultParams, $params);
 
         if (count($params) > 0) {
index 9788f4c1d7d73666e239cbfcc37f6fb57b1dcbe1..35833a9ee6f8e610d366d91262d4e11f21a54b21 100644 (file)
@@ -374,7 +374,9 @@ body.embeded {
 
     main > div > .row > div {
         max-width: 100%;
-        flex: none;
+    }
+
+    main > div > .row > div {
     }
 }
 
index 9f798707c828880a39fe1550beb1270781b1f231..916a76ecc3eb4bcbf0f196013a07678312a1b5b0 100644 (file)
@@ -2,6 +2,7 @@
     @php $seenThemeSelector=true;@endphp
     @push('crud_fields_scripts')
         <script>
+            var hadThemeEditorOpen = false;
             var selector = '.select2_from_array[name="{{$field['name']}}"]';
             $(function () {
                 $(document).on('change', selector, function () {
                     ifr.css('height', ih);
                     $('.themeSelector .preview').css('max-height', (ih / 2) + 10);
                 }
+
+                setInterval(function () {
+                    checkThemeEditor();
+                }, 1000);
             });
 
+            function checkThemeEditor() {
+
+                if ($(".featherlight-content iframe").length === 0) {
+                    // No theme editor window open
+                    if (hadThemeEditorOpen) {
+                        hadThemeEditorOpen = false;
+                        // Reload theme viewer after editor has been closed
+                        var iframe = $('.themeSelector #themePreviewIframe');
+                        iframe.get(0).contentWindow.location = $(iframe).attr('src');
+                        console.log('reload preview theme');
+                    }
+                    return;
+                }
+                $(".featherlight-content iframe").each(function () {
+                    var c = this.contentWindow.location.pathname.toString().split('/');
+                    var idx = c.indexOf('fluidbook-theme');
+                    if (idx > 0 && c.indexOf('edit') >= 0) {
+                        hadThemeEditorOpen = true;
+                        var id = c[idx + 1];
+                        if (id != $(selector).val()) {
+                            if ($(selector).find('option[value="' + id + '"]').length === 0) {
+                                $(selector).append('<option value="' + id + '">Theme #' + id + '</option>');
+                                $(selector).trigger('change');
+                            }
+                            setTimeout(function () {
+                                $(selector).val(id);
+                                $(selector).trigger('change');
+                            }, 250);
+                        }
+                    }
+                });
+            }
+
 
             function updateThemeSelector() {
                 var themeID = $(selector).val();
                 var iframe = $('.themeSelector .preview iframe');
                 $(iframe).attr('src', $(iframe).data('url').replace(/\$id/, themeID));
                 $(".themeSelector .actions a").each(function () {
-                    $(this).attr('href', $(this).data('url').replace(/\$id/, themeID));
+                    $(this).attr('href', $(this).data('url').replace(/\$id/, themeID) + '&ajax=' + $(selector).data('ajax') + '&entry={{addcslashes(get_class($entry),'\\')}}&id={{$entry->id}}&name={{$field['name']}}');
                 });
                 var url = '{{backpack_url('/fluidbook-theme/$id/infos')}}'.replace(/\$id/, themeID);
                 $.ajax({
@@ -57,7 +95,7 @@
             }
 
             .themeSelector .preview {
-                width: 70%;
+                width: 60%;
                 display: inline-block;
                 overflow: hidden;
             }
 
             .themeSelector .actions {
                 display: inline-block;
-                width: 30%;
+                width: 40%;
                 vertical-align: top;
                 padding: 0 0 0 20px;
+                white-space: normal;
             }
 
             .themeSelector .actions a {
         <p class="owner"></p>
         <p>{{__('Crée le')}} <span style="font-weight: bold" class="created_at"></span><br>
             {{__('Mise à jour le')}} <span style="font-weight: bold" class="updated_at"></span></p>
-        <a data-featherlight="iframe" data-featherlight-iframe-style="display:block;width:85vw;height:85vh;" data-url="{{backpack_url('fluidbook-theme/$id/clone-edit')}}?embeded=1" class="btn btn-sm btn-secondary"><i
+        <a data-featherlight="iframe" data-featherlight-iframe-style="display:block;width:85vw;height:85vh;"
+           data-url="{{backpack_url('fluidbook-theme/$id/clone-edit')}}?embeded=1" class="btn btn-sm btn-secondary"><i
                 class="la la-clone"></i> {{__('Dupliquer et éditer')}}</a>
-        <a data-featherlight="iframe" data-featherlight-iframe-style="display:block;width:85vw;height:85vh;" data-url="{{backpack_url('fluidbook-theme/$id/edit')}}?embeded=1" class="btn btn-sm btn-success"><i
+        <a data-featherlight="iframe" data-featherlight-iframe-style="display:block;width:85vw;height:85vh;"
+           data-url="{{backpack_url('fluidbook-theme/$id/edit')}}?embeded=1" class="btn btn-sm btn-success"><i
                 class="la la-edit"></i> {{__('Éditer')}}
         </a>
     </div>
index 6c349fa4edfad14db8ddbd9b4ae5a8e5ea862d1e..77e2a496efb8ebcc23c0a6eb08a85fbaf8ace841 100644 (file)
@@ -5,7 +5,6 @@
             var allTranslations =@json(\App\Models\FluidbookTranslate::getAllFluidbookTranslations());
             var locale = $('select[name="locale"]').val();
             $(document).on('change', 'select[name="locale"]', function () {
-                console.log(locale);
                 locale = $('select[name="locale"]').val()
                 updateTranslationOverwrite();
             });
index dcdf5f1a75c2813a0d5a431a8fc5766d83cec1ca..8002b95b51703592c721dca84b676a1aea243963 100644 (file)
                         var name = $(k).val();
                         variables[name] = filename;
                     });
-                    console.log(variables);
 
                     var json = JSON.stringify(variables);
                     var url = previewURL.replace('&theme=', '&theme=' + encodeURIComponent(json));
                     document.getElementById('themePreviewIframe').src = url;
-
                 });
             });
         })(jQuery);