API - A bit more RESTful (#140)

* Restful routes

* Change public/viewjs to match API routes

* Move the GET and POST together. Fixed Typos. PUT for object/user edits.

* Verb-less Generic Entity Interactions

* Create Grocy.Api.Put

* Create Grocy.Api.Delete

* Fix Volatile Slim Error order in routes and adjust to english noun
This commit is contained in:
Chris Forkner 2019-01-19 00:37:21 -07:00 committed by Bernd Bestel
parent 98d95f80df
commit 0ce8d706a6
41 changed files with 278 additions and 216 deletions

View File

@ -21,12 +21,12 @@
localizedText = text; localizedText = text;
} }
for (var i = 0; i < placeholderValues.length; i++) for (var i = 0; i < placeholderValues.length; i++)
{ {
localizedText = localizedText.replace('#' + (i + 1), placeholderValues[i]); localizedText = localizedText.replace('#' + (i + 1), placeholderValues[i]);
} }
return localizedText; return localizedText;
} }
@ -86,7 +86,7 @@ if (window.localStorage.getItem("sidebar_state") === "collapsed")
$.timeago.settings.allowFuture = true; $.timeago.settings.allowFuture = true;
RefreshContextualTimeago = function() RefreshContextualTimeago = function()
{ {
$("time.timeago").each(function() $("time.timeago").each(function()
{ {
var element = $(this); var element = $(this);
@ -177,6 +177,68 @@ Grocy.Api.Post = function(apiFunction, jsonData, success, error)
xhr.send(JSON.stringify(jsonData)); xhr.send(JSON.stringify(jsonData));
}; };
Grocy.Api.Put = function(apiFunction, jsonData, success, error)
{
var xhr = new XMLHttpRequest();
var url = U('/api/' + apiFunction);
xhr.onreadystatechange = function()
{
if (xhr.readyState === XMLHttpRequest.DONE)
{
if (xhr.status === 200)
{
if (success)
{
success(JSON.parse(xhr.responseText));
}
}
else
{
if (error)
{
error(xhr);
}
}
}
};
xhr.open('PUT', url, true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.send(JSON.stringify(jsonData));
};
Grocy.Api.Delete = function(apiFunction, jsonData, success, error)
{
var xhr = new XMLHttpRequest();
var url = U('/api/' + apiFunction);
xhr.onreadystatechange = function()
{
if (xhr.readyState === XMLHttpRequest.DONE)
{
if (xhr.status === 200)
{
if (success)
{
success(JSON.parse(xhr.responseText));
}
}
else
{
if (error)
{
error(xhr);
}
}
}
};
xhr.open('DELETE', url, true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.send(JSON.stringify(jsonData));
};
Grocy.Api.UploadFile = function(file, group, fileName, success, error) Grocy.Api.UploadFile = function(file, group, fileName, success, error)
{ {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
@ -286,7 +348,7 @@ Grocy.FrontendHelpers.ShowGenericError = function(message, exception)
}); });
} }
}); });
console.error(exception); console.error(exception);
} }
@ -310,7 +372,7 @@ $(".user-setting-control").on("change", function()
{ {
inputType = element.attr("type").toLowerCase(); inputType = element.attr("type").toLowerCase();
} }
if (inputType === "checkbox") if (inputType === "checkbox")
{ {
value = element.is(":checked"); value = element.is(":checked");
@ -319,9 +381,9 @@ $(".user-setting-control").on("change", function()
{ {
var value = element.val(); var value = element.val();
} }
Grocy.UserSettings[settingKey] = value; Grocy.UserSettings[settingKey] = value;
jsonData = { }; jsonData = { };
jsonData.value = value; jsonData.value = value;
Grocy.Api.Post('user/settings/' + settingKey, jsonData, Grocy.Api.Post('user/settings/' + settingKey, jsonData,
@ -358,7 +420,7 @@ ResizeResponsiveEmbeds = function(fillEntireViewport = false)
{ {
var maxHeight = $("body").height(); var maxHeight = $("body").height();
} }
$(".embed-responsive").attr("height", maxHeight.toString() + "px"); $(".embed-responsive").attr("height", maxHeight.toString() + "px");
} }
$(window).on('resize', function() $(window).on('resize', function()

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
batteriesTable.search(value).draw(); batteriesTable.search(value).draw();
}); });
@ -52,7 +52,7 @@ $(document).on('click', '.battery-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/batteries/' + objectId, Grocy.Api.Delete('object/batteries/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/batteries'); window.location.href = U('/batteries');

View File

@ -28,7 +28,7 @@ $("#battery-filter").on("change", function()
{ {
text = ""; text = "";
} }
batteriesJournalTable.column(1).search(text).draw(); batteriesJournalTable.column(1).search(text).draw();
}); });
@ -39,7 +39,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
batteriesJournalTable.search(value).draw(); batteriesJournalTable.search(value).draw();
}); });
@ -56,7 +56,7 @@ $(document).on('click', '.undo-battery-execution-button', function(e)
var element = $(e.currentTarget); var element = $(e.currentTarget);
var chargeCycleId = $(e.currentTarget).attr('data-charge-cycle-id'); var chargeCycleId = $(e.currentTarget).attr('data-charge-cycle-id');
Grocy.Api.Get('batteries/undo-charge-cycle/' + chargeCycleId.toString(), Grocy.Api.Post('batteries/' + chargeCycleId.toString() + '/undo',
function(result) function(result)
{ {
element.closest("tr").addClass("text-muted"); element.closest("tr").addClass("text-muted");

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
batteriesOverviewTable.search(value).draw(); batteriesOverviewTable.search(value).draw();
}); });
@ -41,7 +41,7 @@ $("#status-filter").on("change", function()
// Transfer CSS classes of selected element to dropdown element (for background) // Transfer CSS classes of selected element to dropdown element (for background)
$(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control"); $(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control");
batteriesOverviewTable.column(4).search(value).draw(); batteriesOverviewTable.column(4).search(value).draw();
}); });
@ -61,15 +61,15 @@ $(document).on('click', '.track-charge-cycle-button', function(e)
document.activeElement.blur(); document.activeElement.blur();
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
var batteryId = $(e.currentTarget).attr('data-battery-id'); var batteryId = $(e.currentTarget).attr('data-battery-id');
var batteryName = $(e.currentTarget).attr('data-battery-name'); var batteryName = $(e.currentTarget).attr('data-battery-name');
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss'); var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
Grocy.Api.Get('batteries/track-charge-cycle/' + batteryId + '?tracked_time=' + trackedTime, Grocy.Api.Post('batteries/' + batteryId + '/charged?tracked_time=' + trackedTime,
function() function()
{ {
Grocy.Api.Get('batteries/get-battery-details/' + batteryId, Grocy.Api.Get('batteries/' + batteryId,
function(result) function(result)
{ {
var batteryRow = $('#battery-' + batteryId + '-row'); var batteryRow = $('#battery-' + batteryId + '-row');
@ -128,7 +128,7 @@ $(document).on('click', '.track-charge-cycle-button', function(e)
function RefreshStatistics() function RefreshStatistics()
{ {
var nextXDays = $("#info-due-batteries").data("next-x-days"); var nextXDays = $("#info-due-batteries").data("next-x-days");
Grocy.Api.Get('batteries/get-current', Grocy.Api.Get('batteries',
function(result) function(result)
{ {
var dueCount = 0; var dueCount = 0;
@ -146,7 +146,7 @@ function RefreshStatistics()
dueCount++; dueCount++;
} }
}); });
$("#info-due-batteries").text(Pluralize(dueCount, L('#1 battery is due to be charged within the next #2 days', dueCount, nextXDays), L('#1 batteries are due to be charged within the next #2 days', dueCount, nextXDays))); $("#info-due-batteries").text(Pluralize(dueCount, L('#1 battery is due to be charged within the next #2 days', dueCount, nextXDays), L('#1 batteries are due to be charged within the next #2 days', dueCount, nextXDays)));
$("#info-overdue-batteries").text(Pluralize(overdueCount, L('#1 battery is overdue to be charged', overdueCount), L('#1 batteries are overdue to be charged', overdueCount))); $("#info-overdue-batteries").text(Pluralize(overdueCount, L('#1 battery is overdue to be charged', overdueCount), L('#1 batteries are overdue to be charged', overdueCount)));
}, },

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/batteries', jsonData, Grocy.Api.Post('object/batteries', jsonData,
function(result) function(result)
{ {
window.location.href = U('/batteries'); window.location.href = U('/batteries');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Post('edit-object/batteries/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/batteries/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/batteries'); window.location.href = U('/batteries');
@ -45,7 +45,7 @@ $('#battery-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('battery-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('battery-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -5,10 +5,10 @@
var jsonForm = $('#batterytracking-form').serializeJSON(); var jsonForm = $('#batterytracking-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("batterytracking-form"); Grocy.FrontendHelpers.BeginUiBusy("batterytracking-form");
Grocy.Api.Get('batteries/get-battery-details/' + jsonForm.battery_id, Grocy.Api.Get('batteries/' + jsonForm.battery_id,
function (batteryDetails) function (batteryDetails)
{ {
Grocy.Api.Get('batteries/track-charge-cycle/' + jsonForm.battery_id + '?tracked_time=' + $('#tracked_time').find('input').val(), Grocy.Api.Post('batteries/' + jsonForm.battery_id + '/charge?tracked_time=' + $('#tracked_time').find('input').val(),
function(result) function(result)
{ {
Grocy.FrontendHelpers.EndUiBusy("batterytracking-form"); Grocy.FrontendHelpers.EndUiBusy("batterytracking-form");
@ -73,7 +73,7 @@ $('#batterytracking-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('batterytracking-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('batterytracking-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;
@ -92,7 +92,7 @@ $('#tracked_time').find('input').on('keypress', function (e)
function UndoChargeCycle(chargeCycleId) function UndoChargeCycle(chargeCycleId)
{ {
Grocy.Api.Get('batteries/undo-charge-cycle/' + chargeCycleId.toString(), Grocy.Api.Post('batteries' + chargeCycleId.toString() + '/undo',
function(result) function(result)
{ {
toastr.success(L("Charge cycle successfully undone")); toastr.success(L("Charge cycle successfully undone"));

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/chores', jsonData, Grocy.Api.Post('object/chores', jsonData,
function(result) function(result)
{ {
window.location.href = U('/chores'); window.location.href = U('/chores');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Post('edit-object/chores/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/chores/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/chores'); window.location.href = U('/chores');

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
choresTable.search(value).draw(); choresTable.search(value).draw();
}); });
@ -52,7 +52,7 @@ $(document).on('click', '.chore-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/chores/' + objectId, Grocy.Api.Delete('object/chores/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/chores'); window.location.href = U('/chores');

View File

@ -28,7 +28,7 @@ $("#chore-filter").on("change", function()
{ {
text = ""; text = "";
} }
choresJournalTable.column(1).search(text).draw(); choresJournalTable.column(1).search(text).draw();
}); });
@ -39,7 +39,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
choresJournalTable.search(value).draw(); choresJournalTable.search(value).draw();
}); });
@ -56,7 +56,7 @@ $(document).on('click', '.undo-chore-execution-button', function(e)
var element = $(e.currentTarget); var element = $(e.currentTarget);
var executionId = $(e.currentTarget).attr('data-execution-id'); var executionId = $(e.currentTarget).attr('data-execution-id');
Grocy.Api.Get('chores/undo-chore-execution/' + executionId.toString(), Grocy.Api.Post('chores/' + executionId.toString() + '/undo',
function(result) function(result)
{ {
element.closest("tr").addClass("text-muted"); element.closest("tr").addClass("text-muted");

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
choresOverviewTable.search(value).draw(); choresOverviewTable.search(value).draw();
}); });
@ -41,7 +41,7 @@ $("#status-filter").on("change", function()
// Transfer CSS classes of selected element to dropdown element (for background) // Transfer CSS classes of selected element to dropdown element (for background)
$(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control"); $(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control");
choresOverviewTable.column(4).search(value).draw(); choresOverviewTable.column(4).search(value).draw();
}); });
@ -61,15 +61,15 @@ $(document).on('click', '.track-chore-button', function(e)
document.activeElement.blur(); document.activeElement.blur();
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
var choreId = $(e.currentTarget).attr('data-chore-id'); var choreId = $(e.currentTarget).attr('data-chore-id');
var choreName = $(e.currentTarget).attr('data-chore-name'); var choreName = $(e.currentTarget).attr('data-chore-name');
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss'); var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
Grocy.Api.Get('chores/track-chore-execution/' + choreId + '?tracked_time=' + trackedTime, Grocy.Api.Post('chores/' + choreId + '/execute?tracked_time=' + trackedTime,
function() function()
{ {
Grocy.Api.Get('chores/get-chore-details/' + choreId, Grocy.Api.Get('chores/' + choreId,
function(result) function(result)
{ {
var choreRow = $('#chore-' + choreId + '-row'); var choreRow = $('#chore-' + choreId + '-row');
@ -128,7 +128,7 @@ $(document).on('click', '.track-chore-button', function(e)
function RefreshStatistics() function RefreshStatistics()
{ {
var nextXDays = $("#info-due-chores").data("next-x-days"); var nextXDays = $("#info-due-chores").data("next-x-days");
Grocy.Api.Get('chores/get-current', Grocy.Api.Get('chores',
function(result) function(result)
{ {
var dueCount = 0; var dueCount = 0;
@ -146,7 +146,7 @@ function RefreshStatistics()
dueCount++; dueCount++;
} }
}); });
$("#info-due-chores").text(Pluralize(dueCount, L('#1 chore is due to be done within the next #2 days', dueCount, nextXDays), L('#1 chores are due to be done within the next #2 days', dueCount, nextXDays))); $("#info-due-chores").text(Pluralize(dueCount, L('#1 chore is due to be done within the next #2 days', dueCount, nextXDays), L('#1 chores are due to be done within the next #2 days', dueCount, nextXDays)));
$("#info-overdue-chores").text(Pluralize(overdueCount, L('#1 chore is overdue to be done', overdueCount), L('#1 chores are overdue to be done', overdueCount))); $("#info-overdue-chores").text(Pluralize(overdueCount, L('#1 chore is overdue to be done', overdueCount), L('#1 chores are overdue to be done', overdueCount)));
}, },

View File

@ -5,10 +5,10 @@
var jsonForm = $('#choretracking-form').serializeJSON(); var jsonForm = $('#choretracking-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("choretracking-form"); Grocy.FrontendHelpers.BeginUiBusy("choretracking-form");
Grocy.Api.Get('chores/get-chore-details/' + jsonForm.chore_id, Grocy.Api.Get('chores/' + jsonForm.chore_id,
function (choreDetails) function (choreDetails)
{ {
Grocy.Api.Get('chores/track-chore-execution/' + jsonForm.chore_id + '?tracked_time=' + Grocy.Components.DateTimePicker.GetValue() + "&done_by=" + Grocy.Components.UserPicker.GetValue(), Grocy.Api.Post('chores/' + jsonForm.chore_id + '/execute?tracked_time=' + Grocy.Components.DateTimePicker.GetValue() + "&done_by=" + Grocy.Components.UserPicker.GetValue(),
function(result) function(result)
{ {
Grocy.FrontendHelpers.EndUiBusy("choretracking-form"); Grocy.FrontendHelpers.EndUiBusy("choretracking-form");
@ -89,7 +89,7 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
function UndoChoreExecution(executionId) function UndoChoreExecution(executionId)
{ {
Grocy.Api.Get('chores/undo-chore-execution/' + executionId.toString(), Grocy.Api.Post('chores/' + executionId.toString() + '/undo',
function(result) function(result)
{ {
toastr.success(L("Chore execution successfully undone")); toastr.success(L("Chore execution successfully undone"));

View File

@ -2,7 +2,7 @@ Grocy.Components.BatteryCard = { };
Grocy.Components.BatteryCard.Refresh = function(batteryId) Grocy.Components.BatteryCard.Refresh = function(batteryId)
{ {
Grocy.Api.Get('batteries/get-battery-details/' + batteryId, Grocy.Api.Get('batteries/' + batteryId,
function(batteryDetails) function(batteryDetails)
{ {
$('#batterycard-battery-name').text(batteryDetails.battery.name); $('#batterycard-battery-name').text(batteryDetails.battery.name);
@ -10,7 +10,7 @@ Grocy.Components.BatteryCard.Refresh = function(batteryId)
$('#batterycard-battery-last-charged').text((batteryDetails.last_charged || L('never'))); $('#batterycard-battery-last-charged').text((batteryDetails.last_charged || L('never')));
$('#batterycard-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || '')); $('#batterycard-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || ''));
$('#batterycard-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0')); $('#batterycard-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0'));
$('#batterycard-battery-edit-button').attr("href", U("/battery/" + batteryDetails.battery.id.toString())); $('#batterycard-battery-edit-button').attr("href", U("/battery/" + batteryDetails.battery.id.toString()));
$('#batterycard-battery-edit-button').removeClass("disabled"); $('#batterycard-battery-edit-button').removeClass("disabled");

View File

@ -2,7 +2,7 @@ Grocy.Components.ChoreCard = { };
Grocy.Components.ChoreCard.Refresh = function(choreId) Grocy.Components.ChoreCard.Refresh = function(choreId)
{ {
Grocy.Api.Get('chores/get-chore-details/' + choreId, Grocy.Api.Get('chores/' + choreId,
function(choreDetails) function(choreDetails)
{ {
$('#chorecard-chore-name').text(choreDetails.chore.name); $('#chorecard-chore-name').text(choreDetails.chore.name);
@ -10,7 +10,7 @@ Grocy.Components.ChoreCard.Refresh = function(choreId)
$('#chorecard-chore-last-tracked-timeago').text($.timeago(choreDetails.last_tracked || '')); $('#chorecard-chore-last-tracked-timeago').text($.timeago(choreDetails.last_tracked || ''));
$('#chorecard-chore-tracked-count').text((choreDetails.tracked_count || '0')); $('#chorecard-chore-tracked-count').text((choreDetails.tracked_count || '0'));
$('#chorecard-chore-last-done-by').text((choreDetails.last_done_by.display_name || L('Unknown'))); $('#chorecard-chore-last-done-by').text((choreDetails.last_done_by.display_name || L('Unknown')));
$('#chorecard-chore-edit-button').attr("href", U("/chore/" + choreDetails.chore.id.toString())); $('#chorecard-chore-edit-button').attr("href", U("/chore/" + choreDetails.chore.id.toString()));
$('#chorecard-chore-edit-button').removeClass("disabled"); $('#chorecard-chore-edit-button').removeClass("disabled");

View File

@ -2,7 +2,7 @@ Grocy.Components.ProductCard = { };
Grocy.Components.ProductCard.Refresh = function(productId) Grocy.Components.ProductCard.Refresh = function(productId)
{ {
Grocy.Api.Get('stock/get-product-details/' + productId, Grocy.Api.Get('stock/' + productId,
function(productDetails) function(productDetails)
{ {
var stockAmount = productDetails.stock_amount || '0'; var stockAmount = productDetails.stock_amount || '0';
@ -58,7 +58,7 @@ Grocy.Components.ProductCard.Refresh = function(productId)
} }
); );
Grocy.Api.Get('stock/get-product-price-history/' + productId, Grocy.Api.Get('stock/' + productId + '/pricehistory',
function(priceHistoryDataPoints) function(priceHistoryDataPoints)
{ {
if (priceHistoryDataPoints.length > 0) if (priceHistoryDataPoints.length > 0)

View File

@ -16,17 +16,17 @@
spoiled = 1; spoiled = 1;
} }
var apiUrl = 'stock/consume-product/' + jsonForm.product_id + '/' + jsonForm.amount + '?spoiled=' + spoiled; var apiUrl = 'stock/' + jsonForm.product_id + '/consume/' + jsonForm.amount + '?spoiled=' + spoiled;
if ($("#use_specific_stock_entry").is(":checked")) if ($("#use_specific_stock_entry").is(":checked"))
{ {
apiUrl += "&stock_entry_id=" + jsonForm.specific_stock_entry; apiUrl += "&stock_entry_id=" + jsonForm.specific_stock_entry;
} }
Grocy.Api.Get('stock/get-product-details/' + jsonForm.product_id, Grocy.Api.Get('stock/' + jsonForm.product_id,
function(productDetails) function(productDetails)
{ {
Grocy.Api.Get(apiUrl, Grocy.Api.Post(apiUrl,
function(result) function(result)
{ {
$("#specific_stock_entry").find("option").remove().end().append("<option></option>"); $("#specific_stock_entry").find("option").remove().end().append("<option></option>");
@ -70,17 +70,17 @@ $('#save-mark-as-open-button').on('click', function(e)
jsonForm.amount = 1; jsonForm.amount = 1;
} }
var apiUrl = 'stock/open-product/' + jsonForm.product_id + '/' + jsonForm.amount; var apiUrl = 'stock/' + jsonForm.product_id + '/open/' + jsonForm.amount;
if ($("#use_specific_stock_entry").is(":checked")) if ($("#use_specific_stock_entry").is(":checked"))
{ {
apiUrl += "&stock_entry_id=" + jsonForm.specific_stock_entry; apiUrl += "&stock_entry_id=" + jsonForm.specific_stock_entry;
} }
Grocy.Api.Get('stock/get-product-details/' + jsonForm.product_id, Grocy.Api.Get('stock/' + jsonForm.product_id,
function(productDetails) function(productDetails)
{ {
Grocy.Api.Get(apiUrl, Grocy.Api.Post(apiUrl,
function(result) function(result)
{ {
$("#specific_stock_entry").find("option").remove().end().append("<option></option>"); $("#specific_stock_entry").find("option").remove().end().append("<option></option>");
@ -121,12 +121,12 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
} }
var productId = $(e.target).val(); var productId = $(e.target).val();
if (productId) if (productId)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/get-product-details/' + productId, Grocy.Api.Get('stock/' + productId,
function(productDetails) function(productDetails)
{ {
$('#amount').attr('max', productDetails.stock_amount); $('#amount').attr('max', productDetails.stock_amount);
@ -161,7 +161,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
} }
); );
Grocy.Api.Get("stock/get-product-stock-entries/" + productId, Grocy.Api.Get("stock/" + productId,
function (stockEntries) function (stockEntries)
{ {
stockEntries.forEach(stockEntry => stockEntries.forEach(stockEntry =>
@ -213,7 +213,7 @@ $('#consume-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('consume-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('consume-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;
@ -249,7 +249,7 @@ $("#use_specific_stock_entry").on("change", function()
function UndoStockBooking(bookingId) function UndoStockBooking(bookingId)
{ {
Grocy.Api.Get('stock/undo-booking/' + bookingId.toString(), Grocy.Api.Post('booking/' + bookingId.toString() + '/undo',
function(result) function(result)
{ {
toastr.success(L("Booking successfully undone")); toastr.success(L("Booking successfully undone"));

View File

@ -34,7 +34,7 @@ equipmentTable.on('select', function(e, dt, type, indexes)
function DisplayEquipment(id) function DisplayEquipment(id)
{ {
Grocy.Api.Get('get-object/equipment/' + id, Grocy.Api.Get('object/equipment/' + id,
function(equipmentItem) function(equipmentItem)
{ {
$(".selected-equipment-name").text(equipmentItem.name); $(".selected-equipment-name").text(equipmentItem.name);
@ -73,7 +73,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
equipmentTable.search(value).draw(); equipmentTable.search(value).draw();
}); });
@ -98,7 +98,7 @@ $(document).on('click', '.equipment-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/equipment/' + objectId, Grocy.Api.Delete('object/equipment/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/equipment'); window.location.href = U('/equipment');

View File

@ -15,10 +15,10 @@
{ {
jsonData.instruction_manual_file_name = null; jsonData.instruction_manual_file_name = null;
} }
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/equipment', jsonData, Grocy.Api.Post('object/equipment', jsonData,
function(result) function(result)
{ {
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave) if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
@ -64,7 +64,7 @@
); );
}; };
Grocy.Api.Post('edit-object/equipment/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/equipment/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave) if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
@ -105,7 +105,7 @@ $('#equipment-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('equipment-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('equipment-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -5,10 +5,10 @@
var jsonForm = $('#inventory-form').serializeJSON(); var jsonForm = $('#inventory-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("inventory-form"); Grocy.FrontendHelpers.BeginUiBusy("inventory-form");
Grocy.Api.Get('stock/get-product-details/' + jsonForm.product_id, Grocy.Api.Get('stock/' + jsonForm.product_id,
function (productDetails) function (productDetails)
{ {
Grocy.Api.Get('stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue(), Grocy.Api.Post('stock/' + jsonForm.product_id + '/inventory/' + jsonForm.new_amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue(),
function(result) function(result)
{ {
var addBarcode = GetUriParam('addbarcodetoselection'); var addBarcode = GetUriParam('addbarcodetoselection');
@ -24,7 +24,7 @@
productDetails.product.barcode += ',' + addBarcode; productDetails.product.barcode += ',' + addBarcode;
} }
Grocy.Api.Get('edit-object/products/' + productDetails.product.id, productDetails.product, Grocy.Api.Put('object/products/' + productDetails.product.id, productDetails.product,
function (result) { }, function (result) { },
function(xhr) function(xhr)
{ {
@ -73,7 +73,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/get-product-details/' + productId, Grocy.Api.Get('stock/' + productId,
function(productDetails) function(productDetails)
{ {
$('#new_amount').attr('not-equal', productDetails.stock_amount); $('#new_amount').attr('not-equal', productDetails.stock_amount);
@ -123,7 +123,7 @@ $('#inventory-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('inventory-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('inventory-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;
@ -139,7 +139,7 @@ $('#new_amount').on('keypress', function(e)
{ {
$('#new_amount').trigger('change'); $('#new_amount').trigger('change');
}); });
Grocy.Components.DateTimePicker.GetInputElement().on('change', function(e) Grocy.Components.DateTimePicker.GetInputElement().on('change', function(e)
{ {
Grocy.FrontendHelpers.ValidateForm('inventory-form'); Grocy.FrontendHelpers.ValidateForm('inventory-form');
@ -154,14 +154,14 @@ $('#new_amount').on('keyup', function(e)
{ {
var productId = Grocy.Components.ProductPicker.GetValue(); var productId = Grocy.Components.ProductPicker.GetValue();
var newAmount = parseInt($('#new_amount').val()); var newAmount = parseInt($('#new_amount').val());
if (productId) if (productId)
{ {
Grocy.Api.Get('stock/get-product-details/' + productId, Grocy.Api.Get('stock/' + productId,
function(productDetails) function(productDetails)
{ {
var productStockAmount = parseInt(productDetails.stock_amount || '0'); var productStockAmount = parseInt(productDetails.stock_amount || '0');
if (newAmount > productStockAmount) if (newAmount > productStockAmount)
{ {
var amountToAdd = newAmount - productDetails.stock_amount; var amountToAdd = newAmount - productDetails.stock_amount;
@ -193,7 +193,7 @@ $('#new_amount').on('keyup', function(e)
function UndoStockBooking(bookingId) function UndoStockBooking(bookingId)
{ {
Grocy.Api.Get('stock/undo-booking/' + bookingId.toString(), Grocy.Api.Get('booking/' + bookingId.toString() + '/undo',
function(result) function(result)
{ {
toastr.success(L("Booking successfully undone")); toastr.success(L("Booking successfully undone"));

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/locations', jsonData, Grocy.Api.Post('object/locations', jsonData,
function(result) function(result)
{ {
window.location.href = U('/locations'); window.location.href = U('/locations');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Post('edit-object/locations/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/locations/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/locations'); window.location.href = U('/locations');
@ -45,7 +45,7 @@ $('#location-form input').keydown(function (event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('location-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('location-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
locationsTable.search(value).draw(); locationsTable.search(value).draw();
}); });
@ -52,7 +52,7 @@ $(document).on('click', '.location-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/locations/' + objectId, Grocy.Api.Delete('object/locations/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/locations'); window.location.href = U('/locations');

View File

@ -33,7 +33,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
apiKeysTable.search(value).draw(); apiKeysTable.search(value).draw();
}); });
@ -58,7 +58,7 @@ $(document).on('click', '.apikey-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/api_keys/' + objectId, Grocy.Api.Delete('object/api_keys/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/manageapikeys'); window.location.href = U('/manageapikeys');

View File

@ -25,7 +25,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/products', jsonData, Grocy.Api.Post('object/products', jsonData,
function (result) function (result)
{ {
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave) if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
@ -71,7 +71,7 @@
); );
}; };
Grocy.Api.Post('edit-object/products/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/products/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave) if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
@ -110,7 +110,7 @@ $('#barcode-taginput').tagsManager({
if (Grocy.EditMode === 'edit') if (Grocy.EditMode === 'edit')
{ {
Grocy.Api.Get('get-object/products/' + Grocy.EditObjectId, Grocy.Api.Get('object/products/' + Grocy.EditObjectId,
function (product) function (product)
{ {
if (product.barcode !== null && product.barcode.length > 0) if (product.barcode !== null && product.barcode.length > 0)
@ -182,7 +182,7 @@ $('#product-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/product_groups', jsonData, Grocy.Api.Post('object/product_groups', jsonData,
function(result) function(result)
{ {
window.location.href = U('/productgroups'); window.location.href = U('/productgroups');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Post('edit-object/product_groups/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/product_groups/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/productgroups'); window.location.href = U('/productgroups');
@ -45,7 +45,7 @@ $('#product-group-form input').keydown(function (event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('product-group-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('product-group-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
groupsTable.search(value).draw(); groupsTable.search(value).draw();
}); });
@ -52,7 +52,7 @@ $(document).on('click', '.product-group-delete-button', function(e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/product_groups/' + objectId, Grocy.Api.Delete('object/product_groups/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/productgroups'); window.location.href = U('/productgroups');

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
productsTable.search(value).draw(); productsTable.search(value).draw();
}); });
@ -36,7 +36,7 @@ $(document).on('click', '.product-delete-button', function (e)
var objectName = $(e.currentTarget).attr('data-product-name'); var objectName = $(e.currentTarget).attr('data-product-name');
var objectId = $(e.currentTarget).attr('data-product-id'); var objectId = $(e.currentTarget).attr('data-product-id');
Grocy.Api.Get('stock/get-product-details/' + objectId, Grocy.Api.Get('stock/' + objectId,
function(productDetails) function(productDetails)
{ {
var stockAmount = productDetails.stock_amount || '0'; var stockAmount = productDetails.stock_amount || '0';
@ -59,7 +59,7 @@ $(document).on('click', '.product-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/products/' + objectId, Grocy.Api.Delete('object/products/' + objectId,
function (result) function (result)
{ {
window.location.href = U('/products'); window.location.href = U('/products');

View File

@ -5,7 +5,7 @@
var jsonForm = $('#purchase-form').serializeJSON(); var jsonForm = $('#purchase-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("purchase-form"); Grocy.FrontendHelpers.BeginUiBusy("purchase-form");
Grocy.Api.Get('stock/get-product-details/' + jsonForm.product_id, Grocy.Api.Get('stock/' + jsonForm.product_id,
function(productDetails) function(productDetails)
{ {
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock; var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
@ -16,7 +16,7 @@
price = parseFloat(jsonForm.price).toFixed(2); price = parseFloat(jsonForm.price).toFixed(2);
} }
Grocy.Api.Get('stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue() + '&price=' + price, Grocy.Api.Post('stock/' + jsonForm.product_id + '/add/' + amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue() + '&price=' + price,
function(result) function(result)
{ {
var addBarcode = GetUriParam('addbarcodetoselection'); var addBarcode = GetUriParam('addbarcodetoselection');
@ -32,7 +32,7 @@
productDetails.product.barcode += ',' + addBarcode; productDetails.product.barcode += ',' + addBarcode;
} }
Grocy.Api.Post('edit-object/products/' + productDetails.product.id, productDetails.product, Grocy.Api.Put('object/products/' + productDetails.product.id, productDetails.product,
function (result) { }, function (result) { },
function(xhr) function(xhr)
{ {
@ -89,12 +89,12 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/get-product-details/' + productId, Grocy.Api.Get('stock/' + productId,
function(productDetails) function(productDetails)
{ {
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name); $('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
$('#price').val(productDetails.last_price); $('#price').val(productDetails.last_price);
if (productDetails.product.default_best_before_days.toString() !== '0') if (productDetails.product.default_best_before_days.toString() !== '0')
{ {
if (productDetails.product.default_best_before_days == -1) if (productDetails.product.default_best_before_days == -1)
@ -163,7 +163,7 @@ $('#purchase-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('purchase-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('purchase-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;
@ -197,7 +197,7 @@ if (GetUriParam("flow") === "shoppinglistitemtostock")
function UndoStockBooking(bookingId) function UndoStockBooking(bookingId)
{ {
Grocy.Api.Get('stock/undo-booking/' + bookingId.toString(), Grocy.Api.Get('sbooking/' + bookingId.toString() + '/undo',
function(result) function(result)
{ {
toastr.success(L("Booking successfully undone")); toastr.success(L("Booking successfully undone"));

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/quantity_units', jsonData, Grocy.Api.Post('object/quantity_units', jsonData,
function(result) function(result)
{ {
window.location.href = U('/quantityunits'); window.location.href = U('/quantityunits');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Post('edit-object/quantity_units/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/quantity_units/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/quantityunits'); window.location.href = U('/quantityunits');
@ -45,7 +45,7 @@ $('#quantityunit-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('quantityunit-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('quantityunit-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
quantityUnitsTable.search(value).draw(); quantityUnitsTable.search(value).draw();
}); });
@ -52,7 +52,7 @@ $(document).on('click', '.quantityunit-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/quantity_units/' + objectId, Grocy.Api.Delete('object/quantity_units/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/quantityunits'); window.location.href = U('/quantityunits');

View File

@ -5,7 +5,7 @@
var jsonData = $('#recipe-form').serializeJSON(); var jsonData = $('#recipe-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("recipe-form"); Grocy.FrontendHelpers.BeginUiBusy("recipe-form");
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipes'); window.location.href = U('/recipes');
@ -80,7 +80,7 @@ $('#recipe-form input').keydown(function (event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('recipe-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('recipe-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;
@ -113,8 +113,8 @@ $(document).on('click', '.recipe-pos-delete-button', function(e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { }); Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { });
Grocy.Api.Get('delete-object/recipes_pos/' + objectId, Grocy.Api.Delete('object/recipes_pos/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);
@ -150,8 +150,8 @@ $(document).on('click', '.recipe-include-delete-button', function(e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { }); Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { });
Grocy.Api.Get('delete-object/recipes_nestings/' + objectId, Grocy.Api.Delete('object/recipes_nestings/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);
@ -178,10 +178,10 @@ $(document).on('click', '.recipe-pos-order-missing-button', function(e)
jsonData.amount = productAmount; jsonData.amount = productAmount;
jsonData.note = L('Added for recipe #1', recipeName); jsonData.note = L('Added for recipe #1', recipeName);
Grocy.Api.Post('add-object/shopping_list', jsonData, Grocy.Api.Post('object/shopping_list', jsonData,
function(result) function(result)
{ {
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function () { }, function () { }); Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function () { }, function () { });
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);
}, },
function(xhr) function(xhr)
@ -202,7 +202,7 @@ $(document).on('click', '.recipe-pos-edit-button', function (e)
{ {
var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id'); var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id');
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/' + recipePosId); window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/' + recipePosId);
@ -219,7 +219,7 @@ $(document).on('click', '.recipe-include-edit-button', function (e)
var id = $(e.currentTarget).attr('data-recipe-include-id'); var id = $(e.currentTarget).attr('data-recipe-include-id');
var recipeId = $(e.currentTarget).attr('data-recipe-included-recipe-id'); var recipeId = $(e.currentTarget).attr('data-recipe-included-recipe-id');
console.log(recipeId); console.log(recipeId);
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result) function(result)
{ {
$("#recipe-include-editform-title").text(L("Edit included recipe")); $("#recipe-include-editform-title").text(L("Edit included recipe"));
@ -238,7 +238,7 @@ $(document).on('click', '.recipe-include-edit-button', function (e)
$("#recipe-pos-add-button").on("click", function(e) $("#recipe-pos-add-button").on("click", function(e)
{ {
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/new'); window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/new');
@ -252,7 +252,7 @@ $("#recipe-pos-add-button").on("click", function(e)
$("#recipe-include-add-button").on("click", function(e) $("#recipe-include-add-button").on("click", function(e)
{ {
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result) function(result)
{ {
$("#recipe-include-editform-title").text(L("Add included recipe")); $("#recipe-include-editform-title").text(L("Add included recipe"));
@ -280,7 +280,7 @@ $('#save-recipe-include-button').on('click', function(e)
if (editMode === 'create') if (editMode === 'create')
{ {
Grocy.Api.Post('add-object/recipes_nestings', jsonData, Grocy.Api.Post('object/recipes_nestings', jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);
@ -293,7 +293,7 @@ $('#save-recipe-include-button').on('click', function(e)
} }
else else
{ {
Grocy.Api.Post('edit-object/recipes_nestings/' + nestingId, jsonData, Grocy.Api.Put('object/recipes_nestings/' + nestingId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);

View File

@ -9,7 +9,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/recipes_pos', jsonData, Grocy.Api.Post('object/recipes_pos', jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectParentId); window.location.href = U('/recipe/' + Grocy.EditObjectParentId);
@ -23,7 +23,7 @@
} }
else else
{ {
Grocy.Api.Post('edit-object/recipes_pos/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/recipes_pos/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectParentId); window.location.href = U('/recipe/' + Grocy.EditObjectParentId);
@ -44,8 +44,8 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
if (productId) if (productId)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/get-product-details/' + productId, Grocy.Api.Get('stock/' + productId,
function (productDetails) function (productDetails)
{ {
if (!$("#only_check_single_unit_in_stock").is(":checked")) if (!$("#only_check_single_unit_in_stock").is(":checked"))
@ -93,7 +93,7 @@ $('#recipe-pos-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('recipe-pos-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('recipe-pos-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -38,7 +38,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
recipesTables.search(value).draw(); recipesTables.search(value).draw();
}); });
@ -63,7 +63,7 @@ $("#selectedRecipeDeleteButton").on('click', function(e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/recipes/' + objectId, Grocy.Api.Delete('object/recipes/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/recipes'); window.location.href = U('/recipes');
@ -101,7 +101,7 @@ $(document).on('click', '.recipe-order-missing-button', function(e)
{ {
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
Grocy.Api.Get('recipes/add-not-fulfilled-products-to-shopping-list/' + objectId, Grocy.Api.Post('recipes/' + objectId + '/shoppinglist',
function(result) function(result)
{ {
window.location.href = U('/recipes'); window.location.href = U('/recipes');
@ -140,7 +140,7 @@ $("#selectedRecipeConsumeButton").on('click', function(e)
{ {
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
Grocy.Api.Get('recipes/consume-recipe/' + objectId, Grocy.Api.Get('recipes/' + objectId + '/consume',
function(result) function(result)
{ {
Grocy.FrontendHelpers.EndUiBusy(); Grocy.FrontendHelpers.EndUiBusy();

View File

@ -32,7 +32,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
shoppingListTable.search(value).draw(); shoppingListTable.search(value).draw();
}); });
@ -46,7 +46,7 @@ $("#status-filter").on("change", function()
// Transfer CSS classes of selected element to dropdown element (for background) // Transfer CSS classes of selected element to dropdown element (for background)
$(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control"); $(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control");
shoppingListTable.column(4).search(value).draw(); shoppingListTable.column(4).search(value).draw();
}); });
@ -60,11 +60,11 @@ $(".status-filter-button").on("click", function()
$(document).on('click', '.shoppinglist-delete-button', function (e) $(document).on('click', '.shoppinglist-delete-button', function (e)
{ {
e.preventDefault(); e.preventDefault();
var shoppingListItemId = $(e.currentTarget).attr('data-shoppinglist-id'); var shoppingListItemId = $(e.currentTarget).attr('data-shoppinglist-id');
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
Grocy.Api.Get('delete-object/shopping_list/' + shoppingListItemId, Grocy.Api.Delete('object/shopping_list/' + shoppingListItemId,
function(result) function(result)
{ {
$('#shoppinglistitem-' + shoppingListItemId + '-row').fadeOut(500, function() $('#shoppinglistitem-' + shoppingListItemId + '-row').fadeOut(500, function()
@ -84,7 +84,7 @@ $(document).on('click', '.shoppinglist-delete-button', function (e)
$(document).on('click', '#add-products-below-min-stock-amount', function(e) $(document).on('click', '#add-products-below-min-stock-amount', function(e)
{ {
Grocy.Api.Get('stock/add-missing-products-to-shoppinglist', Grocy.Api.Post('stock/shoppinglist',
function(result) function(result)
{ {
window.location.href = U('/shoppinglist'); window.location.href = U('/shoppinglist');
@ -116,7 +116,7 @@ $(document).on('click', '#clear-shopping-list', function(e)
{ {
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
Grocy.Api.Get('stock/clear-shopping-list', Grocy.Api.Post('stock/clearshoppinglist',
function(result) function(result)
{ {
$('#shoppinglist-table tbody tr').fadeOut(500, function() $('#shoppinglist-table tbody tr').fadeOut(500, function()
@ -140,7 +140,7 @@ $(document).on('click', '#clear-shopping-list', function(e)
$(document).on('click', '.shopping-list-stock-add-workflow-list-item-button', function(e) $(document).on('click', '.shopping-list-stock-add-workflow-list-item-button', function(e)
{ {
e.preventDefault(); e.preventDefault();
var href = $(e.currentTarget).attr('href'); var href = $(e.currentTarget).attr('href');
$("#shopping-list-stock-add-workflow-purchase-form-frame").attr("src", href); $("#shopping-list-stock-add-workflow-purchase-form-frame").attr("src", href);
@ -179,7 +179,7 @@ $("#shopping-list-stock-add-workflow-modal").on("hidden.bs.modal", function(e)
$(window).on("message", function(e) $(window).on("message", function(e)
{ {
var data = e.originalEvent.data; var data = e.originalEvent.data;
if (data.Message === "AfterItemAdded") if (data.Message === "AfterItemAdded")
{ {
$(".shoppinglist-delete-button[data-shoppinglist-id='" + data.Payload + "']").click(); $(".shoppinglist-delete-button[data-shoppinglist-id='" + data.Payload + "']").click();
@ -212,7 +212,7 @@ $(window).on("message", function(e)
$(document).on('click', '#shopping-list-stock-add-workflow-skip-button', function(e) $(document).on('click', '#shopping-list-stock-add-workflow-skip-button', function(e)
{ {
e.preventDefault(); e.preventDefault();
window.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl); window.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl);
}); });

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/shopping_list', jsonData, Grocy.Api.Post('object/shopping_list', jsonData,
function(result) function(result)
{ {
window.location.href = U('/shoppinglist'); window.location.href = U('/shoppinglist');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Post('edit-object/shopping_list/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/shopping_list/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/shoppinglist'); window.location.href = U('/shoppinglist');
@ -42,8 +42,8 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
if (productId) if (productId)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/get-product-details/' + productId, Grocy.Api.Get('stock/' + productId,
function (productDetails) function (productDetails)
{ {
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name); $('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
@ -63,7 +63,7 @@ Grocy.Components.ProductPicker.GetInputElement().focus();
if (Grocy.EditMode === "edit") if (Grocy.EditMode === "edit")
{ {
Grocy.Components.ProductPicker.GetPicker().trigger('change'); Grocy.Components.ProductPicker.GetPicker().trigger('change');
} }
$('#amount').on('focus', function(e) $('#amount').on('focus', function(e)
@ -88,7 +88,7 @@ $('#shoppinglist-form input').keydown(function (event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('shoppinglist-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('shoppinglist-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -28,7 +28,7 @@ $("#product-filter").on("change", function()
{ {
text = ""; text = "";
} }
stockJournalTable.column(1).search(text).draw(); stockJournalTable.column(1).search(text).draw();
}); });
@ -39,7 +39,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
stockJournalTable.search(value).draw(); stockJournalTable.search(value).draw();
}); });
@ -56,7 +56,7 @@ $(document).on('click', '.undo-stock-booking-button', function(e)
var element = $(e.currentTarget); var element = $(e.currentTarget);
var bookingId = $(e.currentTarget).attr('data-booking-id'); var bookingId = $(e.currentTarget).attr('data-booking-id');
Grocy.Api.Get('stock/undo-booking/' + bookingId.toString(), Grocy.Api.Get('booking/' + bookingId.toString() + '/undo',
function(result) function(result)
{ {
element.closest("tr").addClass("text-muted"); element.closest("tr").addClass("text-muted");

View File

@ -30,7 +30,7 @@ $("#location-filter").on("change", function()
{ {
value = ""; value = "";
} }
stockOverviewTable.column(4).search(value).draw(); stockOverviewTable.column(4).search(value).draw();
}); });
@ -41,7 +41,7 @@ $("#product-group-filter").on("change", function()
{ {
value = ""; value = "";
} }
stockOverviewTable.column(6).search(value).draw(); stockOverviewTable.column(6).search(value).draw();
}); });
@ -55,7 +55,7 @@ $("#status-filter").on("change", function()
// Transfer CSS classes of selected element to dropdown element (for background) // Transfer CSS classes of selected element to dropdown element (for background)
$(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control"); $(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control");
stockOverviewTable.column(5).search(value).draw(); stockOverviewTable.column(5).search(value).draw();
}); });
@ -73,7 +73,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
stockOverviewTable.search(value).draw(); stockOverviewTable.search(value).draw();
}); });
@ -86,16 +86,16 @@ $(document).on('click', '.product-consume-button', function(e)
document.activeElement.blur(); document.activeElement.blur();
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
var productId = $(e.currentTarget).attr('data-product-id'); var productId = $(e.currentTarget).attr('data-product-id');
var productName = $(e.currentTarget).attr('data-product-name'); var productName = $(e.currentTarget).attr('data-product-name');
var productQuName = $(e.currentTarget).attr('data-product-qu-name'); var productQuName = $(e.currentTarget).attr('data-product-qu-name');
var consumeAmount = $(e.currentTarget).attr('data-consume-amount'); var consumeAmount = $(e.currentTarget).attr('data-consume-amount');
Grocy.Api.Get('stock/consume-product/' + productId + '/' + consumeAmount, Grocy.Api.Post('stock/' + productId + '/consume/' + consumeAmount,
function() function()
{ {
Grocy.Api.Get('stock/get-product-details/' + productId, Grocy.Api.Get('stock/' + productId,
function(result) function(result)
{ {
var productRow = $('#product-' + productId + '-row'); var productRow = $('#product-' + productId + '-row');
@ -122,7 +122,7 @@ $(document).on('click', '.product-consume-button', function(e)
{ {
$(this).remove(); $(this).remove();
}); });
} }
else else
{ {
$('#product-' + productId + '-amount').parent().effect('highlight', { }, 500); $('#product-' + productId + '-amount').parent().effect('highlight', { }, 500);
@ -183,16 +183,16 @@ $(document).on('click', '.product-open-button', function(e)
document.activeElement.blur(); document.activeElement.blur();
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
var productId = $(e.currentTarget).attr('data-product-id'); var productId = $(e.currentTarget).attr('data-product-id');
var productName = $(e.currentTarget).attr('data-product-name'); var productName = $(e.currentTarget).attr('data-product-name');
var productQuName = $(e.currentTarget).attr('data-product-qu-name'); var productQuName = $(e.currentTarget).attr('data-product-qu-name');
var button = $(e.currentTarget); var button = $(e.currentTarget);
Grocy.Api.Get('stock/open-product/' + productId + '/1', Grocy.Api.Get('stock/' + productId + 'open/1',
function() function()
{ {
Grocy.Api.Get('stock/get-product-details/' + productId, Grocy.Api.Get('stock/' + productId,
function(result) function(result)
{ {
var productRow = $('#product-' + productId + '-row'); var productRow = $('#product-' + productId + '-row');
@ -257,7 +257,7 @@ $(document).on("click", ".product-name-cell", function(e)
function RefreshStatistics() function RefreshStatistics()
{ {
Grocy.Api.Get('stock/get-current-stock', Grocy.Api.Get('stock',
function(result) function(result)
{ {
var amountSum = 0; var amountSum = 0;
@ -273,7 +273,7 @@ function RefreshStatistics()
); );
var nextXDays = $("#info-expiring-products").data("next-x-days"); var nextXDays = $("#info-expiring-products").data("next-x-days");
Grocy.Api.Get('stock/get-current-volatil-stock?expiring_days=' + nextXDays, Grocy.Api.Get('stock/volatile?expiring_days=' + nextXDays,
function(result) function(result)
{ {
$("#info-expiring-products").text(Pluralize(result.expiring_products.length, L('#1 product expires within the next #2 days', result.expiring_products.length, nextXDays), L('#1 products expiring within the next #2 days', result.expiring_products.length, nextXDays))); $("#info-expiring-products").text(Pluralize(result.expiring_products.length, L('#1 product expires within the next #2 days', result.expiring_products.length, nextXDays), L('#1 products expiring within the next #2 days', result.expiring_products.length, nextXDays)));

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
categoriesTable.search(value).draw(); categoriesTable.search(value).draw();
}); });
@ -52,7 +52,7 @@ $(document).on('click', '.task-category-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/task_categories/' + objectId, Grocy.Api.Delete('object/task_categories/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/taskcategories'); window.location.href = U('/taskcategories');

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/task_categories', jsonData, Grocy.Api.Post('object/task_categories', jsonData,
function(result) function(result)
{ {
window.location.href = U('/taskcategories'); window.location.href = U('/taskcategories');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Post('edit-object/task_categories/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/task_categories/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/taskcategories'); window.location.href = U('/taskcategories');
@ -45,7 +45,7 @@ $('#task-category-form input').keydown(function (event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('task-category-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('task-category-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -11,7 +11,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('add-object/tasks', jsonData, Grocy.Api.Post('object/tasks', jsonData,
function(result) function(result)
{ {
window.location.href = U('/tasks'); window.location.href = U('/tasks');
@ -25,7 +25,7 @@
} }
else else
{ {
Grocy.Api.Post('edit-object/tasks/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('object/tasks/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/tasks'); window.location.href = U('/tasks');
@ -49,7 +49,7 @@ $('#task-form input').keydown(function(event)
if (event.keyCode === 13) //Enter if (event.keyCode === 13) //Enter
{ {
event.preventDefault(); event.preventDefault();
if (document.getElementById('task-form').checkValidity() === false) //There is at least one validation error if (document.getElementById('task-form').checkValidity() === false) //There is at least one validation error
{ {
return false; return false;

View File

@ -31,7 +31,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
tasksTable.search(value).draw(); tasksTable.search(value).draw();
}); });
@ -45,7 +45,7 @@ $("#status-filter").on("change", function()
// Transfer CSS classes of selected element to dropdown element (for background) // Transfer CSS classes of selected element to dropdown element (for background)
$(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control"); $(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control");
tasksTable.column(5).search(value).draw(); tasksTable.column(5).search(value).draw();
}); });
@ -65,12 +65,12 @@ $(document).on('click', '.do-task-button', function(e)
document.activeElement.blur(); document.activeElement.blur();
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
var taskId = $(e.currentTarget).attr('data-task-id'); var taskId = $(e.currentTarget).attr('data-task-id');
var taskName = $(e.currentTarget).attr('data-task-name'); var taskName = $(e.currentTarget).attr('data-task-name');
var doneTime = moment().format('YYYY-MM-DD HH:mm:ss'); var doneTime = moment().format('YYYY-MM-DD HH:mm:ss');
Grocy.Api.Get('tasks/mark-task-as-completed/' + taskId + '?done_time=' + doneTime, Grocy.Api.Get('tasks/' + taskId + '/complete?done_time=' + doneTime,
function() function()
{ {
if (!$("#show-done-tasks").is(":checked")) if (!$("#show-done-tasks").is(":checked"))
@ -123,7 +123,7 @@ $(document).on('click', '.delete-task-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('delete-object/tasks/' + objectId, Grocy.Api.Delete('object/tasks/' + objectId,
function(result) function(result)
{ {
$('#task-' + objectId + '-row').fadeOut(500, function () $('#task-' + objectId + '-row').fadeOut(500, function ()
@ -161,7 +161,7 @@ if (GetUriParam('include_done'))
function RefreshStatistics() function RefreshStatistics()
{ {
var nextXDays = $("#info-due-tasks").data("next-x-days"); var nextXDays = $("#info-due-tasks").data("next-x-days");
Grocy.Api.Get('tasks/get-current', Grocy.Api.Get('tasks',
function(result) function(result)
{ {
var dueCount = 0; var dueCount = 0;
@ -179,7 +179,7 @@ function RefreshStatistics()
dueCount++; dueCount++;
} }
}); });
$("#info-due-tasks").text(Pluralize(dueCount, L('#1 task is due to be done within the next #2 days', dueCount, nextXDays), L('#1 tasks are due to be done within the next #2 days', dueCount, nextXDays))); $("#info-due-tasks").text(Pluralize(dueCount, L('#1 task is due to be done within the next #2 days', dueCount, nextXDays), L('#1 tasks are due to be done within the next #2 days', dueCount, nextXDays)));
$("#info-overdue-tasks").text(Pluralize(overdueCount, L('#1 task is overdue to be done', overdueCount), L('#1 tasks are overdue to be done', overdueCount))); $("#info-overdue-tasks").text(Pluralize(overdueCount, L('#1 task is overdue to be done', overdueCount), L('#1 tasks are overdue to be done', overdueCount)));
}, },

View File

@ -27,7 +27,7 @@ $("#search").on("keyup", function()
{ {
value = ""; value = "";
} }
usersTable.search(value).draw(); usersTable.search(value).draw();
}); });
@ -52,7 +52,7 @@ $(document).on('click', '.user-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Get('users/delete/' + objectId, Grocy.Api.Delete('users/delete/' + objectId,
function(result) function(result)
{ {
window.location.href = U('/users'); window.location.href = U('/users');

View File

@ -83,11 +83,11 @@ $app->group('/api', function()
$this->get('/get-openapi-specification', '\Grocy\Controllers\OpenApiController:DocumentationSpec'); $this->get('/get-openapi-specification', '\Grocy\Controllers\OpenApiController:DocumentationSpec');
// Generic entity interaction // Generic entity interaction
$this->get('/get-objects/{entity}', '\Grocy\Controllers\GenericEntityApiController:GetObjects'); $this->get('/object/{entity}', '\Grocy\Controllers\GenericEntityApiController:GetObjects');
$this->get('/get-object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:GetObject'); $this->get('/object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:GetObject');
$this->post('/add-object/{entity}', '\Grocy\Controllers\GenericEntityApiController:AddObject'); $this->post('/object/{entity}', '\Grocy\Controllers\GenericEntityApiController:AddObject');
$this->post('/edit-object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:EditObject'); $this->put('/object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:EditObject');
$this->get('/delete-object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:DeleteObject'); $this->delete('/object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:DeleteObject');
// System // System
$this->get('/system/get-db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime'); $this->get('/system/get-db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime');
@ -99,49 +99,49 @@ $app->group('/api', function()
$this->delete('/file/{group}', '\Grocy\Controllers\FilesApiController:DeleteFile'); $this->delete('/file/{group}', '\Grocy\Controllers\FilesApiController:DeleteFile');
// Users // Users
$this->get('/users/get', '\Grocy\Controllers\UsersApiController:GetUsers'); $this->get('/users', '\Grocy\Controllers\UsersApiController:GetUsers');
$this->post('/users/create', '\Grocy\Controllers\UsersApiController:CreateUser'); $this->post('/users', '\Grocy\Controllers\UsersApiController:CreateUser');
$this->post('/users/edit/{userId}', '\Grocy\Controllers\UsersApiController:EditUser'); $this->put('/users/{userId}', '\Grocy\Controllers\UsersApiController:EditUser');
$this->get('/users/delete/{userId}', '\Grocy\Controllers\UsersApiController:DeleteUser'); $this->delete('/users/{userId}', '\Grocy\Controllers\UsersApiController:DeleteUser');
// User // User
$this->get('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:GetUserSetting'); $this->get('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:GetUserSetting');
$this->post('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:SetUserSetting'); $this->post('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:SetUserSetting');
// Stock // Stock
$this->get('/stock/add-product/{productId}/{amount}', '\Grocy\Controllers\StockApiController:AddProduct'); $this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatilStock');
$this->get('/stock/consume-product/{productId}/{amount}', '\Grocy\Controllers\StockApiController:ConsumeProduct'); $this->get('/stock/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
$this->get('/stock/open-product/{productId}/{amount}', '\Grocy\Controllers\StockApiController:OpenProduct'); $this->get('/stock/{productId}/pricehistory', '\Grocy\Controllers\StockApiController:ProductPriceHistory');
$this->get('/stock/inventory-product/{productId}/{newAmount}', '\Grocy\Controllers\StockApiController:InventoryProduct'); $this->get('/stock/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries');
$this->get('/stock/get-product-details/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails'); $this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock');
$this->get('/stock/get-product-price-history/{productId}', '\Grocy\Controllers\StockApiController:ProductPriceHistory'); $this->post('/stock/{productId}/add/{amount}', '\Grocy\Controllers\StockApiController:AddProduct');
$this->get('/stock/get-product-stock-entries/{productId}', '\Grocy\Controllers\StockApiController:ProductStockEntries'); $this->post('/stock/{productId}/consume/{amount}', '\Grocy\Controllers\StockApiController:ConsumeProduct');
$this->get('/stock/get-current-stock', '\Grocy\Controllers\StockApiController:CurrentStock'); $this->post('/stock/{productId}/open/{amount}', '\Grocy\Controllers\StockApiController:OpenProduct');
$this->get('/stock/get-current-volatil-stock', '\Grocy\Controllers\StockApiController:CurrentVolatilStock'); $this->post('/stock/{productId}/inventory/{newAmount}', '\Grocy\Controllers\StockApiController:InventoryProduct');
$this->get('/stock/add-missing-products-to-shoppinglist', '\Grocy\Controllers\StockApiController:AddMissingProductsToShoppingList'); $this->post('/stock/shoppinglist', '\Grocy\Controllers\StockApiController:AddMissingProductsToShoppingList');
$this->get('/stock/clear-shopping-list', '\Grocy\Controllers\StockApiController:ClearShoppingList'); $this->post('/stock/clearshoppinglist', '\Grocy\Controllers\StockApiController:ClearShoppingList');
$this->get('/stock/external-barcode-lookup/{barcode}', '\Grocy\Controllers\StockApiController:ExternalBarcodeLookup'); $this->get('/barcode/{barcode}', '\Grocy\Controllers\StockApiController:ExternalBarcodeLookup');
$this->get('/stock/undo-booking/{bookingId}', '\Grocy\Controllers\StockApiController:UndoBooking'); $this->post('/booking/{bookingId}/undo', '\Grocy\Controllers\StockApiController:UndoBooking');
// Recipes // Recipes
$this->get('/recipes/add-not-fulfilled-products-to-shopping-list/{recipeId}', '\Grocy\Controllers\RecipesApiController:AddNotFulfilledProductsToShoppingList'); $this->post('/recipes/{recipeId}/shoppinglist', '\Grocy\Controllers\RecipesApiController:AddNotFulfilledProductsToShoppingList');
$this->get('/recipes/consume-recipe/{recipeId}', '\Grocy\Controllers\RecipesApiController:ConsumeRecipe'); $this->post('/recipes/{recipeId}/consume', '\Grocy\Controllers\RecipesApiController:ConsumeRecipe');
// Chores // Chores
$this->get('/chores/track-chore-execution/{choreId}', '\Grocy\Controllers\ChoresApiController:TrackChoreExecution'); $this->get('/chores/{choreId}', '\Grocy\Controllers\ChoresApiController:ChoreDetails');
$this->get('/chores/get-chore-details/{choreId}', '\Grocy\Controllers\ChoresApiController:ChoreDetails'); $this->get('/chores', '\Grocy\Controllers\ChoresApiController:Current');
$this->get('/chores/get-current', '\Grocy\Controllers\ChoresApiController:Current'); $this->post('/chores/{executionId}/undo', '\Grocy\Controllers\ChoresApiController:UndoChoreExecution');
$this->get('/chores/undo-chore-execution/{executionId}', '\Grocy\Controllers\ChoresApiController:UndoChoreExecution'); $this->post('/chores/{choreId}/execute', '\Grocy\Controllers\ChoresApiController:TrackChoreExecution');
// Batteries // Batteries
$this->get('/batteries/track-charge-cycle/{batteryId}', '\Grocy\Controllers\BatteriesApiController:TrackChargeCycle'); $this->get('/batteries/{batteryId}', '\Grocy\Controllers\BatteriesApiController:BatteryDetails');
$this->get('/batteries/get-battery-details/{batteryId}', '\Grocy\Controllers\BatteriesApiController:BatteryDetails'); $this->get('/batteries', '\Grocy\Controllers\BatteriesApiController:Current');
$this->get('/batteries/get-current', '\Grocy\Controllers\BatteriesApiController:Current'); $this->post('/batteries/{batteryId}/charge', '\Grocy\Controllers\BatteriesApiController:TrackChargeCycle');
$this->get('/batteries/undo-charge-cycle/{chargeCycleId}', '\Grocy\Controllers\BatteriesApiController:UndoChargeCycle'); $this->post('/batteries/{chargeCycleId}/undo', '\Grocy\Controllers\BatteriesApiController:UndoChargeCycle');
// Tasks // Tasks
$this->get('/tasks/get-current', '\Grocy\Controllers\TasksApiController:Current'); $this->get('/tasks', '\Grocy\Controllers\TasksApiController:Current');
$this->get('/tasks/mark-task-as-completed/{taskId}', '\Grocy\Controllers\TasksApiController:MarkTaskAsCompleted'); $this->post('/tasks/{taskId}/complete', '\Grocy\Controllers\TasksApiController:MarkTaskAsCompleted');
})->add(new ApiKeyAuthMiddleware($appContainer, $appContainer->LoginControllerInstance->GetSessionCookieName(), $appContainer->ApiKeyHeaderName)) })->add(new ApiKeyAuthMiddleware($appContainer, $appContainer->LoginControllerInstance->GetSessionCookieName(), $appContainer->ApiKeyHeaderName))
->add(JsonMiddleware::class) ->add(JsonMiddleware::class)
->add(new CorsMiddleware([ ->add(new CorsMiddleware([