mirror of
https://github.com/grocy/grocy.git
synced 2025-08-15 02:04:38 +00:00
Finished first version of "pictures for products" (references #58)
This commit is contained in:
@@ -24,6 +24,18 @@ Grocy.Components.ProductCard.Refresh = function(productId)
|
||||
$('#productcard-product-last-price').text(L('Unknown'));
|
||||
}
|
||||
|
||||
if (productDetails.product.picture_file_name !== null && !productDetails.product.picture_file_name.isEmpty())
|
||||
{
|
||||
$("#productcard-no-product-picture").addClass("d-none");
|
||||
$("#productcard-product-picture").removeClass("d-none");
|
||||
$("#productcard-product-picture").attr("src", U('/api/file/productpictures?file_name=' + productDetails.product.picture_file_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#productcard-no-product-picture").removeClass("d-none");
|
||||
$("#productcard-product-picture").addClass("d-none");
|
||||
}
|
||||
|
||||
EmptyElementWhenMatches('#productcard-product-last-purchased-timeago', L('timeago_nan'));
|
||||
EmptyElementWhenMatches('#productcard-product-last-used-timeago', L('timeago_nan'));
|
||||
},
|
||||
|
@@ -1,4 +1,4 @@
|
||||
$('#save-product-button').on('click', function(e)
|
||||
$('#save-product-button').on('click', function (e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
@@ -12,22 +12,28 @@
|
||||
var jsonData = $('#product-form').serializeJSON();
|
||||
if ($("#product-picture")[0].files.length > 0)
|
||||
{
|
||||
jsonData.picture_file_name = $("#product-picture")[0].files[0].name;
|
||||
var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
|
||||
jsonData.picture_file_name = someRandomStuff + $("#product-picture")[0].files[0].name;
|
||||
}
|
||||
|
||||
if (Grocy.DeleteProductPictureOnSave)
|
||||
{
|
||||
jsonData.picture_file_name = null;
|
||||
}
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('add-object/products', jsonData,
|
||||
function(result)
|
||||
function (result)
|
||||
{
|
||||
if (jsonData.hasOwnProperty("picture_file_name"))
|
||||
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
|
||||
{
|
||||
Grocy.Api.UploadFile($("#product-picture"), 'productpictures',
|
||||
function(result)
|
||||
Grocy.Api.UploadFile($("#product-picture")[0].files[0], 'productpictures', jsonData.picture_file_name,
|
||||
function (result)
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
},
|
||||
function(xhr)
|
||||
function (xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
@@ -38,7 +44,7 @@
|
||||
window.location.href = redirectDestination;
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
function (xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
@@ -46,12 +52,26 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Grocy.DeleteProductPictureOnSave)
|
||||
{
|
||||
Grocy.Api.DeleteFile(Grocy.ProductPictureFileName, 'productpictures',
|
||||
function(result)
|
||||
{
|
||||
// Nothing to do
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Grocy.Api.Post('edit-object/products/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
if (jsonData.hasOwnProperty("picture_file_name"))
|
||||
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
|
||||
{
|
||||
Grocy.Api.UploadFile($("#product-picture"), 'productpictures',
|
||||
Grocy.Api.UploadFile($("#product-picture")[0].files[0], 'productpictures', jsonData.picture_file_name,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = redirectDestination;
|
||||
@@ -150,6 +170,15 @@ $('#product-form input').keydown(function(event)
|
||||
}
|
||||
});
|
||||
|
||||
Grocy.DeleteProductPictureOnSave = false;
|
||||
$('#delete-current-product-picture-button').on('click', function (e)
|
||||
{
|
||||
Grocy.DeleteProductPictureOnSave = true;
|
||||
$("#current-product-picture").addClass("d-none");
|
||||
$("#delete-current-product-picture-on-save-hint").removeClass("d-none");
|
||||
$("#delete-current-product-picture-button").addClass("disabled");
|
||||
});
|
||||
|
||||
$('#name').focus();
|
||||
$('.input-group-qu').trigger('change');
|
||||
Grocy.FrontendHelpers.ValidateForm('product-form');
|
||||
|
@@ -141,15 +141,20 @@ $(document).on('click', '.product-consume-button', function(e)
|
||||
);
|
||||
});
|
||||
|
||||
$(document).on("click", ".show-product-picture-button", function(e)
|
||||
$(document).on("click", ".product-name-cell", function(e)
|
||||
{
|
||||
var pictureUrl = $(e.currentTarget).attr("data-picture-url");
|
||||
var productName = $(e.currentTarget).attr("data-product-name");
|
||||
var productHasPicture = BoolVal($(e.currentTarget).attr("data-product-has-picture"));
|
||||
|
||||
bootbox.alert({
|
||||
title: L("Image of product #1", productName),
|
||||
message: "<img src='" + pictureUrl + "' class='img-fluid'>"
|
||||
});
|
||||
if (productHasPicture)
|
||||
{
|
||||
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()
|
||||
|
Reference in New Issue
Block a user