1 // vim: noet:sw=4:ts=4:
2 var xmlDeclaration = /^<\?xml version[^>]+?>/;
4 var serializer = new XMLSerializer();
5 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
6 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
7 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
8 default xml namespace = marcns;
10 var tooltip_hash = {};
22 function $(id) { return document.getElementById(id); }
24 function mangle_005() {
26 var y = now.getUTCFullYear();
28 var m = now.getUTCMonth() + 1;
29 if (m < 10) m = '0' + m;
31 var d = now.getUTCDate();
32 if (d < 10) d = '0' + d;
34 var H = now.getUTCHours();
35 if (H < 10) H = '0' + H;
37 var M = now.getUTCMinutes();
38 if (M < 10) M = '0' + M;
40 var S = now.getUTCSeconds();
41 if (S < 10) S = '0' + S;
44 var stamp = '' + y + m + d + H + M + S + '.0';
45 createControlField('005',stamp);
49 function createControlField (tag,data) {
50 // first, remove the old field, if any;
51 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
53 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
56 // then, find the right position and insert it
58 var cfields = xml_record.controlfield;
59 var base = Number(tag.substring(2));
60 for (var i in cfields) {
61 var t = Number(cfields[i].@tag.toString().substring(2));
63 xml_record.insertChildBefore( cfields[i], cf );
69 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
74 function xml_escape_unicode ( str ) {
77 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
84 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
85 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
86 JSAN.errorLevel = "die"; // none, warn, or die
87 JSAN.addRepository('/xul/server/');
89 // Fake xulG for standalone...
94 window.xulG.record = {};
95 window.xulG.save = {};
97 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
98 window.xulG.save.func = function (r) { alert(r); }
101 var _rid = cgi.param('record');
103 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
106 // End faking part...
108 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
109 document.getElementById('save-button').setAttribute('oncommand',
111 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
112 'save_attempt( xml_string ); ' +
113 'loadRecord(xml_record);'
116 if (window.xulG.record.url) {
117 var req = new XMLHttpRequest();
118 req.open('POST',window.xulG.record.url,false);
120 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
123 xml_record = new XML( window.xulG.record.marc );
124 if (xml_record..record[0]) xml_record = xml_record..record[0];
126 // Get the tooltip xml all async like
127 req = new XMLHttpRequest();
129 // Set a default locale in case preferences fail us
130 var locale = "en-US";
132 // Try to get the locale from our preferences
133 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
135 const Cc = Components.classes;
136 const Ci = Components.interfaces;
137 locale = Cc["@mozilla.org/preferences-service;1"].
138 getService(Ci.nsIPrefBranch).
139 getCharPref("general.useragent.locale");
143 // TODO: We should send a HEAD request to check for the existence of the desired file
144 // then fall back to the default locale if preferred locale is not necessary;
145 // however, for now we have a simplistic check:
147 // we currently have translations for only two locales; in the absence of a
148 // valid locale, default to the almighty en-US
149 if (locale != 'en-US' && locale != 'fr-CA') {
153 // Get the locale-specific tooltips
154 req.open('GET','/xul/server/locale/' + locale + '/marcedit-tooltips.xml',true);
156 context_menus = createComplexXULElement('popupset');
157 document.documentElement.appendChild( context_menus );
159 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
160 context_menus.appendChild( tag_menu );
162 tag_menu.appendChild(
164 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
166 'var e = document.createEvent("KeyEvents");' +
167 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
168 'current_focus.inputField.dispatchEvent(e);'
173 tag_menu.appendChild(
175 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
177 'var e = document.createEvent("KeyEvents");' +
178 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
179 'current_focus.inputField.dispatchEvent(e);'
184 tag_menu.appendChild(
186 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
188 'var e = document.createEvent("KeyEvents");' +
189 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
190 'current_focus.inputField.dispatchEvent(e);'
195 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
197 tag_menu.appendChild(
199 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
201 'var e = document.createEvent("KeyEvents");' +
202 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
203 'current_focus.inputField.dispatchEvent(e);'
208 tag_menu.appendChild(
210 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
212 'var e = document.createEvent("KeyEvents");' +
213 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
214 'current_focus.inputField.dispatchEvent(e);'
219 tag_menu.appendChild(
221 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
223 'var e = document.createEvent("KeyEvents");' +
224 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
225 'current_focus.inputField.dispatchEvent(e);'
230 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
232 p = createComplexXULElement('popupset');
233 document.documentElement.appendChild( p );
235 req.onreadystatechange = function () {
236 if (req.readyState == 4) {
237 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
243 loadRecord(xml_record);
245 if (! xulG.fast_add_item) {
246 document.getElementById('fastItemAdd_checkbox').hidden = true;
248 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
251 alert('FIXME, MARC Editor, my_init: ' + E);
256 function createComplexHTMLElement (e, attrs, objects, text) {
257 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
260 for (var i in attrs) l.setAttribute(i,attrs[i]);
264 for ( var i in objects ) l.appendChild( objects[i] );
268 l.appendChild( document.createTextNode(text) )
274 function createComplexXULElement (e, attrs, objects) {
275 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
278 for (var i in attrs) {
279 if (typeof attrs[i] == 'function') {
280 l.addEventListener( i, attrs[i], true );
282 l.setAttribute(i,attrs[i]);
288 for ( var i in objects ) l.appendChild( objects[i] );
294 function createDescription (attrs) {
295 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
298 function createTooltip (attrs) {
299 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
302 function createLabel (attrs) {
303 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
306 function createVbox (attrs) {
307 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
310 function createHbox (attrs) {
311 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
314 function createRow (attrs) {
315 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
318 function createTextbox (attrs) {
319 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
322 function createMenu (attrs) {
323 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
326 function createMenuPopup (attrs) {
327 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
330 function createPopup (attrs) {
331 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
334 function createMenuitem (attrs) {
335 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
338 function createCheckbox (attrs) {
339 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
342 function createMARCTextbox (element,attrs) {
344 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
345 box.onkeypress = function (event) {
348 while(node = node.parent()) {
352 var row = event.target;
353 while (row.tagName != 'row') row = row.parentNode;
355 if (element.nodeKind() == 'attribute') element[0]=box.value;
356 else element.setChildren( box.value );
358 if (element.localName() != 'controlfield') {
359 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
361 var index_sf, target, move_data;
362 if (element.localName() == 'subfield') {
364 target = event.target.parentNode;
366 var start = event.target.selectionStart;
367 var end = event.target.selectionEnd - event.target.selectionStart ?
368 event.target.selectionEnd :
369 event.target.value.length;
371 move_data = event.target.value.substring(start,end);
372 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
373 event.target.setAttribute('size', event.target.value.length + 2);
375 element.setChildren( event.target.value );
377 } else if (element.localName() == 'code') {
378 index_sf = element.parent();
379 target = event.target.parentNode;
380 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
381 index_sf = element.parent().children()[element.parent().children().length() - 1];
382 target = event.target.parentNode.lastChild.lastChild;
385 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
387 index_sf.parent().insertChildAfter( index_sf, sf );
389 var new_sf = marcSubfield(sf);
391 if (target === target.parentNode.lastChild) {
392 target.parentNode.appendChild( new_sf );
394 target.parentNode.insertBefore( new_sf, target.nextSibling );
397 new_sf.firstChild.nextSibling.focus();
399 event.preventDefault();
402 } else if (event.keyCode == 13 || event.keyCode == 77) {
403 if (event.ctrlKey) { // ctrl+enter
406 if (element.localName() == 'subfield') index = element.parent();
407 if (element.localName() == 'code') index = element.parent().parent();
408 if (element.localName() == 'tag') index = element.parent();
409 if (element.localName() == 'ind1') index = element.parent();
410 if (element.localName() == 'ind2') index = element.parent();
412 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
414 if (event.shiftKey) { // ctrl+shift+enter
415 index.parent().insertChildBefore( index, df );
417 index.parent().insertChildAfter( index, df );
420 var new_df = marcDatafield(df);
422 if (row.parentNode.lastChild === row) {
423 row.parentNode.appendChild( new_df );
425 if (event.shiftKey) { // ctrl+shift+enter
426 row.parentNode.insertBefore( new_df, row );
428 row.parentNode.insertBefore( new_df, row.nextSibling );
432 new_df.firstChild.focus();
434 event.preventDefault();
437 } else if (event.shiftKey) {
438 if (row.previousSibling.className.match('marcDatafieldRow'))
439 row.previousSibling.firstChild.focus();
441 row.nextSibling.firstChild.focus();
444 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
447 if (element.localName() == 'subfield') index = element.parent();
448 if (element.localName() == 'code') index = element.parent().parent();
449 if (element.localName() == 'tag') index = element.parent();
450 if (element.localName() == 'ind1') index = element.parent();
451 if (element.localName() == 'ind2') index = element.parent();
453 for (var i in index.parent().children()) {
454 if (index === index.parent().children()[i]) {
455 delete index.parent().children()[i];
460 row.previousSibling.firstChild.focus();
461 row.parentNode.removeChild(row);
463 event.preventDefault();
466 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
469 if (element.localName() == 'subfield') index = element;
470 if (element.localName() == 'code') index = element.parent();
473 for (var i in index.parent().children()) {
474 if (index === index.parent().children()[i]) {
475 delete index.parent().children()[i];
480 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
481 event.target.parentNode.previousSibling.lastChild.focus();
483 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
486 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
488 event.preventDefault();
491 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
492 createControlField('006','');
493 loadRecord(xml_record);
494 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
495 createControlField('007','');
496 loadRecord(xml_record);
497 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
498 createControlField('008','');
499 loadRecord(xml_record);
505 box.addEventListener(
508 if (element.nodeKind() == 'attribute') element[0]=box.value;
509 else element.setChildren( box.value );
515 box.addEventListener(
518 if (element.nodeKind() == 'attribute') element[0]=box.value;
519 else element.setChildren( box.value );
525 box.addEventListener(
528 if (element.nodeKind() == 'attribute') element[0]=box.value;
529 else element.setChildren( box.value );
535 box.addEventListener(
538 if (element.localName() == 'controlfield')
539 eval('fillFixedFields(xml_record);');
548 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
549 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
550 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
551 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
552 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
553 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
554 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
555 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
561 SCO : {start : 33, len : 1, def : ' ' },
562 REC : {start : 33, len : 1, def : 'n' }
565 SCO : {start : 16, len : 1, def : ' ' },
566 REC : {start : 16, len : 1, def : 'n' }
571 VIS : {start : 33, len : 1, def : ' ' }
574 VIS : {start : 16, len : 1, def : ' ' }
579 VIS : {start : 18, len : 3, def : ' ' }
582 VIS : {start : 1, len : 3, def : ' ' }
587 VIS : {start : 34, len : 1, def : 'n' }
590 VIS : {start : 17, len : 1, def : 'n' }
595 SER : {start : 21, len : 1, def : ' ' }
598 SER : {start : 4, len : 1, def : ' ' }
603 BKS : {start : 39, len : 1, def : 'd' },
604 SER : {start : 39, len : 1, def : 'd' },
605 VIS : {start : 39, len : 1, def : 'd' },
606 MIX : {start : 39, len : 1, def : 'd' },
607 MAP : {start : 39, len : 1, def : 'd' },
608 SCO : {start : 39, len : 1, def : 'd' },
609 REC : {start : 39, len : 1, def : 'd' },
610 COM : {start : 39, len : 1, def : 'd' }
615 MAP : {start : 33, len : 2, def : ' ' }
618 MAP : {start : 16, len : 2, def : ' ' }
623 MAP : {start : 18, len : 4, def : ' ' }
626 MAP : {start : 1, len : 4, def : ' ' }
631 SER : {start : 19, len : 1, def : ' ' }
634 SER : {start : 2, len : 1, def : ' ' }
639 MAP : {start : 22, len : 2, def : ' ' }
642 MAP : {start : 5, len : 2, def : ' ' }
647 SCO : {start : 21, len : 1, def : ' ' },
648 REC : {start : 21, len : 1, def : 'n' }
651 SCO : {start : 4, len : 1, def : ' ' },
652 REC : {start : 4, len : 1, def : 'n' }
657 SER : {start : 22, len : 1, def : ' ' }
660 SER : {start : 5, len : 1, def : ' ' }
665 SCO : {start : 30, len : 2, def : ' ' },
666 REC : {start : 30, len : 2, def : ' ' }
669 SCO : {start : 13, len : 2, def : ' ' },
670 REC : {start : 13, len : 2, def : ' ' }
675 SER : {start : 18, len : 1, def : ' ' }
678 SER : {start : 1, len : 1, def : ' ' }
683 SCO : {start : 20, len : 1, def : ' ' },
684 REC : {start : 20, len : 1, def : 'n' }
687 SCO : {start : 3, len : 1, def : ' ' },
688 REC : {start : 3, len : 1, def : 'n' }
693 COM : {start : 26, len : 1, def : 'u' }
696 COM : {start : 9, len : 1, def : 'u' }
701 SER : {start : 24, len : 1, def : ' ' }
704 SER : {start : 7, len : 1, def : ' ' }
709 SCO : {start : 24, len : 6, def : ' ' },
710 REC : {start : 24, len : 6, def : ' ' }
713 SCO : {start : 7, len : 6, def : ' ' },
714 REC : {start : 7, len : 6, def : ' ' }
719 SCO : {start : 18, len : 2, def : ' ' },
720 REC : {start : 18, len : 2, def : ' ' }
723 SCO : {start : 1, len : 2, def : ' ' },
724 REC : {start : 1, len : 2, def : ' ' }
729 MAP : {start : 25, len : 1, def : ' ' }
732 MAP : {start : 8, len : 1, def : ' ' }
737 BKS : {start : 15, len : 3, def : ' ' },
738 SER : {start : 15, len : 3, def : ' ' },
739 VIS : {start : 15, len : 3, def : ' ' },
740 MIX : {start : 15, len : 3, def : ' ' },
741 MAP : {start : 15, len : 3, def : ' ' },
742 SCO : {start : 15, len : 3, def : ' ' },
743 REC : {start : 15, len : 3, def : ' ' },
744 COM : {start : 15, len : 3, def : ' ' }
749 BKS : {start : 35, len : 3, def : ' ' },
750 SER : {start : 35, len : 3, def : ' ' },
751 VIS : {start : 35, len : 3, def : ' ' },
752 MIX : {start : 35, len : 3, def : ' ' },
753 MAP : {start : 35, len : 3, def : ' ' },
754 SCO : {start : 35, len : 3, def : ' ' },
755 REC : {start : 35, len : 3, def : ' ' },
756 COM : {start : 35, len : 3, def : ' ' }
761 BKS : {start : 38, len : 1, def : ' ' },
762 SER : {start : 38, len : 1, def : ' ' },
763 VIS : {start : 38, len : 1, def : ' ' },
764 MIX : {start : 38, len : 1, def : ' ' },
765 MAP : {start : 38, len : 1, def : ' ' },
766 SCO : {start : 38, len : 1, def : ' ' },
767 REC : {start : 38, len : 1, def : ' ' },
768 COM : {start : 38, len : 1, def : ' ' }
773 BKS : {start : 6, len : 1, def : ' ' },
774 SER : {start : 6, len : 1, def : 'c' },
775 VIS : {start : 6, len : 1, def : ' ' },
776 MIX : {start : 6, len : 1, def : ' ' },
777 MAP : {start : 6, len : 1, def : ' ' },
778 SCO : {start : 6, len : 1, def : ' ' },
779 REC : {start : 6, len : 1, def : ' ' },
780 COM : {start : 6, len : 1, def : ' ' }
785 BKS : {start : 6, len : 1, def : 'a' },
786 SER : {start : 6, len : 1, def : 'a' },
787 VIS : {start : 6, len : 1, def : 'g' },
788 MIX : {start : 6, len : 1, def : 'p' },
789 MAP : {start : 6, len : 1, def : 'e' },
790 SCO : {start : 6, len : 1, def : 'c' },
791 REC : {start : 6, len : 1, def : 'i' },
792 COM : {start : 6, len : 1, def : 'm' }
797 BKS : {start : 8, len : 1, def : ' ' },
798 SER : {start : 8, len : 1, def : ' ' },
799 VIS : {start : 8, len : 1, def : ' ' },
800 MIX : {start : 8, len : 1, def : ' ' },
801 MAP : {start : 8, len : 1, def : ' ' },
802 SCO : {start : 8, len : 1, def : ' ' },
803 REC : {start : 8, len : 1, def : ' ' },
804 COM : {start : 8, len : 1, def : ' ' }
809 BKS : {start : 7, len : 1, def : 'm' },
810 SER : {start : 7, len : 1, def : 's' },
811 VIS : {start : 7, len : 1, def : 'm' },
812 MIX : {start : 7, len : 1, def : 'c' },
813 MAP : {start : 7, len : 1, def : 'm' },
814 SCO : {start : 7, len : 1, def : 'm' },
815 REC : {start : 7, len : 1, def : 'm' },
816 COM : {start : 7, len : 1, def : 'm' }
821 BKS : {start : 18, len : 1, def : ' ' },
822 SER : {start : 18, len : 1, def : ' ' },
823 VIS : {start : 18, len : 1, def : ' ' },
824 MIX : {start : 18, len : 1, def : ' ' },
825 MAP : {start : 18, len : 1, def : ' ' },
826 SCO : {start : 18, len : 1, def : ' ' },
827 REC : {start : 18, len : 1, def : ' ' },
828 COM : {start : 18, len : 1, def : ' ' }
833 BKS : {start : 17, len : 1, def : ' ' },
834 SER : {start : 17, len : 1, def : ' ' },
835 VIS : {start : 17, len : 1, def : ' ' },
836 MIX : {start : 17, len : 1, def : ' ' },
837 MAP : {start : 17, len : 1, def : ' ' },
838 SCO : {start : 17, len : 1, def : ' ' },
839 REC : {start : 17, len : 1, def : ' ' },
840 COM : {start : 17, len : 1, def : ' ' }
845 BKS : {start : 31, len : 1, def : '0' },
846 MAP : {start : 31, len : 1, def : '0' }
849 BKS : {start : 14, len : 1, def : '0' },
850 MAP : {start : 14, len : 1, def : '0' }
855 BKS : {start : 7, len : 4, def : ' ' },
856 SER : {start : 7, len : 4, def : ' ' },
857 VIS : {start : 7, len : 4, def : ' ' },
858 MIX : {start : 7, len : 4, def : ' ' },
859 MAP : {start : 7, len : 4, def : ' ' },
860 SCO : {start : 7, len : 4, def : ' ' },
861 REC : {start : 7, len : 4, def : ' ' },
862 COM : {start : 7, len : 4, def : ' ' }
867 BKS : {start : 11, len : 4, def : ' ' },
868 SER : {start : 11, len : 4, def : '9' },
869 VIS : {start : 11, len : 4, def : ' ' },
870 MIX : {start : 11, len : 4, def : ' ' },
871 MAP : {start : 11, len : 4, def : ' ' },
872 SCO : {start : 11, len : 4, def : ' ' },
873 REC : {start : 11, len : 4, def : ' ' },
874 COM : {start : 11, len : 4, def : ' ' }
879 BKS : {start : 33, len : 1, def : '0' }
882 BKS : {start : 16, len : 1, def : '0' }
887 BKS : {start : 34, len : 1, def : ' ' }
890 BKS : {start : 17, len : 1, def : ' ' }
895 BKS : {start : 18, len : 4, def : ' ' }
898 BKS : {start : 1, len : 4, def : ' ' }
903 BKS : {start : 30, len : 1, def : '0' }
906 BKS : {start : 13, len : 1, def : '0' }
911 BKS : {start : 29, len : 1, def : '0' },
912 SER : {start : 29, len : 1, def : '0' }
915 BKS : {start : 12, len : 1, def : '0' },
916 SER : {start : 12, len : 1, def : '0' }
921 BKS : {start : 24, len : 4, def : ' ' },
922 SER : {start : 25, len : 3, def : ' ' }
925 BKS : {start : 7, len : 4, def : ' ' },
926 SER : {start : 8, len : 3, def : ' ' }
931 BKS : {start : 28, len : 1, def : ' ' },
932 SER : {start : 28, len : 1, def : ' ' },
933 VIS : {start : 28, len : 1, def : ' ' },
934 MAP : {start : 28, len : 1, def : ' ' },
935 COM : {start : 28, len : 1, def : ' ' }
938 BKS : {start : 11, len : 1, def : ' ' },
939 SER : {start : 11, len : 1, def : ' ' },
940 VIS : {start : 11, len : 1, def : ' ' },
941 MAP : {start : 11, len : 1, def : ' ' },
942 COM : {start : 11, len : 1, def : ' ' }
947 BKS : {start : 22, len : 1, def : ' ' },
948 SER : {start : 22, len : 1, def : ' ' },
949 VIS : {start : 22, len : 1, def : ' ' },
950 SCO : {start : 22, len : 1, def : ' ' },
951 REC : {start : 22, len : 1, def : ' ' },
952 COM : {start : 22, len : 1, def : ' ' }
955 BKS : {start : 5, len : 1, def : ' ' },
956 SER : {start : 5, len : 1, def : ' ' },
957 VIS : {start : 5, len : 1, def : ' ' },
958 SCO : {start : 5, len : 1, def : ' ' },
959 REC : {start : 5, len : 1, def : ' ' },
960 COM : {start : 5, len : 1, def : ' ' }
965 BKS : {start : 23, len : 1, def : ' ' },
966 SER : {start : 23, len : 1, def : ' ' },
967 VIS : {start : 29, len : 1, def : ' ' },
968 MIX : {start : 23, len : 1, def : ' ' },
969 MAP : {start : 29, len : 1, def : ' ' },
970 SCO : {start : 23, len : 1, def : ' ' },
971 REC : {start : 23, len : 1, def : ' ' }
974 BKS : {start : 6, len : 1, def : ' ' },
975 SER : {start : 6, len : 1, def : ' ' },
976 VIS : {start : 12, len : 1, def : ' ' },
977 MIX : {start : 6, len : 1, def : ' ' },
978 MAP : {start : 12, len : 1, def : ' ' },
979 SCO : {start : 6, len : 1, def : ' ' },
980 REC : {start : 6, len : 1, def : ' ' }
985 SER : {start : 34, len : 1, def : '0' }
988 SER : {start : 17, len : 1, def : '0' }
993 SER : {start : 33, len : 1, def : ' ' }
996 SER : {start : 16, len : 1, def : ' ' }
1001 function recordType (rec) {
1003 var _l = rec.leader.toString();
1005 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1006 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1008 for (var t in rec_type) {
1009 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1010 document.getElementById('recordTypeLabel').value = t;
1016 // in case we don't have a valid record type ...
1017 _record_type = 'BKS';
1018 return _record_type;
1021 alert('FIXME, MARC Editor, recordType: ' + E);
1025 function toggleFFE () {
1026 var grid = document.getElementById('leaderGrid');
1028 grid.hidden = false;
1035 function changeFFEditor (type) {
1036 var grid = document.getElementById('leaderGrid');
1037 grid.setAttribute('type',type);
1040 function fillFixedFields (rec) {
1042 var grid = document.getElementById('leaderGrid');
1044 var rtype = _record_type;
1046 var _l = rec.leader.toString();
1047 var _6 = rec.controlfield.(@tag=='006').toString();
1048 var _7 = rec.controlfield.(@tag=='007').toString();
1049 var _8 = rec.controlfield.(@tag=='008').toString();
1052 var pre_list = grid.getElementsByTagName('label');
1053 for (var i in pre_list) {
1054 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1055 list.push( pre_list[i] );
1059 for (var i in list) {
1060 var name = list[i].getAttribute('name');
1066 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1067 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1069 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1070 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1072 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1073 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1075 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1076 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1081 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1082 d = ff_pos[name].ldr[rtype].def;
1086 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1087 d = ff_pos[name]._8[rtype].def;
1091 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1092 d = ff_pos[name]._6[rtype].def;
1096 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1097 d = ff_pos[name]._7[rtype].def;
1102 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1108 list[i].nextSibling.value = value;
1113 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1117 function updateFixedFields (element) {
1118 var grid = document.getElementById('leaderGrid');
1119 var recGrid = document.getElementById('recGrid');
1121 var rtype = _record_type;
1122 var new_value = element.value;
1125 ldr : _record.leader,
1126 _6 : _record.controlfield.(@tag=='006'),
1127 _7 : _record.controlfield.(@tag=='007'),
1128 _8 : _record.controlfield.(@tag=='008')
1131 var name = element.getAttribute('name');
1132 for (var i in ff_pos[name]) {
1134 if (!ff_pos[name][i][rtype]) continue;
1135 if (!parts[i]) continue;
1137 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1138 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1140 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1141 new_value += ff_pos[name][i][rtype].def;
1144 parts[i].setChildren( before + new_value + after );
1145 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1151 function marcLeader (leader) {
1152 var row = createRow(
1153 { class : 'marcLeaderRow',
1158 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1161 class : 'marcInd1' } ),
1164 class : 'marcInd2' } ),
1166 { value : leader.text(),
1167 class : 'marcLeader' } )
1173 function marcControlfield (field) {
1174 tagname = field.@tag.toString().substr(2);
1176 if (tagname == '6' || tagname == '7' || tagname == '8') {
1178 { class : 'marcControlfieldRow',
1179 tag : '_' + tagname },
1181 { value : field.@tag,
1183 context : 'tags_popup',
1184 onmouseover : 'getTooltip(this, "tag");',
1185 tooltipid : 'tag' + field.@tag } ),
1187 { value : field.@ind1,
1189 onmouseover : 'getTooltip(this, "ind1");',
1190 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1192 { value : field.@ind2,
1194 onmouseover : 'getTooltip(this, "ind2");',
1195 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1198 { value : field.text(),
1199 class : 'plain marcEditableControlfield',
1200 name : 'CONTROL' + tagname,
1201 oncontext : 'return false();',
1207 { class : 'marcControlfieldRow',
1208 tag : '_' + tagname },
1210 { value : field.@tag,
1212 onmouseover : 'getTooltip(this, "tag");',
1213 tooltipid : 'tag' + field.@tag } ),
1215 { value : field.@ind1,
1217 onmouseover : 'getTooltip(this, "ind1");',
1218 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1220 { value : field.@ind2,
1222 onmouseover : 'getTooltip(this, "ind2");',
1223 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1225 { value : field.text(),
1226 class : 'marcControlfield' } )
1233 function stackSubfields(checkbox) {
1234 var list = document.getElementsByAttribute('name','sf_box');
1237 if (!checkbox.checked) o = 'horizontal';
1239 for (var i = 0; i < list.length; i++) {
1240 if (list[i]) list[i].setAttribute('orient',o);
1244 function fastItemAdd_toggle(checkbox) {
1245 var x = document.getElementById('fastItemAdd_textboxes');
1246 if (checkbox.checked) {
1248 document.getElementById('fastItemAdd_callnumber').focus();
1249 document.getElementById('fastItemAdd_callnumber').select();
1255 function fastItemAdd_attempt(doc_id) {
1257 if (typeof window.xulG.fast_add_item != 'function') { return; }
1258 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1259 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1260 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1261 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1263 alert('fastItemAdd_attempt: ' + E);
1267 function save_attempt(xml_string) {
1269 var result = window.xulG.save.func( xml_string );
1271 if (result.id) fastItemAdd_attempt(result.id);
1272 if (typeof result.on_complete == 'function') result.on_complete();
1275 alert('save_attempt: ' + E);
1279 function marcDatafield (field) {
1280 var row = createRow(
1281 { class : 'marcDatafieldRow' },
1284 { value : field.@tag,
1285 class : 'plain marcTag',
1287 context : 'tags_popup',
1288 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1291 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1294 { value : field.@ind1,
1295 class : 'plain marcInd1',
1297 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1300 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1301 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1304 { value : field.@ind2,
1305 class : 'plain marcInd2',
1307 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1310 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1311 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1312 createHbox({ name : 'sf_box' })
1315 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1316 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1317 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1319 var sf_box = row.lastChild;
1320 if (document.getElementById('stackSubfields').checked)
1321 sf_box.setAttribute('orient','vertical');
1323 sf_box.addEventListener(
1326 if (sf_box === e.target) {
1327 sf_box.lastChild.lastChild.focus();
1328 } else if (e.target.parentNode === sf_box) {
1329 e.target.lastChild.focus();
1336 for (var i in field.subfield) {
1337 var sf = field.subfield[i];
1342 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1343 current_focus = sf_box.lastChild.childNodes[1];
1349 function marcSubfield (sf) {
1351 { class : 'marcSubfieldBox' },
1354 class : 'plain marcSubfieldDelimiter',
1355 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1356 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1357 //onclick : 'this.nextSibling.focus();',
1358 onfocus : 'this.nextSibling.focus();',
1363 class : 'plain marcSubfieldCode',
1364 name : 'marcSubfieldCode',
1365 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1366 oncontextmenu : 'getContextMenu(this, "subfield");',
1367 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1372 { value : sf.text(),
1373 name : sf.parent().@tag + ':' + sf.@code,
1374 class : 'plain marcSubfield',
1375 onmouseover : 'getTooltip(this, "subfield");',
1376 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1377 size : new String(sf.text()).length + 2,
1378 oninput : "this.setAttribute('size', this.value.length + 2);"
1383 function loadRecord(rec) {
1386 var grid_rows = document.getElementById('recGrid').lastChild;
1388 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1390 grid_rows.appendChild( marcLeader( rec.leader ) );
1392 for (var i in rec.controlfield) {
1393 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1396 for (var i in rec.datafield) {
1397 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1400 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1401 changeFFEditor(recordType(rec));
1402 fillFixedFields(rec);
1404 alert('FIXME, MARC Editor, loadRecord: ' + E);
1409 function genToolTips () {
1410 for (var i in bib_data.field) {
1411 var f = bib_data.field[i];
1413 tag_menu.appendChild(
1417 'current_focus.value = "' + f.@tag + '";' +
1418 'var e = document.createEvent("MutationEvents");' +
1419 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1420 'current_focus.inputField.dispatchEvent(e);',
1421 disabled : f.@tag < '010' ? "true" : "false",
1422 tooltiptext : f.description }
1426 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1427 context_menus.appendChild( i1_popup );
1429 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1430 context_menus.appendChild( i2_popup );
1432 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1433 context_menus.appendChild( sf_popup );
1435 tooltip_hash['tag' + f.@tag] = f.description;
1436 for (var j in f.indicator) {
1437 var ind = f.indicator[j];
1438 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1440 if (ind.@position == 1) {
1441 i1_popup.appendChild(
1443 { label : ind.@value,
1445 'current_focus.value = "' + ind.@value + '";' +
1446 'var e = document.createEvent("MutationEvents");' +
1447 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1448 'current_focus.inputField.dispatchEvent(e);',
1449 tooltiptext : ind.description }
1454 if (ind.@position == 2) {
1455 i2_popup.appendChild(
1457 { label : ind.@value,
1459 'current_focus.value = "' + ind.@value + '";' +
1460 'var e = document.createEvent("MutationEvents");' +
1461 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1462 'current_focus.inputField.dispatchEvent(e);',
1463 tooltiptext : ind.description }
1469 for (var j in f.subfield) {
1470 var sf = f.subfield[j];
1471 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1473 sf_popup.appendChild(
1477 'current_focus.value = "' + sf.@code + '";' +
1478 'var e = document.createEvent("MutationEvents");' +
1479 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1480 'current_focus.inputField.dispatchEvent(e);',
1481 tooltiptext : sf.description
1489 function getTooltip (target, type) {
1492 if (type == 'subfield')
1493 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1496 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1499 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1502 tt = 'tag' + target.parentNode.firstChild.value;
1504 if (!document.getElementById( tt )) {
1509 orient : 'vertical',
1510 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1511 class : 'tooltip' },
1512 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1517 target.tooltip = tt;
1521 function getContextMenu (target, type) {
1524 if (type == 'subfield')
1525 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1528 tt = 't' + target.parentNode.firstChild.value + 'i1';
1531 tt = 't' + target.parentNode.firstChild.value + 'i2';
1533 target.setAttribute('context', tt);
1537 var authority_tag_map = {
1538 100 : ['[100,400,500,700]',100],
1539 400 : ['[100,400,500,700]',100],
1540 700 : ['[100,400,500,700]',100],
1541 800 : ['[100,400,500,700]',100],
1542 110 : ['[110,410,510,710]',110],
1543 410 : ['[110,410,510,710]',110],
1544 710 : ['[110,410,510,710]',110],
1545 810 : ['[110,410,510,710]',110],
1546 111 : ['[111,411,511,711]',111],
1547 411 : ['[111,411,511,711]',111],
1548 711 : ['[111,411,511,711]',111],
1549 811 : ['[111,411,511,711]',111],
1550 240 : ['[130,430,530,730]',130],
1551 440 : ['[130,430,530,730]',130],
1552 130 : ['[130,430,530,730]',130],
1553 730 : ['[130,430,530,730]',130],
1554 830 : ['[130,430,530,730]',130],
1555 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1556 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1557 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1558 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1561 function getAuthorityContextMenu (target, sf) {
1562 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1564 var old = document.getElementById( menu_id );
1565 if (old) old.parentNode.removeChild(old);
1567 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1568 context_menus.appendChild( sf_popup );
1570 if (!authority_tag_map[sf.parent().@tag]) {
1571 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1572 target.setAttribute('context', menu_id);
1576 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1578 var res = new XML( auth_data.responseText );
1582 var recs = res.gw::payload.gw::array.gw::string;
1583 for (var i in recs) {
1585 var xml = new XML(x.toString());
1586 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1588 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1591 for (var i in main) {
1592 if (main_text) main_text += ' / ';
1593 main_text += main[i];
1596 rec_list.push( [ main_text, xml ] );
1599 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1601 var main_text = rec_list[i][0];
1602 var xml = rec_list[i][1];
1603 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1605 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1607 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1608 grid.setAttribute('name','-none-');
1609 grid.setAttribute('style','overflow:scroll');
1612 var submenu = createMenu( { label : main_text } );
1614 var popup = createMenuPopup({ flex : "1" });
1615 submenu.appendChild(popup);
1617 var fields = xml.datafield;
1618 for (var j in fields) {
1620 var row = createRow(
1622 createLabel( { value : fields[j].@tag } ),
1623 createLabel( { value : fields[j].@ind1 } ),
1624 createLabel( { value : fields[j].@ind2 } )
1627 var sf_box = createHbox();
1629 var subfields = fields[j].subfield;
1630 for (var k in subfields) {
1633 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1634 subfield : subfields[k].@code,
1635 tag : subfields[k].parent().@tag,
1636 value : subfields[k]
1640 row.appendChild(sf_box);
1643 grid.lastChild.appendChild(row);
1646 grid.hidden = false;
1647 popup.appendChild( grid );
1651 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1652 command : function (event) {
1653 applyAuthority(event.target.previousSibling, target, sf);
1660 sf_popup.appendChild( submenu );
1663 if (sf_popup.childNodes.length == 0)
1664 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1666 target.setAttribute('context', menu_id);
1670 function applyAuthority ( target, ui_sf, e4x_sf ) {
1672 var new_vals = target.getElementsByAttribute('checked','true');
1673 var field = e4x_sf.parent();
1675 for (var i = 0; i < new_vals.length; i++) {
1677 var sf_list = field.subfield;
1678 for (var j in sf_list) {
1680 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1681 sf_list[j] = new_vals[i].getAttribute('value');
1682 new_vals[i].setAttribute('subfield','');
1688 for (var i = 0; i < new_vals.length; i++) {
1689 if (!new_vals[i].getAttribute('subfield')) continue;
1691 var val = new_vals[i].getAttribute('value');
1693 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1694 sf.@code = new_vals[i].getAttribute('subfield');
1696 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1699 var row = marcDatafield( field );
1702 while (node.nodeName != 'row') {
1703 node = node.parentNode;
1706 node.parentNode.replaceChild( row, node );
1712 'a' : { 100 : 'a' },
1716 'a' : { 110 : 'a' },
1720 'a' : { 111 : 'a' },
1724 'a' : { 130 : 'a' },
1728 'a' : { 130 : 'a' },
1732 'a' : { 100 : 'a' },
1736 'a' : { 110 : 'a' },
1740 'a' : { 111 : 'a' },
1744 'a' : { 130 : 'a' },
1745 'n' : { 130 : 'n' },
1749 'a' : { 100 : 'a' },
1753 'a' : { 110 : 'a' },
1757 'a' : { 111 : 'a' },
1761 'a' : { 130 : 'a' },
1765 'a' : { 100 : 'a' },
1769 'a' : { 110 : 'a' },
1773 'a' : { 111 : 'a' },
1777 'a' : { 130 : 'a' },
1781 'a' : { 100 : 'a' },
1782 'd' : { 100 : 'd' },
1783 't' : { 100 : 't' },
1810 'a' : { 110 : 'a' },
1811 'd' : { 110 : 'd' },
1812 't' : { 110 : 't' },
1839 'a' : { 111 : 'a' },
1840 'd' : { 111 : 'd' },
1841 't' : { 111 : 't' },
1868 'a' : { 130 : 'a' },
1872 'a' : { 150 : 'a' },
1873 'b' : { 150 : 'b' },
1900 'a' : { 151 : 'a' },
1927 'a' : { 155 : 'a' },
1955 function validateAuthority (button) {
1956 var grid = document.getElementById('recGrid');
1957 var label = button.getAttribute('label');
1960 var rows = grid.lastChild.childNodes;
1961 for (var i = 0; i < rows.length; i++) {
1963 var tag = row.firstChild;
1965 if (!control_map[tag.value]) continue
1966 button.setAttribute('label', label + ' - ' + tag.value);
1968 var ind1 = tag.nextSibling;
1969 var ind2 = ind1.nextSibling;
1970 var subfields = ind2.nextSibling.childNodes;
1974 for (var j = 0; j < subfields.length; j++) {
1975 var sf = subfields[j];
1976 var sf_code = sf.childNodes[1].value;
1977 var sf_value = sf.childNodes[2].value;
1979 if (!control_map[tag.value][sf_code]) continue;
1982 for (var a_tag in control_map[tag.value][sf_code]) {
1983 if (!tags[a_tag]) tags[a_tag] = [];
1984 tags[a_tag].push({ term : sf_value, subfield : sf_code });
1989 for (var val_tag in tags) {
1990 var auth_data = validateBibField( [val_tag], tags[val_tag]);
1991 var res = new XML( auth_data.responseText );
1992 found = parseInt(res.gw::payload.gw::string.toString());
1996 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1997 for (var j = 0; j < subfields.length; j++) {
1998 var sf = subfields[j];
2000 sf.childNodes[2].inputField.style.color = 'red';
2002 sf.childNodes[2].inputField.style.color = 'black';
2007 button.setAttribute('label', label);
2013 function validateBibField (tags, searches) {
2014 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2015 url += '¶m="tags"¶m=' + js2JSON(tags);
2016 url += '¶m="searches"¶m=' + js2JSON(searches);
2019 var req = new XMLHttpRequest();
2020 req.open('GET',url,false);
2026 function searchAuthority (term, tag, sf, limit) {
2027 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2028 url += '¶m="term"¶m="' + term + '"';
2029 url += '¶m="limit"¶m=' + limit;
2030 url += '¶m="tag"¶m=' + tag;
2031 url += '¶m="subfield"¶m="' + sf + '"';
2034 var req = new XMLHttpRequest();
2035 req.open('GET',url,false);