@@ -274,9 +274,12 @@ class WMSApp {
274274
275275 const data = await response . json ( ) ;
276276 if ( data . success ) {
277- // Reload current session details to reflect changes
277+ // Update UI dynamically without page reload
278+ this . updateBarcodeUIStatus ( barcodeId , processed , notes ) ;
279+
280+ // Update session statistics
278281 if ( this . currentSession ) {
279- await this . loadSessionDetails ( this . currentSession . session . id ) ;
282+ this . updateSessionStatistics ( processed ) ;
280283 }
281284 } else {
282285 throw new Error ( data . error || this . t ( 'failed_to_update_barcode_status' , 'Failed to update barcode status' ) ) ;
@@ -287,6 +290,76 @@ class WMSApp {
287290 }
288291 }
289292
293+ updateBarcodeUIStatus ( barcodeId , processed , notes = '' ) {
294+ // Find the barcode card in the DOM
295+ const barcodeCard = document . querySelector ( `[data-barcode-id="${ barcodeId } "]` ) ;
296+ if ( ! barcodeCard ) return ;
297+
298+ // Update the status span
299+ const statusSpan = barcodeCard . querySelector ( '.status' ) ;
300+ if ( statusSpan ) {
301+ statusSpan . className = `status ${ processed ? 'processed' : 'pending' } ` ;
302+ statusSpan . textContent = processed ? this . t ( 'processed' , 'Processed' ) : this . t ( 'pending' , 'Pending' ) ;
303+ }
304+
305+ // Update the button
306+ const button = barcodeCard . querySelector ( 'button[onclick*="toggleBarcodeStatus"]' ) ;
307+ if ( button ) {
308+ button . className = `btn ${ processed ? 'btn-secondary' : 'btn-success' } ` ;
309+ button . textContent = processed ? this . t ( 'mark_as_pending' , 'Mark as Pending' ) : this . t ( 'mark_as_processed' , 'Mark as Processed' ) ;
310+ button . setAttribute ( 'onclick' , `app.toggleBarcodeStatus(${ barcodeId } , ${ ! processed } )` ) ;
311+ }
312+
313+ // Update notes if provided
314+ if ( notes ) {
315+ let notesDiv = barcodeCard . querySelector ( '.barcode-notes' ) ;
316+ if ( notesDiv ) {
317+ notesDiv . innerHTML = `${ this . t ( 'notes' , 'Notes' ) } : ${ this . escapeHtml ( notes ) } ` ;
318+ } else {
319+ // Add notes div if it doesn't exist
320+ const buttonContainer = button ? button . parentElement : barcodeCard ;
321+ notesDiv = document . createElement ( 'div' ) ;
322+ notesDiv . className = 'barcode-notes' ;
323+ notesDiv . style . marginTop = '0.5rem' ;
324+ notesDiv . style . fontStyle = 'italic' ;
325+ notesDiv . innerHTML = `${ this . t ( 'notes' , 'Notes' ) } : ${ this . escapeHtml ( notes ) } ` ;
326+ buttonContainer . appendChild ( notesDiv ) ;
327+ }
328+ }
329+
330+ // Update the barcode data in current session
331+ if ( this . currentSession && this . currentSession . barcodes ) {
332+ const barcode = this . currentSession . barcodes . find ( b => b . id == barcodeId ) ;
333+ if ( barcode ) {
334+ barcode . processed = processed ;
335+ if ( notes ) barcode . notes = notes ;
336+ }
337+ }
338+ }
339+
340+ updateSessionStatistics ( processed ) {
341+ if ( ! this . currentSession || ! this . currentSession . session ) return ;
342+
343+ // Update processed count in session data
344+ if ( processed ) {
345+ this . currentSession . session . processed_count = Math . min (
346+ this . currentSession . session . processed_count + 1 ,
347+ this . currentSession . session . total_barcodes
348+ ) ;
349+ } else {
350+ this . currentSession . session . processed_count = Math . max (
351+ this . currentSession . session . processed_count - 1 ,
352+ 0
353+ ) ;
354+ }
355+
356+ // Update the processed count display in session header stats
357+ const processedStatCard = document . querySelector ( '#session-details .stat-card:nth-child(2) .stat-value' ) ;
358+ if ( processedStatCard ) {
359+ processedStatCard . textContent = this . currentSession . session . processed_count ;
360+ }
361+ }
362+
290363 async resetAllData ( ) {
291364 // Show confirmation dialog
292365 if ( ! confirm ( this . t ( 'reset_all_warning' , '⚠️ WARNING: This will permanently delete ALL barcode capture sessions and data.\n\nThis action cannot be undone. Are you sure you want to continue?' ) ) ) {
@@ -515,7 +588,7 @@ class WMSApp {
515588 const scanTime = new Date ( barcode . timestamp ) . toLocaleString ( ) ;
516589
517590 html += `
518- <div class="barcode-item">
591+ <div class="barcode-item" data-barcode-id=" ${ barcode . id } " >
519592 <div class="barcode-value">${ this . escapeHtml ( barcode . value ) } </div>
520593 <div class="barcode-meta">
521594 <div class="meta-item">
@@ -546,7 +619,7 @@ class WMSApp {
546619 onclick="app.editBarcode(${ barcode . id } )">
547620 ✏️ ${ this . t ( 'edit' , 'Edit' ) }
548621 </button>
549- ${ barcode . notes ? `<div style="margin-top: 0.5rem; font-style: italic;">${ this . t ( 'notes' , 'Notes' ) } : ${ this . escapeHtml ( barcode . notes ) } </div>` : '' }
622+ ${ barcode . notes ? `<div class="barcode-notes" style="margin-top: 0.5rem; font-style: italic;">${ this . t ( 'notes' , 'Notes' ) } : ${ this . escapeHtml ( barcode . notes ) } </div>` : '' }
550623 </div>
551624 </div>
552625 ` ;
0 commit comments