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;
}
}
@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({
}
.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>