Actualiser assets/js/app.js
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
This commit is contained in:
+47
-2
@@ -7508,7 +7508,7 @@ function editInventoryItem(id) {
|
||||
const scaleEditReady = s.scale_enabled && s.scale_gateway_url && _scaleConnected &&
|
||||
(effectiveUnit === 'g' || effectiveUnit === 'ml');
|
||||
|
||||
window._editingProduct = {
|
||||
window._editingProduct = {
|
||||
name: item.name,
|
||||
category: item.category || '',
|
||||
_isOpened: !!item.opened_at,
|
||||
@@ -7516,7 +7516,13 @@ function editInventoryItem(id) {
|
||||
default_quantity: item.default_quantity,
|
||||
package_unit: item.package_unit || '',
|
||||
};
|
||||
|
||||
|
||||
const itemCatForEdit = mapToLocalCategory(item.category, item.name, item.brand);
|
||||
const itemSubcatOptions = getSubcategoryOptionsHtml(itemCatForEdit, item.subcategory || '');
|
||||
const itemSubcatList = SUBCATEGORIES_BY_CATEGORY[itemCatForEdit];
|
||||
const itemSubcatVisible = (itemSubcatList && itemSubcatList.length > 0) ? 'block' : 'none';
|
||||
const itemSubcatRequired = REQUIRED_SUBCATEGORY_CATEGORIES.includes(itemCatForEdit);
|
||||
|
||||
// Rebuild modal content for editing (don't close and reopen - just replace content)
|
||||
document.getElementById('modal-content').innerHTML = `
|
||||
<div class="modal-header">
|
||||
@@ -7524,6 +7530,18 @@ function editInventoryItem(id) {
|
||||
<button class="modal-close" onclick="closeModal()">✕</button>
|
||||
</div>
|
||||
<form class="form" onsubmit="submitEditInventory(event, ${id}, ${item.product_id})">
|
||||
<div class="form-group">
|
||||
<label>${t('product.category_label')}</label>
|
||||
<select id="edit-inv-category" class="form-input" onchange="onEditInvCategoryChange()">
|
||||
${Object.entries(CATEGORY_LABELS).map(([k, label]) => `<option value="${k}" ${itemCatForEdit === k ? 'selected' : ''}>${label}</option>`).join('')}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group" id="edit-inv-subcategory-group" style="display:${itemSubcatVisible}">
|
||||
<label>📂 Sous-catégorie <span class="subcategory-required-mark" style="display:${itemSubcatRequired ? 'inline' : 'none'};color:#e74c3c">*</span></label>
|
||||
<select id="edit-inv-subcategory" class="form-input">
|
||||
${itemSubcatOptions}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>📦 ${t('inventory.label_quantity').replace('📦 ', '')}</label>
|
||||
<div class="qty-control-with-unit">
|
||||
@@ -7589,6 +7607,11 @@ function editInventoryItem(id) {
|
||||
setQtyInputUnitLabel('edit-qty', item.unit || 'pz');
|
||||
}
|
||||
|
||||
function onEditInvCategoryChange() {
|
||||
const cat = document.getElementById('edit-inv-category')?.value || '';
|
||||
updateSubcategoryField('edit-inv-subcategory', 'edit-inv-subcategory-group', cat);
|
||||
}
|
||||
|
||||
function onEditUnitChange() {
|
||||
const unit = document.getElementById('edit-unit').value;
|
||||
setQtyInputUnitLabel('edit-qty', unit);
|
||||
@@ -7615,6 +7638,13 @@ function onEditUnitChange() {
|
||||
|
||||
async function submitEditInventory(e, id, productId) {
|
||||
e.preventDefault();
|
||||
const category = document.getElementById('edit-inv-category')?.value || '';
|
||||
const subcategory = document.getElementById('edit-inv-subcategory')?.value || '';
|
||||
if (REQUIRED_SUBCATEGORY_CATEGORIES.includes(category) && !subcategory) {
|
||||
showToast('Merci de préciser la sous-catégorie', 'error');
|
||||
document.getElementById('edit-inv-subcategory')?.focus();
|
||||
return;
|
||||
}
|
||||
const qty = parseFloat(document.getElementById('edit-qty').value);
|
||||
const loc = document.getElementById('edit-loc').value;
|
||||
const expiry = document.getElementById('edit-expiry').value || null;
|
||||
@@ -7651,6 +7681,21 @@ async function submitEditInventory(e, id, productId) {
|
||||
payload.package_size = 0;
|
||||
}
|
||||
|
||||
const editedItem = currentInventory.find(i => i.id === id) || {};
|
||||
await api('product_save', {}, 'POST', {
|
||||
id: productId,
|
||||
barcode: editedItem.barcode || null,
|
||||
name: editedItem.name,
|
||||
brand: editedItem.brand || '',
|
||||
category: category,
|
||||
subcategory: subcategory || null,
|
||||
image_url: editedItem.image_url || '',
|
||||
unit: editedItem.unit || 'pz',
|
||||
default_quantity: editedItem.default_quantity || 1,
|
||||
package_unit: editedItem.package_unit || '',
|
||||
notes: editedItem.notes || '',
|
||||
});
|
||||
|
||||
await api('inventory_update', {}, 'POST', payload);
|
||||
closeModal();
|
||||
showToast(t('toast.updated'), 'success');
|
||||
|
||||
Reference in New Issue
Block a user