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.FilteringSelect");
19 dojo.require("dijit.layout.ContentPane");
20 dojo.require("dijit.layout.TabContainer");
21 dojo.require("dijit.layout.LayoutContainer");
22 dojo.require('dijit.form.Button');
23 dojo.require('dijit.form.CheckBox');
24 dojo.require('dijit.Toolbar');
25 dojo.require('dijit.Tooltip');
26 dojo.require('dijit.Menu');
27 dojo.require("dijit.Dialog");
28 dojo.require("dojo.cookie");
29 dojo.require('dojox.grid.DataGrid');
30 dojo.require("dojo.data.ItemFileReadStore");
31 dojo.require('dojo.date.locale');
32 dojo.require('dojo.date.stamp');
33 dojo.require("fieldmapper.Fieldmapper");
34 dojo.require("fieldmapper.dojoData");
35 dojo.require('openils.CGI');
36 dojo.require('openils.User');
37 dojo.require('openils.Event');
38 dojo.require('openils.Util');
39 dojo.require('openils.MarcXPathParser');
40 dojo.require('openils.widget.GridColumnPicker');
44 'vl-generic-progress',
45 'vl-generic-progress-with-total',
50 'vl-queue-select-div',
51 'vl-marc-upload-status-div',
57 var VANDELAY_URL = '/vandelay-upload';
59 var authAttrDefs = [];
60 var queuedRecords = [];
61 var queuedRecordsMap = {};
62 var bibAttrsFetched = false;
63 var authAttrsFetched = false;
64 var attrDefMap = {}; // maps attr def code names to attr def ids
66 var currentQueueId = null;
68 var currentMatchedRecords; // set of loaded matched bib records
69 var currentOverlayRecordsMap; // map of import record to overlay record
70 var currentOverlayRecordsMapGid; // map of import record to overlay record grid id
71 var currentImportRecId; // when analyzing matches, this is the current import record
72 var userBibQueues = []; // only non-complete queues
73 var userAuthQueues = []; // only non-complete queues
75 var allUserAuthQueues;
76 var selectableGridRecords;
77 var cgi = new openils.CGI();
78 var vlQueueGridColumePicker = {};
79 var vlBibSources = [];
85 authtoken = dojo.cookie('ses') || cgi.param('ses');
86 var initNeeded = 5; // how many async responses do we need before we're init'd
87 var initCount = 0; // how many async reponses we've received
89 openils.Util.registerEnterHandler(
90 vlQueueDisplayPage.domNode, function(){retrieveQueuedRecords();});
91 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
93 function checkInitDone() {
95 if(initCount == initNeeded)
99 // Fetch the bib and authority attribute definitions
100 vlFetchBibAttrDefs(function () { checkInitDone(); });
101 vlFetchAuthAttrDefs(function () { checkInitDone(); });
103 vlRetrieveQueueList('bib', null,
105 allUserBibQueues = list;
106 for(var i = 0; i < allUserBibQueues.length; i++) {
107 if(allUserBibQueues[i].complete() == 'f')
108 userBibQueues.push(allUserBibQueues[i]);
114 vlRetrieveQueueList('auth', null,
116 allUserAuthQueues = list;
117 for(var i = 0; i < allUserAuthQueues.length; i++) {
118 if(allUserAuthQueues[i].complete() == 'f')
119 userAuthQueues.push(allUserAuthQueues[i]);
125 fieldmapper.standardRequest(
126 ['open-ils.permacrud', 'open-ils.permacrud.search.cbs.atomic'],
128 params: [authtoken, {id:{"!=":null}}, {order_by:{cbs:'id'}}],
129 oncomplete : function(r) {
130 vlBibSources = openils.Util.readResponse(r, false, true);
140 dojo.addOnLoad(vlInit);
143 // fetch the bib and authority attribute definitions
145 function vlFetchBibAttrDefs(postcomplete) {
147 fieldmapper.standardRequest(
148 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
150 params: [authtoken, {id:{'!=':null}}],
151 onresponse: function(r) {
152 var def = r.recv().content();
153 if(e = openils.Event.parse(def[0]))
155 bibAttrDefs.push(def);
157 oncomplete: function() {
158 bibAttrDefs = bibAttrDefs.sort(
160 if(a.id() > b.id()) return 1;
161 if(a.id() < b.id()) return -1;
171 function vlFetchAuthAttrDefs(postcomplete) {
173 fieldmapper.standardRequest(
174 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
176 params: [authtoken, {id:{'!=':null}}],
177 onresponse: function(r) {
178 var def = r.recv().content();
179 if(e = openils.Event.parse(def[0]))
181 authAttrDefs.push(def);
183 oncomplete: function() {
184 authAttrDefs = authAttrDefs.sort(
186 if(a.id() > b.id()) return 1;
187 if(a.id() < b.id()) return -1;
197 function vlRetrieveQueueList(type, filter, onload) {
198 type = (type == 'bib') ? type : 'authority';
199 fieldmapper.standardRequest(
200 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.owner.retrieve.atomic'],
202 params: [authtoken, null, filter],
203 oncomplete: function(r) {
204 var list = r.recv().content();
205 if(e = openils.Event.parse(list[0]))
214 function displayGlobalDiv(id) {
215 for(var i = 0; i < globalDivs.length; i++) {
217 dojo.style(dojo.byId(globalDivs[i]), 'display', 'none');
219 alert('please define div ' + globalDivs[i]);
222 dojo.style(dojo.byId(id),'display','block');
224 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
225 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
226 openils.Util.removeCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
227 openils.Util.removeCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
230 case 'vl-marc-export-div':
231 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
233 case 'vl-marc-upload-div':
234 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
236 case 'vl-queue-select-div':
237 openils.Util.addCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
239 case 'vl-attr-editor-div':
240 openils.Util.addCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
245 function runStartupCommands() {
246 currentQueueId = cgi.param('qid');
247 currentType = cgi.param('qtype');
248 dojo.style('vl-nav-bar', 'visibility', 'visible');
250 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
255 * asynchronously upload a file of MARC records
257 function uploadMARC(onload){
258 dojo.byId('vl-upload-status-count').innerHTML = '0';
259 dojo.byId('vl-ses-input').value = authtoken;
260 displayGlobalDiv('vl-marc-upload-status-div');
261 dojo.io.iframe.send({
265 form: dojo.byId('vl-marc-upload-form'),
266 handle: function(data,ioArgs){
267 var content = data.documentElement.textContent;
274 * Creates a new vandelay queue
276 function createQueue(queueName, type, onload) {
277 var name = (type=='bib') ? 'bib' : 'authority';
278 var method = 'open-ils.vandelay.'+ name +'_queue.create'
279 fieldmapper.standardRequest(
280 ['open-ils.vandelay', method],
282 params: [authtoken, queueName, null, name],
283 oncomplete : function(r) {
284 var queue = r.recv().content();
285 if(e = openils.Event.parse(queue))
294 * Tells vandelay to pull a batch of records from the cache and explode them
295 * out into the vandelay tables
297 function processSpool(key, queueId, type, onload) {
298 fieldmapper.standardRequest(
299 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
301 params: [authtoken, key, queueId],
302 onresponse : function(r) {
303 var resp = r.recv().content();
304 if(e = openils.Event.parse(resp))
306 dojo.byId('vl-upload-status-count').innerHTML = resp;
308 oncomplete : function(r) {onload();}
313 function retrieveQueuedRecords(type, queueId, onload) {
314 displayGlobalDiv('vl-generic-progress');
316 queuedRecordsMap = {};
317 currentOverlayRecordsMap = {};
318 currentOverlayRecordsMapGid = {};
319 selectableGridRecords = {};
320 //resetVlQueueGridLayout();
322 if(!type) type = currentType;
323 if(!queueId) queueId = currentQueueId;
324 if(!onload) onload = handleRetrieveRecords;
326 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve.atomic';
327 if(vlQueueGridShowMatches.checked)
328 method = method.replace('records', 'records.matches');
330 var sel = dojo.byId('vl-queue-display-limit-selector');
331 var limit = parseInt(sel.options[sel.selectedIndex].value);
332 var offset = limit * parseInt(vlQueueDisplayPage.attr('value')-1);
334 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit}];
335 if(vlQueueGridShowNonImport.checked)
336 params[2].non_imported = 1;
338 fieldmapper.standardRequest(
339 ['open-ils.vandelay', method],
343 onresponse: function(r) {
344 console.log("ONREPONSE");
345 var rec = r.recv().content();
346 if(e = openils.Event.parse(rec))
348 console.log("got record " + rec.id());
349 queuedRecords.push(rec);
350 queuedRecordsMap[rec.id()] = rec;
353 oncomplete: function(r){
354 var recs = r.recv().content();
355 if(e = openils.Event.parse(recs[0]))
357 for(var i = 0; i < recs.length; i++) {
359 queuedRecords.push(rec);
360 queuedRecordsMap[rec.id()] = rec;
368 function vlLoadMatchUI(recId) {
369 displayGlobalDiv('vl-generic-progress');
370 var matches = queuedRecordsMap[recId].matches();
372 currentImportRecId = recId;
373 for(var i = 0; i < matches.length; i++)
374 records.push(matches[i].eg_record());
376 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
377 var params = [records];
378 if(currentType == 'auth') {
379 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
380 parmas = [authtoken, records, {clear_marc:1}];
383 fieldmapper.standardRequest(
387 oncomplete: function(r) {
388 var recs = r.recv().content();
389 if(e = openils.Event.parse(recs))
393 displayGlobalDiv('vl-match-div');
394 resetVlMatchGridLayout();
395 currentMatchedRecords = recs;
396 vlMatchGrid.setStructure(vlMatchGridLayout);
398 // build the data store of records with match information
399 var dataStore = bre.toStoreData(recs, null,
400 {virtualFields:['dest_matchpoint', 'src_matchpoint', '_id']});
401 dataStore.identifier = '_id';
403 var matchSeenMap = {};
405 for(var i = 0; i < dataStore.items.length; i++) {
406 var item = dataStore.items[i];
407 item._id = i; // just need something unique
408 for(var j = 0; j < matches.length; j++) {
409 var match = matches[j];
410 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
411 item.dest_matchpoint = match.field_type();
412 var attr = getRecAttrFromMatch(queuedRecordsMap[recId], match);
413 item.src_matchpoint = getRecAttrDefFromAttr(attr, currentType).code();
414 matchSeenMap[match.id()] = 1;
420 // now populate the grid
421 vlPopulateMatchGrid(vlMatchGrid, dataStore);
427 function vlPopulateMatchGrid(grid, data) {
428 var store = new dojo.data.ItemFileReadStore({data:data});
429 grid.setStore(store);
433 function showMe(id) {
434 dojo.style(dojo.byId(id), 'display', 'block');
436 function hideMe(id) {
437 dojo.style(dojo.byId(id), 'display', 'none');
441 function vlLoadMARCHtml(recId, inCat, oncomplete) {
442 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
443 displayGlobalDiv('vl-generic-progress');
445 var params = [recId, 1];
448 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
449 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
450 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
451 if(currentType == 'auth')
452 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
454 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
455 dijit.byId('vl-marc-html-edit-button').onClick =
456 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
457 params = [authtoken, recId];
458 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
459 if(currentType == 'auth')
460 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
463 fieldmapper.standardRequest(
467 oncomplete: function(r) {
468 displayGlobalDiv('vl-marc-html-div');
469 var html = r.recv().content();
470 dojo.byId('vl-marc-record-html').innerHTML = html;
478 function getRecMatchesFromAttrCode(rec, attrCode) {
480 var attr = getRecAttrFromCode(rec, attrCode);
481 for(var j = 0; j < rec.matches().length; j++) {
482 var match = rec.matches()[j];
483 if(match.matched_attr() == attr.id())
490 function getRecAttrFromMatch(rec, match) {
491 for(var i = 0; i < rec.attributes().length; i++) {
492 var attr = rec.attributes()[i];
493 if(attr.id() == match.matched_attr())
498 function getRecAttrDefFromAttr(attr, type) {
499 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
500 for(var i = 0; i < defs.length; i++) {
502 if(def.id() == attr.field())
507 function getRecAttrFromCode(rec, attrCode) {
508 var defId = attrDefMap[currentType][attrCode];
509 var attrs = rec.attributes();
510 for(var i = 0; i < attrs.length; i++) {
512 if(attr.field() == defId)
518 function vlGetViewMatches(rowIdx, item) {
520 var id = this.grid.store.getValue(item, 'id');
521 var rec = queuedRecordsMap[id];
522 if(rec.matches().length > 0)
523 return this.value.replace('RECID', id);
527 function getAttrValue(rowIdx, item) {
529 var attrCode = this.field.split('.')[1];
530 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
531 var attr = getRecAttrFromCode(rec, attrCode);
532 return (attr) ? attr.attr_value() : '';
535 function vlGetDateTimeField(rowIdx, item) {
537 var value = this.grid.store.getValue(item, this.field);
538 if(!value) return '';
539 var date = dojo.date.stamp.fromISOString(value);
540 return dojo.date.locale.format(date, {selector:'date'});
543 function vlGetCreator(rowIdx, item) {
545 var id = this.grid.store.getValue(item, 'creator');
547 return userCache[id].usrname();
548 var user = fieldmapper.standardRequest(
549 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
550 if(e = openils.Event.parse(user))
552 userCache[id] = user;
553 return user.usrname();
556 function vlGetViewMARC(rowIdx, item) {
558 return this.value.replace('RECID', this.grid.store.getValue(item, 'id'));
561 function vlGetOverlayTargetSelector(rowIdx, item) {
563 var _id = this.grid.store.getValue(item, '_id');
564 var id = this.grid.store.getValue(item, 'id');
565 var value = this.value.replace(/GRIDID/g, _id);
566 value = value.replace(/RECID/g, currentImportRecId);
567 value = value.replace(/ID/g, id);
568 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
569 return value.replace('/>', 'checked="checked"/>');
574 * see if the user has enabled overlays for the current match set and,
575 * if so, map the current import record to the overlay target.
577 function vlHandleOverlayTargetSelected(recId, gridId) {
578 var noneSelected = true;
579 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
580 for(var i = 0; i < checkboxes.length; i++) {
581 var checkbox = checkboxes[i];
582 var matchRecId = checkbox.getAttribute('match');
583 var gid = checkbox.getAttribute('gridid');
584 if(checkbox.checked) {
585 if(matchRecId == recId && gid == gridId) {
586 noneSelected = false;
587 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
588 currentOverlayRecordsMapGid[currentImportRecId] = gid;
589 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
590 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
592 checkbox.checked = false;
598 delete currentOverlayRecordsMap[currentImportRecId];
599 delete currentOverlayRecordsMapGid[currentImportRecId];
600 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
601 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
605 var valLastQueueType = null;
606 function buildRecordGrid(type) {
607 displayGlobalDiv('vl-queue-div');
610 openils.Util.show('vl-bib-queue-grid-wrapper');
611 openils.Util.hide('vl-auth-queue-grid-wrapper');
612 vlQueueGrid = vlBibQueueGrid;
613 vlQueueGridMenu = vlBibQueueGridMenu;
615 openils.Util.show('vl-auth-queue-grid-wrapper');
616 openils.Util.hide('vl-bib-queue-grid-wrapper');
617 vlQueueGrid = vlAuthQueueGrid;
618 vlQueueGridMenu = vlAuthQueueGridMenu;
621 if(valLastQueueType != type) {
622 valLastQueueType = type;
623 resetVlQueueGridLayout();
624 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
625 attrDefMap[type] = {};
626 for(var i = 0; i < defs.length; i++) {
628 attrDefMap[type][def.code()] = def.id();
630 name:def.description(),
631 field:'attr.' + def.code(),
633 selectableColumn:true
635 vlQueueGridLayout[0].cells[0].push(col);
641 storeData = vqbr.toStoreData(queuedRecords);
643 storeData = vqar.toStoreData(queuedRecords);
645 var store = new dojo.data.ItemFileReadStore({data:storeData});
646 vlQueueGrid.setStore(store);
648 if(vlQueueGridColumePicker[type]) {
649 vlQueueGrid.update();
651 vlQueueGrid.attr('structure', vlQueueGridLayout);
652 vlQueueGridMenu.init({
654 authtoken : authtoken,
655 prefix : 'vandelay.queue.'+type
657 vlQueueGridMenu.load();
658 vlQueueGridColumePicker[type] = vlQueueGridMenu;
662 function vlQueueGridPrevPage() {
663 var page = parseInt(vlQueueDisplayPage.getValue());
665 vlQueueDisplayPage.setValue(page - 1);
666 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
669 function vlQueueGridNextPage() {
670 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
671 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
674 function vlDeleteQueue(type, queueId, onload) {
675 fieldmapper.standardRequest(
676 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
678 params: [authtoken, queueId],
679 oncomplete: function(r) {
680 var resp = r.recv().content();
681 if(e = openils.Event.parse(resp))
690 function vlQueueGridDrawSelectBox(rowIdx, item) {
692 var id = this.grid.store.getValue(item, 'id');
693 var domId = 'vl-record-list-selected-' + id;
694 selectableGridRecords[domId] = id;
695 return "<div><input type='checkbox' id='"+domId+"'/></div>";
698 function vlSelectAllQueueGridRecords() {
699 for(var id in selectableGridRecords)
700 dojo.byId(id).checked = true;
702 function vlSelectNoQueueGridRecords() {
703 for(var id in selectableGridRecords)
704 dojo.byId(id).checked = false;
706 function vlToggleQueueGridSelect() {
707 if(dojo.byId('vl-queue-grid-row-selector').checked)
708 vlSelectAllQueueGridRecords();
710 vlSelectNoQueueGridRecords();
713 var handleRetrieveRecords = function() {
714 buildRecordGrid(currentType);
715 vlFetchQueueSummary(currentQueueId, currentType,
717 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
718 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
719 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
724 function vlFetchQueueSummary(qId, type, onload) {
725 fieldmapper.standardRequest(
726 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
728 params: [authtoken, qId],
729 oncomplete : function(r) {
730 var summary = r.recv().content();
731 if(e = openils.Event.parse(summary))
733 return onload(summary);
740 function vlImportSelectedRecords() {
741 displayGlobalDiv('vl-generic-progress-with-total');
744 for(var id in selectableGridRecords) {
745 if(dojo.byId(id).checked) {
746 var recId = selectableGridRecords[id];
747 var rec = queuedRecordsMap[recId];
748 if(!rec.import_time())
753 fieldmapper.standardRequest(
754 ['open-ils.vandelay', 'open-ils.vandelay.'+currentType+'_record.list.import'],
756 params: [authtoken, records, {overlay_map:currentOverlayRecordsMap}],
757 onresponse: function(r) {
758 var resp = r.recv().content();
759 if(e = openils.Event.parse(resp))
762 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
764 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
771 function vlImportAllRecords() {
772 vlImportRecordQueue(currentType, currentQueueId, false,
773 function(){displayGlobalDiv('vl-queue-div');});
776 function vlImportRecordQueue(type, queueId, noMatchOnly, onload) {
777 displayGlobalDiv('vl-generic-progress-with-total');
778 var method = 'open-ils.vandelay.bib_queue.import';
780 method = method.replace('import', 'nomatch.import');
782 method = method.replace('bib', 'auth');
784 fieldmapper.standardRequest(
785 ['open-ils.vandelay', method],
787 params: [authtoken, queueId],
788 onresponse: function(r) {
789 var resp = r.recv().content();
790 if(e = openils.Event.parse(resp))
792 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
794 oncomplete: function() {onload();}
801 * Create queue, upload MARC, process spool, load the newly created queue
803 function batchUpload() {
804 var queueName = dijit.byId('vl-queue-name').getValue();
805 currentType = dijit.byId('vl-record-type').getValue();
807 var handleProcessSpool = function() {
808 if(vlUploadQueueAutoImport.checked) {
809 vlImportRecordQueue(currentType, currentQueueId, true,
811 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
815 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
819 var handleUploadMARC = function(key) {
820 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
821 processSpool(key, currentQueueId, currentType, handleProcessSpool);
824 var handleCreateQueue = function(queue) {
825 currentQueueId = queue.id();
826 uploadMARC(handleUploadMARC);
829 if(vlUploadQueueSelector.getValue() && !queueName) {
830 currentQueueId = vlUploadQueueSelector.getValue();
831 uploadMARC(handleUploadMARC);
833 createQueue(queueName, currentType, handleCreateQueue);
838 function vlFleshQueueSelect(selector, type) {
839 var data = (type == 'bib') ? vbq.toStoreData(allUserBibQueues) : vaq.toStoreData(allUserAuthQueues);
840 selector.store = new dojo.data.ItemFileReadStore({data:data});
841 selector.setValue(null);
842 selector.setDisplayedValue('');
844 selector.setValue(data[0].id());
847 function vlShowUploadForm() {
848 displayGlobalDiv('vl-marc-upload-div');
849 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
850 vlUploadSourceSelector.store =
851 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
852 vlUploadSourceSelector.setValue(vlBibSources[0].id());
855 function vlShowQueueSelect() {
856 displayGlobalDiv('vl-queue-select-div');
857 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
860 function vlFetchQueueFromForm() {
861 currentType = vlQueueSelectType.getValue();
862 currentQueueId = vlQueueSelectQueueList.getValue();
863 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
866 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
868 To run in Firefox directly, must set signed.applets.codebase_principal_support
869 to true in about:config
871 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
872 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
875 // after the record is saved, reload the HTML display
876 var stat = r.recv().content();
877 if(e = openils.Event.parse(stat))
879 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
881 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
885 record : {marc : rec.marc()},
887 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
888 func: function(xmlString) {
889 var method = 'open-ils.permacrud.update.' + rec.classname;
891 fieldmapper.standardRequest(
892 ['open-ils.permacrud', method],
894 params: [authtoken, rec],
903 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
904 var method = 'open-ils.permacrud.search.vqbr';
905 if(currentType != 'bib')
906 method = method.replace(/vqbr/,'vqar');
908 fieldmapper.standardRequest(
909 ['open-ils.permacrud', method],
911 params: [authtoken, {id : recId}],
912 oncomplete: function(r) {
913 var rec = r.recv().content();
914 if(e = openils.Event.parse(rec))
916 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
924 //------------------------------------------------------------
927 // attribute-editor global variables
929 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
930 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
931 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
933 function vlAttrEditorInit() {
934 // set up tooltips on the edit form
935 connectTooltip('attr-editor-tags');
936 connectTooltip('attr-editor-subfields');
939 function vlShowAttrEditor() {
940 displayGlobalDiv('vl-attr-editor-div');
941 loadAttrEditorGrid();
942 idHide('vl-generic-progress');
945 function setAttrEditorGroup(groupName) {
946 // put us into 'bib'-attr or 'auth'-attr mode.
947 if (ATTR_EDIT_GROUP != groupName) {
948 ATTR_EDIT_GROUP = groupName;
949 loadAttrEditorGrid();
953 function onAttrEditorOpen() {
954 // the "bars" have the create/update/cancel/etc. buttons.
955 var create_bar = document.getElementById('attr-editor-create-bar');
956 var update_bar = document.getElementById('attr-editor-update-bar');
957 if (ATTR_EDITOR_IN_UPDATE_MODE) {
958 update_bar.style.display='table-row';
959 create_bar.style.display='none';
960 // hide the dropdown-button
961 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
963 dijit.byId('attr-editor-dialog').reset();
964 create_bar.style.display='table-row';
965 update_bar.style.display='none';
969 function onAttrEditorClose() {
970 // reset the form to a "create" form. (We may have borrowed it for editing.)
971 ATTR_EDITOR_IN_UPDATE_MODE = false;
972 // show the dropdown-button
973 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
976 function loadAttrEditorGrid() {
977 var _data = (ATTR_EDIT_GROUP == 'auth') ?
978 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
980 var store = new dojo.data.ItemFileReadStore({data:_data});
981 attrEditorGrid.setStore(store);
982 dojo.connect(attrEditorGrid, 'onRowDblClick', onAttrEditorClick);
983 attrEditorGrid.update();
986 function attrGridGetTag(n, item) {
987 // grid helper: return the tags from the row's xpath column.
988 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
991 function attrGridGetSubfield(n, item) {
992 // grid helper: return the subfields from the row's xpath column.
993 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
996 function onAttrEditorClick() {
997 var row = this.getItem(this.focus.rowIndex);
998 ATTR_EDIT_ID = this.store.getValue(row, 'id');
999 ATTR_EDITOR_IN_UPDATE_MODE = true;
1001 // populate the popup editor.
1002 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1003 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1004 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1005 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1006 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1007 dijit.byId('attr-editor-identifier').attr('value', this.store.getValue(row, 'ident'));
1008 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1009 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1011 // set up UI for editing
1012 dojo.byId('vl-create-attr-editor-button').click();
1015 function vlSaveAttrDefinition(data) {
1016 idHide('vl-attr-editor-div');
1017 idShow('vl-generic-progress');
1019 data.id = ATTR_EDIT_ID;
1021 // this ought to honour custom xpaths, but overwrite xpaths
1022 // derived from tags/subfields.
1023 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1024 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1025 data.xpath = _xpath;
1028 // build up our permacrud params. Key variables here are
1029 // "create or update" and "bib or auth".
1031 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1032 var isCreate = (ATTR_EDIT_ID == null);
1033 var rad = isAuth ? new vqarad() : new vqbrad() ;
1034 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1035 + (isAuth ? 'vqarad' : 'vqbrad');
1036 var _data = rad.fromStoreItem(data);
1040 fieldmapper.standardRequest(
1041 ['open-ils.permacrud', method],
1043 params: [authtoken, _data ],
1044 onresponse: function(r) { },
1045 oncomplete: function(r) {
1046 attrEditorFetchAttrDefs(vlShowAttrEditor);
1047 ATTR_EDIT_ID = null;
1049 onerror: function(r) {
1050 alert('vlSaveAttrDefinition comms error: ' + r);
1056 function attrEditorFetchAttrDefs(callback) {
1057 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1058 return fn(callback);
1061 function vlAttrDelete() {
1062 idHide('vl-attr-editor-div');
1063 idShow('vl-generic-progress');
1065 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1066 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1067 var rad = isAuth ? new vqarad() : new vqbrad() ;
1068 fieldmapper.standardRequest(
1069 ['open-ils.permacrud', method],
1071 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1072 oncomplete: function() {
1073 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1074 attrEditorFetchAttrDefs(vlShowAttrEditor);
1075 ATTR_EDIT_ID = null;
1077 onerror: function(r) {
1078 alert('vlAttrDelete comms error: ' + r);
1084 // ------------------------------------------------------------
1085 // utilities for attribute editors
1087 // dom utilities (maybe dojo does these, and these should be replaced)
1089 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1090 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1091 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1093 function connectTooltip(fieldId) {
1094 // Given an element id, look up a tooltip element in the doc (same
1095 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1096 // a better way to do this?
1097 var fld = dojo.byId(fieldId);
1098 var tip = dojo.byId(fieldId + '-tip');
1099 dojo.connect(fld, 'onfocus', function(evt) {
1100 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1101 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1106 var xpathParser = new openils.MarcXPathParser();
1108 function tagAndSubFieldsToXpath(tags, subfields) {
1109 // given tags, and subfields, build up an XPath.
1112 'tags':tags.match(/[\d]+/g),
1113 'subfields':subfields.match(/[a-zA-z]/g) };
1114 return xpathParser.compile(parts);
1116 return {'parts':null, 'tags':null, 'error':err};
1120 function looksLikeDerivedXpath(path) {
1121 // Does this path look like it was derived from tags and subfields?
1122 var parsed = xpathParser.parse(path);
1123 if (parsed.tags == null)
1125 var compiled = xpathParser.compile(parsed);
1126 return (path == compiled);
1129 // amazing xpath-util unit-tests
1130 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1131 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');