Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm committed Nov 6, 2024
1 parent 34fed8b commit 098734b
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/resources/views/ui/components/filters-navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,50 @@
</div>{{-- /.navbar-collapse --}}
</nav>

@push('crud_list_scripts')
@push('after_scripts')
@basset('https://unpkg.com/[email protected]/src/URI.min.js')
<script>
function addOrUpdateUriParameter(uri, parameter, value) {
var new_url = normalizeAmpersand(uri);
var new_url = normalizeAmpersand(uri);
new_url = URI(new_url).normalizeQuery();
new_url = URI(new_url).normalizeQuery();
// this param is only needed in datatables persistent url redirector
// not when applying filters so we remove it.
if (new_url.hasQuery('persistent-table')) {
new_url.removeQuery('persistent-table');
}
// this param is only needed in datatables persistent url redirector
// not when applying filters so we remove it.
if (new_url.hasQuery('persistent-table')) {
new_url.removeQuery('persistent-table');
}
if (new_url.hasQuery(parameter)) {
if (new_url.hasQuery(parameter)) {
new_url.removeQuery(parameter);
}
}
if (value !== '' && value != null) {
if (value !== '' && value != null) {
new_url = new_url.addQuery(parameter, value);
}
}
$('#remove_filters_button').toggleClass('invisible', !new_url.query());
$('#remove_filters_button').toggleClass('invisible', !new_url.query());
return normalizeAmpersand(new_url.toString());
}
function updatePageUrl(filterName, filterValue, currentUrl = null) {
currentUrl = currentUrl || window.location.href;
let newUrl = addOrUpdateUriParameter(window.location.href, filterName, filterValue);
let newUrl = addOrUpdateUriParameter(currentUrl, filterName, filterValue);
crud.updateUrl(newUrl);
return newUrl;
}
function updateDatatablesOnFilterChange(filterName, filterValue, update_url = false, debounce = 500) {
// behaviour for ajax tables
var new_url = updatePageUrl(filterName, filterValue, crud.table.ajax.url());
let new_url = updatePageUrl(filterName, filterValue, crud.table.ajax.url());
crud.table.ajax.url(new_url);
// when we are clearing ALL filters, we would not update the table url here, because this is done PER filter
// and we have a function that will do this update for us after all filters had been cleared.
if(update_url) {
// replace the datatables ajax url with new_url and reload it
callFunctionOnce(function() { refreshDatatablesOnFilterChange(new_url) }, debounce, 'refreshDatatablesOnFilterChange');
// replace the datatables ajax url with new_url and reload it
callFunctionOnce(function() { refreshDatatablesOnFilterChange(new_url) }, debounce, 'refreshDatatablesOnFilterChange');
}
return new_url;
Expand Down Expand Up @@ -110,17 +110,16 @@ function normalizeAmpersand(string) {
$("#remove_filters_button").click(function(e) {
e.preventDefault();
// emit a new custom Backpack:filter-removed event
document.dispatchEvent(new CustomEvent('Backpack:filters-cleared'));
// emit a new custom Backpack:filter-removed event
document.dispatchEvent(new CustomEvent('Backpack:filters-cleared'));
});
// hide the Remove filters button when no filter is active
$(".navbar-filters li[filter-name]").on('filter:clear', function() {
var anyActiveFilters = false;
$(".navbar-filters li[filter-name]").each(function () {
if ($(this).hasClass('active')) {
anyActiveFilters = true;
// console.log('ACTIVE FILTER');
anyActiveFilters = true;
}
});
Expand Down

0 comments on commit 098734b

Please sign in to comment.