Bug 28854: Highlight when a scanned item is unexpected
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 25 Nov 2021 17:54:08 +0000 (17:54 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 13 Jul 2022 13:35:38 +0000 (10:35 -0300)
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt

index e3d0d69..c41a8b5 100644 (file)
                                                 [% END %]
                                             </div>
 
+                                            <div id="bundle-feedback" class="alert" style="display:none"></div>
+
                                         </div>
                                         <div class="modal-footer">
                                             <input type="hidden" name="barcode" value="[% item.barcode | html %]">
 
             // item bundles
             $('#verify-items-bundle-contents-barcodes').on('input', function (ev) {
-                const barcodes = ev.target.value.split('\n').map(function(s) { return s.trim() });
-                $('#items-bundle-contents-table tr').each(function () {
-                    const barcode = this.getAttribute('data-barcode');
-                    if (barcodes.includes(barcode)) {
-                        this.classList.add('ok');
+                let char = ev.target.value.slice(-1);
+                if ( char.match(/\n/) ) {
+                    const barcodes = ev.target.value.split('\n').map(function(s) { return s.trim() });
+                    const expected = [];
+                    $('#items-bundle-contents-table tr').each(function () {
+                        const barcode = this.getAttribute('data-barcode');
+                        expected.push(barcode);
+                        if (barcodes.includes(barcode)) {
+                            this.classList.add('ok');
+                        } else {
+                            this.classList.remove('ok');
+                        }
+                    });
+                    const last = barcodes[barcodes.length -2];
+                    const feedback = $('#bundle-feedback');
+                    let string;
+                    if ( !expected.includes(last) ) {
+                        feedback.fadeOut(100, function(){
+                            string = _("Unexpected: ") +last;
+                            feedback.addClass('alert-danger').removeClass('alert-success').html(string).fadeIn(100);
+                        });
                     } else {
-                        this.classList.remove('ok');
+                        feedback.fadeOut(100, function(){
+                            string = _("Varified: ")+last;
+                            feedback.addClass('alert-success').removeClass('alert-danger').html(string).fadeIn(100);
+                        });
                     }
-                })
+                }
             });
 
             $('.bundle_remove').on('click', function() {