View Loading via singleton

This commit is contained in:
Katharina Bogad 2021-06-23 22:41:58 +02:00
parent 4267b42a0a
commit bda2a742ae
3 changed files with 27 additions and 9 deletions

View File

@ -81,9 +81,6 @@ view_eslint_config.globals = eslint_config.globals.concat([
"RefreshLocaleNumberDisplay",
"RefreshLocaleNumberInput",
"LoadImagesLazy",
"GetUriParam",
"UpdateUriParam",
"RemoveUriParam",
"EmptyElementWhenMatches",
"animateCSS"
]);

View File

@ -237,17 +237,33 @@ class GrocyClass
}
}
LoadView(viewName)
LoadView(viewName, scope = null)
{
if (Object.prototype.hasOwnProperty.call(window, viewName + "View"))
{
window[viewName + "View"](this);
window[viewName + "View"](this, scope);
}
else
{
console.error("Could not load view " + viewName + ', not loaded yet.');
}
}
PreloadView(viewName)
PreloadView(viewName, cb = () => { })
{
$.getScript(this.FormatUrl('/viewjs/' + viewName + '.js'));
if (!Object.prototype.hasOwnProperty.call(window, viewName + "View"))
{
$.ajax({
dataType: "script",
cache: true,
url: this.FormatUrl('/viewjs/' + viewName + '.js'),
success: cb
});
}
else
{
cb();
}
}
UndoStockBooking(bookingId)

View File

@ -655,8 +655,13 @@
@if(!empty($__t('bootstrap-select_locale') && $__t('bootstrap-select_locale') != 'x'))<script src="{{ $U('/js/locales/bootstrap-select/', true) }}defaults-{{ $__t('bootstrap-select_locale') }}.js?v={{ $version }}"></script>@endif
<script src="{{ $U('/js/grocy.js?v=', true) }}{{ $version }}"></script>
@hasSection('viewJsName')<script src="{{ $U('/viewjs', true) }}/@yield('viewJsName').js?v={{ $version }}"></script>@endif
<script>
GrocyClass.createSingleton(GrocyConfig);
let viewjsname = null;
@hasSection('viewJsName')
viejsname = "@yield('viewJsName')";
@endif
GrocyClass.createSingleton(GrocyConfig, viewjsname);
</script>
@stack('pageScripts')
@ -690,7 +695,7 @@
@endphp
@stack('componentScripts')
@hasSection('viewJsName')<script src="{{ $U('/viewjs', true) }}/@yield('viewJsName').js?v={{ $version }}"></script>@endif
@if(file_exists(GROCY_DATAPATH . '/custom_js.html'))
@php include GROCY_DATAPATH . '/custom_js.html' @endphp