Fix preview and config not retaining values

This commit is contained in:
Chris 2018-11-06 14:52:45 +00:00
parent e91f65f833
commit b8f04f3d11
3 changed files with 37 additions and 1 deletions

View file

@ -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()) {

View file

@ -81,13 +81,23 @@
@if(isset($item) && $item->enhanced())
<div id="sapconfig" style="display: block;">
@if(isset($item))
@include('SupportedApps::'.$item->getconfig()->name.'.config')
@endif
</div>
@elseif(old('class') && App\Item::isEnhanced(old('class')))
<div id="sapconfig" style="display: block;">
@include('SupportedApps::'.App\Item::nameFromClass(old('class')).'.config')
</div>
@else
<div id="sapconfig"></div>
@endif
</div>

View file

@ -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,6 +45,9 @@
$('.tags').select2();
function appload(appvalue) {
if(appvalue == 'None') {
$('#sapconfig').html('').hide();
} else {
$.post('{{ route('appload') }}', { app: appvalue }, function(data) {
// Main details
$('#appimage').html("<img src='"+data.iconview+"' /><input type='hidden' name='icon' value='"+data.icon+"' />");
@ -53,8 +62,11 @@
$.get('/view/'+data.config, function(getdata) {
$('#sapconfig').html(getdata).show();
});
} else {
$('#sapconfig').html('').hide();
}
}, "json");
}
}