Ultronprime commited on
Commit
3f496fe
·
verified ·
1 Parent(s): 964ed8c

Update events.js

Browse files
Files changed (1) hide show
  1. events.js +38 -0
events.js CHANGED
@@ -10,6 +10,7 @@ import { generatePurchaseOrder } from './purchaseOrderService.js';
10
  */
11
  export function attachAllListeners() {
12
  attachProductInputListeners();
 
13
  attachRestockListeners();
14
  attachPurchaseOrderListener();
15
  }
@@ -34,6 +35,43 @@ function attachProductInputListeners() {
34
  });
35
  }
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  function attachRestockListeners() {
38
  document.querySelectorAll('.restock-icon').forEach(btn => {
39
  if (btn.dataset.listenerAttached) return;
 
10
  */
11
  export function attachAllListeners() {
12
  attachProductInputListeners();
13
+ attachCurrentStockEditListeners(); // REPLACED max stock editor
14
  attachRestockListeners();
15
  attachPurchaseOrderListener();
16
  }
 
35
  });
36
  }
37
 
38
+ function attachCurrentStockEditListeners() {
39
+ document.querySelectorAll('.edit-current-stock').forEach(icon => {
40
+ if (icon.dataset.listenerAttached) return;
41
+ icon.dataset.listenerAttached = 'true';
42
+ icon.addEventListener('click', (e) => {
43
+ const card = e.target.closest('.dashboard-card');
44
+ const valueDiv = card.querySelector('.current-stock-value');
45
+ const materialName = card.dataset.materialName;
46
+ const material = appState.materials.find(m => m.name === materialName);
47
+
48
+ const input = document.createElement('input');
49
+ input.type = 'number';
50
+ input.value = material.currentStock;
51
+ input.className = 'input-field w-24 text-2xl font-bold'; // Match styling
52
+
53
+ valueDiv.replaceWith(input);
54
+ input.focus();
55
+ input.select();
56
+
57
+ const saveChange = () => {
58
+ const newValue = parseInt(input.value, 10);
59
+ if (!isNaN(newValue) && newValue >= 0) {
60
+ material.currentStock = newValue;
61
+ saveState();
62
+ refreshUI();
63
+ } else {
64
+ showToast('Stock must be a valid positive number.', 'error');
65
+ refreshUI(); // Re-render to discard bad input
66
+ }
67
+ };
68
+
69
+ input.addEventListener('blur', saveChange);
70
+ input.addEventListener('keydown', (event) => { if (event.key === 'Enter') input.blur(); });
71
+ });
72
+ });
73
+ }
74
+
75
  function attachRestockListeners() {
76
  document.querySelectorAll('.restock-icon').forEach(btn => {
77
  if (btn.dataset.listenerAttached) return;