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)
685 return id + ':' + rec.matches().length;
690 function vlFormatViewMatches(id) {
691 if(id == -1) return '';
692 var chunks = id.split(':');
695 return '<a href="javascript:void(0);" onclick="vlLoadMatchUI(' + id + ');">' + this.name + ' (' + count + ')</a>';
698 function vlGetViewErrors(rowIdx, item) {
700 var id = this.grid.store.getValue(item, 'id');
701 var rec = queuedRecordsMap[id];
702 // id:rec_error:item_import_error_count
704 (rec.import_error() ? 1 : '') + ':' +
705 (typeof rec.import_items == 'function'
706 ? rec.import_items().filter(function(i) {return i.import_error()}).length
713 function vlFormatViewErrors(chunk) {
714 if(chunk == -1) return '';
715 var id = chunk.split(':')[0];
716 var rec = chunk.split(':')[1];
717 var count = chunk.split(':')[2];
720 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Record</a><br/>'; // TODO I18N
722 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Items ('+count+')</a>'; // TODO I18N
726 //var vlItemErrorColumnPicker;
727 function vlLoadErrorUI(id) {
729 displayGlobalDiv('vl-import-error-div');
730 openils.Util.hide('vl-import-error-grid-all');
731 openils.Util.show('vl-import-error-record');
733 var rec = queuedRecordsMap[id];
735 dojo.byId('vl-error-id').innerHTML = rec.id();
736 dojo.forEach( // TODO sane authority rec. fields
737 ['title', 'author', 'isbn', 'issn', 'upc'],
739 var attr = getRecAttrFromCode(rec, field);
740 var eid = 'vl-error-' + field;
742 openils.Util.show(dojo.byId(eid).parentNode, 'table-row');
743 dojo.byId(eid).innerHTML = attr.attr_value();
745 openils.Util.hide(dojo.byId(eid).parentNode);
749 var iediv = dojo.byId('vl-error-import-error');
750 var eddiv = dojo.byId('vl-error-error-detail');
751 if(rec.import_error()) {
752 openils.Util.show(iediv.parentNode, 'table-row');
753 openils.Util.show(eddiv.parentNode, 'table-row');
754 iediv.innerHTML = rec.import_error();
755 eddiv.innerHTML = rec.error_detail();
757 openils.Util.hide(iediv.parentNode);
758 openils.Util.hide(eddiv.parentNode);
761 var errorItems = rec.import_items().filter(function(i) {return i.import_error()});
762 if(errorItems.length) {
763 openils.Util.show('vl-import-error-grid-some');
764 storeData = vqbr.toStoreData(errorItems);
765 var store = new dojo.data.ItemFileReadStore({data:storeData});
766 vlImportErrorGrid.setStore(store);
767 vlImportErrorGrid.update();
769 openils.Util.hide('vl-import-error-grid-some');
773 function vlLoadErrorUIAll() {
775 displayGlobalDiv('vl-import-error-div');
776 openils.Util.hide('vl-import-error-grid-some');
777 openils.Util.hide('vl-import-error-record');
778 openils.Util.show('vl-import-error-grid-all');
779 vlAllImportErrorGrid.resetStore();
781 vlImportErrorGrid.displayOffset = 0;
783 vlAllImportErrorGrid.dataLoader = function() {
785 vlAllImportErrorGrid.showLoadProgressIndicator();
787 fieldmapper.standardRequest(
788 ['open-ils.vandelay', 'open-ils.vandelay.import_item.queue.retrieve'],
792 authtoken, currentQueueId, {
793 with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null,
794 offset : vlAllImportErrorGrid.displayOffset,
795 limit : vlAllImportErrorGrid.displayLimit
798 onresponse : function(r) {
799 var item = openils.Util.readResponse(r);
801 vlAllImportErrorGrid.store.newItem(vii.toStoreItem(item));
803 oncomplete : function() {
804 vlAllImportErrorGrid.hideLoadProgressIndicator();
810 vlAllImportErrorGrid.dataLoader();
813 function vlGetOrg(rowIdx, item) {
815 var value = this.grid.store.getValue(item, this.field);
816 if(value) return fieldmapper.aou.findOrgUnit(value).shortname();
820 function vlCopyStatus(rowIdx, item) {
822 var value = this.grid.store.getValue(item, this.field);
823 if(value) return copyStatusCache[value].name();
827 // Note, we don't pre-fetch all copy locations because there could be
828 // a lot of them. Instead, fetch-and-cache on demand.
829 function vlCopyLocation(rowIdx, item) {
831 var value = this.grid.store.getValue(item, this.field);
833 if(!copyLocationCache[value]) {
834 copyLocationCache[value] =
835 new openils.PermaCrud().retrieve('acpl', value);
837 return copyLocationCache[value].name();
843 function vlFormatViewMatchMARC(id) {
844 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', true, '+
845 'function(){displayGlobalDiv(\'vl-match-div\');});">' + this.name + '</a>';
848 function getAttrValue(rowIdx, item) {
850 var attrCode = this.field.split('.')[1];
851 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
852 var attr = getRecAttrFromCode(rec, attrCode);
853 return (attr) ? attr.attr_value() : '';
856 function vlGetDateTimeField(rowIdx, item) {
858 var value = this.grid.store.getValue(item, this.field);
859 if(!value) return '';
860 var date = dojo.date.stamp.fromISOString(value);
861 return dojo.date.locale.format(date, {selector:'date'});
864 function vlGetCreator(rowIdx, item) {
866 var id = this.grid.store.getValue(item, 'creator');
868 return userCache[id].usrname();
869 var user = fieldmapper.standardRequest(
870 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
871 if(e = openils.Event.parse(user))
873 userCache[id] = user;
874 return user.usrname();
877 function vlGetViewMARC(rowIdx, item) {
878 return item && this.grid.store.getValue(item, 'id');
881 function vlFormatViewMARC(id) {
882 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
883 'function(){displayGlobalDiv(\'vl-queue-div\');});">' + this.name + '</a>';
886 function vlGetOverlayTargetSelector(rowIdx, item) {
888 return this.grid.store.getValue(item, '_id') + ':' + this.grid.store.getValue(item, 'id');
891 function vlFormatOverlayTargetSelector(val) {
893 var parts = val.split(':');
896 var value = '<input type="checkbox" name="vl-overlay-target-RECID" '+
897 'onclick="vlHandleOverlayTargetSelected(ID, GRIDID);" gridid="GRIDID" match="ID"/>';
898 value = value.replace(/GRIDID/g, _id);
899 value = value.replace(/RECID/g, currentImportRecId);
900 value = value.replace(/ID/g, id);
901 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
902 return value.replace('/>', 'checked="checked"/>');
908 * see if the user has enabled overlays for the current match set and,
909 * if so, map the current import record to the overlay target.
911 function vlHandleOverlayTargetSelected(recId, gridId) {
912 var noneSelected = true;
913 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
914 for(var i = 0; i < checkboxes.length; i++) {
915 var checkbox = checkboxes[i];
916 var matchRecId = checkbox.getAttribute('match');
917 var gid = checkbox.getAttribute('gridid');
918 if(checkbox.checked) {
919 if(matchRecId == recId && gid == gridId) {
920 noneSelected = false;
921 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
922 currentOverlayRecordsMapGid[currentImportRecId] = gid;
923 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
924 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
926 checkbox.checked = false;
932 delete currentOverlayRecordsMap[currentImportRecId];
933 delete currentOverlayRecordsMapGid[currentImportRecId];
934 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
935 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
939 var valLastQueueType = null;
940 var vlQueueGridLayout = null;
941 function buildRecordGrid(type) {
942 displayGlobalDiv('vl-queue-div');
944 vlBibQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
945 vlAuthQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
948 openils.Util.show('vl-bib-queue-grid-wrapper');
949 openils.Util.hide('vl-auth-queue-grid-wrapper');
950 vlQueueGrid = vlBibQueueGrid;
952 openils.Util.show('vl-auth-queue-grid-wrapper');
953 openils.Util.hide('vl-bib-queue-grid-wrapper');
954 vlQueueGrid = vlAuthQueueGrid;
958 if(valLastQueueType != type) {
959 valLastQueueType = type;
960 vlQueueGridLayout = vlQueueGrid.attr('structure');
961 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
962 attrDefMap[type] = {};
963 for(var i = 0; i < defs.length; i++) {
965 attrDefMap[type][def.code()] = def.id();
967 name:def.description(),
968 field:'attr.' + def.code(),
970 selectableColumn:true
972 vlQueueGridLayout[0].cells[0].push(col);
976 dojo.forEach(vlQueueGridLayout[0].cells[0],
978 if(cell.field.match(/^\+/))
979 cell.nonSelectable=true;
985 storeData = vqbr.toStoreData(queuedRecords);
987 storeData = vqar.toStoreData(queuedRecords);
989 var store = new dojo.data.ItemFileReadStore({data:storeData});
990 vlQueueGrid.setStore(store);
992 if(vlQueueGridColumePicker[type]) {
993 vlQueueGrid.update();
996 vlQueueGridColumePicker[type] =
997 new openils.widget.GridColumnPicker(
998 authtoken, 'vandelay.queue.'+type, vlQueueGrid, vlQueueGridLayout);
999 vlQueueGridColumePicker[type].load();
1003 function vlQueueGridPrevPage() {
1004 var page = parseInt(vlQueueDisplayPage.getValue());
1005 if(page < 2) return;
1006 vlQueueDisplayPage.setValue(page - 1);
1007 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1010 function vlQueueGridNextPage() {
1011 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
1012 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1015 function vlDeleteQueue(type, queueId, onload) {
1016 fieldmapper.standardRequest(
1017 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
1019 params: [authtoken, queueId],
1020 oncomplete: function(r) {
1021 var resp = r.recv().content();
1022 if(e = openils.Event.parse(resp))
1031 function vlQueueGridDrawSelectBox(rowIdx, item) {
1032 return item && this.grid.store.getValue(item, 'id');
1035 function vlQueueGridFormatSelectBox(id) {
1036 var domId = 'vl-record-list-selected-' + id;
1037 if (id) { selectableGridRecords[domId] = id; }
1038 return "<div><input type='checkbox' id='"+domId+"'/></div>";
1041 function vlSelectAllQueueGridRecords() {
1042 for(var id in selectableGridRecords)
1043 dojo.byId(id).checked = true;
1045 function vlSelectNoQueueGridRecords() {
1046 for(var id in selectableGridRecords)
1047 dojo.byId(id).checked = false;
1049 function vlToggleQueueGridSelect() {
1050 if(dojo.byId('vl-queue-grid-row-selector').checked)
1051 vlSelectAllQueueGridRecords();
1053 vlSelectNoQueueGridRecords();
1056 var handleRetrieveRecords = function() {
1057 buildRecordGrid(currentType);
1058 vlFetchQueueSummary(currentQueueId, currentType,
1060 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
1061 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
1062 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
1063 dojo.byId('vl-queue-summary-import-item-count').innerHTML = summary.total_items + '';
1064 dojo.byId('vl-queue-summary-import-item-imported-count').innerHTML = summary.total_items_imported + '';
1065 dojo.byId('vl-queue-summary-rec-error-count').innerHTML = summary.rec_import_errors + '';
1066 dojo.byId('vl-queue-summary-item-error-count').innerHTML = summary.item_import_errors + '';
1071 function vlFetchQueueSummary(qId, type, onload) {
1072 fieldmapper.standardRequest(
1073 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
1075 params: [authtoken, qId],
1076 oncomplete : function(r) {
1077 var summary = r.recv().content();
1078 if(e = openils.Event.parse(summary))
1080 return onload(summary);
1086 var _importCancelHandler;
1087 var _importGoHandler;
1088 function vlHandleQueueItemsAction(action) {
1090 if(_importCancelHandler) dojo.disconnect(_importCancelHandler);
1092 _importCancelHandler = dojo.connect(
1093 queueItemsImportCancelButton,
1096 queueItemsImportDialog.hide();
1100 if(_importGoHandler)
1101 dojo.disconnect(_importGoHandler);
1103 _importGoHandler = dojo.connect(
1104 queueItemsImportGoButton,
1107 queueItemsImportDialog.hide();
1109 // hack to set the widgets the import funcs will be looking at. Reset them below.
1110 vlUploadQueueImportNoMatch.attr('value', vlUploadQueueImportNoMatch2.attr('value'));
1111 vlUploadQueueAutoOverlayExact.attr('value', vlUploadQueueAutoOverlayExact2.attr('value'));
1112 vlUploadQueueAutoOverlay1Match.attr('value', vlUploadQueueAutoOverlay1Match2.attr('value'));
1113 vlUploadMergeProfile.attr('value', vlUploadMergeProfile2.attr('value'));
1114 vlUploadFtMergeProfile.attr('value', vlUploadFtMergeProfile2.attr('value'));
1115 vlUploadQueueAutoOverlayBestMatch.attr('value', vlUploadQueueAutoOverlayBestMatch2.attr('value'));
1116 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', vlUploadQueueAutoOverlayBestMatchRatio2.attr('value'));
1118 if(action == 'import') {
1119 vlImportSelectedRecords();
1120 } else if(action == 'import_all') {
1121 vlImportAllRecords();
1124 // reset the widgets to prevent accidental future actions
1125 vlUploadQueueImportNoMatch.attr('value', false);
1126 vlUploadQueueImportNoMatch2.attr('value', false);
1127 vlUploadQueueAutoOverlayExact.attr('value', false);
1128 vlUploadQueueAutoOverlayExact2.attr('value', false);
1129 vlUploadQueueAutoOverlay1Match.attr('value', false);
1130 vlUploadQueueAutoOverlay1Match2.attr('value', false);
1131 vlUploadMergeProfile.attr('value', '');
1132 vlUploadMergeProfile2.attr('value', '');
1133 vlUploadFtMergeProfile.attr('value', '');
1134 vlUploadFtMergeProfile2.attr('value', '');
1135 vlUploadQueueAutoOverlayBestMatch.attr('value', false);
1136 vlUploadQueueAutoOverlayBestMatch2.attr('value', false);
1137 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', '0.0');
1138 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', '0.0');
1142 queueItemsImportDialog.show();
1146 /* import user-selected records */
1147 function vlImportSelectedRecords() {
1150 for(var id in selectableGridRecords) {
1151 if(dojo.byId(id).checked) {
1152 var recId = selectableGridRecords[id];
1153 var rec = queuedRecordsMap[recId];
1154 if(!rec.import_time())
1155 records.push(recId);
1159 vlImportRecordQueue(
1164 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1169 /* import all (non-imported) queue records */
1170 function vlImportAllRecords() {
1171 vlImportRecordQueue(
1176 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1181 /* if recList has values, import only those records */
1182 function vlImportRecordQueue(type, queueId, recList, onload) {
1183 displayGlobalDiv('vl-generic-progress-with-total');
1185 /* set up options */
1186 var options = {overlay_map : currentOverlayRecordsMap};
1188 if(vlUploadQueueImportNoMatch.checked) {
1189 options.import_no_match = true;
1190 vlUploadQueueImportNoMatch.checked = false;
1193 if(vlUploadQueueAutoOverlayExact.checked) {
1194 options.auto_overlay_exact = true;
1195 vlUploadQueueAutoOverlayExact.checked = false;
1198 if(vlUploadQueueAutoOverlayBestMatch.checked) {
1199 options.auto_overlay_best_match = true;
1200 vlUploadQueueAutoOverlayBestMatch.checked = false;
1201 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1204 if(vlUploadQueueAutoOverlay1Match.checked) {
1205 options.auto_overlay_1match = true;
1206 vlUploadQueueAutoOverlay1Match.checked = false;
1207 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1210 var profile = vlUploadMergeProfile.attr('value');
1211 if(profile != null && profile != '') {
1212 options.merge_profile = profile;
1215 var ftprofile = vlUploadFtMergeProfile.attr('value');
1216 if(ftprofile != null && ftprofile != '') {
1217 options.fall_through_merge_profile = ftprofile;
1221 /* determine which method we're calling */
1223 var method = 'open-ils.vandelay.bib_queue.import';
1225 method = method.replace('bib', 'auth');
1227 var params = [authtoken, queueId, options];
1229 method = 'open-ils.vandelay.'+currentType+'_record.list.import';
1230 params[1] = recList;
1233 fieldmapper.standardRequest(
1234 ['open-ils.vandelay', method],
1237 onresponse: function(r) {
1238 var resp = r.recv().content();
1239 if(e = openils.Event.parse(resp))
1241 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
1243 oncomplete: function() {onload();}
1250 * Create queue, upload MARC, process spool, load the newly created queue
1252 function batchUpload() {
1253 var queueName = dijit.byId('vl-queue-name').getValue();
1254 currentType = dijit.byId('vl-record-type').getValue();
1256 var handleProcessSpool = function() {
1258 vlUploadQueueImportNoMatch.checked ||
1259 vlUploadQueueAutoOverlayExact.checked ||
1260 vlUploadQueueAutoOverlay1Match.checked ||
1261 vlUploadQueueAutoOverlayBestMatch.checked ) {
1263 vlImportRecordQueue(
1268 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1272 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1276 var handleUploadMARC = function(key) {
1277 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
1278 processSpool(key, currentQueueId, currentType, handleProcessSpool);
1281 var handleCreateQueue = function(queue) {
1282 currentQueueId = queue.id();
1283 uploadMARC(handleUploadMARC);
1286 if(vlUploadQueueSelector.getValue() && !queueName) {
1287 currentQueueId = vlUploadQueueSelector.getValue();
1288 uploadMARC(handleUploadMARC);
1290 createQueue(queueName, currentType, handleCreateQueue,
1291 vlUploadQueueHoldingsImportProfile.attr('value'),
1292 vlUploadQueueMatchSet.attr('value')
1298 function vlFleshQueueSelect(selector, type) {
1299 var data = (type == 'bib') ? vbq.toStoreData(allUserBibQueues) : vaq.toStoreData(allUserAuthQueues);
1300 selector.store = new dojo.data.ItemFileReadStore({data:data});
1301 selector.setValue(null);
1302 selector.setDisplayedValue('');
1304 selector.setValue(data[0].id());
1306 var qInput = dijit.byId('vl-queue-name');
1308 var selChange = function(val) {
1309 console.log('selector onchange');
1310 // user selected a queue from the selector; clear the input and
1311 // set the item import profile already defined for the queue
1312 var queue = allUserBibQueues.filter(function(q) { return (q.id() == val) })[0];
1314 vlUploadQueueHoldingsImportProfile.attr('value', queue.item_attr_def() || '');
1315 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
1316 vlUploadQueueMatchSet.attr('value', queue.match_set() || '');
1317 vlUploadQueueMatchSet.attr('disabled', true);
1319 vlUploadQueueHoldingsImportProfile.attr('value', '');
1320 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1321 vlUploadQueueMatchSet.attr('value', '');
1322 vlUploadQueueMatchSet.attr('disabled', false);
1324 dojo.disconnect(qInput._onchange);
1325 qInput.attr('value', '');
1326 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1329 var inputChange = function(val) {
1330 console.log('qinput onchange');
1331 // user entered a new queue name. clear the selector
1332 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1333 vlUploadQueueMatchSet.attr('disabled', false);
1334 dojo.disconnect(selector._onchange);
1335 selector.attr('value', '');
1336 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1339 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1340 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1343 function vlUpdateMatchSetSelector(type) {
1344 type = (type.match(/bib/)) ? 'biblio' : 'authority';
1345 vlUploadQueueMatchSet.store =
1346 new dojo.data.ItemFileReadStore({data:vms.toStoreData(matchSets[type])});
1349 function vlShowUploadForm() {
1350 displayGlobalDiv('vl-marc-upload-div');
1351 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
1352 vlUploadSourceSelector.store =
1353 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
1354 vlUploadSourceSelector.setValue(vlBibSources[0].id());
1355 vlUploadQueueHoldingsImportProfile.store =
1356 new dojo.data.ItemFileReadStore({data:viiad.toStoreData(importItemDefs)});
1357 vlUpdateMatchSetSelector(vlUploadRecordType.getValue());
1359 // use ratio from the merge profile if it's set
1361 vlUploadMergeProfile,
1365 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1366 if(profile.lwm_ratio() != null)
1367 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', profile.lwm_ratio()+'');
1371 vlUploadMergeProfile2,
1375 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1376 if(profile.lwm_ratio() != null)
1377 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', profile.lwm_ratio()+'');
1383 function vlShowQueueSelect() {
1384 displayGlobalDiv('vl-queue-select-div');
1385 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
1388 function vlShowMatchSetEditor() {
1389 displayGlobalDiv('vl-match-set-editor-div');
1390 dojo.byId('vl-match-set-editor-div').appendChild(
1391 dojo.create('iframe', {
1392 id : 'vl-match-set-iframe',
1393 src : oilsBasePath + '/eg/conify/global/vandelay/match_set',
1394 style : 'width:100%; height:500px; border:none; margin:0px;'
1399 function vlFetchQueueFromForm() {
1400 currentType = vlQueueSelectType.getValue();
1401 currentQueueId = vlQueueSelectQueueList.getValue();
1402 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1405 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
1407 To run in Firefox directly, must set signed.applets.codebase_principal_support
1408 to true in about:config
1410 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1411 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
1414 if (currentType == 'bib') {
1420 function onsave(r) {
1421 // after the record is saved, reload the HTML display
1422 var stat = r.recv().content();
1423 if(e = openils.Event.parse(stat))
1425 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
1427 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
1431 record : {marc : rec.marc(), "rtype": type},
1433 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
1434 func: function(xmlString) {
1435 var method = 'open-ils.permacrud.update.' + rec.classname;
1436 rec.marc(xmlString);
1437 fieldmapper.standardRequest(
1438 ['open-ils.permacrud', method],
1440 params: [authtoken, rec],
1446 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
1447 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
1451 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
1452 var method = 'open-ils.permacrud.search.vqbr';
1453 if(currentType != 'bib')
1454 method = method.replace(/vqbr/,'vqar');
1456 fieldmapper.standardRequest(
1457 ['open-ils.permacrud', method],
1459 params: [authtoken, {id : recId}],
1460 oncomplete: function(r) {
1461 var rec = r.recv().content();
1462 if(e = openils.Event.parse(rec))
1464 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
1472 //------------------------------------------------------------
1473 // attribute editors
1475 // attribute-editor global variables
1477 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
1478 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
1479 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
1481 function vlAttrEditorInit() {
1482 // set up tooltips on the edit form
1483 connectTooltip('attr-editor-tags');
1484 connectTooltip('attr-editor-subfields');
1487 function vlShowAttrEditor() {
1488 displayGlobalDiv('vl-attr-editor-div');
1489 loadAttrEditorGrid();
1490 idHide('vl-generic-progress');
1493 function setAttrEditorGroup(groupName) {
1494 // put us into 'bib'-attr or 'auth'-attr mode.
1495 if (ATTR_EDIT_GROUP != groupName) {
1496 ATTR_EDIT_GROUP = groupName;
1497 loadAttrEditorGrid();
1501 function onAttrEditorOpen() {
1502 // the "bars" have the create/update/cancel/etc. buttons.
1503 var create_bar = document.getElementById('attr-editor-create-bar');
1504 var update_bar = document.getElementById('attr-editor-update-bar');
1505 if (ATTR_EDITOR_IN_UPDATE_MODE) {
1506 update_bar.style.display='table-row';
1507 create_bar.style.display='none';
1508 // hide the dropdown-button
1509 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
1511 dijit.byId('attr-editor-dialog').reset();
1512 create_bar.style.display='table-row';
1513 update_bar.style.display='none';
1517 function onAttrEditorClose() {
1518 // reset the form to a "create" form. (We may have borrowed it for editing.)
1519 ATTR_EDITOR_IN_UPDATE_MODE = false;
1520 // show the dropdown-button
1521 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
1524 function loadAttrEditorGrid() {
1525 var _data = (ATTR_EDIT_GROUP == 'auth') ?
1526 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
1528 var store = new dojo.data.ItemFileReadStore({data:_data});
1529 attrEditorGrid.setStore(store);
1530 attrEditorGrid.onRowDblClick = onAttrEditorClick;
1531 attrEditorGrid.update();
1534 function attrGridGetTag(n, item) {
1535 // grid helper: return the tags from the row's xpath column.
1536 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
1539 function attrGridGetSubfield(n, item) {
1540 // grid helper: return the subfields from the row's xpath column.
1541 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
1544 function onAttrEditorClick() {
1545 var row = this.getItem(this.focus.rowIndex);
1546 ATTR_EDIT_ID = this.store.getValue(row, 'id');
1547 ATTR_EDITOR_IN_UPDATE_MODE = true;
1549 // populate the popup editor.
1550 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1551 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1552 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1553 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1554 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1555 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1556 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1558 // set up UI for editing
1559 dojo.byId('vl-create-attr-editor-button').click();
1562 function vlSaveAttrDefinition(data) {
1563 idHide('vl-attr-editor-div');
1564 idShow('vl-generic-progress');
1566 data.id = ATTR_EDIT_ID;
1568 // this ought to honour custom xpaths, but overwrite xpaths
1569 // derived from tags/subfields.
1570 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1571 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1572 data.xpath = _xpath;
1575 // build up our permacrud params. Key variables here are
1576 // "create or update" and "bib or auth".
1578 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1579 var isCreate = (ATTR_EDIT_ID == null);
1580 var rad = isAuth ? new vqarad() : new vqbrad() ;
1581 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1582 + (isAuth ? 'vqarad' : 'vqbrad');
1583 var _data = rad.fromStoreItem(data);
1587 fieldmapper.standardRequest(
1588 ['open-ils.permacrud', method],
1590 params: [authtoken, _data ],
1591 onresponse: function(r) { },
1592 oncomplete: function(r) {
1593 attrEditorFetchAttrDefs(vlShowAttrEditor);
1594 ATTR_EDIT_ID = null;
1596 onerror: function(r) {
1597 alert('vlSaveAttrDefinition comms error: ' + r);
1603 function attrEditorFetchAttrDefs(callback) {
1604 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1605 return fn(callback);
1608 function vlAttrDelete() {
1609 idHide('vl-attr-editor-div');
1610 idShow('vl-generic-progress');
1612 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1613 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1614 var rad = isAuth ? new vqarad() : new vqbrad() ;
1615 fieldmapper.standardRequest(
1616 ['open-ils.permacrud', method],
1618 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1619 oncomplete: function() {
1620 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1621 attrEditorFetchAttrDefs(vlShowAttrEditor);
1622 ATTR_EDIT_ID = null;
1624 onerror: function(r) {
1625 alert('vlAttrDelete comms error: ' + r);
1631 // ------------------------------------------------------------
1632 // utilities for attribute editors
1634 // dom utilities (maybe dojo does these, and these should be replaced)
1636 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1637 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1638 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1640 function connectTooltip(fieldId) {
1641 // Given an element id, look up a tooltip element in the doc (same
1642 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1643 // a better way to do this?
1644 var fld = dojo.byId(fieldId);
1645 var tip = dojo.byId(fieldId + '-tip');
1646 dojo.connect(fld, 'onfocus', function(evt) {
1647 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1648 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1653 var xpathParser = new openils.MarcXPathParser();
1655 function tagAndSubFieldsToXpath(tags, subfields) {
1656 // given tags, and subfields, build up an XPath.
1659 'tags':tags.match(/[\d]+/g),
1660 'subfields':subfields.match(/[a-zA-z]/g) };
1661 return xpathParser.compile(parts);
1663 return {'parts':null, 'tags':null, 'error':err};
1667 function looksLikeDerivedXpath(path) {
1668 // Does this path look like it was derived from tags and subfields?
1669 var parsed = xpathParser.parse(path);
1670 if (parsed.tags == null)
1672 var compiled = xpathParser.compile(parsed);
1673 return (path == compiled);
1676 // amazing xpath-util unit-tests
1677 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1678 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');
1682 var profileContextOrg
1683 function vlShowProfileEditor() {
1684 displayGlobalDiv('vl-profile-editor-div');
1687 var connect = function() {
1688 dojo.connect(profileContextOrgSelector, 'onChange',
1690 profileContextOrg = this.attr('value');
1697 new openils.User().buildPermOrgSelector(
1698 'ADMIN_MERGE_PROFILE', profileContextOrgSelector, null, connect);
1701 function buildProfileGrid() {
1703 if(profileContextOrg == null)
1704 profileContextOrg = openils.User.user.ws_ou();
1707 {order_by : {vmp : 'name'}},
1708 {owner : fieldmapper.aou.fullPath(profileContextOrg, true)}
1712 /* --- Import Item Attr Grid --------------- */
1714 var itemAttrContextOrg;
1715 var itemAttrGridFirstTime = true;
1716 function vlShowImportItemAttrEditor() {
1717 displayGlobalDiv('vl-item-attr-editor-div');
1719 if (itemAttrGridFirstTime) {
1721 buildImportItemAttrGrid();
1723 var connect = function() {
1724 dojo.connect(itemAttrContextOrgSelector, 'onChange',
1726 itemAttrContextOrg = this.attr('value');
1727 itemAttrGrid.resetStore();
1728 buildImportItemAttrGrid();
1733 new openils.User().buildPermOrgSelector(
1734 'ADMIN_IMPORT_ITEM_ATTR_DEF',
1735 itemAttrContextOrgSelector, null, connect);
1737 itemAttrGridFirstTime = false;
1741 function buildImportItemAttrGrid() {
1743 if(itemAttrContextOrg == null)
1744 itemAttrContextOrg = openils.User.user.ws_ou();
1746 itemAttrGrid.loadAll(
1747 {order_by : {viiad : 'name'}},
1748 {owner : fieldmapper.aou.fullPath(itemAttrContextOrg, true)}