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');
45 dojo.require('openils.widget.AutoFieldWidget');
49 'vl-generic-progress',
50 'vl-generic-progress-with-total',
55 'vl-queue-select-div',
56 'vl-marc-upload-status-div',
59 'vl-profile-editor-div',
60 'vl-item-attr-editor-div'
64 var VANDELAY_URL = '/vandelay-upload';
66 var authAttrDefs = [];
67 var queuedRecords = [];
68 var queuedRecordsMap = {};
69 var bibAttrsFetched = false;
70 var authAttrsFetched = false;
71 var attrDefMap = {}; // maps attr def code names to attr def ids
73 var currentQueueId = null;
75 var currentMatchedRecords; // set of loaded matched bib records
76 var currentOverlayRecordsMap; // map of import record to overlay record
77 var currentOverlayRecordsMapGid; // map of import record to overlay record grid id
78 var currentImportRecId; // when analyzing matches, this is the current import record
79 var userBibQueues = []; // only non-complete queues
80 var userAuthQueues = []; // only non-complete queues
82 var allUserAuthQueues;
83 var selectableGridRecords;
84 var cgi = new openils.CGI();
85 var vlQueueGridColumePicker = {};
86 var vlBibSources = [];
87 var importItemDefs = [];
93 authtoken = openils.User.authtoken;
94 var initNeeded = 6; // how many async responses do we need before we're init'd
95 var initCount = 0; // how many async reponses we've received
97 openils.Util.registerEnterHandler(
98 vlQueueDisplayPage.domNode, function(){retrieveQueuedRecords();});
99 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
101 function checkInitDone() {
103 if(initCount == initNeeded)
104 runStartupCommands();
107 var profiles = new openils.PermaCrud().retrieveAll('vmp');
108 vlUploadMergeProfile.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(profiles)});
109 vlUploadMergeProfile.labelAttr = 'name';
110 vlUploadMergeProfile.searchAttr = 'name';
111 vlUploadMergeProfile.startup();
113 vlUploadMergeProfile2.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(profiles)});
114 vlUploadMergeProfile2.labelAttr = 'name';
115 vlUploadMergeProfile2.searchAttr = 'name';
116 vlUploadMergeProfile2.startup();
119 // Fetch the bib and authority attribute definitions
120 vlFetchBibAttrDefs(function () { checkInitDone(); });
121 vlFetchAuthAttrDefs(function () { checkInitDone(); });
123 vlRetrieveQueueList('bib', null,
125 allUserBibQueues = list;
126 for(var i = 0; i < allUserBibQueues.length; i++) {
127 if(allUserBibQueues[i].complete() == 'f')
128 userBibQueues.push(allUserBibQueues[i]);
134 vlRetrieveQueueList('auth', null,
136 allUserAuthQueues = list;
137 for(var i = 0; i < allUserAuthQueues.length; i++) {
138 if(allUserAuthQueues[i].complete() == 'f')
139 userAuthQueues.push(allUserAuthQueues[i]);
145 fieldmapper.standardRequest(
146 ['open-ils.permacrud', 'open-ils.permacrud.search.cbs.atomic'],
148 params: [authtoken, {id:{"!=":null}}, {order_by:{cbs:'id'}}],
149 oncomplete : function(r) {
150 vlBibSources = openils.Util.readResponse(r, false, true);
156 var owner = fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(new openils.User().user.ws_ou()));
157 new openils.PermaCrud().search('viiad',
158 {owner: owner.map(function(org) { return org.id(); })},
160 oncomplete: function(r) {
161 importItemDefs = openils.Util.readResponse(r);
171 openils.Util.addOnLoad(vlInit);
174 // fetch the bib and authority attribute definitions
176 function vlFetchBibAttrDefs(postcomplete) {
178 fieldmapper.standardRequest(
179 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
181 params: [authtoken, {id:{'!=':null}}],
182 onresponse: function(r) {
183 var def = r.recv().content();
184 if(e = openils.Event.parse(def[0]))
186 bibAttrDefs.push(def);
188 oncomplete: function() {
189 bibAttrDefs = bibAttrDefs.sort(
191 if(a.id() > b.id()) return 1;
192 if(a.id() < b.id()) return -1;
202 function vlFetchAuthAttrDefs(postcomplete) {
204 fieldmapper.standardRequest(
205 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
207 params: [authtoken, {id:{'!=':null}}],
208 onresponse: function(r) {
209 var def = r.recv().content();
210 if(e = openils.Event.parse(def[0]))
212 authAttrDefs.push(def);
214 oncomplete: function() {
215 authAttrDefs = authAttrDefs.sort(
217 if(a.id() > b.id()) return 1;
218 if(a.id() < b.id()) return -1;
228 function vlRetrieveQueueList(type, filter, onload) {
229 type = (type == 'bib') ? type : 'authority';
230 fieldmapper.standardRequest(
231 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.owner.retrieve.atomic'],
233 params: [authtoken, null, filter],
234 oncomplete: function(r) {
235 var list = r.recv().content();
236 if(e = openils.Event.parse(list[0]))
245 function displayGlobalDiv(id) {
246 for(var i = 0; i < globalDivs.length; i++) {
248 dojo.style(dojo.byId(globalDivs[i]), 'display', 'none');
250 alert('please define div ' + globalDivs[i]);
253 dojo.style(dojo.byId(id),'display','block');
255 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
256 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
257 openils.Util.removeCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
258 openils.Util.removeCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
259 openils.Util.removeCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
262 case 'vl-marc-export-div':
263 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
265 case 'vl-marc-upload-div':
266 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
268 case 'vl-queue-select-div':
269 openils.Util.addCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
271 case 'vl-attr-editor-div':
272 openils.Util.addCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
274 case 'vl-profile-editor-div':
275 openils.Util.addCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
277 case 'vl-item-attr-editor-div':
278 openils.Util.addCSSClass(dojo.byId('vl-menu-import-item-attr-editor'), 'toolbar_selected');
283 function runStartupCommands() {
284 currentQueueId = cgi.param('qid');
285 currentType = cgi.param('qtype');
286 dojo.style('vl-nav-bar', 'visibility', 'visible');
288 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
293 * asynchronously upload a file of MARC records
295 function uploadMARC(onload){
296 dojo.byId('vl-upload-status-count').innerHTML = '0';
297 dojo.byId('vl-ses-input').value = authtoken;
298 displayGlobalDiv('vl-marc-upload-status-div');
299 dojo.io.iframe.send({
303 form: dojo.byId('vl-marc-upload-form'),
304 handle: function(data,ioArgs){
305 var content = data.documentElement.textContent;
312 * Creates a new vandelay queue
314 function createQueue(queueName, type, onload, importDefId) {
315 var name = (type=='bib') ? 'bib' : 'authority';
316 var method = 'open-ils.vandelay.'+ name +'_queue.create'
317 fieldmapper.standardRequest(
318 ['open-ils.vandelay', method],
320 params: [authtoken, queueName, null, name, importDefId],
321 oncomplete : function(r) {
322 var queue = r.recv().content();
323 if(e = openils.Event.parse(queue))
332 * Tells vandelay to pull a batch of records from the cache and explode them
333 * out into the vandelay tables
335 function processSpool(key, queueId, type, onload) {
336 fieldmapper.standardRequest(
337 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
339 params: [authtoken, key, queueId],
340 onresponse : function(r) {
341 var resp = r.recv().content();
342 if(e = openils.Event.parse(resp))
344 dojo.byId('vl-upload-status-count').innerHTML = resp;
346 oncomplete : function(r) {onload();}
351 function retrieveQueuedRecords(type, queueId, onload) {
352 displayGlobalDiv('vl-generic-progress');
354 queuedRecordsMap = {};
355 currentOverlayRecordsMap = {};
356 currentOverlayRecordsMapGid = {};
357 selectableGridRecords = {};
358 //resetVlQueueGridLayout();
360 if(!type) type = currentType;
361 if(!queueId) queueId = currentQueueId;
362 if(!onload) onload = handleRetrieveRecords;
364 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve.atomic';
365 if(vlQueueGridShowMatches.checked)
366 method = method.replace('records', 'records.matches');
368 var sel = dojo.byId('vl-queue-display-limit-selector');
369 var limit = parseInt(sel.options[sel.selectedIndex].value);
370 var offset = limit * parseInt(vlQueueDisplayPage.attr('value')-1);
372 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit}];
373 if(vlQueueGridShowNonImport.checked)
374 params[2].non_imported = 1;
376 fieldmapper.standardRequest(
377 ['open-ils.vandelay', method],
381 onresponse: function(r) {
382 console.log("ONREPONSE");
383 var rec = r.recv().content();
384 if(e = openils.Event.parse(rec))
386 console.log("got record " + rec.id());
387 queuedRecords.push(rec);
388 queuedRecordsMap[rec.id()] = rec;
391 oncomplete: function(r){
392 var recs = r.recv().content();
393 if(e = openils.Event.parse(recs[0]))
395 for(var i = 0; i < recs.length; i++) {
397 queuedRecords.push(rec);
398 queuedRecordsMap[rec.id()] = rec;
406 function vlLoadMatchUI(recId) {
407 displayGlobalDiv('vl-generic-progress');
408 var matches = queuedRecordsMap[recId].matches();
410 currentImportRecId = recId;
411 for(var i = 0; i < matches.length; i++)
412 records.push(matches[i].eg_record());
414 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
415 var params = [records];
416 if(currentType == 'auth') {
417 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
418 parmas = [authtoken, records, {clear_marc:1}];
421 fieldmapper.standardRequest(
425 oncomplete: function(r) {
426 var recs = r.recv().content();
427 if(e = openils.Event.parse(recs))
431 displayGlobalDiv('vl-match-div');
432 resetVlMatchGridLayout();
433 currentMatchedRecords = recs;
434 vlMatchGrid.setStructure(vlMatchGridLayout);
436 // build the data store of records with match information
437 var dataStore = bre.toStoreData(recs, null,
438 {virtualFields:['dest_matchpoint', 'src_matchpoint', '_id']});
439 dataStore.identifier = '_id';
441 var matchSeenMap = {};
443 for(var i = 0; i < dataStore.items.length; i++) {
444 var item = dataStore.items[i];
445 item._id = i; // just need something unique
446 for(var j = 0; j < matches.length; j++) {
447 var match = matches[j];
448 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
449 item.dest_matchpoint = match.field_type();
450 var attr = getRecAttrFromMatch(queuedRecordsMap[recId], match);
451 item.src_matchpoint = getRecAttrDefFromAttr(attr, currentType).code();
452 matchSeenMap[match.id()] = 1;
458 // now populate the grid
459 vlPopulateMatchGrid(vlMatchGrid, dataStore);
465 function vlPopulateMatchGrid(grid, data) {
466 var store = new dojo.data.ItemFileReadStore({data:data});
467 grid.setStore(store);
471 function showMe(id) {
472 dojo.style(dojo.byId(id), 'display', 'block');
474 function hideMe(id) {
475 dojo.style(dojo.byId(id), 'display', 'none');
479 function vlLoadMARCHtml(recId, inCat, oncomplete) {
480 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
481 displayGlobalDiv('vl-generic-progress');
483 var params = [recId, 1];
486 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
487 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
488 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
489 if(currentType == 'auth')
490 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
492 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
493 dijit.byId('vl-marc-html-edit-button').onClick =
494 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
495 params = [authtoken, recId];
496 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
497 if(currentType == 'auth')
498 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
501 fieldmapper.standardRequest(
505 oncomplete: function(r) {
506 displayGlobalDiv('vl-marc-html-div');
507 var html = r.recv().content();
508 dojo.byId('vl-marc-record-html').innerHTML = html;
516 function getRecMatchesFromAttrCode(rec, attrCode) {
518 var attr = getRecAttrFromCode(rec, attrCode);
519 for(var j = 0; j < rec.matches().length; j++) {
520 var match = rec.matches()[j];
521 if(match.matched_attr() == attr.id())
528 function getRecAttrFromMatch(rec, match) {
529 for(var i = 0; i < rec.attributes().length; i++) {
530 var attr = rec.attributes()[i];
531 if(attr.id() == match.matched_attr())
536 function getRecAttrDefFromAttr(attr, type) {
537 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
538 for(var i = 0; i < defs.length; i++) {
540 if(def.id() == attr.field())
545 function getRecAttrFromCode(rec, attrCode) {
546 var defId = attrDefMap[currentType][attrCode];
547 var attrs = rec.attributes();
548 for(var i = 0; i < attrs.length; i++) {
550 if(attr.field() == defId)
556 function vlGetViewMatches(rowIdx, item) {
558 var id = this.grid.store.getValue(item, 'id');
559 var rec = queuedRecordsMap[id];
560 if(rec.matches().length > 0)
566 function vlFormatViewMatches(id) {
567 if(id == -1) return '';
568 return '<a href="javascript:void(0);" onclick="vlLoadMatchUI(' + id + ');">' + this.name + '</a>';
571 function vlFormatViewMatchMARC(id) {
572 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', true, '+
573 'function(){displayGlobalDiv(\'vl-match-div\');});">' + this.name + '</a>';
576 function getAttrValue(rowIdx, item) {
578 var attrCode = this.field.split('.')[1];
579 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
580 var attr = getRecAttrFromCode(rec, attrCode);
581 return (attr) ? attr.attr_value() : '';
584 function vlGetDateTimeField(rowIdx, item) {
586 var value = this.grid.store.getValue(item, this.field);
587 if(!value) return '';
588 var date = dojo.date.stamp.fromISOString(value);
589 return dojo.date.locale.format(date, {selector:'date'});
592 function vlGetCreator(rowIdx, item) {
594 var id = this.grid.store.getValue(item, 'creator');
596 return userCache[id].usrname();
597 var user = fieldmapper.standardRequest(
598 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
599 if(e = openils.Event.parse(user))
601 userCache[id] = user;
602 return user.usrname();
605 function vlGetViewMARC(rowIdx, item) {
606 return item && this.grid.store.getValue(item, 'id');
609 function vlFormatViewMARC(id) {
610 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
611 'function(){displayGlobalDiv(\'vl-queue-div\');});">' + this.name + '</a>';
614 function vlGetOverlayTargetSelector(rowIdx, item) {
616 return this.grid.store.getValue(item, '_id') + ':' + this.grid.store.getValue(item, 'id');
619 function vlFormatOverlayTargetSelector(val) {
621 var parts = val.split(':');
624 var value = '<input type="checkbox" name="vl-overlay-target-RECID" '+
625 'onclick="vlHandleOverlayTargetSelected(ID, GRIDID);" gridid="GRIDID" match="ID"/>';
626 value = value.replace(/GRIDID/g, _id);
627 value = value.replace(/RECID/g, currentImportRecId);
628 value = value.replace(/ID/g, id);
629 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
630 return value.replace('/>', 'checked="checked"/>');
636 * see if the user has enabled overlays for the current match set and,
637 * if so, map the current import record to the overlay target.
639 function vlHandleOverlayTargetSelected(recId, gridId) {
640 var noneSelected = true;
641 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
642 for(var i = 0; i < checkboxes.length; i++) {
643 var checkbox = checkboxes[i];
644 var matchRecId = checkbox.getAttribute('match');
645 var gid = checkbox.getAttribute('gridid');
646 if(checkbox.checked) {
647 if(matchRecId == recId && gid == gridId) {
648 noneSelected = false;
649 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
650 currentOverlayRecordsMapGid[currentImportRecId] = gid;
651 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
652 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
654 checkbox.checked = false;
660 delete currentOverlayRecordsMap[currentImportRecId];
661 delete currentOverlayRecordsMapGid[currentImportRecId];
662 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
663 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
667 var valLastQueueType = null;
668 var vlQueueGridLayout = null;
669 function buildRecordGrid(type) {
670 displayGlobalDiv('vl-queue-div');
673 openils.Util.show('vl-bib-queue-grid-wrapper');
674 openils.Util.hide('vl-auth-queue-grid-wrapper');
675 vlQueueGrid = vlBibQueueGrid;
677 openils.Util.show('vl-auth-queue-grid-wrapper');
678 openils.Util.hide('vl-bib-queue-grid-wrapper');
679 vlQueueGrid = vlAuthQueueGrid;
683 if(valLastQueueType != type) {
684 valLastQueueType = type;
685 vlQueueGridLayout = vlQueueGrid.attr('structure');
686 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
687 attrDefMap[type] = {};
688 for(var i = 0; i < defs.length; i++) {
690 attrDefMap[type][def.code()] = def.id();
692 name:def.description(),
693 field:'attr.' + def.code(),
695 selectableColumn:true
697 vlQueueGridLayout[0].cells[0].push(col);
701 dojo.forEach(vlQueueGridLayout[0].cells[0],
703 if(cell.field.match(/^\+/))
704 cell.nonSelectable=true;
710 storeData = vqbr.toStoreData(queuedRecords);
712 storeData = vqar.toStoreData(queuedRecords);
714 var store = new dojo.data.ItemFileReadStore({data:storeData});
715 vlQueueGrid.setStore(store);
717 if(vlQueueGridColumePicker[type]) {
718 vlQueueGrid.update();
721 vlQueueGridColumePicker[type] =
722 new openils.widget.GridColumnPicker(
723 authtoken, 'vandelay.queue.'+type, vlQueueGrid, vlQueueGridLayout);
724 vlQueueGridColumePicker[type].load();
728 function vlQueueGridPrevPage() {
729 var page = parseInt(vlQueueDisplayPage.getValue());
731 vlQueueDisplayPage.setValue(page - 1);
732 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
735 function vlQueueGridNextPage() {
736 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
737 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
740 function vlDeleteQueue(type, queueId, onload) {
741 fieldmapper.standardRequest(
742 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
744 params: [authtoken, queueId],
745 oncomplete: function(r) {
746 var resp = r.recv().content();
747 if(e = openils.Event.parse(resp))
756 function vlQueueGridDrawSelectBox(rowIdx, item) {
757 return item && this.grid.store.getValue(item, 'id');
760 function vlQueueGridFormatSelectBox(id) {
761 var domId = 'vl-record-list-selected-' + id;
762 if (id) { selectableGridRecords[domId] = id; }
763 return "<div><input type='checkbox' id='"+domId+"'/></div>";
766 function vlSelectAllQueueGridRecords() {
767 for(var id in selectableGridRecords)
768 dojo.byId(id).checked = true;
770 function vlSelectNoQueueGridRecords() {
771 for(var id in selectableGridRecords)
772 dojo.byId(id).checked = false;
774 function vlToggleQueueGridSelect() {
775 if(dojo.byId('vl-queue-grid-row-selector').checked)
776 vlSelectAllQueueGridRecords();
778 vlSelectNoQueueGridRecords();
781 var handleRetrieveRecords = function() {
782 buildRecordGrid(currentType);
783 vlFetchQueueSummary(currentQueueId, currentType,
785 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
786 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
787 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
792 function vlFetchQueueSummary(qId, type, onload) {
793 fieldmapper.standardRequest(
794 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
796 params: [authtoken, qId],
797 oncomplete : function(r) {
798 var summary = r.recv().content();
799 if(e = openils.Event.parse(summary))
801 return onload(summary);
807 function vlHandleQueueItemsAction(action) {
810 queueItemsImportCancelButton,
813 queueItemsImportDialog.hide();
818 queueItemsImportGoButton,
821 queueItemsImportDialog.hide();
823 // hack to set the widgets the import funcs will be looking at. Reset them below.
824 vlUploadQueueAutoImport.attr('value', vlUploadQueueAutoImport2.attr('value'));
825 vlUploadQueueAutoOverlayExact.attr('value', vlUploadQueueAutoOverlayExact2.attr('value'));
826 vlUploadQueueAutoOverlay1Match.attr('value', vlUploadQueueAutoOverlay1Match2.attr('value'));
827 vlUploadMergeProfile.attr('value', vlUploadMergeProfile2.attr('value'));
829 if(action == 'import') {
830 vlImportSelectedRecords();
831 } else if(action == 'import_all') {
832 vlImportAllRecords();
835 // reset the widgets to prevent accidental future actions
836 vlUploadQueueAutoImport.attr('value', false);
837 vlUploadQueueAutoImport2.attr('value', false);
838 vlUploadQueueAutoOverlayExact.attr('value', false);
839 vlUploadQueueAutoOverlayExact2.attr('value', false);
840 vlUploadQueueAutoOverlay1Match.attr('value', false);
841 vlUploadQueueAutoOverlay1Match2.attr('value', false);
842 vlUploadMergeProfile.attr('value', '');
843 vlUploadMergeProfile2.attr('value', '');
847 queueItemsImportDialog.show();
851 function vlImportSelectedRecords() {
852 displayGlobalDiv('vl-generic-progress-with-total');
855 for(var id in selectableGridRecords) {
856 if(dojo.byId(id).checked) {
857 var recId = selectableGridRecords[id];
858 var rec = queuedRecordsMap[recId];
859 if(!rec.import_time())
864 var options = {overlay_map : currentOverlayRecordsMap};
866 if(vlUploadQueueAutoOverlayExact.checked) {
867 options.auto_overlay_exact = true;
868 vlUploadQueueAutoOverlayExact.checked = false;
871 if(vlUploadQueueAutoOverlay1Match.checked) {
872 options.auto_overlay_1match = true;
873 vlUploadQueueAutoOverlay1Match.checked = false;
876 var profile = vlUploadMergeProfile.attr('value');
877 if(profile != null && profile != '') {
878 options.merge_profile = profile;
881 fieldmapper.standardRequest(
882 ['open-ils.vandelay', 'open-ils.vandelay.'+currentType+'_record.list.import'],
884 params: [authtoken, records, options],
885 onresponse: function(r) {
886 var resp = r.recv().content();
887 if(e = openils.Event.parse(resp))
890 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
892 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
899 function vlImportAllRecords() {
900 vlImportRecordQueue(currentType, currentQueueId, false,
901 function(){displayGlobalDiv('vl-queue-div');});
904 function vlImportRecordQueue(type, queueId, noMatchOnly, onload) {
905 displayGlobalDiv('vl-generic-progress-with-total');
906 var method = 'open-ils.vandelay.bib_queue.import';
908 method = method.replace('import', 'nomatch.import');
910 method = method.replace('bib', 'auth');
913 if(vlUploadQueueAutoOverlayExact.checked) {
914 options.auto_overlay_exact = true;
915 vlUploadQueueAutoOverlayExact.checked = false;
918 if(vlUploadQueueAutoOverlay1Match.checked) {
919 options.auto_overlay_1match = true;
920 vlUploadQueueAutoOverlay1Match.checked = false;
923 var profile = vlUploadMergeProfile.attr('value');
924 if(profile != null && profile != '') {
925 options.merge_profile = profile;
928 fieldmapper.standardRequest(
929 ['open-ils.vandelay', method],
931 params: [authtoken, queueId, options],
932 onresponse: function(r) {
933 var resp = r.recv().content();
934 if(e = openils.Event.parse(resp))
936 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
938 oncomplete: function() {onload();}
944 function vlImportHoldings(queueId, importProfile, onload) {
945 displayGlobalDiv('vl-generic-progress-with-total');
946 fieldmapper.standardRequest(
947 ['open-ils.vandelay', 'open-ils.vandelay.bib_record.queue.asset.import'],
949 params: [authtoken, importProfile, queueId],
950 onresponse: function(r) {
951 var resp = openils.Util.readResponse(r);
952 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
954 oncomplete: function() {onload();}
960 * Create queue, upload MARC, process spool, load the newly created queue
962 function batchUpload() {
963 var queueName = dijit.byId('vl-queue-name').getValue();
964 currentType = dijit.byId('vl-record-type').getValue();
966 var handleProcessSpool = function() {
967 if(vlUploadQueueAutoImport.checked || vlUploadQueueAutoOverlayExact.checked || vlUploadQueueAutoOverlay1Match.checked) {
972 vlUploadQueueAutoImport.checked,
974 if(vlUploadQueueHoldingsImport.checked) {
977 vlUploadQueueHoldingsImportProfile.attr('value'),
979 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
983 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
988 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
992 var handleUploadMARC = function(key) {
993 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
994 processSpool(key, currentQueueId, currentType, handleProcessSpool);
997 var handleCreateQueue = function(queue) {
998 currentQueueId = queue.id();
999 uploadMARC(handleUploadMARC);
1002 if(vlUploadQueueSelector.getValue() && !queueName) {
1003 currentQueueId = vlUploadQueueSelector.getValue();
1004 uploadMARC(handleUploadMARC);
1006 createQueue(queueName, currentType, handleCreateQueue, vlUploadQueueHoldingsImportProfile.attr('value'));
1011 function vlFleshQueueSelect(selector, type) {
1012 var data = (type == 'bib') ? vbq.toStoreData(allUserBibQueues) : vaq.toStoreData(allUserAuthQueues);
1013 selector.store = new dojo.data.ItemFileReadStore({data:data});
1014 selector.setValue(null);
1015 selector.setDisplayedValue('');
1017 selector.setValue(data[0].id());
1020 function vlShowUploadForm() {
1021 displayGlobalDiv('vl-marc-upload-div');
1022 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
1023 vlUploadSourceSelector.store =
1024 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
1025 vlUploadSourceSelector.setValue(vlBibSources[0].id());
1026 vlUploadQueueHoldingsImportProfile.store =
1027 new dojo.data.ItemFileReadStore({data:viiad.toStoreData(importItemDefs)});
1028 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
1029 dojo.connect(vlUploadQueueHoldingsImport, 'onChange',
1032 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1034 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
1039 function vlShowQueueSelect() {
1040 displayGlobalDiv('vl-queue-select-div');
1041 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
1044 function vlFetchQueueFromForm() {
1045 currentType = vlQueueSelectType.getValue();
1046 currentQueueId = vlQueueSelectQueueList.getValue();
1047 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1050 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
1052 To run in Firefox directly, must set signed.applets.codebase_principal_support
1053 to true in about:config
1055 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1056 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
1059 if (currentType == 'bib') {
1065 function onsave(r) {
1066 // after the record is saved, reload the HTML display
1067 var stat = r.recv().content();
1068 if(e = openils.Event.parse(stat))
1070 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
1072 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
1076 record : {marc : rec.marc(), "rtype": type},
1078 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
1079 func: function(xmlString) {
1080 var method = 'open-ils.permacrud.update.' + rec.classname;
1081 rec.marc(xmlString);
1082 fieldmapper.standardRequest(
1083 ['open-ils.permacrud', method],
1085 params: [authtoken, rec],
1091 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
1092 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
1096 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
1097 var method = 'open-ils.permacrud.search.vqbr';
1098 if(currentType != 'bib')
1099 method = method.replace(/vqbr/,'vqar');
1101 fieldmapper.standardRequest(
1102 ['open-ils.permacrud', method],
1104 params: [authtoken, {id : recId}],
1105 oncomplete: function(r) {
1106 var rec = r.recv().content();
1107 if(e = openils.Event.parse(rec))
1109 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
1117 //------------------------------------------------------------
1118 // attribute editors
1120 // attribute-editor global variables
1122 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
1123 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
1124 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
1126 function vlAttrEditorInit() {
1127 // set up tooltips on the edit form
1128 connectTooltip('attr-editor-tags');
1129 connectTooltip('attr-editor-subfields');
1132 function vlShowAttrEditor() {
1133 displayGlobalDiv('vl-attr-editor-div');
1134 loadAttrEditorGrid();
1135 idHide('vl-generic-progress');
1138 function setAttrEditorGroup(groupName) {
1139 // put us into 'bib'-attr or 'auth'-attr mode.
1140 if (ATTR_EDIT_GROUP != groupName) {
1141 ATTR_EDIT_GROUP = groupName;
1142 loadAttrEditorGrid();
1146 function onAttrEditorOpen() {
1147 // the "bars" have the create/update/cancel/etc. buttons.
1148 var create_bar = document.getElementById('attr-editor-create-bar');
1149 var update_bar = document.getElementById('attr-editor-update-bar');
1150 if (ATTR_EDITOR_IN_UPDATE_MODE) {
1151 update_bar.style.display='table-row';
1152 create_bar.style.display='none';
1153 // hide the dropdown-button
1154 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
1156 dijit.byId('attr-editor-dialog').reset();
1157 create_bar.style.display='table-row';
1158 update_bar.style.display='none';
1162 function onAttrEditorClose() {
1163 // reset the form to a "create" form. (We may have borrowed it for editing.)
1164 ATTR_EDITOR_IN_UPDATE_MODE = false;
1165 // show the dropdown-button
1166 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
1169 function loadAttrEditorGrid() {
1170 var _data = (ATTR_EDIT_GROUP == 'auth') ?
1171 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
1173 var store = new dojo.data.ItemFileReadStore({data:_data});
1174 attrEditorGrid.setStore(store);
1175 attrEditorGrid.onRowDblClick = onAttrEditorClick;
1176 attrEditorGrid.update();
1179 function attrGridGetTag(n, item) {
1180 // grid helper: return the tags from the row's xpath column.
1181 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
1184 function attrGridGetSubfield(n, item) {
1185 // grid helper: return the subfields from the row's xpath column.
1186 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
1189 function onAttrEditorClick() {
1190 var row = this.getItem(this.focus.rowIndex);
1191 ATTR_EDIT_ID = this.store.getValue(row, 'id');
1192 ATTR_EDITOR_IN_UPDATE_MODE = true;
1194 // populate the popup editor.
1195 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1196 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1197 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1198 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1199 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1200 dijit.byId('attr-editor-identifier').attr('value', this.store.getValue(row, 'ident'));
1201 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1202 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1204 // set up UI for editing
1205 dojo.byId('vl-create-attr-editor-button').click();
1208 function vlSaveAttrDefinition(data) {
1209 idHide('vl-attr-editor-div');
1210 idShow('vl-generic-progress');
1212 data.id = ATTR_EDIT_ID;
1214 // this ought to honour custom xpaths, but overwrite xpaths
1215 // derived from tags/subfields.
1216 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1217 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1218 data.xpath = _xpath;
1221 // build up our permacrud params. Key variables here are
1222 // "create or update" and "bib or auth".
1224 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1225 var isCreate = (ATTR_EDIT_ID == null);
1226 var rad = isAuth ? new vqarad() : new vqbrad() ;
1227 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1228 + (isAuth ? 'vqarad' : 'vqbrad');
1229 var _data = rad.fromStoreItem(data);
1233 fieldmapper.standardRequest(
1234 ['open-ils.permacrud', method],
1236 params: [authtoken, _data ],
1237 onresponse: function(r) { },
1238 oncomplete: function(r) {
1239 attrEditorFetchAttrDefs(vlShowAttrEditor);
1240 ATTR_EDIT_ID = null;
1242 onerror: function(r) {
1243 alert('vlSaveAttrDefinition comms error: ' + r);
1249 function attrEditorFetchAttrDefs(callback) {
1250 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1251 return fn(callback);
1254 function vlAttrDelete() {
1255 idHide('vl-attr-editor-div');
1256 idShow('vl-generic-progress');
1258 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1259 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1260 var rad = isAuth ? new vqarad() : new vqbrad() ;
1261 fieldmapper.standardRequest(
1262 ['open-ils.permacrud', method],
1264 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1265 oncomplete: function() {
1266 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1267 attrEditorFetchAttrDefs(vlShowAttrEditor);
1268 ATTR_EDIT_ID = null;
1270 onerror: function(r) {
1271 alert('vlAttrDelete comms error: ' + r);
1277 // ------------------------------------------------------------
1278 // utilities for attribute editors
1280 // dom utilities (maybe dojo does these, and these should be replaced)
1282 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1283 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1284 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1286 function connectTooltip(fieldId) {
1287 // Given an element id, look up a tooltip element in the doc (same
1288 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1289 // a better way to do this?
1290 var fld = dojo.byId(fieldId);
1291 var tip = dojo.byId(fieldId + '-tip');
1292 dojo.connect(fld, 'onfocus', function(evt) {
1293 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1294 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1299 var xpathParser = new openils.MarcXPathParser();
1301 function tagAndSubFieldsToXpath(tags, subfields) {
1302 // given tags, and subfields, build up an XPath.
1305 'tags':tags.match(/[\d]+/g),
1306 'subfields':subfields.match(/[a-zA-z]/g) };
1307 return xpathParser.compile(parts);
1309 return {'parts':null, 'tags':null, 'error':err};
1313 function looksLikeDerivedXpath(path) {
1314 // Does this path look like it was derived from tags and subfields?
1315 var parsed = xpathParser.parse(path);
1316 if (parsed.tags == null)
1318 var compiled = xpathParser.compile(parsed);
1319 return (path == compiled);
1322 // amazing xpath-util unit-tests
1323 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1324 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');
1328 var profileContextOrg
1329 function vlShowProfileEditor() {
1330 displayGlobalDiv('vl-profile-editor-div');
1333 var connect = function() {
1334 dojo.connect(profileContextOrgSelector, 'onChange',
1336 profileContextOrg = this.attr('value');
1343 new openils.User().buildPermOrgSelector(
1344 'ADMIN_MERGE_PROFILE', profileContextOrgSelector, null, connect);
1347 function buildProfileGrid() {
1349 if(profileContextOrg == null)
1350 profileContextOrg = openils.User.user.ws_ou();
1353 {order_by : {vmp : 'name'}},
1354 {owner : fieldmapper.aou.fullPath(profileContextOrg, true)}
1358 /* --- Import Item Attr Grid --------------- */
1360 var itemAttrContextOrg;
1361 function vlShowImportItemAttrEditor() {
1362 displayGlobalDiv('vl-item-attr-editor-div');
1363 buildImportItemAttrGrid();
1365 var connect = function() {
1366 dojo.connect(itemAttrContextOrgSelector, 'onChange',
1368 itemAttrContextOrg = this.attr('value');
1369 itemAttrGrid.resetStore();
1370 vlShowImportItemAttrEditor();
1375 new openils.User().buildPermOrgSelector(
1376 'ADMIN_IMPORT_ITEM_ATTR_DEF',
1377 itemAttrContextOrgSelector, null, connect);
1380 function buildImportItemAttrGrid() {
1382 if(itemAttrContextOrg == null)
1383 itemAttrContextOrg = openils.User.user.ws_ou();
1385 itemAttrGrid.loadAll(
1386 {order_by : {viiad : 'name'}},
1387 {owner : fieldmapper.aou.fullPath(itemAttrContextOrg, true)}