displaying bib attrs in grid. added option to pass in queue id to bypass upload...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 30 Aug 2008 20:30:06 +0000 (20:30 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 30 Aug 2008 20:30:06 +0000 (20:30 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@10494 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/vandelay/vandelay.html
Open-ILS/web/vandelay/vandelay.js

index 29d3317..85c6edd 100644 (file)
             @import "/js/dojo/dojox/grid/_grid/Grid.css";
             td { padding: 6px; }
         </style>
-        <script type="text/javascript" djConfig="parseOnLoad: true" src="/js/dojo/dojo/dojo.js"></script>
+        <script type="text/javascript" djConfig="parseOnLoad: true,isDebug:false" src="/js/dojo/dojo/dojo.js"></script>
         <script type="text/javascript" src='vandelay.js'></script>
     </head>
     <body class="tundra" onload='vlInit();'>
+        <div id="vl-generic-progress" style='width:100%;text-align:center'>
+            <div dojoType="dijit.ProgressBar" style="width:200px" indeterminate="true"></div>
+        </div>
+
         <!-- MARC upload form -->
-        <div id='vl-marc-upload-div'>
+        <div id='vl-marc-upload-div' style='display:none;'>
             <h1>Evergreen MARC File Upload</h1>
             <form id="vl-marc-upload-form" enctype="multipart/form-data">
                 <input type='hidden' name='ses' id='vl-ses-input'/>
@@ -81,7 +85,7 @@
             </form>
         </div>
         <div id='vl-queue-div' style='display:none;height:100%;'>
-            <h1>Record Queue</h1>
+            <h1>Record Queue</h1><br/>
             <div style='height:100%;'>
                 <div dojoType='dojox.Grid' jsId='vlQueueGrid'> </div>
             </div>
index 6777340..1477b8f 100644 (file)
@@ -26,16 +26,25 @@ dojo.require('openils.CGI');
 dojo.require('openils.User');
 dojo.require('openils.Event');
 
-var authtoken = dojo.cookie('ses') || new openils.CGI().param('ses');
+var authtoken;
 var VANDELAY_URL = '/vandelay';
 var bibAttrDefs = [];
 var authAttrDefs = [];
 var queuedRecords = [];
+var queuedRecordsMap = {};
+var bibAttrsFetched = false;
+var authAttrsFetched = false;
+var attrMap = {};
+var currentType;
+var cgi = new openils.CGI();
 
 /**
   * Grab initial data
   */
 function vlInit() {
+    authtoken = dojo.cookie('ses') || cgi.param('ses');
+    bibAttrsFetched = false;
+    authAttrsFetched = false;
 
     // Fetch the bib and authority attribute definitions
     fieldmapper.standardRequest(
@@ -48,6 +57,11 @@ function vlInit() {
                     return alert(def);
                 bibAttrDefs.push(def);
             },
+            oncomplete: function() {
+                bibAttrsFetched = true;
+                if(authAttrsFetched) 
+                    runStartupCommands();
+            }
         }
     );
 
@@ -60,11 +74,31 @@ function vlInit() {
                 if(openils.Event.parse(def)) 
                     return alert(def);
                 authAttrDefs.push(def);
+            },
+            oncomplete: function() {
+                authAttrsFetched = true;
+                if(bibAttrsFetched) 
+                    runStartupCommands();
             }
         }
     );
 }
 
+function displayGlobalDiv(id) {
+    dojo.style(dojo.byId('vl-generic-progress'),"display","none");
+    dojo.style(dojo.byId('vl-marc-upload-div'),"display","none");
+    dojo.style(dojo.byId('vl-queue-div'),"display","none");
+    dojo.style(dojo.byId(id),"display","block");
+}
+
+function runStartupCommands() {
+    var queueParam = cgi.param('qid');
+    currentType = cgi.param('qtype');
+    if(queueParam) 
+        return retrieveQueuedRecords(currentType, queueParam, handleRetrieveRecords);
+    displayGlobalDiv('vl-marc-upload-div');
+}
+
 /**
   * asynchronously upload a file of MARC records
   */
@@ -140,26 +174,50 @@ function retrieveQueuedRecords(type, queueId, onload) {
                 if(e = openils.Event.parse(rec))
                     return alert(e);
                 queuedRecords.push(rec);
+                queuedRecordsMap[rec.id()] = rec;
             },
             oncomplete: function(){onload();}
         }
     );
 }
 
+function getAttrValue(rowIdx) {
+    var data = this.grid.model.getRow(rowIdx);
+    if(!data) return '';
+    var attrName = this.field.split('.')[1];
+    var defId = attrMap[attrName];
+    var rec = queuedRecordsMap[data.id];
+    var attrs = rec.attributes();
+    for(var i = 0; i < attrs.length; i++) {
+        var attr = attrs[i];
+        if(attr.field() == defId) 
+            return attr.attr_value();
+    }
+    return '';
+}
+
 function buildRecordGrid(type) {
-    dojo.style(dojo.byId('vl-marc-upload-div'),"display","none");
-    dojo.style(dojo.byId('vl-queue-div'),"display","block");
+    displayGlobalDiv('vl-queue-div');
 
     /* test structure... */
     var structure = [{
+        noscroll : true,
         cells : [[
             {name: 'ID', field: 'id'},
-            {name: 'Create Time', field: 'create_time'},
-            {name: 'Import Time', field: 'import_time'},
-            {name: 'Purpose', field: 'purpose'},
         ]]
     }];
 
+    var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
+    for(var i = 0; i < defs.length; i++) {
+        var attr = defs[i]
+        attrMap[attr.code()] = attr.id();
+        structure[0].cells[0].push({
+            name:attr.description(), 
+            field:'attr.' + attr.code(),
+            get: getAttrValue
+        });
+    }
+
     vlQueueGrid.setStructure(structure);
 
     var storeData;
@@ -170,40 +228,38 @@ function buildRecordGrid(type) {
 
     var store = new dojo.data.ItemFileReadStore({data:storeData});
     var model = new dojox.grid.data.DojoData(
-        null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
+        null, store, {rowsPerPage: 100, clientSort: true, query:{id:'*'}});
     vlQueueGrid.setModel(model);
     vlQueueGrid.update();
 }
 
+var handleRetrieveRecords = function() {
+    buildRecordGrid(currentType);
+}
+
 /**
   * Create queue, upload MARC, process spool, load the newly created queue 
   */
 function batchUpload() {
     var queueName = dijit.byId('vl-queue-name').getValue();
-    var recordType = dijit.byId('vl-record-type').getValue();
-
+    currentType = dijit.byId('vl-record-type').getValue();
     var currentQueue = null;
 
-    var handleRetrieveRecords = function() {
-        alert("building record grid");
-        buildRecordGrid(recordType);
-    }
-
     var handleProcessSpool = function() {
-        alert('records uploaded and spooled');
-        retrieveQueuedRecords(recordType, currentQueue.id(), handleRetrieveRecords);
+        console.log('records uploaded and spooled');
+        retrieveQueuedRecords(currentType, currentQueue.id(), handleRetrieveRecords);
     }
 
     var handleUploadMARC = function(key) {
-        alert('marc uploaded');
-        processSpool(key, currentQueue, recordType, handleProcessSpool);
+        console.log('marc uploaded');
+        processSpool(key, currentQueue, currentType, handleProcessSpool);
     };
 
     var handleCreateQueue = function(queue) {
-        alert('queue created ' + queue.name());
+        console.log('queue created ' + queue.name());
         currentQueue = queue;
         uploadMARC(handleUploadMARC);
     };
 
-    createQueue(queueName, recordType, handleCreateQueue);
+    createQueue(queueName, currentType, handleCreateQueue);
 }