ACQ: Avoid refetching LIDs after update if page changes user/berick/acq-avoid-lid-draw-on-update-ignore
authorBill Erickson <berick@esilibrary.com>
Fri, 16 Sep 2011 13:28:15 +0000 (09:28 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 16 Sep 2011 13:28:15 +0000 (09:28 -0400)
After updating a pile of LID (copy) objects in the ACQ lineitem table,
if the user clicks the Return button to return to the main LI table,
avoid re-fetching and re-drawing the copy grid, which is no longer
visible.  This solves the problem of returning to the LI table, opening
the copy display for a new LI, only to find the copies from the
previous LI drawn into the grid.

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

index cf54585..ac6187a 100644 (file)
@@ -39,6 +39,11 @@ var fundStyles = {
     "warning": "color: #c93;"
 };
 
+/* True if the user clicks Return after saving LID changes before 
+ * the LID update has completed.  Setting this helps avoid re-fetching 
+ * copies after the user has navigated away from the copy grid */
+var ignoreCopyUpdateResponse = false;
+
 function AcqLiTable() {
 
     var self = this;
@@ -108,10 +113,14 @@ function AcqLiTable() {
 
     dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
     dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
-    dojo.byId('acq-lit-copies-back-button').onclick = function(){self.show('list')};
     dojo.byId('acq-lit-notes-back-button').onclick = function(){self.show('list')};
     dojo.byId('acq-lit-real-copies-back-button').onclick = function(){self.show('list')};
 
+    dojo.byId('acq-lit-copies-back-button').onclick = function(){
+        ignoreCopyUpdateResponse = true;
+        self.show('list')
+    };
+
     this.reset = function(keep_selectors) {
         while(self.tbody.childNodes[0])
             self.tbody.removeChild(self.tbody.childNodes[0]);
@@ -1832,6 +1841,7 @@ function AcqLiTable() {
                 this._copy_count_cb(liId, total);
 
             openils.Util.show("acq-lit-update-copies-progress");
+            ignoreCopyUpdateResponse = false;
             fieldmapper.standardRequest(
                 ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
                 {   async: true,
@@ -1841,8 +1851,13 @@ function AcqLiTable() {
                         litUpdateCopiesProgress.update(res);
                     },
                     oncomplete: function() {
-                        self.drawCopies(liId, true /* force_fetch */);
                         openils.Util.hide("acq-lit-update-copies-progress");
+                        if (ignoreCopyUpdateResponse) {
+                            console.log("ignoreCopyUpdateResponse = true");
+                            ignoreCopyUpdateResponse = false;
+                            return;
+                        }
+                        self.drawCopies(liId, true /* force_fetch */);
                     }
                 }
             );