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');
46 dojo.require('openils.widget.ProgressDialog');
47 dojo.require('dojox.form.CheckedMultiSelect');
51 'vl-generic-progress',
52 'vl-generic-progress-with-total',
57 'vl-queue-select-div',
58 'vl-marc-upload-status-div',
61 'vl-profile-editor-div',
62 'vl-item-attr-editor-div',
67 var VANDELAY_URL = '/vandelay-upload';
69 var authAttrDefs = [];
70 var queuedRecords = [];
71 var queuedRecordsMap = {};
72 var bibAttrsFetched = false;
73 var authAttrsFetched = false;
74 var attrDefMap = {}; // maps attr def code names to attr def ids
76 var currentQueueId = null;
78 var currentMatchedRecords; // set of loaded matched bib records
79 var currentOverlayRecordsMap; // map of import record to overlay record
80 var currentOverlayRecordsMapGid; // map of import record to overlay record grid id
81 var currentImportRecId; // when analyzing matches, this is the current import record
82 var userBibQueues = []; // only non-complete queues
83 var userAuthQueues = []; // only non-complete queues
85 var allUserAuthQueues;
86 var selectableGridRecords;
87 var cgi = new openils.CGI();
88 var vlQueueGridColumePicker = {};
89 var vlBibSources = [];
90 var importItemDefs = [];
91 var matchSets = {biblio : [], authority : []};
92 var mergeProfiles = [];
93 var copyStatusCache = {};
94 var copyLocationCache = {};
100 const DEFAULT_MATCH_SET = 'vandelay.default_match_set';
107 dojo.requireLocalization("openils.vandelay", "vandelay");
108 localeStrings = dojo.i18n.getLocalization("openils.vandelay", "vandelay");
110 authtoken = openils.User.authtoken;
111 var initNeeded = 9; // how many async responses do we need before we're init'd
112 var initCount = 0; // how many async reponses we've received
114 openils.Util.registerEnterHandler(
115 vlQueueDisplayPage.domNode, function(){retrieveQueuedRecords();});
116 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
118 function checkInitDone() {
120 if(initCount == initNeeded)
121 runStartupCommands();
124 mergeProfiles = new openils.PermaCrud().retrieveAll('vmp');
125 vlUploadMergeProfile.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
126 vlUploadMergeProfile.labelAttr = 'name';
127 vlUploadMergeProfile.searchAttr = 'name';
128 vlUploadMergeProfile.startup();
130 vlUploadMergeProfile2.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
131 vlUploadMergeProfile2.labelAttr = 'name';
132 vlUploadMergeProfile2.searchAttr = 'name';
133 vlUploadMergeProfile2.startup();
135 vlUploadFtMergeProfile.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
136 vlUploadFtMergeProfile.labelAttr = 'name';
137 vlUploadFtMergeProfile.searchAttr = 'name';
138 vlUploadFtMergeProfile.startup();
140 vlUploadFtMergeProfile2.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
141 vlUploadFtMergeProfile2.labelAttr = 'name';
142 vlUploadFtMergeProfile2.searchAttr = 'name';
143 vlUploadFtMergeProfile2.startup();
146 // Fetch the bib and authority attribute definitions
147 vlFetchBibAttrDefs(function () { checkInitDone(); });
148 vlFetchAuthAttrDefs(function () { checkInitDone(); });
150 vlRetrieveQueueList('bib', null,
152 allUserBibQueues = list;
153 for(var i = 0; i < allUserBibQueues.length; i++) {
154 if(allUserBibQueues[i].complete() == 'f')
155 userBibQueues.push(allUserBibQueues[i]);
161 vlRetrieveQueueList('auth', null,
163 allUserAuthQueues = list;
164 for(var i = 0; i < allUserAuthQueues.length; i++) {
165 if(allUserAuthQueues[i].complete() == 'f')
166 userAuthQueues.push(allUserAuthQueues[i]);
172 fieldmapper.standardRequest(
173 ['open-ils.permacrud', 'open-ils.permacrud.search.cbs.atomic'],
175 params: [authtoken, {id:{"!=":null}}, {order_by:{cbs:'id'}}],
176 oncomplete : function(r) {
177 vlBibSources = openils.Util.readResponse(r, false, true);
183 var owner = fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(new openils.User().user.ws_ou()));
184 new openils.PermaCrud().search('viiad',
185 {owner: owner.map(function(org) { return org.id(); })},
187 oncomplete: function(r) {
188 importItemDefs = openils.Util.readResponse(r);
194 new openils.PermaCrud().search('vms',
195 {owner: owner.map(function(org) { return org.id(); })},
197 oncomplete: function(r) {
198 var sets = openils.Util.readResponse(r);
201 if(!matchSets[set.mtype()])
202 matchSets[set.mtype()] = [];
203 matchSets[set.mtype()].push(set);
211 new openils.PermaCrud().retrieveAll('ccs',
213 oncomplete: function(r) {
214 var stats = openils.Util.readResponse(r);
216 function(stat){copyStatusCache[stat.id()] = stat});
222 new openils.PermaCrud().search('vibtg',
223 { always_apply : 'f',
224 owner: owner.map(function(org) { return org.id(); })
226 { order_by : {vibtg : ['label']},
228 oncomplete: function(r) {
229 trashGroups = openils.Util.readResponse(r);
231 if (trashGroups.length == 0) {
232 openils.Util.hide('vl-trash-groups-row');
233 openils.Util.hide('vl-trash-groups-row2');
238 dojo.forEach(trashGroups, function(grp) {
239 var sn = fieldmapper.aou.findOrgUnit(grp.owner()).shortname();
241 label : grp.label() + ' (' + sn + ')',
244 vlUploadTrashGroups.addOption(opt);
245 vlUploadTrashGroups2.addOption(opt);
253 orgSettings = fieldmapper.aou.fetchOrgSettingBatch(openils.User.user.ws_ou(), [
256 for(k in orgSettings)
258 orgSettings[k] = orgSettings[k].value;
265 openils.Util.addOnLoad(vlInit);
268 // fetch the bib and authority attribute definitions
270 function vlFetchBibAttrDefs(postcomplete) {
272 fieldmapper.standardRequest(
273 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
275 params: [authtoken, {id:{'!=':null}}],
276 onresponse: function(r) {
277 var def = r.recv().content();
278 if(e = openils.Event.parse(def[0]))
280 bibAttrDefs.push(def);
282 oncomplete: function() {
283 bibAttrDefs = bibAttrDefs.sort(
285 if(a.id() > b.id()) return 1;
286 if(a.id() < b.id()) return -1;
296 function vlFetchAuthAttrDefs(postcomplete) {
298 fieldmapper.standardRequest(
299 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
301 params: [authtoken, {id:{'!=':null}}],
302 onresponse: function(r) {
303 var def = r.recv().content();
304 if(e = openils.Event.parse(def[0]))
306 authAttrDefs.push(def);
308 oncomplete: function() {
309 authAttrDefs = authAttrDefs.sort(
311 if(a.id() > b.id()) return 1;
312 if(a.id() < b.id()) return -1;
322 function vlRetrieveQueueList(type, filter, onload) {
323 type = (type == 'bib') ? type : 'authority';
324 fieldmapper.standardRequest(
325 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.owner.retrieve.atomic'],
327 params: [authtoken, null, filter],
328 oncomplete: function(r) {
329 var list = r.recv().content();
330 if(e = openils.Event.parse(list[0]))
339 function displayGlobalDiv(id) {
340 for(var i = 0; i < globalDivs.length; i++) {
342 dojo.style(dojo.byId(globalDivs[i]), 'display', 'none');
344 alert('please define div ' + globalDivs[i]);
347 dojo.style(dojo.byId(id),'display','block');
349 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
350 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
351 openils.Util.removeCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
352 openils.Util.removeCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
353 openils.Util.removeCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
354 openils.Util.removeCSSClass(dojo.byId('vl-menu-match-set-editor'), 'toolbar_selected');
356 if(dojo.byId('vl-match-set-iframe'))
357 dojo.byId('vl-match-set-editor-div').removeChild(dojo.byId('vl-match-set-iframe'));
360 case 'vl-marc-export-div':
361 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
363 case 'vl-marc-upload-div':
364 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
366 case 'vl-queue-select-div':
367 openils.Util.addCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
369 case 'vl-attr-editor-div':
370 openils.Util.addCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
372 case 'vl-profile-editor-div':
373 openils.Util.addCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
375 case 'vl-item-attr-editor-div':
376 openils.Util.addCSSClass(dojo.byId('vl-menu-import-item-attr-editor'), 'toolbar_selected');
378 case 'vl-match-set-editor-div':
379 openils.Util.addCSSClass(dojo.byId('vl-menu-match-set-editor'), 'toolbar_selected');
384 function runStartupCommands() {
385 openils.Util.hide(dojo.byId('vl-page-loading'));
386 openils.Util.show(dojo.byId('vl-body-wrapper'));
387 currentQueueId = cgi.param('qid');
388 currentType = cgi.param('qtype');
389 dojo.style('vl-nav-bar', 'visibility', 'visible');
391 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
392 if (cgi.param('page') == 'inspectq')
393 return vlShowQueueSelect();
399 * asynchronously upload a file of MARC records
401 function uploadMARC(onload){
402 dojo.byId('vl-upload-status-count').innerHTML = '0';
403 dojo.byId('vl-ses-input').value = authtoken;
404 displayGlobalDiv('vl-marc-upload-status-div');
405 dojo.io.iframe.send({
409 form: dojo.byId('vl-marc-upload-form'),
410 handle: function(data,ioArgs){
411 var content = data.documentElement.textContent;
418 * Creates a new vandelay queue
420 function createQueue(queueName, type, onload, importDefId, matchSet) {
421 var name = (type=='bib') ? 'bib' : 'authority';
422 var method = 'open-ils.vandelay.'+ name +'_queue.create'
425 if (vlUploadRecordType.getValue().match(/acq/))
428 console.log('record type ' + vlUploadRecordType.getValue());
429 console.log('record type ' + vlUploadRecordType.getValue());
431 fieldmapper.standardRequest(
432 ['open-ils.vandelay', method],
434 params: [authtoken, queueName, null, qType, matchSet, importDefId],
435 oncomplete : function(r) {
436 var queue = r.recv().content();
437 if(e = openils.Event.parse(queue))
446 * Tells vandelay to pull a batch of records from the cache and explode them
447 * out into the vandelay tables
449 function processSpool(key, queueId, type, onload) {
450 fieldmapper.standardRequest(
451 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
453 params: [authtoken, key, queueId],
454 onresponse : function(r) {
455 var resp = r.recv().content();
456 if(e = openils.Event.parse(resp))
458 dojo.byId('vl-upload-status-count').innerHTML = resp;
460 oncomplete : function(r) {onload();}
465 function vlExportInit() {
468 var qsel = dojo.byId('vl-queue-export-options');
469 qsel.onchange = function(newVal) {
470 var value = qsel.options[qsel.selectedIndex].value;
471 qsel.selectedIndex = 0;
473 if(!confirm('Export as "' + value + '"?')) return; // TODO: i18n
474 retrieveQueuedRecords(
478 exportHandler(value, r);
479 displayGlobalDiv('vl-queue-div');
486 var isel = dojo.byId('vl-item-export-options');
487 isel.onchange = function(newVal) {
488 var value = isel.options[isel.selectedIndex].value;
489 isel.selectedIndex = 0;
491 if(!confirm('Export as "' + value + '"?')) return; // TODO: i18n
493 displayGlobalDiv('vl-generic-progress');
494 var method = 'open-ils.vandelay.import_item.queue.export.' + value + '.atomic';
496 fieldmapper.standardRequest(
497 ['open-ils.vandelay', method],
502 {with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null}
505 oncomplete : function(r) {exportHandler(value, r)}
511 function exportHandler(type, response) {
512 displayGlobalDiv('vl-import-error-div');
514 var content = openils.Util.readResponse(response);
516 if (content==1) { alert('Email sent.'); return; }
519 /* handle .atomic versus non-atomic method calls */
520 content = content.constructor == Array
521 ? content[0].template_output().data()
522 : content.template_output().data();
525 openils.Util.printHtmlString(content);
528 //content = content.replace(/\\t/g,'\t'); // if we really wanted to do .tsv instead
529 openils.XUL.contentToFileSaveDialog(content, null, {
530 defaultString : 'VandelayExport.csv',
531 defaultExtension : '.csv',
533 filterExtension : '*.csv',
538 alert('response = ' + response + '\tcontent:\n' + content);
541 alert('Error exporting data: ' + E);
545 function retrieveQueuedRecords(type, queueId, onload, doExport) {
546 displayGlobalDiv('vl-generic-progress');
548 queuedRecordsMap = {};
549 currentOverlayRecordsMap = {};
550 currentOverlayRecordsMapGid = {};
551 selectableGridRecords = {};
553 if(!type) type = currentType;
554 else currentType = type;
555 if(!queueId) queueId = currentQueueId;
556 else currentQueueId = queueId;
557 if(!onload) onload = handleRetrieveRecords;
559 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve';
561 if(doExport) method += '.export.' + doExport;
562 if(vlQueueGridShowMatches.checked)
563 method = method.replace('records', 'records.matches');
567 var sel = dojo.byId('vl-queue-display-limit-selector');
568 var limit = parseInt(sel.options[sel.selectedIndex].value);
569 var offset = limit * parseInt(vlQueueDisplayPage.attr('value')-1);
571 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit, flesh_import_items:1}];
572 if(vlQueueGridShowNonImport.checked)
573 params[2].non_imported = 1;
575 if(vlQueueGridShowImportErrors.checked)
576 params[2].with_import_error = 1;
578 fieldmapper.standardRequest(
579 ['open-ils.vandelay', method],
582 oncomplete: function(r){
583 if(doExport) return onload(r);
584 var recs = r.recv().content();
585 if(e = openils.Event.parse(recs[0]))
587 for(var i = 0; i < recs.length; i++) {
589 queuedRecords.push(rec);
590 queuedRecordsMap[rec.id()] = rec;
598 function vlLoadMatchUI(recId) {
599 displayGlobalDiv('vl-generic-progress');
600 var queuedRec = queuedRecordsMap[recId];
601 var matches = queuedRec.matches();
603 currentImportRecId = recId;
604 for(var i = 0; i < matches.length; i++)
605 records.push(matches[i].eg_record());
607 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
608 var params = [records];
609 if(currentType == 'auth') {
610 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
611 params = [authtoken, records, {clear_marc:1}];
614 fieldmapper.standardRequest(
618 oncomplete: function(r) {
619 var recs = r.recv().content();
620 if(e = openils.Event.parse(recs))
624 displayGlobalDiv('vl-match-div');
625 resetVlMatchGridLayout();
626 currentMatchedRecords = recs;
627 vlMatchGrid.setStructure(vlMatchGridLayout);
629 // build the data store of records with match information
630 var dataStore = bre.toStoreData(recs, null,
631 {virtualFields:['_id', 'match_score', 'match_quality', 'rec_quality']});
632 dataStore.identifier = '_id';
634 var matchSeenMap = {};
636 for(var i = 0; i < dataStore.items.length; i++) {
637 var item = dataStore.items[i];
638 item._id = i; // just need something unique
639 for(var j = 0; j < matches.length; j++) {
640 var match = matches[j];
641 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
642 if(match.match_score)
643 item.match_score = match.match_score();
644 item.match_quality = match.quality();
645 item.rec_quality = queuedRec.quality();
646 matchSeenMap[match.id()] = 1;
652 // now populate the grid
653 vlPopulateMatchGrid(vlMatchGrid, dataStore);
659 function vlPopulateMatchGrid(grid, data) {
660 var store = new dojo.data.ItemFileReadStore({data:data});
661 grid.setStore(store);
665 function showMe(id) {
666 dojo.style(dojo.byId(id), 'display', 'block');
668 function hideMe(id) {
669 dojo.style(dojo.byId(id), 'display', 'none');
673 function vlLoadMARCHtml(recId, inCat, oncomplete) {
674 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
675 displayGlobalDiv('vl-generic-progress');
677 var params = [recId, 1];
680 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
681 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
682 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
683 if(currentType == 'auth')
684 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
686 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
687 dijit.byId('vl-marc-html-edit-button').onClick =
688 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
689 params = [authtoken, recId];
690 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
691 if(currentType == 'auth')
692 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
695 fieldmapper.standardRequest(
699 oncomplete: function(r) {
700 displayGlobalDiv('vl-marc-html-div');
701 var html = r.recv().content();
702 dojo.byId('vl-marc-record-html').innerHTML = html;
710 function getRecMatchesFromAttrCode(rec, attrCode) {
712 var attr = getRecAttrFromCode(rec, attrCode);
713 for(var j = 0; j < rec.matches().length; j++) {
714 var match = rec.matches()[j];
715 if(match.matched_attr() == attr.id())
723 function getRecAttrFromMatch(rec, match) {
724 for(var i = 0; i < rec.attributes().length; i++) {
725 var attr = rec.attributes()[i];
726 if(attr.id() == match.matched_attr())
732 function getRecAttrDefFromAttr(attr, type) {
733 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
734 for(var i = 0; i < defs.length; i++) {
736 if(def.id() == attr.field())
741 function getRecAttrFromCode(rec, attrCode) {
742 var defId = attrDefMap[currentType][attrCode];
743 var attrs = rec.attributes();
744 for(var i = 0; i < attrs.length; i++) {
746 if(attr.field() == defId)
752 function vlGetViewMatches(rowIdx, item) {
754 var id = this.grid.store.getValue(item, 'id');
755 var rec = queuedRecordsMap[id];
756 if(rec.matches().length > 0)
757 return id + ':' + rec.matches().length;
762 function vlFormatViewMatches(id) {
763 if(id == -1) return '';
764 var chunks = id.split(':');
767 return '<a href="javascript:void(0);" onclick="vlLoadMatchUI(' + id + ');">' + this.name + ' (' + count + ')</a>';
770 function vlGetViewErrors(rowIdx, item) {
772 var id = this.grid.store.getValue(item, 'id');
773 var rec = queuedRecordsMap[id];
774 // id:rec_error:item_import_error_count
776 (rec.import_error() ? 1 : '') + ':' +
777 (typeof rec.import_items == 'function'
778 ? rec.import_items().filter(function(i) {return i.import_error()}).length
785 function vlFormatViewErrors(chunk) {
786 if(chunk == -1) return '';
787 var id = chunk.split(':')[0];
788 var rec = chunk.split(':')[1];
789 var count = chunk.split(':')[2];
792 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Record</a><br/>'; // TODO I18N
794 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Items ('+count+')</a>'; // TODO I18N
798 //var vlItemErrorColumnPicker;
799 function vlLoadErrorUI(id) {
801 displayGlobalDiv('vl-import-error-div');
802 openils.Util.hide('vl-import-error-grid-all');
803 openils.Util.show('vl-import-error-record');
805 var rec = queuedRecordsMap[id];
807 dojo.byId('vl-error-id').innerHTML = rec.id();
808 dojo.forEach( // TODO sane authority rec. fields
809 ['title', 'author', 'isbn', 'issn', 'upc'],
811 var attr = getRecAttrFromCode(rec, field);
812 var eid = 'vl-error-' + field;
814 openils.Util.show(dojo.byId(eid).parentNode, 'table-row');
815 dojo.byId(eid).innerHTML = attr.attr_value();
817 openils.Util.hide(dojo.byId(eid).parentNode);
821 var iediv = dojo.byId('vl-error-import-error');
822 var eddiv = dojo.byId('vl-error-error-detail');
823 if(rec.import_error()) {
824 openils.Util.show(iediv.parentNode, 'table-row');
825 openils.Util.show(eddiv.parentNode, 'table-row');
826 iediv.innerHTML = rec.import_error();
827 eddiv.innerHTML = rec.error_detail();
829 openils.Util.hide(iediv.parentNode);
830 openils.Util.hide(eddiv.parentNode);
833 var errorItems = rec.import_items().filter(function(i) {return i.import_error()});
834 if(errorItems.length) {
835 openils.Util.show('vl-import-error-grid-some');
836 storeData = vqbr.toStoreData(errorItems);
837 var store = new dojo.data.ItemFileReadStore({data:storeData});
838 vlImportErrorGrid.setStore(store);
839 vlImportErrorGrid.update();
841 openils.Util.hide('vl-import-error-grid-some');
845 function vlLoadErrorUIAll() {
847 displayGlobalDiv('vl-import-error-div');
848 openils.Util.hide('vl-import-error-grid-some');
849 openils.Util.hide('vl-import-error-record');
850 openils.Util.show('vl-import-error-grid-all');
851 vlAllImportErrorGrid.resetStore();
853 vlImportErrorGrid.displayOffset = 0;
855 vlAllImportErrorGrid.dataLoader = function() {
857 vlAllImportErrorGrid.showLoadProgressIndicator();
859 fieldmapper.standardRequest(
860 ['open-ils.vandelay', 'open-ils.vandelay.import_item.queue.retrieve'],
864 authtoken, currentQueueId, {
865 with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null,
866 offset : vlAllImportErrorGrid.displayOffset,
867 limit : vlAllImportErrorGrid.displayLimit
870 onresponse : function(r) {
871 var item = openils.Util.readResponse(r);
873 vlAllImportErrorGrid.store.newItem(vii.toStoreItem(item));
875 oncomplete : function() {
876 vlAllImportErrorGrid.hideLoadProgressIndicator();
882 vlAllImportErrorGrid.dataLoader();
885 function vlGetOrg(rowIdx, item) {
887 var value = this.grid.store.getValue(item, this.field);
888 if(value) return fieldmapper.aou.findOrgUnit(value).shortname();
892 function vlCopyStatus(rowIdx, item) {
894 var value = this.grid.store.getValue(item, this.field);
895 if(value) return copyStatusCache[value].name();
899 // Note, we don't pre-fetch all copy locations because there could be
900 // a lot of them. Instead, fetch-and-cache on demand.
901 function vlCopyLocation(rowIdx, item) {
903 var value = this.grid.store.getValue(item, this.field);
905 if(!copyLocationCache[value]) {
906 copyLocationCache[value] =
907 new openils.PermaCrud().retrieve('acpl', value);
909 return copyLocationCache[value].name();
915 function vlFormatViewMatchMARC(id) {
916 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', true, '+
917 'function(){displayGlobalDiv(\'vl-match-div\');});">' + this.name + '</a>';
920 function getAttrValue(rowIdx, item) {
922 var attrCode = this.field.split('.')[1];
923 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
924 var attr = getRecAttrFromCode(rec, attrCode);
925 return (attr) ? attr.attr_value() : '';
928 function vlGetDateTimeField(rowIdx, item) {
930 var value = this.grid.store.getValue(item, this.field);
931 if(!value) return '';
932 var date = dojo.date.stamp.fromISOString(value);
933 return dojo.date.locale.format(date, {selector:'date'});
936 function vlGetCreator(rowIdx, item) {
938 var id = this.grid.store.getValue(item, 'creator');
940 return userCache[id].usrname();
941 var user = fieldmapper.standardRequest(
942 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
943 if(e = openils.Event.parse(user))
945 userCache[id] = user;
946 return user.usrname();
949 function vlGetViewMARC(rowIdx, item) {
950 return item && this.grid.store.getValue(item, 'id');
953 function vlFormatViewMARC(id) {
954 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
955 'function(){displayGlobalDiv(\'vl-queue-div\');});">' + this.name + '</a>';
958 function vlGetOverlayTargetSelector(rowIdx, item) {
960 return this.grid.store.getValue(item, '_id') + ':' + this.grid.store.getValue(item, 'id');
963 function vlFormatOverlayTargetSelector(val) {
965 var parts = val.split(':');
968 var value = '<input type="checkbox" name="vl-overlay-target-RECID" '+
969 'onclick="vlHandleOverlayTargetSelected(ID, GRIDID);" gridid="GRIDID" match="ID"/>';
970 value = value.replace(/GRIDID/g, _id);
971 value = value.replace(/RECID/g, currentImportRecId);
972 value = value.replace(/ID/g, id);
973 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
974 return value.replace('/>', 'checked="checked"/>');
980 * see if the user has enabled overlays for the current match set and,
981 * if so, map the current import record to the overlay target.
983 function vlHandleOverlayTargetSelected(recId, gridId) {
984 var noneSelected = true;
985 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
986 for(var i = 0; i < checkboxes.length; i++) {
987 var checkbox = checkboxes[i];
988 var matchRecId = checkbox.getAttribute('match');
989 var gid = checkbox.getAttribute('gridid');
990 if(checkbox.checked) {
991 if(matchRecId == recId && gid == gridId) {
992 noneSelected = false;
993 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
994 currentOverlayRecordsMapGid[currentImportRecId] = gid;
995 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
996 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
998 checkbox.checked = false;
1004 delete currentOverlayRecordsMap[currentImportRecId];
1005 delete currentOverlayRecordsMapGid[currentImportRecId];
1006 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
1007 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
1011 var valLastQueueType = null;
1012 var vlQueueGridLayout = null;
1013 function buildRecordGrid(type) {
1014 displayGlobalDiv('vl-queue-div');
1016 vlBibQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
1017 vlAuthQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
1020 openils.Util.show('vl-bib-queue-grid-wrapper');
1021 openils.Util.hide('vl-auth-queue-grid-wrapper');
1022 vlQueueGrid = vlBibQueueGrid;
1023 openils.Util.show('add-to-bucket-action', 'table-row');
1025 openils.Util.show('vl-auth-queue-grid-wrapper');
1026 openils.Util.hide('vl-bib-queue-grid-wrapper');
1027 vlQueueGrid = vlAuthQueueGrid;
1028 openils.Util.hide('add-to-bucket-action');
1032 if(valLastQueueType != type) {
1033 valLastQueueType = type;
1034 vlQueueGridLayout = vlQueueGrid.attr('structure');
1035 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
1036 attrDefMap[type] = {};
1037 for(var i = 0; i < defs.length; i++) {
1039 attrDefMap[type][def.code()] = def.id();
1041 name:def.description(),
1042 field:'attr.' + def.code(),
1044 selectableColumn:true
1046 vlQueueGridLayout[0].cells[0].push(col);
1050 dojo.forEach(vlQueueGridLayout[0].cells[0],
1052 if(cell.field.match(/^\+/))
1053 cell.nonSelectable=true;
1059 storeData = vqbr.toStoreData(queuedRecords);
1061 storeData = vqar.toStoreData(queuedRecords);
1063 var store = new dojo.data.ItemFileReadStore({data:storeData});
1064 vlQueueGrid.setStore(store);
1066 if(vlQueueGridColumePicker[type]) {
1067 vlQueueGrid.update();
1070 vlQueueGridColumePicker[type] =
1071 new openils.widget.GridColumnPicker(
1072 authtoken, 'vandelay.queue.'+type, vlQueueGrid, vlQueueGridLayout);
1073 vlQueueGridColumePicker[type].load();
1077 function vlQueueGridPrevPage() {
1078 var page = parseInt(vlQueueDisplayPage.getValue());
1079 if(page < 2) return;
1080 vlQueueDisplayPage.setValue(page - 1);
1081 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1084 function vlQueueGridNextPage() {
1085 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
1086 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1089 function vlDeleteQueue(type, queueId, onload) {
1090 fieldmapper.standardRequest(
1091 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
1093 params: [authtoken, queueId],
1094 oncomplete: function(r) {
1095 var resp = r.recv().content();
1096 if(e = openils.Event.parse(resp))
1105 function vlQueueGridDrawSelectBox(rowIdx, item) {
1106 return item && this.grid.store.getValue(item, 'id');
1109 function vlQueueGridFormatSelectBox(id) {
1110 var domId = 'vl-record-list-selected-' + id;
1111 if (id) { selectableGridRecords[domId] = id; }
1112 return "<div><input type='checkbox' id='"+domId+"'/></div>";
1115 function vlSelectAllQueueGridRecords() {
1116 for(var id in selectableGridRecords)
1117 dojo.byId(id).checked = true;
1119 function vlSelectNoQueueGridRecords() {
1120 for(var id in selectableGridRecords)
1121 dojo.byId(id).checked = false;
1123 function vlToggleQueueGridSelect() {
1124 if(dojo.byId('vl-queue-grid-row-selector').checked)
1125 vlSelectAllQueueGridRecords();
1127 vlSelectNoQueueGridRecords();
1130 var handleRetrieveRecords = function() {
1131 buildRecordGrid(currentType);
1132 vlFetchQueueSummary(currentQueueId, currentType,
1134 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
1135 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
1136 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
1137 dojo.byId('vl-queue-summary-import-item-count').innerHTML = summary.total_items + '';
1138 dojo.byId('vl-queue-summary-import-item-imported-count').innerHTML = summary.total_items_imported + '';
1139 dojo.byId('vl-queue-summary-rec-error-count').innerHTML = summary.rec_import_errors + '';
1140 dojo.byId('vl-queue-summary-item-error-count').innerHTML = summary.item_import_errors + '';
1142 if (dojo.byId('create-bucket-dialog-name')) {
1143 dojo.byId('create-bucket-dialog-name').value = summary.queue.name();
1149 function vlFetchQueueSummary(qId, type, onload) {
1150 fieldmapper.standardRequest(
1151 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
1153 params: [authtoken, qId],
1154 oncomplete : function(r) {
1155 var summary = r.recv().content();
1156 if(e = openils.Event.parse(summary))
1158 return onload(summary);
1164 function handleCreateBucket(args) {
1165 var bname = dojo.byId('create-bucket-dialog-name').value;
1168 progressDialog.show(true);
1169 fieldmapper.standardRequest(
1170 ['open-ils.vandelay', 'open-ils.vandelay.bib_queue.to_bucket'],
1172 params : [authtoken, currentQueueId, bname],
1173 oncomplete : function(r) {
1174 progressDialog.hide();
1175 setTimeout(function() {
1176 var resp = openils.Util.readResponse(r);
1177 if (resp.add_count == 0) {
1178 alert(localeStrings.NO_BUCKET_ITEMS);
1181 dojo.string.substitute(
1182 localeStrings.BUCKET_CREATE_SUCCESS,
1183 [resp.add_count, bname, resp.item_count]
1187 }, 200); // give the dialog a chance to hide
1194 var _importCancelHandler;
1195 var _importGoHandler;
1196 function vlHandleQueueItemsAction(action) {
1198 if(_importCancelHandler) dojo.disconnect(_importCancelHandler);
1200 _importCancelHandler = dojo.connect(
1201 queueItemsImportCancelButton,
1204 queueItemsImportDialog.hide();
1208 if(_importGoHandler)
1209 dojo.disconnect(_importGoHandler);
1211 _importGoHandler = dojo.connect(
1212 queueItemsImportGoButton,
1215 queueItemsImportDialog.hide();
1217 // hack to set the widgets the import funcs will be looking at. Reset them below.
1218 vlUploadQueueImportNoMatch.attr('value', vlUploadQueueImportNoMatch2.attr('value'));
1219 vlUploadQueueAutoOverlayExact.attr('value', vlUploadQueueAutoOverlayExact2.attr('value'));
1220 vlUploadQueueAutoOverlay1Match.attr('value', vlUploadQueueAutoOverlay1Match2.attr('value'));
1221 vlUploadMergeProfile.attr('value', vlUploadMergeProfile2.attr('value'));
1222 vlUploadFtMergeProfile.attr('value', vlUploadFtMergeProfile2.attr('value'));
1223 vlUploadQueueAutoOverlayBestMatch.attr('value', vlUploadQueueAutoOverlayBestMatch2.attr('value'));
1224 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', vlUploadQueueAutoOverlayBestMatchRatio2.attr('value'));
1226 // attr('value') and various other incantations won't let me set
1227 // the value on the checkedmultiselect, so we temporarily swap
1228 // the dijits instead.
1229 var tmpTrashGroup = vlUploadTrashGroups;
1230 vlUploadTrashGroups = vlUploadTrashGroups2;
1232 if(action == 'import') {
1233 vlImportSelectedRecords();
1234 } else if(action == 'import_all') {
1235 vlImportAllRecords();
1238 // reset the widgets to prevent accidental future actions
1239 vlUploadQueueImportNoMatch.attr('value', false);
1240 vlUploadQueueImportNoMatch2.attr('value', false);
1241 vlUploadQueueAutoOverlayExact.attr('value', false);
1242 vlUploadQueueAutoOverlayExact2.attr('value', false);
1243 vlUploadQueueAutoOverlay1Match.attr('value', false);
1244 vlUploadQueueAutoOverlay1Match2.attr('value', false);
1245 vlUploadMergeProfile.attr('value', '');
1246 vlUploadMergeProfile2.attr('value', '');
1247 vlUploadFtMergeProfile.attr('value', '');
1248 vlUploadFtMergeProfile2.attr('value', '');
1249 vlUploadTrashGroups.attr('value', '');
1250 vlUploadTrashGroups2.attr('value', '');
1251 vlUploadQueueAutoOverlayBestMatch.attr('value', false);
1252 vlUploadQueueAutoOverlayBestMatch2.attr('value', false);
1253 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', '0.0');
1254 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', '0.0');
1256 // and... swap them back
1257 vlUploadTrashGroups2 = vlUploadTrashGroups;
1258 vlUploadTrashGroups = tmpTrashGroup;
1262 if (currentType.match(/auth/) || trashGroups.length == 0) {
1263 openils.Util.hide('vl-trash-groups-row2');
1265 openils.Util.show('vl-trash-groups-row2', 'table-row');
1268 queueItemsImportDialog.show();
1271 /* import user-selected records */
1272 function vlImportSelectedRecords() {
1275 for(var id in selectableGridRecords) {
1276 if(dojo.byId(id).checked) {
1277 var recId = selectableGridRecords[id];
1278 var rec = queuedRecordsMap[recId];
1279 if(!rec.import_time())
1280 records.push(recId);
1284 vlImportRecordQueue(
1289 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1294 /* import all (non-imported) queue records */
1295 function vlImportAllRecords() {
1296 vlImportRecordQueue(
1301 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1306 /* if recList has values, import only those records */
1307 function vlImportRecordQueue(type, queueId, recList, onload) {
1308 displayGlobalDiv('vl-generic-progress-with-total');
1310 /* set up options */
1311 var options = {overlay_map : currentOverlayRecordsMap};
1313 if(vlUploadQueueImportNoMatch.checked) {
1314 options.import_no_match = true;
1315 vlUploadQueueImportNoMatch.checked = false;
1318 if(vlUploadQueueAutoOverlayExact.checked) {
1319 options.auto_overlay_exact = true;
1320 vlUploadQueueAutoOverlayExact.checked = false;
1323 if(vlUploadQueueAutoOverlayBestMatch.checked) {
1324 options.auto_overlay_best_match = true;
1325 vlUploadQueueAutoOverlayBestMatch.checked = false;
1326 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1329 if(vlUploadQueueAutoOverlay1Match.checked) {
1330 options.auto_overlay_1match = true;
1331 vlUploadQueueAutoOverlay1Match.checked = false;
1332 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1335 var profile = vlUploadMergeProfile.attr('value');
1336 if(profile != null && profile != '') {
1337 options.merge_profile = profile;
1340 var ftprofile = vlUploadFtMergeProfile.attr('value');
1341 if(ftprofile != null && ftprofile != '') {
1342 options.fall_through_merge_profile = ftprofile;
1345 var strip_grps = vlUploadTrashGroups.attr('value');
1346 if (strip_grps != null && strip_grps.length) {
1347 options.strip_field_groups = strip_grps;
1350 /* determine which method we're calling */
1352 var method = 'open-ils.vandelay.bib_queue.import';
1354 method = method.replace('bib', 'auth');
1356 var params = [authtoken, queueId, options];
1358 method = 'open-ils.vandelay.'+currentType+'_record.list.import';
1359 params[1] = recList;
1362 fieldmapper.standardRequest(
1363 ['open-ils.vandelay', method],
1366 onresponse: function(r) {
1367 var resp = r.recv().content();
1368 if(e = openils.Event.parse(resp))
1370 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
1372 oncomplete: function() {onload();}
1379 * Create queue, upload MARC, process spool, load the newly created queue
1381 function batchUpload() {
1382 var queueName = dijit.byId('vl-queue-name').getValue();
1383 currentType = dijit.byId('vl-record-type').getValue();
1385 // could be bib-acq, which makes no sense in most places
1386 if (currentType.match(/bib/)) currentType = 'bib';
1388 var handleProcessSpool = function() {
1390 vlUploadQueueImportNoMatch.checked ||
1391 vlUploadQueueAutoOverlayExact.checked ||
1392 vlUploadQueueAutoOverlay1Match.checked ||
1393 vlUploadQueueAutoOverlayBestMatch.checked ) {
1395 vlImportRecordQueue(
1400 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1404 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1408 var handleUploadMARC = function(key) {
1409 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
1410 processSpool(key, currentQueueId, currentType, handleProcessSpool);
1413 var handleCreateQueue = function(queue) {
1414 currentQueueId = queue.id();
1415 uploadMARC(handleUploadMARC);
1418 if(vlUploadQueueSelector.getValue() && !queueName) {
1419 currentQueueId = vlUploadQueueSelector.getValue();
1420 uploadMARC(handleUploadMARC);
1422 createQueue(queueName, currentType, handleCreateQueue,
1423 vlUploadQueueHoldingsImportProfile.attr('value'),
1424 vlUploadQueueMatchSet.attr('value')
1429 // Inspect Queue no longer uses stores, so put type matching here instead
1430 function vlGetQueueData(type, asStore) {
1436 if(!filter) filter = 'bib';
1437 var bibList = allUserBibQueues.filter(
1439 return (q.queue_type() == filter);
1442 if (!asStore) return bibList;
1443 return vbq.toStoreData(bibList);
1445 if (!asStore) return allUserAuthQueues;
1446 return vaq.toStoreData(allUserAuthQueues);
1450 function vlFleshQueueSelect(selector, type) {
1451 var data = vlGetQueueData(type, true);
1452 selector.store = new dojo.data.ItemFileReadStore({data:data});
1453 selector.setValue(null);
1454 selector.setDisplayedValue('');
1456 selector.setValue(data[0].id());
1458 var qInput = dijit.byId('vl-queue-name');
1460 var selChange = function(val) {
1461 console.log('selector onchange');
1462 // user selected a queue from the selector; clear the input and
1463 // set the item import profile already defined for the queue
1464 var queue = allUserBibQueues.filter(function(q) { return (q.id() == val) })[0];
1466 vlUploadQueueHoldingsImportProfile.attr('value', queue.item_attr_def() || '');
1467 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
1468 vlUploadQueueMatchSet.attr('value', queue.match_set() || '');
1469 vlUploadQueueMatchSet.attr('disabled', true);
1471 vlUploadQueueHoldingsImportProfile.attr('value', '');
1472 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1473 vlUploadQueueMatchSet.attr('value', '');
1474 vlUploadQueueMatchSet.attr('disabled', false);
1476 dojo.disconnect(qInput._onchange);
1477 qInput.attr('value', '');
1478 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1481 var inputChange = function(val) {
1482 console.log('qinput onchange');
1483 // user entered a new queue name. clear the selector
1484 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1485 vlUploadQueueMatchSet.attr('disabled', false);
1486 dojo.disconnect(selector._onchange);
1487 selector.attr('value', '');
1488 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1491 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1492 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1495 function vlUpdateMatchSetSelector(type) {
1496 type = (type.match(/bib/)) ? 'biblio' : 'authority';
1497 vlUploadQueueMatchSet.store =
1498 new dojo.data.ItemFileReadStore({data:vms.toStoreData(matchSets[type])});
1499 // apply default match set
1500 for (var i = 0; i < matchSets[type].length; i++) {
1501 if (matchSets[type][i].id() == orgSettings[DEFAULT_MATCH_SET]) {
1502 vlUploadQueueMatchSet.setValue(matchSets[type][i].id());
1508 function vlShowUploadForm() {
1509 displayGlobalDiv('vl-marc-upload-div');
1510 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
1511 vlUploadSourceSelector.store =
1512 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
1513 vlUploadSourceSelector.setValue(vlBibSources[0].id());
1514 vlUploadQueueHoldingsImportProfile.store =
1515 new dojo.data.ItemFileReadStore({data:viiad.toStoreData(importItemDefs)});
1516 vlUpdateMatchSetSelector(vlUploadRecordType.getValue());
1518 if (vlUploadRecordType.attr('value').match(/auth/) || trashGroups.length == 0) {
1519 openils.Util.hide('vl-trash-groups-row');
1521 openils.Util.show('vl-trash-groups-row', 'table-row');
1524 // use ratio from the merge profile if it's set
1526 vlUploadMergeProfile,
1530 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1531 if(profile.lwm_ratio() != null)
1532 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', profile.lwm_ratio()+'');
1536 vlUploadMergeProfile2,
1540 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1541 if(profile.lwm_ratio() != null)
1542 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', profile.lwm_ratio()+'');
1547 function vlDeleteSelectedQueues() {
1548 var checkboxes = document.getElementById('vlQueueSelectList').getElementsByTagName('input');
1549 var type = vlQueueSelectType.attr('value').replace(/-.*/, '');
1550 for(var i = 0; i < checkboxes.length; i++) {
1551 if(checkboxes[i].getAttribute('name') == 'delete' && checkboxes[i].checked) {
1552 vlDeleteQueue(type, checkboxes[i].getAttribute('value'), function () {});
1555 window.location.reload();
1558 function vlShowQueueSelect() {
1559 displayGlobalDiv('vl-queue-select-div');
1560 var type = vlQueueSelectType.attr('value');
1561 var data = vlGetQueueData(type, false);
1562 type = type.replace(/-.*/, ''); // To remove any sub-typeish info.
1563 var tbody = document.getElementById('vlQueueSelectList');
1567 function vlDeleteSelectedQueues() {
1568 var checkboxes = document.getElementById('vlQueueSelectList').getElementsByTagName('input');
1569 var type = vlQueueSelectType.attr('value').replace(/-.*/, '');
1570 for(var i = 0; i < checkboxes.length; i++) {
1571 if(checkboxes[i].getAttribute('name') == 'delete' && checkboxes[i].checked) {
1572 vlDeleteQueue(type, checkboxes[i].getAttribute('value'), function () {});
1575 window.location.reload();
1578 function vlShowQueueSelect() {
1579 displayGlobalDiv('vl-queue-select-div');
1580 var type = vlQueueSelectType.attr('value');
1581 var data = vlGetQueueData(type, false);
1582 type = type.replace(/-.*/, ''); // To remove any sub-typeish info.
1583 var tbody = document.getElementById('vlQueueSelectList');
1585 while(tbody.firstChild) {
1586 tbody.removeChild(tbody.firstChild);
1589 for(var entry in data) {
1590 var name = data[entry].name();
1591 if(!name.match(/\S/))
1593 var tr = document.createElement('tr');
1594 var td = document.createElement('td');
1595 var checkbox = document.createElement('input');
1596 checkbox.setAttribute('type', 'checkbox');
1597 checkbox.setAttribute('name', 'delete');
1598 checkbox.setAttribute('value', data[entry].id());
1599 td.appendChild(checkbox);
1601 td = document.createElement('td');
1602 var a = document.createElement('a');
1603 a.textContent = name;
1604 a.setAttribute('href', "javascript:retrieveQueuedRecords('" + type + "', " + data[entry].id() + ");");
1607 tbody.appendChild(tr);
1611 function vlShowMatchSetEditor() {
1612 displayGlobalDiv('vl-match-set-editor-div');
1613 dojo.byId('vl-match-set-editor-div').appendChild(
1614 dojo.create('iframe', {
1615 id : 'vl-match-set-iframe',
1616 src : oilsBasePath + '/conify/global/vandelay/match_set',
1617 style : 'width:100%; height:500px; border:none; margin:0px;'
1622 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
1624 To run in Firefox directly, must set signed.applets.codebase_principal_support
1625 to true in about:config
1627 win = window.open('/xul/server/cat/marcedit.xul','','chrome'); // XXX version?
1630 if (currentType == 'bib') {
1636 function onsave(r) {
1637 // after the record is saved, reload the HTML display
1638 var stat = r.recv().content();
1639 if(e = openils.Event.parse(stat))
1641 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
1643 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
1647 record : {marc : rec.marc(), "rtype": type},
1649 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
1650 func: function(xmlString) {
1651 var method = 'open-ils.permacrud.update.' + rec.classname;
1652 rec.marc(xmlString);
1653 fieldmapper.standardRequest(
1654 ['open-ils.permacrud', method],
1656 params: [authtoken, rec],
1662 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
1663 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
1667 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
1668 var method = 'open-ils.permacrud.search.vqbr';
1669 if(currentType != 'bib')
1670 method = method.replace(/vqbr/,'vqar');
1672 fieldmapper.standardRequest(
1673 ['open-ils.permacrud', method],
1675 params: [authtoken, {id : recId}],
1676 oncomplete: function(r) {
1677 var rec = r.recv().content();
1678 if(e = openils.Event.parse(rec))
1680 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
1688 //------------------------------------------------------------
1689 // attribute editors
1691 // attribute-editor global variables
1693 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
1694 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
1695 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
1697 function vlAttrEditorInit() {
1698 // set up tooltips on the edit form
1699 connectTooltip('attr-editor-tags');
1700 connectTooltip('attr-editor-subfields');
1703 function vlShowAttrEditor() {
1704 displayGlobalDiv('vl-attr-editor-div');
1705 loadAttrEditorGrid();
1706 idHide('vl-generic-progress');
1709 function setAttrEditorGroup(groupName) {
1710 // put us into 'bib'-attr or 'auth'-attr mode.
1711 if (ATTR_EDIT_GROUP != groupName) {
1712 ATTR_EDIT_GROUP = groupName;
1713 loadAttrEditorGrid();
1717 function onAttrEditorOpen() {
1718 // the "bars" have the create/update/cancel/etc. buttons.
1719 var create_bar = document.getElementById('attr-editor-create-bar');
1720 var update_bar = document.getElementById('attr-editor-update-bar');
1721 if (ATTR_EDITOR_IN_UPDATE_MODE) {
1722 update_bar.style.display='table-row';
1723 create_bar.style.display='none';
1724 // hide the dropdown-button
1725 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
1727 dijit.byId('attr-editor-dialog').reset();
1728 create_bar.style.display='table-row';
1729 update_bar.style.display='none';
1733 function onAttrEditorClose() {
1734 // reset the form to a "create" form. (We may have borrowed it for editing.)
1735 ATTR_EDITOR_IN_UPDATE_MODE = false;
1736 // show the dropdown-button
1737 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
1740 function loadAttrEditorGrid() {
1741 var _data = (ATTR_EDIT_GROUP == 'auth') ?
1742 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
1744 var store = new dojo.data.ItemFileReadStore({data:_data});
1745 attrEditorGrid.setStore(store);
1746 attrEditorGrid.onRowDblClick = onAttrEditorClick;
1747 attrEditorGrid.update();
1750 function attrGridGetTag(n, item) {
1751 // grid helper: return the tags from the row's xpath column.
1752 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
1755 function attrGridGetSubfield(n, item) {
1756 // grid helper: return the subfields from the row's xpath column.
1757 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
1760 function onAttrEditorClick() {
1761 var row = this.getItem(this.focus.rowIndex);
1762 ATTR_EDIT_ID = this.store.getValue(row, 'id');
1763 ATTR_EDITOR_IN_UPDATE_MODE = true;
1765 // populate the popup editor.
1766 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1767 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1768 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1769 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1770 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1771 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1772 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1774 // set up UI for editing
1775 dojo.byId('vl-create-attr-editor-button').click();
1778 function vlSaveAttrDefinition(data) {
1779 idHide('vl-attr-editor-div');
1780 idShow('vl-generic-progress');
1782 data.id = ATTR_EDIT_ID;
1784 // this ought to honour custom xpaths, but overwrite xpaths
1785 // derived from tags/subfields.
1786 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1787 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1788 data.xpath = _xpath;
1791 // build up our permacrud params. Key variables here are
1792 // "create or update" and "bib or auth".
1794 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1795 var isCreate = (ATTR_EDIT_ID == null);
1796 var rad = isAuth ? new vqarad() : new vqbrad() ;
1797 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1798 + (isAuth ? 'vqarad' : 'vqbrad');
1799 var _data = rad.fromStoreItem(data);
1803 fieldmapper.standardRequest(
1804 ['open-ils.permacrud', method],
1806 params: [authtoken, _data ],
1807 onresponse: function(r) { },
1808 oncomplete: function(r) {
1809 attrEditorFetchAttrDefs(vlShowAttrEditor);
1810 ATTR_EDIT_ID = null;
1812 onerror: function(r) {
1813 alert('vlSaveAttrDefinition comms error: ' + r);
1819 function attrEditorFetchAttrDefs(callback) {
1820 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1821 return fn(callback);
1824 function vlAttrDelete() {
1825 idHide('vl-attr-editor-div');
1826 idShow('vl-generic-progress');
1828 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1829 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1830 var rad = isAuth ? new vqarad() : new vqbrad() ;
1831 fieldmapper.standardRequest(
1832 ['open-ils.permacrud', method],
1834 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1835 oncomplete: function() {
1836 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1837 attrEditorFetchAttrDefs(vlShowAttrEditor);
1838 ATTR_EDIT_ID = null;
1840 onerror: function(r) {
1841 alert('vlAttrDelete comms error: ' + r);
1847 // ------------------------------------------------------------
1848 // utilities for attribute editors
1850 // dom utilities (maybe dojo does these, and these should be replaced)
1852 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1853 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1854 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1856 function connectTooltip(fieldId) {
1857 // Given an element id, look up a tooltip element in the doc (same
1858 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1859 // a better way to do this?
1860 var fld = dojo.byId(fieldId);
1861 var tip = dojo.byId(fieldId + '-tip');
1862 dojo.connect(fld, 'onfocus', function(evt) {
1863 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1864 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1869 var xpathParser = new openils.MarcXPathParser();
1871 function tagAndSubFieldsToXpath(tags, subfields) {
1872 // given tags, and subfields, build up an XPath.
1875 'tags':tags.match(/[\d]+/g),
1876 'subfields':subfields.match(/[a-zA-z]/g) };
1877 return xpathParser.compile(parts);
1879 return {'parts':null, 'tags':null, 'error':err};
1883 function looksLikeDerivedXpath(path) {
1884 // Does this path look like it was derived from tags and subfields?
1885 var parsed = xpathParser.parse(path);
1886 if (parsed.tags == null)
1888 var compiled = xpathParser.compile(parsed);
1889 return (path == compiled);
1892 // amazing xpath-util unit-tests
1893 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1894 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');
1898 var profileContextOrg
1899 function vlShowProfileEditor() {
1900 displayGlobalDiv('vl-profile-editor-div');
1903 var connect = function() {
1904 dojo.connect(profileContextOrgSelector, 'onChange',
1906 profileContextOrg = this.attr('value');
1913 new openils.User().buildPermOrgSelector(
1914 'ADMIN_MERGE_PROFILE', profileContextOrgSelector, null, connect);
1917 function buildProfileGrid() {
1919 if(profileContextOrg == null)
1920 profileContextOrg = openils.User.user.ws_ou();
1923 {order_by : {vmp : 'name'}},
1924 {owner : fieldmapper.aou.fullPath(profileContextOrg, true)}
1928 /* --- Import Item Attr Grid --------------- */
1930 var itemAttrContextOrg;
1931 var itemAttrGridFirstTime = true;
1932 function vlShowImportItemAttrEditor() {
1933 displayGlobalDiv('vl-item-attr-editor-div');
1935 if (itemAttrGridFirstTime) {
1937 buildImportItemAttrGrid();
1939 var connect = function() {
1940 dojo.connect(itemAttrContextOrgSelector, 'onChange',
1942 itemAttrContextOrg = this.attr('value');
1943 itemAttrGrid.resetStore();
1944 buildImportItemAttrGrid();
1949 new openils.User().buildPermOrgSelector(
1950 'ADMIN_IMPORT_ITEM_ATTR_DEF',
1951 itemAttrContextOrgSelector, null, connect);
1953 itemAttrGridFirstTime = false;
1957 function buildImportItemAttrGrid() {
1959 if(itemAttrContextOrg == null)
1960 itemAttrContextOrg = openils.User.user.ws_ou();
1962 itemAttrGrid.loadAll(
1963 {order_by : {viiad : 'name'}},
1964 {owner : fieldmapper.aou.fullPath(itemAttrContextOrg, true)}