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;
1172 // we're missing the required field. Add it now.
1175 if (i == '_6') newfield = '006';
1176 else if (i == '_7') newfield = '007';
1177 else if (i == '_8') newfield = '008';
1180 createControlField(newfield,' ');
1181 parts[i] = _record.controlfield.(@tag==newfield);
1184 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1185 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1187 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1188 new_value += ff_pos[name][i][rtype].def;
1191 parts[i].setChildren( before + new_value + after );
1192 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1198 function marcLeader (leader) {
1199 var row = createRow(
1200 { class : 'marcLeaderRow',
1205 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1208 class : 'marcInd1' } ),
1211 class : 'marcInd2' } ),
1213 { value : leader.text(),
1214 class : 'marcLeader' } )
1220 function marcControlfield (field) {
1221 tagname = field.@tag.toString().substr(2);
1223 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1225 { class : 'marcControlfieldRow',
1226 tag : '_' + tagname },
1228 { value : field.@tag,
1230 context : 'tags_popup',
1231 onmouseover : 'getTooltip(this, "tag");',
1232 tooltipid : 'tag' + field.@tag } ),
1234 { value : field.@ind1,
1236 onmouseover : 'getTooltip(this, "ind1");',
1237 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1239 { value : field.@ind2,
1241 onmouseover : 'getTooltip(this, "ind2");',
1242 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1245 { value : field.text(),
1246 class : 'plain marcEditableControlfield',
1247 name : 'CONTROL' + tagname,
1248 context : 'clipboard',
1254 { class : 'marcControlfieldRow',
1255 tag : '_' + tagname },
1257 { value : field.@tag,
1259 onmouseover : 'getTooltip(this, "tag");',
1260 tooltipid : 'tag' + field.@tag } ),
1262 { value : field.@ind1,
1264 onmouseover : 'getTooltip(this, "ind1");',
1265 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1267 { value : field.@ind2,
1269 onmouseover : 'getTooltip(this, "ind2");',
1270 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1272 { value : field.text(),
1273 class : 'marcControlfield' } )
1280 function stackSubfields(checkbox) {
1281 var list = document.getElementsByAttribute('name','sf_box');
1284 if (!checkbox.checked) o = 'horizontal';
1286 for (var i = 0; i < list.length; i++) {
1287 if (list[i]) list[i].setAttribute('orient',o);
1291 function fastItemAdd_toggle(checkbox) {
1292 var x = document.getElementById('fastItemAdd_textboxes');
1293 if (checkbox.checked) {
1295 document.getElementById('fastItemAdd_callnumber').focus();
1296 document.getElementById('fastItemAdd_callnumber').select();
1302 function fastItemAdd_attempt(doc_id) {
1304 if (typeof window.xulG.fast_add_item != 'function') { return; }
1305 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1306 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1307 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1308 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1309 document.getElementById('fastItemAdd_barcode').value = '';
1311 alert('fastItemAdd_attempt: ' + E);
1315 function save_attempt(xml_string) {
1317 var result = window.xulG.save.func( xml_string );
1319 if (result.id) fastItemAdd_attempt(result.id);
1320 if (typeof result.on_complete == 'function') result.on_complete();
1323 alert('save_attempt: ' + E);
1327 function marcDatafield (field) {
1328 var row = createRow(
1329 { class : 'marcDatafieldRow' },
1332 { value : field.@tag,
1333 class : 'plain marcTag',
1335 context : 'tags_popup',
1336 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1339 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1342 { value : field.@ind1,
1343 class : 'plain marcInd1',
1345 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1348 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1349 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1352 { value : field.@ind2,
1353 class : 'plain marcInd2',
1355 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1358 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1359 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1360 createHbox({ name : 'sf_box' })
1363 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1364 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1365 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1367 var sf_box = row.lastChild;
1368 if (document.getElementById('stackSubfields').checked)
1369 sf_box.setAttribute('orient','vertical');
1371 sf_box.addEventListener(
1374 if (sf_box === e.target) {
1375 sf_box.lastChild.lastChild.focus();
1376 } else if (e.target.parentNode === sf_box) {
1377 e.target.lastChild.focus();
1384 for (var i in field.subfield) {
1385 var sf = field.subfield[i];
1390 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1391 current_focus = sf_box.lastChild.childNodes[1];
1397 function marcSubfield (sf) {
1399 { class : 'marcSubfieldBox' },
1402 class : 'plain marcSubfieldDelimiter',
1403 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1404 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1405 //onclick : 'this.nextSibling.focus();',
1406 onfocus : 'this.nextSibling.focus();',
1411 class : 'plain marcSubfieldCode',
1412 name : 'marcSubfieldCode',
1413 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1414 oncontextmenu : 'getContextMenu(this, "subfield");',
1415 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1420 { value : sf.text(),
1421 name : sf.parent().@tag + ':' + sf.@code,
1422 class : 'plain marcSubfield',
1423 onmouseover : 'getTooltip(this, "subfield");',
1424 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1425 size : new String(sf.text()).length + 2,
1426 oninput : "this.setAttribute('size', this.value.length + 2);"
1431 function loadRecord(rec) {
1434 var grid_rows = document.getElementById('recGrid').lastChild;
1436 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1438 grid_rows.appendChild( marcLeader( rec.leader ) );
1440 for (var i in rec.controlfield) {
1441 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1444 for (var i in rec.datafield) {
1445 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1448 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1449 changeFFEditor(recordType(rec));
1450 fillFixedFields(rec);
1452 alert('FIXME, MARC Editor, loadRecord: ' + E);
1457 function genToolTips () {
1458 for (var i in bib_data.field) {
1459 var f = bib_data.field[i];
1461 tag_menu.appendChild(
1465 'current_focus.value = "' + f.@tag + '";' +
1466 'var e = document.createEvent("MutationEvents");' +
1467 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1468 'current_focus.inputField.dispatchEvent(e);',
1469 disabled : f.@tag < '010' ? "true" : "false",
1470 tooltiptext : f.description }
1474 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1475 context_menus.appendChild( i1_popup );
1477 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1478 context_menus.appendChild( i2_popup );
1480 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1481 context_menus.appendChild( sf_popup );
1483 tooltip_hash['tag' + f.@tag] = f.description;
1484 for (var j in f.indicator) {
1485 var ind = f.indicator[j];
1486 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1488 if (ind.@position == 1) {
1489 i1_popup.appendChild(
1491 { label : ind.@value,
1493 'current_focus.value = "' + ind.@value + '";' +
1494 'var e = document.createEvent("MutationEvents");' +
1495 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1496 'current_focus.inputField.dispatchEvent(e);',
1497 tooltiptext : ind.description }
1502 if (ind.@position == 2) {
1503 i2_popup.appendChild(
1505 { label : ind.@value,
1507 'current_focus.value = "' + ind.@value + '";' +
1508 'var e = document.createEvent("MutationEvents");' +
1509 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1510 'current_focus.inputField.dispatchEvent(e);',
1511 tooltiptext : ind.description }
1517 for (var j in f.subfield) {
1518 var sf = f.subfield[j];
1519 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1521 sf_popup.appendChild(
1525 'current_focus.value = "' + sf.@code + '";' +
1526 'var e = document.createEvent("MutationEvents");' +
1527 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1528 'current_focus.inputField.dispatchEvent(e);',
1529 tooltiptext : sf.description
1537 function getTooltip (target, type) {
1540 if (type == 'subfield')
1541 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1544 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1547 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1550 tt = 'tag' + target.parentNode.firstChild.value;
1552 if (!document.getElementById( tt )) {
1557 orient : 'vertical',
1558 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1559 class : 'tooltip' },
1560 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1565 target.tooltip = tt;
1569 function getContextMenu (target, type) {
1572 if (type == 'subfield')
1573 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1576 tt = 't' + target.parentNode.firstChild.value + 'i1';
1579 tt = 't' + target.parentNode.firstChild.value + 'i2';
1581 target.setAttribute('context', tt);
1585 var authority_tag_map = {
1586 100 : ['[100,400,500,700]',100],
1587 400 : ['[100,400,500,700]',100],
1588 700 : ['[100,400,500,700]',100],
1589 800 : ['[100,400,500,700]',100],
1590 110 : ['[110,410,510,710]',110],
1591 410 : ['[110,410,510,710]',110],
1592 710 : ['[110,410,510,710]',110],
1593 810 : ['[110,410,510,710]',110],
1594 111 : ['[111,411,511,711]',111],
1595 411 : ['[111,411,511,711]',111],
1596 711 : ['[111,411,511,711]',111],
1597 811 : ['[111,411,511,711]',111],
1598 240 : ['[130,430,530,730]',130],
1599 440 : ['[130,430,530,730]',130],
1600 130 : ['[130,430,530,730]',130],
1601 730 : ['[130,430,530,730]',130],
1602 830 : ['[130,430,530,730]',130],
1603 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1604 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1605 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1606 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1609 function getAuthorityContextMenu (target, sf) {
1610 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1612 var old = document.getElementById( menu_id );
1613 if (old) old.parentNode.removeChild(old);
1615 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1616 context_menus.appendChild( sf_popup );
1618 if (!authority_tag_map[sf.parent().@tag]) {
1619 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1620 target.setAttribute('context', 'clipboard');
1624 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1626 var res = new XML( auth_data.responseText );
1630 var recs = res.gw::payload.gw::array.gw::string;
1631 for (var i in recs) {
1633 var xml = new XML(x.toString());
1634 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1636 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1639 for (var i in main) {
1640 if (main_text) main_text += ' / ';
1641 main_text += main[i];
1644 rec_list.push( [ main_text, xml ] );
1647 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1649 var main_text = rec_list[i][0];
1650 var xml = rec_list[i][1];
1651 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1653 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1655 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1656 grid.setAttribute('name','-none-');
1657 grid.setAttribute('style','overflow:scroll');
1660 var submenu = createMenu( { label : main_text } );
1662 var popup = createMenuPopup({ flex : "1" });
1663 submenu.appendChild(popup);
1665 var fields = xml.datafield;
1666 for (var j in fields) {
1668 var row = createRow(
1670 createLabel( { value : fields[j].@tag } ),
1671 createLabel( { value : fields[j].@ind1 } ),
1672 createLabel( { value : fields[j].@ind2 } )
1675 var sf_box = createHbox();
1677 var subfields = fields[j].subfield;
1678 for (var k in subfields) {
1681 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1682 subfield : subfields[k].@code,
1683 tag : subfields[k].parent().@tag,
1684 value : subfields[k]
1688 row.appendChild(sf_box);
1691 grid.lastChild.appendChild(row);
1694 grid.hidden = false;
1695 popup.appendChild( grid );
1699 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1700 command : function (event) {
1701 applyAuthority(event.target.previousSibling, target, sf);
1708 sf_popup.appendChild( submenu );
1711 if (sf_popup.childNodes.length == 0)
1712 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1714 target.setAttribute('context', menu_id);
1718 function applyAuthority ( target, ui_sf, e4x_sf ) {
1720 var new_vals = target.getElementsByAttribute('checked','true');
1721 var field = e4x_sf.parent();
1723 for (var i = 0; i < new_vals.length; i++) {
1725 var sf_list = field.subfield;
1726 for (var j in sf_list) {
1728 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1729 sf_list[j] = new_vals[i].getAttribute('value');
1730 new_vals[i].setAttribute('subfield','');
1736 for (var i = 0; i < new_vals.length; i++) {
1737 if (!new_vals[i].getAttribute('subfield')) continue;
1739 var val = new_vals[i].getAttribute('value');
1741 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1742 sf.@code = new_vals[i].getAttribute('subfield');
1744 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1747 var row = marcDatafield( field );
1750 while (node.nodeName != 'row') {
1751 node = node.parentNode;
1754 node.parentNode.replaceChild( row, node );
1760 'a' : { 100 : 'a' },
1761 'd' : { 100 : 'd' },
1765 'a' : { 110 : 'a' },
1769 'a' : { 111 : 'a' },
1773 'a' : { 130 : 'a' },
1777 'a' : { 130 : 'a' },
1781 'a' : { 100 : 'a' },
1785 'a' : { 110 : 'a' },
1789 'a' : { 111 : 'a' },
1793 'a' : { 130 : 'a' },
1794 'n' : { 130 : 'n' },
1798 'a' : { 100 : 'a' },
1799 'd' : { 100 : 'd' },
1800 'q' : { 100 : 'q' },
1804 'a' : { 110 : 'a' },
1808 'a' : { 111 : 'a' },
1812 'a' : { 130 : 'a' },
1816 'a' : { 100 : 'a' },
1820 'a' : { 110 : 'a' },
1824 'a' : { 111 : 'a' },
1828 'a' : { 130 : 'a' },
1832 'a' : { 100 : 'a' },
1833 'd' : { 100 : 'd' },
1834 'q' : { 100 : 'q' },
1835 't' : { 100 : 't' },
1862 'a' : { 110 : 'a' },
1863 'd' : { 110 : 'd' },
1864 't' : { 110 : 't' },
1891 'a' : { 111 : 'a' },
1892 'd' : { 111 : 'd' },
1893 't' : { 111 : 't' },
1920 'a' : { 130 : 'a' },
1924 'a' : { 150 : 'a' },
1925 'b' : { 150 : 'b' },
1952 'a' : { 151 : 'a' },
1979 'a' : { 155 : 'a' },
2007 function validateAuthority (button) {
2008 var grid = document.getElementById('recGrid');
2009 var label = button.getAttribute('label');
2012 var rows = grid.lastChild.childNodes;
2013 for (var i = 0; i < rows.length; i++) {
2015 var tag = row.firstChild;
2017 if (!control_map[tag.value]) continue
2018 button.setAttribute('label', label + ' - ' + tag.value);
2020 var ind1 = tag.nextSibling;
2021 var ind2 = ind1.nextSibling;
2022 var subfields = ind2.nextSibling.childNodes;
2026 for (var j = 0; j < subfields.length; j++) {
2027 var sf = subfields[j];
2028 var sf_code = sf.childNodes[1].value;
2029 var sf_value = sf.childNodes[2].value;
2031 if (!control_map[tag.value][sf_code]) continue;
2034 for (var a_tag in control_map[tag.value][sf_code]) {
2035 if (!tags[a_tag]) tags[a_tag] = [];
2036 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2041 for (var val_tag in tags) {
2042 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2043 var res = new XML( auth_data.responseText );
2044 found = parseInt(res.gw::payload.gw::string.toString());
2048 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2049 for (var j = 0; j < subfields.length; j++) {
2050 var sf = subfields[j];
2052 sf.childNodes[2].inputField.style.color = 'red';
2054 sf.childNodes[2].inputField.style.color = 'black';
2059 button.setAttribute('label', label);
2065 function validateBibField (tags, searches) {
2066 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2067 url += '¶m="tags"¶m=' + js2JSON(tags);
2068 url += '¶m="searches"¶m=' + js2JSON(searches);
2071 var req = new XMLHttpRequest();
2072 req.open('GET',url,false);
2078 function searchAuthority (term, tag, sf, limit) {
2079 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2080 url += '¶m="term"¶m="' + term + '"';
2081 url += '¶m="limit"¶m=' + limit;
2082 url += '¶m="tag"¶m=' + tag;
2083 url += '¶m="subfield"¶m="' + sf + '"';
2086 var req = new XMLHttpRequest();
2087 req.open('GET',url,false);