From e4f5a23f414a1afe91a758e563bed1112d0bc9d6 Mon Sep 17 00:00:00 2001
From: berick <berick@esilibrary.com>
Date: Fri, 6 May 2011 14:46:25 -0400
Subject: [PATCH] initial export drop-down for queue UI

---
 Open-ILS/web/js/ui/default/vandelay/vandelay.js    | 42 +++++++++++++++-------
 .../web/templates/default/vandelay/inc/queue.tt2   |  7 ++++
 2 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/Open-ILS/web/js/ui/default/vandelay/vandelay.js b/Open-ILS/web/js/ui/default/vandelay/vandelay.js
index f076da868b..193056cc32 100644
--- a/Open-ILS/web/js/ui/default/vandelay/vandelay.js
+++ b/Open-ILS/web/js/ui/default/vandelay/vandelay.js
@@ -185,6 +185,7 @@ function vlInit() {
     );
 
     vlAttrEditorInit();
+    vlExportInit();
 }
 
 
@@ -375,20 +376,45 @@ function processSpool(key, queueId, type, onload) {
     );
 }
 
-function retrieveQueuedRecords(type, queueId, onload) {
+function vlExportInit() {
+    var qsel = dojo.byId('vl-queue-export-options');
+    qsel.onchange = function(newVal) {
+        var value = qsel.options[qsel.selectedIndex].value;
+        qsel.selectedIndex = 0;
+        if(!value) return;
+        if(!confirm('Export as "' + value + '"?')) return; // TODO: i18n
+        retrieveQueuedRecords(
+            currentType, 
+            currentQueueId, 
+            function(r) { exportHandler(value, r) },
+            value
+        );
+    }
+}
+
+function exportHandler(type, response) {
+    var content = openils.Util.readResponse(response);
+    if(type == 'print') {
+        // TODO print the content
+    }
+    alert('response = ' + response);
+}
+
+function retrieveQueuedRecords(type, queueId, onload, doExport) {
     displayGlobalDiv('vl-generic-progress');
     queuedRecords = [];
     queuedRecordsMap = {};
     currentOverlayRecordsMap = {};
     currentOverlayRecordsMapGid = {};
     selectableGridRecords = {};
-    //resetVlQueueGridLayout();
 
     if(!type) type = currentType;
     if(!queueId) queueId = currentQueueId;
     if(!onload) onload = handleRetrieveRecords;
 
     var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve.atomic';
+
+    if(doExport) method += '.export.' + doExport;
     if(vlQueueGridShowMatches.checked)
         method = method.replace('records', 'records.matches');
 
@@ -407,18 +433,8 @@ function retrieveQueuedRecords(type, queueId, onload) {
         ['open-ils.vandelay', method],
         {   async: true,
             params: params,
-            /*
-            onresponse: function(r) {
-                console.log("ONREPONSE");
-                var rec = r.recv().content();
-                if(e = openils.Event.parse(rec))
-                    return alert(e);
-                console.log("got record " + rec.id());
-                queuedRecords.push(rec);
-                queuedRecordsMap[rec.id()] = rec;
-            },
-            */
             oncomplete: function(r){
+                if(doExport) return onload();
                 var recs = r.recv().content();
                 if(e = openils.Event.parse(recs[0]))
                     return alert(e);
diff --git a/Open-ILS/web/templates/default/vandelay/inc/queue.tt2 b/Open-ILS/web/templates/default/vandelay/inc/queue.tt2
index b3402642f5..c34c57fa62 100644
--- a/Open-ILS/web/templates/default/vandelay/inc/queue.tt2
+++ b/Open-ILS/web/templates/default/vandelay/inc/queue.tt2
@@ -69,6 +69,13 @@
             <table id='vl-queue-paging-table' class='queue-nav-table'>
                 <tbody>
                     <tr><td valign='bottom' align='right'>
+                        <select id='vl-queue-export-options' style='margin-right: 10px;'>
+                            <!-- TODO I18N -->
+                            <option value=''>Export Queue As...</option>
+                            <option value='print'>Print</option>
+                            <option value='csv'>CSV</option>
+                            <option value='email'>Email</option>
+                        </select>
                         <span style='padding-right:5px;'>&vandelay.results.per.page;</span>
                         <span class='queue-pager-span'>
                             <select jsId='vlQueueDisplayLimit' id='vl-queue-display-limit-selector'
-- 
2.11.0