From 919ed841c147e89fa45d8cf940ff06f21b34475d Mon Sep 17 00:00:00 2001
From: Bill Erickson <berick@esilibrary.com>
Date: Wed, 29 Feb 2012 17:34:14 -0500
Subject: [PATCH] Acq+Vandelay : skip unneeded vandeley forms

If all lineitems in question are linked to catalog records, avoid
showing the unnecessary vandelay form.  This was already true from the
PO activation action, but this patch adds the same check to the
create-po action from a selection list and PO 'load bibs and items'.

Minor label change for consistency in li_table (Queue -> queue).

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
---
 Open-ILS/src/templates/acq/common/li_table.tt2    |  2 +-
 Open-ILS/web/js/ui/default/acq/common/li_table.js | 33 ++++++++++++++++++-----
 Open-ILS/web/js/ui/default/acq/po/view_po.js      | 14 +---------
 3 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/Open-ILS/src/templates/acq/common/li_table.tt2 b/Open-ILS/src/templates/acq/common/li_table.tt2
index 3a233519c3..3628b888dd 100644
--- a/Open-ILS/src/templates/acq/common/li_table.tt2
+++ b/Open-ILS/src/templates/acq/common/li_table.tt2
@@ -108,7 +108,7 @@
                                         <span name='po' class='hidden'> | <a title='Purchase Order' name='po_link' href='javascript:void(0);'>&#x2318; </a></span>
                                         <span name="show_requests"> | <a title='Patron Requests' name="show_requests_link" href="javascript:void(0);">requests</a></span> 
                                         <span name='pro' class='hidden'> | <a title='[% l('Provider') %]' name='pro_link' href='javascript:void(0);'>&#x235F; </a></span>
-                                        <span name='queue' class='hidden'> | <a title='[% l('Import Queue') %]' name='queue_link' href='javascript:void(0);'>&#x27AC; Queue</a></span>
+                                        <span name='queue' class='hidden'> | <a title='[% l('Import Queue') %]' name='queue_link' href='javascript:void(0);'>[% l('&#x27AC; queue') %]</a></span>
                                     </td>
                                 </tr>
                             </tbody>
diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js
index f2585a166e..860f82ae28 100644
--- a/Open-ILS/web/js/ui/default/acq/common/li_table.js
+++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js
@@ -2124,21 +2124,40 @@ function AcqLiTable() {
 
     this.showAssetCreator = function(onAssetsCreated) {
         if(!this.isPO) return;
-        this.show('asset-creator');
-        if(!this.vlAgent.loaded)
-            this.vlAgent.init();
         var self = this;
-        dojo.connect(assetCreatorButton, 'onClick', 
-            function() { self.createAssets(onAssetsCreated) });
+    
+        // first, let's see if this PO has any LI's that need to be merged/imported
+        self.pcrud.search('jub', {purchase_order : this.isPO, eg_bib_id : null}, {
+            id_list : true,
+            oncomplete : function(r) {
+                var resp = openils.Util.readResponse(r);
+                if (resp && resp.length) {
+                    // PO has some non-linked jubs.  
+                    
+                    self.show('asset-creator');
+                    if(!self.vlAgent.loaded)
+                        self.vlAgent.init();
+
+                    dojo.connect(assetCreatorButton, 'onClick', 
+                        function() { self.createAssets(onAssetsCreated) });
+
+                } else {
+
+                    // all jubs linked, move on to asset creation
+                    self.createAssets(onAssetsCreated, true); 
+                }
+            }
+        });
     }
 
-    this.createAssets = function(onAssetsCreated) {
+    this.createAssets = function(onAssetsCreated, noVl) {
         this.show('acq-lit-progress-numbers');
         var self = this;
+        var vlArgs = (noVl) ? {} : {vandelay : this.vlAgent.values()};
         fieldmapper.standardRequest(
             ['open-ils.acq', 'open-ils.acq.purchase_order.assets.create'],
             {   async: true,
-                params: [this.authtoken, this.isPO, {vandelay : this.vlAgent.values()}],
+                params: [this.authtoken, this.isPO, vlArgs],
                 onresponse: function(r) {
                     var resp = openils.Util.readResponse(r);
                     self._updateProgressNumbers(resp, !Boolean(onAssetsCreated), onAssetsCreated);
diff --git a/Open-ILS/web/js/ui/default/acq/po/view_po.js b/Open-ILS/web/js/ui/default/acq/po/view_po.js
index 6c08ce1263..07c29e789c 100644
--- a/Open-ILS/web/js/ui/default/acq/po/view_po.js
+++ b/Open-ILS/web/js/ui/default/acq/po/view_po.js
@@ -513,19 +513,7 @@ function activatePo() {
             return false;
     }
 
-    // first, let's see if this PO has any LI's that need to be merged/imported
-    pcrud.search('jub', {purchase_order : poId, eg_bib_id : null}, {
-        id_list : true,
-        oncomplete : function(r) {
-            var resp = openils.Util.readResponse(r);
-            if (resp && resp.length) {
-                // kick off the merge/import process
-                liTable.showAssetCreator(activatePoStage2);
-            } else {
-                activatePoStage2();
-            }
-        }
-    });
+    liTable.showAssetCreator(activatePoStage2);
 }
 
 function activatePoStage2() {
-- 
2.11.0