ACQ invoice receive UI handles async LI retrieval user/berick/lp1046354-invoice-receive-copies-async-repair
authorBill Erickson <berick@esilibrary.com>
Wed, 3 Oct 2012 19:00:26 +0000 (15:00 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 3 Oct 2012 19:00:26 +0000 (15:00 -0400)
openils.acq.Linetitem.fetchAndRender() now fetches lineitems
asynchronously.  This commit causes the invoice receive UI to calculate
the copies to be received after all lineitems have been (async) fetched.
Without this, it always appears as though there are no copies to receive

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/acq/invoice/receive.js

index 1ed65be..1eddf86 100644 (file)
@@ -265,28 +265,38 @@ function ReceivableCopyTable() {
             this._set_invoice_header();
         }
 
-        this.pcrud.search("acqie", {"invoice": this.inv_id}).forEach(
+        var entries = this.pcrud.search("acqie", {"invoice": this.inv_id});
+        var fetched = 0;
+        var self = this;
+
+        entries.forEach(
             function(entry) {
                 if (entry.lineitem()) {
                     openils.acq.Lineitem.fetchAndRender(
                         entry.lineitem(),
                         {"flesh_li_details": true, "flesh_notes": true},
-                        function(li, str) { self.add_lineitem(entry, li, str); }
+                        function(li, str) { 
+                            self.add_lineitem(entry, li, str); 
+
+                            fetched++;
+                            if (fetched == entries.length) {
+                                self._render_copy_count_info();
+
+                                if (openils.Util.objectProperties(self.li_by_lid).length) {
+                                    openils.Util.show("non-empty");
+                                    openils.Util.hide("empty");
+                                } else {
+                                    openils.Util.hide("non-empty");
+                                    openils.Util.show("empty");
+                                }
+
+                                progress_dialog.hide();
+                            }
+                        }
                     );
                 }
             }
         );
-
-        this._render_copy_count_info();
-
-        if (openils.Util.objectProperties(this.li_by_lid).length) {
-            openils.Util.show("non-empty");
-            openils.Util.hide("empty");
-        } else {
-            openils.Util.hide("non-empty");
-            openils.Util.show("empty");
-        }
-        progress_dialog.hide();
     };
 
     /* returns an array of lineitem_detail IDs */