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 // Find the next textbox that we can use for a focus point
343 // For control fields, use the first editable text box
344 // For data fields, focus on the first subfield text box
345 function setFocusToNextTag (row, direction) {
346 while (direction == 'up' ? row = row.previousSibling : row = row.nextSibling) {
347 var children = row.childNodes;
348 for (var i = 0; i < children.length; i++) {
349 // This would be way cleaner with dojo.query()
350 if (row.className == 'marcDatafieldRow') {
351 // marcSubfield lives in hbox.hbox.textbox
352 var hboxKids = children[i].childNodes;
353 if (children[i].tagName == 'hbox') {
354 for (var j = 0; j < hboxKids.length; j++) {
355 var msfBoxKids = hboxKids[j].childNodes;
356 if (hboxKids[j].className == 'marcSubfieldBox') {
357 for (var k = 0; k < msfBoxKids.length; k++) {
358 if (msfBoxKids[k].className == 'plain marcSubfield') {
359 msfBoxKids[k].focus();
368 if (children[i].tagName == 'textbox') {
379 function createMARCTextbox (element,attrs) {
381 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
382 box.onkeypress = function (event) {
385 while(node = node.parent()) {
389 var row = event.target;
390 while (row.tagName != 'row') row = row.parentNode;
392 if (element.nodeKind() == 'attribute') element[0]=box.value;
393 else element.setChildren( box.value );
395 if (element.localName() != 'controlfield') {
396 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
398 var index_sf, target, move_data;
399 if (element.localName() == 'subfield') {
401 target = event.target.parentNode;
403 var start = event.target.selectionStart;
404 var end = event.target.selectionEnd - event.target.selectionStart ?
405 event.target.selectionEnd :
406 event.target.value.length;
408 move_data = event.target.value.substring(start,end);
409 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
410 event.target.setAttribute('size', event.target.value.length + 2);
412 element.setChildren( event.target.value );
414 } else if (element.localName() == 'code') {
415 index_sf = element.parent();
416 target = event.target.parentNode;
417 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
418 index_sf = element.parent().children()[element.parent().children().length() - 1];
419 target = event.target.parentNode.lastChild.lastChild;
422 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
424 index_sf.parent().insertChildAfter( index_sf, sf );
426 var new_sf = marcSubfield(sf);
428 if (target === target.parentNode.lastChild) {
429 target.parentNode.appendChild( new_sf );
431 target.parentNode.insertBefore( new_sf, target.nextSibling );
434 new_sf.firstChild.nextSibling.focus();
436 event.preventDefault();
439 } else if (event.keyCode == 13 || event.keyCode == 77) {
440 if (event.ctrlKey) { // ctrl+enter
443 if (element.localName() == 'subfield') index = element.parent();
444 if (element.localName() == 'code') index = element.parent().parent();
445 if (element.localName() == 'tag') index = element.parent();
446 if (element.localName() == 'ind1') index = element.parent();
447 if (element.localName() == 'ind2') index = element.parent();
449 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
451 if (event.shiftKey) { // ctrl+shift+enter
452 index.parent().insertChildBefore( index, df );
454 index.parent().insertChildAfter( index, df );
457 var new_df = marcDatafield(df);
459 if (row.parentNode.lastChild === row) {
460 row.parentNode.appendChild( new_df );
462 if (event.shiftKey) { // ctrl+shift+enter
463 row.parentNode.insertBefore( new_df, row );
465 row.parentNode.insertBefore( new_df, row.nextSibling );
469 new_df.firstChild.focus();
471 event.preventDefault();
474 } else if (event.shiftKey) {
475 if (row.previousSibling.className.match('marcDatafieldRow'))
476 row.previousSibling.firstChild.focus();
478 row.nextSibling.firstChild.focus();
481 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
482 if (event.ctrlKey) { // CTRL key: copy the field
484 if (element.localName() == 'subfield') index = element.parent();
485 if (element.localName() == 'code') index = element.parent().parent();
486 if (element.localName() == 'tag') index = element.parent();
487 if (element.localName() == 'ind1') index = element.parent();
488 if (element.localName() == 'ind2') index = element.parent();
490 var copyField = index.copy();
492 if (event.keyCode == 38) { // ctrl+up-arrow
493 index.parent().insertChildBefore( index, copyField );
495 index.parent().insertChildAfter( index, copyField );
498 var new_df = marcDatafield(copyField);
500 if (row.parentNode.lastChild === row) {
501 row.parentNode.appendChild( new_df );
503 if (event.keyCode == 38) { // ctrl+up-arrow
504 row.parentNode.insertBefore( new_df, row );
505 } else { // ctrl+down-arrow
506 row.parentNode.insertBefore( new_df, row.nextSibling );
510 new_df.firstChild.focus();
512 event.preventDefault();
516 if (event.keyCode == 38) {
517 return setFocusToNextTag(row, 'up');
519 if (event.keyCode == 40) {
520 return setFocusToNextTag(row, 'down');
525 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
528 if (element.localName() == 'subfield') index = element.parent();
529 if (element.localName() == 'code') index = element.parent().parent();
530 if (element.localName() == 'tag') index = element.parent();
531 if (element.localName() == 'ind1') index = element.parent();
532 if (element.localName() == 'ind2') index = element.parent();
534 for (var i in index.parent().children()) {
535 if (index === index.parent().children()[i]) {
536 delete index.parent().children()[i];
541 row.previousSibling.firstChild.focus();
542 row.parentNode.removeChild(row);
544 event.preventDefault();
547 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
550 if (element.localName() == 'subfield') index = element;
551 if (element.localName() == 'code') index = element.parent();
554 for (var i in index.parent().children()) {
555 if (index === index.parent().children()[i]) {
556 delete index.parent().children()[i];
561 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
562 event.target.parentNode.previousSibling.lastChild.focus();
564 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
567 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
569 event.preventDefault();
572 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
573 createControlField('006',' ');
574 loadRecord(xml_record);
575 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
576 createControlField('007',' ');
577 loadRecord(xml_record);
578 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
579 createControlField('008',' ');
580 loadRecord(xml_record);
585 } else { // event on a control field
586 if (event.keyCode == 38) {
587 return setFocusToNextTag(row, 'up');
588 } else if (event.keyCode == 40) {
589 return setFocusToNextTag(row, 'down');
594 box.addEventListener(
597 if (element.nodeKind() == 'attribute') element[0]=box.value;
598 else element.setChildren( box.value );
604 box.addEventListener(
607 if (element.nodeKind() == 'attribute') element[0]=box.value;
608 else element.setChildren( box.value );
614 box.addEventListener(
617 if (element.nodeKind() == 'attribute') element[0]=box.value;
618 else element.setChildren( box.value );
624 box.addEventListener(
627 if (element.localName() == 'controlfield')
628 eval('fillFixedFields(xml_record);');
637 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
638 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
639 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
640 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
641 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
642 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
643 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
644 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
650 SCO : {start : 33, len : 1, def : ' ' },
651 REC : {start : 33, len : 1, def : 'n' }
654 SCO : {start : 16, len : 1, def : ' ' },
655 REC : {start : 16, len : 1, def : 'n' }
660 VIS : {start : 33, len : 1, def : ' ' }
663 VIS : {start : 16, len : 1, def : ' ' }
668 VIS : {start : 18, len : 3, def : ' ' }
671 VIS : {start : 1, len : 3, def : ' ' }
676 VIS : {start : 34, len : 1, def : 'n' }
679 VIS : {start : 17, len : 1, def : 'n' }
684 SER : {start : 21, len : 1, def : ' ' }
687 SER : {start : 4, len : 1, def : ' ' }
692 BKS : {start : 39, len : 1, def : 'd' },
693 SER : {start : 39, len : 1, def : 'd' },
694 VIS : {start : 39, len : 1, def : 'd' },
695 MIX : {start : 39, len : 1, def : 'd' },
696 MAP : {start : 39, len : 1, def : 'd' },
697 SCO : {start : 39, len : 1, def : 'd' },
698 REC : {start : 39, len : 1, def : 'd' },
699 COM : {start : 39, len : 1, def : 'd' }
704 MAP : {start : 33, len : 2, def : ' ' }
707 MAP : {start : 16, len : 2, def : ' ' }
712 MAP : {start : 18, len : 4, def : ' ' }
715 MAP : {start : 1, len : 4, def : ' ' }
720 SER : {start : 19, len : 1, def : ' ' }
723 SER : {start : 2, len : 1, def : ' ' }
728 MAP : {start : 22, len : 2, def : ' ' }
731 MAP : {start : 5, len : 2, def : ' ' }
736 SCO : {start : 21, len : 1, def : ' ' },
737 REC : {start : 21, len : 1, def : 'n' }
740 SCO : {start : 4, len : 1, def : ' ' },
741 REC : {start : 4, len : 1, def : 'n' }
746 SER : {start : 22, len : 1, def : ' ' }
749 SER : {start : 5, len : 1, def : ' ' }
754 SCO : {start : 30, len : 2, def : ' ' },
755 REC : {start : 30, len : 2, def : ' ' }
758 SCO : {start : 13, len : 2, def : ' ' },
759 REC : {start : 13, len : 2, def : ' ' }
764 SER : {start : 18, len : 1, def : ' ' }
767 SER : {start : 1, len : 1, def : ' ' }
772 SCO : {start : 20, len : 1, def : ' ' },
773 REC : {start : 20, len : 1, def : 'n' }
776 SCO : {start : 3, len : 1, def : ' ' },
777 REC : {start : 3, len : 1, def : 'n' }
782 COM : {start : 26, len : 1, def : 'u' }
785 COM : {start : 9, len : 1, def : 'u' }
790 SER : {start : 24, len : 1, def : ' ' }
793 SER : {start : 7, len : 1, def : ' ' }
798 SCO : {start : 24, len : 6, def : ' ' },
799 REC : {start : 24, len : 6, def : ' ' }
802 SCO : {start : 7, len : 6, def : ' ' },
803 REC : {start : 7, len : 6, def : ' ' }
808 SCO : {start : 18, len : 2, def : ' ' },
809 REC : {start : 18, len : 2, def : ' ' }
812 SCO : {start : 1, len : 2, def : ' ' },
813 REC : {start : 1, len : 2, def : ' ' }
818 MAP : {start : 25, len : 1, def : ' ' }
821 MAP : {start : 8, len : 1, def : ' ' }
826 BKS : {start : 15, len : 3, def : ' ' },
827 SER : {start : 15, len : 3, def : ' ' },
828 VIS : {start : 15, len : 3, def : ' ' },
829 MIX : {start : 15, len : 3, def : ' ' },
830 MAP : {start : 15, len : 3, def : ' ' },
831 SCO : {start : 15, len : 3, def : ' ' },
832 REC : {start : 15, len : 3, def : ' ' },
833 COM : {start : 15, len : 3, def : ' ' }
838 BKS : {start : 35, len : 3, def : ' ' },
839 SER : {start : 35, len : 3, def : ' ' },
840 VIS : {start : 35, len : 3, def : ' ' },
841 MIX : {start : 35, len : 3, def : ' ' },
842 MAP : {start : 35, len : 3, def : ' ' },
843 SCO : {start : 35, len : 3, def : ' ' },
844 REC : {start : 35, len : 3, def : ' ' },
845 COM : {start : 35, len : 3, def : ' ' }
850 BKS : {start : 38, len : 1, def : ' ' },
851 SER : {start : 38, len : 1, def : ' ' },
852 VIS : {start : 38, len : 1, def : ' ' },
853 MIX : {start : 38, len : 1, def : ' ' },
854 MAP : {start : 38, len : 1, def : ' ' },
855 SCO : {start : 38, len : 1, def : ' ' },
856 REC : {start : 38, len : 1, def : ' ' },
857 COM : {start : 38, len : 1, def : ' ' }
862 BKS : {start : 6, len : 1, def : ' ' },
863 SER : {start : 6, len : 1, def : 'c' },
864 VIS : {start : 6, len : 1, def : ' ' },
865 MIX : {start : 6, len : 1, def : ' ' },
866 MAP : {start : 6, len : 1, def : ' ' },
867 SCO : {start : 6, len : 1, def : ' ' },
868 REC : {start : 6, len : 1, def : ' ' },
869 COM : {start : 6, len : 1, def : ' ' }
874 BKS : {start : 6, len : 1, def : 'a' },
875 SER : {start : 6, len : 1, def : 'a' },
876 VIS : {start : 6, len : 1, def : 'g' },
877 MIX : {start : 6, len : 1, def : 'p' },
878 MAP : {start : 6, len : 1, def : 'e' },
879 SCO : {start : 6, len : 1, def : 'c' },
880 REC : {start : 6, len : 1, def : 'i' },
881 COM : {start : 6, len : 1, def : 'm' }
886 BKS : {start : 8, len : 1, def : ' ' },
887 SER : {start : 8, len : 1, def : ' ' },
888 VIS : {start : 8, len : 1, def : ' ' },
889 MIX : {start : 8, len : 1, def : ' ' },
890 MAP : {start : 8, len : 1, def : ' ' },
891 SCO : {start : 8, len : 1, def : ' ' },
892 REC : {start : 8, len : 1, def : ' ' },
893 COM : {start : 8, len : 1, def : ' ' }
898 BKS : {start : 7, len : 1, def : 'm' },
899 SER : {start : 7, len : 1, def : 's' },
900 VIS : {start : 7, len : 1, def : 'm' },
901 MIX : {start : 7, len : 1, def : 'c' },
902 MAP : {start : 7, len : 1, def : 'm' },
903 SCO : {start : 7, len : 1, def : 'm' },
904 REC : {start : 7, len : 1, def : 'm' },
905 COM : {start : 7, len : 1, def : 'm' }
910 BKS : {start : 18, len : 1, def : ' ' },
911 SER : {start : 18, len : 1, def : ' ' },
912 VIS : {start : 18, len : 1, def : ' ' },
913 MIX : {start : 18, len : 1, def : ' ' },
914 MAP : {start : 18, len : 1, def : ' ' },
915 SCO : {start : 18, len : 1, def : ' ' },
916 REC : {start : 18, len : 1, def : ' ' },
917 COM : {start : 18, len : 1, def : ' ' }
922 BKS : {start : 17, len : 1, def : ' ' },
923 SER : {start : 17, len : 1, def : ' ' },
924 VIS : {start : 17, len : 1, def : ' ' },
925 MIX : {start : 17, len : 1, def : ' ' },
926 MAP : {start : 17, len : 1, def : ' ' },
927 SCO : {start : 17, len : 1, def : ' ' },
928 REC : {start : 17, len : 1, def : ' ' },
929 COM : {start : 17, len : 1, def : ' ' }
934 BKS : {start : 31, len : 1, def : '0' },
935 MAP : {start : 31, len : 1, def : '0' }
938 BKS : {start : 14, len : 1, def : '0' },
939 MAP : {start : 14, len : 1, def : '0' }
944 BKS : {start : 7, len : 4, def : ' ' },
945 SER : {start : 7, len : 4, def : ' ' },
946 VIS : {start : 7, len : 4, def : ' ' },
947 MIX : {start : 7, len : 4, def : ' ' },
948 MAP : {start : 7, len : 4, def : ' ' },
949 SCO : {start : 7, len : 4, def : ' ' },
950 REC : {start : 7, len : 4, def : ' ' },
951 COM : {start : 7, len : 4, def : ' ' }
956 BKS : {start : 11, len : 4, def : ' ' },
957 SER : {start : 11, len : 4, def : '9' },
958 VIS : {start : 11, len : 4, def : ' ' },
959 MIX : {start : 11, len : 4, def : ' ' },
960 MAP : {start : 11, len : 4, def : ' ' },
961 SCO : {start : 11, len : 4, def : ' ' },
962 REC : {start : 11, len : 4, def : ' ' },
963 COM : {start : 11, len : 4, def : ' ' }
968 BKS : {start : 33, len : 1, def : '0' }
971 BKS : {start : 16, len : 1, def : '0' }
976 BKS : {start : 34, len : 1, def : ' ' }
979 BKS : {start : 17, len : 1, def : ' ' }
984 BKS : {start : 18, len : 4, def : ' ' }
987 BKS : {start : 1, len : 4, def : ' ' }
992 BKS : {start : 30, len : 1, def : '0' }
995 BKS : {start : 13, len : 1, def : '0' }
1000 BKS : {start : 29, len : 1, def : '0' },
1001 SER : {start : 29, len : 1, def : '0' }
1004 BKS : {start : 12, len : 1, def : '0' },
1005 SER : {start : 12, len : 1, def : '0' }
1010 BKS : {start : 24, len : 4, def : ' ' },
1011 SER : {start : 25, len : 3, def : ' ' }
1014 BKS : {start : 7, len : 4, def : ' ' },
1015 SER : {start : 8, len : 3, def : ' ' }
1020 BKS : {start : 28, len : 1, def : ' ' },
1021 SER : {start : 28, len : 1, def : ' ' },
1022 VIS : {start : 28, len : 1, def : ' ' },
1023 MAP : {start : 28, len : 1, def : ' ' },
1024 COM : {start : 28, len : 1, def : ' ' }
1027 BKS : {start : 11, len : 1, def : ' ' },
1028 SER : {start : 11, len : 1, def : ' ' },
1029 VIS : {start : 11, len : 1, def : ' ' },
1030 MAP : {start : 11, len : 1, def : ' ' },
1031 COM : {start : 11, len : 1, def : ' ' }
1036 BKS : {start : 22, len : 1, def : ' ' },
1037 SER : {start : 22, len : 1, def : ' ' },
1038 VIS : {start : 22, len : 1, def : ' ' },
1039 SCO : {start : 22, len : 1, def : ' ' },
1040 REC : {start : 22, len : 1, def : ' ' },
1041 COM : {start : 22, len : 1, def : ' ' }
1044 BKS : {start : 5, len : 1, def : ' ' },
1045 SER : {start : 5, len : 1, def : ' ' },
1046 VIS : {start : 5, len : 1, def : ' ' },
1047 SCO : {start : 5, len : 1, def : ' ' },
1048 REC : {start : 5, len : 1, def : ' ' },
1049 COM : {start : 5, len : 1, def : ' ' }
1054 BKS : {start : 23, len : 1, def : ' ' },
1055 SER : {start : 23, len : 1, def : ' ' },
1056 VIS : {start : 29, len : 1, def : ' ' },
1057 MIX : {start : 23, len : 1, def : ' ' },
1058 MAP : {start : 29, len : 1, def : ' ' },
1059 SCO : {start : 23, len : 1, def : ' ' },
1060 REC : {start : 23, len : 1, def : ' ' }
1063 BKS : {start : 6, len : 1, def : ' ' },
1064 SER : {start : 6, len : 1, def : ' ' },
1065 VIS : {start : 12, len : 1, def : ' ' },
1066 MIX : {start : 6, len : 1, def : ' ' },
1067 MAP : {start : 12, len : 1, def : ' ' },
1068 SCO : {start : 6, len : 1, def : ' ' },
1069 REC : {start : 6, len : 1, def : ' ' }
1074 SER : {start : 34, len : 1, def : '0' }
1077 SER : {start : 17, len : 1, def : '0' }
1082 SER : {start : 33, len : 1, def : ' ' }
1085 SER : {start : 16, len : 1, def : ' ' }
1090 function recordType (rec) {
1092 var _l = rec.leader.toString();
1094 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1095 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1097 for (var t in rec_type) {
1098 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1099 document.getElementById('recordTypeLabel').value = t;
1105 // in case we don't have a valid record type ...
1106 _record_type = 'BKS';
1107 return _record_type;
1110 alert('FIXME, MARC Editor, recordType: ' + E);
1114 function toggleFFE () {
1115 var grid = document.getElementById('leaderGrid');
1117 grid.hidden = false;
1124 function changeFFEditor (type) {
1125 var grid = document.getElementById('leaderGrid');
1126 grid.setAttribute('type',type);
1129 function fillFixedFields (rec) {
1131 var grid = document.getElementById('leaderGrid');
1133 var rtype = _record_type;
1135 var _l = rec.leader.toString();
1136 var _6 = rec.controlfield.(@tag=='006').toString();
1137 var _7 = rec.controlfield.(@tag=='007').toString();
1138 var _8 = rec.controlfield.(@tag=='008').toString();
1141 var pre_list = grid.getElementsByTagName('label');
1142 for (var i in pre_list) {
1143 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1144 list.push( pre_list[i] );
1148 for (var i in list) {
1149 var name = list[i].getAttribute('name');
1155 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1156 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1158 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1159 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1161 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1162 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1164 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1165 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1170 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1171 d = ff_pos[name].ldr[rtype].def;
1175 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1176 d = ff_pos[name]._8[rtype].def;
1180 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1181 d = ff_pos[name]._6[rtype].def;
1185 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1186 d = ff_pos[name]._7[rtype].def;
1191 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1197 list[i].nextSibling.value = value;
1202 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1206 function updateFixedFields (element) {
1207 var grid = document.getElementById('leaderGrid');
1208 var recGrid = document.getElementById('recGrid');
1210 var rtype = _record_type;
1211 var new_value = element.value;
1214 ldr : _record.leader,
1215 _6 : _record.controlfield.(@tag=='006'),
1216 _7 : _record.controlfield.(@tag=='007'),
1217 _8 : _record.controlfield.(@tag=='008')
1220 var name = element.getAttribute('name');
1221 for (var i in ff_pos[name]) {
1223 if (!ff_pos[name][i][rtype]) continue;
1225 // we're missing the required field. Add it now.
1228 if (i == '_6') newfield = '006';
1229 else if (i == '_7') newfield = '007';
1230 else if (i == '_8') newfield = '008';
1233 createControlField(newfield,' ');
1234 parts[i] = _record.controlfield.(@tag==newfield);
1237 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1238 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1240 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1241 new_value += ff_pos[name][i][rtype].def;
1244 parts[i].setChildren( before + new_value + after );
1245 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1251 function marcLeader (leader) {
1252 var row = createRow(
1253 { class : 'marcLeaderRow',
1258 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1261 class : 'marcInd1' } ),
1264 class : 'marcInd2' } ),
1266 { value : leader.text(),
1267 class : 'marcLeader' } )
1273 function marcControlfield (field) {
1274 tagname = field.@tag.toString().substr(2);
1276 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1278 { class : 'marcControlfieldRow',
1279 tag : '_' + tagname },
1281 { value : field.@tag,
1283 context : 'tags_popup',
1284 onmouseover : 'getTooltip(this, "tag");',
1285 tooltipid : 'tag' + field.@tag } ),
1287 { value : field.@ind1,
1289 onmouseover : 'getTooltip(this, "ind1");',
1290 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1292 { value : field.@ind2,
1294 onmouseover : 'getTooltip(this, "ind2");',
1295 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1298 { value : field.text(),
1299 class : 'plain marcEditableControlfield',
1300 name : 'CONTROL' + tagname,
1301 context : 'clipboard',
1307 { class : 'marcControlfieldRow',
1308 tag : '_' + tagname },
1310 { value : field.@tag,
1312 onmouseover : 'getTooltip(this, "tag");',
1313 tooltipid : 'tag' + field.@tag } ),
1315 { value : field.@ind1,
1317 onmouseover : 'getTooltip(this, "ind1");',
1318 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1320 { value : field.@ind2,
1322 onmouseover : 'getTooltip(this, "ind2");',
1323 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1325 { value : field.text(),
1326 class : 'marcControlfield' } )
1333 function stackSubfields(checkbox) {
1334 var list = document.getElementsByAttribute('name','sf_box');
1337 if (!checkbox.checked) o = 'horizontal';
1339 for (var i = 0; i < list.length; i++) {
1340 if (list[i]) list[i].setAttribute('orient',o);
1344 function fastItemAdd_toggle(checkbox) {
1345 var x = document.getElementById('fastItemAdd_textboxes');
1346 if (checkbox.checked) {
1348 document.getElementById('fastItemAdd_callnumber').focus();
1349 document.getElementById('fastItemAdd_callnumber').select();
1355 function fastItemAdd_attempt(doc_id) {
1357 if (typeof window.xulG.fast_add_item != 'function') { return; }
1358 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1359 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1360 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1361 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1362 document.getElementById('fastItemAdd_barcode').value = '';
1364 alert('fastItemAdd_attempt: ' + E);
1368 function save_attempt(xml_string) {
1370 var result = window.xulG.save.func( xml_string );
1372 if (result.id) fastItemAdd_attempt(result.id);
1373 if (typeof result.on_complete == 'function') result.on_complete();
1376 alert('save_attempt: ' + E);
1380 function marcDatafield (field) {
1381 var row = createRow(
1382 { class : 'marcDatafieldRow' },
1385 { value : field.@tag,
1386 class : 'plain marcTag',
1388 context : 'tags_popup',
1389 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1392 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1395 { value : field.@ind1,
1396 class : 'plain marcInd1',
1398 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1401 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1402 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1405 { value : field.@ind2,
1406 class : 'plain marcInd2',
1408 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1411 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1412 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1413 createHbox({ name : 'sf_box' })
1416 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1417 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1418 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1420 var sf_box = row.lastChild;
1421 if (document.getElementById('stackSubfields').checked)
1422 sf_box.setAttribute('orient','vertical');
1424 sf_box.addEventListener(
1427 if (sf_box === e.target) {
1428 sf_box.lastChild.lastChild.focus();
1429 } else if (e.target.parentNode === sf_box) {
1430 e.target.lastChild.focus();
1437 for (var i in field.subfield) {
1438 var sf = field.subfield[i];
1443 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1444 current_focus = sf_box.lastChild.childNodes[1];
1450 function marcSubfield (sf) {
1452 { class : 'marcSubfieldBox' },
1455 class : 'plain marcSubfieldDelimiter',
1456 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1457 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1458 //onclick : 'this.nextSibling.focus();',
1459 onfocus : 'this.nextSibling.focus();',
1464 class : 'plain marcSubfieldCode',
1465 name : 'marcSubfieldCode',
1466 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1467 oncontextmenu : 'getContextMenu(this, "subfield");',
1468 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1473 { value : sf.text(),
1474 name : sf.parent().@tag + ':' + sf.@code,
1475 class : 'plain marcSubfield',
1476 onmouseover : 'getTooltip(this, "subfield");',
1477 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1478 size : new String(sf.text()).length + 2,
1479 oninput : "this.setAttribute('size', this.value.length + 2);"
1484 function loadRecord(rec) {
1487 var grid_rows = document.getElementById('recGrid').lastChild;
1489 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1491 grid_rows.appendChild( marcLeader( rec.leader ) );
1493 for (var i in rec.controlfield) {
1494 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1497 for (var i in rec.datafield) {
1498 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1501 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1502 changeFFEditor(recordType(rec));
1503 fillFixedFields(rec);
1505 alert('FIXME, MARC Editor, loadRecord: ' + E);
1510 function genToolTips () {
1511 for (var i in bib_data.field) {
1512 var f = bib_data.field[i];
1514 tag_menu.appendChild(
1518 'current_focus.value = "' + f.@tag + '";' +
1519 'var e = document.createEvent("MutationEvents");' +
1520 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1521 'current_focus.inputField.dispatchEvent(e);',
1522 disabled : f.@tag < '010' ? "true" : "false",
1523 tooltiptext : f.description }
1527 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1528 context_menus.appendChild( i1_popup );
1530 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1531 context_menus.appendChild( i2_popup );
1533 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1534 context_menus.appendChild( sf_popup );
1536 tooltip_hash['tag' + f.@tag] = f.description;
1537 for (var j in f.indicator) {
1538 var ind = f.indicator[j];
1539 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1541 if (ind.@position == 1) {
1542 i1_popup.appendChild(
1544 { label : ind.@value,
1546 'current_focus.value = "' + ind.@value + '";' +
1547 'var e = document.createEvent("MutationEvents");' +
1548 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1549 'current_focus.inputField.dispatchEvent(e);',
1550 tooltiptext : ind.description }
1555 if (ind.@position == 2) {
1556 i2_popup.appendChild(
1558 { label : ind.@value,
1560 'current_focus.value = "' + ind.@value + '";' +
1561 'var e = document.createEvent("MutationEvents");' +
1562 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1563 'current_focus.inputField.dispatchEvent(e);',
1564 tooltiptext : ind.description }
1570 for (var j in f.subfield) {
1571 var sf = f.subfield[j];
1572 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1574 sf_popup.appendChild(
1578 'current_focus.value = "' + sf.@code + '";' +
1579 'var e = document.createEvent("MutationEvents");' +
1580 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1581 'current_focus.inputField.dispatchEvent(e);',
1582 tooltiptext : sf.description
1590 function getTooltip (target, type) {
1593 if (type == 'subfield')
1594 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1597 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1600 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1603 tt = 'tag' + target.parentNode.firstChild.value;
1605 if (!document.getElementById( tt )) {
1610 orient : 'vertical',
1611 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1612 class : 'tooltip' },
1613 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1618 target.tooltip = tt;
1622 function getContextMenu (target, type) {
1625 if (type == 'subfield')
1626 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1629 tt = 't' + target.parentNode.firstChild.value + 'i1';
1632 tt = 't' + target.parentNode.firstChild.value + 'i2';
1634 target.setAttribute('context', tt);
1638 var authority_tag_map = {
1639 100 : ['[100,400,500,700]',100],
1640 400 : ['[100,400,500,700]',100],
1641 700 : ['[100,400,500,700]',100],
1642 800 : ['[100,400,500,700]',100],
1643 110 : ['[110,410,510,710]',110],
1644 410 : ['[110,410,510,710]',110],
1645 710 : ['[110,410,510,710]',110],
1646 810 : ['[110,410,510,710]',110],
1647 111 : ['[111,411,511,711]',111],
1648 411 : ['[111,411,511,711]',111],
1649 711 : ['[111,411,511,711]',111],
1650 811 : ['[111,411,511,711]',111],
1651 240 : ['[130,430,530,730]',130],
1652 440 : ['[130,430,530,730]',130],
1653 130 : ['[130,430,530,730]',130],
1654 730 : ['[130,430,530,730]',130],
1655 830 : ['[130,430,530,730]',130],
1656 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1657 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1658 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1659 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1662 function getAuthorityContextMenu (target, sf) {
1663 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1665 var old = document.getElementById( menu_id );
1666 if (old) old.parentNode.removeChild(old);
1668 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1669 context_menus.appendChild( sf_popup );
1671 if (!authority_tag_map[sf.parent().@tag]) {
1672 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1673 target.setAttribute('context', 'clipboard');
1677 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1679 var res = new XML( auth_data.responseText );
1683 var recs = res.gw::payload.gw::array.gw::string;
1684 for (var i in recs) {
1686 var xml = new XML(x.toString());
1687 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1689 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1692 for (var i in main) {
1693 if (main_text) main_text += ' / ';
1694 main_text += main[i];
1697 rec_list.push( [ main_text, xml ] );
1700 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1702 var main_text = rec_list[i][0];
1703 var xml = rec_list[i][1];
1704 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1706 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1708 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1709 grid.setAttribute('name','-none-');
1710 grid.setAttribute('style','overflow:scroll');
1713 var submenu = createMenu( { label : main_text } );
1715 var popup = createMenuPopup({ flex : "1" });
1716 submenu.appendChild(popup);
1718 var fields = xml.datafield;
1719 for (var j in fields) {
1721 var row = createRow(
1723 createLabel( { value : fields[j].@tag } ),
1724 createLabel( { value : fields[j].@ind1 } ),
1725 createLabel( { value : fields[j].@ind2 } )
1728 var sf_box = createHbox();
1730 var subfields = fields[j].subfield;
1731 for (var k in subfields) {
1734 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1735 subfield : subfields[k].@code,
1736 tag : subfields[k].parent().@tag,
1737 value : subfields[k]
1741 row.appendChild(sf_box);
1744 grid.lastChild.appendChild(row);
1747 grid.hidden = false;
1748 popup.appendChild( grid );
1752 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1753 command : function (event) {
1754 applyAuthority(event.target.previousSibling, target, sf);
1761 sf_popup.appendChild( submenu );
1764 if (sf_popup.childNodes.length == 0)
1765 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1767 target.setAttribute('context', menu_id);
1771 function applyAuthority ( target, ui_sf, e4x_sf ) {
1773 var new_vals = target.getElementsByAttribute('checked','true');
1774 var field = e4x_sf.parent();
1776 for (var i = 0; i < new_vals.length; i++) {
1778 var sf_list = field.subfield;
1779 for (var j in sf_list) {
1781 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1782 sf_list[j] = new_vals[i].getAttribute('value');
1783 new_vals[i].setAttribute('subfield','');
1789 for (var i = 0; i < new_vals.length; i++) {
1790 if (!new_vals[i].getAttribute('subfield')) continue;
1792 var val = new_vals[i].getAttribute('value');
1794 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1795 sf.@code = new_vals[i].getAttribute('subfield');
1797 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1800 var row = marcDatafield( field );
1803 while (node.nodeName != 'row') {
1804 node = node.parentNode;
1807 node.parentNode.replaceChild( row, node );
1813 'a' : { 100 : 'a' },
1814 'd' : { 100 : 'd' },
1818 'a' : { 110 : 'a' },
1822 'a' : { 111 : 'a' },
1826 'a' : { 130 : 'a' },
1830 'a' : { 130 : 'a' },
1834 'a' : { 100 : 'a' },
1838 'a' : { 110 : 'a' },
1842 'a' : { 111 : 'a' },
1846 'a' : { 130 : 'a' },
1847 'n' : { 130 : 'n' },
1851 'a' : { 100 : 'a' },
1852 'd' : { 100 : 'd' },
1853 'q' : { 100 : 'q' },
1857 'a' : { 110 : 'a' },
1861 'a' : { 111 : 'a' },
1865 'a' : { 130 : 'a' },
1869 'a' : { 100 : 'a' },
1873 'a' : { 110 : 'a' },
1877 'a' : { 111 : 'a' },
1881 'a' : { 130 : 'a' },
1885 'a' : { 100 : 'a' },
1886 'd' : { 100 : 'd' },
1887 'q' : { 100 : 'q' },
1888 't' : { 100 : 't' },
1915 'a' : { 110 : 'a' },
1916 'd' : { 110 : 'd' },
1917 't' : { 110 : 't' },
1944 'a' : { 111 : 'a' },
1945 'd' : { 111 : 'd' },
1946 't' : { 111 : 't' },
1973 'a' : { 130 : 'a' },
1977 'a' : { 150 : 'a' },
1978 'b' : { 150 : 'b' },
2005 'a' : { 151 : 'a' },
2032 'a' : { 155 : 'a' },
2060 function validateAuthority (button) {
2061 var grid = document.getElementById('recGrid');
2062 var label = button.getAttribute('label');
2065 var rows = grid.lastChild.childNodes;
2066 for (var i = 0; i < rows.length; i++) {
2068 var tag = row.firstChild;
2070 if (!control_map[tag.value]) continue
2071 button.setAttribute('label', label + ' - ' + tag.value);
2073 var ind1 = tag.nextSibling;
2074 var ind2 = ind1.nextSibling;
2075 var subfields = ind2.nextSibling.childNodes;
2079 for (var j = 0; j < subfields.length; j++) {
2080 var sf = subfields[j];
2081 var sf_code = sf.childNodes[1].value;
2082 var sf_value = sf.childNodes[2].value;
2084 if (!control_map[tag.value][sf_code]) continue;
2087 for (var a_tag in control_map[tag.value][sf_code]) {
2088 if (!tags[a_tag]) tags[a_tag] = [];
2089 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2094 for (var val_tag in tags) {
2095 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2096 var res = new XML( auth_data.responseText );
2097 found = parseInt(res.gw::payload.gw::string.toString());
2101 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2102 for (var j = 0; j < subfields.length; j++) {
2103 var sf = subfields[j];
2105 sf.childNodes[2].inputField.style.color = 'red';
2107 sf.childNodes[2].inputField.style.color = 'black';
2112 button.setAttribute('label', label);
2118 function validateBibField (tags, searches) {
2119 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2120 url += '¶m="tags"¶m=' + js2JSON(tags);
2121 url += '¶m="searches"¶m=' + js2JSON(searches);
2124 var req = new XMLHttpRequest();
2125 req.open('GET',url,false);
2131 function searchAuthority (term, tag, sf, limit) {
2132 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2133 url += '¶m="term"¶m="' + term + '"';
2134 url += '¶m="limit"¶m=' + limit;
2135 url += '¶m="tag"¶m=' + tag;
2136 url += '¶m="subfield"¶m="' + sf + '"';
2139 var req = new XMLHttpRequest();
2140 req.open('GET',url,false);