grocy/public/viewjs/locations.js
4lloyd 76cbf796b6
[WIP] Simplified overviews on mobile (#1115)
* Simplified stock overview on mobile.

* Stock table horizontally scrollable

* Use the new mobile views for all pages (except the shopping list page, use the existing special handling there for now)
And add a clear filter button to all pages

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
2020-11-07 14:53:45 +01:00

66 lines
1.3 KiB
JavaScript

var locationsTable = $('#locations-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 },
{ 'searchable': false, "targets": 0 }
]
});
$('#locations-table tbody').removeClass("d-none");
locationsTable.columns.adjust().draw();
$('.dataTables_scrollBody').addClass("dragscroll");
dragscroll.reset();
$("#search").on("keyup", Delay(function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
locationsTable.search(value).draw();
}, 200));
$("#clear-filter-button").on("click", function()
{
$("#search").val("");
locationsTable.search("").draw();
});
$(document).on('click', '.location-delete-button', function(e)
{
var objectName = $(e.currentTarget).attr('data-location-name');
var objectId = $(e.currentTarget).attr('data-location-id');
bootbox.confirm({
message: __t('Are you sure to delete location "%s"?', objectName),
closeButton: false,
buttons: {
confirm: {
label: __t('Yes'),
className: 'btn-success'
},
cancel: {
label: __t('No'),
className: 'btn-danger'
}
},
callback: function(result)
{
if (result === true)
{
Grocy.Api.Delete('objects/locations/' + objectId, {},
function(result)
{
window.location.href = U('/locations');
},
function(xhr)
{
console.error(xhr);
}
);
}
}
});
});