JBAS-1038 Refresh notes on print/receive/cancel
authorBill Erickson <berickxx@gmail.com>
Fri, 15 Jan 2016 22:09:34 +0000 (17:09 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Refresh lineitem notes after a PO print, lineitem receive, or lineitem
cancel action occur to pick up the latest lineitem action notes.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/default/acq/common/li_table.js
Open-ILS/web/js/ui/default/acq/po/view_po.js

index 2f935b4..8b12f9c 100644 (file)
@@ -219,6 +219,9 @@ function AcqLiTable() {
 
         if (!dojo.isArray(disabled_fields)) disabled_fields = [];
 
+        // Widgets already created.  No need to rebuild.
+        if (this.batchUpdateWidgets) return;
+
         /* Note that this will directly contain dijits, not the AutoWidget
          * wrapper object. */
         if (!this.batchUpdateWidgets) {
@@ -1337,6 +1340,30 @@ function AcqLiTable() {
         */
     };
 
+    /* Re-fetches lineitem notes and updates 
+     * note count for selected lineitems */
+    this.refreshLiNotes = function(li_ids) {
+        var self = this;
+        if (!li_ids) li_ids = Object.keys(this.liCache);
+        dojo.forEach(li_ids, function(li_id) {
+            fieldmapper.standardRequest(
+                ['open-ils.acq', 
+                    'open-ils.acq.lineitem.retrieve.authoritative'],
+                {   async: true,
+                    params: [self.authtoken, li_id, 
+                        {clear_marc : true, flesh_notes : true}],
+                    oncomplete: function(r) {
+                        var li = openils.Util.readResponse(r);
+                        // update the notes array on cached 
+                        // lineitem for consistency.
+                        self.liCache[li_id].lineitem_notes(li.lineitem_notes());
+                        self.updateLiNotesCount(li);
+                    }
+                }
+            );
+        });
+    }
+
     this.updateLiNotesCount = function(li, row) {
         if (!row) row = this._findLiRow(li);
 
@@ -1517,6 +1544,12 @@ function AcqLiTable() {
      */
     this.drawLiNotes = function(li) {
         var self = this;
+
+        // get the LI from the cache, since it may have been 
+        // modified since this closure was first created.
+        // See refreshLiNotes();
+        li = self.liCache[li.id()];
+
         this.focusLineitem = li.id();
 
         if (!acqLitAlertAlertText._store_ready)
@@ -3325,6 +3358,9 @@ function AcqLiTable() {
                             }
                         }
                     }
+                }, 
+                "oncomplete" : function() {
+                    self.refreshLiNotes(id_list);
                 }
             }
         );
@@ -3394,6 +3430,7 @@ function AcqLiTable() {
 
     this.printPO = function() {
         if(!this.isPO) return;
+        var self = this;
         progressDialog.show(true);
         fieldmapper.standardRequest(
             ['open-ils.acq', 'open-ils.acq.purchase_order.format'],
@@ -3405,6 +3442,7 @@ function AcqLiTable() {
                     if(evt && evt.template_output()) {
                         openils.Util.printHtmlString(evt.template_output().data());
                     }
+                    self.refreshLiNotes();
                 }
             }
         );
@@ -3471,6 +3509,10 @@ function AcqLiTable() {
                     var resp = openils.Util.readResponse(r);
                     self._updateProgressNumbers(resp, true);
                 },
+                oncomplete : function() {
+                    self.refreshLiNotes(
+                        li_list.map(function(li) { return li.id(); }))
+                }
             }
         );
     };
@@ -3495,6 +3537,10 @@ function AcqLiTable() {
                         );
                         progressDialog.hide();
                     }
+                },
+                oncomplete : function() {
+                    if (part == 'lineitem' && !rollback)
+                        self.refreshLiNotes([obj.id()]);
                 }
             }
         );
index 19febae..e1f786a 100644 (file)
@@ -189,6 +189,7 @@ function cancellationUpdater(r) {
                 }
             }
         }
+        liTable.refreshLiNotes();
     }
 }