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, null, {
466 defaultString : 'VandelayExport.csv',
467 defaultExtension : '.csv',
469 filterExtension : '*.csv',
474 alert('response = ' + response + '\tcontent:\n' + content);
477 alert('Error exporting data: ' + E);
481 function retrieveQueuedRecords(type, queueId, onload, doExport) {
482 displayGlobalDiv('vl-generic-progress');
484 queuedRecordsMap = {};
485 currentOverlayRecordsMap = {};
486 currentOverlayRecordsMapGid = {};
487 selectableGridRecords = {};
489 if(!type) type = currentType;
490 if(!queueId) queueId = currentQueueId;
491 if(!onload) onload = handleRetrieveRecords;
493 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve';
495 if(doExport) method += '.export.' + doExport;
496 if(vlQueueGridShowMatches.checked)
497 method = method.replace('records', 'records.matches');
501 var sel = dojo.byId('vl-queue-display-limit-selector');
502 var limit = parseInt(sel.options[sel.selectedIndex].value);
503 var offset = limit * parseInt(vlQueueDisplayPage.attr('value')-1);
505 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit, flesh_import_items:1}];
506 if(vlQueueGridShowNonImport.checked)
507 params[2].non_imported = 1;
509 if(vlQueueGridShowImportErrors.checked)
510 params[2].with_import_error = 1;
512 fieldmapper.standardRequest(
513 ['open-ils.vandelay', method],
516 oncomplete: function(r){
517 if(doExport) return onload(r);
518 var recs = r.recv().content();
519 if(e = openils.Event.parse(recs[0]))
521 for(var i = 0; i < recs.length; i++) {
523 queuedRecords.push(rec);
524 queuedRecordsMap[rec.id()] = rec;
532 function vlLoadMatchUI(recId) {
533 displayGlobalDiv('vl-generic-progress');
534 var queuedRec = queuedRecordsMap[recId];
535 var matches = queuedRec.matches();
537 currentImportRecId = recId;
538 for(var i = 0; i < matches.length; i++)
539 records.push(matches[i].eg_record());
541 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
542 var params = [records];
543 if(currentType == 'auth') {
544 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
545 params = [authtoken, records, {clear_marc:1}];
548 fieldmapper.standardRequest(
552 oncomplete: function(r) {
553 var recs = r.recv().content();
554 if(e = openils.Event.parse(recs))
558 displayGlobalDiv('vl-match-div');
559 resetVlMatchGridLayout();
560 currentMatchedRecords = recs;
561 vlMatchGrid.setStructure(vlMatchGridLayout);
563 // build the data store of records with match information
564 var dataStore = bre.toStoreData(recs, null,
565 {virtualFields:['_id', 'match_score', 'match_quality', 'rec_quality']});
566 dataStore.identifier = '_id';
568 var matchSeenMap = {};
570 for(var i = 0; i < dataStore.items.length; i++) {
571 var item = dataStore.items[i];
572 item._id = i; // just need something unique
573 for(var j = 0; j < matches.length; j++) {
574 var match = matches[j];
575 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
576 if(match.match_score)
577 item.match_score = match.match_score();
578 item.match_quality = match.quality();
579 item.rec_quality = queuedRec.quality();
580 matchSeenMap[match.id()] = 1;
586 // now populate the grid
587 vlPopulateMatchGrid(vlMatchGrid, dataStore);
593 function vlPopulateMatchGrid(grid, data) {
594 var store = new dojo.data.ItemFileReadStore({data:data});
595 grid.setStore(store);
599 function showMe(id) {
600 dojo.style(dojo.byId(id), 'display', 'block');
602 function hideMe(id) {
603 dojo.style(dojo.byId(id), 'display', 'none');
607 function vlLoadMARCHtml(recId, inCat, oncomplete) {
608 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
609 displayGlobalDiv('vl-generic-progress');
611 var params = [recId, 1];
614 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
615 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
616 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
617 if(currentType == 'auth')
618 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
620 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
621 dijit.byId('vl-marc-html-edit-button').onClick =
622 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
623 params = [authtoken, recId];
624 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
625 if(currentType == 'auth')
626 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
629 fieldmapper.standardRequest(
633 oncomplete: function(r) {
634 displayGlobalDiv('vl-marc-html-div');
635 var html = r.recv().content();
636 dojo.byId('vl-marc-record-html').innerHTML = html;
644 function getRecMatchesFromAttrCode(rec, attrCode) {
646 var attr = getRecAttrFromCode(rec, attrCode);
647 for(var j = 0; j < rec.matches().length; j++) {
648 var match = rec.matches()[j];
649 if(match.matched_attr() == attr.id())
657 function getRecAttrFromMatch(rec, match) {
658 for(var i = 0; i < rec.attributes().length; i++) {
659 var attr = rec.attributes()[i];
660 if(attr.id() == match.matched_attr())
666 function getRecAttrDefFromAttr(attr, type) {
667 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
668 for(var i = 0; i < defs.length; i++) {
670 if(def.id() == attr.field())
675 function getRecAttrFromCode(rec, attrCode) {
676 var defId = attrDefMap[currentType][attrCode];
677 var attrs = rec.attributes();
678 for(var i = 0; i < attrs.length; i++) {
680 if(attr.field() == defId)
686 function vlGetViewMatches(rowIdx, item) {
688 var id = this.grid.store.getValue(item, 'id');
689 var rec = queuedRecordsMap[id];
690 if(rec.matches().length > 0)
691 return id + ':' + rec.matches().length;
696 function vlFormatViewMatches(id) {
697 if(id == -1) return '';
698 var chunks = id.split(':');
701 return '<a href="javascript:void(0);" onclick="vlLoadMatchUI(' + id + ');">' + this.name + ' (' + count + ')</a>';
704 function vlGetViewErrors(rowIdx, item) {
706 var id = this.grid.store.getValue(item, 'id');
707 var rec = queuedRecordsMap[id];
708 // id:rec_error:item_import_error_count
710 (rec.import_error() ? 1 : '') + ':' +
711 (typeof rec.import_items == 'function'
712 ? rec.import_items().filter(function(i) {return i.import_error()}).length
719 function vlFormatViewErrors(chunk) {
720 if(chunk == -1) return '';
721 var id = chunk.split(':')[0];
722 var rec = chunk.split(':')[1];
723 var count = chunk.split(':')[2];
726 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Record</a><br/>'; // TODO I18N
728 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Items ('+count+')</a>'; // TODO I18N
732 //var vlItemErrorColumnPicker;
733 function vlLoadErrorUI(id) {
735 displayGlobalDiv('vl-import-error-div');
736 openils.Util.hide('vl-import-error-grid-all');
737 openils.Util.show('vl-import-error-record');
739 var rec = queuedRecordsMap[id];
741 dojo.byId('vl-error-id').innerHTML = rec.id();
742 dojo.forEach( // TODO sane authority rec. fields
743 ['title', 'author', 'isbn', 'issn', 'upc'],
745 var attr = getRecAttrFromCode(rec, field);
746 var eid = 'vl-error-' + field;
748 openils.Util.show(dojo.byId(eid).parentNode, 'table-row');
749 dojo.byId(eid).innerHTML = attr.attr_value();
751 openils.Util.hide(dojo.byId(eid).parentNode);
755 var iediv = dojo.byId('vl-error-import-error');
756 var eddiv = dojo.byId('vl-error-error-detail');
757 if(rec.import_error()) {
758 openils.Util.show(iediv.parentNode, 'table-row');
759 openils.Util.show(eddiv.parentNode, 'table-row');
760 iediv.innerHTML = rec.import_error();
761 eddiv.innerHTML = rec.error_detail();
763 openils.Util.hide(iediv.parentNode);
764 openils.Util.hide(eddiv.parentNode);
767 var errorItems = rec.import_items().filter(function(i) {return i.import_error()});
768 if(errorItems.length) {
769 openils.Util.show('vl-import-error-grid-some');
770 storeData = vqbr.toStoreData(errorItems);
771 var store = new dojo.data.ItemFileReadStore({data:storeData});
772 vlImportErrorGrid.setStore(store);
773 vlImportErrorGrid.update();
775 openils.Util.hide('vl-import-error-grid-some');
779 function vlLoadErrorUIAll() {
781 displayGlobalDiv('vl-import-error-div');
782 openils.Util.hide('vl-import-error-grid-some');
783 openils.Util.hide('vl-import-error-record');
784 openils.Util.show('vl-import-error-grid-all');
785 vlAllImportErrorGrid.resetStore();
787 vlImportErrorGrid.displayOffset = 0;
789 vlAllImportErrorGrid.dataLoader = function() {
791 vlAllImportErrorGrid.showLoadProgressIndicator();
793 fieldmapper.standardRequest(
794 ['open-ils.vandelay', 'open-ils.vandelay.import_item.queue.retrieve'],
798 authtoken, currentQueueId, {
799 with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null,
800 offset : vlAllImportErrorGrid.displayOffset,
801 limit : vlAllImportErrorGrid.displayLimit
804 onresponse : function(r) {
805 var item = openils.Util.readResponse(r);
807 vlAllImportErrorGrid.store.newItem(vii.toStoreItem(item));
809 oncomplete : function() {
810 vlAllImportErrorGrid.hideLoadProgressIndicator();
816 vlAllImportErrorGrid.dataLoader();
819 function vlGetOrg(rowIdx, item) {
821 var value = this.grid.store.getValue(item, this.field);
822 if(value) return fieldmapper.aou.findOrgUnit(value).shortname();
826 function vlCopyStatus(rowIdx, item) {
828 var value = this.grid.store.getValue(item, this.field);
829 if(value) return copyStatusCache[value].name();
833 // Note, we don't pre-fetch all copy locations because there could be
834 // a lot of them. Instead, fetch-and-cache on demand.
835 function vlCopyLocation(rowIdx, item) {
837 var value = this.grid.store.getValue(item, this.field);
839 if(!copyLocationCache[value]) {
840 copyLocationCache[value] =
841 new openils.PermaCrud().retrieve('acpl', value);
843 return copyLocationCache[value].name();
849 function vlFormatViewMatchMARC(id) {
850 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', true, '+
851 'function(){displayGlobalDiv(\'vl-match-div\');});">' + this.name + '</a>';
854 function getAttrValue(rowIdx, item) {
856 var attrCode = this.field.split('.')[1];
857 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
858 var attr = getRecAttrFromCode(rec, attrCode);
859 return (attr) ? attr.attr_value() : '';
862 function vlGetDateTimeField(rowIdx, item) {
864 var value = this.grid.store.getValue(item, this.field);
865 if(!value) return '';
866 var date = dojo.date.stamp.fromISOString(value);
867 return dojo.date.locale.format(date, {selector:'date'});
870 function vlGetCreator(rowIdx, item) {
872 var id = this.grid.store.getValue(item, 'creator');
874 return userCache[id].usrname();
875 var user = fieldmapper.standardRequest(
876 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
877 if(e = openils.Event.parse(user))
879 userCache[id] = user;
880 return user.usrname();
883 function vlGetViewMARC(rowIdx, item) {
884 return item && this.grid.store.getValue(item, 'id');
887 function vlFormatViewMARC(id) {
888 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
889 'function(){displayGlobalDiv(\'vl-queue-div\');});">' + this.name + '</a>';
892 function vlGetOverlayTargetSelector(rowIdx, item) {
894 return this.grid.store.getValue(item, '_id') + ':' + this.grid.store.getValue(item, 'id');
897 function vlFormatOverlayTargetSelector(val) {
899 var parts = val.split(':');
902 var value = '<input type="checkbox" name="vl-overlay-target-RECID" '+
903 'onclick="vlHandleOverlayTargetSelected(ID, GRIDID);" gridid="GRIDID" match="ID"/>';
904 value = value.replace(/GRIDID/g, _id);
905 value = value.replace(/RECID/g, currentImportRecId);
906 value = value.replace(/ID/g, id);
907 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
908 return value.replace('/>', 'checked="checked"/>');
914 * see if the user has enabled overlays for the current match set and,
915 * if so, map the current import record to the overlay target.
917 function vlHandleOverlayTargetSelected(recId, gridId) {
918 var noneSelected = true;
919 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
920 for(var i = 0; i < checkboxes.length; i++) {
921 var checkbox = checkboxes[i];
922 var matchRecId = checkbox.getAttribute('match');
923 var gid = checkbox.getAttribute('gridid');
924 if(checkbox.checked) {
925 if(matchRecId == recId && gid == gridId) {
926 noneSelected = false;
927 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
928 currentOverlayRecordsMapGid[currentImportRecId] = gid;
929 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
930 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
932 checkbox.checked = false;
938 delete currentOverlayRecordsMap[currentImportRecId];
939 delete currentOverlayRecordsMapGid[currentImportRecId];
940 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
941 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
945 var valLastQueueType = null;
946 var vlQueueGridLayout = null;
947 function buildRecordGrid(type) {
948 displayGlobalDiv('vl-queue-div');
950 vlBibQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
951 vlAuthQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
954 openils.Util.show('vl-bib-queue-grid-wrapper');
955 openils.Util.hide('vl-auth-queue-grid-wrapper');
956 vlQueueGrid = vlBibQueueGrid;
958 openils.Util.show('vl-auth-queue-grid-wrapper');
959 openils.Util.hide('vl-bib-queue-grid-wrapper');
960 vlQueueGrid = vlAuthQueueGrid;
964 if(valLastQueueType != type) {
965 valLastQueueType = type;
966 vlQueueGridLayout = vlQueueGrid.attr('structure');
967 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
968 attrDefMap[type] = {};
969 for(var i = 0; i < defs.length; i++) {
971 attrDefMap[type][def.code()] = def.id();
973 name:def.description(),
974 field:'attr.' + def.code(),
976 selectableColumn:true
978 vlQueueGridLayout[0].cells[0].push(col);
982 dojo.forEach(vlQueueGridLayout[0].cells[0],
984 if(cell.field.match(/^\+/))
985 cell.nonSelectable=true;
991 storeData = vqbr.toStoreData(queuedRecords);
993 storeData = vqar.toStoreData(queuedRecords);
995 var store = new dojo.data.ItemFileReadStore({data:storeData});
996 vlQueueGrid.setStore(store);
998 if(vlQueueGridColumePicker[type]) {
999 vlQueueGrid.update();
1002 vlQueueGridColumePicker[type] =
1003 new openils.widget.GridColumnPicker(
1004 authtoken, 'vandelay.queue.'+type, vlQueueGrid, vlQueueGridLayout);
1005 vlQueueGridColumePicker[type].load();
1009 function vlQueueGridPrevPage() {
1010 var page = parseInt(vlQueueDisplayPage.getValue());
1011 if(page < 2) return;
1012 vlQueueDisplayPage.setValue(page - 1);
1013 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1016 function vlQueueGridNextPage() {
1017 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
1018 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1021 function vlDeleteQueue(type, queueId, onload) {
1022 fieldmapper.standardRequest(
1023 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
1025 params: [authtoken, queueId],
1026 oncomplete: function(r) {
1027 var resp = r.recv().content();
1028 if(e = openils.Event.parse(resp))
1037 function vlQueueGridDrawSelectBox(rowIdx, item) {
1038 return item && this.grid.store.getValue(item, 'id');
1041 function vlQueueGridFormatSelectBox(id) {
1042 var domId = 'vl-record-list-selected-' + id;
1043 if (id) { selectableGridRecords[domId] = id; }
1044 return "<div><input type='checkbox' id='"+domId+"'/></div>";
1047 function vlSelectAllQueueGridRecords() {
1048 for(var id in selectableGridRecords)
1049 dojo.byId(id).checked = true;
1051 function vlSelectNoQueueGridRecords() {
1052 for(var id in selectableGridRecords)
1053 dojo.byId(id).checked = false;
1055 function vlToggleQueueGridSelect() {
1056 if(dojo.byId('vl-queue-grid-row-selector').checked)
1057 vlSelectAllQueueGridRecords();
1059 vlSelectNoQueueGridRecords();
1062 var handleRetrieveRecords = function() {
1063 buildRecordGrid(currentType);
1064 vlFetchQueueSummary(currentQueueId, currentType,
1066 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
1067 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
1068 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
1069 dojo.byId('vl-queue-summary-import-item-count').innerHTML = summary.total_items + '';
1070 dojo.byId('vl-queue-summary-import-item-imported-count').innerHTML = summary.total_items_imported + '';
1071 dojo.byId('vl-queue-summary-rec-error-count').innerHTML = summary.rec_import_errors + '';
1072 dojo.byId('vl-queue-summary-item-error-count').innerHTML = summary.item_import_errors + '';
1077 function vlFetchQueueSummary(qId, type, onload) {
1078 fieldmapper.standardRequest(
1079 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
1081 params: [authtoken, qId],
1082 oncomplete : function(r) {
1083 var summary = r.recv().content();
1084 if(e = openils.Event.parse(summary))
1086 return onload(summary);
1092 var _importCancelHandler;
1093 var _importGoHandler;
1094 function vlHandleQueueItemsAction(action) {
1096 if(_importCancelHandler) dojo.disconnect(_importCancelHandler);
1098 _importCancelHandler = dojo.connect(
1099 queueItemsImportCancelButton,
1102 queueItemsImportDialog.hide();
1106 if(_importGoHandler)
1107 dojo.disconnect(_importGoHandler);
1109 _importGoHandler = dojo.connect(
1110 queueItemsImportGoButton,
1113 queueItemsImportDialog.hide();
1115 // hack to set the widgets the import funcs will be looking at. Reset them below.
1116 vlUploadQueueImportNoMatch.attr('value', vlUploadQueueImportNoMatch2.attr('value'));
1117 vlUploadQueueAutoOverlayExact.attr('value', vlUploadQueueAutoOverlayExact2.attr('value'));
1118 vlUploadQueueAutoOverlay1Match.attr('value', vlUploadQueueAutoOverlay1Match2.attr('value'));
1119 vlUploadMergeProfile.attr('value', vlUploadMergeProfile2.attr('value'));
1120 vlUploadFtMergeProfile.attr('value', vlUploadFtMergeProfile2.attr('value'));
1121 vlUploadQueueAutoOverlayBestMatch.attr('value', vlUploadQueueAutoOverlayBestMatch2.attr('value'));
1122 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', vlUploadQueueAutoOverlayBestMatchRatio2.attr('value'));
1124 if(action == 'import') {
1125 vlImportSelectedRecords();
1126 } else if(action == 'import_all') {
1127 vlImportAllRecords();
1130 // reset the widgets to prevent accidental future actions
1131 vlUploadQueueImportNoMatch.attr('value', false);
1132 vlUploadQueueImportNoMatch2.attr('value', false);
1133 vlUploadQueueAutoOverlayExact.attr('value', false);
1134 vlUploadQueueAutoOverlayExact2.attr('value', false);
1135 vlUploadQueueAutoOverlay1Match.attr('value', false);
1136 vlUploadQueueAutoOverlay1Match2.attr('value', false);
1137 vlUploadMergeProfile.attr('value', '');
1138 vlUploadMergeProfile2.attr('value', '');
1139 vlUploadFtMergeProfile.attr('value', '');
1140 vlUploadFtMergeProfile2.attr('value', '');
1141 vlUploadQueueAutoOverlayBestMatch.attr('value', false);
1142 vlUploadQueueAutoOverlayBestMatch2.attr('value', false);
1143 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', '0.0');
1144 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', '0.0');
1148 queueItemsImportDialog.show();
1152 /* import user-selected records */
1153 function vlImportSelectedRecords() {
1156 for(var id in selectableGridRecords) {
1157 if(dojo.byId(id).checked) {
1158 var recId = selectableGridRecords[id];
1159 var rec = queuedRecordsMap[recId];
1160 if(!rec.import_time())
1161 records.push(recId);
1165 vlImportRecordQueue(
1170 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1175 /* import all (non-imported) queue records */
1176 function vlImportAllRecords() {
1177 vlImportRecordQueue(
1182 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1187 /* if recList has values, import only those records */
1188 function vlImportRecordQueue(type, queueId, recList, onload) {
1189 displayGlobalDiv('vl-generic-progress-with-total');
1191 /* set up options */
1192 var options = {overlay_map : currentOverlayRecordsMap};
1194 if(vlUploadQueueImportNoMatch.checked) {
1195 options.import_no_match = true;
1196 vlUploadQueueImportNoMatch.checked = false;
1199 if(vlUploadQueueAutoOverlayExact.checked) {
1200 options.auto_overlay_exact = true;
1201 vlUploadQueueAutoOverlayExact.checked = false;
1204 if(vlUploadQueueAutoOverlayBestMatch.checked) {
1205 options.auto_overlay_best_match = true;
1206 vlUploadQueueAutoOverlayBestMatch.checked = false;
1207 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1210 if(vlUploadQueueAutoOverlay1Match.checked) {
1211 options.auto_overlay_1match = true;
1212 vlUploadQueueAutoOverlay1Match.checked = false;
1213 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1216 var profile = vlUploadMergeProfile.attr('value');
1217 if(profile != null && profile != '') {
1218 options.merge_profile = profile;
1221 var ftprofile = vlUploadFtMergeProfile.attr('value');
1222 if(ftprofile != null && ftprofile != '') {
1223 options.fall_through_merge_profile = ftprofile;
1227 /* determine which method we're calling */
1229 var method = 'open-ils.vandelay.bib_queue.import';
1231 method = method.replace('bib', 'auth');
1233 var params = [authtoken, queueId, options];
1235 method = 'open-ils.vandelay.'+currentType+'_record.list.import';
1236 params[1] = recList;
1239 fieldmapper.standardRequest(
1240 ['open-ils.vandelay', method],
1243 onresponse: function(r) {
1244 var resp = r.recv().content();
1245 if(e = openils.Event.parse(resp))
1247 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
1249 oncomplete: function() {onload();}
1256 * Create queue, upload MARC, process spool, load the newly created queue
1258 function batchUpload() {
1259 var queueName = dijit.byId('vl-queue-name').getValue();
1260 currentType = dijit.byId('vl-record-type').getValue();
1262 var handleProcessSpool = function() {
1264 vlUploadQueueImportNoMatch.checked ||
1265 vlUploadQueueAutoOverlayExact.checked ||
1266 vlUploadQueueAutoOverlay1Match.checked ||
1267 vlUploadQueueAutoOverlayBestMatch.checked ) {
1269 vlImportRecordQueue(
1274 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1278 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1282 var handleUploadMARC = function(key) {
1283 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
1284 processSpool(key, currentQueueId, currentType, handleProcessSpool);
1287 var handleCreateQueue = function(queue) {
1288 currentQueueId = queue.id();
1289 uploadMARC(handleUploadMARC);
1292 if(vlUploadQueueSelector.getValue() && !queueName) {
1293 currentQueueId = vlUploadQueueSelector.getValue();
1294 uploadMARC(handleUploadMARC);
1296 createQueue(queueName, currentType, handleCreateQueue,
1297 vlUploadQueueHoldingsImportProfile.attr('value'),
1298 vlUploadQueueMatchSet.attr('value')
1304 function vlFleshQueueSelect(selector, type) {
1305 var data = (type == 'bib') ? vbq.toStoreData(allUserBibQueues) : vaq.toStoreData(allUserAuthQueues);
1306 selector.store = new dojo.data.ItemFileReadStore({data:data});
1307 selector.setValue(null);
1308 selector.setDisplayedValue('');
1310 selector.setValue(data[0].id());
1312 var qInput = dijit.byId('vl-queue-name');
1314 var selChange = function(val) {
1315 console.log('selector onchange');
1316 // user selected a queue from the selector; clear the input and
1317 // set the item import profile already defined for the queue
1318 var queue = allUserBibQueues.filter(function(q) { return (q.id() == val) })[0];
1320 vlUploadQueueHoldingsImportProfile.attr('value', queue.item_attr_def() || '');
1321 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
1322 vlUploadQueueMatchSet.attr('value', queue.match_set() || '');
1323 vlUploadQueueMatchSet.attr('disabled', true);
1325 vlUploadQueueHoldingsImportProfile.attr('value', '');
1326 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1327 vlUploadQueueMatchSet.attr('value', '');
1328 vlUploadQueueMatchSet.attr('disabled', false);
1330 dojo.disconnect(qInput._onchange);
1331 qInput.attr('value', '');
1332 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1335 var inputChange = function(val) {
1336 console.log('qinput onchange');
1337 // user entered a new queue name. clear the selector
1338 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1339 vlUploadQueueMatchSet.attr('disabled', false);
1340 dojo.disconnect(selector._onchange);
1341 selector.attr('value', '');
1342 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1345 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1346 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1349 function vlUpdateMatchSetSelector(type) {
1350 type = (type.match(/bib/)) ? 'biblio' : 'authority';
1351 vlUploadQueueMatchSet.store =
1352 new dojo.data.ItemFileReadStore({data:vms.toStoreData(matchSets[type])});
1355 function vlShowUploadForm() {
1356 displayGlobalDiv('vl-marc-upload-div');
1357 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
1358 vlUploadSourceSelector.store =
1359 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
1360 vlUploadSourceSelector.setValue(vlBibSources[0].id());
1361 vlUploadQueueHoldingsImportProfile.store =
1362 new dojo.data.ItemFileReadStore({data:viiad.toStoreData(importItemDefs)});
1363 vlUpdateMatchSetSelector(vlUploadRecordType.getValue());
1365 // use ratio from the merge profile if it's set
1367 vlUploadMergeProfile,
1371 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1372 if(profile.lwm_ratio() != null)
1373 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', profile.lwm_ratio()+'');
1377 vlUploadMergeProfile2,
1381 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1382 if(profile.lwm_ratio() != null)
1383 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', profile.lwm_ratio()+'');
1389 function vlShowQueueSelect() {
1390 displayGlobalDiv('vl-queue-select-div');
1391 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
1394 function vlShowMatchSetEditor() {
1395 displayGlobalDiv('vl-match-set-editor-div');
1396 dojo.byId('vl-match-set-editor-div').appendChild(
1397 dojo.create('iframe', {
1398 id : 'vl-match-set-iframe',
1399 src : oilsBasePath + '/conify/global/vandelay/match_set',
1400 style : 'width:100%; height:500px; border:none; margin:0px;'
1405 function vlFetchQueueFromForm() {
1406 currentType = vlQueueSelectType.getValue();
1407 currentQueueId = vlQueueSelectQueueList.getValue();
1408 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1411 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
1413 To run in Firefox directly, must set signed.applets.codebase_principal_support
1414 to true in about:config
1416 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1417 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
1420 if (currentType == 'bib') {
1426 function onsave(r) {
1427 // after the record is saved, reload the HTML display
1428 var stat = r.recv().content();
1429 if(e = openils.Event.parse(stat))
1431 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
1433 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
1437 record : {marc : rec.marc(), "rtype": type},
1439 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
1440 func: function(xmlString) {
1441 var method = 'open-ils.permacrud.update.' + rec.classname;
1442 rec.marc(xmlString);
1443 fieldmapper.standardRequest(
1444 ['open-ils.permacrud', method],
1446 params: [authtoken, rec],
1452 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
1453 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
1457 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
1458 var method = 'open-ils.permacrud.search.vqbr';
1459 if(currentType != 'bib')
1460 method = method.replace(/vqbr/,'vqar');
1462 fieldmapper.standardRequest(
1463 ['open-ils.permacrud', method],
1465 params: [authtoken, {id : recId}],
1466 oncomplete: function(r) {
1467 var rec = r.recv().content();
1468 if(e = openils.Event.parse(rec))
1470 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
1478 //------------------------------------------------------------
1479 // attribute editors
1481 // attribute-editor global variables
1483 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
1484 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
1485 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
1487 function vlAttrEditorInit() {
1488 // set up tooltips on the edit form
1489 connectTooltip('attr-editor-tags');
1490 connectTooltip('attr-editor-subfields');
1493 function vlShowAttrEditor() {
1494 displayGlobalDiv('vl-attr-editor-div');
1495 loadAttrEditorGrid();
1496 idHide('vl-generic-progress');
1499 function setAttrEditorGroup(groupName) {
1500 // put us into 'bib'-attr or 'auth'-attr mode.
1501 if (ATTR_EDIT_GROUP != groupName) {
1502 ATTR_EDIT_GROUP = groupName;
1503 loadAttrEditorGrid();
1507 function onAttrEditorOpen() {
1508 // the "bars" have the create/update/cancel/etc. buttons.
1509 var create_bar = document.getElementById('attr-editor-create-bar');
1510 var update_bar = document.getElementById('attr-editor-update-bar');
1511 if (ATTR_EDITOR_IN_UPDATE_MODE) {
1512 update_bar.style.display='table-row';
1513 create_bar.style.display='none';
1514 // hide the dropdown-button
1515 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
1517 dijit.byId('attr-editor-dialog').reset();
1518 create_bar.style.display='table-row';
1519 update_bar.style.display='none';
1523 function onAttrEditorClose() {
1524 // reset the form to a "create" form. (We may have borrowed it for editing.)
1525 ATTR_EDITOR_IN_UPDATE_MODE = false;
1526 // show the dropdown-button
1527 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
1530 function loadAttrEditorGrid() {
1531 var _data = (ATTR_EDIT_GROUP == 'auth') ?
1532 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
1534 var store = new dojo.data.ItemFileReadStore({data:_data});
1535 attrEditorGrid.setStore(store);
1536 attrEditorGrid.onRowDblClick = onAttrEditorClick;
1537 attrEditorGrid.update();
1540 function attrGridGetTag(n, item) {
1541 // grid helper: return the tags from the row's xpath column.
1542 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
1545 function attrGridGetSubfield(n, item) {
1546 // grid helper: return the subfields from the row's xpath column.
1547 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
1550 function onAttrEditorClick() {
1551 var row = this.getItem(this.focus.rowIndex);
1552 ATTR_EDIT_ID = this.store.getValue(row, 'id');
1553 ATTR_EDITOR_IN_UPDATE_MODE = true;
1555 // populate the popup editor.
1556 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1557 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1558 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1559 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1560 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1561 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1562 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1564 // set up UI for editing
1565 dojo.byId('vl-create-attr-editor-button').click();
1568 function vlSaveAttrDefinition(data) {
1569 idHide('vl-attr-editor-div');
1570 idShow('vl-generic-progress');
1572 data.id = ATTR_EDIT_ID;
1574 // this ought to honour custom xpaths, but overwrite xpaths
1575 // derived from tags/subfields.
1576 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1577 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1578 data.xpath = _xpath;
1581 // build up our permacrud params. Key variables here are
1582 // "create or update" and "bib or auth".
1584 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1585 var isCreate = (ATTR_EDIT_ID == null);
1586 var rad = isAuth ? new vqarad() : new vqbrad() ;
1587 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1588 + (isAuth ? 'vqarad' : 'vqbrad');
1589 var _data = rad.fromStoreItem(data);
1593 fieldmapper.standardRequest(
1594 ['open-ils.permacrud', method],
1596 params: [authtoken, _data ],
1597 onresponse: function(r) { },
1598 oncomplete: function(r) {
1599 attrEditorFetchAttrDefs(vlShowAttrEditor);
1600 ATTR_EDIT_ID = null;
1602 onerror: function(r) {
1603 alert('vlSaveAttrDefinition comms error: ' + r);
1609 function attrEditorFetchAttrDefs(callback) {
1610 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1611 return fn(callback);
1614 function vlAttrDelete() {
1615 idHide('vl-attr-editor-div');
1616 idShow('vl-generic-progress');
1618 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1619 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1620 var rad = isAuth ? new vqarad() : new vqbrad() ;
1621 fieldmapper.standardRequest(
1622 ['open-ils.permacrud', method],
1624 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1625 oncomplete: function() {
1626 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1627 attrEditorFetchAttrDefs(vlShowAttrEditor);
1628 ATTR_EDIT_ID = null;
1630 onerror: function(r) {
1631 alert('vlAttrDelete comms error: ' + r);
1637 // ------------------------------------------------------------
1638 // utilities for attribute editors
1640 // dom utilities (maybe dojo does these, and these should be replaced)
1642 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1643 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1644 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1646 function connectTooltip(fieldId) {
1647 // Given an element id, look up a tooltip element in the doc (same
1648 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1649 // a better way to do this?
1650 var fld = dojo.byId(fieldId);
1651 var tip = dojo.byId(fieldId + '-tip');
1652 dojo.connect(fld, 'onfocus', function(evt) {
1653 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1654 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1659 var xpathParser = new openils.MarcXPathParser();
1661 function tagAndSubFieldsToXpath(tags, subfields) {
1662 // given tags, and subfields, build up an XPath.
1665 'tags':tags.match(/[\d]+/g),
1666 'subfields':subfields.match(/[a-zA-z]/g) };
1667 return xpathParser.compile(parts);
1669 return {'parts':null, 'tags':null, 'error':err};
1673 function looksLikeDerivedXpath(path) {
1674 // Does this path look like it was derived from tags and subfields?
1675 var parsed = xpathParser.parse(path);
1676 if (parsed.tags == null)
1678 var compiled = xpathParser.compile(parsed);
1679 return (path == compiled);
1682 // amazing xpath-util unit-tests
1683 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1684 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');
1688 var profileContextOrg
1689 function vlShowProfileEditor() {
1690 displayGlobalDiv('vl-profile-editor-div');
1693 var connect = function() {
1694 dojo.connect(profileContextOrgSelector, 'onChange',
1696 profileContextOrg = this.attr('value');
1703 new openils.User().buildPermOrgSelector(
1704 'ADMIN_MERGE_PROFILE', profileContextOrgSelector, null, connect);
1707 function buildProfileGrid() {
1709 if(profileContextOrg == null)
1710 profileContextOrg = openils.User.user.ws_ou();
1713 {order_by : {vmp : 'name'}},
1714 {owner : fieldmapper.aou.fullPath(profileContextOrg, true)}
1718 /* --- Import Item Attr Grid --------------- */
1720 var itemAttrContextOrg;
1721 var itemAttrGridFirstTime = true;
1722 function vlShowImportItemAttrEditor() {
1723 displayGlobalDiv('vl-item-attr-editor-div');
1725 if (itemAttrGridFirstTime) {
1727 buildImportItemAttrGrid();
1729 var connect = function() {
1730 dojo.connect(itemAttrContextOrgSelector, 'onChange',
1732 itemAttrContextOrg = this.attr('value');
1733 itemAttrGrid.resetStore();
1734 buildImportItemAttrGrid();
1739 new openils.User().buildPermOrgSelector(
1740 'ADMIN_IMPORT_ITEM_ATTR_DEF',
1741 itemAttrContextOrgSelector, null, connect);
1743 itemAttrGridFirstTime = false;
1747 function buildImportItemAttrGrid() {
1749 if(itemAttrContextOrg == null)
1750 itemAttrContextOrg = openils.User.user.ws_ou();
1752 itemAttrGrid.loadAll(
1753 {order_by : {viiad : 'name'}},
1754 {owner : fieldmapper.aou.fullPath(itemAttrContextOrg, true)}