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 = [];
96 authtoken = openils.User.authtoken;
97 var initNeeded = 7; // how many async responses do we need before we're init'd
98 var initCount = 0; // how many async reponses we've received
100 openils.Util.registerEnterHandler(
101 vlQueueDisplayPage.domNode, function(){retrieveQueuedRecords();});
102 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
104 function checkInitDone() {
106 if(initCount == initNeeded)
107 runStartupCommands();
110 mergeProfiles = new openils.PermaCrud().retrieveAll('vmp');
111 vlUploadMergeProfile.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
112 vlUploadMergeProfile.labelAttr = 'name';
113 vlUploadMergeProfile.searchAttr = 'name';
114 vlUploadMergeProfile.startup();
116 vlUploadMergeProfile2.store = new dojo.data.ItemFileReadStore({data:fieldmapper.vmp.toStoreData(mergeProfiles)});
117 vlUploadMergeProfile2.labelAttr = 'name';
118 vlUploadMergeProfile2.searchAttr = 'name';
119 vlUploadMergeProfile2.startup();
122 // Fetch the bib and authority attribute definitions
123 vlFetchBibAttrDefs(function () { checkInitDone(); });
124 vlFetchAuthAttrDefs(function () { checkInitDone(); });
126 vlRetrieveQueueList('bib', null,
128 allUserBibQueues = list;
129 for(var i = 0; i < allUserBibQueues.length; i++) {
130 if(allUserBibQueues[i].complete() == 'f')
131 userBibQueues.push(allUserBibQueues[i]);
137 vlRetrieveQueueList('auth', null,
139 allUserAuthQueues = list;
140 for(var i = 0; i < allUserAuthQueues.length; i++) {
141 if(allUserAuthQueues[i].complete() == 'f')
142 userAuthQueues.push(allUserAuthQueues[i]);
148 fieldmapper.standardRequest(
149 ['open-ils.permacrud', 'open-ils.permacrud.search.cbs.atomic'],
151 params: [authtoken, {id:{"!=":null}}, {order_by:{cbs:'id'}}],
152 oncomplete : function(r) {
153 vlBibSources = openils.Util.readResponse(r, false, true);
159 var owner = fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(new openils.User().user.ws_ou()));
160 new openils.PermaCrud().search('viiad',
161 {owner: owner.map(function(org) { return org.id(); })},
163 oncomplete: function(r) {
164 importItemDefs = openils.Util.readResponse(r);
170 new openils.PermaCrud().search('vms',
171 {owner: owner.map(function(org) { return org.id(); })},
173 oncomplete: function(r) {
174 var sets = openils.Util.readResponse(r);
177 if(!matchSets[set.mtype()])
178 matchSets[set.mtype()] = [];
179 matchSets[set.mtype()].push(set);
192 openils.Util.addOnLoad(vlInit);
195 // fetch the bib and authority attribute definitions
197 function vlFetchBibAttrDefs(postcomplete) {
199 fieldmapper.standardRequest(
200 ['open-ils.permacrud', 'open-ils.permacrud.search.vqbrad'],
202 params: [authtoken, {id:{'!=':null}}],
203 onresponse: function(r) {
204 var def = r.recv().content();
205 if(e = openils.Event.parse(def[0]))
207 bibAttrDefs.push(def);
209 oncomplete: function() {
210 bibAttrDefs = bibAttrDefs.sort(
212 if(a.id() > b.id()) return 1;
213 if(a.id() < b.id()) return -1;
223 function vlFetchAuthAttrDefs(postcomplete) {
225 fieldmapper.standardRequest(
226 ['open-ils.permacrud', 'open-ils.permacrud.search.vqarad'],
228 params: [authtoken, {id:{'!=':null}}],
229 onresponse: function(r) {
230 var def = r.recv().content();
231 if(e = openils.Event.parse(def[0]))
233 authAttrDefs.push(def);
235 oncomplete: function() {
236 authAttrDefs = authAttrDefs.sort(
238 if(a.id() > b.id()) return 1;
239 if(a.id() < b.id()) return -1;
249 function vlRetrieveQueueList(type, filter, onload) {
250 type = (type == 'bib') ? type : 'authority';
251 fieldmapper.standardRequest(
252 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.owner.retrieve.atomic'],
254 params: [authtoken, null, filter],
255 oncomplete: function(r) {
256 var list = r.recv().content();
257 if(e = openils.Event.parse(list[0]))
266 function displayGlobalDiv(id) {
267 for(var i = 0; i < globalDivs.length; i++) {
269 dojo.style(dojo.byId(globalDivs[i]), 'display', 'none');
271 alert('please define div ' + globalDivs[i]);
274 dojo.style(dojo.byId(id),'display','block');
276 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
277 openils.Util.removeCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
278 openils.Util.removeCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
279 openils.Util.removeCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
280 openils.Util.removeCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
281 openils.Util.removeCSSClass(dojo.byId('vl-menu-match-set-editor'), 'toolbar_selected');
283 if(dojo.byId('vl-match-set-iframe'))
284 dojo.byId('vl-match-set-editor-div').removeChild(dojo.byId('vl-match-set-iframe'));
287 case 'vl-marc-export-div':
288 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-export'), 'toolbar_selected');
290 case 'vl-marc-upload-div':
291 openils.Util.addCSSClass(dojo.byId('vl-menu-marc-upload'), 'toolbar_selected');
293 case 'vl-queue-select-div':
294 openils.Util.addCSSClass(dojo.byId('vl-menu-queue-select'), 'toolbar_selected');
296 case 'vl-attr-editor-div':
297 openils.Util.addCSSClass(dojo.byId('vl-menu-attr-editor'), 'toolbar_selected');
299 case 'vl-profile-editor-div':
300 openils.Util.addCSSClass(dojo.byId('vl-menu-profile-editor'), 'toolbar_selected');
302 case 'vl-item-attr-editor-div':
303 openils.Util.addCSSClass(dojo.byId('vl-menu-import-item-attr-editor'), 'toolbar_selected');
305 case 'vl-match-set-editor-div':
306 openils.Util.addCSSClass(dojo.byId('vl-menu-match-set-editor'), 'toolbar_selected');
311 function runStartupCommands() {
312 currentQueueId = cgi.param('qid');
313 currentType = cgi.param('qtype');
314 dojo.style('vl-nav-bar', 'visibility', 'visible');
316 return retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
321 * asynchronously upload a file of MARC records
323 function uploadMARC(onload){
324 dojo.byId('vl-upload-status-count').innerHTML = '0';
325 dojo.byId('vl-ses-input').value = authtoken;
326 displayGlobalDiv('vl-marc-upload-status-div');
327 dojo.io.iframe.send({
331 form: dojo.byId('vl-marc-upload-form'),
332 handle: function(data,ioArgs){
333 var content = data.documentElement.textContent;
340 * Creates a new vandelay queue
342 function createQueue(queueName, type, onload, importDefId, matchSet) {
343 var name = (type=='bib') ? 'bib' : 'authority';
344 var method = 'open-ils.vandelay.'+ name +'_queue.create'
345 fieldmapper.standardRequest(
346 ['open-ils.vandelay', method],
348 params: [authtoken, queueName, null, name, matchSet, importDefId],
349 oncomplete : function(r) {
350 var queue = r.recv().content();
351 if(e = openils.Event.parse(queue))
360 * Tells vandelay to pull a batch of records from the cache and explode them
361 * out into the vandelay tables
363 function processSpool(key, queueId, type, onload) {
364 fieldmapper.standardRequest(
365 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'.process_spool'],
367 params: [authtoken, key, queueId],
368 onresponse : function(r) {
369 var resp = r.recv().content();
370 if(e = openils.Event.parse(resp))
372 dojo.byId('vl-upload-status-count').innerHTML = resp;
374 oncomplete : function(r) {onload();}
379 function vlExportInit() {
382 var qsel = dojo.byId('vl-queue-export-options');
383 qsel.onchange = function(newVal) {
384 var value = qsel.options[qsel.selectedIndex].value;
385 qsel.selectedIndex = 0;
387 if(!confirm('Export as "' + value + '"?')) return; // TODO: i18n
388 retrieveQueuedRecords(
392 exportHandler(value, r);
393 displayGlobalDiv('vl-queue-div');
400 var isel = dojo.byId('vl-item-export-options');
401 isel.onchange = function(newVal) {
402 var value = isel.options[isel.selectedIndex].value;
403 isel.selectedIndex = 0;
405 if(!confirm('Export as "' + value + '"?')) return; // TODO: i18n
407 var method = 'open-ils.vandelay.import_item.queue.export.' + value + '.atomic';
409 fieldmapper.standardRequest(
410 ['open-ils.vandelay', method],
415 {with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null}
418 oncomplete : function(r) {exportHandler(value, r)}
424 function exportHandler(type, response) {
426 var content = openils.Util.readResponse(response);
428 if (content==1) { alert('Email sent.'); }
431 /* handle .atomic versus non-atomic method calls */
432 content = content.constructor == Array
433 ? content[0].template_output().data()
434 : content.template_output().data();
437 openils.Util.printHtmlString(content);
440 //content = content.replace(/\\t/g,'\t'); // if we really wanted to do .tsv instead
441 openils.XUL.contentToFileSaveDialog(content);
444 alert('response = ' + response + '\tcontent:\n' + content);
447 alert('Error exporting data: ' + E);
451 function retrieveQueuedRecords(type, queueId, onload, doExport) {
452 displayGlobalDiv('vl-generic-progress');
454 queuedRecordsMap = {};
455 currentOverlayRecordsMap = {};
456 currentOverlayRecordsMapGid = {};
457 selectableGridRecords = {};
459 if(!type) type = currentType;
460 if(!queueId) queueId = currentQueueId;
461 if(!onload) onload = handleRetrieveRecords;
463 var method = 'open-ils.vandelay.'+type+'_queue.records.retrieve';
465 if(doExport) method += '.export.' + doExport;
466 if(vlQueueGridShowMatches.checked)
467 method = method.replace('records', 'records.matches');
471 var sel = dojo.byId('vl-queue-display-limit-selector');
472 var limit = parseInt(sel.options[sel.selectedIndex].value);
473 var offset = limit * parseInt(vlQueueDisplayPage.attr('value')-1);
475 var params = [authtoken, queueId, {clear_marc: 1, offset: offset, limit: limit, flesh_import_items:1}];
476 if(vlQueueGridShowNonImport.checked)
477 params[2].non_imported = 1;
479 if(vlQueueGridShowImportErrors.checked)
480 params[2].with_import_error = 1;
482 fieldmapper.standardRequest(
483 ['open-ils.vandelay', method],
486 oncomplete: function(r){
487 if(doExport) return onload(r);
488 var recs = r.recv().content();
489 if(e = openils.Event.parse(recs[0]))
491 for(var i = 0; i < recs.length; i++) {
493 queuedRecords.push(rec);
494 queuedRecordsMap[rec.id()] = rec;
502 function vlLoadMatchUI(recId) {
503 displayGlobalDiv('vl-generic-progress');
504 var queuedRec = queuedRecordsMap[recId];
505 var matches = queuedRec.matches();
507 currentImportRecId = recId;
508 for(var i = 0; i < matches.length; i++)
509 records.push(matches[i].eg_record());
511 var retrieve = ['open-ils.search', 'open-ils.search.biblio.record_entry.slim.retrieve'];
512 var params = [records];
513 if(currentType == 'auth') {
514 retrieve = ['open-ils.cat', 'open-ils.cat.authority.record.retrieve'];
515 params = [authtoken, records, {clear_marc:1}];
518 fieldmapper.standardRequest(
522 oncomplete: function(r) {
523 var recs = r.recv().content();
524 if(e = openils.Event.parse(recs))
528 displayGlobalDiv('vl-match-div');
529 resetVlMatchGridLayout();
530 currentMatchedRecords = recs;
531 vlMatchGrid.setStructure(vlMatchGridLayout);
533 // build the data store of records with match information
534 var dataStore = bre.toStoreData(recs, null,
535 {virtualFields:['_id', 'match_score', 'match_quality', 'rec_quality']});
536 dataStore.identifier = '_id';
538 var matchSeenMap = {};
540 for(var i = 0; i < dataStore.items.length; i++) {
541 var item = dataStore.items[i];
542 item._id = i; // just need something unique
543 for(var j = 0; j < matches.length; j++) {
544 var match = matches[j];
545 if(match.eg_record() == item.id && !matchSeenMap[match.id()]) {
546 if(match.match_score)
547 item.match_score = match.match_score();
548 item.match_quality = match.quality();
549 item.rec_quality = queuedRec.quality();
550 matchSeenMap[match.id()] = 1;
556 // now populate the grid
557 vlPopulateMatchGrid(vlMatchGrid, dataStore);
563 function vlPopulateMatchGrid(grid, data) {
564 var store = new dojo.data.ItemFileReadStore({data:data});
565 grid.setStore(store);
569 function showMe(id) {
570 dojo.style(dojo.byId(id), 'display', 'block');
572 function hideMe(id) {
573 dojo.style(dojo.byId(id), 'display', 'none');
577 function vlLoadMARCHtml(recId, inCat, oncomplete) {
578 dijit.byId('vl-marc-html-done-button').onClick = oncomplete;
579 displayGlobalDiv('vl-generic-progress');
581 var params = [recId, 1];
584 hideMe('vl-marc-html-edit-button'); // don't show marc editor button
585 dijit.byId('vl-marc-html-edit-button').onClick = function(){}
586 api = ['open-ils.search', 'open-ils.search.biblio.record.html'];
587 if(currentType == 'auth')
588 api = ['open-ils.search', 'open-ils.search.authority.to_html'];
590 showMe('vl-marc-html-edit-button'); // plug in the marc editor button
591 dijit.byId('vl-marc-html-edit-button').onClick =
592 function() {vlLoadMarcEditor(currentType, recId, oncomplete);};
593 params = [authtoken, recId];
594 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_bib_record.html'];
595 if(currentType == 'auth')
596 api = ['open-ils.vandelay', 'open-ils.vandelay.queued_authority_record.html'];
599 fieldmapper.standardRequest(
603 oncomplete: function(r) {
604 displayGlobalDiv('vl-marc-html-div');
605 var html = r.recv().content();
606 dojo.byId('vl-marc-record-html').innerHTML = html;
614 function getRecMatchesFromAttrCode(rec, attrCode) {
616 var attr = getRecAttrFromCode(rec, attrCode);
617 for(var j = 0; j < rec.matches().length; j++) {
618 var match = rec.matches()[j];
619 if(match.matched_attr() == attr.id())
627 function getRecAttrFromMatch(rec, match) {
628 for(var i = 0; i < rec.attributes().length; i++) {
629 var attr = rec.attributes()[i];
630 if(attr.id() == match.matched_attr())
636 function getRecAttrDefFromAttr(attr, type) {
637 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
638 for(var i = 0; i < defs.length; i++) {
640 if(def.id() == attr.field())
645 function getRecAttrFromCode(rec, attrCode) {
646 var defId = attrDefMap[currentType][attrCode];
647 var attrs = rec.attributes();
648 for(var i = 0; i < attrs.length; i++) {
650 if(attr.field() == defId)
656 function vlGetViewMatches(rowIdx, item) {
658 var id = this.grid.store.getValue(item, 'id');
659 var rec = queuedRecordsMap[id];
660 if(rec.matches().length > 0)
666 function vlFormatViewMatches(id) {
667 if(id == -1) return '';
668 return '<a href="javascript:void(0);" onclick="vlLoadMatchUI(' + id + ');">' + this.name + '</a>';
671 function vlGetViewErrors(rowIdx, item) {
673 var id = this.grid.store.getValue(item, 'id');
674 var rec = queuedRecordsMap[id];
675 // id:rec_error:item_import_error_count
677 (rec.import_error() ? 1 : '') + ':' +
678 rec.import_items().filter(function(i) {return i.import_error()}).length;
683 function vlFormatViewErrors(chunk) {
684 if(chunk == -1) return '';
685 var id = chunk.split(':')[0];
686 var rec = chunk.split(':')[1];
687 var count = chunk.split(':')[2];
690 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Record</a><br/>'; // TODO I18N
692 links += '<a href="javascript:void(0);" onclick="vlLoadErrorUI(' + id + ');">Items ('+count+')</a>'; // TODO I18N
696 //var vlItemErrorColumnPicker;
697 function vlLoadErrorUI(id) {
699 displayGlobalDiv('vl-import-error-div');
700 openils.Util.hide('vl-import-error-grid-all');
701 openils.Util.show('vl-import-error-record');
703 var rec = queuedRecordsMap[id];
705 dojo.byId('vl-error-id').innerHTML = rec.id();
706 dojo.forEach( // TODO sane authority rec. fields
707 ['title', 'author', 'isbn', 'issn', 'upc'],
709 var attr = getRecAttrFromCode(rec, field);
710 var eid = 'vl-error-' + field;
712 openils.Util.show(dojo.byId(eid).parentNode, 'table-row');
713 dojo.byId(eid).innerHTML = attr.attr_value();
715 openils.Util.hide(dojo.byId(eid).parentNode);
719 var iediv = dojo.byId('vl-error-import-error');
720 var eddiv = dojo.byId('vl-error-error-detail');
721 if(rec.import_error()) {
722 openils.Util.show(iediv.parentNode, 'table-row');
723 openils.Util.show(eddiv.parentNode, 'table-row');
724 iediv.innerHTML = rec.import_error();
725 eddiv.innerHTML = rec.error_detail();
727 openils.Util.hide(iediv.parentNode);
728 openils.Util.hide(eddiv.parentNode);
731 var errorItems = rec.import_items().filter(function(i) {return i.import_error()});
732 if(errorItems.length) {
733 openils.Util.show('vl-import-error-grid-some');
734 storeData = vqbr.toStoreData(errorItems);
735 var store = new dojo.data.ItemFileReadStore({data:storeData});
736 vlImportErrorGrid.setStore(store);
737 vlImportErrorGrid.update();
739 openils.Util.hide('vl-import-error-grid-some');
743 function vlLoadErrorUIAll() {
745 displayGlobalDiv('vl-import-error-div');
746 openils.Util.hide('vl-import-error-grid-some');
747 openils.Util.hide('vl-import-error-record');
748 openils.Util.show('vl-import-error-grid-all');
749 vlAllImportErrorGrid.resetStore();
751 vlImportErrorGrid.displayOffset = 0;
753 vlAllImportErrorGrid.dataLoader = function() {
755 vlAllImportErrorGrid.showLoadProgressIndicator();
757 fieldmapper.standardRequest(
758 ['open-ils.vandelay', 'open-ils.vandelay.import_item.queue.retrieve'],
762 authtoken, currentQueueId, {
763 with_import_error: (vlImportItemsShowErrors.checked) ? 1 : null,
764 offset : vlAllImportErrorGrid.displayOffset,
765 limit : vlAllImportErrorGrid.displayLimit
768 onresponse : function(r) {
769 var item = openils.Util.readResponse(r);
771 vlAllImportErrorGrid.store.newItem(vii.toStoreItem(item));
773 oncomplete : function() {
774 vlAllImportErrorGrid.hideLoadProgressIndicator();
780 vlAllImportErrorGrid.dataLoader();
783 function vlGetOrg(rowIdx, item) {
785 var value = this.grid.store.getValue(item, this.field);
786 if(value) return fieldmapper.aou.findOrgUnit(value).shortname();
790 function vlFormatViewMatchMARC(id) {
791 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', true, '+
792 'function(){displayGlobalDiv(\'vl-match-div\');});">' + this.name + '</a>';
795 function getAttrValue(rowIdx, item) {
797 var attrCode = this.field.split('.')[1];
798 var rec = queuedRecordsMap[this.grid.store.getValue(item, 'id')];
799 var attr = getRecAttrFromCode(rec, attrCode);
800 return (attr) ? attr.attr_value() : '';
803 function vlGetDateTimeField(rowIdx, item) {
805 var value = this.grid.store.getValue(item, this.field);
806 if(!value) return '';
807 var date = dojo.date.stamp.fromISOString(value);
808 return dojo.date.locale.format(date, {selector:'date'});
811 function vlGetCreator(rowIdx, item) {
813 var id = this.grid.store.getValue(item, 'creator');
815 return userCache[id].usrname();
816 var user = fieldmapper.standardRequest(
817 ['open-ils.actor', 'open-ils.actor.user.retrieve'], [authtoken, id]);
818 if(e = openils.Event.parse(user))
820 userCache[id] = user;
821 return user.usrname();
824 function vlGetViewMARC(rowIdx, item) {
825 return item && this.grid.store.getValue(item, 'id');
828 function vlFormatViewMARC(id) {
829 return '<a href="javascript:void(0);" onclick="vlLoadMARCHtml(' + id + ', false, '+
830 'function(){displayGlobalDiv(\'vl-queue-div\');});">' + this.name + '</a>';
833 function vlGetOverlayTargetSelector(rowIdx, item) {
835 return this.grid.store.getValue(item, '_id') + ':' + this.grid.store.getValue(item, 'id');
838 function vlFormatOverlayTargetSelector(val) {
840 var parts = val.split(':');
843 var value = '<input type="checkbox" name="vl-overlay-target-RECID" '+
844 'onclick="vlHandleOverlayTargetSelected(ID, GRIDID);" gridid="GRIDID" match="ID"/>';
845 value = value.replace(/GRIDID/g, _id);
846 value = value.replace(/RECID/g, currentImportRecId);
847 value = value.replace(/ID/g, id);
848 if(_id == currentOverlayRecordsMapGid[currentImportRecId])
849 return value.replace('/>', 'checked="checked"/>');
855 * see if the user has enabled overlays for the current match set and,
856 * if so, map the current import record to the overlay target.
858 function vlHandleOverlayTargetSelected(recId, gridId) {
859 var noneSelected = true;
860 var checkboxes = dojo.query('[name=vl-overlay-target-'+currentImportRecId+']');
861 for(var i = 0; i < checkboxes.length; i++) {
862 var checkbox = checkboxes[i];
863 var matchRecId = checkbox.getAttribute('match');
864 var gid = checkbox.getAttribute('gridid');
865 if(checkbox.checked) {
866 if(matchRecId == recId && gid == gridId) {
867 noneSelected = false;
868 currentOverlayRecordsMap[currentImportRecId] = matchRecId;
869 currentOverlayRecordsMapGid[currentImportRecId] = gid;
870 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = true;
871 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = 'overlay_selected';
873 checkbox.checked = false;
879 delete currentOverlayRecordsMap[currentImportRecId];
880 delete currentOverlayRecordsMapGid[currentImportRecId];
881 dojo.byId('vl-record-list-selected-' + currentImportRecId).checked = false;
882 dojo.byId('vl-record-list-selected-' + currentImportRecId).parentNode.className = '';
886 var valLastQueueType = null;
887 var vlQueueGridLayout = null;
888 function buildRecordGrid(type) {
889 displayGlobalDiv('vl-queue-div');
892 openils.Util.show('vl-bib-queue-grid-wrapper');
893 openils.Util.hide('vl-auth-queue-grid-wrapper');
894 vlQueueGrid = vlBibQueueGrid;
896 openils.Util.show('vl-auth-queue-grid-wrapper');
897 openils.Util.hide('vl-bib-queue-grid-wrapper');
898 vlQueueGrid = vlAuthQueueGrid;
902 if(valLastQueueType != type) {
903 valLastQueueType = type;
904 vlQueueGridLayout = vlQueueGrid.attr('structure');
905 var defs = (type == 'bib') ? bibAttrDefs : authAttrDefs;
906 attrDefMap[type] = {};
907 for(var i = 0; i < defs.length; i++) {
909 attrDefMap[type][def.code()] = def.id();
911 name:def.description(),
912 field:'attr.' + def.code(),
914 selectableColumn:true
916 vlQueueGridLayout[0].cells[0].push(col);
920 dojo.forEach(vlQueueGridLayout[0].cells[0],
922 if(cell.field.match(/^\+/))
923 cell.nonSelectable=true;
929 storeData = vqbr.toStoreData(queuedRecords);
931 storeData = vqar.toStoreData(queuedRecords);
933 var store = new dojo.data.ItemFileReadStore({data:storeData});
934 vlQueueGrid.setStore(store);
936 if(vlQueueGridColumePicker[type]) {
937 vlQueueGrid.update();
940 vlQueueGridColumePicker[type] =
941 new openils.widget.GridColumnPicker(
942 authtoken, 'vandelay.queue.'+type, vlQueueGrid, vlQueueGridLayout);
943 vlQueueGridColumePicker[type].load();
947 function vlQueueGridPrevPage() {
948 var page = parseInt(vlQueueDisplayPage.getValue());
950 vlQueueDisplayPage.setValue(page - 1);
951 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
954 function vlQueueGridNextPage() {
955 vlQueueDisplayPage.setValue(parseInt(vlQueueDisplayPage.getValue())+1);
956 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
959 function vlDeleteQueue(type, queueId, onload) {
960 fieldmapper.standardRequest(
961 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.delete'],
963 params: [authtoken, queueId],
964 oncomplete: function(r) {
965 var resp = r.recv().content();
966 if(e = openils.Event.parse(resp))
975 function vlQueueGridDrawSelectBox(rowIdx, item) {
976 return item && this.grid.store.getValue(item, 'id');
979 function vlQueueGridFormatSelectBox(id) {
980 var domId = 'vl-record-list-selected-' + id;
981 if (id) { selectableGridRecords[domId] = id; }
982 return "<div><input type='checkbox' id='"+domId+"'/></div>";
985 function vlSelectAllQueueGridRecords() {
986 for(var id in selectableGridRecords)
987 dojo.byId(id).checked = true;
989 function vlSelectNoQueueGridRecords() {
990 for(var id in selectableGridRecords)
991 dojo.byId(id).checked = false;
993 function vlToggleQueueGridSelect() {
994 if(dojo.byId('vl-queue-grid-row-selector').checked)
995 vlSelectAllQueueGridRecords();
997 vlSelectNoQueueGridRecords();
1000 var handleRetrieveRecords = function() {
1001 buildRecordGrid(currentType);
1002 vlFetchQueueSummary(currentQueueId, currentType,
1004 dojo.byId('vl-queue-summary-name').innerHTML = summary.queue.name();
1005 dojo.byId('vl-queue-summary-total-count').innerHTML = summary.total +'';
1006 dojo.byId('vl-queue-summary-import-count').innerHTML = summary.imported + '';
1007 dojo.byId('vl-queue-summary-import-item-count').innerHTML = summary.total_items + '';
1008 dojo.byId('vl-queue-summary-rec-error-count').innerHTML = summary.rec_import_errors + '';
1009 dojo.byId('vl-queue-summary-item-error-count').innerHTML = summary.item_import_errors + '';
1014 function vlFetchQueueSummary(qId, type, onload) {
1015 fieldmapper.standardRequest(
1016 ['open-ils.vandelay', 'open-ils.vandelay.'+type+'_queue.summary.retrieve'],
1018 params: [authtoken, qId],
1019 oncomplete : function(r) {
1020 var summary = r.recv().content();
1021 if(e = openils.Event.parse(summary))
1023 return onload(summary);
1029 function vlHandleQueueItemsAction(action) {
1032 queueItemsImportCancelButton,
1035 queueItemsImportDialog.hide();
1040 queueItemsImportGoButton,
1043 queueItemsImportDialog.hide();
1045 // hack to set the widgets the import funcs will be looking at. Reset them below.
1046 vlUploadQueueImportNoMatch.attr('value', vlUploadQueueImportNoMatch2.attr('value'));
1047 vlUploadQueueAutoOverlayExact.attr('value', vlUploadQueueAutoOverlayExact2.attr('value'));
1048 vlUploadQueueAutoOverlay1Match.attr('value', vlUploadQueueAutoOverlay1Match2.attr('value'));
1049 vlUploadMergeProfile.attr('value', vlUploadMergeProfile2.attr('value'));
1050 vlUploadQueueAutoOverlayBestMatch.attr('value', vlUploadQueueAutoOverlayBestMatch2.attr('value'));
1051 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', vlUploadQueueAutoOverlayBestMatchRatio2.attr('value'));
1053 if(action == 'import') {
1054 vlImportSelectedRecords();
1055 } else if(action == 'import_all') {
1056 vlImportAllRecords();
1059 // reset the widgets to prevent accidental future actions
1060 vlUploadQueueImportNoMatch.attr('value', false);
1061 vlUploadQueueImportNoMatch2.attr('value', false);
1062 vlUploadQueueAutoOverlayExact.attr('value', false);
1063 vlUploadQueueAutoOverlayExact2.attr('value', false);
1064 vlUploadQueueAutoOverlay1Match.attr('value', false);
1065 vlUploadQueueAutoOverlay1Match2.attr('value', false);
1066 vlUploadMergeProfile.attr('value', '');
1067 vlUploadMergeProfile2.attr('value', '');
1068 vlUploadQueueAutoOverlayBestMatch.attr('value', false);
1069 vlUploadQueueAutoOverlayBestMatch2.attr('value', false);
1070 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', '0.0');
1071 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', '0.0');
1075 queueItemsImportDialog.show();
1079 /* import user-selected records */
1080 function vlImportSelectedRecords() {
1083 for(var id in selectableGridRecords) {
1084 if(dojo.byId(id).checked) {
1085 var recId = selectableGridRecords[id];
1086 var rec = queuedRecordsMap[recId];
1087 if(!rec.import_time())
1088 records.push(recId);
1092 vlImportRecordQueue(
1097 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1102 /* import all (non-imported) queue records */
1103 function vlImportAllRecords() {
1104 vlImportRecordQueue(
1109 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1114 /* if recList has values, import only those records */
1115 function vlImportRecordQueue(type, queueId, recList, onload) {
1116 displayGlobalDiv('vl-generic-progress-with-total');
1118 /* set up options */
1119 var mergeOpt = false;
1120 var options = {overlay_map : currentOverlayRecordsMap};
1122 if(vlUploadQueueImportNoMatch.checked) {
1123 options.import_no_match = true;
1124 vlUploadQueueImportNoMatch.checked = false;
1127 if(vlUploadQueueAutoOverlayExact.checked) {
1128 options.auto_overlay_exact = true;
1129 vlUploadQueueAutoOverlayExact.checked = false;
1133 if(vlUploadQueueAutoOverlayBestMatch.checked) {
1134 options.auto_overlay_best_match = true;
1135 vlUploadQueueAutoOverlayBestMatch.checked = false;
1136 options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
1140 if(vlUploadQueueAutoOverlay1Match.checked) {
1141 options.auto_overlay_1match = true;
1142 vlUploadQueueAutoOverlay1Match.checked = false;
1146 var profile = vlUploadMergeProfile.attr('value');
1147 if(profile != null && profile != '') {
1148 options.merge_profile = profile;
1151 /* determine which method we're calling */
1153 var method = 'open-ils.vandelay.bib_queue.import';
1155 method = method.replace('bib', 'auth');
1158 // in the interest of speed, if no merge options are
1159 // chosen, tell the back-end code to only process records
1160 // that have no matches
1161 method = method.replace(/\.import/, '.nomatch.import');
1164 var params = [authtoken, queueId, options];
1166 method = 'open-ils.vandelay.'+currentType+'_record.list.import';
1167 params[1] = recList;
1170 fieldmapper.standardRequest(
1171 ['open-ils.vandelay', method],
1174 onresponse: function(r) {
1175 var resp = r.recv().content();
1176 if(e = openils.Event.parse(resp))
1178 vlControlledProgressBar.update({maximum:resp.total, progress:resp.progress});
1180 oncomplete: function() {onload();}
1187 * Create queue, upload MARC, process spool, load the newly created queue
1189 function batchUpload() {
1190 var queueName = dijit.byId('vl-queue-name').getValue();
1191 currentType = dijit.byId('vl-record-type').getValue();
1193 var handleProcessSpool = function() {
1195 vlUploadQueueImportNoMatch.checked ||
1196 vlUploadQueueAutoOverlayExact.checked ||
1197 vlUploadQueueAutoOverlay1Match.checked ||
1198 vlUploadQueueAutoOverlayBestMatch.checked ) {
1200 vlImportRecordQueue(
1205 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1209 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1213 var handleUploadMARC = function(key) {
1214 dojo.style(dojo.byId('vl-upload-status-processing'), 'display', 'block');
1215 processSpool(key, currentQueueId, currentType, handleProcessSpool);
1218 var handleCreateQueue = function(queue) {
1219 currentQueueId = queue.id();
1220 uploadMARC(handleUploadMARC);
1223 if(vlUploadQueueSelector.getValue() && !queueName) {
1224 currentQueueId = vlUploadQueueSelector.getValue();
1225 uploadMARC(handleUploadMARC);
1227 createQueue(queueName, currentType, handleCreateQueue,
1228 vlUploadQueueHoldingsImportProfile.attr('value'),
1229 vlUploadQueueMatchSet.attr('value')
1235 function vlFleshQueueSelect(selector, type) {
1236 var data = (type == 'bib') ? vbq.toStoreData(allUserBibQueues) : vaq.toStoreData(allUserAuthQueues);
1237 selector.store = new dojo.data.ItemFileReadStore({data:data});
1238 selector.setValue(null);
1239 selector.setDisplayedValue('');
1241 selector.setValue(data[0].id());
1243 var qInput = dijit.byId('vl-queue-name');
1245 var selChange = function(val) {
1246 console.log('selector onchange');
1247 // user selected a queue from the selector; clear the input and
1248 // set the item import profile already defined for the queue
1249 var queue = allUserBibQueues.filter(function(q) { return (q.id() == val) })[0];
1251 vlUploadQueueHoldingsImportProfile.attr('value', queue.item_attr_def() || '');
1252 vlUploadQueueHoldingsImportProfile.attr('disabled', true);
1253 vlUploadQueueMatchSet.attr('value', queue.match_set() || '');
1254 vlUploadQueueMatchSet.attr('disabled', true);
1256 vlUploadQueueHoldingsImportProfile.attr('value', '');
1257 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1258 vlUploadQueueMatchSet.attr('value', '');
1259 vlUploadQueueMatchSet.attr('disabled', false);
1261 dojo.disconnect(qInput._onchange);
1262 qInput.attr('value', '');
1263 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1266 var inputChange = function(val) {
1267 console.log('qinput onchange');
1268 // user entered a new queue name. clear the selector
1269 vlUploadQueueHoldingsImportProfile.attr('value', '');
1270 vlUploadQueueHoldingsImportProfile.attr('disabled', false);
1271 vlUploadQueueMatchSet.attr('value', '');
1272 vlUploadQueueMatchSet.attr('disabled', false);
1273 dojo.disconnect(selector._onchange);
1274 selector.attr('value', '');
1275 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1278 selector._onchange = dojo.connect(selector, 'onChange', selChange);
1279 qInput._onchange = dojo.connect(qInput, 'onChange', inputChange);
1282 function vlUpdateMatchSetSelector(type) {
1283 type = (type.match(/bib/)) ? 'biblio' : 'authority';
1284 vlUploadQueueMatchSet.store =
1285 new dojo.data.ItemFileReadStore({data:vms.toStoreData(matchSets[type])});
1288 function vlShowUploadForm() {
1289 displayGlobalDiv('vl-marc-upload-div');
1290 vlFleshQueueSelect(vlUploadQueueSelector, vlUploadRecordType.getValue());
1291 vlUploadSourceSelector.store =
1292 new dojo.data.ItemFileReadStore({data:cbs.toStoreData(vlBibSources, 'source')});
1293 vlUploadSourceSelector.setValue(vlBibSources[0].id());
1294 vlUploadQueueHoldingsImportProfile.store =
1295 new dojo.data.ItemFileReadStore({data:viiad.toStoreData(importItemDefs)});
1296 vlUpdateMatchSetSelector(vlUploadRecordType.getValue());
1298 // use ratio from the merge profile if it's set
1300 vlUploadMergeProfile,
1304 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1305 if(profile.lwm_ratio() != null)
1306 vlUploadQueueAutoOverlayBestMatchRatio.attr('value', profile.lwm_ratio()+'');
1310 vlUploadMergeProfile2,
1314 var profile = mergeProfiles.filter(function(p) { return (p.id() == val); })[0];
1315 if(profile.lwm_ratio() != null)
1316 vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', profile.lwm_ratio()+'');
1322 function vlShowQueueSelect() {
1323 displayGlobalDiv('vl-queue-select-div');
1324 vlFleshQueueSelect(vlQueueSelectQueueList, vlQueueSelectType.getValue());
1327 function vlShowMatchSetEditor() {
1328 displayGlobalDiv('vl-match-set-editor-div');
1329 dojo.byId('vl-match-set-editor-div').appendChild(
1330 dojo.create('iframe', {
1331 id : 'vl-match-set-iframe',
1332 src : oilsBasePath + '/eg/conify/global/vandelay/match_set',
1333 style : 'width:100%; height:500px; border:none; margin:0px;'
1338 function vlFetchQueueFromForm() {
1339 currentType = vlQueueSelectType.getValue();
1340 currentQueueId = vlQueueSelectQueueList.getValue();
1341 retrieveQueuedRecords(currentType, currentQueueId, handleRetrieveRecords);
1344 function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
1346 To run in Firefox directly, must set signed.applets.codebase_principal_support
1347 to true in about:config
1349 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1350 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
1353 if (currentType == 'bib') {
1359 function onsave(r) {
1360 // after the record is saved, reload the HTML display
1361 var stat = r.recv().content();
1362 if(e = openils.Event.parse(stat))
1364 alert(dojo.byId('vl-marc-edit-complete-label').innerHTML);
1366 vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler);
1370 record : {marc : rec.marc(), "rtype": type},
1372 label: dojo.byId('vl-marc-edit-save-label').innerHTML,
1373 func: function(xmlString) {
1374 var method = 'open-ils.permacrud.update.' + rec.classname;
1375 rec.marc(xmlString);
1376 fieldmapper.standardRequest(
1377 ['open-ils.permacrud', method],
1379 params: [authtoken, rec],
1385 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
1386 'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
1390 function vlLoadMarcEditor(type, recId, postReloadHTMLHandler) {
1391 var method = 'open-ils.permacrud.search.vqbr';
1392 if(currentType != 'bib')
1393 method = method.replace(/vqbr/,'vqar');
1395 fieldmapper.standardRequest(
1396 ['open-ils.permacrud', method],
1398 params: [authtoken, {id : recId}],
1399 oncomplete: function(r) {
1400 var rec = r.recv().content();
1401 if(e = openils.Event.parse(rec))
1403 vlOpenMarcEditWindow(rec, postReloadHTMLHandler);
1411 //------------------------------------------------------------
1412 // attribute editors
1414 // attribute-editor global variables
1416 var ATTR_EDITOR_IN_UPDATE_MODE = false; // true on 'edit', false on 'create'
1417 var ATTR_EDIT_ID = null; // id of current 'edit' attribute
1418 var ATTR_EDIT_GROUP = 'bib'; // bib-attrs or auth-attrs
1420 function vlAttrEditorInit() {
1421 // set up tooltips on the edit form
1422 connectTooltip('attr-editor-tags');
1423 connectTooltip('attr-editor-subfields');
1426 function vlShowAttrEditor() {
1427 displayGlobalDiv('vl-attr-editor-div');
1428 loadAttrEditorGrid();
1429 idHide('vl-generic-progress');
1432 function setAttrEditorGroup(groupName) {
1433 // put us into 'bib'-attr or 'auth'-attr mode.
1434 if (ATTR_EDIT_GROUP != groupName) {
1435 ATTR_EDIT_GROUP = groupName;
1436 loadAttrEditorGrid();
1440 function onAttrEditorOpen() {
1441 // the "bars" have the create/update/cancel/etc. buttons.
1442 var create_bar = document.getElementById('attr-editor-create-bar');
1443 var update_bar = document.getElementById('attr-editor-update-bar');
1444 if (ATTR_EDITOR_IN_UPDATE_MODE) {
1445 update_bar.style.display='table-row';
1446 create_bar.style.display='none';
1447 // hide the dropdown-button
1448 idStyle('vl-create-attr-editor-button', 'visibility', 'hidden');
1450 dijit.byId('attr-editor-dialog').reset();
1451 create_bar.style.display='table-row';
1452 update_bar.style.display='none';
1456 function onAttrEditorClose() {
1457 // reset the form to a "create" form. (We may have borrowed it for editing.)
1458 ATTR_EDITOR_IN_UPDATE_MODE = false;
1459 // show the dropdown-button
1460 idStyle('vl-create-attr-editor-button', 'visibility', 'visible');
1463 function loadAttrEditorGrid() {
1464 var _data = (ATTR_EDIT_GROUP == 'auth') ?
1465 vqarad.toStoreData(authAttrDefs) : vqbrad.toStoreData(bibAttrDefs) ;
1467 var store = new dojo.data.ItemFileReadStore({data:_data});
1468 attrEditorGrid.setStore(store);
1469 attrEditorGrid.onRowDblClick = onAttrEditorClick;
1470 attrEditorGrid.update();
1473 function attrGridGetTag(n, item) {
1474 // grid helper: return the tags from the row's xpath column.
1475 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).tags;
1478 function attrGridGetSubfield(n, item) {
1479 // grid helper: return the subfields from the row's xpath column.
1480 return item && xpathParser.parse(this.grid.store.getValue(item, 'xpath')).subfields;
1483 function onAttrEditorClick() {
1484 var row = this.getItem(this.focus.rowIndex);
1485 ATTR_EDIT_ID = this.store.getValue(row, 'id');
1486 ATTR_EDITOR_IN_UPDATE_MODE = true;
1488 // populate the popup editor.
1489 dijit.byId('attr-editor-code').attr('value', this.store.getValue(row, 'code'));
1490 dijit.byId('attr-editor-description').attr('value', this.store.getValue(row, 'description'));
1491 var parsed_xpath = xpathParser.parse(this.store.getValue(row, 'xpath'));
1492 dijit.byId('attr-editor-tags').attr('value', parsed_xpath.tags);
1493 dijit.byId('attr-editor-subfields').attr('value', parsed_xpath.subfields);
1494 dijit.byId('attr-editor-xpath').attr('value', this.store.getValue(row, 'xpath'));
1495 dijit.byId('attr-editor-remove').attr('value', this.store.getValue(row, 'remove'));
1497 // set up UI for editing
1498 dojo.byId('vl-create-attr-editor-button').click();
1501 function vlSaveAttrDefinition(data) {
1502 idHide('vl-attr-editor-div');
1503 idShow('vl-generic-progress');
1505 data.id = ATTR_EDIT_ID;
1507 // this ought to honour custom xpaths, but overwrite xpaths
1508 // derived from tags/subfields.
1509 if (data.xpath == '' || looksLikeDerivedXpath(data.xpath)) {
1510 var _xpath = tagAndSubFieldsToXpath(data.tag, data.subfield);
1511 data.xpath = _xpath;
1514 // build up our permacrud params. Key variables here are
1515 // "create or update" and "bib or auth".
1517 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1518 var isCreate = (ATTR_EDIT_ID == null);
1519 var rad = isAuth ? new vqarad() : new vqbrad() ;
1520 var method = 'open-ils.permacrud' + (isCreate ? '.create.' : '.update.')
1521 + (isAuth ? 'vqarad' : 'vqbrad');
1522 var _data = rad.fromStoreItem(data);
1526 fieldmapper.standardRequest(
1527 ['open-ils.permacrud', method],
1529 params: [authtoken, _data ],
1530 onresponse: function(r) { },
1531 oncomplete: function(r) {
1532 attrEditorFetchAttrDefs(vlShowAttrEditor);
1533 ATTR_EDIT_ID = null;
1535 onerror: function(r) {
1536 alert('vlSaveAttrDefinition comms error: ' + r);
1542 function attrEditorFetchAttrDefs(callback) {
1543 var fn = (ATTR_EDIT_GROUP == 'auth') ? vlFetchAuthAttrDefs : vlFetchBibAttrDefs;
1544 return fn(callback);
1547 function vlAttrDelete() {
1548 idHide('vl-attr-editor-div');
1549 idShow('vl-generic-progress');
1551 var isAuth = (ATTR_EDIT_GROUP == 'auth');
1552 var method = 'open-ils.permacrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad');
1553 var rad = isAuth ? new vqarad() : new vqbrad() ;
1554 fieldmapper.standardRequest(
1555 ['open-ils.permacrud', method],
1557 params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ],
1558 oncomplete: function() {
1559 dijit.byId('attr-editor-dialog').onCancel(); // close the dialog
1560 attrEditorFetchAttrDefs(vlShowAttrEditor);
1561 ATTR_EDIT_ID = null;
1563 onerror: function(r) {
1564 alert('vlAttrDelete comms error: ' + r);
1570 // ------------------------------------------------------------
1571 // utilities for attribute editors
1573 // dom utilities (maybe dojo does these, and these should be replaced)
1575 function idStyle(obId, k, v) { document.getElementById(obId).style[k] = v; }
1576 function idShow(obId) { idStyle(obId, 'display', 'block'); }
1577 function idHide(obId) { idStyle(obId, 'display' , 'none'); }
1579 function connectTooltip(fieldId) {
1580 // Given an element id, look up a tooltip element in the doc (same
1581 // id with a '-tip' suffix) and associate the two. Maybe dojo has
1582 // a better way to do this?
1583 var fld = dojo.byId(fieldId);
1584 var tip = dojo.byId(fieldId + '-tip');
1585 dojo.connect(fld, 'onfocus', function(evt) {
1586 dijit.showTooltip(tip.innerHTML, fld, ['below', 'after']); });
1587 dojo.connect(fld, 'onblur', function(evt) { dijit.hideTooltip(fld); });
1592 var xpathParser = new openils.MarcXPathParser();
1594 function tagAndSubFieldsToXpath(tags, subfields) {
1595 // given tags, and subfields, build up an XPath.
1598 'tags':tags.match(/[\d]+/g),
1599 'subfields':subfields.match(/[a-zA-z]/g) };
1600 return xpathParser.compile(parts);
1602 return {'parts':null, 'tags':null, 'error':err};
1606 function looksLikeDerivedXpath(path) {
1607 // Does this path look like it was derived from tags and subfields?
1608 var parsed = xpathParser.parse(path);
1609 if (parsed.tags == null)
1611 var compiled = xpathParser.compile(parsed);
1612 return (path == compiled);
1615 // amazing xpath-util unit-tests
1616 if (!looksLikeDerivedXpath('//*[@tag="901"]/*[@code="c"]')) alert('vandelay xpath-utility error');
1617 if ( looksLikeDerivedXpath('ba-boo-ba-boo!')) alert('vandelay xpath-utility error');
1621 var profileContextOrg
1622 function vlShowProfileEditor() {
1623 displayGlobalDiv('vl-profile-editor-div');
1626 var connect = function() {
1627 dojo.connect(profileContextOrgSelector, 'onChange',
1629 profileContextOrg = this.attr('value');
1636 new openils.User().buildPermOrgSelector(
1637 'ADMIN_MERGE_PROFILE', profileContextOrgSelector, null, connect);
1640 function buildProfileGrid() {
1642 if(profileContextOrg == null)
1643 profileContextOrg = openils.User.user.ws_ou();
1646 {order_by : {vmp : 'name'}},
1647 {owner : fieldmapper.aou.fullPath(profileContextOrg, true)}
1651 /* --- Import Item Attr Grid --------------- */
1653 var itemAttrContextOrg;
1654 function vlShowImportItemAttrEditor() {
1655 displayGlobalDiv('vl-item-attr-editor-div');
1656 buildImportItemAttrGrid();
1658 var connect = function() {
1659 dojo.connect(itemAttrContextOrgSelector, 'onChange',
1661 itemAttrContextOrg = this.attr('value');
1662 itemAttrGrid.resetStore();
1663 vlShowImportItemAttrEditor();
1668 new openils.User().buildPermOrgSelector(
1669 'ADMIN_IMPORT_ITEM_ATTR_DEF',
1670 itemAttrContextOrgSelector, null, connect);
1673 function buildImportItemAttrGrid() {
1675 if(itemAttrContextOrg == null)
1676 itemAttrContextOrg = openils.User.user.ws_ou();
1678 itemAttrGrid.loadAll(
1679 {order_by : {viiad : 'name'}},
1680 {owner : fieldmapper.aou.fullPath(itemAttrContextOrg, true)}