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("dijit.layout.ContentPane");
21 dojo.require("dijit.layout.TabContainer");
22 dojo.require("dijit.layout.LayoutContainer");
23 dojo.require('dijit.form.Button');
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.Grid");
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.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 = {};
84 authtoken = dojo.cookie('ses') || cgi.param('ses');
85 var initNeeded = 4; // how many async responses do we need before we're init'd
86 var initCount = 0; // how many async reponses we've received
88 openils.Util.registerEnterHandler(
89 vlQueueDisplayPage.domNode, function(){retrieveQueuedRecords();});
90 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
92 function checkInitDone() {
94 if(initCount == initNeeded)
98 // Fetch the bib and authority attribute definitions
99 vlFetchBibAttrDefs(function () { checkInitDone(); });
100 vlFetchAuthAttrDefs(function () { checkInitDone(); });
102 vlRetrieveQueueList('bib', null,
104 allUserBibQueues = list;
105 for(var i = 0; i < allUserBibQueues.length; i++) {
106 if(allUserBibQueues[i].complete() == 'f')
107 userBibQueues.push(allUserBibQueues[i]);
113 vlRetrieveQueueList('auth', null,
115 allUserAuthQueues = list;
116 for(var i = 0; i < allUserAuthQueues.length; i++) {
117 if(allUserAuthQueues[i].complete() == 'f')
118 userAuthQueues.push(allUserAuthQueues[i]);
128 dojo.addOnLoad(vlInit);
131 // fetch the bib and authority attribute definitions
133 function vlFetchBibAttrDefs(postcomplete) {
135 fieldmapper.standardRequest(
136 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
138 params: [authtoken, {id:{'!=':null}}],
139 onresponse: function(r) {
140 var def = r.recv().content();
141 if(e = openils.Event.parse(def[0]))
143 bibAttrDefs.push(def);
145 oncomplete: function() {
146 bibAttrDefs = bibAttrDefs.sort(
148 if(a.id() > b.id()) return 1;
149 if(a.id() < b.id()) return -1;
159 function vlFetchAuthAttrDefs(postcomplete) {
161 fieldmapper.standardRequest(
162 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
164 params: [authtoken, {id:{'!=':null}}],
165 onresponse: function(r) {
166 var def = r.recv().content();
167 if(e = openils.Event.parse(def[0]))
169 authAttrDefs.push(def);
171 oncomplete: function() {
172 authAttrDefs = authAttrDefs.sort(
174 if(a.id() > b.id()) return 1;
175 if(a.id() < b.id()) return -1;
185 function vlRetrieveQueueList(type, filter, onload) {
186 type = (type == 'bib') ? type : 'authority';
187 fieldmapper.standardRequest(
188 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.owner.retrieve.atomic'],
190 params: [authtoken, null, filter],
191 oncomplete: function(r) {
192 var list = r.recv().content();
193 if(e = openils.Event.parse(list[0]))
202 function displayGlobalDiv(id) {
203 for(var i = 0; i < globalDivs.length; i++) {
205 dojo.style(dojo.byId(globalDivs[i]), 'display', 'none');
207 alert('please define div ' + globalDivs[i]);
210 dojo.style(dojo.byId(id),'display','block');
212 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
213 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
214 openils.Util.removeCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
215 openils.Util.removeCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
218 case 'vl-marc-export-div':
219 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
221 case 'vl-marc-upload-div':
222 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
224 case 'vl-queue-select-div':
225 openils.Util.addCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
227 case 'vl-attr-editor-div':
228 openils.Util.addCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
233 function runStartupCommands() {
234 currentQueueId = cgi.param('qid');
235 currentType = cgi.param('qtype');
236 dojo.style('vl-nav-bar', 'visibility', 'visible');
238 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
243 * asynchronously upload a file of MARC records
245 function uploadMARC(onload){
246 dojo.byId('vl-upload-status-count').innerHTML = '0';
247 dojo.byId('vl-ses-input').value = authtoken;
248 displayGlobalDiv('vl-marc-upload-status-div');
249 dojo.io.iframe.send({
253 form: dojo.byId('vl-marc-upload-form'),
254 handle: function(data,ioArgs){
255 var content = data.documentElement.textContent;
262 * Creates a new vandelay queue
264 function createQueue(queueName, type, onload) {
265 var name = (type=='bib') ? 'bib' : 'authority';
266 var method = 'open-ils.vandelay.'+ name +'_queue.create'
267 fieldmapper.standardRequest(
268 ['open-ils.vandelay', method],
270 params: [authtoken, queueName, null, name],
271 oncomplete : function(r) {
272 var queue = r.recv().content();
273 if(e = openils.Event.parse(queue))
282 * Tells vandelay to pull a batch of records from the cache and explode them
283 * out into the vandelay tables
285 function processSpool(key, queueId, type, onload) {
286 fieldmapper.standardRequest(
287 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
289 params: [authtoken, key, queueId],
290 onresponse : function(r) {
291 var resp = r.recv().content();
292 if(e = openils.Event.parse(resp))
294 dojo.byId('vl-upload-status-count').innerHTML = resp;
296 oncomplete : function(r) {onload();}
301 function retrieveQueuedRecords(type, queueId, onload) {
302 displayGlobalDiv('vl-generic-progress');
304 queuedRecordsMap = {};
305 currentOverlayRecordsMap = {};
306 currentOverlayRecordsMapGid = {};
307 selectableGridRecords = {};
308 resetVlQueueGridLayout();
310 if(!type) type = currentType;
311 if(!queueId) queueId = currentQueueId;
312 if(!onload) onload = handleRetrieveRecords;
314 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve.atomic';
315 if(vlQueueGridShowMatches.checked)
316 method = method.replace('records', 'records.matches');
318 //var limit = parseInt(vlQueueDisplayLimit.getValue());
319 var sel = dojo.byId('vl-queue-display-limit-selector');
320 var limit = parseInt(sel.options[sel.selectedIndex].value);
321 var offset = limit * parseInt(vlQueueDisplayPage.getValue()-1);
323 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit}];
324 if(vlQueueGridShowNonImport.checked)
325 params[2].non_imported = 1;
327 fieldmapper.standardRequest(
328 ['open-ils.vandelay', method],
332 onresponse: function(r) {
333 console.log("ONREPONSE");
334 var rec = r.recv().content();
335 if(e = openils.Event.parse(rec))
337 console.log("got record " + rec.id());
338 queuedRecords.push(rec);
339 queuedRecordsMap[rec.id()] = rec;
342 oncomplete: function(r){
343 var recs = r.recv().content();
344 if(e = openils.Event.parse(recs[0]))
346 for(var i = 0; i < recs.length; i++) {
348 queuedRecords.push(rec);
349 queuedRecordsMap[rec.id()] = rec;
357 function vlLoadMatchUI(recId) {
358 displayGlobalDiv('vl-generic-progress');
359 var matches = queuedRecordsMap[recId].matches();
361 currentImportRecId = recId;
362 for(var i = 0; i < matches.length; i++)
363 records.push(matches[i].eg_record());
365 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
366 var params = [records];
367 if(currentType == 'auth') {
368 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
369 parmas = [authtoken, records, {clear_marc:1}];
372 fieldmapper.standardRequest(
376 oncomplete: function(r) {
377 var recs = r.recv().content();
378 if(e = openils.Event.parse(recs))
382 displayGlobalDiv('vl-match-div');
383 resetVlMatchGridLayout();
384 currentMatchedRecords = recs;
385 if(!vlMatchGrid.structure)
386 vlMatchGrid.setStructure(vlMatchGridLayout);
388 // build the data store of records with match information
389 var dataStore = bre.toStoreData(recs, null,
390 {virtualFields:['dest_matchpoint', 'src_matchpoint', '_id']});
391 dataStore.identifier = '_id';
393 var matchSeenMap = {};
395 for(var i = 0; i < dataStore.items.length; i++) {
396 var item = dataStore.items[i];
397 item._id = i; // just need something unique
398 for(var j = 0; j < matches.length; j++) {
399 var match = matches[j];
400 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
401 item.dest_matchpoint = match.field_type();
402 var attr = getRecAttrFromMatch(queuedRecordsMap[recId], match);
403 item.src_matchpoint = getRecAttrDefFromAttr(attr, currentType).code();
404 matchSeenMap[match.id()] = 1;
410 // now populate the grid
411 vlPopulateMatchGrid(vlMatchGrid, dataStore);
417 function vlPopulateMatchGrid(grid, data) {
418 var store = new dojo.data.ItemFileReadStore({data:data});
419 var model = new dojox.grid.data.DojoData(
420 null, store, {rowsPerPage: 100, clientSort: true, query:{id:'*'}});
421 grid.setModel(model);
425 function showMe(id) {
426 dojo.style(dojo.byId(id), 'display', 'block');
428 function hideMe(id) {
429 dojo.style(dojo.byId(id), 'display', 'none');
433 function vlLoadMARCHtml(recId, inCat, oncomplete) {
434 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
435 displayGlobalDiv('vl-generic-progress');
437 var params = [recId, 1];
440 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
441 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
442 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
443 if(currentType == 'auth')
444 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
446 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
447 dijit.byId('vl-marc-html-edit-button').onClick =
448 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
449 params = [authtoken, recId];
450 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
451 if(currentType == 'auth')
452 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
455 fieldmapper.standardRequest(
459 oncomplete: function(r) {
460 displayGlobalDiv('vl-marc-html-div');
461 var html = r.recv().content();
462 dojo.byId('vl-marc-record-html').innerHTML = html;
470 function getRecMatchesFromAttrCode(rec, attrCode) {
472 var attr = getRecAttrFromCode(rec, attrCode);
473 for(var j = 0; j < rec.matches().length; j++) {
474 var match = rec.matches()[j];
475 if(match.matched_attr() == attr.id())
482 function getRecAttrFromMatch(rec, match) {
483 for(var i = 0; i < rec.attributes().length; i++) {
484 var attr = rec.attributes()[i];
485 if(attr.id() == match.matched_attr())
490 function getRecAttrDefFromAttr(attr, type) {
491 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
492 for(var i = 0; i < defs.length; i++) {
494 if(def.id() == attr.field())
499 function getRecAttrFromCode(rec, attrCode) {
500 var defId = attrDefMap[currentType][attrCode];
501 var attrs = rec.attributes();
502 for(var i = 0; i < attrs.length; i++) {
504 if(attr.field() == defId)
510 function vlGetViewMatches(rowIdx) {
511 var data = this.grid.model.getRow(rowIdx);
513 var rec = queuedRecordsMap[data.id];
514 if(rec.matches().length > 0)
515 return this.value.replace('RECID', data.id);
519 function getAttrValue(rowIdx) {
520 var data = this.grid.model.getRow(rowIdx);
522 var attrCode = this.field.split('.')[1];
523 var rec = queuedRecordsMap[data.id];
524 var attr = getRecAttrFromCode(rec, attrCode);
525 return (attr) ? attr.attr_value() : '';
528 function vlGetDateTimeField(rowIdx) {
529 data = this.grid.model.getRow(rowIdx);
531 if(!data[this.field]) return '';
532 var date = dojo.date.stamp.fromISOString(data[this.field]);
533 return dojo.date.locale.format(date, {selector:'date'});
536 function vlGetCreator(rowIdx) {
537 data = this.grid.model.getRow(rowIdx);
539 var id = data.creator;
541 return userCache[id].usrname();
542 var user = fieldmapper.standardRequest(
543 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
544 if(e = openils.Event.parse(user))
546 userCache[id] = user;
547 return user.usrname();
550 function vlGetViewMARC(rowIdx) {
551 data = this.grid.model.getRow(rowIdx);
553 return this.value.replace('RECID', data.id);
556 function vlGetOverlayTargetSelector(rowIdx) {
557 data = this.grid.model.getRow(rowIdx);
559 var value = this.value.replace(/GRIDID/g, data._id);
560 value = value.replace(/RECID/g, currentImportRecId);
561 value = value.replace(/ID/g, data.id);
562 if(data._id == currentOverlayRecordsMapGid[currentImportRecId])
563 return value.replace('/>', 'checked="checked"/>');
569 * see if the user has enabled overlays for the current match set and,
570 * if so, map the current import record to the overlay target.
572 function vlHandleOverlayTargetSelected(recId, gridId) {
573 var noneSelected = true;
574 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
575 for(var i = 0; i < checkboxes.length; i++) {
576 var checkbox = checkboxes[i];
577 var matchRecId = checkbox.getAttribute('match');
578 var gid = checkbox.getAttribute('gridid');
579 if(checkbox.checked) {
580 if(matchRecId == recId && gid == gridId) {
581 noneSelected = false;
582 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
583 currentOverlayRecordsMapGid[currentImportRecId] = gid;
584 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
585 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
587 checkbox.checked = false;
593 delete currentOverlayRecordsMap[currentImportRecId];
594 delete currentOverlayRecordsMapGid[currentImportRecId];
595 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
596 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
600 var valLastQueueType = null;
601 function buildRecordGrid(type) {
602 displayGlobalDiv('vl-queue-div');
604 if(valLastQueueType != type) {
605 valLastQueueType = type;
606 resetVlQueueGridLayout();
607 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
608 attrDefMap[type] = {};
609 for(var i = 0; i < defs.length; i++) {
611 attrDefMap[type][def.code()] = def.id();
613 name:def.description(),
614 field:'attr.' + def.code(),
616 selectableColumn:true
618 vlQueueGridLayout[0].cells[0].push(col);
624 storeData = vqbr.toStoreData(queuedRecords);
626 storeData = vqar.toStoreData(queuedRecords);
628 var store = new dojo.data.ItemFileReadStore({data:storeData});
629 var model = new dojox.grid.data.DojoData(
630 null, store, {rowsPerPage: 100, clientSort: true, query:{id:'*'}});
631 vlQueueGrid.setModel(model);
634 if(vlQueueGridColumePicker[type]) {
635 vlQueueGrid.update();
637 vlQueueGridColumePicker[type] =
638 new openils.GridColumnPicker(vlQueueGridColumePickerDialog,
639 vlQueueGrid, vlQueueGridLayout, authtoken, 'vandelay.queue.'+type);
640 vlQueueGridColumePicker[type].load();
644 function vlQueueGridPrevPage() {
645 var page = parseInt(vlQueueDisplayPage.getValue());
647 vlQueueDisplayPage.setValue(page - 1);
648 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
651 function vlQueueGridNextPage() {
652 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
653 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
656 function vlDeleteQueue(type, queueId, onload) {
657 fieldmapper.standardRequest(
658 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
660 params: [authtoken, queueId],
661 oncomplete: function(r) {
662 var resp = r.recv().content();
663 if(e = openils.Event.parse(resp))
672 function vlQueueGridDrawSelectBox(rowIdx) {
673 var data = this.grid.model.getRow(rowIdx);
675 var domId = 'vl-record-list-selected-' +data.id;
676 selectableGridRecords[domId] = data.id;
677 return "<div><input type='checkbox' id='"+domId+"'/></div>";
680 function vlSelectAllQueueGridRecords() {
681 for(var id in selectableGridRecords)
682 dojo.byId(id).checked = true;
684 function vlSelectNoQueueGridRecords() {
685 for(var id in selectableGridRecords)
686 dojo.byId(id).checked = false;
688 function vlToggleQueueGridSelect() {
689 if(dojo.byId('vl-queue-grid-row-selector').checked)
690 vlSelectAllQueueGridRecords();
692 vlSelectNoQueueGridRecords();
695 var handleRetrieveRecords = function() {
696 buildRecordGrid(currentType);
697 vlFetchQueueSummary(currentQueueId, currentType,
699 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
700 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
701 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
706 function vlFetchQueueSummary(qId, type, onload) {
707 fieldmapper.standardRequest(
708 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
710 params: [authtoken, qId],
711 oncomplete : function(r) {
712 var summary = r.recv().content();
713 if(e = openils.Event.parse(summary))
715 return onload(summary);
722 function vlImportSelectedRecords() {
723 displayGlobalDiv('vl-generic-progress-with-total');
726 for(var id in selectableGridRecords) {
727 if(dojo.byId(id).checked) {
728 var recId = selectableGridRecords[id];
729 var rec = queuedRecordsMap[recId];
730 if(!rec.import_time())
735 fieldmapper.standardRequest(
736 ['open-ils.vandelay', 'open-ils.vandelay.'+currentType+'_record.list.import'],
738 params: [authtoken, records, {overlay_map:currentOverlayRecordsMap}],
739 onresponse: function(r) {
740 var resp = r.recv().content();
741 if(e = openils.Event.parse(resp))
744 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
746 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
753 function vlImportAllRecords() {
754 vlImportRecordQueue(currentType, currentQueueId, false,
755 function(){displayGlobalDiv('vl-queue-div');});
758 function vlImportRecordQueue(type, queueId, noMatchOnly, onload) {
759 displayGlobalDiv('vl-generic-progress-with-total');
760 var method = 'open-ils.vandelay.bib_queue.import';
762 method = method.replace('import', 'nomatch.import');
764 method = method.replace('bib', 'auth');
766 fieldmapper.standardRequest(
767 ['open-ils.vandelay', method],
769 params: [authtoken, queueId],
770 onresponse: function(r) {
771 var resp = r.recv().content();
772 if(e = openils.Event.parse(resp))
774 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
776 oncomplete: function() {onload();}
783 * Create queue, upload MARC, process spool, load the newly created queue
785 function batchUpload() {
786 var queueName = dijit.byId('vl-queue-name').getValue();
787 currentType = dijit.byId('vl-record-type').getValue();
789 var handleProcessSpool = function() {
790 console.log('records uploaded and spooled');
791 if(vlUploadQueueAutoImport.checked) {
792 vlImportRecordQueue(currentType, currentQueueId, true,
794 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
798 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
802 var handleUploadMARC = function(key) {
803 console.log('marc uploaded');
804 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
805 processSpool(key, currentQueueId, currentType, handleProcessSpool);
808 var handleCreateQueue = function(queue) {
809 console.log('queue created ' + queue.name());
810 currentQueueId = queue.id();
811 uploadMARC(handleUploadMARC);
814 if(vlUploadQueueSelector.getValue() && !queueName) {
815 currentQueueId = vlUploadQueueSelector.getValue();
816 console.log('adding records to existing queue ' + currentQueueId);
817 uploadMARC(handleUploadMARC);
819 createQueue(queueName, currentType, handleCreateQueue);
824 function vlFleshQueueSelect(selector, type) {
825 var data = (type == 'bib') ? vbq.toStoreData(allUserBibQueues) : vaq.toStoreData(allUserAuthQueues);
826 selector.store = new dojo.data.ItemFileReadStore({data:data});
827 selector.setValue(null);
828 selector.setDisplayedValue('');
830 selector.setValue(data[0].id());
833 function vlShowUploadForm() {
834 displayGlobalDiv('vl-marc-upload-div');
835 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
838 function vlShowQueueSelect() {
839 displayGlobalDiv('vl-queue-select-div');
840 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
843 function vlFetchQueueFromForm() {
844 currentType = vlQueueSelectType.getValue();
845 currentQueueId = vlQueueSelectQueueList.getValue();
846 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
849 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
851 To run in Firefox directly, must set signed.applets.codebase_principal_support
852 to true in about:config
854 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
855 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
858 // after the record is saved, reload the HTML display
859 var stat = r.recv().content();
860 if(e = openils.Event.parse(stat))
862 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
864 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
868 record : {marc : rec.marc()},
870 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
871 func: function(xmlString) {
872 var method = 'open-ils.permacrud.update.' + rec.classname;
874 fieldmapper.standardRequest(
875 ['open-ils.permacrud', method],
877 params: [authtoken, rec],
886 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
887 var method = 'open-ils.permacrud.search.vqbr';
888 if(currentType != 'bib')
889 method = method.replace(/vqbr/,'vqar');
891 fieldmapper.standardRequest(
892 ['open-ils.permacrud', method],
894 params: [authtoken, {id : recId}],
895 oncomplete: function(r) {
896 var rec = r.recv().content();
897 if(e = openils.Event.parse(rec))
899 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
907 //------------------------------------------------------------
910 // attribute-editor global variables
912 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
913 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
914 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
916 function vlAttrEditorInit() {
917 // set up tooltips on the edit form
918 connectTooltip('attr-editor-tags');
919 connectTooltip('attr-editor-subfields');
922 function vlShowAttrEditor() {
923 displayGlobalDiv('vl-attr-editor-div');
924 loadAttrEditorGrid();
925 idHide('vl-generic-progress');
928 function setAttrEditorGroup(groupName) {
929 // put us into 'bib'-attr or 'auth'-attr mode.
930 if (ATTR_EDIT_GROUP != groupName) {
931 ATTR_EDIT_GROUP = groupName;
932 loadAttrEditorGrid();
936 function onAttrEditorOpen() {
937 // the "bars" have the create/update/cancel/etc. buttons.
938 var create_bar = document.getElementById('attr-editor-create-bar');
939 var update_bar = document.getElementById('attr-editor-update-bar');
940 if (ATTR_EDITOR_IN_UPDATE_MODE) {
941 update_bar.style.display='table-row';
942 create_bar.style.display='none';
943 // hide the dropdown-button
944 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
946 dijit.byId('attr-editor-dialog').reset();
947 create_bar.style.display='table-row';
948 update_bar.style.display='none';
952 function onAttrEditorClose() {
953 // reset the form to a "create" form. (We may have borrowed it for editing.)
954 ATTR_EDITOR_IN_UPDATE_MODE = false;
955 // show the dropdown-button
956 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
959 function loadAttrEditorGrid() {
960 var _data = (ATTR_EDIT_GROUP == 'auth') ?
961 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
963 var store = new dojo.data.ItemFileReadStore({data:_data});
964 var model = new dojox.grid.data.DojoData(
965 null, store, {rowsPerPage: 100, clientSort: true, query:{id:'*'}});
966 attrEditorGrid.setModel(model);
967 attrEditorGrid.setStructure(vlAttrGridLayout);
968 attrEditorGrid.onRowClick = onAttrEditorClick;
969 attrEditorGrid.update();
972 function attrGridGetTag(n) {
973 // grid helper: return the tags from the row's xpath column.
974 var xp = this.grid.model.getRow(n);
975 return xp && xpathParser.parse(xp.xpath).tags;
978 function attrGridGetSubfield(n) {
979 // grid helper: return the subfields from the row's xpath column.
980 var xp = this.grid.model.getRow(n);
981 return xp && xpathParser.parse(xp.xpath).subfields;
984 function onAttrEditorClick(evt) {
985 var row = attrEditorGrid.model.getRow(evt.rowIndex);
986 ATTR_EDIT_ID = row.id;
987 ATTR_EDITOR_IN_UPDATE_MODE = true;
989 // populate the popup editor.
990 dojo.byId('attr-editor-code').value = row.code;
991 dojo.byId('attr-editor-description').value = row.description;
992 var parsed_xpath = xpathParser.parse(row.xpath);
993 dojo.byId('attr-editor-tags').value = parsed_xpath.tags;
994 dojo.byId('attr-editor-subfields').value = parsed_xpath.subfields;
995 dojo.byId('attr-editor-identifier').value = (row.ident ? 'True':'False');
996 dojo.byId('attr-editor-xpath').value = row.xpath;
997 dojo.byId('attr-editor-remove').value = row.remove;
999 // set up UI for editing
1000 dojo.byId('vl-create-attr-editor-button').click();
1003 function vlSaveAttrDefinition(data) {
1004 idHide('vl-attr-editor-div');
1005 idShow('vl-generic-progress');
1007 data.id = ATTR_EDIT_ID;
1009 // this ought to honour custom xpaths, but overwrite xpaths
1010 // derived from tags/subfields.
1011 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1012 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1013 data.xpath = _xpath;
1016 // build up our permacrud params. Key variables here are
1017 // "create or update" and "bib or auth".
1019 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1020 var isCreate = (ATTR_EDIT_ID == null);
1021 var rad = isAuth ? new vqarad() : new vqbrad() ;
1022 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1023 + (isAuth ? 'vqarad' : 'vqbrad');
1024 var _data = rad.fromStoreItem(data);
1028 fieldmapper.standardRequest(
1029 ['open-ils.permacrud', method],
1031 params: [authtoken, _data ],
1032 onresponse: function(r) { },
1033 oncomplete: function(r) {
1034 attrEditorFetchAttrDefs(vlShowAttrEditor);
1035 ATTR_EDIT_ID = null;
1037 onerror: function(r) {
1038 alert('vlSaveAttrDefinition comms error: ' + r);
1044 function attrEditorFetchAttrDefs(callback) {
1045 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1046 return fn(callback);
1049 function vlAttrDelete() {
1050 idHide('vl-attr-editor-div');
1051 idShow('vl-generic-progress');
1053 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1054 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1055 var rad = isAuth ? new vqarad() : new vqbrad() ;
1056 fieldmapper.standardRequest(
1057 ['open-ils.permacrud', method],
1059 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1060 oncomplete: function() {
1061 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1062 attrEditorFetchAttrDefs(vlShowAttrEditor);
1063 ATTR_EDIT_ID = null;
1065 onerror: function(r) {
1066 alert('vlAttrDelete comms error: ' + r);
1072 // ------------------------------------------------------------
1073 // utilities for attribute editors
1075 // dom utilities (maybe dojo does these, and these should be replaced)
1077 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1078 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1079 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1081 function connectTooltip(fieldId) {
1082 // Given an element id, look up a tooltip element in the doc (same
1083 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1084 // a better way to do this?
1085 var fld = dojo.byId(fieldId);
1086 var tip = dojo.byId(fieldId + '-tip');
1087 dojo.connect(fld, 'onfocus', function(evt) {
1088 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1089 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1094 var xpathParser = new openils.MarcXPathParser();
1096 function tagAndSubFieldsToXpath(tags, subfields) {
1097 // given tags, and subfields, build up an XPath.
1100 'tags':tags.match(/[\d]+/g),
1101 'subfields':subfields.match(/[a-zA-z]/g) };
1102 return xpathParser.compile(parts);
1104 return {'parts':null, 'tags':null, 'error':err};
1108 function looksLikeDerivedXpath(path) {
1109 // Does this path look like it was derived from tags and subfields?
1110 var parsed = xpathParser.parse(path);
1111 if (parsed.tags == null)
1113 var compiled = xpathParser.compile(parsed);
1114 return (path == compiled);
1117 // amazing xpath-util unit-tests
1118 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1119 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');