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) public function scopeOfType($query, $type)
{ {
switch($type) { switch($type) {
@ -148,6 +156,12 @@ class Item extends Model
return (bool)($app instanceof \App\EnhancedApps); return (bool)($app instanceof \App\EnhancedApps);
} }
public static function isEnhanced($class)
{
$app = new $class;
return (bool)($app instanceof \App\EnhancedApps);
}
public function enabled() public function enabled()
{ {
if($this->enhanced()) { if($this->enhanced()) {

View file

@ -81,13 +81,23 @@
@if(isset($item) && $item->enhanced()) @if(isset($item) && $item->enhanced())
<div id="sapconfig" style="display: block;"> <div id="sapconfig" style="display: block;">
@if(isset($item)) @if(isset($item))
@include('SupportedApps::'.$item->getconfig()->name.'.config') @include('SupportedApps::'.$item->getconfig()->name.'.config')
@endif @endif
</div> </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 @else
<div id="sapconfig"></div> <div id="sapconfig"></div>
@endif @endif
</div> </div>

View file

@ -26,6 +26,12 @@
appload(appvalue); 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) { $('#appname').on('keyup change', function(e) {
$('#tile-preview .title').html($(this).val()); $('#tile-preview .title').html($(this).val());
}) })
@ -39,7 +45,10 @@
$('.tags').select2(); $('.tags').select2();
function appload(appvalue) { 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 // Main details
$('#appimage').html("<img src='"+data.iconview+"' /><input type='hidden' name='icon' value='"+data.icon+"' />"); $('#appimage').html("<img src='"+data.iconview+"' /><input type='hidden' name='icon' value='"+data.icon+"' />");
$('input[name=colour]').val(data.colour); $('input[name=colour]').val(data.colour);
@ -53,8 +62,11 @@
$.get('/view/'+data.config, function(getdata) { $.get('/view/'+data.config, function(getdata) {
$('#sapconfig').html(getdata).show(); $('#sapconfig').html(getdata).show();
}); });
} else {
$('#sapconfig').html('').hide();
} }
}, "json"); }, "json");
}
} }