Spaces:
Running
Running
Update events.js
Browse files
events.js
CHANGED
|
@@ -10,9 +10,8 @@ import { generatePurchaseOrder } from './purchaseOrderService.js';
|
|
| 10 |
*/
|
| 11 |
export function attachAllListeners() {
|
| 12 |
attachProductInputListeners();
|
| 13 |
-
attachMaxStockEditListeners();
|
| 14 |
attachRestockListeners();
|
| 15 |
-
attachPurchaseOrderListener();
|
| 16 |
}
|
| 17 |
|
| 18 |
/**
|
|
@@ -35,38 +34,6 @@ function attachProductInputListeners() {
|
|
| 35 |
});
|
| 36 |
}
|
| 37 |
|
| 38 |
-
function attachMaxStockEditListeners() {
|
| 39 |
-
document.querySelectorAll('.edit-max-stock').forEach(icon => {
|
| 40 |
-
if (icon.dataset.listenerAttached) return;
|
| 41 |
-
icon.dataset.listenerAttached = 'true';
|
| 42 |
-
icon.addEventListener('click', (e) => {
|
| 43 |
-
const valueSpan = e.target.closest('.flex').querySelector('.max-stock-value');
|
| 44 |
-
const materialName = e.target.closest('.dashboard-card').dataset.materialName;
|
| 45 |
-
const material = appState.materials.find(m => m.name === materialName);
|
| 46 |
-
const input = document.createElement('input');
|
| 47 |
-
input.type = 'number';
|
| 48 |
-
input.value = material.maxStock;
|
| 49 |
-
input.className = 'input-field w-20 text-right font-semibold';
|
| 50 |
-
valueSpan.replaceWith(input);
|
| 51 |
-
input.focus();
|
| 52 |
-
input.select();
|
| 53 |
-
const saveChange = () => {
|
| 54 |
-
const newValue = parseInt(input.value, 10);
|
| 55 |
-
if (!isNaN(newValue) && newValue >= material.currentStock) {
|
| 56 |
-
material.maxStock = newValue;
|
| 57 |
-
saveState();
|
| 58 |
-
refreshUI();
|
| 59 |
-
} else {
|
| 60 |
-
showToast('Max stock must be a number >= current stock.', 'error');
|
| 61 |
-
refreshUI();
|
| 62 |
-
}
|
| 63 |
-
};
|
| 64 |
-
input.addEventListener('blur', saveChange);
|
| 65 |
-
input.addEventListener('keydown', (event) => { if (event.key === 'Enter') input.blur(); });
|
| 66 |
-
});
|
| 67 |
-
});
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
function attachRestockListeners() {
|
| 71 |
document.querySelectorAll('.restock-icon').forEach(btn => {
|
| 72 |
if (btn.dataset.listenerAttached) return;
|
|
|
|
| 10 |
*/
|
| 11 |
export function attachAllListeners() {
|
| 12 |
attachProductInputListeners();
|
|
|
|
| 13 |
attachRestockListeners();
|
| 14 |
+
attachPurchaseOrderListener();
|
| 15 |
}
|
| 16 |
|
| 17 |
/**
|
|
|
|
| 34 |
});
|
| 35 |
}
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
function attachRestockListeners() {
|
| 38 |
document.querySelectorAll('.restock-icon').forEach(btn => {
|
| 39 |
if (btn.dataset.listenerAttached) return;
|