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 'window.xulG.save.func( 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);
246 alert('FIXME, MARC Editor, my_init: ' + E);
251 function createComplexHTMLElement (e, attrs, objects, text) {
252 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
255 for (var i in attrs) l.setAttribute(i,attrs[i]);
259 for ( var i in objects ) l.appendChild( objects[i] );
263 l.appendChild( document.createTextNode(text) )
269 function createComplexXULElement (e, attrs, objects) {
270 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
273 for (var i in attrs) {
274 if (typeof attrs[i] == 'function') {
275 l.addEventListener( i, attrs[i], true );
277 l.setAttribute(i,attrs[i]);
283 for ( var i in objects ) l.appendChild( objects[i] );
289 function createDescription (attrs) {
290 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
293 function createTooltip (attrs) {
294 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
297 function createLabel (attrs) {
298 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
301 function createVbox (attrs) {
302 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
305 function createHbox (attrs) {
306 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
309 function createRow (attrs) {
310 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
313 function createTextbox (attrs) {
314 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
317 function createMenu (attrs) {
318 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
321 function createMenuPopup (attrs) {
322 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
325 function createPopup (attrs) {
326 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
329 function createMenuitem (attrs) {
330 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
333 function createCheckbox (attrs) {
334 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
337 function createMARCTextbox (element,attrs) {
339 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
340 box.onkeypress = function (event) {
343 while(node = node.parent()) {
347 var row = event.target;
348 while (row.tagName != 'row') row = row.parentNode;
350 if (element.nodeKind() == 'attribute') element[0]=box.value;
351 else element.setChildren( box.value );
353 if (element.localName() != 'controlfield') {
354 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
356 var index_sf, target, move_data;
357 if (element.localName() == 'subfield') {
359 target = event.target.parentNode;
361 var start = event.target.selectionStart;
362 var end = event.target.selectionEnd - event.target.selectionStart ?
363 event.target.selectionEnd :
364 event.target.value.length;
366 move_data = event.target.value.substring(start,end);
367 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
368 event.target.setAttribute('size', event.target.value.length + 2);
370 element.setChildren( event.target.value );
372 } else if (element.localName() == 'code') {
373 index_sf = element.parent();
374 target = event.target.parentNode;
375 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
376 index_sf = element.parent().children()[element.parent().children().length() - 1];
377 target = event.target.parentNode.lastChild.lastChild;
380 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
382 index_sf.parent().insertChildAfter( index_sf, sf );
384 var new_sf = marcSubfield(sf);
386 if (target === target.parentNode.lastChild) {
387 target.parentNode.appendChild( new_sf );
389 target.parentNode.insertBefore( new_sf, target.nextSibling );
392 new_sf.firstChild.nextSibling.focus();
394 event.preventDefault();
397 } else if (event.keyCode == 13 || event.keyCode == 77) {
398 if (event.ctrlKey) { // ctrl+enter
401 if (element.localName() == 'subfield') index = element.parent();
402 if (element.localName() == 'code') index = element.parent().parent();
403 if (element.localName() == 'tag') index = element.parent();
404 if (element.localName() == 'ind1') index = element.parent();
405 if (element.localName() == 'ind2') index = element.parent();
407 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
409 if (event.shiftKey) { // ctrl+shift+enter
410 index.parent().insertChildBefore( index, df );
412 index.parent().insertChildAfter( index, df );
415 var new_df = marcDatafield(df);
417 if (row.parentNode.lastChild === row) {
418 row.parentNode.appendChild( new_df );
420 if (event.shiftKey) { // ctrl+shift+enter
421 row.parentNode.insertBefore( new_df, row );
423 row.parentNode.insertBefore( new_df, row.nextSibling );
427 new_df.firstChild.focus();
429 event.preventDefault();
432 } else if (event.shiftKey) {
433 if (row.previousSibling.className.match('marcDatafieldRow'))
434 row.previousSibling.firstChild.focus();
436 row.nextSibling.firstChild.focus();
439 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
442 if (element.localName() == 'subfield') index = element.parent();
443 if (element.localName() == 'code') index = element.parent().parent();
444 if (element.localName() == 'tag') index = element.parent();
445 if (element.localName() == 'ind1') index = element.parent();
446 if (element.localName() == 'ind2') index = element.parent();
448 for (var i in index.parent().children()) {
449 if (index === index.parent().children()[i]) {
450 delete index.parent().children()[i];
455 row.previousSibling.firstChild.focus();
456 row.parentNode.removeChild(row);
458 event.preventDefault();
461 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
464 if (element.localName() == 'subfield') index = element;
465 if (element.localName() == 'code') index = element.parent();
468 for (var i in index.parent().children()) {
469 if (index === index.parent().children()[i]) {
470 delete index.parent().children()[i];
475 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
476 event.target.parentNode.previousSibling.lastChild.focus();
478 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
481 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
483 event.preventDefault();
486 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
487 createControlField('006','');
488 loadRecord(xml_record);
489 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
490 createControlField('007','');
491 loadRecord(xml_record);
492 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
493 createControlField('008','');
494 loadRecord(xml_record);
500 box.addEventListener(
503 if (element.nodeKind() == 'attribute') element[0]=box.value;
504 else element.setChildren( box.value );
510 box.addEventListener(
513 if (element.nodeKind() == 'attribute') element[0]=box.value;
514 else element.setChildren( box.value );
520 box.addEventListener(
523 if (element.nodeKind() == 'attribute') element[0]=box.value;
524 else element.setChildren( box.value );
530 box.addEventListener(
533 if (element.localName() == 'controlfield')
534 eval('fillFixedFields(xml_record);');
543 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
544 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
545 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
546 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
547 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
548 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
549 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
550 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
556 SCO : {start : 33, len : 1, def : ' ' },
557 REC : {start : 33, len : 1, def : 'n' }
560 SCO : {start : 16, len : 1, def : ' ' },
561 REC : {start : 16, len : 1, def : 'n' }
566 VIS : {start : 33, len : 1, def : ' ' }
569 VIS : {start : 16, len : 1, def : ' ' }
574 VIS : {start : 18, len : 3, def : ' ' }
577 VIS : {start : 1, len : 3, def : ' ' }
582 VIS : {start : 34, len : 1, def : 'n' }
585 VIS : {start : 17, len : 1, def : 'n' }
590 SER : {start : 21, len : 1, def : ' ' }
593 SER : {start : 4, len : 1, def : ' ' }
598 BKS : {start : 39, len : 1, def : 'd' },
599 SER : {start : 39, len : 1, def : 'd' },
600 VIS : {start : 39, len : 1, def : 'd' },
601 MIX : {start : 39, len : 1, def : 'd' },
602 MAP : {start : 39, len : 1, def : 'd' },
603 SCO : {start : 39, len : 1, def : 'd' },
604 REC : {start : 39, len : 1, def : 'd' },
605 COM : {start : 39, len : 1, def : 'd' }
610 MAP : {start : 33, len : 2, def : ' ' }
613 MAP : {start : 16, len : 2, def : ' ' }
618 MAP : {start : 18, len : 4, def : ' ' }
621 MAP : {start : 1, len : 4, def : ' ' }
626 SER : {start : 19, len : 1, def : ' ' }
629 SER : {start : 2, len : 1, def : ' ' }
634 MAP : {start : 22, len : 2, def : ' ' }
637 MAP : {start : 5, len : 2, def : ' ' }
642 SCO : {start : 21, len : 1, def : ' ' },
643 REC : {start : 21, len : 1, def : 'n' }
646 SCO : {start : 4, len : 1, def : ' ' },
647 REC : {start : 4, len : 1, def : 'n' }
652 SER : {start : 22, len : 1, def : ' ' }
655 SER : {start : 5, len : 1, def : ' ' }
660 SCO : {start : 30, len : 2, def : ' ' },
661 REC : {start : 30, len : 2, def : ' ' }
664 SCO : {start : 13, len : 2, def : ' ' },
665 REC : {start : 13, len : 2, def : ' ' }
670 SER : {start : 18, len : 1, def : ' ' }
673 SER : {start : 1, len : 1, def : ' ' }
678 SCO : {start : 20, len : 1, def : ' ' },
679 REC : {start : 20, len : 1, def : 'n' }
682 SCO : {start : 3, len : 1, def : ' ' },
683 REC : {start : 3, len : 1, def : 'n' }
688 COM : {start : 26, len : 1, def : 'u' }
691 COM : {start : 9, len : 1, def : 'u' }
696 SER : {start : 24, len : 1, def : ' ' }
699 SER : {start : 7, len : 1, def : ' ' }
704 SCO : {start : 24, len : 6, def : ' ' },
705 REC : {start : 24, len : 6, def : ' ' }
708 SCO : {start : 7, len : 6, def : ' ' },
709 REC : {start : 7, len : 6, def : ' ' }
714 SCO : {start : 18, len : 2, def : ' ' },
715 REC : {start : 18, len : 2, def : ' ' }
718 SCO : {start : 1, len : 2, def : ' ' },
719 REC : {start : 1, len : 2, def : ' ' }
724 MAP : {start : 25, len : 1, def : ' ' }
727 MAP : {start : 8, len : 1, def : ' ' }
732 BKS : {start : 15, len : 3, def : ' ' },
733 SER : {start : 15, len : 3, def : ' ' },
734 VIS : {start : 15, len : 3, def : ' ' },
735 MIX : {start : 15, len : 3, def : ' ' },
736 MAP : {start : 15, len : 3, def : ' ' },
737 SCO : {start : 15, len : 3, def : ' ' },
738 REC : {start : 15, len : 3, def : ' ' },
739 COM : {start : 15, len : 3, def : ' ' }
744 BKS : {start : 35, len : 3, def : ' ' },
745 SER : {start : 35, len : 3, def : ' ' },
746 VIS : {start : 35, len : 3, def : ' ' },
747 MIX : {start : 35, len : 3, def : ' ' },
748 MAP : {start : 35, len : 3, def : ' ' },
749 SCO : {start : 35, len : 3, def : ' ' },
750 REC : {start : 35, len : 3, def : ' ' },
751 COM : {start : 35, len : 3, def : ' ' }
756 BKS : {start : 38, len : 1, def : ' ' },
757 SER : {start : 38, len : 1, def : ' ' },
758 VIS : {start : 38, len : 1, def : ' ' },
759 MIX : {start : 38, len : 1, def : ' ' },
760 MAP : {start : 38, len : 1, def : ' ' },
761 SCO : {start : 38, len : 1, def : ' ' },
762 REC : {start : 38, len : 1, def : ' ' },
763 COM : {start : 38, len : 1, def : ' ' }
768 BKS : {start : 6, len : 1, def : ' ' },
769 SER : {start : 6, len : 1, def : 'c' },
770 VIS : {start : 6, len : 1, def : ' ' },
771 MIX : {start : 6, len : 1, def : ' ' },
772 MAP : {start : 6, len : 1, def : ' ' },
773 SCO : {start : 6, len : 1, def : ' ' },
774 REC : {start : 6, len : 1, def : ' ' },
775 COM : {start : 6, len : 1, def : ' ' }
780 BKS : {start : 6, len : 1, def : 'a' },
781 SER : {start : 6, len : 1, def : 'a' },
782 VIS : {start : 6, len : 1, def : 'g' },
783 MIX : {start : 6, len : 1, def : 'p' },
784 MAP : {start : 6, len : 1, def : 'e' },
785 SCO : {start : 6, len : 1, def : 'c' },
786 REC : {start : 6, len : 1, def : 'i' },
787 COM : {start : 6, len : 1, def : 'm' }
792 BKS : {start : 8, len : 1, def : ' ' },
793 SER : {start : 8, len : 1, def : ' ' },
794 VIS : {start : 8, len : 1, def : ' ' },
795 MIX : {start : 8, len : 1, def : ' ' },
796 MAP : {start : 8, len : 1, def : ' ' },
797 SCO : {start : 8, len : 1, def : ' ' },
798 REC : {start : 8, len : 1, def : ' ' },
799 COM : {start : 8, len : 1, def : ' ' }
804 BKS : {start : 7, len : 1, def : 'm' },
805 SER : {start : 7, len : 1, def : 's' },
806 VIS : {start : 7, len : 1, def : 'm' },
807 MIX : {start : 7, len : 1, def : 'c' },
808 MAP : {start : 7, len : 1, def : 'm' },
809 SCO : {start : 7, len : 1, def : 'm' },
810 REC : {start : 7, len : 1, def : 'm' },
811 COM : {start : 7, len : 1, def : 'm' }
816 BKS : {start : 18, len : 1, def : ' ' },
817 SER : {start : 18, len : 1, def : ' ' },
818 VIS : {start : 18, len : 1, def : ' ' },
819 MIX : {start : 18, len : 1, def : ' ' },
820 MAP : {start : 18, len : 1, def : ' ' },
821 SCO : {start : 18, len : 1, def : ' ' },
822 REC : {start : 18, len : 1, def : ' ' },
823 COM : {start : 18, len : 1, def : ' ' }
828 BKS : {start : 17, len : 1, def : ' ' },
829 SER : {start : 17, len : 1, def : ' ' },
830 VIS : {start : 17, len : 1, def : ' ' },
831 MIX : {start : 17, len : 1, def : ' ' },
832 MAP : {start : 17, len : 1, def : ' ' },
833 SCO : {start : 17, len : 1, def : ' ' },
834 REC : {start : 17, len : 1, def : ' ' },
835 COM : {start : 17, len : 1, def : ' ' }
840 BKS : {start : 31, len : 1, def : '0' },
841 MAP : {start : 31, len : 1, def : '0' }
844 BKS : {start : 14, len : 1, def : '0' },
845 MAP : {start : 14, len : 1, def : '0' }
850 BKS : {start : 7, len : 4, def : ' ' },
851 SER : {start : 7, len : 4, def : ' ' },
852 VIS : {start : 7, len : 4, def : ' ' },
853 MIX : {start : 7, len : 4, def : ' ' },
854 MAP : {start : 7, len : 4, def : ' ' },
855 SCO : {start : 7, len : 4, def : ' ' },
856 REC : {start : 7, len : 4, def : ' ' },
857 COM : {start : 7, len : 4, def : ' ' }
862 BKS : {start : 11, len : 4, def : ' ' },
863 SER : {start : 11, len : 4, def : '9' },
864 VIS : {start : 11, len : 4, def : ' ' },
865 MIX : {start : 11, len : 4, def : ' ' },
866 MAP : {start : 11, len : 4, def : ' ' },
867 SCO : {start : 11, len : 4, def : ' ' },
868 REC : {start : 11, len : 4, def : ' ' },
869 COM : {start : 11, len : 4, def : ' ' }
874 BKS : {start : 33, len : 1, def : '0' }
877 BKS : {start : 16, len : 1, def : '0' }
882 BKS : {start : 34, len : 1, def : ' ' }
885 BKS : {start : 17, len : 1, def : ' ' }
890 BKS : {start : 18, len : 4, def : ' ' }
893 BKS : {start : 1, len : 4, def : ' ' }
898 BKS : {start : 30, len : 1, def : '0' }
901 BKS : {start : 13, len : 1, def : '0' }
906 BKS : {start : 29, len : 1, def : '0' },
907 SER : {start : 29, len : 1, def : '0' }
910 BKS : {start : 12, len : 1, def : '0' },
911 SER : {start : 12, len : 1, def : '0' }
916 BKS : {start : 24, len : 4, def : ' ' },
917 SER : {start : 25, len : 3, def : ' ' }
920 BKS : {start : 7, len : 4, def : ' ' },
921 SER : {start : 8, len : 3, def : ' ' }
926 BKS : {start : 28, len : 1, def : ' ' },
927 SER : {start : 28, len : 1, def : ' ' },
928 VIS : {start : 28, len : 1, def : ' ' },
929 MAP : {start : 28, len : 1, def : ' ' },
930 COM : {start : 28, len : 1, def : ' ' }
933 BKS : {start : 11, len : 1, def : ' ' },
934 SER : {start : 11, len : 1, def : ' ' },
935 VIS : {start : 11, len : 1, def : ' ' },
936 MAP : {start : 11, len : 1, def : ' ' },
937 COM : {start : 11, len : 1, def : ' ' }
942 BKS : {start : 22, len : 1, def : ' ' },
943 SER : {start : 22, len : 1, def : ' ' },
944 VIS : {start : 22, len : 1, def : ' ' },
945 SCO : {start : 22, len : 1, def : ' ' },
946 REC : {start : 22, len : 1, def : ' ' },
947 COM : {start : 22, len : 1, def : ' ' }
950 BKS : {start : 5, len : 1, def : ' ' },
951 SER : {start : 5, len : 1, def : ' ' },
952 VIS : {start : 5, len : 1, def : ' ' },
953 SCO : {start : 5, len : 1, def : ' ' },
954 REC : {start : 5, len : 1, def : ' ' },
955 COM : {start : 5, len : 1, def : ' ' }
960 BKS : {start : 23, len : 1, def : ' ' },
961 SER : {start : 23, len : 1, def : ' ' },
962 VIS : {start : 29, len : 1, def : ' ' },
963 MIX : {start : 23, len : 1, def : ' ' },
964 MAP : {start : 29, len : 1, def : ' ' },
965 SCO : {start : 23, len : 1, def : ' ' },
966 REC : {start : 23, len : 1, def : ' ' }
969 BKS : {start : 6, len : 1, def : ' ' },
970 SER : {start : 6, len : 1, def : ' ' },
971 VIS : {start : 12, len : 1, def : ' ' },
972 MIX : {start : 6, len : 1, def : ' ' },
973 MAP : {start : 12, len : 1, def : ' ' },
974 SCO : {start : 6, len : 1, def : ' ' },
975 REC : {start : 6, len : 1, def : ' ' }
980 SER : {start : 34, len : 1, def : '0' }
983 SER : {start : 17, len : 1, def : '0' }
988 SER : {start : 33, len : 1, def : ' ' }
991 SER : {start : 16, len : 1, def : ' ' }
996 function recordType (rec) {
998 var _l = rec.leader.toString();
1000 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1001 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1003 for (var t in rec_type) {
1004 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1005 document.getElementById('recordTypeLabel').value = t;
1011 // in case we don't have a valid record type ...
1012 _record_type = 'BKS';
1013 return _record_type;
1016 alert('FIXME, MARC Editor, recordType: ' + E);
1020 function toggleFFE () {
1021 var grid = document.getElementById('leaderGrid');
1023 grid.hidden = false;
1030 function changeFFEditor (type) {
1031 var grid = document.getElementById('leaderGrid');
1032 grid.setAttribute('type',type);
1035 function fillFixedFields (rec) {
1037 var grid = document.getElementById('leaderGrid');
1039 var rtype = _record_type;
1041 var _l = rec.leader.toString();
1042 var _6 = rec.controlfield.(@tag=='006').toString();
1043 var _7 = rec.controlfield.(@tag=='007').toString();
1044 var _8 = rec.controlfield.(@tag=='008').toString();
1047 var pre_list = grid.getElementsByTagName('label');
1048 for (var i in pre_list) {
1049 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1050 list.push( pre_list[i] );
1054 for (var i in list) {
1055 var name = list[i].getAttribute('name');
1061 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1062 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1064 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1065 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1067 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1068 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1070 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1071 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1076 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1077 d = ff_pos[name].ldr[rtype].def;
1081 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1082 d = ff_pos[name]._8[rtype].def;
1086 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1087 d = ff_pos[name]._6[rtype].def;
1091 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1092 d = ff_pos[name]._7[rtype].def;
1097 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1103 list[i].nextSibling.value = value;
1108 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1112 function updateFixedFields (element) {
1113 var grid = document.getElementById('leaderGrid');
1114 var recGrid = document.getElementById('recGrid');
1116 var rtype = _record_type;
1117 var new_value = element.value;
1120 ldr : _record.leader,
1121 _6 : _record.controlfield.(@tag=='006'),
1122 _7 : _record.controlfield.(@tag=='007'),
1123 _8 : _record.controlfield.(@tag=='008')
1126 var name = element.getAttribute('name');
1127 for (var i in ff_pos[name]) {
1129 if (!ff_pos[name][i][rtype]) continue;
1130 if (!parts[i]) continue;
1132 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1133 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1135 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1136 new_value += ff_pos[name][i][rtype].def;
1139 parts[i].setChildren( before + new_value + after );
1140 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1146 function marcLeader (leader) {
1147 var row = createRow(
1148 { class : 'marcLeaderRow',
1153 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1156 class : 'marcInd1' } ),
1159 class : 'marcInd2' } ),
1161 { value : leader.text(),
1162 class : 'marcLeader' } )
1168 function marcControlfield (field) {
1169 tagname = field.@tag.toString().substr(2);
1171 if (tagname == '6' || tagname == '7' || tagname == '8') {
1173 { class : 'marcControlfieldRow',
1174 tag : '_' + tagname },
1176 { value : field.@tag,
1178 context : 'tags_popup',
1179 onmouseover : 'getTooltip(this, "tag");',
1180 tooltipid : 'tag' + field.@tag } ),
1182 { value : field.@ind1,
1184 onmouseover : 'getTooltip(this, "ind1");',
1185 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1187 { value : field.@ind2,
1189 onmouseover : 'getTooltip(this, "ind2");',
1190 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1193 { value : field.text(),
1194 class : 'plain marcEditableControlfield',
1195 name : 'CONTROL' + tagname,
1196 oncontext : 'return false();',
1202 { class : 'marcControlfieldRow',
1203 tag : '_' + tagname },
1205 { value : field.@tag,
1207 onmouseover : 'getTooltip(this, "tag");',
1208 tooltipid : 'tag' + field.@tag } ),
1210 { value : field.@ind1,
1212 onmouseover : 'getTooltip(this, "ind1");',
1213 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1215 { value : field.@ind2,
1217 onmouseover : 'getTooltip(this, "ind2");',
1218 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1220 { value : field.text(),
1221 class : 'marcControlfield' } )
1228 function stackSubfields(checkbox) {
1229 var list = document.getElementsByAttribute('name','sf_box');
1232 if (!checkbox.checked /* this property gets changed after the oncommand handler, so we're testing for the opposite value */) o = 'horizontal';
1234 for (var i = 0; i < list.length; i++) {
1235 if (list[i]) list[i].setAttribute('orient',o);
1239 function marcDatafield (field) {
1240 var row = createRow(
1241 { class : 'marcDatafieldRow' },
1244 { value : field.@tag,
1245 class : 'plain marcTag',
1247 context : 'tags_popup',
1248 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1251 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1254 { value : field.@ind1,
1255 class : 'plain marcInd1',
1257 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1260 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1261 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1264 { value : field.@ind2,
1265 class : 'plain marcInd2',
1267 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1270 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1271 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1272 createHbox({ name : 'sf_box' })
1275 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1276 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1277 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1279 var sf_box = row.lastChild;
1280 if (document.getElementById('stackSubfields').checked)
1281 sf_box.setAttribute('orient','vertical');
1283 sf_box.addEventListener(
1286 if (sf_box === e.target) {
1287 sf_box.lastChild.lastChild.focus();
1288 } else if (e.target.parentNode === sf_box) {
1289 e.target.lastChild.focus();
1296 for (var i in field.subfield) {
1297 var sf = field.subfield[i];
1302 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1303 current_focus = sf_box.lastChild.childNodes[1];
1309 function marcSubfield (sf) {
1311 { class : 'marcSubfieldBox' },
1314 class : 'plain marcSubfieldDelimiter',
1315 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1316 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1317 //onclick : 'this.nextSibling.focus();',
1318 onfocus : 'this.nextSibling.focus();',
1323 class : 'plain marcSubfieldCode',
1324 name : 'marcSubfieldCode',
1325 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1326 oncontextmenu : 'getContextMenu(this, "subfield");',
1327 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1332 { value : sf.text(),
1333 name : sf.parent().@tag + ':' + sf.@code,
1334 class : 'plain marcSubfield',
1335 onmouseover : 'getTooltip(this, "subfield");',
1336 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1337 size : new String(sf.text()).length + 2,
1338 oninput : "this.setAttribute('size', this.value.length + 2);"
1343 function loadRecord(rec) {
1346 var grid_rows = document.getElementById('recGrid').lastChild;
1348 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1350 grid_rows.appendChild( marcLeader( rec.leader ) );
1352 for (var i in rec.controlfield) {
1353 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1356 for (var i in rec.datafield) {
1357 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1360 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1361 changeFFEditor(recordType(rec));
1362 fillFixedFields(rec);
1364 alert('FIXME, MARC Editor, loadRecord: ' + E);
1369 function genToolTips () {
1370 for (var i in bib_data.field) {
1371 var f = bib_data.field[i];
1373 tag_menu.appendChild(
1377 'current_focus.value = "' + f.@tag + '";' +
1378 'var e = document.createEvent("MutationEvents");' +
1379 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1380 'current_focus.inputField.dispatchEvent(e);',
1381 disabled : f.@tag < '010' ? "true" : "false",
1382 tooltiptext : f.description }
1386 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1387 context_menus.appendChild( i1_popup );
1389 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1390 context_menus.appendChild( i2_popup );
1392 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1393 context_menus.appendChild( sf_popup );
1395 tooltip_hash['tag' + f.@tag] = f.description;
1396 for (var j in f.indicator) {
1397 var ind = f.indicator[j];
1398 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1400 if (ind.@position == 1) {
1401 i1_popup.appendChild(
1403 { label : ind.@value,
1405 'current_focus.value = "' + ind.@value + '";' +
1406 'var e = document.createEvent("MutationEvents");' +
1407 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1408 'current_focus.inputField.dispatchEvent(e);',
1409 tooltiptext : ind.description }
1414 if (ind.@position == 2) {
1415 i2_popup.appendChild(
1417 { label : ind.@value,
1419 'current_focus.value = "' + ind.@value + '";' +
1420 'var e = document.createEvent("MutationEvents");' +
1421 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1422 'current_focus.inputField.dispatchEvent(e);',
1423 tooltiptext : ind.description }
1429 for (var j in f.subfield) {
1430 var sf = f.subfield[j];
1431 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1433 sf_popup.appendChild(
1437 'current_focus.value = "' + sf.@code + '";' +
1438 'var e = document.createEvent("MutationEvents");' +
1439 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1440 'current_focus.inputField.dispatchEvent(e);',
1441 tooltiptext : sf.description
1449 function getTooltip (target, type) {
1452 if (type == 'subfield')
1453 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1456 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1459 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1462 tt = 'tag' + target.parentNode.firstChild.value;
1464 if (!document.getElementById( tt )) {
1469 orient : 'vertical',
1470 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1471 class : 'tooltip' },
1472 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1477 target.tooltip = tt;
1481 function getContextMenu (target, type) {
1484 if (type == 'subfield')
1485 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1488 tt = 't' + target.parentNode.firstChild.value + 'i1';
1491 tt = 't' + target.parentNode.firstChild.value + 'i2';
1493 target.setAttribute('context', tt);
1497 var authority_tag_map = {
1498 100 : ['[100,400,500,700]',100],
1499 400 : ['[100,400,500,700]',100],
1500 700 : ['[100,400,500,700]',100],
1501 800 : ['[100,400,500,700]',100],
1502 110 : ['[110,410,510,710]',110],
1503 410 : ['[110,410,510,710]',110],
1504 710 : ['[110,410,510,710]',110],
1505 810 : ['[110,410,510,710]',110],
1506 111 : ['[111,411,511,711]',111],
1507 411 : ['[111,411,511,711]',111],
1508 711 : ['[111,411,511,711]',111],
1509 811 : ['[111,411,511,711]',111],
1510 240 : ['[130,430,530,730]',130],
1511 440 : ['[130,430,530,730]',130],
1512 130 : ['[130,430,530,730]',130],
1513 730 : ['[130,430,530,730]',130],
1514 830 : ['[130,430,530,730]',130],
1515 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1516 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1517 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1518 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1521 function getAuthorityContextMenu (target, sf) {
1522 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1524 var old = document.getElementById( menu_id );
1525 if (old) old.parentNode.removeChild(old);
1527 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1528 context_menus.appendChild( sf_popup );
1530 if (!authority_tag_map[sf.parent().@tag]) {
1531 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1532 target.setAttribute('context', menu_id);
1536 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1538 var res = new XML( auth_data.responseText );
1542 var recs = res.gw::payload.gw::array.gw::string;
1543 for (var i in recs) {
1545 var xml = new XML(x.toString());
1546 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1548 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1551 for (var i in main) {
1552 if (main_text) main_text += ' / ';
1553 main_text += main[i];
1556 rec_list.push( [ main_text, xml ] );
1559 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1561 var main_text = rec_list[i][0];
1562 var xml = rec_list[i][1];
1563 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1565 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1567 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1568 grid.setAttribute('name','-none-');
1569 grid.setAttribute('style','overflow:scroll');
1572 var submenu = createMenu( { label : main_text } );
1574 var popup = createMenuPopup({ flex : "1" });
1575 submenu.appendChild(popup);
1577 var fields = xml.datafield;
1578 for (var j in fields) {
1580 var row = createRow(
1582 createLabel( { value : fields[j].@tag } ),
1583 createLabel( { value : fields[j].@ind1 } ),
1584 createLabel( { value : fields[j].@ind2 } )
1587 var sf_box = createHbox();
1589 var subfields = fields[j].subfield;
1590 for (var k in subfields) {
1593 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1594 subfield : subfields[k].@code,
1595 tag : subfields[k].parent().@tag,
1596 value : subfields[k]
1600 row.appendChild(sf_box);
1603 grid.lastChild.appendChild(row);
1606 grid.hidden = false;
1607 popup.appendChild( grid );
1611 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1612 command : function (event) {
1613 applyAuthority(event.target.previousSibling, target, sf);
1620 sf_popup.appendChild( submenu );
1623 if (sf_popup.childNodes.length == 0)
1624 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1626 target.setAttribute('context', menu_id);
1630 function applyAuthority ( target, ui_sf, e4x_sf ) {
1632 var new_vals = target.getElementsByAttribute('checked','true');
1633 var field = e4x_sf.parent();
1635 for (var i = 0; i < new_vals.length; i++) {
1637 var sf_list = field.subfield;
1638 for (var j in sf_list) {
1640 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1641 sf_list[j] = new_vals[i].getAttribute('value');
1642 new_vals[i].setAttribute('subfield','');
1648 for (var i = 0; i < new_vals.length; i++) {
1649 if (!new_vals[i].getAttribute('subfield')) continue;
1651 var val = new_vals[i].getAttribute('value');
1653 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1654 sf.@code = new_vals[i].getAttribute('subfield');
1656 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1659 var row = marcDatafield( field );
1662 while (node.nodeName != 'row') {
1663 node = node.parentNode;
1666 node.parentNode.replaceChild( row, node );
1672 'a' : { 100 : 'a' },
1676 'a' : { 110 : 'a' },
1680 'a' : { 111 : 'a' },
1684 'a' : { 130 : 'a' },
1688 'a' : { 130 : 'a' },
1692 'a' : { 100 : 'a' },
1696 'a' : { 110 : 'a' },
1700 'a' : { 111 : 'a' },
1704 'a' : { 130 : 'a' },
1705 'n' : { 130 : 'n' },
1709 'a' : { 100 : 'a' },
1713 'a' : { 110 : 'a' },
1717 'a' : { 111 : 'a' },
1721 'a' : { 130 : 'a' },
1725 'a' : { 100 : 'a' },
1729 'a' : { 110 : 'a' },
1733 'a' : { 111 : 'a' },
1737 'a' : { 130 : 'a' },
1741 'a' : { 100 : 'a' },
1742 'd' : { 100 : 'd' },
1743 't' : { 100 : 't' },
1770 'a' : { 110 : 'a' },
1771 'd' : { 110 : 'd' },
1772 't' : { 110 : 't' },
1799 'a' : { 111 : 'a' },
1800 'd' : { 111 : 'd' },
1801 't' : { 111 : 't' },
1828 'a' : { 130 : 'a' },
1832 'a' : { 150 : 'a' },
1833 'b' : { 150 : 'b' },
1860 'a' : { 151 : 'a' },
1887 'a' : { 155 : 'a' },
1915 function validateAuthority (button) {
1916 var grid = document.getElementById('recGrid');
1917 var label = button.getAttribute('label');
1920 var rows = grid.lastChild.childNodes;
1921 for (var i = 0; i < rows.length; i++) {
1923 var tag = row.firstChild;
1925 if (!control_map[tag.value]) continue
1926 button.setAttribute('label', label + ' - ' + tag.value);
1928 var ind1 = tag.nextSibling;
1929 var ind2 = ind1.nextSibling;
1930 var subfields = ind2.nextSibling.childNodes;
1934 for (var j = 0; j < subfields.length; j++) {
1935 var sf = subfields[j];
1936 var sf_code = sf.childNodes[1].value;
1937 var sf_value = sf.childNodes[2].value;
1939 if (!control_map[tag.value][sf_code]) continue;
1942 for (var a_tag in control_map[tag.value][sf_code]) {
1943 if (!tags[a_tag]) tags[a_tag] = [];
1944 tags[a_tag].push({ term : sf_value, subfield : sf_code });
1949 for (var val_tag in tags) {
1950 var auth_data = validateBibField( [val_tag], tags[val_tag]);
1951 var res = new XML( auth_data.responseText );
1952 found = parseInt(res.gw::payload.gw::string.toString());
1956 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1957 for (var j = 0; j < subfields.length; j++) {
1958 var sf = subfields[j];
1960 sf.childNodes[2].inputField.style.color = 'red';
1962 sf.childNodes[2].inputField.style.color = 'black';
1967 button.setAttribute('label', label);
1973 function validateBibField (tags, searches) {
1974 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1975 url += '¶m="tags"¶m=' + js2JSON(tags);
1976 url += '¶m="searches"¶m=' + js2JSON(searches);
1979 var req = new XMLHttpRequest();
1980 req.open('GET',url,false);
1986 function searchAuthority (term, tag, sf, limit) {
1987 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1988 url += '¶m="term"¶m="' + term + '"';
1989 url += '¶m="limit"¶m=' + limit;
1990 url += '¶m="tag"¶m=' + tag;
1991 url += '¶m="subfield"¶m="' + sf + '"';
1994 var req = new XMLHttpRequest();
1995 req.open('GET',url,false);