1 /* ---------------------------------------------------------------------------
2 # Copyright (C) 2008 Georgia Public Library Service
3 # Bill Erickson <erickson@esilibrary.com>
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.
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');
26 var authtoken = dojo.cookie('ses') || new openils.CGI().param('ses');
27 var VANDELAY_URL = '/vandelay';
29 var authAttrDefs = [];
36 // Fetch the bib and authority attribute definitions
37 fieldmapper.standardRequest(
38 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
40 params: [authtoken, {id:{'!=':null}}],
41 onresponse: function(r) {
42 var def = r.recv().content();
43 if(openils.Event.parse(def))
45 bibAttrDefs.push(def);
50 fieldmapper.standardRequest(
51 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
53 params: [authtoken, {id:{'!=':null}}],
54 onresponse: function(r) {
55 var def = r.recv().content();
56 if(openils.Event.parse(def))
58 authAttrDefs.push(def);
65 * asynchronously upload a file of MARC records
67 function uploadMARC(onload){
68 dojo.byId('vl-ses-input').value = authtoken;
69 dojo.style(dojo.byId('vl-input-td'),"display","none");
70 dojo.style(dojo.byId('vl-upload-progress-span'),"display","inline");
72 dojo.style(dojo.byId('vl-file-label'), 'display', 'none');
73 dojo.style(dojo.byId('vl-file-uploading'), 'display', 'inline');
79 form: dojo.byId('vl-marc-upload-form'),
80 handle: function(data,ioArgs){
81 var content = data.documentElement.textContent;
82 var key = content.split(/\n/)[2]; /* XXX have to strip the headers.. (why?) */
83 dojo.style(dojo.byId('vl-input-td'),"display","inline");
84 dojo.style(dojo.byId('vl-upload-progress-span'),"display","none");
85 dojo.style(dojo.byId('vl-file-label'), 'display', 'inline');
86 dojo.style(dojo.byId('vl-file-uploading'), 'display', 'none');
93 * Creates a new vandelay queue
95 function createQueue(queueName, type, onload) {
96 fieldmapper.standardRequest(
97 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.create'],
99 params: [authtoken, queueName, null, type],
100 oncomplete : function(r) {
101 var queue = r.recv().content();
102 if(e = openils.Event.parse(queue))
111 * Tells vendelay to pull a batch of records from the cache and explode them
112 * out into the vandelay tables
114 function processSpool(key, queue, type, onload) {
115 fieldmapper.standardRequest(
116 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
118 params: [authtoken, key, queue.id()],
119 oncomplete : function(r) {
120 var queue = r.recv().content();
121 if(e = openils.Event.parse(queue))
130 * Create queue, upload MARC, process spool, load the newly created queue
132 function batchUpload() {
133 var queueName = dijit.byId('vl-queue-name').getValue();
134 var recordType = dijit.byId('vl-record-type').getValue();
136 var currentQueue = null;
138 var handleProcessSpool = function() {
139 alert('records uploaded and spooled');
142 var handleUploadMARC = function(key) {
143 alert('marc uploaded');
144 processSpool(key, currentQueue, recordType, handleProcessSpool);
147 var handleCreateQueue = function(queue) {
148 alert('queue created ' + queue.name());
149 currentQueue = queue;
150 uploadMARC(handleUploadMARC);
153 createQueue(queueName, recordType, handleCreateQueue);