mirror of
https://github.com/grocy/grocy.git
synced 2025-08-19 03:40:10 +00:00
Finish first early version of "pictures for products" (references #58)
This commit is contained in:
@@ -9,12 +9,34 @@
|
||||
redirectDestination = returnTo + '?createdproduct=' + encodeURIComponent($('#name').val());
|
||||
}
|
||||
|
||||
var jsonData = $('#product-form').serializeJSON();
|
||||
if ($("#product-picture")[0].files.length > 0)
|
||||
{
|
||||
jsonData.picture_file_name = $("#product-picture")[0].files[0].name;
|
||||
}
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('add-object/products', $('#product-form').serializeJSON(),
|
||||
Grocy.Api.Post('add-object/products', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
if (jsonData.hasOwnProperty("picture_file_name"))
|
||||
{
|
||||
Grocy.Api.UploadFile($("#product-picture"), 'productpictures',
|
||||
function(result)
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@@ -24,10 +46,26 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Post('edit-object/products/' + Grocy.EditObjectId, $('#product-form').serializeJSON(),
|
||||
Grocy.Api.Post('edit-object/products/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
if (jsonData.hasOwnProperty("picture_file_name"))
|
||||
{
|
||||
Grocy.Api.UploadFile($("#product-picture"), 'productpictures',
|
||||
function(result)
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
|
@@ -141,6 +141,17 @@ $(document).on('click', '.product-consume-button', function(e)
|
||||
);
|
||||
});
|
||||
|
||||
$(document).on("click", ".show-product-picture-button", function(e)
|
||||
{
|
||||
var pictureUrl = $(e.currentTarget).attr("data-picture-url");
|
||||
var productName = $(e.currentTarget).attr("data-product-name");
|
||||
|
||||
bootbox.alert({
|
||||
title: L("Image of product #1", productName),
|
||||
message: "<img src='" + pictureUrl + "' class='img-fluid'>"
|
||||
});
|
||||
});
|
||||
|
||||
function RefreshStatistics()
|
||||
{
|
||||
Grocy.Api.Get('stock/get-current-stock',
|
||||
|
Reference in New Issue
Block a user