From b8f04f3d1108f61b939414c1e7187f9b849ea240 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 14:52:45 +0000 Subject: [PATCH] Fix preview and config not retaining values --- app/Item.php | 14 ++++++++++++++ resources/views/items/form.blade.php | 10 ++++++++++ resources/views/items/scripts.blade.php | 14 +++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/Item.php b/app/Item.php index 1f3f8509..0c7f7778 100644 --- a/app/Item.php +++ b/app/Item.php @@ -124,6 +124,14 @@ class Item extends Model } } + public static function nameFromClass($class) + { + $explode = explode('\\', $class); + $name = end($explode); + + return $name; + } + public function scopeOfType($query, $type) { switch($type) { @@ -148,6 +156,12 @@ class Item extends Model return (bool)($app instanceof \App\EnhancedApps); } + public static function isEnhanced($class) + { + $app = new $class; + return (bool)($app instanceof \App\EnhancedApps); + } + public function enabled() { if($this->enhanced()) { diff --git a/resources/views/items/form.blade.php b/resources/views/items/form.blade.php index 684cf23f..be2656bb 100644 --- a/resources/views/items/form.blade.php +++ b/resources/views/items/form.blade.php @@ -81,13 +81,23 @@ @if(isset($item) && $item->enhanced()) +
@if(isset($item)) @include('SupportedApps::'.$item->getconfig()->name.'.config') @endif
+ + @elseif(old('class') && App\Item::isEnhanced(old('class'))) + +
+ @include('SupportedApps::'.App\Item::nameFromClass(old('class')).'.config') +
+ @else +
+ @endif diff --git a/resources/views/items/scripts.blade.php b/resources/views/items/scripts.blade.php index 5d08d93a..6ab3a223 100644 --- a/resources/views/items/scripts.blade.php +++ b/resources/views/items/scripts.blade.php @@ -26,6 +26,12 @@ appload(appvalue); } }); + // initial load + $('#tile-preview .title').html($('#appname').val()); + $('#tile-preview .item').css('backgroundColor', $('#appcolour').val()); + $('#tile-preview .app-icon').attr('src', $('#appimage img').attr('src')); + + // Updates $('#appname').on('keyup change', function(e) { $('#tile-preview .title').html($(this).val()); }) @@ -39,7 +45,10 @@ $('.tags').select2(); function appload(appvalue) { - $.post('{{ route('appload') }}', { app: appvalue }, function(data) { + if(appvalue == 'None') { + $('#sapconfig').html('').hide(); + } else { + $.post('{{ route('appload') }}', { app: appvalue }, function(data) { // Main details $('#appimage').html(""); $('input[name=colour]').val(data.colour); @@ -53,8 +62,11 @@ $.get('/view/'+data.config, function(getdata) { $('#sapconfig').html(getdata).show(); }); + } else { + $('#sapconfig').html('').hide(); } }, "json"); + } }