1 /* ---------------------------------------------------------------------------
2 # Copyright (C) 2008 Georgia Public Library Service
3 # Bill Erickson <erickson@esilibrary.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 # --------------------------------------------------------------------------- */
15 dojo.require("dojo.parser");
16 dojo.require("dojo.io.iframe");
17 dojo.require("dijit.ProgressBar");
18 dojo.require("dijit.form.FilteringSelect");
19 dojo.require("dijit.layout.ContentPane");
20 dojo.require("dijit.layout.TabContainer");
21 dojo.require("dijit.layout.LayoutContainer");
22 dojo.require('dijit.form.Button');
23 dojo.require('dijit.form.CheckBox');
24 dojo.require('dijit.Toolbar');
25 dojo.require('dijit.Tooltip');
26 dojo.require('dijit.Menu');
27 dojo.require("dijit.Dialog");
28 dojo.require("dojo.cookie");
29 dojo.require('dojox.grid.DataGrid');
30 dojo.require("dojo.data.ItemFileReadStore");
31 dojo.require('dojo.date.locale');
32 dojo.require('dojo.date.stamp');
33 dojo.require("fieldmapper.Fieldmapper");
34 dojo.require("fieldmapper.dojoData");
35 dojo.require("fieldmapper.OrgUtils");
36 dojo.require('openils.CGI');
37 dojo.require('openils.User');
38 dojo.require('openils.Event');
39 dojo.require('openils.Util');
40 dojo.require('openils.MarcXPathParser');
41 dojo.require('openils.widget.GridColumnPicker');
42 dojo.require('openils.PermaCrud');
43 dojo.require('openils.widget.OrgUnitFilteringSelect');
44 dojo.require('openils.widget.AutoGrid');
45 dojo.require('openils.widget.AutoFieldWidget');
46 dojo.require('openils.widget.ProgressDialog');
50 'vl-generic-progress',
51 'vl-generic-progress-with-total',
56 'vl-queue-select-div',
57 'vl-marc-upload-status-div',
60 'vl-profile-editor-div',
61 'vl-item-attr-editor-div',
66 var VANDELAY_URL = '/vandelay-upload';
68 var authAttrDefs = [];
69 var queuedRecords = [];
70 var queuedRecordsMap = {};
71 var bibAttrsFetched = false;
72 var authAttrsFetched = false;
73 var attrDefMap = {}; // maps attr def code names to attr def ids
75 var currentQueueId = null;
77 var currentMatchedRecords; // set of loaded matched bib records
78 var currentOverlayRecordsMap; // map of import record to overlay record
79 var currentOverlayRecordsMapGid; // map of import record to overlay record grid id
80 var currentImportRecId; // when analyzing matches, this is the current import record
81 var userBibQueues = []; // only non-complete queues
82 var userAuthQueues = []; // only non-complete queues
84 var allUserAuthQueues;
85 var selectableGridRecords;
86 var cgi = new openils.CGI();
87 var vlQueueGridColumePicker = {};
88 var vlBibSources = [];
89 var importItemDefs = [];
91 var mergeProfiles = [];
92 var copyStatusCache = {};
93 var copyLocationCache = {};
101 dojo.requireLocalization("openils.vandelay", "vandelay");
102 localeStrings = dojo.i18n.getLocalization("openils.vandelay", "vandelay");
104 authtoken = openils.User.authtoken;
105 var initNeeded = 8; // how many async responses do we need before we're init'd
106 var initCount = 0; // how many async reponses we've received
108 openils.Util.registerEnterHandler(
109 vlQueueDisplayPage.domNode, function(){retrieveQueuedRecords();});
110 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
112 function checkInitDone() {
114 if(initCount == initNeeded)
115 runStartupCommands();
118 mergeProfiles = new openils.PermaCrud().retrieveAll('vmp');
119 vlUploadMergeProfile.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
120 vlUploadMergeProfile.labelAttr = 'name';
121 vlUploadMergeProfile.searchAttr = 'name';
122 vlUploadMergeProfile.startup();
124 vlUploadMergeProfile2.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
125 vlUploadMergeProfile2.labelAttr = 'name';
126 vlUploadMergeProfile2.searchAttr = 'name';
127 vlUploadMergeProfile2.startup();
129 vlUploadFtMergeProfile.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
130 vlUploadFtMergeProfile.labelAttr = 'name';
131 vlUploadFtMergeProfile.searchAttr = 'name';
132 vlUploadFtMergeProfile.startup();
134 vlUploadFtMergeProfile2.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
135 vlUploadFtMergeProfile2.labelAttr = 'name';
136 vlUploadFtMergeProfile2.searchAttr = 'name';
137 vlUploadFtMergeProfile2.startup();
140 // Fetch the bib and authority attribute definitions
141 vlFetchBibAttrDefs(function () { checkInitDone(); });
142 vlFetchAuthAttrDefs(function () { checkInitDone(); });
144 vlRetrieveQueueList('bib', null,
146 allUserBibQueues = list;
147 for(var i = 0; i < allUserBibQueues.length; i++) {
148 if(allUserBibQueues[i].complete() == 'f')
149 userBibQueues.push(allUserBibQueues[i]);
155 vlRetrieveQueueList('auth', null,
157 allUserAuthQueues = list;
158 for(var i = 0; i < allUserAuthQueues.length; i++) {
159 if(allUserAuthQueues[i].complete() == 'f')
160 userAuthQueues.push(allUserAuthQueues[i]);
166 fieldmapper.standardRequest(
167 ['open-ils.permacrud', 'open-ils.permacrud.search.cbs.atomic'],
169 params: [authtoken, {id:{"!=":null}}, {order_by:{cbs:'id'}}],
170 oncomplete : function(r) {
171 vlBibSources = openils.Util.readResponse(r, false, true);
177 var owner = fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(new openils.User().user.ws_ou()));
178 new openils.PermaCrud().search('viiad',
179 {owner: owner.map(function(org) { return org.id(); })},
181 oncomplete: function(r) {
182 importItemDefs = openils.Util.readResponse(r);
188 new openils.PermaCrud().search('vms',
189 {owner: owner.map(function(org) { return org.id(); })},
191 oncomplete: function(r) {
192 var sets = openils.Util.readResponse(r);
195 if(!matchSets[set.mtype()])
196 matchSets[set.mtype()] = [];
197 matchSets[set.mtype()].push(set);
205 new openils.PermaCrud().retrieveAll('ccs',
207 oncomplete: function(r) {
208 var stats = openils.Util.readResponse(r);
209 dojo.forEach(stats, function(stat){copyStatusCache[stat.id()] = stat});
220 openils.Util.addOnLoad(vlInit);
223 // fetch the bib and authority attribute definitions
225 function vlFetchBibAttrDefs(postcomplete) {
227 fieldmapper.standardRequest(
228 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
230 params: [authtoken, {id:{'!=':null}}],
231 onresponse: function(r) {
232 var def = r.recv().content();
233 if(e = openils.Event.parse(def[0]))
235 bibAttrDefs.push(def);
237 oncomplete: function() {
238 bibAttrDefs = bibAttrDefs.sort(
240 if(a.id() > b.id()) return 1;
241 if(a.id() < b.id()) return -1;
251 function vlFetchAuthAttrDefs(postcomplete) {
253 fieldmapper.standardRequest(
254 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
256 params: [authtoken, {id:{'!=':null}}],
257 onresponse: function(r) {
258 var def = r.recv().content();
259 if(e = openils.Event.parse(def[0]))
261 authAttrDefs.push(def);
263 oncomplete: function() {
264 authAttrDefs = authAttrDefs.sort(
266 if(a.id() > b.id()) return 1;
267 if(a.id() < b.id()) return -1;
277 function vlRetrieveQueueList(type, filter, onload) {
278 type = (type == 'bib') ? type : 'authority';
279 fieldmapper.standardRequest(
280 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.owner.retrieve.atomic'],
282 params: [authtoken, null, filter],
283 oncomplete: function(r) {
284 var list = r.recv().content();
285 if(e = openils.Event.parse(list[0]))
294 function displayGlobalDiv(id) {
295 for(var i = 0; i < globalDivs.length; i++) {
297 dojo.style(dojo.byId(globalDivs[i]), 'display', 'none');
299 alert('please define div ' + globalDivs[i]);
302 dojo.style(dojo.byId(id),'display','block');
304 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
305 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
306 openils.Util.removeCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
307 openils.Util.removeCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
308 openils.Util.removeCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
309 openils.Util.removeCSSClass(dojo.byId('vl-menu-match-set-editor'), 'toolbar_selected');
311 if(dojo.byId('vl-match-set-iframe'))
312 dojo.byId('vl-match-set-editor-div').removeChild(dojo.byId('vl-match-set-iframe'));
315 case 'vl-marc-export-div':
316 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
318 case 'vl-marc-upload-div':
319 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
321 case 'vl-queue-select-div':
322 openils.Util.addCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
324 case 'vl-attr-editor-div':
325 openils.Util.addCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
327 case 'vl-profile-editor-div':
328 openils.Util.addCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
330 case 'vl-item-attr-editor-div':
331 openils.Util.addCSSClass(dojo.byId('vl-menu-import-item-attr-editor'), 'toolbar_selected');
333 case 'vl-match-set-editor-div':
334 openils.Util.addCSSClass(dojo.byId('vl-menu-match-set-editor'), 'toolbar_selected');
339 function runStartupCommands() {
340 openils.Util.hide(dojo.byId('vl-page-loading'));
341 openils.Util.show(dojo.byId('vl-body-wrapper'));
342 currentQueueId = cgi.param('qid');
343 currentType = cgi.param('qtype');
344 dojo.style('vl-nav-bar', 'visibility', 'visible');
346 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
347 if (cgi.param('page', 'inspectq'))
348 return displayGlobalDiv('vl-queue-select-div');
354 * asynchronously upload a file of MARC records
356 function uploadMARC(onload){
357 dojo.byId('vl-upload-status-count').innerHTML = '0';
358 dojo.byId('vl-ses-input').value = authtoken;
359 displayGlobalDiv('vl-marc-upload-status-div');
360 dojo.io.iframe.send({
364 form: dojo.byId('vl-marc-upload-form'),
365 handle: function(data,ioArgs){
366 var content = data.documentElement.textContent;
373 * Creates a new vandelay queue
375 function createQueue(queueName, type, onload, importDefId, matchSet) {
376 var name = (type=='bib') ? 'bib' : 'authority';
377 var method = 'open-ils.vandelay.'+ name +'_queue.create'
378 fieldmapper.standardRequest(
379 ['open-ils.vandelay', method],
381 params: [authtoken, queueName, null, name, matchSet, importDefId],
382 oncomplete : function(r) {
383 var queue = r.recv().content();
384 if(e = openils.Event.parse(queue))
393 * Tells vandelay to pull a batch of records from the cache and explode them
394 * out into the vandelay tables
396 function processSpool(key, queueId, type, onload) {
397 fieldmapper.standardRequest(
398 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
400 params: [authtoken, key, queueId],
401 onresponse : function(r) {
402 var resp = r.recv().content();
403 if(e = openils.Event.parse(resp))
405 dojo.byId('vl-upload-status-count').innerHTML = resp;
407 oncomplete : function(r) {onload();}
412 function vlExportInit() {
415 var qsel = dojo.byId('vl-queue-export-options');
416 qsel.onchange = function(newVal) {
417 var value = qsel.options[qsel.selectedIndex].value;
418 qsel.selectedIndex = 0;
420 if(!confirm('Export as "' + value + '"?')) return; // TODO: i18n
421 retrieveQueuedRecords(
425 exportHandler(value, r);
426 displayGlobalDiv('vl-queue-div');
433 var isel = dojo.byId('vl-item-export-options');
434 isel.onchange = function(newVal) {
435 var value = isel.options[isel.selectedIndex].value;
436 isel.selectedIndex = 0;
438 if(!confirm('Export as "' + value + '"?')) return; // TODO: i18n
440 displayGlobalDiv('vl-generic-progress');
441 var method = 'open-ils.vandelay.import_item.queue.export.' + value + '.atomic';
443 fieldmapper.standardRequest(
444 ['open-ils.vandelay', method],
449 {with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null}
452 oncomplete : function(r) {exportHandler(value, r)}
458 function exportHandler(type, response) {
459 displayGlobalDiv('vl-import-error-div');
461 var content = openils.Util.readResponse(response);
463 if (content==1) { alert('Email sent.'); return; }
466 /* handle .atomic versus non-atomic method calls */
467 content = content.constructor == Array
468 ? content[0].template_output().data()
469 : content.template_output().data();
472 openils.Util.printHtmlString(content);
475 //content = content.replace(/\\t/g,'\t'); // if we really wanted to do .tsv instead
476 openils.XUL.contentToFileSaveDialog(content, null, {
477 defaultString : 'VandelayExport.csv',
478 defaultExtension : '.csv',
480 filterExtension : '*.csv',
485 alert('response = ' + response + '\tcontent:\n' + content);
488 alert('Error exporting data: ' + E);
492 function retrieveQueuedRecords(type, queueId, onload, doExport) {
493 displayGlobalDiv('vl-generic-progress');
495 queuedRecordsMap = {};
496 currentOverlayRecordsMap = {};
497 currentOverlayRecordsMapGid = {};
498 selectableGridRecords = {};
500 if(!type) type = currentType;
501 if(!queueId) queueId = currentQueueId;
502 if(!onload) onload = handleRetrieveRecords;
504 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve';
506 if(doExport) method += '.export.' + doExport;
507 if(vlQueueGridShowMatches.checked)
508 method = method.replace('records', 'records.matches');
512 var sel = dojo.byId('vl-queue-display-limit-selector');
513 var limit = parseInt(sel.options[sel.selectedIndex].value);
514 var offset = limit * parseInt(vlQueueDisplayPage.attr('value')-1);
516 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit, flesh_import_items:1}];
517 if(vlQueueGridShowNonImport.checked)
518 params[2].non_imported = 1;
520 if(vlQueueGridShowImportErrors.checked)
521 params[2].with_import_error = 1;
523 fieldmapper.standardRequest(
524 ['open-ils.vandelay', method],
527 oncomplete: function(r){
528 if(doExport) return onload(r);
529 var recs = r.recv().content();
530 if(e = openils.Event.parse(recs[0]))
532 for(var i = 0; i < recs.length; i++) {
534 queuedRecords.push(rec);
535 queuedRecordsMap[rec.id()] = rec;
543 function vlLoadMatchUI(recId) {
544 displayGlobalDiv('vl-generic-progress');
545 var queuedRec = queuedRecordsMap[recId];
546 var matches = queuedRec.matches();
548 currentImportRecId = recId;
549 for(var i = 0; i < matches.length; i++)
550 records.push(matches[i].eg_record());
552 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
553 var params = [records];
554 if(currentType == 'auth') {
555 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
556 params = [authtoken, records, {clear_marc:1}];
559 fieldmapper.standardRequest(
563 oncomplete: function(r) {
564 var recs = r.recv().content();
565 if(e = openils.Event.parse(recs))
569 displayGlobalDiv('vl-match-div');
570 resetVlMatchGridLayout();
571 currentMatchedRecords = recs;
572 vlMatchGrid.setStructure(vlMatchGridLayout);
574 // build the data store of records with match information
575 var dataStore = bre.toStoreData(recs, null,
576 {virtualFields:['_id', 'match_score', 'match_quality', 'rec_quality']});
577 dataStore.identifier = '_id';
579 var matchSeenMap = {};
581 for(var i = 0; i < dataStore.items.length; i++) {
582 var item = dataStore.items[i];
583 item._id = i; // just need something unique
584 for(var j = 0; j < matches.length; j++) {
585 var match = matches[j];
586 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
587 if(match.match_score)
588 item.match_score = match.match_score();
589 item.match_quality = match.quality();
590 item.rec_quality = queuedRec.quality();
591 matchSeenMap[match.id()] = 1;
597 // now populate the grid
598 vlPopulateMatchGrid(vlMatchGrid, dataStore);
604 function vlPopulateMatchGrid(grid, data) {
605 var store = new dojo.data.ItemFileReadStore({data:data});
606 grid.setStore(store);
610 function showMe(id) {
611 dojo.style(dojo.byId(id), 'display', 'block');
613 function hideMe(id) {
614 dojo.style(dojo.byId(id), 'display', 'none');
618 function vlLoadMARCHtml(recId, inCat, oncomplete) {
619 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
620 displayGlobalDiv('vl-generic-progress');
622 var params = [recId, 1];
625 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
626 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
627 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
628 if(currentType == 'auth')
629 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
631 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
632 dijit.byId('vl-marc-html-edit-button').onClick =
633 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
634 params = [authtoken, recId];
635 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
636 if(currentType == 'auth')
637 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
640 fieldmapper.standardRequest(
644 oncomplete: function(r) {
645 displayGlobalDiv('vl-marc-html-div');
646 var html = r.recv().content();
647 dojo.byId('vl-marc-record-html').innerHTML = html;
655 function getRecMatchesFromAttrCode(rec, attrCode) {
657 var attr = getRecAttrFromCode(rec, attrCode);
658 for(var j = 0; j < rec.matches().length; j++) {
659 var match = rec.matches()[j];
660 if(match.matched_attr() == attr.id())
668 function getRecAttrFromMatch(rec, match) {
669 for(var i = 0; i < rec.attributes().length; i++) {
670 var attr = rec.attributes()[i];
671 if(attr.id() == match.matched_attr())
677 function getRecAttrDefFromAttr(attr, type) {
678 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
679 for(var i = 0; i < defs.length; i++) {
681 if(def.id() == attr.field())
686 function getRecAttrFromCode(rec, attrCode) {
687 var defId = attrDefMap[currentType][attrCode];
688 var attrs = rec.attributes();
689 for(var i = 0; i < attrs.length; i++) {
691 if(attr.field() == defId)
697 function vlGetViewMatches(rowIdx, item) {
699 var id = this.grid.store.getValue(item, 'id');
700 var rec = queuedRecordsMap[id];
701 if(rec.matches().length > 0)
702 return id + ':' + rec.matches().length;
707 function vlFormatViewMatches(id) {
708 if(id == -1) return '';
709 var chunks = id.split(':');
712 return '<a href="javascript:void(0);" onclick="vlLoadMatchUI(' + id + ');">' + this.name + ' (' + count + ')</a>';
715 function vlGetViewErrors(rowIdx, item) {
717 var id = this.grid.store.getValue(item, 'id');
718 var rec = queuedRecordsMap[id];
719 // id:rec_error:item_import_error_count
721 (rec.import_error() ? 1 : '') + ':' +
722 (typeof rec.import_items == 'function'
723 ? rec.import_items().filter(function(i) {return i.import_error()}).length
730 function vlFormatViewErrors(chunk) {
731 if(chunk == -1) return '';
732 var id = chunk.split(':')[0];
733 var rec = chunk.split(':')[1];
734 var count = chunk.split(':')[2];
737 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Record</a><br/>'; // TODO I18N
739 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Items ('+count+')</a>'; // TODO I18N
743 //var vlItemErrorColumnPicker;
744 function vlLoadErrorUI(id) {
746 displayGlobalDiv('vl-import-error-div');
747 openils.Util.hide('vl-import-error-grid-all');
748 openils.Util.show('vl-import-error-record');
750 var rec = queuedRecordsMap[id];
752 dojo.byId('vl-error-id').innerHTML = rec.id();
753 dojo.forEach( // TODO sane authority rec. fields
754 ['title', 'author', 'isbn', 'issn', 'upc'],
756 var attr = getRecAttrFromCode(rec, field);
757 var eid = 'vl-error-' + field;
759 openils.Util.show(dojo.byId(eid).parentNode, 'table-row');
760 dojo.byId(eid).innerHTML = attr.attr_value();
762 openils.Util.hide(dojo.byId(eid).parentNode);
766 var iediv = dojo.byId('vl-error-import-error');
767 var eddiv = dojo.byId('vl-error-error-detail');
768 if(rec.import_error()) {
769 openils.Util.show(iediv.parentNode, 'table-row');
770 openils.Util.show(eddiv.parentNode, 'table-row');
771 iediv.innerHTML = rec.import_error();
772 eddiv.innerHTML = rec.error_detail();
774 openils.Util.hide(iediv.parentNode);
775 openils.Util.hide(eddiv.parentNode);
778 var errorItems = rec.import_items().filter(function(i) {return i.import_error()});
779 if(errorItems.length) {
780 openils.Util.show('vl-import-error-grid-some');
781 storeData = vqbr.toStoreData(errorItems);
782 var store = new dojo.data.ItemFileReadStore({data:storeData});
783 vlImportErrorGrid.setStore(store);
784 vlImportErrorGrid.update();
786 openils.Util.hide('vl-import-error-grid-some');
790 function vlLoadErrorUIAll() {
792 displayGlobalDiv('vl-import-error-div');
793 openils.Util.hide('vl-import-error-grid-some');
794 openils.Util.hide('vl-import-error-record');
795 openils.Util.show('vl-import-error-grid-all');
796 vlAllImportErrorGrid.resetStore();
798 vlImportErrorGrid.displayOffset = 0;
800 vlAllImportErrorGrid.dataLoader = function() {
802 vlAllImportErrorGrid.showLoadProgressIndicator();
804 fieldmapper.standardRequest(
805 ['open-ils.vandelay', 'open-ils.vandelay.import_item.queue.retrieve'],
809 authtoken, currentQueueId, {
810 with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null,
811 offset : vlAllImportErrorGrid.displayOffset,
812 limit : vlAllImportErrorGrid.displayLimit
815 onresponse : function(r) {
816 var item = openils.Util.readResponse(r);
818 vlAllImportErrorGrid.store.newItem(vii.toStoreItem(item));
820 oncomplete : function() {
821 vlAllImportErrorGrid.hideLoadProgressIndicator();
827 vlAllImportErrorGrid.dataLoader();
830 function vlGetOrg(rowIdx, item) {
832 var value = this.grid.store.getValue(item, this.field);
833 if(value) return fieldmapper.aou.findOrgUnit(value).shortname();
837 function vlCopyStatus(rowIdx, item) {
839 var value = this.grid.store.getValue(item, this.field);
840 if(value) return copyStatusCache[value].name();
844 // Note, we don't pre-fetch all copy locations because there could be
845 // a lot of them. Instead, fetch-and-cache on demand.
846 function vlCopyLocation(rowIdx, item) {
848 var value = this.grid.store.getValue(item, this.field);
850 if(!copyLocationCache[value]) {
851 copyLocationCache[value] =
852 new openils.PermaCrud().retrieve('acpl', value);
854 return copyLocationCache[value].name();
860 function vlFormatViewMatchMARC(id) {
861 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', true, '+
862 'function(){displayGlobalDiv(\'vl-match-div\');});">' + this.name + '</a>';
865 function getAttrValue(rowIdx, item) {
867 var attrCode = this.field.split('.')[1];
868 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
869 var attr = getRecAttrFromCode(rec, attrCode);
870 return (attr) ? attr.attr_value() : '';
873 function vlGetDateTimeField(rowIdx, item) {
875 var value = this.grid.store.getValue(item, this.field);
876 if(!value) return '';
877 var date = dojo.date.stamp.fromISOString(value);
878 return dojo.date.locale.format(date, {selector:'date'});
881 function vlGetCreator(rowIdx, item) {
883 var id = this.grid.store.getValue(item, 'creator');
885 return userCache[id].usrname();
886 var user = fieldmapper.standardRequest(
887 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
888 if(e = openils.Event.parse(user))
890 userCache[id] = user;
891 return user.usrname();
894 function vlGetViewMARC(rowIdx, item) {
895 return item && this.grid.store.getValue(item, 'id');
898 function vlFormatViewMARC(id) {
899 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
900 'function(){displayGlobalDiv(\'vl-queue-div\');});">' + this.name + '</a>';
903 function vlGetOverlayTargetSelector(rowIdx, item) {
905 return this.grid.store.getValue(item, '_id') + ':' + this.grid.store.getValue(item, 'id');
908 function vlFormatOverlayTargetSelector(val) {
910 var parts = val.split(':');
913 var value = '<input type="checkbox" name="vl-overlay-target-RECID" '+
914 'onclick="vlHandleOverlayTargetSelected(ID, GRIDID);" gridid="GRIDID" match="ID"/>';
915 value = value.replace(/GRIDID/g, _id);
916 value = value.replace(/RECID/g, currentImportRecId);
917 value = value.replace(/ID/g, id);
918 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
919 return value.replace('/>', 'checked="checked"/>');
925 * see if the user has enabled overlays for the current match set and,
926 * if so, map the current import record to the overlay target.
928 function vlHandleOverlayTargetSelected(recId, gridId) {
929 var noneSelected = true;
930 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
931 for(var i = 0; i < checkboxes.length; i++) {
932 var checkbox = checkboxes[i];
933 var matchRecId = checkbox.getAttribute('match');
934 var gid = checkbox.getAttribute('gridid');
935 if(checkbox.checked) {
936 if(matchRecId == recId && gid == gridId) {
937 noneSelected = false;
938 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
939 currentOverlayRecordsMapGid[currentImportRecId] = gid;
940 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
941 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
943 checkbox.checked = false;
949 delete currentOverlayRecordsMap[currentImportRecId];
950 delete currentOverlayRecordsMapGid[currentImportRecId];
951 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
952 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
956 var valLastQueueType = null;
957 var vlQueueGridLayout = null;
958 function buildRecordGrid(type) {
959 displayGlobalDiv('vl-queue-div');
961 vlBibQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
962 vlAuthQueueGrid.canSort = function(col){ if(Math.abs(col) == 1) { return false; } else { return true; } };
965 openils.Util.show('vl-bib-queue-grid-wrapper');
966 openils.Util.hide('vl-auth-queue-grid-wrapper');
967 vlQueueGrid = vlBibQueueGrid;
968 openils.Util.show('add-to-bucket-action', 'table-row');
970 openils.Util.show('vl-auth-queue-grid-wrapper');
971 openils.Util.hide('vl-bib-queue-grid-wrapper');
972 vlQueueGrid = vlAuthQueueGrid;
973 openils.Util.hide('add-to-bucket-action');
977 if(valLastQueueType != type) {
978 valLastQueueType = type;
979 vlQueueGridLayout = vlQueueGrid.attr('structure');
980 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
981 attrDefMap[type] = {};
982 for(var i = 0; i < defs.length; i++) {
984 attrDefMap[type][def.code()] = def.id();
986 name:def.description(),
987 field:'attr.' + def.code(),
989 selectableColumn:true
991 vlQueueGridLayout[0].cells[0].push(col);
995 dojo.forEach(vlQueueGridLayout[0].cells[0],
997 if(cell.field.match(/^\+/))
998 cell.nonSelectable=true;
1004 storeData = vqbr.toStoreData(queuedRecords);
1006 storeData = vqar.toStoreData(queuedRecords);
1008 var store = new dojo.data.ItemFileReadStore({data:storeData});
1009 vlQueueGrid.setStore(store);
1011 if(vlQueueGridColumePicker[type]) {
1012 vlQueueGrid.update();
1015 vlQueueGridColumePicker[type] =
1016 new openils.widget.GridColumnPicker(
1017 authtoken, 'vandelay.queue.'+type, vlQueueGrid, vlQueueGridLayout);
1018 vlQueueGridColumePicker[type].load();
1022 function vlQueueGridPrevPage() {
1023 var page = parseInt(vlQueueDisplayPage.getValue());
1024 if(page < 2) return;
1025 vlQueueDisplayPage.setValue(page - 1);
1026 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1029 function vlQueueGridNextPage() {
1030 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
1031 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1034 function vlDeleteQueue(type, queueId, onload) {
1035 fieldmapper.standardRequest(
1036 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
1038 params: [authtoken, queueId],
1039 oncomplete: function(r) {
1040 var resp = r.recv().content();
1041 if(e = openils.Event.parse(resp))
1050 function vlQueueGridDrawSelectBox(rowIdx, item) {
1051 return item && this.grid.store.getValue(item, 'id');
1054 function vlQueueGridFormatSelectBox(id) {
1055 var domId = 'vl-record-list-selected-' + id;
1056 if (id) { selectableGridRecords[domId] = id; }
1057 return "<div><input type='checkbox' id='"+domId+"'/></div>";
1060 function vlSelectAllQueueGridRecords() {
1061 for(var id in selectableGridRecords)
1062 dojo.byId(id).checked = true;
1064 function vlSelectNoQueueGridRecords() {
1065 for(var id in selectableGridRecords)
1066 dojo.byId(id).checked = false;
1068 function vlToggleQueueGridSelect() {
1069 if(dojo.byId('vl-queue-grid-row-selector').checked)
1070 vlSelectAllQueueGridRecords();
1072 vlSelectNoQueueGridRecords();
1075 var handleRetrieveRecords = function() {
1076 buildRecordGrid(currentType);
1077 vlFetchQueueSummary(currentQueueId, currentType,
1079 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
1080 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
1081 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
1082 dojo.byId('vl-queue-summary-import-item-count').innerHTML = summary.total_items + '';
1083 dojo.byId('vl-queue-summary-import-item-imported-count').innerHTML = summary.total_items_imported + '';
1084 dojo.byId('vl-queue-summary-rec-error-count').innerHTML = summary.rec_import_errors + '';
1085 dojo.byId('vl-queue-summary-item-error-count').innerHTML = summary.item_import_errors + '';
1087 if (dojo.byId('create-bucket-dialog-name')) {
1088 dojo.byId('create-bucket-dialog-name').value = summary.queue.name();
1094 function vlFetchQueueSummary(qId, type, onload) {
1095 fieldmapper.standardRequest(
1096 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
1098 params: [authtoken, qId],
1099 oncomplete : function(r) {
1100 var summary = r.recv().content();
1101 if(e = openils.Event.parse(summary))
1103 return onload(summary);
1109 function handleCreateBucket(args) {
1110 var bname = dojo.byId('create-bucket-dialog-name').value;
1113 progressDialog.show(true);
1114 fieldmapper.standardRequest(
1115 ['open-ils.vandelay', 'open-ils.vandelay.bib_queue.to_bucket'],
1117 params : [authtoken, currentQueueId, bname],
1118 oncomplete : function(r) {
1119 progressDialog.hide();
1120 setTimeout(function() {
1121 var resp = openils.Util.readResponse(r);
1122 if (resp.add_count == 0) {
1123 alert(localeStrings.NO_BUCKET_ITEMS);
1126 dojo.string.substitute(
1127 localeStrings.BUCKET_CREATE_SUCCESS,
1128 [resp.add_count, bname, resp.item_count]
1132 }, 200); // give the dialog a chance to hide
1139 var _importCancelHandler;
1140 var _importGoHandler;
1141 function vlHandleQueueItemsAction(action) {
1143 if(_importCancelHandler) dojo.disconnect(_importCancelHandler);
1145 _importCancelHandler = dojo.connect(
1146 queueItemsImportCancelButton,
1149 queueItemsImportDialog.hide();
1153 if(_importGoHandler)
1154 dojo.disconnect(_importGoHandler);
1156 _importGoHandler = dojo.connect(
1157 queueItemsImportGoButton,
1160 queueItemsImportDialog.hide();
1162 // hack to set the widgets the import funcs will be looking at. Reset them below.
1163 vlUploadQueueImportNoMatch.attr('value', vlUploadQueueImportNoMatch2.attr('value'));
1164 vlUploadQueueAutoOverlayExact.attr('value', vlUploadQueueAutoOverlayExact2.attr('value'));
1165 vlUploadQueueAutoOverlay1Match.attr('value', vlUploadQueueAutoOverlay1Match2.attr('value'));
1166 vlUploadMergeProfile.attr('value', vlUploadMergeProfile2.attr('value'));
1167 vlUploadFtMergeProfile.attr('value', vlUploadFtMergeProfile2.attr('value'));
1168 vlUploadQueueAutoOverlayBestMatch.attr('value', vlUploadQueueAutoOverlayBestMatch2.attr('value'));
1169 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', vlUploadQueueAutoOverlayBestMatchRatio2.attr('value'));
1171 if(action == 'import') {
1172 vlImportSelectedRecords();
1173 } else if(action == 'import_all') {
1174 vlImportAllRecords();
1177 // reset the widgets to prevent accidental future actions
1178 vlUploadQueueImportNoMatch.attr('value', false);
1179 vlUploadQueueImportNoMatch2.attr('value', false);
1180 vlUploadQueueAutoOverlayExact.attr('value', false);
1181 vlUploadQueueAutoOverlayExact2.attr('value', false);
1182 vlUploadQueueAutoOverlay1Match.attr('value', false);
1183 vlUploadQueueAutoOverlay1Match2.attr('value', false);
1184 vlUploadMergeProfile.attr('value', '');
1185 vlUploadMergeProfile2.attr('value', '');
1186 vlUploadFtMergeProfile.attr('value', '');
1187 vlUploadFtMergeProfile2.attr('value', '');
1188 vlUploadQueueAutoOverlayBestMatch.attr('value', false);
1189 vlUploadQueueAutoOverlayBestMatch2.attr('value', false);
1190 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', '0.0');
1191 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', '0.0');
1195 queueItemsImportDialog.show();
1198 function vlHandleCreateBucket() {
1200 create-bucket-dialog-name
1204 /* import user-selected records */
1205 function vlImportSelectedRecords() {
1208 for(var id in selectableGridRecords) {
1209 if(dojo.byId(id).checked) {
1210 var recId = selectableGridRecords[id];
1211 var rec = queuedRecordsMap[recId];
1212 if(!rec.import_time())
1213 records.push(recId);
1217 vlImportRecordQueue(
1222 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1227 /* import all (non-imported) queue records */
1228 function vlImportAllRecords() {
1229 vlImportRecordQueue(
1234 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1239 /* if recList has values, import only those records */
1240 function vlImportRecordQueue(type, queueId, recList, onload) {
1241 displayGlobalDiv('vl-generic-progress-with-total');
1243 /* set up options */
1244 var options = {overlay_map : currentOverlayRecordsMap};
1246 if(vlUploadQueueImportNoMatch.checked) {
1247 options.import_no_match = true;
1248 vlUploadQueueImportNoMatch.checked = false;
1251 if(vlUploadQueueAutoOverlayExact.checked) {
1252 options.auto_overlay_exact = true;
1253 vlUploadQueueAutoOverlayExact.checked = false;
1256 if(vlUploadQueueAutoOverlayBestMatch.checked) {
1257 options.auto_overlay_best_match = true;
1258 vlUploadQueueAutoOverlayBestMatch.checked = false;
1259 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1262 if(vlUploadQueueAutoOverlay1Match.checked) {
1263 options.auto_overlay_1match = true;
1264 vlUploadQueueAutoOverlay1Match.checked = false;
1265 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1268 var profile = vlUploadMergeProfile.attr('value');
1269 if(profile != null && profile != '') {
1270 options.merge_profile = profile;
1273 var ftprofile = vlUploadFtMergeProfile.attr('value');
1274 if(ftprofile != null && ftprofile != '') {
1275 options.fall_through_merge_profile = ftprofile;
1279 /* determine which method we're calling */
1281 var method = 'open-ils.vandelay.bib_queue.import';
1283 method = method.replace('bib', 'auth');
1285 var params = [authtoken, queueId, options];
1287 method = 'open-ils.vandelay.'+currentType+'_record.list.import';
1288 params[1] = recList;
1291 fieldmapper.standardRequest(
1292 ['open-ils.vandelay', method],
1295 onresponse: function(r) {
1296 var resp = r.recv().content();
1297 if(e = openils.Event.parse(resp))
1299 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
1301 oncomplete: function() {onload();}
1308 * Create queue, upload MARC, process spool, load the newly created queue
1310 function batchUpload() {
1311 var queueName = dijit.byId('vl-queue-name').getValue();
1312 currentType = dijit.byId('vl-record-type').getValue();
1314 var handleProcessSpool = function() {
1316 vlUploadQueueImportNoMatch.checked ||
1317 vlUploadQueueAutoOverlayExact.checked ||
1318 vlUploadQueueAutoOverlay1Match.checked ||
1319 vlUploadQueueAutoOverlayBestMatch.checked ) {
1321 vlImportRecordQueue(
1326 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1330 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1334 var handleUploadMARC = function(key) {
1335 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
1336 processSpool(key, currentQueueId, currentType, handleProcessSpool);
1339 var handleCreateQueue = function(queue) {
1340 currentQueueId = queue.id();
1341 uploadMARC(handleUploadMARC);
1344 if(vlUploadQueueSelector.getValue() && !queueName) {
1345 currentQueueId = vlUploadQueueSelector.getValue();
1346 uploadMARC(handleUploadMARC);
1348 createQueue(queueName, currentType, handleCreateQueue,
1349 vlUploadQueueHoldingsImportProfile.attr('value'),
1350 vlUploadQueueMatchSet.attr('value')
1356 function vlFleshQueueSelect(selector, type) {
1358 if (type == 'bib') {
1359 var bibList = allUserBibQueues.filter(
1361 return (q.queue_type() == 'bib');
1364 data = vbq.toStoreData(bibList);
1365 } else if (type == 'bib-acq') {
1366 // ACQ queues are a special type of bib queue
1367 var acqList = allUserBibQueues.filter(
1369 return (q.queue_type() == 'acq');
1372 data = vbq.toStoreData(acqList);
1374 data = vaq.toStoreData(allUserAuthQueues);
1377 selector.store = new dojo.data.ItemFileReadStore({data:data});
1378 selector.setValue(null);
1379 selector.setDisplayedValue('');
1381 selector.setValue(data[0].id());
1383 var qInput = dijit.byId('vl-queue-name');
1385 var selChange = function(val) {
1386 console.log('selector onchange');
1387 // user selected a queue from the selector; clear the input and
1388 // set the item import profile already defined for the queue
1389 var queue = allUserBibQueues.filter(function(q) { return (q.id() == val) })[0];
1391 vlUploadQueueHoldingsImportProfile.attr('value', queue.item_attr_def() || '');
1392 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
1393 vlUploadQueueMatchSet.attr('value', queue.match_set() || '');
1394 vlUploadQueueMatchSet.attr('disabled', true);
1396 vlUploadQueueHoldingsImportProfile.attr('value', '');
1397 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1398 vlUploadQueueMatchSet.attr('value', '');
1399 vlUploadQueueMatchSet.attr('disabled', false);
1401 dojo.disconnect(qInput._onchange);
1402 qInput.attr('value', '');
1403 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1406 var inputChange = function(val) {
1407 console.log('qinput onchange');
1408 // user entered a new queue name. clear the selector
1409 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1410 vlUploadQueueMatchSet.attr('disabled', false);
1411 dojo.disconnect(selector._onchange);
1412 selector.attr('value', '');
1413 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1416 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1417 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1420 function vlUpdateMatchSetSelector(type) {
1421 type = (type.match(/bib/)) ? 'biblio' : 'authority';
1422 vlUploadQueueMatchSet.store =
1423 new dojo.data.ItemFileReadStore({data:vms.toStoreData(matchSets[type])});
1426 function vlShowUploadForm() {
1427 displayGlobalDiv('vl-marc-upload-div');
1428 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
1429 vlUploadSourceSelector.store =
1430 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
1431 vlUploadSourceSelector.setValue(vlBibSources[0].id());
1432 vlUploadQueueHoldingsImportProfile.store =
1433 new dojo.data.ItemFileReadStore({data:viiad.toStoreData(importItemDefs)});
1434 vlUpdateMatchSetSelector(vlUploadRecordType.getValue());
1436 // use ratio from the merge profile if it's set
1438 vlUploadMergeProfile,
1442 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1443 if(profile.lwm_ratio() != null)
1444 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', profile.lwm_ratio()+'');
1448 vlUploadMergeProfile2,
1452 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1453 if(profile.lwm_ratio() != null)
1454 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', profile.lwm_ratio()+'');
1460 function vlShowQueueSelect() {
1461 displayGlobalDiv('vl-queue-select-div');
1462 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
1465 function vlShowMatchSetEditor() {
1466 displayGlobalDiv('vl-match-set-editor-div');
1467 dojo.byId('vl-match-set-editor-div').appendChild(
1468 dojo.create('iframe', {
1469 id : 'vl-match-set-iframe',
1470 src : oilsBasePath + '/conify/global/vandelay/match_set',
1471 style : 'width:100%; height:500px; border:none; margin:0px;'
1476 function vlFetchQueueFromForm() {
1477 currentType = vlQueueSelectType.attr('value').replace(/-.*/, ''); // trim bib-acq
1478 currentQueueId = vlQueueSelectQueueList.getValue();
1479 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1482 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
1484 To run in Firefox directly, must set signed.applets.codebase_principal_support
1485 to true in about:config
1487 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1488 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
1491 if (currentType == 'bib') {
1497 function onsave(r) {
1498 // after the record is saved, reload the HTML display
1499 var stat = r.recv().content();
1500 if(e = openils.Event.parse(stat))
1502 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
1504 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
1508 record : {marc : rec.marc(), "rtype": type},
1510 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
1511 func: function(xmlString) {
1512 var method = 'open-ils.permacrud.update.' + rec.classname;
1513 rec.marc(xmlString);
1514 fieldmapper.standardRequest(
1515 ['open-ils.permacrud', method],
1517 params: [authtoken, rec],
1523 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
1524 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
1528 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
1529 var method = 'open-ils.permacrud.search.vqbr';
1530 if(currentType != 'bib')
1531 method = method.replace(/vqbr/,'vqar');
1533 fieldmapper.standardRequest(
1534 ['open-ils.permacrud', method],
1536 params: [authtoken, {id : recId}],
1537 oncomplete: function(r) {
1538 var rec = r.recv().content();
1539 if(e = openils.Event.parse(rec))
1541 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
1549 //------------------------------------------------------------
1550 // attribute editors
1552 // attribute-editor global variables
1554 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
1555 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
1556 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
1558 function vlAttrEditorInit() {
1559 // set up tooltips on the edit form
1560 connectTooltip('attr-editor-tags');
1561 connectTooltip('attr-editor-subfields');
1564 function vlShowAttrEditor() {
1565 displayGlobalDiv('vl-attr-editor-div');
1566 loadAttrEditorGrid();
1567 idHide('vl-generic-progress');
1570 function setAttrEditorGroup(groupName) {
1571 // put us into 'bib'-attr or 'auth'-attr mode.
1572 if (ATTR_EDIT_GROUP != groupName) {
1573 ATTR_EDIT_GROUP = groupName;
1574 loadAttrEditorGrid();
1578 function onAttrEditorOpen() {
1579 // the "bars" have the create/update/cancel/etc. buttons.
1580 var create_bar = document.getElementById('attr-editor-create-bar');
1581 var update_bar = document.getElementById('attr-editor-update-bar');
1582 if (ATTR_EDITOR_IN_UPDATE_MODE) {
1583 update_bar.style.display='table-row';
1584 create_bar.style.display='none';
1585 // hide the dropdown-button
1586 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
1588 dijit.byId('attr-editor-dialog').reset();
1589 create_bar.style.display='table-row';
1590 update_bar.style.display='none';
1594 function onAttrEditorClose() {
1595 // reset the form to a "create" form. (We may have borrowed it for editing.)
1596 ATTR_EDITOR_IN_UPDATE_MODE = false;
1597 // show the dropdown-button
1598 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
1601 function loadAttrEditorGrid() {
1602 var _data = (ATTR_EDIT_GROUP == 'auth') ?
1603 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
1605 var store = new dojo.data.ItemFileReadStore({data:_data});
1606 attrEditorGrid.setStore(store);
1607 attrEditorGrid.onRowDblClick = onAttrEditorClick;
1608 attrEditorGrid.update();
1611 function attrGridGetTag(n, item) {
1612 // grid helper: return the tags from the row's xpath column.
1613 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
1616 function attrGridGetSubfield(n, item) {
1617 // grid helper: return the subfields from the row's xpath column.
1618 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
1621 function onAttrEditorClick() {
1622 var row = this.getItem(this.focus.rowIndex);
1623 ATTR_EDIT_ID = this.store.getValue(row, 'id');
1624 ATTR_EDITOR_IN_UPDATE_MODE = true;
1626 // populate the popup editor.
1627 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1628 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1629 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1630 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1631 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1632 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1633 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1635 // set up UI for editing
1636 dojo.byId('vl-create-attr-editor-button').click();
1639 function vlSaveAttrDefinition(data) {
1640 idHide('vl-attr-editor-div');
1641 idShow('vl-generic-progress');
1643 data.id = ATTR_EDIT_ID;
1645 // this ought to honour custom xpaths, but overwrite xpaths
1646 // derived from tags/subfields.
1647 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1648 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1649 data.xpath = _xpath;
1652 // build up our permacrud params. Key variables here are
1653 // "create or update" and "bib or auth".
1655 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1656 var isCreate = (ATTR_EDIT_ID == null);
1657 var rad = isAuth ? new vqarad() : new vqbrad() ;
1658 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1659 + (isAuth ? 'vqarad' : 'vqbrad');
1660 var _data = rad.fromStoreItem(data);
1664 fieldmapper.standardRequest(
1665 ['open-ils.permacrud', method],
1667 params: [authtoken, _data ],
1668 onresponse: function(r) { },
1669 oncomplete: function(r) {
1670 attrEditorFetchAttrDefs(vlShowAttrEditor);
1671 ATTR_EDIT_ID = null;
1673 onerror: function(r) {
1674 alert('vlSaveAttrDefinition comms error: ' + r);
1680 function attrEditorFetchAttrDefs(callback) {
1681 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1682 return fn(callback);
1685 function vlAttrDelete() {
1686 idHide('vl-attr-editor-div');
1687 idShow('vl-generic-progress');
1689 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1690 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1691 var rad = isAuth ? new vqarad() : new vqbrad() ;
1692 fieldmapper.standardRequest(
1693 ['open-ils.permacrud', method],
1695 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1696 oncomplete: function() {
1697 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1698 attrEditorFetchAttrDefs(vlShowAttrEditor);
1699 ATTR_EDIT_ID = null;
1701 onerror: function(r) {
1702 alert('vlAttrDelete comms error: ' + r);
1708 // ------------------------------------------------------------
1709 // utilities for attribute editors
1711 // dom utilities (maybe dojo does these, and these should be replaced)
1713 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1714 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1715 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1717 function connectTooltip(fieldId) {
1718 // Given an element id, look up a tooltip element in the doc (same
1719 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1720 // a better way to do this?
1721 var fld = dojo.byId(fieldId);
1722 var tip = dojo.byId(fieldId + '-tip');
1723 dojo.connect(fld, 'onfocus', function(evt) {
1724 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1725 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1730 var xpathParser = new openils.MarcXPathParser();
1732 function tagAndSubFieldsToXpath(tags, subfields) {
1733 // given tags, and subfields, build up an XPath.
1736 'tags':tags.match(/[\d]+/g),
1737 'subfields':subfields.match(/[a-zA-z]/g) };
1738 return xpathParser.compile(parts);
1740 return {'parts':null, 'tags':null, 'error':err};
1744 function looksLikeDerivedXpath(path) {
1745 // Does this path look like it was derived from tags and subfields?
1746 var parsed = xpathParser.parse(path);
1747 if (parsed.tags == null)
1749 var compiled = xpathParser.compile(parsed);
1750 return (path == compiled);
1753 // amazing xpath-util unit-tests
1754 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1755 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');
1759 var profileContextOrg
1760 function vlShowProfileEditor() {
1761 displayGlobalDiv('vl-profile-editor-div');
1764 var connect = function() {
1765 dojo.connect(profileContextOrgSelector, 'onChange',
1767 profileContextOrg = this.attr('value');
1774 new openils.User().buildPermOrgSelector(
1775 'ADMIN_MERGE_PROFILE', profileContextOrgSelector, null, connect);
1778 function buildProfileGrid() {
1780 if(profileContextOrg == null)
1781 profileContextOrg = openils.User.user.ws_ou();
1784 {order_by : {vmp : 'name'}},
1785 {owner : fieldmapper.aou.fullPath(profileContextOrg, true)}
1789 /* --- Import Item Attr Grid --------------- */
1791 var itemAttrContextOrg;
1792 var itemAttrGridFirstTime = true;
1793 function vlShowImportItemAttrEditor() {
1794 displayGlobalDiv('vl-item-attr-editor-div');
1796 if (itemAttrGridFirstTime) {
1798 buildImportItemAttrGrid();
1800 var connect = function() {
1801 dojo.connect(itemAttrContextOrgSelector, 'onChange',
1803 itemAttrContextOrg = this.attr('value');
1804 itemAttrGrid.resetStore();
1805 buildImportItemAttrGrid();
1810 new openils.User().buildPermOrgSelector(
1811 'ADMIN_IMPORT_ITEM_ATTR_DEF',
1812 itemAttrContextOrgSelector, null, connect);
1814 itemAttrGridFirstTime = false;
1818 function buildImportItemAttrGrid() {
1820 if(itemAttrContextOrg == null)
1821 itemAttrContextOrg = openils.User.user.ws_ou();
1823 itemAttrGrid.loadAll(
1824 {order_by : {viiad : 'name'}},
1825 {owner : fieldmapper.aou.fullPath(itemAttrContextOrg, true)}