Added product groups (this closes #55)

This commit is contained in:
Bernd Bestel
2018-09-24 13:02:52 +02:00
parent e472711d23
commit 66095738e3
15 changed files with 339 additions and 29 deletions

View File

@@ -0,0 +1,55 @@
$('#save-product-group-button').on('click', function(e)
{
e.preventDefault();
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('add-object/product_groups', $('#product-group-form').serializeJSON(),
function(result)
{
window.location.href = U('/productgroups');
},
function(xhr)
{
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
}
);
}
else
{
Grocy.Api.Post('edit-object/product_groups/' + Grocy.EditObjectId, $('#product-group-form').serializeJSON(),
function(result)
{
window.location.href = U('/productgroups');
},
function(xhr)
{
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
}
);
}
});
$('#product-group-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('product-group-form');
});
$('#product-group-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('product-group-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-product-group-button').click();
}
}
});
$('#name').focus();
Grocy.FrontendHelpers.ValidateForm('product-group-form');

View File

@@ -0,0 +1,62 @@
var groupsTable = $('#productgroups-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true,
'stateSaveParams': function(settings, data)
{
data.search.search = "";
}
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
groupsTable.search(value).draw();
});
$(document).on('click', '.product-group-delete-button', function(e)
{
var objectName = $(e.currentTarget).attr('data-group-name');
var objectId = $(e.currentTarget).attr('data-group-id');
bootbox.confirm({
message: L('Are you sure to delete product group "#1"?', objectName),
buttons: {
confirm: {
label: L('Yes'),
className: 'btn-success'
},
cancel: {
label: L('No'),
className: 'btn-danger'
}
},
callback: function(result)
{
if (result === true)
{
Grocy.Api.Get('delete-object/product_groups/' + objectId,
function(result)
{
window.location.href = U('/productgroups');
},
function(xhr)
{
console.error(xhr);
}
);
}
}
});
});

View File

@@ -1,8 +1,10 @@
var shoppingListTable = $('#shoppinglist-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
"orderFixed": [[3, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
{ 'orderable': false, 'targets': 0 },
{ 'visible': false, 'targets': 3 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
@@ -11,6 +13,9 @@
'stateSaveParams': function(settings, data)
{
data.search.search = "";
},
'rowGroup': {
dataSrc: 3
}
});