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';
30 * asynchronously upload a file of MARC records
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");
37 dojo.style(dojo.byId('vl-file-label'), 'display', 'none');
38 dojo.style(dojo.byId('vl-file-uploading'), 'display', 'inline');
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');
58 * Creates a new vandelay queue
60 function createQueue(queueName, type, onload) {
61 fieldmapper.standardRequest(
62 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.create'],
64 params: [authtoken, queueName, null, type],
65 oncomplete : function(r) {
66 var queue = r.recv().content();
67 if(e = openils.Event.parse(queue))
76 * Tells vendelay to pull a batch of records from the cache and explode them
77 * out into the vandelay tables
79 function processSpool(key, queueId, type, onload) {
80 fieldmapper.standardRequest(
81 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
83 params: [authtoken, key, queueId],
84 oncomplete : function(r) {
85 var queue = r.recv().content();
86 if(e = openils.Event.parse(queue))
95 * Create queue, upload MARC, process spool, load the newly created queue
97 function batchUpload() {
98 var queueName = dijit.byId('vl-queue-name').getValue();
99 var recordType = dijit.byId('vl-record-type').getValue();
101 var currentQueueId = null;
103 var handleProcessSpool = function() {
104 alert('records uploaded and spooled');
107 var handleUploadMARC = function(key) {
108 processSpool(key, currentQueueId, recordType, handleProcessSpool);
111 var handleCreateQueue = function(queueId) {
112 currentQueueId = queueId;
113 uploadMARC(handleUploadMARC);
116 createQueue(queueName, recordType, handleCreateQueue);