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("fieldmapper.OrgUtils");
36 dojo.require('openils.CGI');
37 dojo.require('openils.User');
38 dojo.require('openils.Event');
39 dojo.require('openils.Util');
40 dojo.require('openils.MarcXPathParser');
41 dojo.require('openils.widget.GridColumnPicker');
42 dojo.require('openils.PermaCrud');
46 'vl-generic-progress',
47 'vl-generic-progress-with-total',
52 'vl-queue-select-div',
53 'vl-marc-upload-status-div',
59 var VANDELAY_URL = '/vandelay-upload';
61 var authAttrDefs = [];
62 var queuedRecords = [];
63 var queuedRecordsMap = {};
64 var bibAttrsFetched = false;
65 var authAttrsFetched = false;
66 var attrDefMap = {}; // maps attr def code names to attr def ids
68 var currentQueueId = null;
70 var currentMatchedRecords; // set of loaded matched bib records
71 var currentOverlayRecordsMap; // map of import record to overlay record
72 var currentOverlayRecordsMapGid; // map of import record to overlay record grid id
73 var currentImportRecId; // when analyzing matches, this is the current import record
74 var userBibQueues = []; // only non-complete queues
75 var userAuthQueues = []; // only non-complete queues
77 var allUserAuthQueues;
78 var selectableGridRecords;
79 var cgi = new openils.CGI();
80 var vlQueueGridColumePicker = {};
81 var vlBibSources = [];
82 var importItemDefs = [];
88 authtoken = openils.User.authtoken;
89 var initNeeded = 6; // how many async responses do we need before we're init'd
90 var initCount = 0; // how many async reponses we've received
92 openils.Util.registerEnterHandler(
93 vlQueueDisplayPage.domNode, function(){retrieveQueuedRecords();});
94 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
96 function checkInitDone() {
98 if(initCount == initNeeded)
102 // Fetch the bib and authority attribute definitions
103 vlFetchBibAttrDefs(function () { checkInitDone(); });
104 vlFetchAuthAttrDefs(function () { checkInitDone(); });
106 vlRetrieveQueueList('bib', null,
108 allUserBibQueues = list;
109 for(var i = 0; i < allUserBibQueues.length; i++) {
110 if(allUserBibQueues[i].complete() == 'f')
111 userBibQueues.push(allUserBibQueues[i]);
117 vlRetrieveQueueList('auth', null,
119 allUserAuthQueues = list;
120 for(var i = 0; i < allUserAuthQueues.length; i++) {
121 if(allUserAuthQueues[i].complete() == 'f')
122 userAuthQueues.push(allUserAuthQueues[i]);
128 fieldmapper.standardRequest(
129 ['open-ils.permacrud', 'open-ils.permacrud.search.cbs.atomic'],
131 params: [authtoken, {id:{"!=":null}}, {order_by:{cbs:'id'}}],
132 oncomplete : function(r) {
133 vlBibSources = openils.Util.readResponse(r, false, true);
139 var owner = fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(new openils.User().user.ws_ou()));
140 new openils.PermaCrud().search('viiad',
141 {owner: owner.map(function(org) { return org.id(); })},
143 oncomplete: function(r) {
144 importItemDefs = openils.Util.readResponse(r);
154 openils.Util.addOnLoad(vlInit);
157 // fetch the bib and authority attribute definitions
159 function vlFetchBibAttrDefs(postcomplete) {
161 fieldmapper.standardRequest(
162 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
164 params: [authtoken, {id:{'!=':null}}],
165 onresponse: function(r) {
166 var def = r.recv().content();
167 if(e = openils.Event.parse(def[0]))
169 bibAttrDefs.push(def);
171 oncomplete: function() {
172 bibAttrDefs = bibAttrDefs.sort(
174 if(a.id() > b.id()) return 1;
175 if(a.id() < b.id()) return -1;
185 function vlFetchAuthAttrDefs(postcomplete) {
187 fieldmapper.standardRequest(
188 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
190 params: [authtoken, {id:{'!=':null}}],
191 onresponse: function(r) {
192 var def = r.recv().content();
193 if(e = openils.Event.parse(def[0]))
195 authAttrDefs.push(def);
197 oncomplete: function() {
198 authAttrDefs = authAttrDefs.sort(
200 if(a.id() > b.id()) return 1;
201 if(a.id() < b.id()) return -1;
211 function vlRetrieveQueueList(type, filter, onload) {
212 type = (type == 'bib') ? type : 'authority';
213 fieldmapper.standardRequest(
214 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.owner.retrieve.atomic'],
216 params: [authtoken, null, filter],
217 oncomplete: function(r) {
218 var list = r.recv().content();
219 if(e = openils.Event.parse(list[0]))
228 function displayGlobalDiv(id) {
229 for(var i = 0; i < globalDivs.length; i++) {
231 dojo.style(dojo.byId(globalDivs[i]), 'display', 'none');
233 alert('please define div ' + globalDivs[i]);
236 dojo.style(dojo.byId(id),'display','block');
238 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
239 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
240 openils.Util.removeCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
241 openils.Util.removeCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
244 case 'vl-marc-export-div':
245 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
247 case 'vl-marc-upload-div':
248 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
250 case 'vl-queue-select-div':
251 openils.Util.addCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
253 case 'vl-attr-editor-div':
254 openils.Util.addCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
259 function runStartupCommands() {
260 currentQueueId = cgi.param('qid');
261 currentType = cgi.param('qtype');
262 dojo.style('vl-nav-bar', 'visibility', 'visible');
264 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
269 * asynchronously upload a file of MARC records
271 function uploadMARC(onload){
272 dojo.byId('vl-upload-status-count').innerHTML = '0';
273 dojo.byId('vl-ses-input').value = authtoken;
274 displayGlobalDiv('vl-marc-upload-status-div');
275 dojo.io.iframe.send({
279 form: dojo.byId('vl-marc-upload-form'),
280 handle: function(data,ioArgs){
281 var content = data.documentElement.textContent;
288 * Creates a new vandelay queue
290 function createQueue(queueName, type, onload, importDefId) {
291 var name = (type=='bib') ? 'bib' : 'authority';
292 var method = 'open-ils.vandelay.'+ name +'_queue.create'
293 fieldmapper.standardRequest(
294 ['open-ils.vandelay', method],
296 params: [authtoken, queueName, null, name, importDefId],
297 oncomplete : function(r) {
298 var queue = r.recv().content();
299 if(e = openils.Event.parse(queue))
308 * Tells vandelay to pull a batch of records from the cache and explode them
309 * out into the vandelay tables
311 function processSpool(key, queueId, type, onload) {
312 fieldmapper.standardRequest(
313 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
315 params: [authtoken, key, queueId],
316 onresponse : function(r) {
317 var resp = r.recv().content();
318 if(e = openils.Event.parse(resp))
320 dojo.byId('vl-upload-status-count').innerHTML = resp;
322 oncomplete : function(r) {onload();}
327 function retrieveQueuedRecords(type, queueId, onload) {
328 displayGlobalDiv('vl-generic-progress');
330 queuedRecordsMap = {};
331 currentOverlayRecordsMap = {};
332 currentOverlayRecordsMapGid = {};
333 selectableGridRecords = {};
334 //resetVlQueueGridLayout();
336 if(!type) type = currentType;
337 if(!queueId) queueId = currentQueueId;
338 if(!onload) onload = handleRetrieveRecords;
340 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve.atomic';
341 if(vlQueueGridShowMatches.checked)
342 method = method.replace('records', 'records.matches');
344 var sel = dojo.byId('vl-queue-display-limit-selector');
345 var limit = parseInt(sel.options[sel.selectedIndex].value);
346 var offset = limit * parseInt(vlQueueDisplayPage.attr('value')-1);
348 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit}];
349 if(vlQueueGridShowNonImport.checked)
350 params[2].non_imported = 1;
352 fieldmapper.standardRequest(
353 ['open-ils.vandelay', method],
357 onresponse: function(r) {
358 console.log("ONREPONSE");
359 var rec = r.recv().content();
360 if(e = openils.Event.parse(rec))
362 console.log("got record " + rec.id());
363 queuedRecords.push(rec);
364 queuedRecordsMap[rec.id()] = rec;
367 oncomplete: function(r){
368 var recs = r.recv().content();
369 if(e = openils.Event.parse(recs[0]))
371 for(var i = 0; i < recs.length; i++) {
373 queuedRecords.push(rec);
374 queuedRecordsMap[rec.id()] = rec;
382 function vlLoadMatchUI(recId) {
383 displayGlobalDiv('vl-generic-progress');
384 var matches = queuedRecordsMap[recId].matches();
386 currentImportRecId = recId;
387 for(var i = 0; i < matches.length; i++)
388 records.push(matches[i].eg_record());
390 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
391 var params = [records];
392 if(currentType == 'auth') {
393 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
394 parmas = [authtoken, records, {clear_marc:1}];
397 fieldmapper.standardRequest(
401 oncomplete: function(r) {
402 var recs = r.recv().content();
403 if(e = openils.Event.parse(recs))
407 displayGlobalDiv('vl-match-div');
408 resetVlMatchGridLayout();
409 currentMatchedRecords = recs;
410 vlMatchGrid.setStructure(vlMatchGridLayout);
412 // build the data store of records with match information
413 var dataStore = bre.toStoreData(recs, null,
414 {virtualFields:['dest_matchpoint', 'src_matchpoint', '_id']});
415 dataStore.identifier = '_id';
417 var matchSeenMap = {};
419 for(var i = 0; i < dataStore.items.length; i++) {
420 var item = dataStore.items[i];
421 item._id = i; // just need something unique
422 for(var j = 0; j < matches.length; j++) {
423 var match = matches[j];
424 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
425 item.dest_matchpoint = match.field_type();
426 var attr = getRecAttrFromMatch(queuedRecordsMap[recId], match);
427 item.src_matchpoint = getRecAttrDefFromAttr(attr, currentType).code();
428 matchSeenMap[match.id()] = 1;
434 // now populate the grid
435 vlPopulateMatchGrid(vlMatchGrid, dataStore);
441 function vlPopulateMatchGrid(grid, data) {
442 var store = new dojo.data.ItemFileReadStore({data:data});
443 grid.setStore(store);
447 function showMe(id) {
448 dojo.style(dojo.byId(id), 'display', 'block');
450 function hideMe(id) {
451 dojo.style(dojo.byId(id), 'display', 'none');
455 function vlLoadMARCHtml(recId, inCat, oncomplete) {
456 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
457 displayGlobalDiv('vl-generic-progress');
459 var params = [recId, 1];
462 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
463 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
464 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
465 if(currentType == 'auth')
466 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
468 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
469 dijit.byId('vl-marc-html-edit-button').onClick =
470 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
471 params = [authtoken, recId];
472 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
473 if(currentType == 'auth')
474 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
477 fieldmapper.standardRequest(
481 oncomplete: function(r) {
482 displayGlobalDiv('vl-marc-html-div');
483 var html = r.recv().content();
484 dojo.byId('vl-marc-record-html').innerHTML = html;
492 function getRecMatchesFromAttrCode(rec, attrCode) {
494 var attr = getRecAttrFromCode(rec, attrCode);
495 for(var j = 0; j < rec.matches().length; j++) {
496 var match = rec.matches()[j];
497 if(match.matched_attr() == attr.id())
504 function getRecAttrFromMatch(rec, match) {
505 for(var i = 0; i < rec.attributes().length; i++) {
506 var attr = rec.attributes()[i];
507 if(attr.id() == match.matched_attr())
512 function getRecAttrDefFromAttr(attr, type) {
513 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
514 for(var i = 0; i < defs.length; i++) {
516 if(def.id() == attr.field())
521 function getRecAttrFromCode(rec, attrCode) {
522 var defId = attrDefMap[currentType][attrCode];
523 var attrs = rec.attributes();
524 for(var i = 0; i < attrs.length; i++) {
526 if(attr.field() == defId)
532 function vlGetViewMatches(rowIdx, item) {
534 var id = this.grid.store.getValue(item, 'id');
535 var rec = queuedRecordsMap[id];
536 if(rec.matches().length > 0)
542 function vlFormatViewMatches(id) {
543 if(id == -1) return '';
544 return '<a href="javascript:void(0);" onclick="vlLoadMatchUI(' + id + ');">' + this.name + '</a>';
547 function vlFormatViewMatchMARC(id) {
548 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
549 'function(){displayGlobalDiv(\'vl-match-div\');});">' + this.name + '</a>';
552 function getAttrValue(rowIdx, item) {
554 var attrCode = this.field.split('.')[1];
555 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
556 var attr = getRecAttrFromCode(rec, attrCode);
557 return (attr) ? attr.attr_value() : '';
560 function vlGetDateTimeField(rowIdx, item) {
562 var value = this.grid.store.getValue(item, this.field);
563 if(!value) return '';
564 var date = dojo.date.stamp.fromISOString(value);
565 return dojo.date.locale.format(date, {selector:'date'});
568 function vlGetCreator(rowIdx, item) {
570 var id = this.grid.store.getValue(item, 'creator');
572 return userCache[id].usrname();
573 var user = fieldmapper.standardRequest(
574 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
575 if(e = openils.Event.parse(user))
577 userCache[id] = user;
578 return user.usrname();
581 function vlGetViewMARC(rowIdx, item) {
582 return item && this.grid.store.getValue(item, 'id');
585 function vlFormatViewMARC(id) {
586 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
587 'function(){displayGlobalDiv(\'vl-queue-div\');});">' + this.name + '</a>';
590 function vlGetOverlayTargetSelector(rowIdx, item) {
592 return this.grid.store.getValue(item, '_id') + ':' + this.grid.store.getValue(item, 'id');
595 function vlFormatOverlayTargetSelector(val) {
597 var parts = val.split(':');
600 var value = '<input type="checkbox" name="vl-overlay-target-RECID" '+
601 'onclick="vlHandleOverlayTargetSelected(ID, GRIDID);" gridid="GRIDID" match="ID"/>';
602 value = value.replace(/GRIDID/g, _id);
603 value = value.replace(/RECID/g, currentImportRecId);
604 value = value.replace(/ID/g, id);
605 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
606 return value.replace('/>', 'checked="checked"/>');
612 * see if the user has enabled overlays for the current match set and,
613 * if so, map the current import record to the overlay target.
615 function vlHandleOverlayTargetSelected(recId, gridId) {
616 var noneSelected = true;
617 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
618 for(var i = 0; i < checkboxes.length; i++) {
619 var checkbox = checkboxes[i];
620 var matchRecId = checkbox.getAttribute('match');
621 var gid = checkbox.getAttribute('gridid');
622 if(checkbox.checked) {
623 if(matchRecId == recId && gid == gridId) {
624 noneSelected = false;
625 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
626 currentOverlayRecordsMapGid[currentImportRecId] = gid;
627 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
628 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
630 checkbox.checked = false;
636 delete currentOverlayRecordsMap[currentImportRecId];
637 delete currentOverlayRecordsMapGid[currentImportRecId];
638 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
639 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
643 var valLastQueueType = null;
644 var vlQueueGridLayout = null;
645 function buildRecordGrid(type) {
646 displayGlobalDiv('vl-queue-div');
649 openils.Util.show('vl-bib-queue-grid-wrapper');
650 openils.Util.hide('vl-auth-queue-grid-wrapper');
651 vlQueueGrid = vlBibQueueGrid;
653 openils.Util.show('vl-auth-queue-grid-wrapper');
654 openils.Util.hide('vl-bib-queue-grid-wrapper');
655 vlQueueGrid = vlAuthQueueGrid;
659 if(valLastQueueType != type) {
660 valLastQueueType = type;
661 vlQueueGridLayout = vlQueueGrid.attr('structure');
662 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
663 attrDefMap[type] = {};
664 for(var i = 0; i < defs.length; i++) {
666 attrDefMap[type][def.code()] = def.id();
668 name:def.description(),
669 field:'attr.' + def.code(),
671 selectableColumn:true
673 vlQueueGridLayout[0].cells[0].push(col);
677 dojo.forEach(vlQueueGridLayout[0].cells[0],
679 if(cell.field.match(/^\+/))
680 cell.nonSelectable=true;
686 storeData = vqbr.toStoreData(queuedRecords);
688 storeData = vqar.toStoreData(queuedRecords);
690 var store = new dojo.data.ItemFileReadStore({data:storeData});
691 vlQueueGrid.setStore(store);
693 if(vlQueueGridColumePicker[type]) {
694 vlQueueGrid.update();
697 vlQueueGridColumePicker[type] =
698 new openils.widget.GridColumnPicker(
699 authtoken, 'vandelay.queue.'+type, vlQueueGrid, vlQueueGridLayout);
700 vlQueueGridColumePicker[type].load();
704 function vlQueueGridPrevPage() {
705 var page = parseInt(vlQueueDisplayPage.getValue());
707 vlQueueDisplayPage.setValue(page - 1);
708 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
711 function vlQueueGridNextPage() {
712 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
713 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
716 function vlDeleteQueue(type, queueId, onload) {
717 fieldmapper.standardRequest(
718 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
720 params: [authtoken, queueId],
721 oncomplete: function(r) {
722 var resp = r.recv().content();
723 if(e = openils.Event.parse(resp))
732 function vlQueueGridDrawSelectBox(rowIdx, item) {
733 return item && this.grid.store.getValue(item, 'id');
736 function vlQueueGridFormatSelectBox(id) {
737 var domId = 'vl-record-list-selected-' + id;
738 if (id) { selectableGridRecords[domId] = id; }
739 return "<div><input type='checkbox' id='"+domId+"'/></div>";
742 function vlSelectAllQueueGridRecords() {
743 for(var id in selectableGridRecords)
744 dojo.byId(id).checked = true;
746 function vlSelectNoQueueGridRecords() {
747 for(var id in selectableGridRecords)
748 dojo.byId(id).checked = false;
750 function vlToggleQueueGridSelect() {
751 if(dojo.byId('vl-queue-grid-row-selector').checked)
752 vlSelectAllQueueGridRecords();
754 vlSelectNoQueueGridRecords();
757 var handleRetrieveRecords = function() {
758 buildRecordGrid(currentType);
759 vlFetchQueueSummary(currentQueueId, currentType,
761 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
762 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
763 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
768 function vlFetchQueueSummary(qId, type, onload) {
769 fieldmapper.standardRequest(
770 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
772 params: [authtoken, qId],
773 oncomplete : function(r) {
774 var summary = r.recv().content();
775 if(e = openils.Event.parse(summary))
777 return onload(summary);
784 function vlImportSelectedRecords() {
785 displayGlobalDiv('vl-generic-progress-with-total');
788 for(var id in selectableGridRecords) {
789 if(dojo.byId(id).checked) {
790 var recId = selectableGridRecords[id];
791 var rec = queuedRecordsMap[recId];
792 if(!rec.import_time())
797 fieldmapper.standardRequest(
798 ['open-ils.vandelay', 'open-ils.vandelay.'+currentType+'_record.list.import'],
800 params: [authtoken, records, {overlay_map:currentOverlayRecordsMap}],
801 onresponse: function(r) {
802 var resp = r.recv().content();
803 if(e = openils.Event.parse(resp))
806 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
808 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
815 function vlImportAllRecords() {
816 vlImportRecordQueue(currentType, currentQueueId, false,
817 function(){displayGlobalDiv('vl-queue-div');});
820 function vlImportRecordQueue(type, queueId, noMatchOnly, onload) {
821 displayGlobalDiv('vl-generic-progress-with-total');
822 var method = 'open-ils.vandelay.bib_queue.import';
824 method = method.replace('import', 'nomatch.import');
826 method = method.replace('bib', 'auth');
829 if(vlUploadQueueAutoOverlayExact.checked) {
830 options.auto_overlay_exact = true;
831 vlUploadQueueAutoOverlayExact.checked = false;
834 fieldmapper.standardRequest(
835 ['open-ils.vandelay', method],
837 params: [authtoken, queueId, options],
838 onresponse: function(r) {
839 var resp = r.recv().content();
840 if(e = openils.Event.parse(resp))
842 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
844 oncomplete: function() {onload();}
850 function vlImportHoldings(queueId, importProfile, onload) {
851 displayGlobalDiv('vl-generic-progress-with-total');
852 fieldmapper.standardRequest(
853 ['open-ils.vandelay', 'open-ils.vandelay.bib_record.queue.asset.import'],
855 params: [authtoken, importProfile, queueId],
856 onresponse: function(r) {
857 var resp = openils.Util.readResponse(r);
858 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
860 oncomplete: function() {onload();}
866 * Create queue, upload MARC, process spool, load the newly created queue
868 function batchUpload() {
869 var queueName = dijit.byId('vl-queue-name').getValue();
870 currentType = dijit.byId('vl-record-type').getValue();
872 var handleProcessSpool = function() {
873 if(vlUploadQueueAutoImport.checked || vlUploadQueueAutoOverlayExact.checked) {
878 vlUploadQueueAutoImport.checked,
880 if(vlUploadQueueHoldingsImport.checked) {
883 vlUploadQueueHoldingsImportProfile.attr('value'),
885 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
889 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
894 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
898 var handleUploadMARC = function(key) {
899 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
900 processSpool(key, currentQueueId, currentType, handleProcessSpool);
903 var handleCreateQueue = function(queue) {
904 currentQueueId = queue.id();
905 uploadMARC(handleUploadMARC);
908 if(vlUploadQueueSelector.getValue() && !queueName) {
909 currentQueueId = vlUploadQueueSelector.getValue();
910 uploadMARC(handleUploadMARC);
912 createQueue(queueName, currentType, handleCreateQueue, vlUploadQueueHoldingsImportProfile.attr('value'));
917 function vlFleshQueueSelect(selector, type) {
918 var data = (type == 'bib') ? vbq.toStoreData(allUserBibQueues) : vaq.toStoreData(allUserAuthQueues);
919 selector.store = new dojo.data.ItemFileReadStore({data:data});
920 selector.setValue(null);
921 selector.setDisplayedValue('');
923 selector.setValue(data[0].id());
926 function vlShowUploadForm() {
927 displayGlobalDiv('vl-marc-upload-div');
928 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
929 vlUploadSourceSelector.store =
930 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
931 vlUploadSourceSelector.setValue(vlBibSources[0].id());
932 vlUploadQueueHoldingsImportProfile.store =
933 new dojo.data.ItemFileReadStore({data:viiad.toStoreData(importItemDefs)});
934 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
935 dojo.connect(vlUploadQueueHoldingsImport, 'onChange',
938 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
940 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
945 function vlShowQueueSelect() {
946 displayGlobalDiv('vl-queue-select-div');
947 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
950 function vlFetchQueueFromForm() {
951 currentType = vlQueueSelectType.getValue();
952 currentQueueId = vlQueueSelectQueueList.getValue();
953 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
956 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
958 To run in Firefox directly, must set signed.applets.codebase_principal_support
959 to true in about:config
961 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
962 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
965 // after the record is saved, reload the HTML display
966 var stat = r.recv().content();
967 if(e = openils.Event.parse(stat))
969 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
971 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
975 record : {marc : rec.marc()},
977 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
978 func: function(xmlString) {
979 var method = 'open-ils.permacrud.update.' + rec.classname;
981 fieldmapper.standardRequest(
982 ['open-ils.permacrud', method],
984 params: [authtoken, rec],
993 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
994 var method = 'open-ils.permacrud.search.vqbr';
995 if(currentType != 'bib')
996 method = method.replace(/vqbr/,'vqar');
998 fieldmapper.standardRequest(
999 ['open-ils.permacrud', method],
1001 params: [authtoken, {id : recId}],
1002 oncomplete: function(r) {
1003 var rec = r.recv().content();
1004 if(e = openils.Event.parse(rec))
1006 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
1014 //------------------------------------------------------------
1015 // attribute editors
1017 // attribute-editor global variables
1019 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
1020 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
1021 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
1023 function vlAttrEditorInit() {
1024 // set up tooltips on the edit form
1025 connectTooltip('attr-editor-tags');
1026 connectTooltip('attr-editor-subfields');
1029 function vlShowAttrEditor() {
1030 displayGlobalDiv('vl-attr-editor-div');
1031 loadAttrEditorGrid();
1032 idHide('vl-generic-progress');
1035 function setAttrEditorGroup(groupName) {
1036 // put us into 'bib'-attr or 'auth'-attr mode.
1037 if (ATTR_EDIT_GROUP != groupName) {
1038 ATTR_EDIT_GROUP = groupName;
1039 loadAttrEditorGrid();
1043 function onAttrEditorOpen() {
1044 // the "bars" have the create/update/cancel/etc. buttons.
1045 var create_bar = document.getElementById('attr-editor-create-bar');
1046 var update_bar = document.getElementById('attr-editor-update-bar');
1047 if (ATTR_EDITOR_IN_UPDATE_MODE) {
1048 update_bar.style.display='table-row';
1049 create_bar.style.display='none';
1050 // hide the dropdown-button
1051 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
1053 dijit.byId('attr-editor-dialog').reset();
1054 create_bar.style.display='table-row';
1055 update_bar.style.display='none';
1059 function onAttrEditorClose() {
1060 // reset the form to a "create" form. (We may have borrowed it for editing.)
1061 ATTR_EDITOR_IN_UPDATE_MODE = false;
1062 // show the dropdown-button
1063 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
1066 function loadAttrEditorGrid() {
1067 var _data = (ATTR_EDIT_GROUP == 'auth') ?
1068 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
1070 var store = new dojo.data.ItemFileReadStore({data:_data});
1071 attrEditorGrid.setStore(store);
1072 dojo.connect(attrEditorGrid, 'onRowDblClick', onAttrEditorClick);
1073 attrEditorGrid.update();
1076 function attrGridGetTag(n, item) {
1077 // grid helper: return the tags from the row's xpath column.
1078 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
1081 function attrGridGetSubfield(n, item) {
1082 // grid helper: return the subfields from the row's xpath column.
1083 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
1086 function onAttrEditorClick() {
1087 var row = this.getItem(this.focus.rowIndex);
1088 ATTR_EDIT_ID = this.store.getValue(row, 'id');
1089 ATTR_EDITOR_IN_UPDATE_MODE = true;
1091 // populate the popup editor.
1092 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1093 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1094 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1095 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1096 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1097 dijit.byId('attr-editor-identifier').attr('value', this.store.getValue(row, 'ident'));
1098 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1099 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1101 // set up UI for editing
1102 dojo.byId('vl-create-attr-editor-button').click();
1105 function vlSaveAttrDefinition(data) {
1106 idHide('vl-attr-editor-div');
1107 idShow('vl-generic-progress');
1109 data.id = ATTR_EDIT_ID;
1111 // this ought to honour custom xpaths, but overwrite xpaths
1112 // derived from tags/subfields.
1113 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1114 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1115 data.xpath = _xpath;
1118 // build up our permacrud params. Key variables here are
1119 // "create or update" and "bib or auth".
1121 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1122 var isCreate = (ATTR_EDIT_ID == null);
1123 var rad = isAuth ? new vqarad() : new vqbrad() ;
1124 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1125 + (isAuth ? 'vqarad' : 'vqbrad');
1126 var _data = rad.fromStoreItem(data);
1130 fieldmapper.standardRequest(
1131 ['open-ils.permacrud', method],
1133 params: [authtoken, _data ],
1134 onresponse: function(r) { },
1135 oncomplete: function(r) {
1136 attrEditorFetchAttrDefs(vlShowAttrEditor);
1137 ATTR_EDIT_ID = null;
1139 onerror: function(r) {
1140 alert('vlSaveAttrDefinition comms error: ' + r);
1146 function attrEditorFetchAttrDefs(callback) {
1147 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1148 return fn(callback);
1151 function vlAttrDelete() {
1152 idHide('vl-attr-editor-div');
1153 idShow('vl-generic-progress');
1155 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1156 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1157 var rad = isAuth ? new vqarad() : new vqbrad() ;
1158 fieldmapper.standardRequest(
1159 ['open-ils.permacrud', method],
1161 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1162 oncomplete: function() {
1163 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1164 attrEditorFetchAttrDefs(vlShowAttrEditor);
1165 ATTR_EDIT_ID = null;
1167 onerror: function(r) {
1168 alert('vlAttrDelete comms error: ' + r);
1174 // ------------------------------------------------------------
1175 // utilities for attribute editors
1177 // dom utilities (maybe dojo does these, and these should be replaced)
1179 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1180 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1181 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1183 function connectTooltip(fieldId) {
1184 // Given an element id, look up a tooltip element in the doc (same
1185 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1186 // a better way to do this?
1187 var fld = dojo.byId(fieldId);
1188 var tip = dojo.byId(fieldId + '-tip');
1189 dojo.connect(fld, 'onfocus', function(evt) {
1190 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1191 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1196 var xpathParser = new openils.MarcXPathParser();
1198 function tagAndSubFieldsToXpath(tags, subfields) {
1199 // given tags, and subfields, build up an XPath.
1202 'tags':tags.match(/[\d]+/g),
1203 'subfields':subfields.match(/[a-zA-z]/g) };
1204 return xpathParser.compile(parts);
1206 return {'parts':null, 'tags':null, 'error':err};
1210 function looksLikeDerivedXpath(path) {
1211 // Does this path look like it was derived from tags and subfields?
1212 var parsed = xpathParser.parse(path);
1213 if (parsed.tags == null)
1215 var compiled = xpathParser.compile(parsed);
1216 return (path == compiled);
1219 // amazing xpath-util unit-tests
1220 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1221 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');