clearing invalid cards from the cards() array when the "mark lost" button is clicked
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 24 Sep 2006 15:20:31 +0000 (15:20 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 24 Sep 2006 15:20:31 +0000 (15:20 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6201 dcc99617-32d9-48b4-a31d-7c20da2025e4

Evergreen/xul/staff_client/server/patron/ue.js

index e9b7a9b..7c922b8 100644 (file)
@@ -627,6 +627,16 @@ function uEditMarkCardLost() {
                        card.ischanged(1);
                        card.active(0);
 
+                       if( !card.barcode() ) {
+                               /* a card exists in the array with no barcode */
+                               ueRemoveCard(card.id());
+
+                       } else if( card.isnew() && card.active() == 0 ) {
+                               /* a new card was created, then never used, removing.. */
+                               _debug("removing new inactive card "+card.barcode());
+                               ueRemoveCard(card.id());
+                       }
+
                        /* create a new card for the patron */
                        var newcard = new ac();
                        newcard.id(uEditCardVirtId--);
@@ -647,6 +657,17 @@ function uEditMarkCardLost() {
 }
 
 
+function ueRemoveCard(id) {
+       _debug("removing card from cards() array: " + id);
+       var cds = grep( patron.cards(), function(c){return (c.id() != id)});
+       if(!cds) cds = [];
+       for( var j = 0; j < cds.length; j++ )
+               _debug("patron card array now has :  "+cds[j].id());
+       patron.cards(cds);
+}
+
+
+
 function compactArray(arr) {
        var a = [];
        for( var i = 0; arr && i < arr.length; i++ ) {