Files
grocy/public/viewjs/products.js

103 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-07-09 19:27:22 +02:00
var productsTable = $('#products-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 },
{ 'searchable': false, "targets": 0 }
].concat($.fn.dataTable.defaults.columnDefs)
2018-07-09 19:27:22 +02:00
});
$('#products-table tbody').removeClass("d-none");
productsTable.columns.adjust().draw();
2018-07-09 19:27:22 +02:00
$("#search").on("keyup", Delay(function()
2018-07-09 19:27:22 +02:00
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
2018-07-09 19:27:22 +02:00
productsTable.search(value).draw();
}, 200));
2018-07-09 19:27:22 +02:00
$("#product-group-filter").on("change", function()
{
var value = $("#product-group-filter option:selected").text();
if (value === __t("All"))
{
value = "";
}
2020-11-15 09:21:54 +01:00
productsTable.column(6).search(value).draw();
});
$("#clear-filter-button").on("click", function()
{
$("#search").val("");
$("#product-group-filter").val("all");
productsTable.column(7).search("").draw();
productsTable.search("").draw();
$("#show-disabled-products").prop('checked', false);
});
if (typeof GetUriParam("product-group") !== "undefined")
{
$("#product-group-filter").val(GetUriParam("product-group"));
$("#product-group-filter").trigger("change");
}
2020-08-30 12:18:16 +02:00
$(document).on('click', '.product-delete-button', function(e)
2017-04-15 23:16:20 +02:00
{
var objectName = $(e.currentTarget).attr('data-product-name');
var objectId = $(e.currentTarget).attr('data-product-id');
bootbox.confirm({
2020-12-07 19:55:31 +01:00
message: __t('Are you sure to delete product "%s"?', objectName) + '<br><br>' + __t('This also removes any stock amount, the journal and all other references of this product - consider disabling it instead, if you want to keep that and just hide the product.'),
closeButton: false,
buttons: {
confirm: {
label: __t('Yes'),
className: 'btn-success'
},
cancel: {
label: __t('No'),
className: 'btn-danger'
}
},
callback: function(result)
2017-04-15 23:16:20 +02:00
{
if (result === true)
2017-04-15 23:16:20 +02:00
{
jsonData = {};
jsonData.active = 0;
Grocy.Api.Delete('objects/products/' + objectId, {},
function(result)
{
window.location.href = U('/products');
2017-04-15 23:16:20 +02:00
},
function(xhr)
2017-04-15 23:16:20 +02:00
{
console.error(xhr);
2017-04-15 23:16:20 +02:00
}
);
2017-04-15 23:16:20 +02:00
}
}
});
});
$("#show-disabled-products").change(function()
{
if (this.checked)
{
window.location.href = U('/products?include_disabled');
}
else
{
window.location.href = U('/products');
}
2017-04-15 23:16:20 +02:00
});
if (GetUriParam('include_disabled'))
{
$("#show-disabled-products").prop('checked', true);
}