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 = {};
21 function $(id) { return document.getElementById(id); }
23 function mangle_005() {
25 var y = now.getUTCFullYear();
27 var m = now.getUTCMonth() + 1;
28 if (m < 10) m = '0' + m;
30 var d = now.getUTCDate();
31 if (d < 10) d = '0' + d;
33 var H = now.getUTCHours();
34 if (H < 10) H = '0' + H;
36 var M = now.getUTCMinutes();
37 if (M < 10) M = '0' + M;
39 var S = now.getUTCSeconds();
40 if (S < 10) S = '0' + S;
43 var stamp = '' + y + m + d + H + M + S + '.0';
44 createControlField('005',stamp);
48 function createControlField (tag,data) {
49 // first, remove the old field, if any;
50 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
52 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
55 // then, find the right position and insert it
57 var cfields = xml_record.controlfield;
58 var base = Number(tag.substring(2));
59 for (var i in cfields) {
60 var t = Number(cfields[i].@tag.toString().substring(2));
62 xml_record.insertChildBefore( cfields[i], cf );
68 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
73 function xml_escape_unicode ( str ) {
76 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
83 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
84 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
85 JSAN.errorLevel = "die"; // none, warn, or die
86 JSAN.addRepository('/xul/server/');
88 // Fake xulG for standalone...
93 window.xulG.record = {};
94 window.xulG.save = {};
96 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
97 window.xulG.save.func = function (r) { alert(r); }
100 var _rid = cgi.param('record');
102 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
105 // End faking part...
107 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
108 document.getElementById('save-button').setAttribute('oncommand',
110 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
111 'window.xulG.save.func( xml_string ); ' +
112 'loadRecord(xml_record);'
115 if (window.xulG.record.url) {
116 var req = new XMLHttpRequest();
117 req.open('POST',window.xulG.record.url,false);
119 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
122 xml_record = new XML( window.xulG.record.marc );
123 if (xml_record..record[0]) xml_record = xml_record..record[0];
125 // Get the tooltip xml all async like
126 req = new XMLHttpRequest();
128 // Set a default locale in case preferences fail us
129 var locale = "en-US";
131 // Try to get the locale from our preferences
132 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
134 const Cc = Components.classes;
135 const Ci = Components.interfaces;
136 locale = Cc["@mozilla.org/preferences-service;1"].
137 getService(Ci.nsIPrefBranch).
138 getCharPref("general.useragent.locale");
142 // TODO: We should send a HEAD request to check for the existence of the desired file
143 // then fall back to the default locale if preferred locale is not necessary;
144 // however, for now we have a simplistic check:
146 // we currently have translations for only two locales; in the absence of a
147 // valid locale, default to the almighty en-US
148 if (locale != 'en-US' && locale != 'fr-CA') {
152 // Get the locale-specific tooltips
153 req.open('GET','/xul/server/locale/' + locale + '/marcedit-tooltips.xml',true);
155 context_menus = createComplexXULElement('popupset');
156 document.documentElement.appendChild( context_menus );
158 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
159 context_menus.appendChild( tag_menu );
161 tag_menu.appendChild(
163 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
165 'var e = document.createEvent("KeyEvents");' +
166 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
167 'current_focus.inputField.dispatchEvent(e);'
172 tag_menu.appendChild(
174 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
176 'var e = document.createEvent("KeyEvents");' +
177 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
178 'current_focus.inputField.dispatchEvent(e);'
183 tag_menu.appendChild(
185 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
187 'var e = document.createEvent("KeyEvents");' +
188 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
189 'current_focus.inputField.dispatchEvent(e);'
194 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
196 tag_menu.appendChild(
198 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
200 'var e = document.createEvent("KeyEvents");' +
201 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
202 'current_focus.inputField.dispatchEvent(e);'
207 tag_menu.appendChild(
209 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
211 'var e = document.createEvent("KeyEvents");' +
212 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
213 'current_focus.inputField.dispatchEvent(e);'
218 tag_menu.appendChild(
220 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
222 'var e = document.createEvent("KeyEvents");' +
223 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
224 'current_focus.inputField.dispatchEvent(e);'
229 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
231 p = createComplexXULElement('popupset');
232 document.documentElement.appendChild( p );
234 req.onreadystatechange = function () {
235 if (req.readyState == 4) {
236 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
242 loadRecord(xml_record);
245 alert('FIXME, MARC Editor, my_init: ' + E);
250 function createComplexHTMLElement (e, attrs, objects, text) {
251 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
254 for (var i in attrs) l.setAttribute(i,attrs[i]);
258 for ( var i in objects ) l.appendChild( objects[i] );
262 l.appendChild( document.createTextNode(text) )
268 function createComplexXULElement (e, attrs, objects) {
269 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
272 for (var i in attrs) {
273 if (typeof attrs[i] == 'function') {
274 l.addEventListener( i, attrs[i], true );
276 l.setAttribute(i,attrs[i]);
282 for ( var i in objects ) l.appendChild( objects[i] );
288 function createDescription (attrs) {
289 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
292 function createTooltip (attrs) {
293 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
296 function createLabel (attrs) {
297 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
300 function createVbox (attrs) {
301 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
304 function createHbox (attrs) {
305 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
308 function createRow (attrs) {
309 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
312 function createTextbox (attrs) {
313 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
316 function createMenu (attrs) {
317 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
320 function createMenuPopup (attrs) {
321 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
324 function createPopup (attrs) {
325 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
328 function createMenuitem (attrs) {
329 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
332 function createCheckbox (attrs) {
333 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
336 function createMARCTextbox (element,attrs) {
338 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
339 box.onkeypress = function (event) {
342 while(node = node.parent()) {
346 var row = event.target;
347 while (row.tagName != 'row') row = row.parentNode;
349 if (element.nodeKind() == 'attribute') element[0]=box.value;
350 else element.setChildren( box.value );
352 if (element.localName() != 'controlfield') {
353 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
355 var index_sf, target, move_data;
356 if (element.localName() == 'subfield') {
358 target = event.target.parentNode;
360 var start = event.target.selectionStart;
361 var end = event.target.selectionEnd - event.target.selectionStart ?
362 event.target.selectionEnd :
363 event.target.value.length;
365 move_data = event.target.value.substring(start,end);
366 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
367 event.target.setAttribute('size', event.target.value.length + 2);
369 element.setChildren( event.target.value );
371 } else if (element.localName() == 'code') {
372 index_sf = element.parent();
373 target = event.target.parentNode;
374 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
375 index_sf = element.parent().children()[element.parent().children().length() - 1];
376 target = event.target.parentNode.lastChild.lastChild;
379 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
381 index_sf.parent().insertChildAfter( index_sf, sf );
383 var new_sf = marcSubfield(sf);
385 if (target === target.parentNode.lastChild) {
386 target.parentNode.appendChild( new_sf );
388 target.parentNode.insertBefore( new_sf, target.nextSibling );
391 new_sf.firstChild.nextSibling.focus();
393 event.preventDefault();
396 } else if (event.keyCode == 13 || event.keyCode == 77) {
397 if (event.ctrlKey) { // ctrl+enter
400 if (element.localName() == 'subfield') index = element.parent();
401 if (element.localName() == 'code') index = element.parent().parent();
402 if (element.localName() == 'tag') index = element.parent();
403 if (element.localName() == 'ind1') index = element.parent();
404 if (element.localName() == 'ind2') index = element.parent();
406 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
408 if (event.shiftKey) { // ctrl+shift+enter
409 index.parent().insertChildBefore( index, df );
411 index.parent().insertChildAfter( index, df );
414 var new_df = marcDatafield(df);
416 if (row.parentNode.lastChild === row) {
417 row.parentNode.appendChild( new_df );
419 if (event.shiftKey) { // ctrl+shift+enter
420 row.parentNode.insertBefore( new_df, row );
422 row.parentNode.insertBefore( new_df, row.nextSibling );
426 new_df.firstChild.focus();
428 event.preventDefault();
431 } else if (event.shiftKey) {
432 if (row.previousSibling.className.match('marcDatafieldRow'))
433 row.previousSibling.firstChild.focus();
435 row.nextSibling.firstChild.focus();
438 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
441 if (element.localName() == 'subfield') index = element.parent();
442 if (element.localName() == 'code') index = element.parent().parent();
443 if (element.localName() == 'tag') index = element.parent();
444 if (element.localName() == 'ind1') index = element.parent();
445 if (element.localName() == 'ind2') index = element.parent();
447 for (var i in index.parent().children()) {
448 if (index === index.parent().children()[i]) {
449 delete index.parent().children()[i];
454 row.previousSibling.firstChild.focus();
455 row.parentNode.removeChild(row);
457 event.preventDefault();
460 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
463 if (element.localName() == 'subfield') index = element;
464 if (element.localName() == 'code') index = element.parent();
467 for (var i in index.parent().children()) {
468 if (index === index.parent().children()[i]) {
469 delete index.parent().children()[i];
474 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
475 event.target.parentNode.previousSibling.lastChild.focus();
477 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
480 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
482 event.preventDefault();
485 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
486 createControlField('006','');
487 loadRecord(xml_record);
488 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
489 createControlField('007','');
490 loadRecord(xml_record);
491 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
492 createControlField('008','');
493 loadRecord(xml_record);
499 box.addEventListener(
502 if (element.nodeKind() == 'attribute') element[0]=box.value;
503 else element.setChildren( box.value );
509 box.addEventListener(
512 if (element.nodeKind() == 'attribute') element[0]=box.value;
513 else element.setChildren( box.value );
519 box.addEventListener(
522 if (element.nodeKind() == 'attribute') element[0]=box.value;
523 else element.setChildren( box.value );
529 box.addEventListener(
532 if (element.localName() == 'controlfield')
533 eval('fillFixedFields(xml_record);');
542 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
543 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
544 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
545 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
546 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
547 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
548 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
549 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
555 SCO : {start : 33, len : 1, def : ' ' },
556 REC : {start : 33, len : 1, def : 'n' }
559 SCO : {start : 16, len : 1, def : ' ' },
560 REC : {start : 16, len : 1, def : 'n' }
565 VIS : {start : 33, len : 1, def : ' ' }
568 VIS : {start : 16, len : 1, def : ' ' }
573 VIS : {start : 18, len : 3, def : ' ' }
576 VIS : {start : 1, len : 3, def : ' ' }
581 VIS : {start : 34, len : 1, def : 'n' }
584 VIS : {start : 17, len : 1, def : 'n' }
589 SER : {start : 21, len : 1, def : ' ' }
592 SER : {start : 4, len : 1, def : ' ' }
597 BKS : {start : 39, len : 1, def : 'd' },
598 SER : {start : 39, len : 1, def : 'd' },
599 VIS : {start : 39, len : 1, def : 'd' },
600 MIX : {start : 39, len : 1, def : 'd' },
601 MAP : {start : 39, len : 1, def : 'd' },
602 SCO : {start : 39, len : 1, def : 'd' },
603 REC : {start : 39, len : 1, def : 'd' },
604 COM : {start : 39, len : 1, def : 'd' }
609 MAP : {start : 33, len : 2, def : ' ' }
612 MAP : {start : 16, len : 2, def : ' ' }
617 MAP : {start : 18, len : 4, def : ' ' }
620 MAP : {start : 1, len : 4, def : ' ' }
625 SER : {start : 19, len : 1, def : ' ' }
628 SER : {start : 2, len : 1, def : ' ' }
633 MAP : {start : 22, len : 2, def : ' ' }
636 MAP : {start : 5, len : 2, def : ' ' }
641 SCO : {start : 21, len : 1, def : ' ' },
642 REC : {start : 21, len : 1, def : 'n' }
645 SCO : {start : 4, len : 1, def : ' ' },
646 REC : {start : 4, len : 1, def : 'n' }
651 SER : {start : 22, len : 1, def : ' ' }
654 SER : {start : 5, len : 1, def : ' ' }
659 SCO : {start : 30, len : 2, def : ' ' },
660 REC : {start : 30, len : 2, def : ' ' }
663 SCO : {start : 13, len : 2, def : ' ' },
664 REC : {start : 13, len : 2, def : ' ' }
669 SER : {start : 18, len : 1, def : ' ' }
672 SER : {start : 1, len : 1, def : ' ' }
677 SCO : {start : 20, len : 1, def : ' ' },
678 REC : {start : 20, len : 1, def : 'n' }
681 SCO : {start : 3, len : 1, def : ' ' },
682 REC : {start : 3, len : 1, def : 'n' }
687 COM : {start : 26, len : 1, def : 'u' }
690 COM : {start : 9, len : 1, def : 'u' }
695 SER : {start : 24, len : 1, def : ' ' }
698 SER : {start : 7, len : 1, def : ' ' }
703 SCO : {start : 24, len : 6, def : ' ' },
704 REC : {start : 24, len : 6, def : ' ' }
707 SCO : {start : 7, len : 6, def : ' ' },
708 REC : {start : 7, len : 6, def : ' ' }
713 SCO : {start : 18, len : 2, def : ' ' },
714 REC : {start : 18, len : 2, def : ' ' }
717 SCO : {start : 1, len : 2, def : ' ' },
718 REC : {start : 1, len : 2, def : ' ' }
723 MAP : {start : 25, len : 1, def : ' ' }
726 MAP : {start : 8, len : 1, def : ' ' }
731 BKS : {start : 15, len : 3, def : ' ' },
732 SER : {start : 15, len : 3, def : ' ' },
733 VIS : {start : 15, len : 3, def : ' ' },
734 MIX : {start : 15, len : 3, def : ' ' },
735 MAP : {start : 15, len : 3, def : ' ' },
736 SCO : {start : 15, len : 3, def : ' ' },
737 REC : {start : 15, len : 3, def : ' ' },
738 COM : {start : 15, len : 3, def : ' ' }
743 BKS : {start : 35, len : 3, def : ' ' },
744 SER : {start : 35, len : 3, def : ' ' },
745 VIS : {start : 35, len : 3, def : ' ' },
746 MIX : {start : 35, len : 3, def : ' ' },
747 MAP : {start : 35, len : 3, def : ' ' },
748 SCO : {start : 35, len : 3, def : ' ' },
749 REC : {start : 35, len : 3, def : ' ' },
750 COM : {start : 35, len : 3, def : ' ' }
755 BKS : {start : 38, len : 1, def : ' ' },
756 SER : {start : 38, len : 1, def : ' ' },
757 VIS : {start : 38, len : 1, def : ' ' },
758 MIX : {start : 38, len : 1, def : ' ' },
759 MAP : {start : 38, len : 1, def : ' ' },
760 SCO : {start : 38, len : 1, def : ' ' },
761 REC : {start : 38, len : 1, def : ' ' },
762 COM : {start : 38, len : 1, def : ' ' }
767 BKS : {start : 6, len : 1, def : ' ' },
768 SER : {start : 6, len : 1, def : 'c' },
769 VIS : {start : 6, len : 1, def : ' ' },
770 MIX : {start : 6, len : 1, def : ' ' },
771 MAP : {start : 6, len : 1, def : ' ' },
772 SCO : {start : 6, len : 1, def : ' ' },
773 REC : {start : 6, len : 1, def : ' ' },
774 COM : {start : 6, len : 1, def : ' ' }
779 BKS : {start : 6, len : 1, def : 'a' },
780 SER : {start : 6, len : 1, def : 'a' },
781 VIS : {start : 6, len : 1, def : 'g' },
782 MIX : {start : 6, len : 1, def : 'p' },
783 MAP : {start : 6, len : 1, def : 'e' },
784 SCO : {start : 6, len : 1, def : 'c' },
785 REC : {start : 6, len : 1, def : 'i' },
786 COM : {start : 6, len : 1, def : 'm' }
791 BKS : {start : 8, len : 1, def : ' ' },
792 SER : {start : 8, len : 1, def : ' ' },
793 VIS : {start : 8, len : 1, def : ' ' },
794 MIX : {start : 8, len : 1, def : ' ' },
795 MAP : {start : 8, len : 1, def : ' ' },
796 SCO : {start : 8, len : 1, def : ' ' },
797 REC : {start : 8, len : 1, def : ' ' },
798 COM : {start : 8, len : 1, def : ' ' }
803 BKS : {start : 7, len : 1, def : 'm' },
804 SER : {start : 7, len : 1, def : 's' },
805 VIS : {start : 7, len : 1, def : 'm' },
806 MIX : {start : 7, len : 1, def : 'c' },
807 MAP : {start : 7, len : 1, def : 'm' },
808 SCO : {start : 7, len : 1, def : 'm' },
809 REC : {start : 7, len : 1, def : 'm' },
810 COM : {start : 7, len : 1, def : 'm' }
815 BKS : {start : 18, len : 1, def : ' ' },
816 SER : {start : 18, len : 1, def : ' ' },
817 VIS : {start : 18, len : 1, def : ' ' },
818 MIX : {start : 18, len : 1, def : ' ' },
819 MAP : {start : 18, len : 1, def : ' ' },
820 SCO : {start : 18, len : 1, def : ' ' },
821 REC : {start : 18, len : 1, def : ' ' },
822 COM : {start : 18, len : 1, def : ' ' }
827 BKS : {start : 17, len : 1, def : ' ' },
828 SER : {start : 17, len : 1, def : ' ' },
829 VIS : {start : 17, len : 1, def : ' ' },
830 MIX : {start : 17, len : 1, def : ' ' },
831 MAP : {start : 17, len : 1, def : ' ' },
832 SCO : {start : 17, len : 1, def : ' ' },
833 REC : {start : 17, len : 1, def : ' ' },
834 COM : {start : 17, len : 1, def : ' ' }
839 BKS : {start : 31, len : 1, def : '0' },
840 MAP : {start : 31, len : 1, def : '0' }
843 BKS : {start : 14, len : 1, def : '0' },
844 MAP : {start : 14, len : 1, def : '0' }
849 BKS : {start : 7, len : 4, def : ' ' },
850 SER : {start : 7, len : 4, def : ' ' },
851 VIS : {start : 7, len : 4, def : ' ' },
852 MIX : {start : 7, len : 4, def : ' ' },
853 MAP : {start : 7, len : 4, def : ' ' },
854 SCO : {start : 7, len : 4, def : ' ' },
855 REC : {start : 7, len : 4, def : ' ' },
856 COM : {start : 7, len : 4, def : ' ' }
861 BKS : {start : 11, len : 4, def : ' ' },
862 SER : {start : 11, len : 4, def : '9' },
863 VIS : {start : 11, len : 4, def : ' ' },
864 MIX : {start : 11, len : 4, def : ' ' },
865 MAP : {start : 11, len : 4, def : ' ' },
866 SCO : {start : 11, len : 4, def : ' ' },
867 REC : {start : 11, len : 4, def : ' ' },
868 COM : {start : 11, len : 4, def : ' ' }
873 BKS : {start : 33, len : 1, def : '0' }
876 BKS : {start : 16, len : 1, def : '0' }
881 BKS : {start : 34, len : 1, def : ' ' }
884 BKS : {start : 17, len : 1, def : ' ' }
889 BKS : {start : 18, len : 4, def : ' ' }
892 BKS : {start : 1, len : 4, def : ' ' }
897 BKS : {start : 30, len : 1, def : '0' }
900 BKS : {start : 13, len : 1, def : '0' }
905 BKS : {start : 29, len : 1, def : '0' },
906 SER : {start : 29, len : 1, def : '0' }
909 BKS : {start : 12, len : 1, def : '0' },
910 SER : {start : 12, len : 1, def : '0' }
915 BKS : {start : 24, len : 4, def : ' ' },
916 SER : {start : 25, len : 3, def : ' ' }
919 BKS : {start : 7, len : 4, def : ' ' },
920 SER : {start : 8, len : 3, def : ' ' }
925 BKS : {start : 28, len : 1, def : ' ' },
926 SER : {start : 28, len : 1, def : ' ' },
927 VIS : {start : 28, len : 1, def : ' ' },
928 MAP : {start : 28, len : 1, def : ' ' },
929 COM : {start : 28, len : 1, def : ' ' }
932 BKS : {start : 11, len : 1, def : ' ' },
933 SER : {start : 11, len : 1, def : ' ' },
934 VIS : {start : 11, len : 1, def : ' ' },
935 MAP : {start : 11, len : 1, def : ' ' },
936 COM : {start : 11, len : 1, def : ' ' }
941 BKS : {start : 22, len : 1, def : ' ' },
942 SER : {start : 22, len : 1, def : ' ' },
943 VIS : {start : 22, len : 1, def : ' ' },
944 SCO : {start : 22, len : 1, def : ' ' },
945 REC : {start : 22, len : 1, def : ' ' },
946 COM : {start : 22, len : 1, def : ' ' }
949 BKS : {start : 5, len : 1, def : ' ' },
950 SER : {start : 5, len : 1, def : ' ' },
951 VIS : {start : 5, len : 1, def : ' ' },
952 SCO : {start : 5, len : 1, def : ' ' },
953 REC : {start : 5, len : 1, def : ' ' },
954 COM : {start : 5, len : 1, def : ' ' }
959 BKS : {start : 23, len : 1, def : ' ' },
960 SER : {start : 23, len : 1, def : ' ' },
961 VIS : {start : 29, len : 1, def : ' ' },
962 MIX : {start : 23, len : 1, def : ' ' },
963 MAP : {start : 29, len : 1, def : ' ' },
964 SCO : {start : 23, len : 1, def : ' ' },
965 REC : {start : 23, len : 1, def : ' ' }
968 BKS : {start : 6, len : 1, def : ' ' },
969 SER : {start : 6, len : 1, def : ' ' },
970 VIS : {start : 12, len : 1, def : ' ' },
971 MIX : {start : 6, len : 1, def : ' ' },
972 MAP : {start : 12, len : 1, def : ' ' },
973 SCO : {start : 6, len : 1, def : ' ' },
974 REC : {start : 6, len : 1, def : ' ' }
979 SER : {start : 34, len : 1, def : '0' }
982 SER : {start : 17, len : 1, def : '0' }
987 SER : {start : 33, len : 1, def : ' ' }
990 SER : {start : 16, len : 1, def : ' ' }
995 function recordType (rec) {
997 var _l = rec.leader.toString();
999 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1000 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1002 for (var t in rec_type) {
1003 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1004 document.getElementById('recordTypeLabel').value = t;
1010 alert('FIXME, MARC Editor, recordType: ' + E);
1014 function toggleFFE () {
1015 var grid = document.getElementById('leaderGrid');
1017 grid.hidden = false;
1024 function changeFFEditor (type) {
1025 var grid = document.getElementById('leaderGrid');
1026 grid.setAttribute('type',type);
1029 function fillFixedFields (rec) {
1031 var grid = document.getElementById('leaderGrid');
1033 var rtype = _record_type;
1035 var _l = rec.leader.toString();
1036 var _6 = rec.controlfield.(@tag=='006').toString();
1037 var _7 = rec.controlfield.(@tag=='007').toString();
1038 var _8 = rec.controlfield.(@tag=='008').toString();
1041 var pre_list = grid.getElementsByTagName('label');
1042 for (var i in pre_list) {
1043 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1044 list.push( pre_list[i] );
1048 for (var i in list) {
1049 var name = list[i].getAttribute('name');
1055 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1056 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1058 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1059 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1061 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1062 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1064 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1065 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1070 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1071 d = ff_pos[name].ldr[rtype].def;
1075 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1076 d = ff_pos[name]._8[rtype].def;
1080 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1081 d = ff_pos[name]._6[rtype].def;
1085 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1086 d = ff_pos[name]._7[rtype].def;
1091 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1097 list[i].nextSibling.value = value;
1102 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1106 function updateFixedFields (element) {
1107 var grid = document.getElementById('leaderGrid');
1108 var recGrid = document.getElementById('recGrid');
1110 var rtype = _record_type;
1111 var new_value = element.value;
1114 ldr : _record.leader,
1115 _6 : _record.controlfield.(@tag=='006'),
1116 _7 : _record.controlfield.(@tag=='007'),
1117 _8 : _record.controlfield.(@tag=='008')
1120 var name = element.getAttribute('name');
1121 for (var i in ff_pos[name]) {
1123 if (!ff_pos[name][i][rtype]) continue;
1124 if (!parts[i]) continue;
1126 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1127 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1129 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1130 new_value += ff_pos[name][i][rtype].def;
1133 parts[i].setChildren( before + new_value + after );
1134 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1140 function marcLeader (leader) {
1141 var row = createRow(
1142 { class : 'marcLeaderRow',
1147 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1150 class : 'marcInd1' } ),
1153 class : 'marcInd2' } ),
1155 { value : leader.text(),
1156 class : 'marcLeader' } )
1162 function marcControlfield (field) {
1163 tagname = field.@tag.toString().substr(2);
1165 if (tagname == '6' || tagname == '7' || tagname == '8') {
1167 { class : 'marcControlfieldRow',
1168 tag : '_' + tagname },
1170 { value : field.@tag,
1172 context : 'tags_popup',
1173 onmouseover : 'getTooltip(this, "tag");',
1174 tooltipid : 'tag' + field.@tag } ),
1176 { value : field.@ind1,
1178 onmouseover : 'getTooltip(this, "ind1");',
1179 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1181 { value : field.@ind2,
1183 onmouseover : 'getTooltip(this, "ind2");',
1184 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1187 { value : field.text(),
1188 class : 'plain marcEditableControlfield',
1189 name : 'CONTROL' + tagname,
1190 oncontext : 'return false();',
1196 { class : 'marcControlfieldRow',
1197 tag : '_' + tagname },
1199 { value : field.@tag,
1201 onmouseover : 'getTooltip(this, "tag");',
1202 tooltipid : 'tag' + field.@tag } ),
1204 { value : field.@ind1,
1206 onmouseover : 'getTooltip(this, "ind1");',
1207 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1209 { value : field.@ind2,
1211 onmouseover : 'getTooltip(this, "ind2");',
1212 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1214 { value : field.text(),
1215 class : 'marcControlfield' } )
1222 function stackSubfields(checkbox) {
1223 var list = document.getElementsByAttribute('name','sf_box');
1226 if (checkbox.checked) o = 'horizontal';
1228 for (var i = 0; i < list.length; i++) {
1229 if (list[i]) list[i].setAttribute('orient',o);
1233 function marcDatafield (field) {
1234 var row = createRow(
1235 { class : 'marcDatafieldRow' },
1238 { value : field.@tag,
1239 class : 'plain marcTag',
1241 context : 'tags_popup',
1242 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1245 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1248 { value : field.@ind1,
1249 class : 'plain marcInd1',
1251 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1254 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1255 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1258 { value : field.@ind2,
1259 class : 'plain marcInd2',
1261 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1264 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1265 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1266 createHbox({ name : 'sf_box' })
1269 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1270 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1271 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1273 var sf_box = row.lastChild;
1274 if (document.getElementById('stackSubfields').checked)
1275 sf_box.setAttribute('orient','vertical');
1277 sf_box.addEventListener(
1280 if (sf_box === e.target) {
1281 sf_box.lastChild.lastChild.focus();
1282 } else if (e.target.parentNode === sf_box) {
1283 e.target.lastChild.focus();
1290 for (var i in field.subfield) {
1291 var sf = field.subfield[i];
1296 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1297 current_focus = sf_box.lastChild.childNodes[1];
1303 function marcSubfield (sf) {
1305 { class : 'marcSubfieldBox' },
1308 class : 'plain marcSubfieldDelimiter',
1309 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1310 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1311 //onclick : 'this.nextSibling.focus();',
1312 onfocus : 'this.nextSibling.focus();',
1317 class : 'plain marcSubfieldCode',
1318 name : 'marcSubfieldCode',
1319 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1320 oncontextmenu : 'getContextMenu(this, "subfield");',
1321 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1326 { value : sf.text(),
1327 name : sf.parent().@tag + ':' + sf.@code,
1328 class : 'plain marcSubfield',
1329 onmouseover : 'getTooltip(this, "subfield");',
1330 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1331 size : new String(sf.text()).length + 2,
1332 oninput : "this.setAttribute('size', this.value.length + 2);"
1337 function loadRecord(rec) {
1340 var grid_rows = document.getElementById('recGrid').lastChild;
1342 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1344 grid_rows.appendChild( marcLeader( rec.leader ) );
1346 for (var i in rec.controlfield) {
1347 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1350 for (var i in rec.datafield) {
1351 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1354 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1355 changeFFEditor(recordType(rec));
1356 fillFixedFields(rec);
1358 alert('FIXME, MARC Editor, loadRecord: ' + E);
1363 function genToolTips () {
1364 for (var i in bib_data.field) {
1365 var f = bib_data.field[i];
1367 tag_menu.appendChild(
1371 'current_focus.value = "' + f.@tag + '";' +
1372 'var e = document.createEvent("MutationEvents");' +
1373 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1374 'current_focus.inputField.dispatchEvent(e);',
1375 disabled : f.@tag < '010' ? "true" : "false",
1376 tooltiptext : f.description }
1380 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1381 context_menus.appendChild( i1_popup );
1383 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1384 context_menus.appendChild( i2_popup );
1386 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1387 context_menus.appendChild( sf_popup );
1389 tooltip_hash['tag' + f.@tag] = f.description;
1390 for (var j in f.indicator) {
1391 var ind = f.indicator[j];
1392 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1394 if (ind.@position == 1) {
1395 i1_popup.appendChild(
1397 { label : ind.@value,
1399 'current_focus.value = "' + ind.@value + '";' +
1400 'var e = document.createEvent("MutationEvents");' +
1401 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1402 'current_focus.inputField.dispatchEvent(e);',
1403 tooltiptext : ind.description }
1408 if (ind.@position == 2) {
1409 i2_popup.appendChild(
1411 { label : ind.@value,
1413 'current_focus.value = "' + ind.@value + '";' +
1414 'var e = document.createEvent("MutationEvents");' +
1415 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1416 'current_focus.inputField.dispatchEvent(e);',
1417 tooltiptext : ind.description }
1423 for (var j in f.subfield) {
1424 var sf = f.subfield[j];
1425 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1427 sf_popup.appendChild(
1431 'current_focus.value = "' + sf.@code + '";' +
1432 'var e = document.createEvent("MutationEvents");' +
1433 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1434 'current_focus.inputField.dispatchEvent(e);',
1435 tooltiptext : sf.description
1443 function getTooltip (target, type) {
1446 if (type == 'subfield')
1447 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1450 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1453 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1456 tt = 'tag' + target.parentNode.firstChild.value;
1458 if (!document.getElementById( tt )) {
1463 orient : 'vertical',
1464 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1465 class : 'tooltip' },
1466 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1471 target.tooltip = tt;
1475 function getContextMenu (target, type) {
1478 if (type == 'subfield')
1479 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1482 tt = 't' + target.parentNode.firstChild.value + 'i1';
1485 tt = 't' + target.parentNode.firstChild.value + 'i2';
1487 target.setAttribute('context', tt);
1491 var authority_tag_map = {
1492 100 : ['[100,400,500,700]',100],
1493 400 : ['[100,400,500,700]',100],
1494 700 : ['[100,400,500,700]',100],
1495 800 : ['[100,400,500,700]',100],
1496 110 : ['[110,410,510,710]',110],
1497 410 : ['[110,410,510,710]',110],
1498 710 : ['[110,410,510,710]',110],
1499 810 : ['[110,410,510,710]',110],
1500 111 : ['[111,411,511,711]',111],
1501 411 : ['[111,411,511,711]',111],
1502 711 : ['[111,411,511,711]',111],
1503 811 : ['[111,411,511,711]',111],
1504 240 : ['[130,430,530,730]',130],
1505 440 : ['[130,430,530,730]',130],
1506 130 : ['[130,430,530,730]',130],
1507 730 : ['[130,430,530,730]',130],
1508 830 : ['[130,430,530,730]',130],
1509 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1510 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1511 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1512 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1515 function getAuthorityContextMenu (target, sf) {
1516 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1518 var old = document.getElementById( menu_id );
1519 if (old) old.parentNode.removeChild(old);
1521 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1522 context_menus.appendChild( sf_popup );
1524 if (!authority_tag_map[sf.parent().@tag]) {
1525 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1526 target.setAttribute('context', menu_id);
1530 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1532 var res = new XML( auth_data.responseText );
1536 var recs = res.gw::payload.gw::array.gw::string;
1537 for (var i in recs) {
1539 var xml = new XML(x.toString());
1540 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1542 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1545 for (var i in main) {
1546 if (main_text) main_text += ' / ';
1547 main_text += main[i];
1550 rec_list.push( [ main_text, xml ] );
1553 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1555 var main_text = rec_list[i][0];
1556 var xml = rec_list[i][1];
1557 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1559 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1561 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1562 grid.setAttribute('name','-none-');
1563 grid.setAttribute('style','overflow:scroll');
1566 var submenu = createMenu( { label : main_text } );
1568 var popup = createMenuPopup({ flex : "1" });
1569 submenu.appendChild(popup);
1571 var fields = xml.datafield;
1572 for (var j in fields) {
1574 var row = createRow(
1576 createLabel( { value : fields[j].@tag } ),
1577 createLabel( { value : fields[j].@ind1 } ),
1578 createLabel( { value : fields[j].@ind2 } )
1581 var sf_box = createHbox();
1583 var subfields = fields[j].subfield;
1584 for (var k in subfields) {
1587 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1588 subfield : subfields[k].@code,
1589 tag : subfields[k].parent().@tag,
1590 value : subfields[k]
1594 row.appendChild(sf_box);
1597 grid.lastChild.appendChild(row);
1600 grid.hidden = false;
1601 popup.appendChild( grid );
1605 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1606 command : function (event) {
1607 applyAuthority(event.target.previousSibling, target, sf);
1614 sf_popup.appendChild( submenu );
1617 if (sf_popup.childNodes.length == 0)
1618 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1620 target.setAttribute('context', menu_id);
1624 function applyAuthority ( target, ui_sf, e4x_sf ) {
1626 var new_vals = target.getElementsByAttribute('checked','true');
1627 var field = e4x_sf.parent();
1629 for (var i = 0; i < new_vals.length; i++) {
1631 var sf_list = field.subfield;
1632 for (var j in sf_list) {
1634 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1635 sf_list[j] = new_vals[i].getAttribute('value');
1636 new_vals[i].setAttribute('subfield','');
1642 for (var i = 0; i < new_vals.length; i++) {
1643 if (!new_vals[i].getAttribute('subfield')) continue;
1645 var val = new_vals[i].getAttribute('value');
1647 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1648 sf.@code = new_vals[i].getAttribute('subfield');
1650 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1653 var row = marcDatafield( field );
1656 while (node.nodeName != 'row') {
1657 node = node.parentNode;
1660 node.parentNode.replaceChild( row, node );
1666 'a' : { 100 : 'a' },
1670 'a' : { 110 : 'a' },
1674 'a' : { 111 : 'a' },
1678 'a' : { 130 : 'a' },
1682 'a' : { 130 : 'a' },
1686 'a' : { 100 : 'a' },
1690 'a' : { 110 : 'a' },
1694 'a' : { 111 : 'a' },
1698 'a' : { 130 : 'a' },
1699 'n' : { 130 : 'n' },
1703 'a' : { 100 : 'a' },
1707 'a' : { 110 : 'a' },
1711 'a' : { 111 : 'a' },
1715 'a' : { 130 : 'a' },
1719 'a' : { 100 : 'a' },
1723 'a' : { 110 : 'a' },
1727 'a' : { 111 : 'a' },
1731 'a' : { 130 : 'a' },
1735 'a' : { 100 : 'a' },
1736 'd' : { 100 : 'd' },
1737 't' : { 100 : 't' },
1764 'a' : { 110 : 'a' },
1765 'd' : { 110 : 'd' },
1766 't' : { 110 : 't' },
1793 'a' : { 111 : 'a' },
1794 'd' : { 111 : 'd' },
1795 't' : { 111 : 't' },
1822 'a' : { 130 : 'a' },
1826 'a' : { 150 : 'a' },
1827 'b' : { 150 : 'b' },
1854 'a' : { 151 : 'a' },
1881 'a' : { 155 : 'a' },
1909 function validateAuthority (button) {
1910 var grid = document.getElementById('recGrid');
1911 var label = button.getAttribute('label');
1914 var rows = grid.lastChild.childNodes;
1915 for (var i = 0; i < rows.length; i++) {
1917 var tag = row.firstChild;
1919 if (!control_map[tag.value]) continue
1920 button.setAttribute('label', label + ' - ' + tag.value);
1922 var ind1 = tag.nextSibling;
1923 var ind2 = ind1.nextSibling;
1924 var subfields = ind2.nextSibling.childNodes;
1928 for (var j = 0; j < subfields.length; j++) {
1929 var sf = subfields[j];
1930 var sf_code = sf.childNodes[1].value;
1931 var sf_value = sf.childNodes[2].value;
1933 if (!control_map[tag.value][sf_code]) continue;
1936 for (var a_tag in control_map[tag.value][sf_code]) {
1937 if (!tags[a_tag]) tags[a_tag] = [];
1938 tags[a_tag].push({ term : sf_value, subfield : sf_code });
1943 for (var val_tag in tags) {
1944 var auth_data = validateBibField( [val_tag], tags[val_tag]);
1945 var res = new XML( auth_data.responseText );
1946 found = parseInt(res.gw::payload.gw::string.toString());
1950 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1951 for (var j = 0; j < subfields.length; j++) {
1952 var sf = subfields[j];
1954 sf.childNodes[2].inputField.style.color = 'red';
1956 sf.childNodes[2].inputField.style.color = 'black';
1961 button.setAttribute('label', label);
1967 function validateBibField (tags, searches) {
1968 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1969 url += '¶m="tags"¶m=' + js2JSON(tags);
1970 url += '¶m="searches"¶m=' + js2JSON(searches);
1973 var req = new XMLHttpRequest();
1974 req.open('GET',url,false);
1980 function searchAuthority (term, tag, sf, limit) {
1981 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1982 url += '¶m="term"¶m="' + term + '"';
1983 url += '¶m="limit"¶m=' + limit;
1984 url += '¶m="tag"¶m=' + tag;
1985 url += '¶m="subfield"¶m="' + sf + '"';
1988 var req = new XMLHttpRequest();
1989 req.open('GET',url,false);