1 // vim: noet:sw=4:ts=4:
2 var xmlDeclaration = /^<\?xml version[^>]+?>/;
4 var serializer = new XMLSerializer();
5 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
6 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
7 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
8 default xml namespace = marcns;
10 var tooltip_hash = {};
22 function $(id) { return document.getElementById(id); }
24 function mangle_005() {
26 var y = now.getUTCFullYear();
28 var m = now.getUTCMonth() + 1;
29 if (m < 10) m = '0' + m;
31 var d = now.getUTCDate();
32 if (d < 10) d = '0' + d;
34 var H = now.getUTCHours();
35 if (H < 10) H = '0' + H;
37 var M = now.getUTCMinutes();
38 if (M < 10) M = '0' + M;
40 var S = now.getUTCSeconds();
41 if (S < 10) S = '0' + S;
44 var stamp = '' + y + m + d + H + M + S + '.0';
45 createControlField('005',stamp);
49 function createControlField (tag,data) {
50 // first, remove the old field, if any;
51 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
53 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
56 // then, find the right position and insert it
58 var cfields = xml_record.controlfield;
59 var base = Number(tag.substring(2));
60 for (var i in cfields) {
61 var t = Number(cfields[i].@tag.toString().substring(2));
63 xml_record.insertChildBefore( cfields[i], cf );
69 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
74 function xml_escape_unicode ( str ) {
77 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
84 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
85 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
86 JSAN.errorLevel = "die"; // none, warn, or die
87 JSAN.addRepository('/xul/server/');
89 // Fake xulG for standalone...
94 window.xulG.record = {};
95 window.xulG.save = {};
97 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
98 window.xulG.save.func = function (r) { alert(r); }
101 var _rid = cgi.param('record');
103 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
106 // End faking part...
108 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
109 document.getElementById('save-button').setAttribute('oncommand',
111 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
112 'save_attempt( xml_string ); ' +
113 'loadRecord(xml_record);'
116 if (window.xulG.record.url) {
117 var req = new XMLHttpRequest();
118 req.open('POST',window.xulG.record.url,false);
120 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
123 xml_record = new XML( window.xulG.record.marc );
124 if (xml_record..record[0]) xml_record = xml_record..record[0];
126 // Get the tooltip xml all async like
127 req = new XMLHttpRequest();
129 // Set a default locale in case preferences fail us
130 var locale = "en-US";
132 // Try to get the locale from our preferences
133 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
135 const Cc = Components.classes;
136 const Ci = Components.interfaces;
137 locale = Cc["@mozilla.org/preferences-service;1"].
138 getService(Ci.nsIPrefBranch).
139 getCharPref("general.useragent.locale");
143 // TODO: We should send a HEAD request to check for the existence of the desired file
144 // then fall back to the default locale if preferred locale is not necessary;
145 // however, for now we have a simplistic check:
147 // we currently have translations for only two locales; in the absence of a
148 // valid locale, default to the almighty en-US
149 if (locale != 'en-US' && locale != 'fr-CA') {
153 // Get the locale-specific tooltips
154 req.open('GET','/xul/server/locale/' + locale + '/marcedit-tooltips.xml',true);
156 context_menus = createComplexXULElement('popupset');
157 document.documentElement.appendChild( context_menus );
159 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
160 context_menus.appendChild( tag_menu );
162 tag_menu.appendChild(
164 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
166 'var e = document.createEvent("KeyEvents");' +
167 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
168 'current_focus.inputField.dispatchEvent(e);'
173 tag_menu.appendChild(
175 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
177 'var e = document.createEvent("KeyEvents");' +
178 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
179 'current_focus.inputField.dispatchEvent(e);'
184 tag_menu.appendChild(
186 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
188 'var e = document.createEvent("KeyEvents");' +
189 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
190 'current_focus.inputField.dispatchEvent(e);'
195 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
197 tag_menu.appendChild(
199 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
201 'var e = document.createEvent("KeyEvents");' +
202 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
203 'current_focus.inputField.dispatchEvent(e);'
208 tag_menu.appendChild(
210 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
212 'var e = document.createEvent("KeyEvents");' +
213 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
214 'current_focus.inputField.dispatchEvent(e);'
219 tag_menu.appendChild(
221 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
223 'var e = document.createEvent("KeyEvents");' +
224 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
225 'current_focus.inputField.dispatchEvent(e);'
230 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
232 p = createComplexXULElement('popupset');
233 document.documentElement.appendChild( p );
235 req.onreadystatechange = function () {
236 if (req.readyState == 4) {
237 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
243 loadRecord(xml_record);
245 if (! xulG.fast_add_item) {
246 document.getElementById('fastItemAdd_checkbox').hidden = true;
248 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
251 alert('FIXME, MARC Editor, my_init: ' + E);
256 function createComplexHTMLElement (e, attrs, objects, text) {
257 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
260 for (var i in attrs) l.setAttribute(i,attrs[i]);
264 for ( var i in objects ) l.appendChild( objects[i] );
268 l.appendChild( document.createTextNode(text) )
274 function createComplexXULElement (e, attrs, objects) {
275 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
278 for (var i in attrs) {
279 if (typeof attrs[i] == 'function') {
280 l.addEventListener( i, attrs[i], true );
282 l.setAttribute(i,attrs[i]);
288 for ( var i in objects ) l.appendChild( objects[i] );
294 function createDescription (attrs) {
295 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
298 function createTooltip (attrs) {
299 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
302 function createLabel (attrs) {
303 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
306 function createVbox (attrs) {
307 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
310 function createHbox (attrs) {
311 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
314 function createRow (attrs) {
315 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
318 function createTextbox (attrs) {
319 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
322 function createMenu (attrs) {
323 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
326 function createMenuPopup (attrs) {
327 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
330 function createPopup (attrs) {
331 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
334 function createMenuitem (attrs) {
335 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
338 function createCheckbox (attrs) {
339 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
342 function createMARCTextbox (element,attrs) {
344 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
345 box.onkeypress = function (event) {
348 while(node = node.parent()) {
352 var row = event.target;
353 while (row.tagName != 'row') row = row.parentNode;
355 if (element.nodeKind() == 'attribute') element[0]=box.value;
356 else element.setChildren( box.value );
358 if (element.localName() != 'controlfield') {
359 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
361 var index_sf, target, move_data;
362 if (element.localName() == 'subfield') {
364 target = event.target.parentNode;
366 var start = event.target.selectionStart;
367 var end = event.target.selectionEnd - event.target.selectionStart ?
368 event.target.selectionEnd :
369 event.target.value.length;
371 move_data = event.target.value.substring(start,end);
372 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
373 event.target.setAttribute('size', event.target.value.length + 2);
375 element.setChildren( event.target.value );
377 } else if (element.localName() == 'code') {
378 index_sf = element.parent();
379 target = event.target.parentNode;
380 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
381 index_sf = element.parent().children()[element.parent().children().length() - 1];
382 target = event.target.parentNode.lastChild.lastChild;
385 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
387 index_sf.parent().insertChildAfter( index_sf, sf );
389 var new_sf = marcSubfield(sf);
391 if (target === target.parentNode.lastChild) {
392 target.parentNode.appendChild( new_sf );
394 target.parentNode.insertBefore( new_sf, target.nextSibling );
397 new_sf.firstChild.nextSibling.focus();
399 event.preventDefault();
402 } else if (event.keyCode == 13 || event.keyCode == 77) {
403 if (event.ctrlKey) { // ctrl+enter
406 if (element.localName() == 'subfield') index = element.parent();
407 if (element.localName() == 'code') index = element.parent().parent();
408 if (element.localName() == 'tag') index = element.parent();
409 if (element.localName() == 'ind1') index = element.parent();
410 if (element.localName() == 'ind2') index = element.parent();
412 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
414 if (event.shiftKey) { // ctrl+shift+enter
415 index.parent().insertChildBefore( index, df );
417 index.parent().insertChildAfter( index, df );
420 var new_df = marcDatafield(df);
422 if (row.parentNode.lastChild === row) {
423 row.parentNode.appendChild( new_df );
425 if (event.shiftKey) { // ctrl+shift+enter
426 row.parentNode.insertBefore( new_df, row );
428 row.parentNode.insertBefore( new_df, row.nextSibling );
432 new_df.firstChild.focus();
434 event.preventDefault();
437 } else if (event.shiftKey) {
438 if (row.previousSibling.className.match('marcDatafieldRow'))
439 row.previousSibling.firstChild.focus();
441 row.nextSibling.firstChild.focus();
444 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
445 if (event.ctrlKey) { // CTRL key: copy the field
447 if (element.localName() == 'subfield') index = element.parent();
448 if (element.localName() == 'code') index = element.parent().parent();
449 if (element.localName() == 'tag') index = element.parent();
450 if (element.localName() == 'ind1') index = element.parent();
451 if (element.localName() == 'ind2') index = element.parent();
453 var copyField = index.copy();
455 if (event.keyCode == 38) { // ctrl+up-arrow
456 index.parent().insertChildBefore( index, copyField );
458 index.parent().insertChildAfter( index, copyField );
461 var new_df = marcDatafield(copyField);
463 if (row.parentNode.lastChild === row) {
464 row.parentNode.appendChild( new_df );
466 if (event.keyCode == 38) { // ctrl+up-arrow
467 row.parentNode.insertBefore( new_df, row );
468 } else { // ctrl+down-arrow
469 row.parentNode.insertBefore( new_df, row.nextSibling );
473 new_df.firstChild.focus();
475 event.preventDefault();
480 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
483 if (element.localName() == 'subfield') index = element.parent();
484 if (element.localName() == 'code') index = element.parent().parent();
485 if (element.localName() == 'tag') index = element.parent();
486 if (element.localName() == 'ind1') index = element.parent();
487 if (element.localName() == 'ind2') index = element.parent();
489 for (var i in index.parent().children()) {
490 if (index === index.parent().children()[i]) {
491 delete index.parent().children()[i];
496 row.previousSibling.firstChild.focus();
497 row.parentNode.removeChild(row);
499 event.preventDefault();
502 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
505 if (element.localName() == 'subfield') index = element;
506 if (element.localName() == 'code') index = element.parent();
509 for (var i in index.parent().children()) {
510 if (index === index.parent().children()[i]) {
511 delete index.parent().children()[i];
516 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
517 event.target.parentNode.previousSibling.lastChild.focus();
519 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
522 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
524 event.preventDefault();
527 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
528 createControlField('006','');
529 loadRecord(xml_record);
530 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
531 createControlField('007','');
532 loadRecord(xml_record);
533 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
534 createControlField('008','');
535 loadRecord(xml_record);
541 box.addEventListener(
544 if (element.nodeKind() == 'attribute') element[0]=box.value;
545 else element.setChildren( box.value );
551 box.addEventListener(
554 if (element.nodeKind() == 'attribute') element[0]=box.value;
555 else element.setChildren( box.value );
561 box.addEventListener(
564 if (element.nodeKind() == 'attribute') element[0]=box.value;
565 else element.setChildren( box.value );
571 box.addEventListener(
574 if (element.localName() == 'controlfield')
575 eval('fillFixedFields(xml_record);');
584 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
585 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
586 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
587 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
588 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
589 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
590 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
591 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
597 SCO : {start : 33, len : 1, def : ' ' },
598 REC : {start : 33, len : 1, def : 'n' }
601 SCO : {start : 16, len : 1, def : ' ' },
602 REC : {start : 16, len : 1, def : 'n' }
607 VIS : {start : 33, len : 1, def : ' ' }
610 VIS : {start : 16, len : 1, def : ' ' }
615 VIS : {start : 18, len : 3, def : ' ' }
618 VIS : {start : 1, len : 3, def : ' ' }
623 VIS : {start : 34, len : 1, def : 'n' }
626 VIS : {start : 17, len : 1, def : 'n' }
631 SER : {start : 21, len : 1, def : ' ' }
634 SER : {start : 4, len : 1, def : ' ' }
639 BKS : {start : 39, len : 1, def : 'd' },
640 SER : {start : 39, len : 1, def : 'd' },
641 VIS : {start : 39, len : 1, def : 'd' },
642 MIX : {start : 39, len : 1, def : 'd' },
643 MAP : {start : 39, len : 1, def : 'd' },
644 SCO : {start : 39, len : 1, def : 'd' },
645 REC : {start : 39, len : 1, def : 'd' },
646 COM : {start : 39, len : 1, def : 'd' }
651 MAP : {start : 33, len : 2, def : ' ' }
654 MAP : {start : 16, len : 2, def : ' ' }
659 MAP : {start : 18, len : 4, def : ' ' }
662 MAP : {start : 1, len : 4, def : ' ' }
667 SER : {start : 19, len : 1, def : ' ' }
670 SER : {start : 2, len : 1, def : ' ' }
675 MAP : {start : 22, len : 2, def : ' ' }
678 MAP : {start : 5, len : 2, def : ' ' }
683 SCO : {start : 21, len : 1, def : ' ' },
684 REC : {start : 21, len : 1, def : 'n' }
687 SCO : {start : 4, len : 1, def : ' ' },
688 REC : {start : 4, len : 1, def : 'n' }
693 SER : {start : 22, len : 1, def : ' ' }
696 SER : {start : 5, len : 1, def : ' ' }
701 SCO : {start : 30, len : 2, def : ' ' },
702 REC : {start : 30, len : 2, def : ' ' }
705 SCO : {start : 13, len : 2, def : ' ' },
706 REC : {start : 13, len : 2, def : ' ' }
711 SER : {start : 18, len : 1, def : ' ' }
714 SER : {start : 1, len : 1, def : ' ' }
719 SCO : {start : 20, len : 1, def : ' ' },
720 REC : {start : 20, len : 1, def : 'n' }
723 SCO : {start : 3, len : 1, def : ' ' },
724 REC : {start : 3, len : 1, def : 'n' }
729 COM : {start : 26, len : 1, def : 'u' }
732 COM : {start : 9, len : 1, def : 'u' }
737 SER : {start : 24, len : 1, def : ' ' }
740 SER : {start : 7, len : 1, def : ' ' }
745 SCO : {start : 24, len : 6, def : ' ' },
746 REC : {start : 24, len : 6, def : ' ' }
749 SCO : {start : 7, len : 6, def : ' ' },
750 REC : {start : 7, len : 6, def : ' ' }
755 SCO : {start : 18, len : 2, def : ' ' },
756 REC : {start : 18, len : 2, def : ' ' }
759 SCO : {start : 1, len : 2, def : ' ' },
760 REC : {start : 1, len : 2, def : ' ' }
765 MAP : {start : 25, len : 1, def : ' ' }
768 MAP : {start : 8, len : 1, def : ' ' }
773 BKS : {start : 15, len : 3, def : ' ' },
774 SER : {start : 15, len : 3, def : ' ' },
775 VIS : {start : 15, len : 3, def : ' ' },
776 MIX : {start : 15, len : 3, def : ' ' },
777 MAP : {start : 15, len : 3, def : ' ' },
778 SCO : {start : 15, len : 3, def : ' ' },
779 REC : {start : 15, len : 3, def : ' ' },
780 COM : {start : 15, len : 3, def : ' ' }
785 BKS : {start : 35, len : 3, def : ' ' },
786 SER : {start : 35, len : 3, def : ' ' },
787 VIS : {start : 35, len : 3, def : ' ' },
788 MIX : {start : 35, len : 3, def : ' ' },
789 MAP : {start : 35, len : 3, def : ' ' },
790 SCO : {start : 35, len : 3, def : ' ' },
791 REC : {start : 35, len : 3, def : ' ' },
792 COM : {start : 35, len : 3, def : ' ' }
797 BKS : {start : 38, len : 1, def : ' ' },
798 SER : {start : 38, len : 1, def : ' ' },
799 VIS : {start : 38, len : 1, def : ' ' },
800 MIX : {start : 38, len : 1, def : ' ' },
801 MAP : {start : 38, len : 1, def : ' ' },
802 SCO : {start : 38, len : 1, def : ' ' },
803 REC : {start : 38, len : 1, def : ' ' },
804 COM : {start : 38, len : 1, def : ' ' }
809 BKS : {start : 6, len : 1, def : ' ' },
810 SER : {start : 6, len : 1, def : 'c' },
811 VIS : {start : 6, len : 1, def : ' ' },
812 MIX : {start : 6, len : 1, def : ' ' },
813 MAP : {start : 6, len : 1, def : ' ' },
814 SCO : {start : 6, len : 1, def : ' ' },
815 REC : {start : 6, len : 1, def : ' ' },
816 COM : {start : 6, len : 1, def : ' ' }
821 BKS : {start : 6, len : 1, def : 'a' },
822 SER : {start : 6, len : 1, def : 'a' },
823 VIS : {start : 6, len : 1, def : 'g' },
824 MIX : {start : 6, len : 1, def : 'p' },
825 MAP : {start : 6, len : 1, def : 'e' },
826 SCO : {start : 6, len : 1, def : 'c' },
827 REC : {start : 6, len : 1, def : 'i' },
828 COM : {start : 6, len : 1, def : 'm' }
833 BKS : {start : 8, len : 1, def : ' ' },
834 SER : {start : 8, len : 1, def : ' ' },
835 VIS : {start : 8, len : 1, def : ' ' },
836 MIX : {start : 8, len : 1, def : ' ' },
837 MAP : {start : 8, len : 1, def : ' ' },
838 SCO : {start : 8, len : 1, def : ' ' },
839 REC : {start : 8, len : 1, def : ' ' },
840 COM : {start : 8, len : 1, def : ' ' }
845 BKS : {start : 7, len : 1, def : 'm' },
846 SER : {start : 7, len : 1, def : 's' },
847 VIS : {start : 7, len : 1, def : 'm' },
848 MIX : {start : 7, len : 1, def : 'c' },
849 MAP : {start : 7, len : 1, def : 'm' },
850 SCO : {start : 7, len : 1, def : 'm' },
851 REC : {start : 7, len : 1, def : 'm' },
852 COM : {start : 7, len : 1, def : 'm' }
857 BKS : {start : 18, len : 1, def : ' ' },
858 SER : {start : 18, len : 1, def : ' ' },
859 VIS : {start : 18, len : 1, def : ' ' },
860 MIX : {start : 18, len : 1, def : ' ' },
861 MAP : {start : 18, len : 1, def : ' ' },
862 SCO : {start : 18, len : 1, def : ' ' },
863 REC : {start : 18, len : 1, def : ' ' },
864 COM : {start : 18, len : 1, def : ' ' }
869 BKS : {start : 17, len : 1, def : ' ' },
870 SER : {start : 17, len : 1, def : ' ' },
871 VIS : {start : 17, len : 1, def : ' ' },
872 MIX : {start : 17, len : 1, def : ' ' },
873 MAP : {start : 17, len : 1, def : ' ' },
874 SCO : {start : 17, len : 1, def : ' ' },
875 REC : {start : 17, len : 1, def : ' ' },
876 COM : {start : 17, len : 1, def : ' ' }
881 BKS : {start : 31, len : 1, def : '0' },
882 MAP : {start : 31, len : 1, def : '0' }
885 BKS : {start : 14, len : 1, def : '0' },
886 MAP : {start : 14, len : 1, def : '0' }
891 BKS : {start : 7, len : 4, def : ' ' },
892 SER : {start : 7, len : 4, def : ' ' },
893 VIS : {start : 7, len : 4, def : ' ' },
894 MIX : {start : 7, len : 4, def : ' ' },
895 MAP : {start : 7, len : 4, def : ' ' },
896 SCO : {start : 7, len : 4, def : ' ' },
897 REC : {start : 7, len : 4, def : ' ' },
898 COM : {start : 7, len : 4, def : ' ' }
903 BKS : {start : 11, len : 4, def : ' ' },
904 SER : {start : 11, len : 4, def : '9' },
905 VIS : {start : 11, len : 4, def : ' ' },
906 MIX : {start : 11, len : 4, def : ' ' },
907 MAP : {start : 11, len : 4, def : ' ' },
908 SCO : {start : 11, len : 4, def : ' ' },
909 REC : {start : 11, len : 4, def : ' ' },
910 COM : {start : 11, len : 4, def : ' ' }
915 BKS : {start : 33, len : 1, def : '0' }
918 BKS : {start : 16, len : 1, def : '0' }
923 BKS : {start : 34, len : 1, def : ' ' }
926 BKS : {start : 17, len : 1, def : ' ' }
931 BKS : {start : 18, len : 4, def : ' ' }
934 BKS : {start : 1, len : 4, def : ' ' }
939 BKS : {start : 30, len : 1, def : '0' }
942 BKS : {start : 13, len : 1, def : '0' }
947 BKS : {start : 29, len : 1, def : '0' },
948 SER : {start : 29, len : 1, def : '0' }
951 BKS : {start : 12, len : 1, def : '0' },
952 SER : {start : 12, len : 1, def : '0' }
957 BKS : {start : 24, len : 4, def : ' ' },
958 SER : {start : 25, len : 3, def : ' ' }
961 BKS : {start : 7, len : 4, def : ' ' },
962 SER : {start : 8, len : 3, def : ' ' }
967 BKS : {start : 28, len : 1, def : ' ' },
968 SER : {start : 28, len : 1, def : ' ' },
969 VIS : {start : 28, len : 1, def : ' ' },
970 MAP : {start : 28, len : 1, def : ' ' },
971 COM : {start : 28, len : 1, def : ' ' }
974 BKS : {start : 11, len : 1, def : ' ' },
975 SER : {start : 11, len : 1, def : ' ' },
976 VIS : {start : 11, len : 1, def : ' ' },
977 MAP : {start : 11, len : 1, def : ' ' },
978 COM : {start : 11, len : 1, def : ' ' }
983 BKS : {start : 22, len : 1, def : ' ' },
984 SER : {start : 22, len : 1, def : ' ' },
985 VIS : {start : 22, len : 1, def : ' ' },
986 SCO : {start : 22, len : 1, def : ' ' },
987 REC : {start : 22, len : 1, def : ' ' },
988 COM : {start : 22, len : 1, def : ' ' }
991 BKS : {start : 5, len : 1, def : ' ' },
992 SER : {start : 5, len : 1, def : ' ' },
993 VIS : {start : 5, len : 1, def : ' ' },
994 SCO : {start : 5, len : 1, def : ' ' },
995 REC : {start : 5, len : 1, def : ' ' },
996 COM : {start : 5, len : 1, def : ' ' }
1001 BKS : {start : 23, len : 1, def : ' ' },
1002 SER : {start : 23, len : 1, def : ' ' },
1003 VIS : {start : 29, len : 1, def : ' ' },
1004 MIX : {start : 23, len : 1, def : ' ' },
1005 MAP : {start : 29, len : 1, def : ' ' },
1006 SCO : {start : 23, len : 1, def : ' ' },
1007 REC : {start : 23, len : 1, def : ' ' }
1010 BKS : {start : 6, len : 1, def : ' ' },
1011 SER : {start : 6, len : 1, def : ' ' },
1012 VIS : {start : 12, len : 1, def : ' ' },
1013 MIX : {start : 6, len : 1, def : ' ' },
1014 MAP : {start : 12, len : 1, def : ' ' },
1015 SCO : {start : 6, len : 1, def : ' ' },
1016 REC : {start : 6, len : 1, def : ' ' }
1021 SER : {start : 34, len : 1, def : '0' }
1024 SER : {start : 17, len : 1, def : '0' }
1029 SER : {start : 33, len : 1, def : ' ' }
1032 SER : {start : 16, len : 1, def : ' ' }
1037 function recordType (rec) {
1039 var _l = rec.leader.toString();
1041 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1042 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1044 for (var t in rec_type) {
1045 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1046 document.getElementById('recordTypeLabel').value = t;
1052 // in case we don't have a valid record type ...
1053 _record_type = 'BKS';
1054 return _record_type;
1057 alert('FIXME, MARC Editor, recordType: ' + E);
1061 function toggleFFE () {
1062 var grid = document.getElementById('leaderGrid');
1064 grid.hidden = false;
1071 function changeFFEditor (type) {
1072 var grid = document.getElementById('leaderGrid');
1073 grid.setAttribute('type',type);
1076 function fillFixedFields (rec) {
1078 var grid = document.getElementById('leaderGrid');
1080 var rtype = _record_type;
1082 var _l = rec.leader.toString();
1083 var _6 = rec.controlfield.(@tag=='006').toString();
1084 var _7 = rec.controlfield.(@tag=='007').toString();
1085 var _8 = rec.controlfield.(@tag=='008').toString();
1088 var pre_list = grid.getElementsByTagName('label');
1089 for (var i in pre_list) {
1090 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1091 list.push( pre_list[i] );
1095 for (var i in list) {
1096 var name = list[i].getAttribute('name');
1102 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1103 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1105 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1106 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1108 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1109 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1111 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1112 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1117 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1118 d = ff_pos[name].ldr[rtype].def;
1122 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1123 d = ff_pos[name]._8[rtype].def;
1127 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1128 d = ff_pos[name]._6[rtype].def;
1132 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1133 d = ff_pos[name]._7[rtype].def;
1138 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1144 list[i].nextSibling.value = value;
1149 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1153 function updateFixedFields (element) {
1154 var grid = document.getElementById('leaderGrid');
1155 var recGrid = document.getElementById('recGrid');
1157 var rtype = _record_type;
1158 var new_value = element.value;
1161 ldr : _record.leader,
1162 _6 : _record.controlfield.(@tag=='006'),
1163 _7 : _record.controlfield.(@tag=='007'),
1164 _8 : _record.controlfield.(@tag=='008')
1167 var name = element.getAttribute('name');
1168 for (var i in ff_pos[name]) {
1170 if (!ff_pos[name][i][rtype]) continue;
1171 if (!parts[i]) continue;
1173 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1174 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1176 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1177 new_value += ff_pos[name][i][rtype].def;
1180 parts[i].setChildren( before + new_value + after );
1181 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1187 function marcLeader (leader) {
1188 var row = createRow(
1189 { class : 'marcLeaderRow',
1194 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1197 class : 'marcInd1' } ),
1200 class : 'marcInd2' } ),
1202 { value : leader.text(),
1203 class : 'marcLeader' } )
1209 function marcControlfield (field) {
1210 tagname = field.@tag.toString().substr(2);
1212 if (tagname == '6' || tagname == '7' || tagname == '8') {
1214 { class : 'marcControlfieldRow',
1215 tag : '_' + tagname },
1217 { value : field.@tag,
1219 context : 'tags_popup',
1220 onmouseover : 'getTooltip(this, "tag");',
1221 tooltipid : 'tag' + field.@tag } ),
1223 { value : field.@ind1,
1225 onmouseover : 'getTooltip(this, "ind1");',
1226 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1228 { value : field.@ind2,
1230 onmouseover : 'getTooltip(this, "ind2");',
1231 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1234 { value : field.text(),
1235 class : 'plain marcEditableControlfield',
1236 name : 'CONTROL' + tagname,
1237 oncontext : 'return false();',
1243 { class : 'marcControlfieldRow',
1244 tag : '_' + tagname },
1246 { value : field.@tag,
1248 onmouseover : 'getTooltip(this, "tag");',
1249 tooltipid : 'tag' + field.@tag } ),
1251 { value : field.@ind1,
1253 onmouseover : 'getTooltip(this, "ind1");',
1254 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1256 { value : field.@ind2,
1258 onmouseover : 'getTooltip(this, "ind2");',
1259 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1261 { value : field.text(),
1262 class : 'marcControlfield' } )
1269 function stackSubfields(checkbox) {
1270 var list = document.getElementsByAttribute('name','sf_box');
1273 if (!checkbox.checked) o = 'horizontal';
1275 for (var i = 0; i < list.length; i++) {
1276 if (list[i]) list[i].setAttribute('orient',o);
1280 function fastItemAdd_toggle(checkbox) {
1281 var x = document.getElementById('fastItemAdd_textboxes');
1282 if (checkbox.checked) {
1284 document.getElementById('fastItemAdd_callnumber').focus();
1285 document.getElementById('fastItemAdd_callnumber').select();
1291 function fastItemAdd_attempt(doc_id) {
1293 if (typeof window.xulG.fast_add_item != 'function') { return; }
1294 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1295 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1296 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1297 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1299 alert('fastItemAdd_attempt: ' + E);
1303 function save_attempt(xml_string) {
1305 var result = window.xulG.save.func( xml_string );
1307 if (result.id) fastItemAdd_attempt(result.id);
1308 if (typeof result.on_complete == 'function') result.on_complete();
1311 alert('save_attempt: ' + E);
1315 function marcDatafield (field) {
1316 var row = createRow(
1317 { class : 'marcDatafieldRow' },
1320 { value : field.@tag,
1321 class : 'plain marcTag',
1323 context : 'tags_popup',
1324 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1327 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1330 { value : field.@ind1,
1331 class : 'plain marcInd1',
1333 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1336 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1337 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1340 { value : field.@ind2,
1341 class : 'plain marcInd2',
1343 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1346 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1347 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1348 createHbox({ name : 'sf_box' })
1351 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1352 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1353 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1355 var sf_box = row.lastChild;
1356 if (document.getElementById('stackSubfields').checked)
1357 sf_box.setAttribute('orient','vertical');
1359 sf_box.addEventListener(
1362 if (sf_box === e.target) {
1363 sf_box.lastChild.lastChild.focus();
1364 } else if (e.target.parentNode === sf_box) {
1365 e.target.lastChild.focus();
1372 for (var i in field.subfield) {
1373 var sf = field.subfield[i];
1378 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1379 current_focus = sf_box.lastChild.childNodes[1];
1385 function marcSubfield (sf) {
1387 { class : 'marcSubfieldBox' },
1390 class : 'plain marcSubfieldDelimiter',
1391 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1392 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1393 //onclick : 'this.nextSibling.focus();',
1394 onfocus : 'this.nextSibling.focus();',
1399 class : 'plain marcSubfieldCode',
1400 name : 'marcSubfieldCode',
1401 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1402 oncontextmenu : 'getContextMenu(this, "subfield");',
1403 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1408 { value : sf.text(),
1409 name : sf.parent().@tag + ':' + sf.@code,
1410 class : 'plain marcSubfield',
1411 onmouseover : 'getTooltip(this, "subfield");',
1412 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1413 size : new String(sf.text()).length + 2,
1414 oninput : "this.setAttribute('size', this.value.length + 2);"
1419 function loadRecord(rec) {
1422 var grid_rows = document.getElementById('recGrid').lastChild;
1424 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1426 grid_rows.appendChild( marcLeader( rec.leader ) );
1428 for (var i in rec.controlfield) {
1429 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1432 for (var i in rec.datafield) {
1433 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1436 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1437 changeFFEditor(recordType(rec));
1438 fillFixedFields(rec);
1440 alert('FIXME, MARC Editor, loadRecord: ' + E);
1445 function genToolTips () {
1446 for (var i in bib_data.field) {
1447 var f = bib_data.field[i];
1449 tag_menu.appendChild(
1453 'current_focus.value = "' + f.@tag + '";' +
1454 'var e = document.createEvent("MutationEvents");' +
1455 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1456 'current_focus.inputField.dispatchEvent(e);',
1457 disabled : f.@tag < '010' ? "true" : "false",
1458 tooltiptext : f.description }
1462 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1463 context_menus.appendChild( i1_popup );
1465 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1466 context_menus.appendChild( i2_popup );
1468 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1469 context_menus.appendChild( sf_popup );
1471 tooltip_hash['tag' + f.@tag] = f.description;
1472 for (var j in f.indicator) {
1473 var ind = f.indicator[j];
1474 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1476 if (ind.@position == 1) {
1477 i1_popup.appendChild(
1479 { label : ind.@value,
1481 'current_focus.value = "' + ind.@value + '";' +
1482 'var e = document.createEvent("MutationEvents");' +
1483 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1484 'current_focus.inputField.dispatchEvent(e);',
1485 tooltiptext : ind.description }
1490 if (ind.@position == 2) {
1491 i2_popup.appendChild(
1493 { label : ind.@value,
1495 'current_focus.value = "' + ind.@value + '";' +
1496 'var e = document.createEvent("MutationEvents");' +
1497 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1498 'current_focus.inputField.dispatchEvent(e);',
1499 tooltiptext : ind.description }
1505 for (var j in f.subfield) {
1506 var sf = f.subfield[j];
1507 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1509 sf_popup.appendChild(
1513 'current_focus.value = "' + sf.@code + '";' +
1514 'var e = document.createEvent("MutationEvents");' +
1515 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1516 'current_focus.inputField.dispatchEvent(e);',
1517 tooltiptext : sf.description
1525 function getTooltip (target, type) {
1528 if (type == 'subfield')
1529 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1532 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1535 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1538 tt = 'tag' + target.parentNode.firstChild.value;
1540 if (!document.getElementById( tt )) {
1545 orient : 'vertical',
1546 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1547 class : 'tooltip' },
1548 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1553 target.tooltip = tt;
1557 function getContextMenu (target, type) {
1560 if (type == 'subfield')
1561 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1564 tt = 't' + target.parentNode.firstChild.value + 'i1';
1567 tt = 't' + target.parentNode.firstChild.value + 'i2';
1569 target.setAttribute('context', tt);
1573 var authority_tag_map = {
1574 100 : ['[100,400,500,700]',100],
1575 400 : ['[100,400,500,700]',100],
1576 700 : ['[100,400,500,700]',100],
1577 800 : ['[100,400,500,700]',100],
1578 110 : ['[110,410,510,710]',110],
1579 410 : ['[110,410,510,710]',110],
1580 710 : ['[110,410,510,710]',110],
1581 810 : ['[110,410,510,710]',110],
1582 111 : ['[111,411,511,711]',111],
1583 411 : ['[111,411,511,711]',111],
1584 711 : ['[111,411,511,711]',111],
1585 811 : ['[111,411,511,711]',111],
1586 240 : ['[130,430,530,730]',130],
1587 440 : ['[130,430,530,730]',130],
1588 130 : ['[130,430,530,730]',130],
1589 730 : ['[130,430,530,730]',130],
1590 830 : ['[130,430,530,730]',130],
1591 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1592 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1593 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1594 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1597 function getAuthorityContextMenu (target, sf) {
1598 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1600 var old = document.getElementById( menu_id );
1601 if (old) old.parentNode.removeChild(old);
1603 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1604 context_menus.appendChild( sf_popup );
1606 if (!authority_tag_map[sf.parent().@tag]) {
1607 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1608 target.setAttribute('context', menu_id);
1612 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1614 var res = new XML( auth_data.responseText );
1618 var recs = res.gw::payload.gw::array.gw::string;
1619 for (var i in recs) {
1621 var xml = new XML(x.toString());
1622 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1624 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1627 for (var i in main) {
1628 if (main_text) main_text += ' / ';
1629 main_text += main[i];
1632 rec_list.push( [ main_text, xml ] );
1635 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1637 var main_text = rec_list[i][0];
1638 var xml = rec_list[i][1];
1639 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1641 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1643 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1644 grid.setAttribute('name','-none-');
1645 grid.setAttribute('style','overflow:scroll');
1648 var submenu = createMenu( { label : main_text } );
1650 var popup = createMenuPopup({ flex : "1" });
1651 submenu.appendChild(popup);
1653 var fields = xml.datafield;
1654 for (var j in fields) {
1656 var row = createRow(
1658 createLabel( { value : fields[j].@tag } ),
1659 createLabel( { value : fields[j].@ind1 } ),
1660 createLabel( { value : fields[j].@ind2 } )
1663 var sf_box = createHbox();
1665 var subfields = fields[j].subfield;
1666 for (var k in subfields) {
1669 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1670 subfield : subfields[k].@code,
1671 tag : subfields[k].parent().@tag,
1672 value : subfields[k]
1676 row.appendChild(sf_box);
1679 grid.lastChild.appendChild(row);
1682 grid.hidden = false;
1683 popup.appendChild( grid );
1687 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1688 command : function (event) {
1689 applyAuthority(event.target.previousSibling, target, sf);
1696 sf_popup.appendChild( submenu );
1699 if (sf_popup.childNodes.length == 0)
1700 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1702 target.setAttribute('context', menu_id);
1706 function applyAuthority ( target, ui_sf, e4x_sf ) {
1708 var new_vals = target.getElementsByAttribute('checked','true');
1709 var field = e4x_sf.parent();
1711 for (var i = 0; i < new_vals.length; i++) {
1713 var sf_list = field.subfield;
1714 for (var j in sf_list) {
1716 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1717 sf_list[j] = new_vals[i].getAttribute('value');
1718 new_vals[i].setAttribute('subfield','');
1724 for (var i = 0; i < new_vals.length; i++) {
1725 if (!new_vals[i].getAttribute('subfield')) continue;
1727 var val = new_vals[i].getAttribute('value');
1729 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1730 sf.@code = new_vals[i].getAttribute('subfield');
1732 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1735 var row = marcDatafield( field );
1738 while (node.nodeName != 'row') {
1739 node = node.parentNode;
1742 node.parentNode.replaceChild( row, node );
1748 'a' : { 100 : 'a' },
1749 'd' : { 100 : 'd' },
1753 'a' : { 110 : 'a' },
1757 'a' : { 111 : 'a' },
1761 'a' : { 130 : 'a' },
1765 'a' : { 130 : 'a' },
1769 'a' : { 100 : 'a' },
1773 'a' : { 110 : 'a' },
1777 'a' : { 111 : 'a' },
1781 'a' : { 130 : 'a' },
1782 'n' : { 130 : 'n' },
1786 'a' : { 100 : 'a' },
1787 'd' : { 100 : 'd' },
1788 'q' : { 100 : 'q' },
1792 'a' : { 110 : 'a' },
1796 'a' : { 111 : 'a' },
1800 'a' : { 130 : 'a' },
1804 'a' : { 100 : 'a' },
1808 'a' : { 110 : 'a' },
1812 'a' : { 111 : 'a' },
1816 'a' : { 130 : 'a' },
1820 'a' : { 100 : 'a' },
1821 'd' : { 100 : 'd' },
1822 'q' : { 100 : 'q' },
1823 't' : { 100 : 't' },
1850 'a' : { 110 : 'a' },
1851 'd' : { 110 : 'd' },
1852 't' : { 110 : 't' },
1879 'a' : { 111 : 'a' },
1880 'd' : { 111 : 'd' },
1881 't' : { 111 : 't' },
1908 'a' : { 130 : 'a' },
1912 'a' : { 150 : 'a' },
1913 'b' : { 150 : 'b' },
1940 'a' : { 151 : 'a' },
1967 'a' : { 155 : 'a' },
1995 function validateAuthority (button) {
1996 var grid = document.getElementById('recGrid');
1997 var label = button.getAttribute('label');
2000 var rows = grid.lastChild.childNodes;
2001 for (var i = 0; i < rows.length; i++) {
2003 var tag = row.firstChild;
2005 if (!control_map[tag.value]) continue
2006 button.setAttribute('label', label + ' - ' + tag.value);
2008 var ind1 = tag.nextSibling;
2009 var ind2 = ind1.nextSibling;
2010 var subfields = ind2.nextSibling.childNodes;
2014 for (var j = 0; j < subfields.length; j++) {
2015 var sf = subfields[j];
2016 var sf_code = sf.childNodes[1].value;
2017 var sf_value = sf.childNodes[2].value;
2019 if (!control_map[tag.value][sf_code]) continue;
2022 for (var a_tag in control_map[tag.value][sf_code]) {
2023 if (!tags[a_tag]) tags[a_tag] = [];
2024 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2029 for (var val_tag in tags) {
2030 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2031 var res = new XML( auth_data.responseText );
2032 found = parseInt(res.gw::payload.gw::string.toString());
2036 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2037 for (var j = 0; j < subfields.length; j++) {
2038 var sf = subfields[j];
2040 sf.childNodes[2].inputField.style.color = 'red';
2042 sf.childNodes[2].inputField.style.color = 'black';
2047 button.setAttribute('label', label);
2053 function validateBibField (tags, searches) {
2054 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2055 url += '¶m="tags"¶m=' + js2JSON(tags);
2056 url += '¶m="searches"¶m=' + js2JSON(searches);
2059 var req = new XMLHttpRequest();
2060 req.open('GET',url,false);
2066 function searchAuthority (term, tag, sf, limit) {
2067 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2068 url += '¶m="term"¶m="' + term + '"';
2069 url += '¶m="limit"¶m=' + limit;
2070 url += '¶m="tag"¶m=' + tag;
2071 url += '¶m="subfield"¶m="' + sf + '"';
2074 var req = new XMLHttpRequest();
2075 req.open('GET',url,false);