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',
65 var VANDELAY_URL = '/vandelay-upload';
67 var authAttrDefs = [];
68 var queuedRecords = [];
69 var queuedRecordsMap = {};
70 var bibAttrsFetched = false;
71 var authAttrsFetched = false;
72 var attrDefMap = {}; // maps attr def code names to attr def ids
74 var currentQueueId = null;
76 var currentMatchedRecords; // set of loaded matched bib records
77 var currentOverlayRecordsMap; // map of import record to overlay record
78 var currentOverlayRecordsMapGid; // map of import record to overlay record grid id
79 var currentImportRecId; // when analyzing matches, this is the current import record
80 var userBibQueues = []; // only non-complete queues
81 var userAuthQueues = []; // only non-complete queues
83 var allUserAuthQueues;
84 var selectableGridRecords;
85 var cgi = new openils.CGI();
86 var vlQueueGridColumePicker = {};
87 var vlBibSources = [];
88 var importItemDefs = [];
90 var mergeProfiles = [];
91 var copyStatusCache = {};
92 var copyLocationCache = {};
98 authtoken = openils.User.authtoken;
99 var initNeeded = 8; // how many async responses do we need before we're init'd
100 var initCount = 0; // how many async reponses we've received
102 openils.Util.registerEnterHandler(
103 vlQueueDisplayPage.domNode, function(){retrieveQueuedRecords();});
104 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
106 function checkInitDone() {
108 if(initCount == initNeeded)
109 runStartupCommands();
112 mergeProfiles = new openils.PermaCrud().retrieveAll('vmp');
113 vlUploadMergeProfile.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
114 vlUploadMergeProfile.labelAttr = 'name';
115 vlUploadMergeProfile.searchAttr = 'name';
116 vlUploadMergeProfile.startup();
118 vlUploadMergeProfile2.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
119 vlUploadMergeProfile2.labelAttr = 'name';
120 vlUploadMergeProfile2.searchAttr = 'name';
121 vlUploadMergeProfile2.startup();
123 vlUploadFtMergeProfile.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
124 vlUploadFtMergeProfile.labelAttr = 'name';
125 vlUploadFtMergeProfile.searchAttr = 'name';
126 vlUploadFtMergeProfile.startup();
128 vlUploadFtMergeProfile2.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
129 vlUploadFtMergeProfile2.labelAttr = 'name';
130 vlUploadFtMergeProfile2.searchAttr = 'name';
131 vlUploadFtMergeProfile2.startup();
134 // Fetch the bib and authority attribute definitions
135 vlFetchBibAttrDefs(function () { checkInitDone(); });
136 vlFetchAuthAttrDefs(function () { checkInitDone(); });
138 vlRetrieveQueueList('bib', null,
140 allUserBibQueues = list;
141 for(var i = 0; i < allUserBibQueues.length; i++) {
142 if(allUserBibQueues[i].complete() == 'f')
143 userBibQueues.push(allUserBibQueues[i]);
149 vlRetrieveQueueList('auth', null,
151 allUserAuthQueues = list;
152 for(var i = 0; i < allUserAuthQueues.length; i++) {
153 if(allUserAuthQueues[i].complete() == 'f')
154 userAuthQueues.push(allUserAuthQueues[i]);
160 fieldmapper.standardRequest(
161 ['open-ils.permacrud', 'open-ils.permacrud.search.cbs.atomic'],
163 params: [authtoken, {id:{"!=":null}}, {order_by:{cbs:'id'}}],
164 oncomplete : function(r) {
165 vlBibSources = openils.Util.readResponse(r, false, true);
171 var owner = fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(new openils.User().user.ws_ou()));
172 new openils.PermaCrud().search('viiad',
173 {owner: owner.map(function(org) { return org.id(); })},
175 oncomplete: function(r) {
176 importItemDefs = openils.Util.readResponse(r);
182 new openils.PermaCrud().search('vms',
183 {owner: owner.map(function(org) { return org.id(); })},
185 oncomplete: function(r) {
186 var sets = openils.Util.readResponse(r);
189 if(!matchSets[set.mtype()])
190 matchSets[set.mtype()] = [];
191 matchSets[set.mtype()].push(set);
199 new openils.PermaCrud().retrieveAll('ccs',
201 oncomplete: function(r) {
202 var stats = openils.Util.readResponse(r);
203 dojo.forEach(stats, function(stat){copyStatusCache[stat.id()] = stat});
214 openils.Util.addOnLoad(vlInit);
217 // fetch the bib and authority attribute definitions
219 function vlFetchBibAttrDefs(postcomplete) {
221 fieldmapper.standardRequest(
222 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
224 params: [authtoken, {id:{'!=':null}}],
225 onresponse: function(r) {
226 var def = r.recv().content();
227 if(e = openils.Event.parse(def[0]))
229 bibAttrDefs.push(def);
231 oncomplete: function() {
232 bibAttrDefs = bibAttrDefs.sort(
234 if(a.id() > b.id()) return 1;
235 if(a.id() < b.id()) return -1;
245 function vlFetchAuthAttrDefs(postcomplete) {
247 fieldmapper.standardRequest(
248 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
250 params: [authtoken, {id:{'!=':null}}],
251 onresponse: function(r) {
252 var def = r.recv().content();
253 if(e = openils.Event.parse(def[0]))
255 authAttrDefs.push(def);
257 oncomplete: function() {
258 authAttrDefs = authAttrDefs.sort(
260 if(a.id() > b.id()) return 1;
261 if(a.id() < b.id()) return -1;
271 function vlRetrieveQueueList(type, filter, onload) {
272 type = (type == 'bib') ? type : 'authority';
273 fieldmapper.standardRequest(
274 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.owner.retrieve.atomic'],
276 params: [authtoken, null, filter],
277 oncomplete: function(r) {
278 var list = r.recv().content();
279 if(e = openils.Event.parse(list[0]))
288 function displayGlobalDiv(id) {
289 for(var i = 0; i < globalDivs.length; i++) {
291 dojo.style(dojo.byId(globalDivs[i]), 'display', 'none');
293 alert('please define div ' + globalDivs[i]);
296 dojo.style(dojo.byId(id),'display','block');
298 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
299 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
300 openils.Util.removeCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
301 openils.Util.removeCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
302 openils.Util.removeCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
303 openils.Util.removeCSSClass(dojo.byId('vl-menu-match-set-editor'), 'toolbar_selected');
305 if(dojo.byId('vl-match-set-iframe'))
306 dojo.byId('vl-match-set-editor-div').removeChild(dojo.byId('vl-match-set-iframe'));
309 case 'vl-marc-export-div':
310 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
312 case 'vl-marc-upload-div':
313 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
315 case 'vl-queue-select-div':
316 openils.Util.addCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
318 case 'vl-attr-editor-div':
319 openils.Util.addCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
321 case 'vl-profile-editor-div':
322 openils.Util.addCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
324 case 'vl-item-attr-editor-div':
325 openils.Util.addCSSClass(dojo.byId('vl-menu-import-item-attr-editor'), 'toolbar_selected');
327 case 'vl-match-set-editor-div':
328 openils.Util.addCSSClass(dojo.byId('vl-menu-match-set-editor'), 'toolbar_selected');
333 function runStartupCommands() {
334 currentQueueId = cgi.param('qid');
335 currentType = cgi.param('qtype');
336 dojo.style('vl-nav-bar', 'visibility', 'visible');
338 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
343 * asynchronously upload a file of MARC records
345 function uploadMARC(onload){
346 dojo.byId('vl-upload-status-count').innerHTML = '0';
347 dojo.byId('vl-ses-input').value = authtoken;
348 displayGlobalDiv('vl-marc-upload-status-div');
349 dojo.io.iframe.send({
353 form: dojo.byId('vl-marc-upload-form'),
354 handle: function(data,ioArgs){
355 var content = data.documentElement.textContent;
362 * Creates a new vandelay queue
364 function createQueue(queueName, type, onload, importDefId, matchSet) {
365 var name = (type=='bib') ? 'bib' : 'authority';
366 var method = 'open-ils.vandelay.'+ name +'_queue.create'
367 fieldmapper.standardRequest(
368 ['open-ils.vandelay', method],
370 params: [authtoken, queueName, null, name, matchSet, importDefId],
371 oncomplete : function(r) {
372 var queue = r.recv().content();
373 if(e = openils.Event.parse(queue))
382 * Tells vandelay to pull a batch of records from the cache and explode them
383 * out into the vandelay tables
385 function processSpool(key, queueId, type, onload) {
386 fieldmapper.standardRequest(
387 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
389 params: [authtoken, key, queueId],
390 onresponse : function(r) {
391 var resp = r.recv().content();
392 if(e = openils.Event.parse(resp))
394 dojo.byId('vl-upload-status-count').innerHTML = resp;
396 oncomplete : function(r) {onload();}
401 function vlExportInit() {
404 var qsel = dojo.byId('vl-queue-export-options');
405 qsel.onchange = function(newVal) {
406 var value = qsel.options[qsel.selectedIndex].value;
407 qsel.selectedIndex = 0;
409 if(!confirm('Export as "' + value + '"?')) return; // TODO: i18n
410 retrieveQueuedRecords(
414 exportHandler(value, r);
415 displayGlobalDiv('vl-queue-div');
422 var isel = dojo.byId('vl-item-export-options');
423 isel.onchange = function(newVal) {
424 var value = isel.options[isel.selectedIndex].value;
425 isel.selectedIndex = 0;
427 if(!confirm('Export as "' + value + '"?')) return; // TODO: i18n
429 displayGlobalDiv('vl-generic-progress');
430 var method = 'open-ils.vandelay.import_item.queue.export.' + value + '.atomic';
432 fieldmapper.standardRequest(
433 ['open-ils.vandelay', method],
438 {with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null}
441 oncomplete : function(r) {exportHandler(value, r)}
447 function exportHandler(type, response) {
448 displayGlobalDiv('vl-import-error-div');
450 var content = openils.Util.readResponse(response);
452 if (content==1) { alert('Email sent.'); return; }
455 /* handle .atomic versus non-atomic method calls */
456 content = content.constructor == Array
457 ? content[0].template_output().data()
458 : content.template_output().data();
461 openils.Util.printHtmlString(content);
464 //content = content.replace(/\\t/g,'\t'); // if we really wanted to do .tsv instead
465 openils.XUL.contentToFileSaveDialog(content);
468 alert('response = ' + response + '\tcontent:\n' + content);
471 alert('Error exporting data: ' + E);
475 function retrieveQueuedRecords(type, queueId, onload, doExport) {
476 displayGlobalDiv('vl-generic-progress');
478 queuedRecordsMap = {};
479 currentOverlayRecordsMap = {};
480 currentOverlayRecordsMapGid = {};
481 selectableGridRecords = {};
483 if(!type) type = currentType;
484 if(!queueId) queueId = currentQueueId;
485 if(!onload) onload = handleRetrieveRecords;
487 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve';
489 if(doExport) method += '.export.' + doExport;
490 if(vlQueueGridShowMatches.checked)
491 method = method.replace('records', 'records.matches');
495 var sel = dojo.byId('vl-queue-display-limit-selector');
496 var limit = parseInt(sel.options[sel.selectedIndex].value);
497 var offset = limit * parseInt(vlQueueDisplayPage.attr('value')-1);
499 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit, flesh_import_items:1}];
500 if(vlQueueGridShowNonImport.checked)
501 params[2].non_imported = 1;
503 if(vlQueueGridShowImportErrors.checked)
504 params[2].with_import_error = 1;
506 fieldmapper.standardRequest(
507 ['open-ils.vandelay', method],
510 oncomplete: function(r){
511 if(doExport) return onload(r);
512 var recs = r.recv().content();
513 if(e = openils.Event.parse(recs[0]))
515 for(var i = 0; i < recs.length; i++) {
517 queuedRecords.push(rec);
518 queuedRecordsMap[rec.id()] = rec;
526 function vlLoadMatchUI(recId) {
527 displayGlobalDiv('vl-generic-progress');
528 var queuedRec = queuedRecordsMap[recId];
529 var matches = queuedRec.matches();
531 currentImportRecId = recId;
532 for(var i = 0; i < matches.length; i++)
533 records.push(matches[i].eg_record());
535 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
536 var params = [records];
537 if(currentType == 'auth') {
538 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
539 params = [authtoken, records, {clear_marc:1}];
542 fieldmapper.standardRequest(
546 oncomplete: function(r) {
547 var recs = r.recv().content();
548 if(e = openils.Event.parse(recs))
552 displayGlobalDiv('vl-match-div');
553 resetVlMatchGridLayout();
554 currentMatchedRecords = recs;
555 vlMatchGrid.setStructure(vlMatchGridLayout);
557 // build the data store of records with match information
558 var dataStore = bre.toStoreData(recs, null,
559 {virtualFields:['_id', 'match_score', 'match_quality', 'rec_quality']});
560 dataStore.identifier = '_id';
562 var matchSeenMap = {};
564 for(var i = 0; i < dataStore.items.length; i++) {
565 var item = dataStore.items[i];
566 item._id = i; // just need something unique
567 for(var j = 0; j < matches.length; j++) {
568 var match = matches[j];
569 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
570 if(match.match_score)
571 item.match_score = match.match_score();
572 item.match_quality = match.quality();
573 item.rec_quality = queuedRec.quality();
574 matchSeenMap[match.id()] = 1;
580 // now populate the grid
581 vlPopulateMatchGrid(vlMatchGrid, dataStore);
587 function vlPopulateMatchGrid(grid, data) {
588 var store = new dojo.data.ItemFileReadStore({data:data});
589 grid.setStore(store);
593 function showMe(id) {
594 dojo.style(dojo.byId(id), 'display', 'block');
596 function hideMe(id) {
597 dojo.style(dojo.byId(id), 'display', 'none');
601 function vlLoadMARCHtml(recId, inCat, oncomplete) {
602 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
603 displayGlobalDiv('vl-generic-progress');
605 var params = [recId, 1];
608 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
609 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
610 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
611 if(currentType == 'auth')
612 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
614 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
615 dijit.byId('vl-marc-html-edit-button').onClick =
616 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
617 params = [authtoken, recId];
618 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
619 if(currentType == 'auth')
620 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
623 fieldmapper.standardRequest(
627 oncomplete: function(r) {
628 displayGlobalDiv('vl-marc-html-div');
629 var html = r.recv().content();
630 dojo.byId('vl-marc-record-html').innerHTML = html;
638 function getRecMatchesFromAttrCode(rec, attrCode) {
640 var attr = getRecAttrFromCode(rec, attrCode);
641 for(var j = 0; j < rec.matches().length; j++) {
642 var match = rec.matches()[j];
643 if(match.matched_attr() == attr.id())
651 function getRecAttrFromMatch(rec, match) {
652 for(var i = 0; i < rec.attributes().length; i++) {
653 var attr = rec.attributes()[i];
654 if(attr.id() == match.matched_attr())
660 function getRecAttrDefFromAttr(attr, type) {
661 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
662 for(var i = 0; i < defs.length; i++) {
664 if(def.id() == attr.field())
669 function getRecAttrFromCode(rec, attrCode) {
670 var defId = attrDefMap[currentType][attrCode];
671 var attrs = rec.attributes();
672 for(var i = 0; i < attrs.length; i++) {
674 if(attr.field() == defId)
680 function vlGetViewMatches(rowIdx, item) {
682 var id = this.grid.store.getValue(item, 'id');
683 var rec = queuedRecordsMap[id];
684 if(rec.matches().length > 0)
690 function vlFormatViewMatches(id) {
691 if(id == -1) return '';
692 return '<a href="javascript:void(0);" onclick="vlLoadMatchUI(' + id + ');">' + this.name + '</a>';
695 function vlGetViewErrors(rowIdx, item) {
697 var id = this.grid.store.getValue(item, 'id');
698 var rec = queuedRecordsMap[id];
699 // id:rec_error:item_import_error_count
701 (rec.import_error() ? 1 : '') + ':' +
702 (typeof rec.import_items == 'function'
703 ? rec.import_items().filter(function(i) {return i.import_error()}).length
710 function vlFormatViewErrors(chunk) {
711 if(chunk == -1) return '';
712 var id = chunk.split(':')[0];
713 var rec = chunk.split(':')[1];
714 var count = chunk.split(':')[2];
717 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Record</a><br/>'; // TODO I18N
719 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Items ('+count+')</a>'; // TODO I18N
723 //var vlItemErrorColumnPicker;
724 function vlLoadErrorUI(id) {
726 displayGlobalDiv('vl-import-error-div');
727 openils.Util.hide('vl-import-error-grid-all');
728 openils.Util.show('vl-import-error-record');
730 var rec = queuedRecordsMap[id];
732 dojo.byId('vl-error-id').innerHTML = rec.id();
733 dojo.forEach( // TODO sane authority rec. fields
734 ['title', 'author', 'isbn', 'issn', 'upc'],
736 var attr = getRecAttrFromCode(rec, field);
737 var eid = 'vl-error-' + field;
739 openils.Util.show(dojo.byId(eid).parentNode, 'table-row');
740 dojo.byId(eid).innerHTML = attr.attr_value();
742 openils.Util.hide(dojo.byId(eid).parentNode);
746 var iediv = dojo.byId('vl-error-import-error');
747 var eddiv = dojo.byId('vl-error-error-detail');
748 if(rec.import_error()) {
749 openils.Util.show(iediv.parentNode, 'table-row');
750 openils.Util.show(eddiv.parentNode, 'table-row');
751 iediv.innerHTML = rec.import_error();
752 eddiv.innerHTML = rec.error_detail();
754 openils.Util.hide(iediv.parentNode);
755 openils.Util.hide(eddiv.parentNode);
758 var errorItems = rec.import_items().filter(function(i) {return i.import_error()});
759 if(errorItems.length) {
760 openils.Util.show('vl-import-error-grid-some');
761 storeData = vqbr.toStoreData(errorItems);
762 var store = new dojo.data.ItemFileReadStore({data:storeData});
763 vlImportErrorGrid.setStore(store);
764 vlImportErrorGrid.update();
766 openils.Util.hide('vl-import-error-grid-some');
770 function vlLoadErrorUIAll() {
772 displayGlobalDiv('vl-import-error-div');
773 openils.Util.hide('vl-import-error-grid-some');
774 openils.Util.hide('vl-import-error-record');
775 openils.Util.show('vl-import-error-grid-all');
776 vlAllImportErrorGrid.resetStore();
778 vlImportErrorGrid.displayOffset = 0;
780 vlAllImportErrorGrid.dataLoader = function() {
782 vlAllImportErrorGrid.showLoadProgressIndicator();
784 fieldmapper.standardRequest(
785 ['open-ils.vandelay', 'open-ils.vandelay.import_item.queue.retrieve'],
789 authtoken, currentQueueId, {
790 with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null,
791 offset : vlAllImportErrorGrid.displayOffset,
792 limit : vlAllImportErrorGrid.displayLimit
795 onresponse : function(r) {
796 var item = openils.Util.readResponse(r);
798 vlAllImportErrorGrid.store.newItem(vii.toStoreItem(item));
800 oncomplete : function() {
801 vlAllImportErrorGrid.hideLoadProgressIndicator();
807 vlAllImportErrorGrid.dataLoader();
810 function vlGetOrg(rowIdx, item) {
812 var value = this.grid.store.getValue(item, this.field);
813 if(value) return fieldmapper.aou.findOrgUnit(value).shortname();
817 function vlCopyStatus(rowIdx, item) {
819 var value = this.grid.store.getValue(item, this.field);
820 if(value) return copyStatusCache[value].name();
824 // Note, we don't pre-fetch all copy locations because there could be
825 // a lot of them. Instead, fetch-and-cache on demand.
826 function vlCopyLocation(rowIdx, item) {
828 var value = this.grid.store.getValue(item, this.field);
830 if(!copyLocationCache[value]) {
831 copyLocationCache[value] =
832 new openils.PermaCrud().retrieve('acpl', value);
834 return copyLocationCache[value].name();
840 function vlFormatViewMatchMARC(id) {
841 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', true, '+
842 'function(){displayGlobalDiv(\'vl-match-div\');});">' + this.name + '</a>';
845 function getAttrValue(rowIdx, item) {
847 var attrCode = this.field.split('.')[1];
848 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
849 var attr = getRecAttrFromCode(rec, attrCode);
850 return (attr) ? attr.attr_value() : '';
853 function vlGetDateTimeField(rowIdx, item) {
855 var value = this.grid.store.getValue(item, this.field);
856 if(!value) return '';
857 var date = dojo.date.stamp.fromISOString(value);
858 return dojo.date.locale.format(date, {selector:'date'});
861 function vlGetCreator(rowIdx, item) {
863 var id = this.grid.store.getValue(item, 'creator');
865 return userCache[id].usrname();
866 var user = fieldmapper.standardRequest(
867 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
868 if(e = openils.Event.parse(user))
870 userCache[id] = user;
871 return user.usrname();
874 function vlGetViewMARC(rowIdx, item) {
875 return item && this.grid.store.getValue(item, 'id');
878 function vlFormatViewMARC(id) {
879 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
880 'function(){displayGlobalDiv(\'vl-queue-div\');});">' + this.name + '</a>';
883 function vlGetOverlayTargetSelector(rowIdx, item) {
885 return this.grid.store.getValue(item, '_id') + ':' + this.grid.store.getValue(item, 'id');
888 function vlFormatOverlayTargetSelector(val) {
890 var parts = val.split(':');
893 var value = '<input type="checkbox" name="vl-overlay-target-RECID" '+
894 'onclick="vlHandleOverlayTargetSelected(ID, GRIDID);" gridid="GRIDID" match="ID"/>';
895 value = value.replace(/GRIDID/g, _id);
896 value = value.replace(/RECID/g, currentImportRecId);
897 value = value.replace(/ID/g, id);
898 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
899 return value.replace('/>', 'checked="checked"/>');
905 * see if the user has enabled overlays for the current match set and,
906 * if so, map the current import record to the overlay target.
908 function vlHandleOverlayTargetSelected(recId, gridId) {
909 var noneSelected = true;
910 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
911 for(var i = 0; i < checkboxes.length; i++) {
912 var checkbox = checkboxes[i];
913 var matchRecId = checkbox.getAttribute('match');
914 var gid = checkbox.getAttribute('gridid');
915 if(checkbox.checked) {
916 if(matchRecId == recId && gid == gridId) {
917 noneSelected = false;
918 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
919 currentOverlayRecordsMapGid[currentImportRecId] = gid;
920 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
921 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
923 checkbox.checked = false;
929 delete currentOverlayRecordsMap[currentImportRecId];
930 delete currentOverlayRecordsMapGid[currentImportRecId];
931 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
932 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
936 var valLastQueueType = null;
937 var vlQueueGridLayout = null;
938 function buildRecordGrid(type) {
939 displayGlobalDiv('vl-queue-div');
941 vlBibQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
942 vlAuthQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
945 openils.Util.show('vl-bib-queue-grid-wrapper');
946 openils.Util.hide('vl-auth-queue-grid-wrapper');
947 vlQueueGrid = vlBibQueueGrid;
949 openils.Util.show('vl-auth-queue-grid-wrapper');
950 openils.Util.hide('vl-bib-queue-grid-wrapper');
951 vlQueueGrid = vlAuthQueueGrid;
955 if(valLastQueueType != type) {
956 valLastQueueType = type;
957 vlQueueGridLayout = vlQueueGrid.attr('structure');
958 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
959 attrDefMap[type] = {};
960 for(var i = 0; i < defs.length; i++) {
962 attrDefMap[type][def.code()] = def.id();
964 name:def.description(),
965 field:'attr.' + def.code(),
967 selectableColumn:true
969 vlQueueGridLayout[0].cells[0].push(col);
973 dojo.forEach(vlQueueGridLayout[0].cells[0],
975 if(cell.field.match(/^\+/))
976 cell.nonSelectable=true;
982 storeData = vqbr.toStoreData(queuedRecords);
984 storeData = vqar.toStoreData(queuedRecords);
986 var store = new dojo.data.ItemFileReadStore({data:storeData});
987 vlQueueGrid.setStore(store);
989 if(vlQueueGridColumePicker[type]) {
990 vlQueueGrid.update();
993 vlQueueGridColumePicker[type] =
994 new openils.widget.GridColumnPicker(
995 authtoken, 'vandelay.queue.'+type, vlQueueGrid, vlQueueGridLayout);
996 vlQueueGridColumePicker[type].load();
1000 function vlQueueGridPrevPage() {
1001 var page = parseInt(vlQueueDisplayPage.getValue());
1002 if(page < 2) return;
1003 vlQueueDisplayPage.setValue(page - 1);
1004 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1007 function vlQueueGridNextPage() {
1008 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
1009 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1012 function vlDeleteQueue(type, queueId, onload) {
1013 fieldmapper.standardRequest(
1014 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
1016 params: [authtoken, queueId],
1017 oncomplete: function(r) {
1018 var resp = r.recv().content();
1019 if(e = openils.Event.parse(resp))
1028 function vlQueueGridDrawSelectBox(rowIdx, item) {
1029 return item && this.grid.store.getValue(item, 'id');
1032 function vlQueueGridFormatSelectBox(id) {
1033 var domId = 'vl-record-list-selected-' + id;
1034 if (id) { selectableGridRecords[domId] = id; }
1035 return "<div><input type='checkbox' id='"+domId+"'/></div>";
1038 function vlSelectAllQueueGridRecords() {
1039 for(var id in selectableGridRecords)
1040 dojo.byId(id).checked = true;
1042 function vlSelectNoQueueGridRecords() {
1043 for(var id in selectableGridRecords)
1044 dojo.byId(id).checked = false;
1046 function vlToggleQueueGridSelect() {
1047 if(dojo.byId('vl-queue-grid-row-selector').checked)
1048 vlSelectAllQueueGridRecords();
1050 vlSelectNoQueueGridRecords();
1053 var handleRetrieveRecords = function() {
1054 buildRecordGrid(currentType);
1055 vlFetchQueueSummary(currentQueueId, currentType,
1057 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
1058 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
1059 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
1060 dojo.byId('vl-queue-summary-import-item-count').innerHTML = summary.total_items + '';
1061 dojo.byId('vl-queue-summary-import-item-imported-count').innerHTML = summary.total_items_imported + '';
1062 dojo.byId('vl-queue-summary-rec-error-count').innerHTML = summary.rec_import_errors + '';
1063 dojo.byId('vl-queue-summary-item-error-count').innerHTML = summary.item_import_errors + '';
1068 function vlFetchQueueSummary(qId, type, onload) {
1069 fieldmapper.standardRequest(
1070 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
1072 params: [authtoken, qId],
1073 oncomplete : function(r) {
1074 var summary = r.recv().content();
1075 if(e = openils.Event.parse(summary))
1077 return onload(summary);
1083 var _importCancelHandler;
1084 var _importGoHandler;
1085 function vlHandleQueueItemsAction(action) {
1087 if(_importCancelHandler) dojo.disconnect(_importCancelHandler);
1089 _importCancelHandler = dojo.connect(
1090 queueItemsImportCancelButton,
1093 queueItemsImportDialog.hide();
1097 if(_importGoHandler)
1098 dojo.disconnect(_importGoHandler);
1100 _importGoHandler = dojo.connect(
1101 queueItemsImportGoButton,
1104 queueItemsImportDialog.hide();
1106 // hack to set the widgets the import funcs will be looking at. Reset them below.
1107 vlUploadQueueImportNoMatch.attr('value', vlUploadQueueImportNoMatch2.attr('value'));
1108 vlUploadQueueAutoOverlayExact.attr('value', vlUploadQueueAutoOverlayExact2.attr('value'));
1109 vlUploadQueueAutoOverlay1Match.attr('value', vlUploadQueueAutoOverlay1Match2.attr('value'));
1110 vlUploadMergeProfile.attr('value', vlUploadMergeProfile2.attr('value'));
1111 vlUploadFtMergeProfile.attr('value', vlUploadFtMergeProfile2.attr('value'));
1112 vlUploadQueueAutoOverlayBestMatch.attr('value', vlUploadQueueAutoOverlayBestMatch2.attr('value'));
1113 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', vlUploadQueueAutoOverlayBestMatchRatio2.attr('value'));
1115 if(action == 'import') {
1116 vlImportSelectedRecords();
1117 } else if(action == 'import_all') {
1118 vlImportAllRecords();
1121 // reset the widgets to prevent accidental future actions
1122 vlUploadQueueImportNoMatch.attr('value', false);
1123 vlUploadQueueImportNoMatch2.attr('value', false);
1124 vlUploadQueueAutoOverlayExact.attr('value', false);
1125 vlUploadQueueAutoOverlayExact2.attr('value', false);
1126 vlUploadQueueAutoOverlay1Match.attr('value', false);
1127 vlUploadQueueAutoOverlay1Match2.attr('value', false);
1128 vlUploadMergeProfile.attr('value', '');
1129 vlUploadMergeProfile2.attr('value', '');
1130 vlUploadFtMergeProfile.attr('value', '');
1131 vlUploadFtMergeProfile2.attr('value', '');
1132 vlUploadQueueAutoOverlayBestMatch.attr('value', false);
1133 vlUploadQueueAutoOverlayBestMatch2.attr('value', false);
1134 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', '0.0');
1135 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', '0.0');
1139 queueItemsImportDialog.show();
1143 /* import user-selected records */
1144 function vlImportSelectedRecords() {
1147 for(var id in selectableGridRecords) {
1148 if(dojo.byId(id).checked) {
1149 var recId = selectableGridRecords[id];
1150 var rec = queuedRecordsMap[recId];
1151 if(!rec.import_time())
1152 records.push(recId);
1156 vlImportRecordQueue(
1161 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1166 /* import all (non-imported) queue records */
1167 function vlImportAllRecords() {
1168 vlImportRecordQueue(
1173 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1178 /* if recList has values, import only those records */
1179 function vlImportRecordQueue(type, queueId, recList, onload) {
1180 displayGlobalDiv('vl-generic-progress-with-total');
1182 /* set up options */
1183 var options = {overlay_map : currentOverlayRecordsMap};
1185 if(vlUploadQueueImportNoMatch.checked) {
1186 options.import_no_match = true;
1187 vlUploadQueueImportNoMatch.checked = false;
1190 if(vlUploadQueueAutoOverlayExact.checked) {
1191 options.auto_overlay_exact = true;
1192 vlUploadQueueAutoOverlayExact.checked = false;
1195 if(vlUploadQueueAutoOverlayBestMatch.checked) {
1196 options.auto_overlay_best_match = true;
1197 vlUploadQueueAutoOverlayBestMatch.checked = false;
1198 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1201 if(vlUploadQueueAutoOverlay1Match.checked) {
1202 options.auto_overlay_1match = true;
1203 vlUploadQueueAutoOverlay1Match.checked = false;
1204 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1207 var profile = vlUploadMergeProfile.attr('value');
1208 if(profile != null && profile != '') {
1209 options.merge_profile = profile;
1212 var ftprofile = vlUploadFtMergeProfile.attr('value');
1213 if(ftprofile != null && ftprofile != '') {
1214 options.fall_through_merge_profile = ftprofile;
1218 /* determine which method we're calling */
1220 var method = 'open-ils.vandelay.bib_queue.import';
1222 method = method.replace('bib', 'auth');
1224 var params = [authtoken, queueId, options];
1226 method = 'open-ils.vandelay.'+currentType+'_record.list.import';
1227 params[1] = recList;
1230 fieldmapper.standardRequest(
1231 ['open-ils.vandelay', method],
1234 onresponse: function(r) {
1235 var resp = r.recv().content();
1236 if(e = openils.Event.parse(resp))
1238 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
1240 oncomplete: function() {onload();}
1247 * Create queue, upload MARC, process spool, load the newly created queue
1249 function batchUpload() {
1250 var queueName = dijit.byId('vl-queue-name').getValue();
1251 currentType = dijit.byId('vl-record-type').getValue();
1253 var handleProcessSpool = function() {
1255 vlUploadQueueImportNoMatch.checked ||
1256 vlUploadQueueAutoOverlayExact.checked ||
1257 vlUploadQueueAutoOverlay1Match.checked ||
1258 vlUploadQueueAutoOverlayBestMatch.checked ) {
1260 vlImportRecordQueue(
1265 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1269 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1273 var handleUploadMARC = function(key) {
1274 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
1275 processSpool(key, currentQueueId, currentType, handleProcessSpool);
1278 var handleCreateQueue = function(queue) {
1279 currentQueueId = queue.id();
1280 uploadMARC(handleUploadMARC);
1283 if(vlUploadQueueSelector.getValue() && !queueName) {
1284 currentQueueId = vlUploadQueueSelector.getValue();
1285 uploadMARC(handleUploadMARC);
1287 createQueue(queueName, currentType, handleCreateQueue,
1288 vlUploadQueueHoldingsImportProfile.attr('value'),
1289 vlUploadQueueMatchSet.attr('value')
1295 function vlFleshQueueSelect(selector, type) {
1296 var data = (type == 'bib') ? vbq.toStoreData(allUserBibQueues) : vaq.toStoreData(allUserAuthQueues);
1297 selector.store = new dojo.data.ItemFileReadStore({data:data});
1298 selector.setValue(null);
1299 selector.setDisplayedValue('');
1301 selector.setValue(data[0].id());
1303 var qInput = dijit.byId('vl-queue-name');
1305 var selChange = function(val) {
1306 console.log('selector onchange');
1307 // user selected a queue from the selector; clear the input and
1308 // set the item import profile already defined for the queue
1309 var queue = allUserBibQueues.filter(function(q) { return (q.id() == val) })[0];
1311 vlUploadQueueHoldingsImportProfile.attr('value', queue.item_attr_def() || '');
1312 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
1313 vlUploadQueueMatchSet.attr('value', queue.match_set() || '');
1314 vlUploadQueueMatchSet.attr('disabled', true);
1316 vlUploadQueueHoldingsImportProfile.attr('value', '');
1317 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1318 vlUploadQueueMatchSet.attr('value', '');
1319 vlUploadQueueMatchSet.attr('disabled', false);
1321 dojo.disconnect(qInput._onchange);
1322 qInput.attr('value', '');
1323 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1326 var inputChange = function(val) {
1327 console.log('qinput onchange');
1328 // user entered a new queue name. clear the selector
1329 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1330 vlUploadQueueMatchSet.attr('disabled', false);
1331 dojo.disconnect(selector._onchange);
1332 selector.attr('value', '');
1333 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1336 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1337 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1340 function vlUpdateMatchSetSelector(type) {
1341 type = (type.match(/bib/)) ? 'biblio' : 'authority';
1342 vlUploadQueueMatchSet.store =
1343 new dojo.data.ItemFileReadStore({data:vms.toStoreData(matchSets[type])});
1346 function vlShowUploadForm() {
1347 displayGlobalDiv('vl-marc-upload-div');
1348 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
1349 vlUploadSourceSelector.store =
1350 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
1351 vlUploadSourceSelector.setValue(vlBibSources[0].id());
1352 vlUploadQueueHoldingsImportProfile.store =
1353 new dojo.data.ItemFileReadStore({data:viiad.toStoreData(importItemDefs)});
1354 vlUpdateMatchSetSelector(vlUploadRecordType.getValue());
1356 // use ratio from the merge profile if it's set
1358 vlUploadMergeProfile,
1362 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1363 if(profile.lwm_ratio() != null)
1364 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', profile.lwm_ratio()+'');
1368 vlUploadMergeProfile2,
1372 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1373 if(profile.lwm_ratio() != null)
1374 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', profile.lwm_ratio()+'');
1380 function vlShowQueueSelect() {
1381 displayGlobalDiv('vl-queue-select-div');
1382 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
1385 function vlShowMatchSetEditor() {
1386 displayGlobalDiv('vl-match-set-editor-div');
1387 dojo.byId('vl-match-set-editor-div').appendChild(
1388 dojo.create('iframe', {
1389 id : 'vl-match-set-iframe',
1390 src : oilsBasePath + '/eg/conify/global/vandelay/match_set',
1391 style : 'width:100%; height:500px; border:none; margin:0px;'
1396 function vlFetchQueueFromForm() {
1397 currentType = vlQueueSelectType.getValue();
1398 currentQueueId = vlQueueSelectQueueList.getValue();
1399 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1402 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
1404 To run in Firefox directly, must set signed.applets.codebase_principal_support
1405 to true in about:config
1407 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1408 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
1411 if (currentType == 'bib') {
1417 function onsave(r) {
1418 // after the record is saved, reload the HTML display
1419 var stat = r.recv().content();
1420 if(e = openils.Event.parse(stat))
1422 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
1424 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
1428 record : {marc : rec.marc(), "rtype": type},
1430 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
1431 func: function(xmlString) {
1432 var method = 'open-ils.permacrud.update.' + rec.classname;
1433 rec.marc(xmlString);
1434 fieldmapper.standardRequest(
1435 ['open-ils.permacrud', method],
1437 params: [authtoken, rec],
1443 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
1444 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
1448 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
1449 var method = 'open-ils.permacrud.search.vqbr';
1450 if(currentType != 'bib')
1451 method = method.replace(/vqbr/,'vqar');
1453 fieldmapper.standardRequest(
1454 ['open-ils.permacrud', method],
1456 params: [authtoken, {id : recId}],
1457 oncomplete: function(r) {
1458 var rec = r.recv().content();
1459 if(e = openils.Event.parse(rec))
1461 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
1469 //------------------------------------------------------------
1470 // attribute editors
1472 // attribute-editor global variables
1474 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
1475 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
1476 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
1478 function vlAttrEditorInit() {
1479 // set up tooltips on the edit form
1480 connectTooltip('attr-editor-tags');
1481 connectTooltip('attr-editor-subfields');
1484 function vlShowAttrEditor() {
1485 displayGlobalDiv('vl-attr-editor-div');
1486 loadAttrEditorGrid();
1487 idHide('vl-generic-progress');
1490 function setAttrEditorGroup(groupName) {
1491 // put us into 'bib'-attr or 'auth'-attr mode.
1492 if (ATTR_EDIT_GROUP != groupName) {
1493 ATTR_EDIT_GROUP = groupName;
1494 loadAttrEditorGrid();
1498 function onAttrEditorOpen() {
1499 // the "bars" have the create/update/cancel/etc. buttons.
1500 var create_bar = document.getElementById('attr-editor-create-bar');
1501 var update_bar = document.getElementById('attr-editor-update-bar');
1502 if (ATTR_EDITOR_IN_UPDATE_MODE) {
1503 update_bar.style.display='table-row';
1504 create_bar.style.display='none';
1505 // hide the dropdown-button
1506 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
1508 dijit.byId('attr-editor-dialog').reset();
1509 create_bar.style.display='table-row';
1510 update_bar.style.display='none';
1514 function onAttrEditorClose() {
1515 // reset the form to a "create" form. (We may have borrowed it for editing.)
1516 ATTR_EDITOR_IN_UPDATE_MODE = false;
1517 // show the dropdown-button
1518 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
1521 function loadAttrEditorGrid() {
1522 var _data = (ATTR_EDIT_GROUP == 'auth') ?
1523 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
1525 var store = new dojo.data.ItemFileReadStore({data:_data});
1526 attrEditorGrid.setStore(store);
1527 attrEditorGrid.onRowDblClick = onAttrEditorClick;
1528 attrEditorGrid.update();
1531 function attrGridGetTag(n, item) {
1532 // grid helper: return the tags from the row's xpath column.
1533 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
1536 function attrGridGetSubfield(n, item) {
1537 // grid helper: return the subfields from the row's xpath column.
1538 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
1541 function onAttrEditorClick() {
1542 var row = this.getItem(this.focus.rowIndex);
1543 ATTR_EDIT_ID = this.store.getValue(row, 'id');
1544 ATTR_EDITOR_IN_UPDATE_MODE = true;
1546 // populate the popup editor.
1547 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1548 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1549 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1550 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1551 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1552 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1553 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1555 // set up UI for editing
1556 dojo.byId('vl-create-attr-editor-button').click();
1559 function vlSaveAttrDefinition(data) {
1560 idHide('vl-attr-editor-div');
1561 idShow('vl-generic-progress');
1563 data.id = ATTR_EDIT_ID;
1565 // this ought to honour custom xpaths, but overwrite xpaths
1566 // derived from tags/subfields.
1567 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1568 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1569 data.xpath = _xpath;
1572 // build up our permacrud params. Key variables here are
1573 // "create or update" and "bib or auth".
1575 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1576 var isCreate = (ATTR_EDIT_ID == null);
1577 var rad = isAuth ? new vqarad() : new vqbrad() ;
1578 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1579 + (isAuth ? 'vqarad' : 'vqbrad');
1580 var _data = rad.fromStoreItem(data);
1584 fieldmapper.standardRequest(
1585 ['open-ils.permacrud', method],
1587 params: [authtoken, _data ],
1588 onresponse: function(r) { },
1589 oncomplete: function(r) {
1590 attrEditorFetchAttrDefs(vlShowAttrEditor);
1591 ATTR_EDIT_ID = null;
1593 onerror: function(r) {
1594 alert('vlSaveAttrDefinition comms error: ' + r);
1600 function attrEditorFetchAttrDefs(callback) {
1601 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1602 return fn(callback);
1605 function vlAttrDelete() {
1606 idHide('vl-attr-editor-div');
1607 idShow('vl-generic-progress');
1609 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1610 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1611 var rad = isAuth ? new vqarad() : new vqbrad() ;
1612 fieldmapper.standardRequest(
1613 ['open-ils.permacrud', method],
1615 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1616 oncomplete: function() {
1617 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1618 attrEditorFetchAttrDefs(vlShowAttrEditor);
1619 ATTR_EDIT_ID = null;
1621 onerror: function(r) {
1622 alert('vlAttrDelete comms error: ' + r);
1628 // ------------------------------------------------------------
1629 // utilities for attribute editors
1631 // dom utilities (maybe dojo does these, and these should be replaced)
1633 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1634 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1635 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1637 function connectTooltip(fieldId) {
1638 // Given an element id, look up a tooltip element in the doc (same
1639 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1640 // a better way to do this?
1641 var fld = dojo.byId(fieldId);
1642 var tip = dojo.byId(fieldId + '-tip');
1643 dojo.connect(fld, 'onfocus', function(evt) {
1644 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1645 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1650 var xpathParser = new openils.MarcXPathParser();
1652 function tagAndSubFieldsToXpath(tags, subfields) {
1653 // given tags, and subfields, build up an XPath.
1656 'tags':tags.match(/[\d]+/g),
1657 'subfields':subfields.match(/[a-zA-z]/g) };
1658 return xpathParser.compile(parts);
1660 return {'parts':null, 'tags':null, 'error':err};
1664 function looksLikeDerivedXpath(path) {
1665 // Does this path look like it was derived from tags and subfields?
1666 var parsed = xpathParser.parse(path);
1667 if (parsed.tags == null)
1669 var compiled = xpathParser.compile(parsed);
1670 return (path == compiled);
1673 // amazing xpath-util unit-tests
1674 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1675 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');
1679 var profileContextOrg
1680 function vlShowProfileEditor() {
1681 displayGlobalDiv('vl-profile-editor-div');
1684 var connect = function() {
1685 dojo.connect(profileContextOrgSelector, 'onChange',
1687 profileContextOrg = this.attr('value');
1694 new openils.User().buildPermOrgSelector(
1695 'ADMIN_MERGE_PROFILE', profileContextOrgSelector, null, connect);
1698 function buildProfileGrid() {
1700 if(profileContextOrg == null)
1701 profileContextOrg = openils.User.user.ws_ou();
1704 {order_by : {vmp : 'name'}},
1705 {owner : fieldmapper.aou.fullPath(profileContextOrg, true)}
1709 /* --- Import Item Attr Grid --------------- */
1711 var itemAttrContextOrg;
1712 var itemAttrGridFirstTime = true;
1713 function vlShowImportItemAttrEditor() {
1714 displayGlobalDiv('vl-item-attr-editor-div');
1716 if (itemAttrGridFirstTime) {
1718 buildImportItemAttrGrid();
1720 var connect = function() {
1721 dojo.connect(itemAttrContextOrgSelector, 'onChange',
1723 itemAttrContextOrg = this.attr('value');
1724 itemAttrGrid.resetStore();
1725 buildImportItemAttrGrid();
1730 new openils.User().buildPermOrgSelector(
1731 'ADMIN_IMPORT_ITEM_ATTR_DEF',
1732 itemAttrContextOrgSelector, null, connect);
1734 itemAttrGridFirstTime = false;
1738 function buildImportItemAttrGrid() {
1740 if(itemAttrContextOrg == null)
1741 itemAttrContextOrg = openils.User.user.ws_ou();
1743 itemAttrGrid.loadAll(
1744 {order_by : {viiad : 'name'}},
1745 {owner : fieldmapper.aou.fullPath(itemAttrContextOrg, true)}