mirror of
https://github.com/grocy/grocy.git
synced 2026-04-07 05:16:15 +02:00
Embedded barcode and qu-conversion with page reload on change
This commit is contained in:
parent
c3f77591ee
commit
410a0f0094
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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")));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@
|
|||
<div class="col-lg-6 col-xs-12">
|
||||
<h2>
|
||||
{{ $__t('QU conversions') }}
|
||||
<a id="qu-conversion-add-button" class="btn btn-outline-dark" href="#">
|
||||
<a class="btn btn-outline-dark show-as-dialog-link" type="button" href="{{ $U('/quantityunitconversion/new?embedded&product=' . $product->id ) }}">
|
||||
<i class="fas fa-plus"></i> {{ $__t('Add') }}
|
||||
</a>
|
||||
</h2>
|
||||
|
|
@ -315,7 +315,7 @@
|
|||
@if($quConversion->product_id == $product->id || $quConversion->product_id == null)
|
||||
<tr>
|
||||
<td class="fit-content border-right">
|
||||
<a class="btn btn-sm btn-info qu-conversion-edit-button @if($quConversion->product_id == null) disabled @endif" href="#" data-qu-conversion-id="{{ $quConversion->id }}">
|
||||
<a class="btn btn-sm btn-info show-as-dialog-link @if($quConversion->product_id == null) disabled @endif" href="{{ $U('/quantityunitconversion/' . $quConversion->id . '?embedded&product=' . $product->id ) }}">
|
||||
<i class="fas fa-edit"></i>
|
||||
</a>
|
||||
<a class="btn btn-sm btn-danger qu-conversion-delete-button @if($quConversion->product_id == null) disabled @endif" href="#" data-qu-conversion-id="{{ $quConversion->id }}">
|
||||
|
|
@ -347,7 +347,7 @@
|
|||
|
||||
<h2>
|
||||
{{ $__t('Barcode Details') }}
|
||||
<a id="barcode-add-button" class="btn btn-outline-dark" href="#">
|
||||
<a class="btn btn-outline-dark show-as-dialog-link" type="button" href="{{ $U('/productbarcodes/new?embedded&product=' . $product->id ) }}">
|
||||
<i class="fas fa-plus"></i> {{ $__t('Add') }}
|
||||
</a>
|
||||
</h2>
|
||||
|
|
@ -367,7 +367,7 @@
|
|||
@if($barcode->product_id == $product->id || $barcode->product_id == null)
|
||||
<tr>
|
||||
<td class="fit-content border-right">
|
||||
<a class="btn btn-sm btn-info barcode-edit-button @if($barcode->product_id == null) disabled @endif" href="#" data-barcode-id="{{ $barcode->id }}">
|
||||
<a class="btn btn-sm btn-info show-as-dialog-link @if($barcode->product_id == null) disabled @endif" href="{{ $U('/productbarcodes/' . $barcode->id . '?embedded&product=' . $product->id ) }}">
|
||||
<i class="fas fa-edit"></i>
|
||||
</a>
|
||||
<a class="btn btn-sm btn-danger barcode-delete-button @if($barcode->product_id == null) disabled @endif" href="#" data-barcode-id="{{ $barcode->id }}" data-barcode="{{ $barcode->barcode }}" data-product-barcode="{{ $product->barcode }}" data-product-id="{{ $product->id }}">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user