diff --git a/public/viewjs/productbarcodesform.js b/public/viewjs/productbarcodesform.js index 58617402..29b57822 100644 --- a/public/viewjs/productbarcodesform.js +++ b/public/viewjs/productbarcodesform.js @@ -10,8 +10,6 @@ Grocy.Api.Post('objects/product_barcodes', jsonData, function(result) { - Grocy.EditObjectId = result.created_object_id; - window.location.href = U("/product/" + GetUriParam("product")); }, function(xhr) { @@ -25,7 +23,6 @@ Grocy.Api.Put('objects/product_barcodes/' + Grocy.EditObjectId, jsonData, function(result) { - window.location.href = U("/product/" + GetUriParam("product")); }, function(xhr) { @@ -35,38 +32,8 @@ ); } - Grocy.Api.Get('stock/products/' + jsonData.product_id, - function(productDetails) - { - var existingBarcodes = productDetails.product.barcode || ''; - if (existingBarcodes.length === 0) - { - productDetails.product.barcode = jsonData.barcode; - } - else - { - productDetails.product.barcode += ',' + jsonData.barcode; - } - var jsonDataProduct = {}; - jsonDataProduct.barcode = productDetails.product.barcode; - - Grocy.Api.Put('objects/products/' + jsonData.product_id, jsonDataProduct, - function(result) - { - }, - function(xhr) - { - Grocy.FrontendHelpers.EndUiBusy("barcode-form"); - Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) - } - ); - }, - function(xhr) - { - Grocy.FrontendHelpers.EndUiBusy("barcode-form"); - Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response); - } - ); + window.parent.postMessage(WindowMessageBag("ProductBarcodesChanged"), U("/product/" + GetUriParam("product"))); + window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product"))); }); $('#barcode').on('change', function(e) diff --git a/public/viewjs/productform.js b/public/viewjs/productform.js index 4832428e..6292a7a6 100644 --- a/public/viewjs/productform.js +++ b/public/viewjs/productform.js @@ -381,7 +381,6 @@ var barcodeTable = $('#barcode-table').DataTable({ $('#barcode-table tbody').removeClass("d-none"); barcodeTable.columns.adjust().draw(); - Grocy.Components.UserfieldsForm.Load(); $("#name").trigger("keyup"); $('#name').focus(); @@ -429,19 +428,6 @@ $(document).on('click', '.qu-conversion-delete-button', function(e) }); }); -$(document).on('click', '.qu-conversion-edit-button', function (e) -{ - var id = $(e.currentTarget).attr('data-qu-conversion-id'); - Grocy.ProductEditFormRedirectUri = U("/quantityunitconversion/" + id.toString() + "?product=editobjectid"); - $('#save-product-button').click(); -}); - -$("#qu-conversion-add-button").on("click", function(e) -{ - Grocy.ProductEditFormRedirectUri = U("/quantityunitconversion/new?product=editobjectid"); - $('#save-product-button').click(); -}); - $(document).on('click', '.barcode-delete-button', function(e) { var objectId = $(e.currentTarget).attr('data-barcode-id'); @@ -477,47 +463,11 @@ $(document).on('click', '.barcode-delete-button', function(e) console.error(xhr); } ); - - var newBarcode = ''; - productBarcode.split(',').forEach(function(item) - { - if(barcode != item) - { - newBarcode += ',' + item; - } - }); - - var jsonDataProduct = {}; - jsonDataProduct.barcode = newBarcode; - - Grocy.Api.Put('objects/products/' + productId, jsonDataProduct, - function(result) - { - }, - function(xhr) - { - Grocy.FrontendHelpers.EndUiBusy("product-form"); - Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) - } - ); } } }); }); -$(document).on('click', '.barcode-edit-button', function (e) -{ - var id = $(e.currentTarget).attr('data-barcode-id'); - Grocy.ProductEditFormRedirectUri = U("/productbarcodes/" + id.toString() + "?product=editobjectid"); - $('#save-product-button').click(); -}); - -$("#barcode-add-button").on("click", function(e) -{ - Grocy.ProductEditFormRedirectUri = U("/productbarcodes/new?product=editobjectid"); - $('#save-product-button').click(); -}); - $('#qu_id_purchase').blur(function(e) { // Preset the stock quantity unit with the purchase quantity unit, if the stock quantity unit is unset. @@ -528,3 +478,13 @@ $('#qu_id_purchase').blur(function(e) Grocy.FrontendHelpers.ValidateForm('product-form'); } }); + +$(window).on("message", function(e) +{ + var data = e.originalEvent.data; + + if (data.Message === "ProductBarcodesChanged" || data.Message === "ProductQUConversionChanged") + { + window.location.reload(); + } +}); diff --git a/public/viewjs/quantityunitconversionform.js b/public/viewjs/quantityunitconversionform.js index a21e74ed..5137fc7e 100644 --- a/public/viewjs/quantityunitconversionform.js +++ b/public/viewjs/quantityunitconversionform.js @@ -25,7 +25,8 @@ } else { - window.location.href = U("/product/" + GetUriParam("product")); + window.parent.postMessage(WindowMessageBag("ProductQUConversionChanged"), U("/product/" + GetUriParam("product"))); + window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product"))); } }); }, @@ -54,7 +55,8 @@ } else { - window.location.href = U("/product/" + GetUriParam("product")); + window.parent.postMessage(WindowMessageBag("ProductQUConversionChanged"), U("/product/" + GetUriParam("product"))); + window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product"))); } }); }, @@ -79,7 +81,8 @@ } else { - window.location.href = U("/product/" + GetUriParam("product")); + window.parent.postMessage(WindowMessageBag("ProductQUConversionChanged"), U("/product/" + GetUriParam("product"))); + window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product"))); } }); }, diff --git a/views/productform.blade.php b/views/productform.blade.php index 6af4090c..10eb367d 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -294,7 +294,7 @@

{{ $__t('QU conversions') }} - + {{ $__t('Add') }}

@@ -315,7 +315,7 @@ @if($quConversion->product_id == $product->id || $quConversion->product_id == null) - + @@ -347,7 +347,7 @@

{{ $__t('Barcode Details') }} - + {{ $__t('Add') }}

@@ -367,7 +367,7 @@ @if($barcode->product_id == $product->id || $barcode->product_id == null) - +