]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/vandelay/vandelay.js
passing around the queue object, not the id
[working/Evergreen.git] / Open-ILS / web / vandelay / vandelay.js
1 /* ---------------------------------------------------------------------------
2 # Copyright (C) 2008  Georgia Public Library Service
3 # Bill Erickson <erickson@esilibrary.com>
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 # --------------------------------------------------------------------------- */
15 dojo.require("dojo.parser");
16 dojo.require("dojo.io.iframe"); 
17 dojo.require("dijit.ProgressBar"); 
18 dojo.require("dijit.form.Button"); 
19 dojo.require("dijit.form.FilteringSelect"); 
20 dojo.require("dojo.cookie");
21 dojo.require("fieldmapper.Fieldmapper");
22 dojo.require('openils.CGI');
23 dojo.require('openils.User');
24 dojo.require('openils.Event');
25
26 var authtoken = dojo.cookie('ses') || new openils.CGI().param('ses');
27 var VANDELAY_URL = '/vandelay';
28
29 /**
30   * asynchronously upload a file of MARC records
31   */
32 function uploadMARC(onload){
33     dojo.byId('vl-ses-input').value = authtoken;
34     dojo.style(dojo.byId('vl-input-td'),"display","none");
35     dojo.style(dojo.byId('vl-upload-progress-span'),"display","inline"); 
36
37     dojo.style(dojo.byId('vl-file-label'), 'display', 'none');
38     dojo.style(dojo.byId('vl-file-uploading'), 'display', 'inline');
39
40     dojo.io.iframe.send({
41         url: VANDELAY_URL,
42         method: "post",
43         handleAs: "html",
44         form: dojo.byId('vl-marc-upload-form'),
45         handle: function(data,ioArgs){
46             var content = data.documentElement.textContent;
47             var key = content.split(/\n/)[2]; /* XXX have to strip the headers.. (why?) */
48             dojo.style(dojo.byId('vl-input-td'),"display","inline");
49             dojo.style(dojo.byId('vl-upload-progress-span'),"display","none");
50             dojo.style(dojo.byId('vl-file-label'), 'display', 'inline');
51             dojo.style(dojo.byId('vl-file-uploading'), 'display', 'none');
52             onload(key);
53         }
54     });
55 }       
56
57 /**
58   * Creates a new vandelay queue
59   */
60 function createQueue(queueName, type, onload) {
61     fieldmapper.standardRequest(
62         ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.create'],
63         {   async: true,
64             params: [authtoken, queueName, null, type],
65             oncomplete : function(r) {
66                 var queue = r.recv().content();
67                 if(e = openils.Event.parse(queue)) 
68                     return alert(e);
69                 onload(queue.id());
70             }
71         }
72     );
73 }
74
75 /**
76   * Tells vendelay to pull a batch of records from the cache and explode them
77   * out into the vandelay tables
78   */
79 function processSpool(key, queue, type, onload) {
80     fieldmapper.standardRequest(
81         ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
82         {   async: true,
83             params: [authtoken, key, queue.id()],
84             oncomplete : function(r) {
85                 var queue = r.recv().content();
86                 if(e = openils.Event.parse(queue)) 
87                     return alert(e);
88                 onload();
89             }
90         }
91     );
92 }
93
94 /**
95   * Create queue, upload MARC, process spool, load the newly created queue 
96   */
97 function batchUpload() {
98     var queueName = dijit.byId('vl-queue-name').getValue();
99     var recordType = dijit.byId('vl-record-type').getValue();
100
101     var currentQueue = null;
102
103     var handleProcessSpool = function() {
104         alert('records uploaded and spooled');
105     }
106
107     var handleUploadMARC = function(key) {
108         processSpool(key, currentQueue, recordType, handleProcessSpool);
109     };
110
111     var handleCreateQueue = function(queue) {
112         currentQueue = queue;
113         uploadMARC(handleUploadMARC);
114     };
115
116     createQueue(queueName, recordType, handleCreateQueue);
117 }