Fix datatable modals

This commit is contained in:
Katharina Bogad 2021-06-25 17:16:26 +02:00
parent 5be9faed43
commit 4cde333d35
6 changed files with 62 additions and 5 deletions

View File

@ -378,6 +378,10 @@ class GrocyClass
grocyProxy.Initialize(proxy);
self.LoadView(data.viewJsName, "#" + scopeId, proxy);
},
onShown: () =>
{
grocyProxy.FrontendHelpers.OnShown();
},
onHide: () =>
{
grocyProxy.Unload();
@ -388,10 +392,16 @@ class GrocyClass
}
});
},
error: (xhr, text, data) => { console.error(text); }
error: (xhr, text, data) =>
{
console.error(text);
}
})
}
Unload()
{
return; // root grocy instances never get unloaded.
}
UndoStockBooking(bookingId)

View File

@ -20,6 +20,7 @@ class GrocyFrontendHelpers
}
this.dropdowns = {}
this.dataTables = [];
this.InitDropdowns();
}
@ -249,6 +250,7 @@ class GrocyFrontendHelpers
InitDataTable(dataTable, searchFunction = null, clearFunction = null)
{
this.dataTables.push(dataTable);
dataTable.columns.adjust().draw();
var self = this;
@ -275,6 +277,16 @@ class GrocyFrontendHelpers
self.$scope("#clear-filter-button").on("click", clearFunction || defaultClearFunction);
}
// This method is called if this FrontendHelper is scoped to a modal
// and the modal is acutally shown.
OnShown()
{
for (let table of this.dataTables)
{
table.columns.adjust();
}
}
MakeFilterForColumn(selector, column, table, filterFunction = null, transferCss = false, valueMod = null)
{
var self = this;

View File

@ -44,6 +44,8 @@ class GrocyProxy
Object.assign(this.config.UserSettings, RootGrocy.UserSettings);
this.UserSettings = config.UserSettings;
}
this.unloaders = [];
}
Initialize(proxy)
@ -55,6 +57,11 @@ class GrocyProxy
this.FrontendHelpers = new GrocyFrontendHelpers(proxy, this.RootGrocy.Api, this.scopeSelector);
}
RegisterUnload(cb)
{
this.unloaders.push(cb);
}
Unload()
{
for (let component in this.Components)
@ -65,6 +72,13 @@ class GrocyProxy
comp.Unload();
}
}
let unloader = this.unloaders.pop();
while (unloader !== undefined)
{
unloader();
unloader = this.unloaders.pop();
}
}
Use(componentName, scope = null)

View File

@ -34,7 +34,7 @@
$scope('#stockentries-table tbody').removeClass("d-none");
stockEntriesTable.columns.adjust().draw();
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex)
var moreSearch = function(settings, data, dataIndex)
{
var productId = productpicker.GetValue();
@ -44,6 +44,16 @@
}
return false;
};
$.fn.dataTable.ext.search.push(moreSearch);
Grocy.RegisterUnload(() =>
{
var funcIdx = $.fn.dataTable.ext.search.indexOf(moreSearch);
if (funcIdx !== -1)
$.fn.dataTable.ext.search.splice(funcIdx);
});
$scope("#clear-filter-button").on("click", function()

View File

@ -2150,3 +2150,9 @@ msgstr ""
msgid "Unable to print"
msgstr ""
msgid "Datum 1"
msgstr ""
msgid "Datum ohne Zeit"
msgstr ""

View File

@ -4,12 +4,17 @@
@section('activeNav', '')
@section('viewJsName', 'stockjournalsummary')
@php
$collapsed_none = $embedded ? '' : 'd-md-none';
$collapsed_flex = $embedded ? '' : 'd-md-flex';
@endphp
@section('content')
<div class="row">
<div class="col">
<h2 class="title">@yield('title')</h2>
<div class="float-right">
<button class="btn btn-outline-dark d-md-none mt-2 order-1 order-md-3"
<button class="btn btn-outline-dark {{ $collapsed_none }} mt-2 order-1 order-md-3"
type="button"
data-toggle="collapse"
data-target="#table-filter-row">
@ -21,7 +26,7 @@
<hr class="my-2">
<div class="row collapse d-md-flex"
<div class="row collapse {{ $collapsed_flex }}"
id="table-filter-row">
<div class="col-12 col-md-6 col-xl-2">
<div class="input-group">