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) + ";"; }
82 // Fake xulG for standalone...
87 window.xulG.record = {};
88 window.xulG.save = {};
90 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
91 window.xulG.save.func = function (r) { alert(r); }
94 var _rid = cgi.param('record');
96 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
101 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
102 document.getElementById('save-button').setAttribute('oncommand',
104 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
105 'window.xulG.save.func( xml_string ); ' +
106 'loadRecord(xml_record);'
109 if (window.xulG.record.url) {
110 var req = new XMLHttpRequest();
111 req.open('POST',window.xulG.record.url,false);
113 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
116 xml_record = new XML( window.xulG.record.marc );
117 if (xml_record..record[0]) xml_record = xml_record..record[0];
119 // Get the tooltip xml all async like
120 req = new XMLHttpRequest();
122 // Set a default locale in case preferences fail us
123 var locale = "en-US";
125 // Try to get the locale from our preferences
126 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
128 const Cc = Components.classes;
129 const Ci = Components.interfaces;
130 locale = Cc["@mozilla.org/preferences-service;1"].
131 getService(Ci.nsIPrefBranch).
132 getCharPref("general.useragent.locale");
136 // TODO: We should send a HEAD request to check for the existence of the desired file
137 // then fall back to the default locale if preferred locale is not necessary;
138 // however, for now we have a simplistic check:
140 // we currently have translations for only two locales; in the absence of a
141 // valid locale, default to the almighty en-US
142 if (locale != 'en-US' && locale != 'fr-CA') {
146 // Get the locale-specific tooltips
147 req.open('GET','/xul/server/locale/' + locale + '/marcedit-tooltips.xml',true);
149 context_menus = createComplexXULElement('popupset');
150 document.documentElement.appendChild( context_menus );
152 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
153 context_menus.appendChild( tag_menu );
155 tag_menu.appendChild(
157 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
159 'var e = document.createEvent("KeyEvents");' +
160 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
161 'current_focus.inputField.dispatchEvent(e);'
166 tag_menu.appendChild(
168 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
170 'var e = document.createEvent("KeyEvents");' +
171 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
172 'current_focus.inputField.dispatchEvent(e);'
177 tag_menu.appendChild(
179 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
181 'var e = document.createEvent("KeyEvents");' +
182 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
183 'current_focus.inputField.dispatchEvent(e);'
188 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
190 tag_menu.appendChild(
192 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
194 'var e = document.createEvent("KeyEvents");' +
195 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
196 'current_focus.inputField.dispatchEvent(e);'
201 tag_menu.appendChild(
203 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
205 'var e = document.createEvent("KeyEvents");' +
206 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
207 'current_focus.inputField.dispatchEvent(e);'
212 tag_menu.appendChild(
214 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
216 'var e = document.createEvent("KeyEvents");' +
217 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
218 'current_focus.inputField.dispatchEvent(e);'
223 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
225 p = createComplexXULElement('popupset');
226 document.documentElement.appendChild( p );
228 req.onreadystatechange = function () {
229 if (req.readyState == 4) {
230 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
236 loadRecord(xml_record);
240 alert('FIXME, MARC Editor, my_init: ' + E);
245 function createComplexHTMLElement (e, attrs, objects, text) {
246 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
249 for (var i in attrs) l.setAttribute(i,attrs[i]);
253 for ( var i in objects ) l.appendChild( objects[i] );
257 l.appendChild( document.createTextNode(text) )
263 function createComplexXULElement (e, attrs, objects) {
264 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
267 for (var i in attrs) {
268 if (typeof attrs[i] == 'function') {
269 l.addEventListener( i, attrs[i], true );
271 l.setAttribute(i,attrs[i]);
277 for ( var i in objects ) l.appendChild( objects[i] );
283 function createDescription (attrs) {
284 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
287 function createTooltip (attrs) {
288 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
291 function createLabel (attrs) {
292 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
295 function createVbox (attrs) {
296 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
299 function createHbox (attrs) {
300 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
303 function createRow (attrs) {
304 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
307 function createTextbox (attrs) {
308 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
311 function createMenu (attrs) {
312 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
315 function createMenuPopup (attrs) {
316 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
319 function createPopup (attrs) {
320 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
323 function createMenuitem (attrs) {
324 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
327 function createCheckbox (attrs) {
328 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
331 function createMARCTextbox (element,attrs) {
333 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
334 box.onkeypress = function (event) {
337 while(node = node.parent()) {
341 var row = event.target;
342 while (row.tagName != 'row') row = row.parentNode;
344 if (element.nodeKind() == 'attribute') element[0]=box.value;
345 else element.setChildren( box.value );
347 if (element.localName() != 'controlfield') {
348 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
350 var index_sf, target, move_data;
351 if (element.localName() == 'subfield') {
353 target = event.target.parentNode;
355 var start = event.target.selectionStart;
356 var end = event.target.selectionEnd - event.target.selectionStart ?
357 event.target.selectionEnd :
358 event.target.value.length;
360 move_data = event.target.value.substring(start,end);
361 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
362 event.target.setAttribute('size', event.target.value.length + 2);
364 element.setChildren( event.target.value );
366 } else if (element.localName() == 'code') {
367 index_sf = element.parent();
368 target = event.target.parentNode;
369 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
370 index_sf = element.parent().children()[element.parent().children().length() - 1];
371 target = event.target.parentNode.lastChild.lastChild;
374 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
376 index_sf.parent().insertChildAfter( index_sf, sf );
378 var new_sf = marcSubfield(sf);
380 if (target === target.parentNode.lastChild) {
381 target.parentNode.appendChild( new_sf );
383 target.parentNode.insertBefore( new_sf, target.nextSibling );
386 new_sf.firstChild.nextSibling.focus();
388 event.preventDefault();
391 } else if (event.keyCode == 13 || event.keyCode == 77) {
392 if (event.ctrlKey) { // ctrl+enter
395 if (element.localName() == 'subfield') index = element.parent();
396 if (element.localName() == 'code') index = element.parent().parent();
397 if (element.localName() == 'tag') index = element.parent();
398 if (element.localName() == 'ind1') index = element.parent();
399 if (element.localName() == 'ind2') index = element.parent();
401 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
403 if (event.shiftKey) { // ctrl+shift+enter
404 index.parent().insertChildBefore( index, df );
406 index.parent().insertChildAfter( index, df );
409 var new_df = marcDatafield(df);
411 if (row.parentNode.lastChild === row) {
412 row.parentNode.appendChild( new_df );
414 if (event.shiftKey) { // ctrl+shift+enter
415 row.parentNode.insertBefore( new_df, row );
417 row.parentNode.insertBefore( new_df, row.nextSibling );
421 new_df.firstChild.focus();
423 event.preventDefault();
426 } else if (event.shiftKey) {
427 if (row.previousSibling.className.match('marcDatafieldRow'))
428 row.previousSibling.firstChild.focus();
430 row.nextSibling.firstChild.focus();
433 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
436 if (element.localName() == 'subfield') index = element.parent();
437 if (element.localName() == 'code') index = element.parent().parent();
438 if (element.localName() == 'tag') index = element.parent();
439 if (element.localName() == 'ind1') index = element.parent();
440 if (element.localName() == 'ind2') index = element.parent();
442 for (var i in index.parent().children()) {
443 if (index === index.parent().children()[i]) {
444 delete index.parent().children()[i];
449 row.previousSibling.firstChild.focus();
450 row.parentNode.removeChild(row);
452 event.preventDefault();
455 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
458 if (element.localName() == 'subfield') index = element;
459 if (element.localName() == 'code') index = element.parent();
462 for (var i in index.parent().children()) {
463 if (index === index.parent().children()[i]) {
464 delete index.parent().children()[i];
469 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
470 event.target.parentNode.previousSibling.lastChild.focus();
472 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
475 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
477 event.preventDefault();
480 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
481 createControlField('006','');
482 loadRecord(xml_record);
483 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
484 createControlField('007','');
485 loadRecord(xml_record);
486 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
487 createControlField('008','');
488 loadRecord(xml_record);
494 box.addEventListener(
497 if (element.nodeKind() == 'attribute') element[0]=box.value;
498 else element.setChildren( box.value );
504 box.addEventListener(
507 if (element.nodeKind() == 'attribute') element[0]=box.value;
508 else element.setChildren( box.value );
514 box.addEventListener(
517 if (element.nodeKind() == 'attribute') element[0]=box.value;
518 else element.setChildren( box.value );
524 box.addEventListener(
527 if (element.localName() == 'controlfield')
528 eval('fillFixedFields(xml_record);');
537 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
538 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
539 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
540 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
541 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
542 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
543 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
544 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
550 SCO : {start : 33, len : 1, def : ' ' },
551 REC : {start : 33, len : 1, def : 'n' }
554 SCO : {start : 16, len : 1, def : ' ' },
555 REC : {start : 16, len : 1, def : 'n' }
560 VIS : {start : 33, len : 1, def : ' ' }
563 VIS : {start : 16, len : 1, def : ' ' }
568 VIS : {start : 18, len : 3, def : ' ' }
571 VIS : {start : 1, len : 3, def : ' ' }
576 VIS : {start : 34, len : 1, def : 'n' }
579 VIS : {start : 17, len : 1, def : 'n' }
584 SER : {start : 21, len : 1, def : ' ' }
587 SER : {start : 4, len : 1, def : ' ' }
592 BKS : {start : 39, len : 1, def : 'd' },
593 SER : {start : 39, len : 1, def : 'd' },
594 VIS : {start : 39, len : 1, def : 'd' },
595 MIX : {start : 39, len : 1, def : 'd' },
596 MAP : {start : 39, len : 1, def : 'd' },
597 SCO : {start : 39, len : 1, def : 'd' },
598 REC : {start : 39, len : 1, def : 'd' },
599 COM : {start : 39, len : 1, def : 'd' }
604 MAP : {start : 33, len : 2, def : ' ' }
607 MAP : {start : 16, len : 2, def : ' ' }
612 MAP : {start : 18, len : 4, def : ' ' }
615 MAP : {start : 1, len : 4, def : ' ' }
620 SER : {start : 19, len : 1, def : ' ' }
623 SER : {start : 2, len : 1, def : ' ' }
628 MAP : {start : 22, len : 2, def : ' ' }
631 MAP : {start : 5, len : 2, def : ' ' }
636 SCO : {start : 21, len : 1, def : ' ' },
637 REC : {start : 21, len : 1, def : 'n' }
640 SCO : {start : 4, len : 1, def : ' ' },
641 REC : {start : 4, len : 1, def : 'n' }
646 SER : {start : 22, len : 1, def : ' ' }
649 SER : {start : 5, len : 1, def : ' ' }
654 SCO : {start : 30, len : 2, def : ' ' },
655 REC : {start : 30, len : 2, def : ' ' }
658 SCO : {start : 13, len : 2, def : ' ' },
659 REC : {start : 13, len : 2, def : ' ' }
664 SER : {start : 18, len : 1, def : ' ' }
667 SER : {start : 1, len : 1, def : ' ' }
672 SCO : {start : 20, len : 1, def : ' ' },
673 REC : {start : 20, len : 1, def : 'n' }
676 SCO : {start : 3, len : 1, def : ' ' },
677 REC : {start : 3, len : 1, def : 'n' }
682 COM : {start : 26, len : 1, def : 'u' }
685 COM : {start : 9, len : 1, def : 'u' }
690 SER : {start : 24, len : 1, def : ' ' }
693 SER : {start : 7, len : 1, def : ' ' }
698 SCO : {start : 24, len : 6, def : ' ' },
699 REC : {start : 24, len : 6, def : ' ' }
702 SCO : {start : 7, len : 6, def : ' ' },
703 REC : {start : 7, len : 6, def : ' ' }
708 SCO : {start : 18, len : 2, def : ' ' },
709 REC : {start : 18, len : 2, def : ' ' }
712 SCO : {start : 1, len : 2, def : ' ' },
713 REC : {start : 1, len : 2, def : ' ' }
718 MAP : {start : 25, len : 1, def : ' ' }
721 MAP : {start : 8, len : 1, def : ' ' }
726 BKS : {start : 15, len : 3, def : ' ' },
727 SER : {start : 15, len : 3, def : ' ' },
728 VIS : {start : 15, len : 3, def : ' ' },
729 MIX : {start : 15, len : 3, def : ' ' },
730 MAP : {start : 15, len : 3, def : ' ' },
731 SCO : {start : 15, len : 3, def : ' ' },
732 REC : {start : 15, len : 3, def : ' ' },
733 COM : {start : 15, len : 3, def : ' ' }
738 BKS : {start : 35, len : 3, def : ' ' },
739 SER : {start : 35, len : 3, def : ' ' },
740 VIS : {start : 35, len : 3, def : ' ' },
741 MIX : {start : 35, len : 3, def : ' ' },
742 MAP : {start : 35, len : 3, def : ' ' },
743 SCO : {start : 35, len : 3, def : ' ' },
744 REC : {start : 35, len : 3, def : ' ' },
745 COM : {start : 35, len : 3, def : ' ' }
750 BKS : {start : 38, len : 1, def : ' ' },
751 SER : {start : 38, len : 1, def : ' ' },
752 VIS : {start : 38, len : 1, def : ' ' },
753 MIX : {start : 38, len : 1, def : ' ' },
754 MAP : {start : 38, len : 1, def : ' ' },
755 SCO : {start : 38, len : 1, def : ' ' },
756 REC : {start : 38, len : 1, def : ' ' },
757 COM : {start : 38, len : 1, def : ' ' }
762 BKS : {start : 6, len : 1, def : ' ' },
763 SER : {start : 6, len : 1, def : 'c' },
764 VIS : {start : 6, len : 1, def : ' ' },
765 MIX : {start : 6, len : 1, def : ' ' },
766 MAP : {start : 6, len : 1, def : ' ' },
767 SCO : {start : 6, len : 1, def : ' ' },
768 REC : {start : 6, len : 1, def : ' ' },
769 COM : {start : 6, len : 1, def : ' ' }
774 BKS : {start : 6, len : 1, def : 'a' },
775 SER : {start : 6, len : 1, def : 'a' },
776 VIS : {start : 6, len : 1, def : 'g' },
777 MIX : {start : 6, len : 1, def : 'p' },
778 MAP : {start : 6, len : 1, def : 'e' },
779 SCO : {start : 6, len : 1, def : 'c' },
780 REC : {start : 6, len : 1, def : 'i' },
781 COM : {start : 6, len : 1, def : 'm' }
786 BKS : {start : 8, len : 1, def : ' ' },
787 SER : {start : 8, len : 1, def : ' ' },
788 VIS : {start : 8, len : 1, def : ' ' },
789 MIX : {start : 8, len : 1, def : ' ' },
790 MAP : {start : 8, len : 1, def : ' ' },
791 SCO : {start : 8, len : 1, def : ' ' },
792 REC : {start : 8, len : 1, def : ' ' },
793 COM : {start : 8, len : 1, def : ' ' }
798 BKS : {start : 7, len : 1, def : 'm' },
799 SER : {start : 7, len : 1, def : 's' },
800 VIS : {start : 7, len : 1, def : 'm' },
801 MIX : {start : 7, len : 1, def : 'c' },
802 MAP : {start : 7, len : 1, def : 'm' },
803 SCO : {start : 7, len : 1, def : 'm' },
804 REC : {start : 7, len : 1, def : 'm' },
805 COM : {start : 7, len : 1, def : 'm' }
810 BKS : {start : 18, len : 1, def : ' ' },
811 SER : {start : 18, len : 1, def : ' ' },
812 VIS : {start : 18, len : 1, def : ' ' },
813 MIX : {start : 18, len : 1, def : ' ' },
814 MAP : {start : 18, len : 1, def : ' ' },
815 SCO : {start : 18, len : 1, def : ' ' },
816 REC : {start : 18, len : 1, def : ' ' },
817 COM : {start : 18, len : 1, def : ' ' }
822 BKS : {start : 17, len : 1, def : ' ' },
823 SER : {start : 17, len : 1, def : ' ' },
824 VIS : {start : 17, len : 1, def : ' ' },
825 MIX : {start : 17, len : 1, def : ' ' },
826 MAP : {start : 17, len : 1, def : ' ' },
827 SCO : {start : 17, len : 1, def : ' ' },
828 REC : {start : 17, len : 1, def : ' ' },
829 COM : {start : 17, len : 1, def : ' ' }
834 BKS : {start : 31, len : 1, def : '0' },
835 MAP : {start : 31, len : 1, def : '0' }
838 BKS : {start : 14, len : 1, def : '0' },
839 MAP : {start : 14, len : 1, def : '0' }
844 BKS : {start : 7, len : 4, def : ' ' },
845 SER : {start : 7, len : 4, def : ' ' },
846 VIS : {start : 7, len : 4, def : ' ' },
847 MIX : {start : 7, len : 4, def : ' ' },
848 MAP : {start : 7, len : 4, def : ' ' },
849 SCO : {start : 7, len : 4, def : ' ' },
850 REC : {start : 7, len : 4, def : ' ' },
851 COM : {start : 7, len : 4, def : ' ' }
856 BKS : {start : 11, len : 4, def : ' ' },
857 SER : {start : 11, len : 4, def : '9' },
858 VIS : {start : 11, len : 4, def : ' ' },
859 MIX : {start : 11, len : 4, def : ' ' },
860 MAP : {start : 11, len : 4, def : ' ' },
861 SCO : {start : 11, len : 4, def : ' ' },
862 REC : {start : 11, len : 4, def : ' ' },
863 COM : {start : 11, len : 4, def : ' ' }
868 BKS : {start : 33, len : 1, def : '0' }
871 BKS : {start : 16, len : 1, def : '0' }
876 BKS : {start : 34, len : 1, def : ' ' }
879 BKS : {start : 17, len : 1, def : ' ' }
884 BKS : {start : 18, len : 4, def : ' ' }
887 BKS : {start : 1, len : 4, def : ' ' }
892 BKS : {start : 30, len : 1, def : '0' }
895 BKS : {start : 13, len : 1, def : '0' }
900 BKS : {start : 29, len : 1, def : '0' },
901 SER : {start : 29, len : 1, def : '0' }
904 BKS : {start : 12, len : 1, def : '0' },
905 SER : {start : 12, len : 1, def : '0' }
910 BKS : {start : 24, len : 4, def : ' ' },
911 SER : {start : 25, len : 3, def : ' ' }
914 BKS : {start : 7, len : 4, def : ' ' },
915 SER : {start : 8, len : 3, def : ' ' }
920 BKS : {start : 28, len : 1, def : ' ' },
921 SER : {start : 28, len : 1, def : ' ' },
922 VIS : {start : 28, len : 1, def : ' ' },
923 MAP : {start : 28, len : 1, def : ' ' },
924 COM : {start : 28, len : 1, def : ' ' }
927 BKS : {start : 11, len : 1, def : ' ' },
928 SER : {start : 11, len : 1, def : ' ' },
929 VIS : {start : 11, len : 1, def : ' ' },
930 MAP : {start : 11, len : 1, def : ' ' },
931 COM : {start : 11, len : 1, def : ' ' }
936 BKS : {start : 22, len : 1, def : ' ' },
937 SER : {start : 22, len : 1, def : ' ' },
938 VIS : {start : 22, len : 1, def : ' ' },
939 SCO : {start : 22, len : 1, def : ' ' },
940 REC : {start : 22, len : 1, def : ' ' },
941 COM : {start : 22, len : 1, def : ' ' }
944 BKS : {start : 5, len : 1, def : ' ' },
945 SER : {start : 5, len : 1, def : ' ' },
946 VIS : {start : 5, len : 1, def : ' ' },
947 SCO : {start : 5, len : 1, def : ' ' },
948 REC : {start : 5, len : 1, def : ' ' },
949 COM : {start : 5, len : 1, def : ' ' }
954 BKS : {start : 23, len : 1, def : ' ' },
955 SER : {start : 23, len : 1, def : ' ' },
956 VIS : {start : 29, len : 1, def : ' ' },
957 MIX : {start : 23, len : 1, def : ' ' },
958 MAP : {start : 29, len : 1, def : ' ' },
959 SCO : {start : 23, len : 1, def : ' ' },
960 REC : {start : 23, len : 1, def : ' ' }
963 BKS : {start : 6, len : 1, def : ' ' },
964 SER : {start : 6, len : 1, def : ' ' },
965 VIS : {start : 12, len : 1, def : ' ' },
966 MIX : {start : 6, len : 1, def : ' ' },
967 MAP : {start : 12, len : 1, def : ' ' },
968 SCO : {start : 6, len : 1, def : ' ' },
969 REC : {start : 6, len : 1, def : ' ' }
974 SER : {start : 34, len : 1, def : '0' }
977 SER : {start : 17, len : 1, def : '0' }
982 SER : {start : 33, len : 1, def : ' ' }
985 SER : {start : 16, len : 1, def : ' ' }
990 function recordType (rec) {
992 var _l = rec.leader.toString();
994 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
995 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
997 for (var t in rec_type) {
998 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
999 document.getElementById('recordTypeLabel').value = t;
1005 alert('FIXME, MARC Editor, recordType: ' + E);
1009 function toggleFFE () {
1010 var grid = document.getElementById('leaderGrid');
1012 grid.hidden = false;
1019 function changeFFEditor (type) {
1020 var grid = document.getElementById('leaderGrid');
1021 grid.setAttribute('type',type);
1024 function fillFixedFields (rec) {
1026 var grid = document.getElementById('leaderGrid');
1028 var rtype = _record_type;
1030 var _l = rec.leader.toString();
1031 var _6 = rec.controlfield.(@tag=='006').toString();
1032 var _7 = rec.controlfield.(@tag=='007').toString();
1033 var _8 = rec.controlfield.(@tag=='008').toString();
1036 var pre_list = grid.getElementsByTagName('label');
1037 for (var i in pre_list) {
1038 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1039 list.push( pre_list[i] );
1043 for (var i in list) {
1044 var name = list[i].getAttribute('name');
1050 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1051 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1053 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1054 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1056 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1057 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1059 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1060 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1065 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1066 d = ff_pos[name].ldr[rtype].def;
1070 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1071 d = ff_pos[name]._8[rtype].def;
1075 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1076 d = ff_pos[name]._6[rtype].def;
1080 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1081 d = ff_pos[name]._7[rtype].def;
1086 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1092 list[i].nextSibling.value = value;
1097 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1101 function updateFixedFields (element) {
1102 var grid = document.getElementById('leaderGrid');
1103 var recGrid = document.getElementById('recGrid');
1105 var rtype = _record_type;
1106 var new_value = element.value;
1109 ldr : _record.leader,
1110 _6 : _record.controlfield.(@tag=='006'),
1111 _7 : _record.controlfield.(@tag=='007'),
1112 _8 : _record.controlfield.(@tag=='008')
1115 var name = element.getAttribute('name');
1116 for (var i in ff_pos[name]) {
1118 if (!ff_pos[name][i][rtype]) continue;
1119 if (!parts[i]) continue;
1121 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1122 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1124 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1125 new_value += ff_pos[name][i][rtype].def;
1128 parts[i].setChildren( before + new_value + after );
1129 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1135 function marcLeader (leader) {
1136 var row = createRow(
1137 { class : 'marcLeaderRow',
1142 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1145 class : 'marcInd1' } ),
1148 class : 'marcInd2' } ),
1150 { value : leader.text(),
1151 class : 'marcLeader' } )
1157 function marcControlfield (field) {
1158 tagname = field.@tag.toString().substr(2);
1160 if (tagname == '6' || tagname == '7' || tagname == '8') {
1162 { class : 'marcControlfieldRow',
1163 tag : '_' + tagname },
1165 { value : field.@tag,
1167 context : 'tags_popup',
1168 onmouseover : 'getTooltip(this, "tag");',
1169 tooltipid : 'tag' + field.@tag } ),
1171 { value : field.@ind1,
1173 onmouseover : 'getTooltip(this, "ind1");',
1174 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1176 { value : field.@ind2,
1178 onmouseover : 'getTooltip(this, "ind2");',
1179 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1182 { value : field.text(),
1183 class : 'plain marcEditableControlfield',
1184 name : 'CONTROL' + tagname,
1185 oncontext : 'return false();',
1191 { class : 'marcControlfieldRow',
1192 tag : '_' + tagname },
1194 { value : field.@tag,
1196 onmouseover : 'getTooltip(this, "tag");',
1197 tooltipid : 'tag' + field.@tag } ),
1199 { value : field.@ind1,
1201 onmouseover : 'getTooltip(this, "ind1");',
1202 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1204 { value : field.@ind2,
1206 onmouseover : 'getTooltip(this, "ind2");',
1207 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1209 { value : field.text(),
1210 class : 'marcControlfield' } )
1217 function stackSubfields(checkbox) {
1218 var list = document.getElementsByAttribute('name','sf_box');
1221 if (checkbox.checked) o = 'horizontal';
1223 for (var i = 0; i < list.length; i++) {
1224 if (list[i]) list[i].setAttribute('orient',o);
1228 function marcDatafield (field) {
1229 var row = createRow(
1230 { class : 'marcDatafieldRow' },
1233 { value : field.@tag,
1234 class : 'plain marcTag',
1236 context : 'tags_popup',
1237 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1240 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1243 { value : field.@ind1,
1244 class : 'plain marcInd1',
1246 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1249 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1250 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1253 { value : field.@ind2,
1254 class : 'plain marcInd2',
1256 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1259 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1260 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1261 createHbox({ name : 'sf_box' })
1264 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1265 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1266 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1268 var sf_box = row.lastChild;
1269 if (document.getElementById('stackSubfields').checked)
1270 sf_box.setAttribute('orient','vertical');
1272 sf_box.addEventListener(
1275 if (sf_box === e.target) {
1276 sf_box.lastChild.lastChild.focus();
1277 } else if (e.target.parentNode === sf_box) {
1278 e.target.lastChild.focus();
1285 for (var i in field.subfield) {
1286 var sf = field.subfield[i];
1291 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1292 current_focus = sf_box.lastChild.childNodes[1];
1298 function marcSubfield (sf) {
1300 { class : 'marcSubfieldBox' },
1303 class : 'plain marcSubfieldDelimiter',
1304 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1305 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1306 //onclick : 'this.nextSibling.focus();',
1307 onfocus : 'this.nextSibling.focus();',
1312 class : 'plain marcSubfieldCode',
1313 name : 'marcSubfieldCode',
1314 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1315 oncontextmenu : 'getContextMenu(this, "subfield");',
1316 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1321 { value : sf.text(),
1322 name : sf.parent().@tag + ':' + sf.@code,
1323 class : 'plain marcSubfield',
1324 onmouseover : 'getTooltip(this, "subfield");',
1325 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1326 size : new String(sf.text()).length + 2,
1327 oninput : "this.setAttribute('size', this.value.length + 2);"
1332 function loadRecord(rec) {
1335 var grid_rows = document.getElementById('recGrid').lastChild;
1337 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1339 grid_rows.appendChild( marcLeader( rec.leader ) );
1341 for (var i in rec.controlfield) {
1342 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1345 for (var i in rec.datafield) {
1346 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1349 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1350 changeFFEditor(recordType(rec));
1351 fillFixedFields(rec);
1353 alert('FIXME, MARC Editor, loadRecord: ' + E);
1358 function genToolTips () {
1359 for (var i in bib_data.field) {
1360 var f = bib_data.field[i];
1362 tag_menu.appendChild(
1366 'current_focus.value = "' + f.@tag + '";' +
1367 'var e = document.createEvent("MutationEvents");' +
1368 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1369 'current_focus.inputField.dispatchEvent(e);',
1370 disabled : f.@tag < '010' ? "true" : "false",
1371 tooltiptext : f.description }
1375 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1376 context_menus.appendChild( i1_popup );
1378 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1379 context_menus.appendChild( i2_popup );
1381 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1382 context_menus.appendChild( sf_popup );
1384 tooltip_hash['tag' + f.@tag] = f.description;
1385 for (var j in f.indicator) {
1386 var ind = f.indicator[j];
1387 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1389 if (ind.@position == 1) {
1390 i1_popup.appendChild(
1392 { label : ind.@value,
1394 'current_focus.value = "' + ind.@value + '";' +
1395 'var e = document.createEvent("MutationEvents");' +
1396 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1397 'current_focus.inputField.dispatchEvent(e);',
1398 tooltiptext : ind.description }
1403 if (ind.@position == 2) {
1404 i2_popup.appendChild(
1406 { label : ind.@value,
1408 'current_focus.value = "' + ind.@value + '";' +
1409 'var e = document.createEvent("MutationEvents");' +
1410 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1411 'current_focus.inputField.dispatchEvent(e);',
1412 tooltiptext : ind.description }
1418 for (var j in f.subfield) {
1419 var sf = f.subfield[j];
1420 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1422 sf_popup.appendChild(
1426 'current_focus.value = "' + sf.@code + '";' +
1427 'var e = document.createEvent("MutationEvents");' +
1428 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1429 'current_focus.inputField.dispatchEvent(e);',
1430 tooltiptext : sf.description
1438 function getTooltip (target, type) {
1441 if (type == 'subfield')
1442 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1445 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1448 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1451 tt = 'tag' + target.parentNode.firstChild.value;
1453 if (!document.getElementById( tt )) {
1458 orient : 'vertical',
1459 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1460 class : 'tooltip' },
1461 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1466 target.tooltip = tt;
1470 function getContextMenu (target, type) {
1473 if (type == 'subfield')
1474 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1477 tt = 't' + target.parentNode.firstChild.value + 'i1';
1480 tt = 't' + target.parentNode.firstChild.value + 'i2';
1482 target.setAttribute('context', tt);
1486 var authority_tag_map = {
1487 100 : ['[100,400,500,700]',100],
1488 400 : ['[100,400,500,700]',100],
1489 700 : ['[100,400,500,700]',100],
1490 800 : ['[100,400,500,700]',100],
1491 110 : ['[110,410,510,710]',110],
1492 410 : ['[110,410,510,710]',110],
1493 710 : ['[110,410,510,710]',110],
1494 810 : ['[110,410,510,710]',110],
1495 111 : ['[111,411,511,711]',111],
1496 411 : ['[111,411,511,711]',111],
1497 711 : ['[111,411,511,711]',111],
1498 811 : ['[111,411,511,711]',111],
1499 240 : ['[130,430,530,730]',130],
1500 440 : ['[130,430,530,730]',130],
1501 130 : ['[130,430,530,730]',130],
1502 730 : ['[130,430,530,730]',130],
1503 830 : ['[130,430,530,730]',130],
1504 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1505 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1506 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1507 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1510 function getAuthorityContextMenu (target, sf) {
1511 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1513 var old = document.getElementById( menu_id );
1514 if (old) old.parentNode.removeChild(old);
1516 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1517 context_menus.appendChild( sf_popup );
1519 if (!authority_tag_map[sf.parent().@tag]) {
1520 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1521 target.setAttribute('context', menu_id);
1525 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1527 var res = new XML( auth_data.responseText );
1531 var recs = res.gw::payload.gw::array.gw::string;
1532 for (var i in recs) {
1534 var xml = new XML(x.toString());
1535 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1537 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1540 for (var i in main) {
1541 if (main_text) main_text += ' / ';
1542 main_text += main[i];
1545 rec_list.push( [ main_text, xml ] );
1548 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1550 var main_text = rec_list[i][0];
1551 var xml = rec_list[i][1];
1552 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1554 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1556 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1557 grid.setAttribute('name','-none-');
1558 grid.setAttribute('style','overflow:scroll');
1561 var submenu = createMenu( { label : main_text } );
1563 var popup = createMenuPopup({ flex : "1" });
1564 submenu.appendChild(popup);
1566 var fields = xml.datafield;
1567 for (var j in fields) {
1569 var row = createRow(
1571 createLabel( { value : fields[j].@tag } ),
1572 createLabel( { value : fields[j].@ind1 } ),
1573 createLabel( { value : fields[j].@ind2 } )
1576 var sf_box = createHbox();
1578 var subfields = fields[j].subfield;
1579 for (var k in subfields) {
1582 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1583 subfield : subfields[k].@code,
1584 tag : subfields[k].parent().@tag,
1585 value : subfields[k]
1589 row.appendChild(sf_box);
1592 grid.lastChild.appendChild(row);
1595 grid.hidden = false;
1596 popup.appendChild( grid );
1600 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1601 command : function (event) {
1602 applyAuthority(event.target.previousSibling, target, sf);
1609 sf_popup.appendChild( submenu );
1612 if (sf_popup.childNodes.length == 0)
1613 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1615 target.setAttribute('context', menu_id);
1619 function applyAuthority ( target, ui_sf, e4x_sf ) {
1621 var new_vals = target.getElementsByAttribute('checked','true');
1622 var field = e4x_sf.parent();
1624 for (var i = 0; i < new_vals.length; i++) {
1626 var sf_list = field.subfield;
1627 for (var j in sf_list) {
1629 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1630 sf_list[j] = new_vals[i].getAttribute('value');
1631 new_vals[i].setAttribute('subfield','');
1637 for (var i = 0; i < new_vals.length; i++) {
1638 if (!new_vals[i].getAttribute('subfield')) continue;
1640 var val = new_vals[i].getAttribute('value');
1642 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1643 sf.@code = new_vals[i].getAttribute('subfield');
1645 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1648 var row = marcDatafield( field );
1651 while (node.nodeName != 'row') {
1652 node = node.parentNode;
1655 node.parentNode.replaceChild( row, node );
1661 'a' : { 100 : 'a' },
1665 'a' : { 110 : 'a' },
1669 'a' : { 111 : 'a' },
1673 'a' : { 130 : 'a' },
1677 'a' : { 130 : 'a' },
1681 'a' : { 100 : 'a' },
1685 'a' : { 110 : 'a' },
1689 'a' : { 111 : 'a' },
1693 'a' : { 130 : 'a' },
1694 'n' : { 130 : 'n' },
1698 'a' : { 100 : 'a' },
1702 'a' : { 110 : 'a' },
1706 'a' : { 111 : 'a' },
1710 'a' : { 130 : 'a' },
1714 'a' : { 100 : 'a' },
1718 'a' : { 110 : 'a' },
1722 'a' : { 111 : 'a' },
1726 'a' : { 130 : 'a' },
1730 'a' : { 100 : 'a' },
1731 'd' : { 100 : 'd' },
1732 't' : { 100 : 't' },
1759 'a' : { 110 : 'a' },
1760 'd' : { 110 : 'd' },
1761 't' : { 110 : 't' },
1788 'a' : { 111 : 'a' },
1789 'd' : { 111 : 'd' },
1790 't' : { 111 : 't' },
1817 'a' : { 130 : 'a' },
1821 'a' : { 150 : 'a' },
1822 'b' : { 150 : 'b' },
1849 'a' : { 151 : 'a' },
1876 'a' : { 155 : 'a' },
1904 function validateAuthority (button) {
1905 var grid = document.getElementById('recGrid');
1906 var label = button.getAttribute('label');
1909 var rows = grid.lastChild.childNodes;
1910 for (var i = 0; i < rows.length; i++) {
1912 var tag = row.firstChild;
1914 if (!control_map[tag.value]) continue
1915 button.setAttribute('label', label + ' - ' + tag.value);
1917 var ind1 = tag.nextSibling;
1918 var ind2 = ind1.nextSibling;
1919 var subfields = ind2.nextSibling.childNodes;
1923 for (var j = 0; j < subfields.length; j++) {
1924 var sf = subfields[j];
1925 var sf_code = sf.childNodes[1].value;
1926 var sf_value = sf.childNodes[2].value;
1928 if (!control_map[tag.value][sf_code]) continue;
1931 for (var a_tag in control_map[tag.value][sf_code]) {
1932 if (!tags[a_tag]) tags[a_tag] = [];
1933 tags[a_tag].push({ term : sf_value, subfield : sf_code });
1938 for (var val_tag in tags) {
1939 var auth_data = validateBibField( [val_tag], tags[val_tag]);
1940 var res = new XML( auth_data.responseText );
1941 found = parseInt(res.gw::payload.gw::string.toString());
1945 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1946 for (var j = 0; j < subfields.length; j++) {
1947 var sf = subfields[j];
1949 sf.childNodes[2].inputField.style.color = 'red';
1951 sf.childNodes[2].inputField.style.color = 'black';
1956 button.setAttribute('label', label);
1962 function validateBibField (tags, searches) {
1963 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1964 url += '¶m="tags"¶m=' + js2JSON(tags);
1965 url += '¶m="searches"¶m=' + js2JSON(searches);
1968 var req = new XMLHttpRequest();
1969 req.open('GET',url,false);
1975 function searchAuthority (term, tag, sf, limit) {
1976 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1977 url += '¶m="term"¶m="' + term + '"';
1978 url += '¶m="limit"¶m=' + limit;
1979 url += '¶m="tag"¶m=' + tag;
1980 url += '¶m="subfield"¶m="' + sf + '"';
1983 var req = new XMLHttpRequest();
1984 req.open('GET',url,false);