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);
1128 // Hide FFEditor rows that we don't need for our current type
1129 // Again, this would be easier with dojo
1130 var row_list = grid.childNodes;
1132 for (var i = 0; i < row_list.length; i++) {
1133 if (row_list[i].nodeType && row_list[i].tagName == 'rows') {
1138 // If all of the labels for a given row do not include our
1139 // desired type in their set attribute, we can hide that row
1140 row_list = rows.childNodes;
1141 for (var i = 0; i < row_list.length; i++) {
1142 if (row_list[i].nodeType && row_list[i].tagName == 'row') {
1143 var label_list = row_list[i].childNodes;
1144 var found_type = false;
1145 for (var j = 0; j < label_list.length; j++) {
1146 if (label_list[j].nodeType &&
1147 label_list[j].tagName == 'label' &&
1148 label_list[j].getAttribute('set').indexOf(type) != -1) {
1153 row_list[i].hidden = true;
1159 function fillFixedFields (rec) {
1161 var grid = document.getElementById('leaderGrid');
1163 var rtype = _record_type;
1165 var _l = rec.leader.toString();
1166 var _6 = rec.controlfield.(@tag=='006').toString();
1167 var _7 = rec.controlfield.(@tag=='007').toString();
1168 var _8 = rec.controlfield.(@tag=='008').toString();
1171 var pre_list = grid.getElementsByTagName('label');
1172 for (var i in pre_list) {
1173 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1174 list.push( pre_list[i] );
1178 for (var i in list) {
1179 var name = list[i].getAttribute('name');
1185 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1186 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1188 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1189 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1191 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1192 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1194 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1195 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1200 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1201 d = ff_pos[name].ldr[rtype].def;
1205 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1206 d = ff_pos[name]._8[rtype].def;
1210 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1211 d = ff_pos[name]._6[rtype].def;
1215 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1216 d = ff_pos[name]._7[rtype].def;
1221 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1227 list[i].nextSibling.value = value;
1232 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1236 function updateFixedFields (element) {
1237 var grid = document.getElementById('leaderGrid');
1238 var recGrid = document.getElementById('recGrid');
1240 var rtype = _record_type;
1241 var new_value = element.value;
1244 ldr : _record.leader,
1245 _6 : _record.controlfield.(@tag=='006'),
1246 _7 : _record.controlfield.(@tag=='007'),
1247 _8 : _record.controlfield.(@tag=='008')
1250 var name = element.getAttribute('name');
1251 for (var i in ff_pos[name]) {
1253 if (!ff_pos[name][i][rtype]) continue;
1255 // we're missing the required field. Add it now.
1258 if (i == '_6') newfield = '006';
1259 else if (i == '_7') newfield = '007';
1260 else if (i == '_8') newfield = '008';
1263 createControlField(newfield,' ');
1264 parts[i] = _record.controlfield.(@tag==newfield);
1267 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1268 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1270 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1271 new_value += ff_pos[name][i][rtype].def;
1274 parts[i].setChildren( before + new_value + after );
1275 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1281 function marcLeader (leader) {
1282 var row = createRow(
1283 { class : 'marcLeaderRow',
1288 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1291 class : 'marcInd1' } ),
1294 class : 'marcInd2' } ),
1296 { value : leader.text(),
1297 class : 'marcLeader' } )
1303 function marcControlfield (field) {
1304 tagname = field.@tag.toString().substr(2);
1306 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1308 { class : 'marcControlfieldRow',
1309 tag : '_' + tagname },
1311 { value : field.@tag,
1313 context : 'tags_popup',
1314 onmouseover : 'getTooltip(this, "tag");',
1315 tooltipid : 'tag' + field.@tag } ),
1317 { value : field.@ind1,
1319 onmouseover : 'getTooltip(this, "ind1");',
1320 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1322 { value : field.@ind2,
1324 onmouseover : 'getTooltip(this, "ind2");',
1325 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1328 { value : field.text(),
1329 class : 'plain marcEditableControlfield',
1330 name : 'CONTROL' + tagname,
1331 context : 'clipboard',
1337 { class : 'marcControlfieldRow',
1338 tag : '_' + tagname },
1340 { value : field.@tag,
1342 onmouseover : 'getTooltip(this, "tag");',
1343 tooltipid : 'tag' + field.@tag } ),
1345 { value : field.@ind1,
1347 onmouseover : 'getTooltip(this, "ind1");',
1348 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1350 { value : field.@ind2,
1352 onmouseover : 'getTooltip(this, "ind2");',
1353 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1355 { value : field.text(),
1356 class : 'marcControlfield' } )
1363 function stackSubfields(checkbox) {
1364 var list = document.getElementsByAttribute('name','sf_box');
1367 if (!checkbox.checked) o = 'horizontal';
1369 for (var i = 0; i < list.length; i++) {
1370 if (list[i]) list[i].setAttribute('orient',o);
1374 function fastItemAdd_toggle(checkbox) {
1375 var x = document.getElementById('fastItemAdd_textboxes');
1376 if (checkbox.checked) {
1378 document.getElementById('fastItemAdd_callnumber').focus();
1379 document.getElementById('fastItemAdd_callnumber').select();
1385 function fastItemAdd_attempt(doc_id) {
1387 if (typeof window.xulG.fast_add_item != 'function') { return; }
1388 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1389 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1390 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1391 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1392 document.getElementById('fastItemAdd_barcode').value = '';
1394 alert('fastItemAdd_attempt: ' + E);
1398 function save_attempt(xml_string) {
1400 var result = window.xulG.save.func( xml_string );
1402 if (result.id) fastItemAdd_attempt(result.id);
1403 if (typeof result.on_complete == 'function') result.on_complete();
1406 alert('save_attempt: ' + E);
1410 function marcDatafield (field) {
1411 var row = createRow(
1412 { class : 'marcDatafieldRow' },
1415 { value : field.@tag,
1416 class : 'plain marcTag',
1418 context : 'tags_popup',
1419 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1422 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1425 { value : field.@ind1,
1426 class : 'plain marcInd1',
1428 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1431 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1432 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1435 { value : field.@ind2,
1436 class : 'plain marcInd2',
1438 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1441 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1442 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1443 createHbox({ name : 'sf_box' })
1446 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1447 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1448 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1450 var sf_box = row.lastChild;
1451 if (document.getElementById('stackSubfields').checked)
1452 sf_box.setAttribute('orient','vertical');
1454 sf_box.addEventListener(
1457 if (sf_box === e.target) {
1458 sf_box.lastChild.lastChild.focus();
1459 } else if (e.target.parentNode === sf_box) {
1460 e.target.lastChild.focus();
1467 for (var i in field.subfield) {
1468 var sf = field.subfield[i];
1473 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1474 current_focus = sf_box.lastChild.childNodes[1];
1480 function marcSubfield (sf) {
1482 { class : 'marcSubfieldBox' },
1485 class : 'plain marcSubfieldDelimiter',
1486 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1487 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1488 //onclick : 'this.nextSibling.focus();',
1489 onfocus : 'this.nextSibling.focus();',
1494 class : 'plain marcSubfieldCode',
1495 name : 'marcSubfieldCode',
1496 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1497 oncontextmenu : 'getContextMenu(this, "subfield");',
1498 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1503 { value : sf.text(),
1504 name : sf.parent().@tag + ':' + sf.@code,
1505 class : 'plain marcSubfield',
1506 onmouseover : 'getTooltip(this, "subfield");',
1507 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1508 size : new String(sf.text()).length + 2,
1509 oninput : "this.setAttribute('size', this.value.length + 2);"
1514 function loadRecord(rec) {
1517 var grid_rows = document.getElementById('recGrid').lastChild;
1519 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1521 grid_rows.appendChild( marcLeader( rec.leader ) );
1523 for (var i in rec.controlfield) {
1524 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1527 for (var i in rec.datafield) {
1528 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1531 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1532 changeFFEditor(recordType(rec));
1533 fillFixedFields(rec);
1535 alert('FIXME, MARC Editor, loadRecord: ' + E);
1540 function genToolTips () {
1541 for (var i in bib_data.field) {
1542 var f = bib_data.field[i];
1544 tag_menu.appendChild(
1548 'current_focus.value = "' + f.@tag + '";' +
1549 'var e = document.createEvent("MutationEvents");' +
1550 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1551 'current_focus.inputField.dispatchEvent(e);',
1552 disabled : f.@tag < '010' ? "true" : "false",
1553 tooltiptext : f.description }
1557 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1558 context_menus.appendChild( i1_popup );
1560 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1561 context_menus.appendChild( i2_popup );
1563 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1564 context_menus.appendChild( sf_popup );
1566 tooltip_hash['tag' + f.@tag] = f.description;
1567 for (var j in f.indicator) {
1568 var ind = f.indicator[j];
1569 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1571 if (ind.@position == 1) {
1572 i1_popup.appendChild(
1574 { label : ind.@value,
1576 'current_focus.value = "' + ind.@value + '";' +
1577 'var e = document.createEvent("MutationEvents");' +
1578 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1579 'current_focus.inputField.dispatchEvent(e);',
1580 tooltiptext : ind.description }
1585 if (ind.@position == 2) {
1586 i2_popup.appendChild(
1588 { label : ind.@value,
1590 'current_focus.value = "' + ind.@value + '";' +
1591 'var e = document.createEvent("MutationEvents");' +
1592 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1593 'current_focus.inputField.dispatchEvent(e);',
1594 tooltiptext : ind.description }
1600 for (var j in f.subfield) {
1601 var sf = f.subfield[j];
1602 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1604 sf_popup.appendChild(
1608 'current_focus.value = "' + sf.@code + '";' +
1609 'var e = document.createEvent("MutationEvents");' +
1610 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1611 'current_focus.inputField.dispatchEvent(e);',
1612 tooltiptext : sf.description
1620 function getTooltip (target, type) {
1623 if (type == 'subfield')
1624 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1627 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1630 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1633 tt = 'tag' + target.parentNode.firstChild.value;
1635 if (!document.getElementById( tt )) {
1640 orient : 'vertical',
1641 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1642 class : 'tooltip' },
1643 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1648 target.tooltip = tt;
1652 function getContextMenu (target, type) {
1655 if (type == 'subfield')
1656 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1659 tt = 't' + target.parentNode.firstChild.value + 'i1';
1662 tt = 't' + target.parentNode.firstChild.value + 'i2';
1664 target.setAttribute('context', tt);
1668 var authority_tag_map = {
1669 100 : ['[100,400,500,700]',100],
1670 400 : ['[100,400,500,700]',100],
1671 700 : ['[100,400,500,700]',100],
1672 800 : ['[100,400,500,700]',100],
1673 110 : ['[110,410,510,710]',110],
1674 410 : ['[110,410,510,710]',110],
1675 710 : ['[110,410,510,710]',110],
1676 810 : ['[110,410,510,710]',110],
1677 111 : ['[111,411,511,711]',111],
1678 411 : ['[111,411,511,711]',111],
1679 711 : ['[111,411,511,711]',111],
1680 811 : ['[111,411,511,711]',111],
1681 240 : ['[130,430,530,730]',130],
1682 440 : ['[130,430,530,730]',130],
1683 130 : ['[130,430,530,730]',130],
1684 730 : ['[130,430,530,730]',130],
1685 830 : ['[130,430,530,730]',130],
1686 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1687 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1688 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1689 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1692 function getAuthorityContextMenu (target, sf) {
1693 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1695 var old = document.getElementById( menu_id );
1696 if (old) old.parentNode.removeChild(old);
1698 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1699 context_menus.appendChild( sf_popup );
1701 if (!authority_tag_map[sf.parent().@tag]) {
1702 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1703 target.setAttribute('context', 'clipboard');
1707 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1709 var res = new XML( auth_data.responseText );
1713 var recs = res.gw::payload.gw::array.gw::string;
1714 for (var i in recs) {
1716 var xml = new XML(x.toString());
1717 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1719 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1722 for (var i in main) {
1723 if (main_text) main_text += ' / ';
1724 main_text += main[i];
1727 rec_list.push( [ main_text, xml ] );
1730 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1732 var main_text = rec_list[i][0];
1733 var xml = rec_list[i][1];
1734 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1736 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1738 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1739 grid.setAttribute('name','-none-');
1740 grid.setAttribute('style','overflow:scroll');
1743 var submenu = createMenu( { label : main_text } );
1745 var popup = createMenuPopup({ flex : "1" });
1746 submenu.appendChild(popup);
1748 var fields = xml.datafield;
1749 for (var j in fields) {
1751 var row = createRow(
1753 createLabel( { value : fields[j].@tag } ),
1754 createLabel( { value : fields[j].@ind1 } ),
1755 createLabel( { value : fields[j].@ind2 } )
1758 var sf_box = createHbox();
1760 var subfields = fields[j].subfield;
1761 for (var k in subfields) {
1764 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1765 subfield : subfields[k].@code,
1766 tag : subfields[k].parent().@tag,
1767 value : subfields[k]
1771 row.appendChild(sf_box);
1774 grid.lastChild.appendChild(row);
1777 grid.hidden = false;
1778 popup.appendChild( grid );
1782 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1783 command : function (event) {
1784 applyAuthority(event.target.previousSibling, target, sf);
1791 sf_popup.appendChild( submenu );
1794 if (sf_popup.childNodes.length == 0)
1795 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1797 target.setAttribute('context', menu_id);
1801 function applyAuthority ( target, ui_sf, e4x_sf ) {
1803 var new_vals = target.getElementsByAttribute('checked','true');
1804 var field = e4x_sf.parent();
1806 for (var i = 0; i < new_vals.length; i++) {
1808 var sf_list = field.subfield;
1809 for (var j in sf_list) {
1811 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1812 sf_list[j] = new_vals[i].getAttribute('value');
1813 new_vals[i].setAttribute('subfield','');
1819 for (var i = 0; i < new_vals.length; i++) {
1820 if (!new_vals[i].getAttribute('subfield')) continue;
1822 var val = new_vals[i].getAttribute('value');
1824 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1825 sf.@code = new_vals[i].getAttribute('subfield');
1827 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1830 var row = marcDatafield( field );
1833 while (node.nodeName != 'row') {
1834 node = node.parentNode;
1837 node.parentNode.replaceChild( row, node );
1843 'a' : { 100 : 'a' },
1844 'd' : { 100 : 'd' },
1848 'a' : { 110 : 'a' },
1852 'a' : { 111 : 'a' },
1856 'a' : { 130 : 'a' },
1860 'a' : { 130 : 'a' },
1864 'a' : { 100 : 'a' },
1868 'a' : { 110 : 'a' },
1872 'a' : { 111 : 'a' },
1876 'a' : { 130 : 'a' },
1877 'n' : { 130 : 'n' },
1881 'a' : { 100 : 'a' },
1882 'd' : { 100 : 'd' },
1883 'q' : { 100 : 'q' },
1887 'a' : { 110 : 'a' },
1891 'a' : { 111 : 'a' },
1895 'a' : { 130 : 'a' },
1899 'a' : { 100 : 'a' },
1903 'a' : { 110 : 'a' },
1907 'a' : { 111 : 'a' },
1911 'a' : { 130 : 'a' },
1915 'a' : { 100 : 'a' },
1916 'd' : { 100 : 'd' },
1917 'q' : { 100 : 'q' },
1918 't' : { 100 : 't' },
1945 'a' : { 110 : 'a' },
1946 'd' : { 110 : 'd' },
1947 't' : { 110 : 't' },
1974 'a' : { 111 : 'a' },
1975 'd' : { 111 : 'd' },
1976 't' : { 111 : 't' },
2003 'a' : { 130 : 'a' },
2007 'a' : { 150 : 'a' },
2008 'b' : { 150 : 'b' },
2035 'a' : { 151 : 'a' },
2062 'a' : { 155 : 'a' },
2090 function validateAuthority (button) {
2091 var grid = document.getElementById('recGrid');
2092 var label = button.getAttribute('label');
2095 var rows = grid.lastChild.childNodes;
2096 for (var i = 0; i < rows.length; i++) {
2098 var tag = row.firstChild;
2100 if (!control_map[tag.value]) continue
2101 button.setAttribute('label', label + ' - ' + tag.value);
2103 var ind1 = tag.nextSibling;
2104 var ind2 = ind1.nextSibling;
2105 var subfields = ind2.nextSibling.childNodes;
2109 for (var j = 0; j < subfields.length; j++) {
2110 var sf = subfields[j];
2111 var sf_code = sf.childNodes[1].value;
2112 var sf_value = sf.childNodes[2].value;
2114 if (!control_map[tag.value][sf_code]) continue;
2117 for (var a_tag in control_map[tag.value][sf_code]) {
2118 if (!tags[a_tag]) tags[a_tag] = [];
2119 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2124 for (var val_tag in tags) {
2125 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2126 var res = new XML( auth_data.responseText );
2127 found = parseInt(res.gw::payload.gw::string.toString());
2131 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2132 for (var j = 0; j < subfields.length; j++) {
2133 var sf = subfields[j];
2135 sf.childNodes[2].inputField.style.color = 'red';
2137 sf.childNodes[2].inputField.style.color = 'black';
2142 button.setAttribute('label', label);
2148 function validateBibField (tags, searches) {
2149 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2150 url += '¶m="tags"¶m=' + js2JSON(tags);
2151 url += '¶m="searches"¶m=' + js2JSON(searches);
2154 var req = new XMLHttpRequest();
2155 req.open('GET',url,false);
2161 function searchAuthority (term, tag, sf, limit) {
2162 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2163 url += '¶m="term"¶m="' + term + '"';
2164 url += '¶m="limit"¶m=' + limit;
2165 url += '¶m="tag"¶m=' + tag;
2166 url += '¶m="subfield"¶m="' + sf + '"';
2169 var req = new XMLHttpRequest();
2170 req.open('GET',url,false);