2018-07-09 19:27:22 +02:00
|
|
|
|
var productsTable = $('#products-table').DataTable({
|
|
|
|
|
'paginate': false,
|
|
|
|
|
'order': [[1, 'asc']],
|
|
|
|
|
'columnDefs': [
|
|
|
|
|
{ 'orderable': false, 'targets': 0 }
|
|
|
|
|
],
|
2018-07-10 20:37:13 +02:00
|
|
|
|
'language': JSON.parse(L('datatables_localization')),
|
2018-07-14 08:48:14 +02:00
|
|
|
|
'scrollY': false,
|
|
|
|
|
'colReorder': true
|
2018-07-09 19:27:22 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#search").on("keyup", function()
|
|
|
|
|
{
|
|
|
|
|
var value = $(this).val();
|
|
|
|
|
if (value === "all")
|
|
|
|
|
{
|
|
|
|
|
value = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
productsTable.search(value).draw();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(document).on('click', '.product-delete-button', function (e)
|
2017-04-15 23:16:20 +02:00
|
|
|
|
{
|
2018-04-21 19:18:00 +02:00
|
|
|
|
var objectName = $(e.currentTarget).attr('data-product-name');
|
|
|
|
|
var objectId = $(e.currentTarget).attr('data-product-id');
|
|
|
|
|
|
2017-04-15 23:16:20 +02:00
|
|
|
|
bootbox.confirm({
|
2018-04-21 19:18:00 +02:00
|
|
|
|
message: L('Are you sure to delete product "#1"?', objectName),
|
2017-04-15 23:16:20 +02:00
|
|
|
|
buttons: {
|
|
|
|
|
confirm: {
|
2018-04-18 19:37:36 +02:00
|
|
|
|
label: L('Yes'),
|
2017-04-15 23:16:20 +02:00
|
|
|
|
className: 'btn-success'
|
|
|
|
|
},
|
|
|
|
|
cancel: {
|
2018-04-18 19:37:36 +02:00
|
|
|
|
label: L('No'),
|
2017-04-15 23:16:20 +02:00
|
|
|
|
className: 'btn-danger'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
callback: function(result)
|
|
|
|
|
{
|
2017-04-20 22:01:14 +02:00
|
|
|
|
if (result === true)
|
2017-04-15 23:16:20 +02:00
|
|
|
|
{
|
2018-04-21 19:18:00 +02:00
|
|
|
|
Grocy.Api.Get('delete-object/products/' + objectId,
|
2017-04-15 23:16:20 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2018-04-18 19:03:39 +02:00
|
|
|
|
window.location.href = U('/products');
|
2017-04-15 23:16:20 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
|
|
|
|
console.error(xhr);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|