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');
43 dojo.require('openils.widget.OrgUnitFilteringSelect');
44 dojo.require('openils.widget.AutoGrid');
48 'vl-generic-progress',
49 'vl-generic-progress-with-total',
54 'vl-queue-select-div',
55 'vl-marc-upload-status-div',
58 'vl-profile-editor-div'
62 var VANDELAY_URL = '/vandelay-upload';
64 var authAttrDefs = [];
65 var queuedRecords = [];
66 var queuedRecordsMap = {};
67 var bibAttrsFetched = false;
68 var authAttrsFetched = false;
69 var attrDefMap = {}; // maps attr def code names to attr def ids
71 var currentQueueId = null;
73 var currentMatchedRecords; // set of loaded matched bib records
74 var currentOverlayRecordsMap; // map of import record to overlay record
75 var currentOverlayRecordsMapGid; // map of import record to overlay record grid id
76 var currentImportRecId; // when analyzing matches, this is the current import record
77 var userBibQueues = []; // only non-complete queues
78 var userAuthQueues = []; // only non-complete queues
80 var allUserAuthQueues;
81 var selectableGridRecords;
82 var cgi = new openils.CGI();
83 var vlQueueGridColumePicker = {};
84 var vlBibSources = [];
85 var importItemDefs = [];
91 authtoken = openils.User.authtoken;
92 var initNeeded = 6; // how many async responses do we need before we're init'd
93 var initCount = 0; // how many async reponses we've received
95 openils.Util.registerEnterHandler(
96 vlQueueDisplayPage.domNode, function(){retrieveQueuedRecords();});
97 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
99 function checkInitDone() {
101 if(initCount == initNeeded)
102 runStartupCommands();
105 // Fetch the bib and authority attribute definitions
106 vlFetchBibAttrDefs(function () { checkInitDone(); });
107 vlFetchAuthAttrDefs(function () { checkInitDone(); });
109 vlRetrieveQueueList('bib', null,
111 allUserBibQueues = list;
112 for(var i = 0; i < allUserBibQueues.length; i++) {
113 if(allUserBibQueues[i].complete() == 'f')
114 userBibQueues.push(allUserBibQueues[i]);
120 vlRetrieveQueueList('auth', null,
122 allUserAuthQueues = list;
123 for(var i = 0; i < allUserAuthQueues.length; i++) {
124 if(allUserAuthQueues[i].complete() == 'f')
125 userAuthQueues.push(allUserAuthQueues[i]);
131 fieldmapper.standardRequest(
132 ['open-ils.permacrud', 'open-ils.permacrud.search.cbs.atomic'],
134 params: [authtoken, {id:{"!=":null}}, {order_by:{cbs:'id'}}],
135 oncomplete : function(r) {
136 vlBibSources = openils.Util.readResponse(r, false, true);
142 var owner = fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(new openils.User().user.ws_ou()));
143 new openils.PermaCrud().search('viiad',
144 {owner: owner.map(function(org) { return org.id(); })},
146 oncomplete: function(r) {
147 importItemDefs = openils.Util.readResponse(r);
157 openils.Util.addOnLoad(vlInit);
160 // fetch the bib and authority attribute definitions
162 function vlFetchBibAttrDefs(postcomplete) {
164 fieldmapper.standardRequest(
165 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
167 params: [authtoken, {id:{'!=':null}}],
168 onresponse: function(r) {
169 var def = r.recv().content();
170 if(e = openils.Event.parse(def[0]))
172 bibAttrDefs.push(def);
174 oncomplete: function() {
175 bibAttrDefs = bibAttrDefs.sort(
177 if(a.id() > b.id()) return 1;
178 if(a.id() < b.id()) return -1;
188 function vlFetchAuthAttrDefs(postcomplete) {
190 fieldmapper.standardRequest(
191 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
193 params: [authtoken, {id:{'!=':null}}],
194 onresponse: function(r) {
195 var def = r.recv().content();
196 if(e = openils.Event.parse(def[0]))
198 authAttrDefs.push(def);
200 oncomplete: function() {
201 authAttrDefs = authAttrDefs.sort(
203 if(a.id() > b.id()) return 1;
204 if(a.id() < b.id()) return -1;
214 function vlRetrieveQueueList(type, filter, onload) {
215 type = (type == 'bib') ? type : 'authority';
216 fieldmapper.standardRequest(
217 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.owner.retrieve.atomic'],
219 params: [authtoken, null, filter],
220 oncomplete: function(r) {
221 var list = r.recv().content();
222 if(e = openils.Event.parse(list[0]))
231 function displayGlobalDiv(id) {
232 for(var i = 0; i < globalDivs.length; i++) {
234 dojo.style(dojo.byId(globalDivs[i]), 'display', 'none');
236 alert('please define div ' + globalDivs[i]);
239 dojo.style(dojo.byId(id),'display','block');
241 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
242 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
243 openils.Util.removeCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
244 openils.Util.removeCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
245 openils.Util.removeCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
248 case 'vl-marc-export-div':
249 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
251 case 'vl-marc-upload-div':
252 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
254 case 'vl-queue-select-div':
255 openils.Util.addCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
257 case 'vl-attr-editor-div':
258 openils.Util.addCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
260 case 'vl-profile-editor-div':
261 openils.Util.addCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
266 function runStartupCommands() {
267 currentQueueId = cgi.param('qid');
268 currentType = cgi.param('qtype');
269 dojo.style('vl-nav-bar', 'visibility', 'visible');
271 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
276 * asynchronously upload a file of MARC records
278 function uploadMARC(onload){
279 dojo.byId('vl-upload-status-count').innerHTML = '0';
280 dojo.byId('vl-ses-input').value = authtoken;
281 displayGlobalDiv('vl-marc-upload-status-div');
282 dojo.io.iframe.send({
286 form: dojo.byId('vl-marc-upload-form'),
287 handle: function(data,ioArgs){
288 var content = data.documentElement.textContent;
295 * Creates a new vandelay queue
297 function createQueue(queueName, type, onload, importDefId) {
298 var name = (type=='bib') ? 'bib' : 'authority';
299 var method = 'open-ils.vandelay.'+ name +'_queue.create'
300 fieldmapper.standardRequest(
301 ['open-ils.vandelay', method],
303 params: [authtoken, queueName, null, name, importDefId],
304 oncomplete : function(r) {
305 var queue = r.recv().content();
306 if(e = openils.Event.parse(queue))
315 * Tells vandelay to pull a batch of records from the cache and explode them
316 * out into the vandelay tables
318 function processSpool(key, queueId, type, onload) {
319 fieldmapper.standardRequest(
320 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
322 params: [authtoken, key, queueId],
323 onresponse : function(r) {
324 var resp = r.recv().content();
325 if(e = openils.Event.parse(resp))
327 dojo.byId('vl-upload-status-count').innerHTML = resp;
329 oncomplete : function(r) {onload();}
334 function retrieveQueuedRecords(type, queueId, onload) {
335 displayGlobalDiv('vl-generic-progress');
337 queuedRecordsMap = {};
338 currentOverlayRecordsMap = {};
339 currentOverlayRecordsMapGid = {};
340 selectableGridRecords = {};
341 //resetVlQueueGridLayout();
343 if(!type) type = currentType;
344 if(!queueId) queueId = currentQueueId;
345 if(!onload) onload = handleRetrieveRecords;
347 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve.atomic';
348 if(vlQueueGridShowMatches.checked)
349 method = method.replace('records', 'records.matches');
351 var sel = dojo.byId('vl-queue-display-limit-selector');
352 var limit = parseInt(sel.options[sel.selectedIndex].value);
353 var offset = limit * parseInt(vlQueueDisplayPage.attr('value')-1);
355 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit}];
356 if(vlQueueGridShowNonImport.checked)
357 params[2].non_imported = 1;
359 fieldmapper.standardRequest(
360 ['open-ils.vandelay', method],
364 onresponse: function(r) {
365 console.log("ONREPONSE");
366 var rec = r.recv().content();
367 if(e = openils.Event.parse(rec))
369 console.log("got record " + rec.id());
370 queuedRecords.push(rec);
371 queuedRecordsMap[rec.id()] = rec;
374 oncomplete: function(r){
375 var recs = r.recv().content();
376 if(e = openils.Event.parse(recs[0]))
378 for(var i = 0; i < recs.length; i++) {
380 queuedRecords.push(rec);
381 queuedRecordsMap[rec.id()] = rec;
389 function vlLoadMatchUI(recId) {
390 displayGlobalDiv('vl-generic-progress');
391 var matches = queuedRecordsMap[recId].matches();
393 currentImportRecId = recId;
394 for(var i = 0; i < matches.length; i++)
395 records.push(matches[i].eg_record());
397 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
398 var params = [records];
399 if(currentType == 'auth') {
400 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
401 parmas = [authtoken, records, {clear_marc:1}];
404 fieldmapper.standardRequest(
408 oncomplete: function(r) {
409 var recs = r.recv().content();
410 if(e = openils.Event.parse(recs))
414 displayGlobalDiv('vl-match-div');
415 resetVlMatchGridLayout();
416 currentMatchedRecords = recs;
417 vlMatchGrid.setStructure(vlMatchGridLayout);
419 // build the data store of records with match information
420 var dataStore = bre.toStoreData(recs, null,
421 {virtualFields:['dest_matchpoint', 'src_matchpoint', '_id']});
422 dataStore.identifier = '_id';
424 var matchSeenMap = {};
426 for(var i = 0; i < dataStore.items.length; i++) {
427 var item = dataStore.items[i];
428 item._id = i; // just need something unique
429 for(var j = 0; j < matches.length; j++) {
430 var match = matches[j];
431 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
432 item.dest_matchpoint = match.field_type();
433 var attr = getRecAttrFromMatch(queuedRecordsMap[recId], match);
434 item.src_matchpoint = getRecAttrDefFromAttr(attr, currentType).code();
435 matchSeenMap[match.id()] = 1;
441 // now populate the grid
442 vlPopulateMatchGrid(vlMatchGrid, dataStore);
448 function vlPopulateMatchGrid(grid, data) {
449 var store = new dojo.data.ItemFileReadStore({data:data});
450 grid.setStore(store);
454 function showMe(id) {
455 dojo.style(dojo.byId(id), 'display', 'block');
457 function hideMe(id) {
458 dojo.style(dojo.byId(id), 'display', 'none');
462 function vlLoadMARCHtml(recId, inCat, oncomplete) {
463 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
464 displayGlobalDiv('vl-generic-progress');
466 var params = [recId, 1];
469 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
470 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
471 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
472 if(currentType == 'auth')
473 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
475 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
476 dijit.byId('vl-marc-html-edit-button').onClick =
477 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
478 params = [authtoken, recId];
479 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
480 if(currentType == 'auth')
481 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
484 fieldmapper.standardRequest(
488 oncomplete: function(r) {
489 displayGlobalDiv('vl-marc-html-div');
490 var html = r.recv().content();
491 dojo.byId('vl-marc-record-html').innerHTML = html;
499 function getRecMatchesFromAttrCode(rec, attrCode) {
501 var attr = getRecAttrFromCode(rec, attrCode);
502 for(var j = 0; j < rec.matches().length; j++) {
503 var match = rec.matches()[j];
504 if(match.matched_attr() == attr.id())
511 function getRecAttrFromMatch(rec, match) {
512 for(var i = 0; i < rec.attributes().length; i++) {
513 var attr = rec.attributes()[i];
514 if(attr.id() == match.matched_attr())
519 function getRecAttrDefFromAttr(attr, type) {
520 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
521 for(var i = 0; i < defs.length; i++) {
523 if(def.id() == attr.field())
528 function getRecAttrFromCode(rec, attrCode) {
529 var defId = attrDefMap[currentType][attrCode];
530 var attrs = rec.attributes();
531 for(var i = 0; i < attrs.length; i++) {
533 if(attr.field() == defId)
539 function vlGetViewMatches(rowIdx, item) {
541 var id = this.grid.store.getValue(item, 'id');
542 var rec = queuedRecordsMap[id];
543 if(rec.matches().length > 0)
549 function vlFormatViewMatches(id) {
550 if(id == -1) return '';
551 return '<a href="javascript:void(0);" onclick="vlLoadMatchUI(' + id + ');">' + this.name + '</a>';
554 function vlFormatViewMatchMARC(id) {
555 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
556 'function(){displayGlobalDiv(\'vl-match-div\');});">' + this.name + '</a>';
559 function getAttrValue(rowIdx, item) {
561 var attrCode = this.field.split('.')[1];
562 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
563 var attr = getRecAttrFromCode(rec, attrCode);
564 return (attr) ? attr.attr_value() : '';
567 function vlGetDateTimeField(rowIdx, item) {
569 var value = this.grid.store.getValue(item, this.field);
570 if(!value) return '';
571 var date = dojo.date.stamp.fromISOString(value);
572 return dojo.date.locale.format(date, {selector:'date'});
575 function vlGetCreator(rowIdx, item) {
577 var id = this.grid.store.getValue(item, 'creator');
579 return userCache[id].usrname();
580 var user = fieldmapper.standardRequest(
581 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
582 if(e = openils.Event.parse(user))
584 userCache[id] = user;
585 return user.usrname();
588 function vlGetViewMARC(rowIdx, item) {
589 return item && this.grid.store.getValue(item, 'id');
592 function vlFormatViewMARC(id) {
593 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
594 'function(){displayGlobalDiv(\'vl-queue-div\');});">' + this.name + '</a>';
597 function vlGetOverlayTargetSelector(rowIdx, item) {
599 return this.grid.store.getValue(item, '_id') + ':' + this.grid.store.getValue(item, 'id');
602 function vlFormatOverlayTargetSelector(val) {
604 var parts = val.split(':');
607 var value = '<input type="checkbox" name="vl-overlay-target-RECID" '+
608 'onclick="vlHandleOverlayTargetSelected(ID, GRIDID);" gridid="GRIDID" match="ID"/>';
609 value = value.replace(/GRIDID/g, _id);
610 value = value.replace(/RECID/g, currentImportRecId);
611 value = value.replace(/ID/g, id);
612 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
613 return value.replace('/>', 'checked="checked"/>');
619 * see if the user has enabled overlays for the current match set and,
620 * if so, map the current import record to the overlay target.
622 function vlHandleOverlayTargetSelected(recId, gridId) {
623 var noneSelected = true;
624 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
625 for(var i = 0; i < checkboxes.length; i++) {
626 var checkbox = checkboxes[i];
627 var matchRecId = checkbox.getAttribute('match');
628 var gid = checkbox.getAttribute('gridid');
629 if(checkbox.checked) {
630 if(matchRecId == recId && gid == gridId) {
631 noneSelected = false;
632 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
633 currentOverlayRecordsMapGid[currentImportRecId] = gid;
634 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
635 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
637 checkbox.checked = false;
643 delete currentOverlayRecordsMap[currentImportRecId];
644 delete currentOverlayRecordsMapGid[currentImportRecId];
645 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
646 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
650 var valLastQueueType = null;
651 var vlQueueGridLayout = null;
652 function buildRecordGrid(type) {
653 displayGlobalDiv('vl-queue-div');
656 openils.Util.show('vl-bib-queue-grid-wrapper');
657 openils.Util.hide('vl-auth-queue-grid-wrapper');
658 vlQueueGrid = vlBibQueueGrid;
660 openils.Util.show('vl-auth-queue-grid-wrapper');
661 openils.Util.hide('vl-bib-queue-grid-wrapper');
662 vlQueueGrid = vlAuthQueueGrid;
666 if(valLastQueueType != type) {
667 valLastQueueType = type;
668 vlQueueGridLayout = vlQueueGrid.attr('structure');
669 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
670 attrDefMap[type] = {};
671 for(var i = 0; i < defs.length; i++) {
673 attrDefMap[type][def.code()] = def.id();
675 name:def.description(),
676 field:'attr.' + def.code(),
678 selectableColumn:true
680 vlQueueGridLayout[0].cells[0].push(col);
684 dojo.forEach(vlQueueGridLayout[0].cells[0],
686 if(cell.field.match(/^\+/))
687 cell.nonSelectable=true;
693 storeData = vqbr.toStoreData(queuedRecords);
695 storeData = vqar.toStoreData(queuedRecords);
697 var store = new dojo.data.ItemFileReadStore({data:storeData});
698 vlQueueGrid.setStore(store);
700 if(vlQueueGridColumePicker[type]) {
701 vlQueueGrid.update();
704 vlQueueGridColumePicker[type] =
705 new openils.widget.GridColumnPicker(
706 authtoken, 'vandelay.queue.'+type, vlQueueGrid, vlQueueGridLayout);
707 vlQueueGridColumePicker[type].load();
711 function vlQueueGridPrevPage() {
712 var page = parseInt(vlQueueDisplayPage.getValue());
714 vlQueueDisplayPage.setValue(page - 1);
715 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
718 function vlQueueGridNextPage() {
719 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
720 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
723 function vlDeleteQueue(type, queueId, onload) {
724 fieldmapper.standardRequest(
725 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
727 params: [authtoken, queueId],
728 oncomplete: function(r) {
729 var resp = r.recv().content();
730 if(e = openils.Event.parse(resp))
739 function vlQueueGridDrawSelectBox(rowIdx, item) {
740 return item && this.grid.store.getValue(item, 'id');
743 function vlQueueGridFormatSelectBox(id) {
744 var domId = 'vl-record-list-selected-' + id;
745 if (id) { selectableGridRecords[domId] = id; }
746 return "<div><input type='checkbox' id='"+domId+"'/></div>";
749 function vlSelectAllQueueGridRecords() {
750 for(var id in selectableGridRecords)
751 dojo.byId(id).checked = true;
753 function vlSelectNoQueueGridRecords() {
754 for(var id in selectableGridRecords)
755 dojo.byId(id).checked = false;
757 function vlToggleQueueGridSelect() {
758 if(dojo.byId('vl-queue-grid-row-selector').checked)
759 vlSelectAllQueueGridRecords();
761 vlSelectNoQueueGridRecords();
764 var handleRetrieveRecords = function() {
765 buildRecordGrid(currentType);
766 vlFetchQueueSummary(currentQueueId, currentType,
768 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
769 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
770 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
775 function vlFetchQueueSummary(qId, type, onload) {
776 fieldmapper.standardRequest(
777 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
779 params: [authtoken, qId],
780 oncomplete : function(r) {
781 var summary = r.recv().content();
782 if(e = openils.Event.parse(summary))
784 return onload(summary);
791 function vlImportSelectedRecords() {
792 displayGlobalDiv('vl-generic-progress-with-total');
795 for(var id in selectableGridRecords) {
796 if(dojo.byId(id).checked) {
797 var recId = selectableGridRecords[id];
798 var rec = queuedRecordsMap[recId];
799 if(!rec.import_time())
804 fieldmapper.standardRequest(
805 ['open-ils.vandelay', 'open-ils.vandelay.'+currentType+'_record.list.import'],
807 params: [authtoken, records, {overlay_map:currentOverlayRecordsMap}],
808 onresponse: function(r) {
809 var resp = r.recv().content();
810 if(e = openils.Event.parse(resp))
813 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
815 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
822 function vlImportAllRecords() {
823 vlImportRecordQueue(currentType, currentQueueId, false,
824 function(){displayGlobalDiv('vl-queue-div');});
827 function vlImportRecordQueue(type, queueId, noMatchOnly, onload) {
828 displayGlobalDiv('vl-generic-progress-with-total');
829 var method = 'open-ils.vandelay.bib_queue.import';
831 method = method.replace('import', 'nomatch.import');
833 method = method.replace('bib', 'auth');
836 if(vlUploadQueueAutoOverlayExact.checked) {
837 options.auto_overlay_exact = true;
838 vlUploadQueueAutoOverlayExact.checked = false;
841 fieldmapper.standardRequest(
842 ['open-ils.vandelay', method],
844 params: [authtoken, queueId, options],
845 onresponse: function(r) {
846 var resp = r.recv().content();
847 if(e = openils.Event.parse(resp))
849 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
851 oncomplete: function() {onload();}
857 function vlImportHoldings(queueId, importProfile, onload) {
858 displayGlobalDiv('vl-generic-progress-with-total');
859 fieldmapper.standardRequest(
860 ['open-ils.vandelay', 'open-ils.vandelay.bib_record.queue.asset.import'],
862 params: [authtoken, importProfile, queueId],
863 onresponse: function(r) {
864 var resp = openils.Util.readResponse(r);
865 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
867 oncomplete: function() {onload();}
873 * Create queue, upload MARC, process spool, load the newly created queue
875 function batchUpload() {
876 var queueName = dijit.byId('vl-queue-name').getValue();
877 currentType = dijit.byId('vl-record-type').getValue();
879 var handleProcessSpool = function() {
880 if(vlUploadQueueAutoImport.checked || vlUploadQueueAutoOverlayExact.checked) {
885 vlUploadQueueAutoImport.checked,
887 if(vlUploadQueueHoldingsImport.checked) {
890 vlUploadQueueHoldingsImportProfile.attr('value'),
892 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
896 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
901 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
905 var handleUploadMARC = function(key) {
906 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
907 processSpool(key, currentQueueId, currentType, handleProcessSpool);
910 var handleCreateQueue = function(queue) {
911 currentQueueId = queue.id();
912 uploadMARC(handleUploadMARC);
915 if(vlUploadQueueSelector.getValue() && !queueName) {
916 currentQueueId = vlUploadQueueSelector.getValue();
917 uploadMARC(handleUploadMARC);
919 createQueue(queueName, currentType, handleCreateQueue, vlUploadQueueHoldingsImportProfile.attr('value'));
924 function vlFleshQueueSelect(selector, type) {
925 var data = (type == 'bib') ? vbq.toStoreData(allUserBibQueues) : vaq.toStoreData(allUserAuthQueues);
926 selector.store = new dojo.data.ItemFileReadStore({data:data});
927 selector.setValue(null);
928 selector.setDisplayedValue('');
930 selector.setValue(data[0].id());
933 function vlShowUploadForm() {
934 displayGlobalDiv('vl-marc-upload-div');
935 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
936 vlUploadSourceSelector.store =
937 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
938 vlUploadSourceSelector.setValue(vlBibSources[0].id());
939 vlUploadQueueHoldingsImportProfile.store =
940 new dojo.data.ItemFileReadStore({data:viiad.toStoreData(importItemDefs)});
941 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
942 dojo.connect(vlUploadQueueHoldingsImport, 'onChange',
945 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
947 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
952 function vlShowQueueSelect() {
953 displayGlobalDiv('vl-queue-select-div');
954 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
957 function vlFetchQueueFromForm() {
958 currentType = vlQueueSelectType.getValue();
959 currentQueueId = vlQueueSelectQueueList.getValue();
960 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
963 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
965 To run in Firefox directly, must set signed.applets.codebase_principal_support
966 to true in about:config
968 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
969 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
972 // after the record is saved, reload the HTML display
973 var stat = r.recv().content();
974 if(e = openils.Event.parse(stat))
976 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
978 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
982 record : {marc : rec.marc()},
984 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
985 func: function(xmlString) {
986 var method = 'open-ils.permacrud.update.' + rec.classname;
988 fieldmapper.standardRequest(
989 ['open-ils.permacrud', method],
991 params: [authtoken, rec],
1000 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
1001 var method = 'open-ils.permacrud.search.vqbr';
1002 if(currentType != 'bib')
1003 method = method.replace(/vqbr/,'vqar');
1005 fieldmapper.standardRequest(
1006 ['open-ils.permacrud', method],
1008 params: [authtoken, {id : recId}],
1009 oncomplete: function(r) {
1010 var rec = r.recv().content();
1011 if(e = openils.Event.parse(rec))
1013 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
1021 //------------------------------------------------------------
1022 // attribute editors
1024 // attribute-editor global variables
1026 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
1027 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
1028 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
1030 function vlAttrEditorInit() {
1031 // set up tooltips on the edit form
1032 connectTooltip('attr-editor-tags');
1033 connectTooltip('attr-editor-subfields');
1036 function vlShowAttrEditor() {
1037 displayGlobalDiv('vl-attr-editor-div');
1038 loadAttrEditorGrid();
1039 idHide('vl-generic-progress');
1042 function setAttrEditorGroup(groupName) {
1043 // put us into 'bib'-attr or 'auth'-attr mode.
1044 if (ATTR_EDIT_GROUP != groupName) {
1045 ATTR_EDIT_GROUP = groupName;
1046 loadAttrEditorGrid();
1050 function onAttrEditorOpen() {
1051 // the "bars" have the create/update/cancel/etc. buttons.
1052 var create_bar = document.getElementById('attr-editor-create-bar');
1053 var update_bar = document.getElementById('attr-editor-update-bar');
1054 if (ATTR_EDITOR_IN_UPDATE_MODE) {
1055 update_bar.style.display='table-row';
1056 create_bar.style.display='none';
1057 // hide the dropdown-button
1058 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
1060 dijit.byId('attr-editor-dialog').reset();
1061 create_bar.style.display='table-row';
1062 update_bar.style.display='none';
1066 function onAttrEditorClose() {
1067 // reset the form to a "create" form. (We may have borrowed it for editing.)
1068 ATTR_EDITOR_IN_UPDATE_MODE = false;
1069 // show the dropdown-button
1070 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
1073 function loadAttrEditorGrid() {
1074 var _data = (ATTR_EDIT_GROUP == 'auth') ?
1075 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
1077 var store = new dojo.data.ItemFileReadStore({data:_data});
1078 attrEditorGrid.setStore(store);
1079 dojo.connect(attrEditorGrid, 'onRowDblClick', onAttrEditorClick);
1080 attrEditorGrid.update();
1083 function attrGridGetTag(n, item) {
1084 // grid helper: return the tags from the row's xpath column.
1085 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
1088 function attrGridGetSubfield(n, item) {
1089 // grid helper: return the subfields from the row's xpath column.
1090 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
1093 function onAttrEditorClick() {
1094 var row = this.getItem(this.focus.rowIndex);
1095 ATTR_EDIT_ID = this.store.getValue(row, 'id');
1096 ATTR_EDITOR_IN_UPDATE_MODE = true;
1098 // populate the popup editor.
1099 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1100 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1101 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1102 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1103 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1104 dijit.byId('attr-editor-identifier').attr('value', this.store.getValue(row, 'ident'));
1105 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1106 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1108 // set up UI for editing
1109 dojo.byId('vl-create-attr-editor-button').click();
1112 function vlSaveAttrDefinition(data) {
1113 idHide('vl-attr-editor-div');
1114 idShow('vl-generic-progress');
1116 data.id = ATTR_EDIT_ID;
1118 // this ought to honour custom xpaths, but overwrite xpaths
1119 // derived from tags/subfields.
1120 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1121 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1122 data.xpath = _xpath;
1125 // build up our permacrud params. Key variables here are
1126 // "create or update" and "bib or auth".
1128 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1129 var isCreate = (ATTR_EDIT_ID == null);
1130 var rad = isAuth ? new vqarad() : new vqbrad() ;
1131 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1132 + (isAuth ? 'vqarad' : 'vqbrad');
1133 var _data = rad.fromStoreItem(data);
1137 fieldmapper.standardRequest(
1138 ['open-ils.permacrud', method],
1140 params: [authtoken, _data ],
1141 onresponse: function(r) { },
1142 oncomplete: function(r) {
1143 attrEditorFetchAttrDefs(vlShowAttrEditor);
1144 ATTR_EDIT_ID = null;
1146 onerror: function(r) {
1147 alert('vlSaveAttrDefinition comms error: ' + r);
1153 function attrEditorFetchAttrDefs(callback) {
1154 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1155 return fn(callback);
1158 function vlAttrDelete() {
1159 idHide('vl-attr-editor-div');
1160 idShow('vl-generic-progress');
1162 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1163 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1164 var rad = isAuth ? new vqarad() : new vqbrad() ;
1165 fieldmapper.standardRequest(
1166 ['open-ils.permacrud', method],
1168 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1169 oncomplete: function() {
1170 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1171 attrEditorFetchAttrDefs(vlShowAttrEditor);
1172 ATTR_EDIT_ID = null;
1174 onerror: function(r) {
1175 alert('vlAttrDelete comms error: ' + r);
1181 // ------------------------------------------------------------
1182 // utilities for attribute editors
1184 // dom utilities (maybe dojo does these, and these should be replaced)
1186 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1187 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1188 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1190 function connectTooltip(fieldId) {
1191 // Given an element id, look up a tooltip element in the doc (same
1192 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1193 // a better way to do this?
1194 var fld = dojo.byId(fieldId);
1195 var tip = dojo.byId(fieldId + '-tip');
1196 dojo.connect(fld, 'onfocus', function(evt) {
1197 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1198 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1203 var xpathParser = new openils.MarcXPathParser();
1205 function tagAndSubFieldsToXpath(tags, subfields) {
1206 // given tags, and subfields, build up an XPath.
1209 'tags':tags.match(/[\d]+/g),
1210 'subfields':subfields.match(/[a-zA-z]/g) };
1211 return xpathParser.compile(parts);
1213 return {'parts':null, 'tags':null, 'error':err};
1217 function looksLikeDerivedXpath(path) {
1218 // Does this path look like it was derived from tags and subfields?
1219 var parsed = xpathParser.parse(path);
1220 if (parsed.tags == null)
1222 var compiled = xpathParser.compile(parsed);
1223 return (path == compiled);
1226 // amazing xpath-util unit-tests
1227 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1228 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');
1232 var profileContextOrg
1233 function vlShowProfileEditor() {
1234 displayGlobalDiv('vl-profile-editor-div');
1237 var connect = function() {
1238 dojo.connect(profileContextOrgSelector, 'onChange',
1240 profileContextOrg = this.attr('value');
1247 new openils.User().buildPermOrgSelector(
1248 '"ADMIN_MERGE_PROFILE', profileContextOrgSelector, null, connect);
1251 function buildProfileGrid() {
1253 if(profileContextOrg == null)
1254 profileContextOrg = openils.User.user.ws_ou();
1257 {order_by : {vmp : 'name'}},
1258 {owner : fieldmapper.aou.fullPath(profileContextOrg, true)}