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) + ";"; }
81 function swap_editors () {
83 dojo.require('MARC.Record');
85 var xe = $('xul-editor');
86 var te = $('text-editor');
88 te.hidden = te.hidden ? false : true;
89 xe.hidden = xe.hidden ? false : true;
92 // get the marcxml from the text box
93 var xml_string = new MARC.Record({
94 marcbreaker : $('text-editor-box').value,
98 // reset the xml record and rerender it
99 xml_record = new XML( xml_string );
100 loadRecord(xml_record);
102 var xml_string = xml_record.toXMLString();
104 // push the xml record into the textbox
105 var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
106 $('text-editor-box').value = rec.toBreaker();
114 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
115 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
116 JSAN.errorLevel = "die"; // none, warn, or die
117 JSAN.addRepository('/xul/server/');
119 // Fake xulG for standalone...
124 window.xulG.record = {};
125 window.xulG.save = {};
127 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
128 window.xulG.save.func = function (r) { alert(r); }
131 var _rid = cgi.param('record');
133 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
136 // End faking part...
138 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
139 document.getElementById('save-button').setAttribute('oncommand',
140 'if ($("xul-editor").hidden) swap_editors(); ' +
142 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
143 'save_attempt( xml_string ); ' +
144 'loadRecord(xml_record);'
147 if (window.xulG.record.url) {
148 var req = new XMLHttpRequest();
149 req.open('POST',window.xulG.record.url,false);
151 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
154 xml_record = new XML( window.xulG.record.marc );
155 if (xml_record..record[0]) xml_record = xml_record..record[0];
157 // Get the tooltip xml all async like
158 req = new XMLHttpRequest();
160 // Set a default locale in case preferences fail us
161 var locale = "en-US";
163 // Try to get the locale from our preferences
164 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
166 const Cc = Components.classes;
167 const Ci = Components.interfaces;
168 locale = Cc["@mozilla.org/preferences-service;1"].
169 getService(Ci.nsIPrefBranch).
170 getCharPref("general.useragent.locale");
174 // TODO: We should send a HEAD request to check for the existence of the desired file
175 // then fall back to the default locale if preferred locale is not necessary;
176 // however, for now we have a simplistic check:
178 // we currently have translations for only two locales; in the absence of a
179 // valid locale, default to the almighty en-US
180 if (locale != 'en-US' && locale != 'fr-CA') {
184 // Get the locale-specific tooltips
185 req.open('GET','/xul/server/locale/' + locale + '/marcedit-tooltips.xml',true);
187 context_menus = createComplexXULElement('popupset');
188 document.documentElement.appendChild( context_menus );
190 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
191 context_menus.appendChild( tag_menu );
193 tag_menu.appendChild(
195 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
197 'var e = document.createEvent("KeyEvents");' +
198 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
199 'current_focus.inputField.dispatchEvent(e);'
204 tag_menu.appendChild(
206 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
208 'var e = document.createEvent("KeyEvents");' +
209 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
210 'current_focus.inputField.dispatchEvent(e);'
215 tag_menu.appendChild(
217 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
219 'var e = document.createEvent("KeyEvents");' +
220 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
221 'current_focus.inputField.dispatchEvent(e);'
226 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
228 tag_menu.appendChild(
230 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
232 'var e = document.createEvent("KeyEvents");' +
233 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
234 'current_focus.inputField.dispatchEvent(e);'
239 tag_menu.appendChild(
241 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
243 'var e = document.createEvent("KeyEvents");' +
244 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
245 'current_focus.inputField.dispatchEvent(e);'
250 tag_menu.appendChild(
252 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
254 'var e = document.createEvent("KeyEvents");' +
255 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
256 'current_focus.inputField.dispatchEvent(e);'
261 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
263 p = createComplexXULElement('popupset');
264 document.documentElement.appendChild( p );
266 req.onreadystatechange = function () {
267 if (req.readyState == 4) {
268 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
274 loadRecord(xml_record);
276 if (! xulG.fast_add_item) {
277 document.getElementById('fastItemAdd_checkbox').hidden = true;
279 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
282 alert('FIXME, MARC Editor, my_init: ' + E);
287 function createComplexHTMLElement (e, attrs, objects, text) {
288 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
291 for (var i in attrs) l.setAttribute(i,attrs[i]);
295 for ( var i in objects ) l.appendChild( objects[i] );
299 l.appendChild( document.createTextNode(text) )
305 function createComplexXULElement (e, attrs, objects) {
306 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
309 for (var i in attrs) {
310 if (typeof attrs[i] == 'function') {
311 l.addEventListener( i, attrs[i], true );
313 l.setAttribute(i,attrs[i]);
319 for ( var i in objects ) l.appendChild( objects[i] );
325 function createDescription (attrs) {
326 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
329 function createTooltip (attrs) {
330 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
333 function createLabel (attrs) {
334 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
337 function createVbox (attrs) {
338 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
341 function createHbox (attrs) {
342 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
345 function createRow (attrs) {
346 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
349 function createTextbox (attrs) {
350 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
353 function createMenu (attrs) {
354 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
357 function createMenuPopup (attrs) {
358 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
361 function createPopup (attrs) {
362 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
365 function createMenuitem (attrs) {
366 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
369 function createCheckbox (attrs) {
370 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
373 // Find the next textbox that we can use for a focus point
374 // For control fields, use the first editable text box
375 // For data fields, focus on the first subfield text box
376 function setFocusToNextTag (row, direction) {
377 while (direction == 'up' ? row = row.previousSibling : row = row.nextSibling) {
378 var children = row.childNodes;
379 for (var i = 0; i < children.length; i++) {
380 // This would be way cleaner with dojo.query()
381 if (row.className == 'marcDatafieldRow') {
382 // marcSubfield lives in hbox.hbox.textbox
383 var hboxKids = children[i].childNodes;
384 if (children[i].tagName == 'hbox') {
385 for (var j = 0; j < hboxKids.length; j++) {
386 var msfBoxKids = hboxKids[j].childNodes;
387 if (hboxKids[j].className == 'marcSubfieldBox') {
388 for (var k = 0; k < msfBoxKids.length; k++) {
389 if (msfBoxKids[k].className == 'plain marcSubfield') {
390 msfBoxKids[k].focus();
399 if (children[i].tagName == 'textbox') {
410 function createMARCTextbox (element,attrs) {
412 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
413 box.onkeypress = function (event) {
416 while(node = node.parent()) {
420 var row = event.target;
421 while (row.tagName != 'row') row = row.parentNode;
423 if (element.nodeKind() == 'attribute') element[0]=box.value;
424 else element.setChildren( box.value );
426 if (element.localName() != 'controlfield') {
427 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
429 var index_sf, target, move_data;
430 if (element.localName() == 'subfield') {
432 target = event.target.parentNode;
434 var start = event.target.selectionStart;
435 var end = event.target.selectionEnd - event.target.selectionStart ?
436 event.target.selectionEnd :
437 event.target.value.length;
439 move_data = event.target.value.substring(start,end);
440 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
441 event.target.setAttribute('size', event.target.value.length + 2);
443 element.setChildren( event.target.value );
445 } else if (element.localName() == 'code') {
446 index_sf = element.parent();
447 target = event.target.parentNode;
448 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
449 index_sf = element.parent().children()[element.parent().children().length() - 1];
450 target = event.target.parentNode.lastChild.lastChild;
453 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
455 index_sf.parent().insertChildAfter( index_sf, sf );
457 var new_sf = marcSubfield(sf);
459 if (target === target.parentNode.lastChild) {
460 target.parentNode.appendChild( new_sf );
462 target.parentNode.insertBefore( new_sf, target.nextSibling );
465 new_sf.firstChild.nextSibling.focus();
467 event.preventDefault();
470 } else if (event.keyCode == 13 || event.keyCode == 77) {
471 if (event.ctrlKey) { // ctrl+enter
474 if (element.localName() == 'subfield') index = element.parent();
475 if (element.localName() == 'code') index = element.parent().parent();
476 if (element.localName() == 'tag') index = element.parent();
477 if (element.localName() == 'ind1') index = element.parent();
478 if (element.localName() == 'ind2') index = element.parent();
480 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
482 if (event.shiftKey) { // ctrl+shift+enter
483 index.parent().insertChildBefore( index, df );
485 index.parent().insertChildAfter( index, df );
488 var new_df = marcDatafield(df);
490 if (row.parentNode.lastChild === row) {
491 row.parentNode.appendChild( new_df );
493 if (event.shiftKey) { // ctrl+shift+enter
494 row.parentNode.insertBefore( new_df, row );
496 row.parentNode.insertBefore( new_df, row.nextSibling );
500 new_df.firstChild.focus();
502 event.preventDefault();
505 } else if (event.shiftKey) {
506 if (row.previousSibling.className.match('marcDatafieldRow'))
507 row.previousSibling.firstChild.focus();
509 row.nextSibling.firstChild.focus();
512 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
513 if (event.ctrlKey) { // CTRL key: copy the field
515 if (element.localName() == 'subfield') index = element.parent();
516 if (element.localName() == 'code') index = element.parent().parent();
517 if (element.localName() == 'tag') index = element.parent();
518 if (element.localName() == 'ind1') index = element.parent();
519 if (element.localName() == 'ind2') index = element.parent();
521 var copyField = index.copy();
523 if (event.keyCode == 38) { // ctrl+up-arrow
524 index.parent().insertChildBefore( index, copyField );
526 index.parent().insertChildAfter( index, copyField );
529 var new_df = marcDatafield(copyField);
531 if (row.parentNode.lastChild === row) {
532 row.parentNode.appendChild( new_df );
534 if (event.keyCode == 38) { // ctrl+up-arrow
535 row.parentNode.insertBefore( new_df, row );
536 } else { // ctrl+down-arrow
537 row.parentNode.insertBefore( new_df, row.nextSibling );
541 new_df.firstChild.focus();
543 event.preventDefault();
547 if (event.keyCode == 38) {
548 return setFocusToNextTag(row, 'up');
550 if (event.keyCode == 40) {
551 return setFocusToNextTag(row, 'down');
556 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
559 if (element.localName() == 'subfield') index = element.parent();
560 if (element.localName() == 'code') index = element.parent().parent();
561 if (element.localName() == 'tag') index = element.parent();
562 if (element.localName() == 'ind1') index = element.parent();
563 if (element.localName() == 'ind2') index = element.parent();
565 for (var i in index.parent().children()) {
566 if (index === index.parent().children()[i]) {
567 delete index.parent().children()[i];
572 row.previousSibling.firstChild.focus();
573 row.parentNode.removeChild(row);
575 event.preventDefault();
578 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
581 if (element.localName() == 'subfield') index = element;
582 if (element.localName() == 'code') index = element.parent();
585 for (var i in index.parent().children()) {
586 if (index === index.parent().children()[i]) {
587 delete index.parent().children()[i];
592 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
593 event.target.parentNode.previousSibling.lastChild.focus();
595 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
598 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
600 event.preventDefault();
603 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
604 createControlField('006',' ');
605 loadRecord(xml_record);
606 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
607 createControlField('007',' ');
608 loadRecord(xml_record);
609 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
610 createControlField('008',' ');
611 loadRecord(xml_record);
616 } else { // event on a control field
617 if (event.keyCode == 38) {
618 return setFocusToNextTag(row, 'up');
619 } else if (event.keyCode == 40) {
620 return setFocusToNextTag(row, 'down');
625 box.addEventListener(
628 if (element.nodeKind() == 'attribute') element[0]=box.value;
629 else element.setChildren( box.value );
635 box.addEventListener(
638 if (element.nodeKind() == 'attribute') element[0]=box.value;
639 else element.setChildren( box.value );
645 box.addEventListener(
648 if (element.nodeKind() == 'attribute') element[0]=box.value;
649 else element.setChildren( box.value );
655 box.addEventListener(
658 if (element.localName() == 'controlfield')
659 eval('fillFixedFields(xml_record);');
668 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
669 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
670 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
671 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
672 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
673 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
674 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
675 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
681 SCO : {start : 33, len : 1, def : ' ' },
682 REC : {start : 33, len : 1, def : 'n' }
685 SCO : {start : 16, len : 1, def : ' ' },
686 REC : {start : 16, len : 1, def : 'n' }
691 VIS : {start : 33, len : 1, def : ' ' }
694 VIS : {start : 16, len : 1, def : ' ' }
699 VIS : {start : 18, len : 3, def : ' ' }
702 VIS : {start : 1, len : 3, def : ' ' }
707 VIS : {start : 34, len : 1, def : 'n' }
710 VIS : {start : 17, len : 1, def : 'n' }
715 SER : {start : 21, len : 1, def : ' ' }
718 SER : {start : 4, len : 1, def : ' ' }
723 BKS : {start : 39, len : 1, def : 'd' },
724 SER : {start : 39, len : 1, def : 'd' },
725 VIS : {start : 39, len : 1, def : 'd' },
726 MIX : {start : 39, len : 1, def : 'd' },
727 MAP : {start : 39, len : 1, def : 'd' },
728 SCO : {start : 39, len : 1, def : 'd' },
729 REC : {start : 39, len : 1, def : 'd' },
730 COM : {start : 39, len : 1, def : 'd' }
735 MAP : {start : 33, len : 2, def : ' ' }
738 MAP : {start : 16, len : 2, def : ' ' }
743 MAP : {start : 18, len : 4, def : ' ' }
746 MAP : {start : 1, len : 4, def : ' ' }
751 SER : {start : 19, len : 1, def : ' ' }
754 SER : {start : 2, len : 1, def : ' ' }
759 MAP : {start : 22, len : 2, def : ' ' }
762 MAP : {start : 5, len : 2, def : ' ' }
767 SCO : {start : 21, len : 1, def : ' ' },
768 REC : {start : 21, len : 1, def : 'n' }
771 SCO : {start : 4, len : 1, def : ' ' },
772 REC : {start : 4, len : 1, def : 'n' }
777 SER : {start : 22, len : 1, def : ' ' }
780 SER : {start : 5, len : 1, def : ' ' }
785 SCO : {start : 30, len : 2, def : ' ' },
786 REC : {start : 30, len : 2, def : ' ' }
789 SCO : {start : 13, len : 2, def : ' ' },
790 REC : {start : 13, len : 2, def : ' ' }
795 SER : {start : 18, len : 1, def : ' ' }
798 SER : {start : 1, len : 1, def : ' ' }
803 SCO : {start : 20, len : 1, def : ' ' },
804 REC : {start : 20, len : 1, def : 'n' }
807 SCO : {start : 3, len : 1, def : ' ' },
808 REC : {start : 3, len : 1, def : 'n' }
813 COM : {start : 26, len : 1, def : 'u' }
816 COM : {start : 9, len : 1, def : 'u' }
821 SER : {start : 24, len : 1, def : ' ' }
824 SER : {start : 7, len : 1, def : ' ' }
829 SCO : {start : 24, len : 6, def : ' ' },
830 REC : {start : 24, len : 6, def : ' ' }
833 SCO : {start : 7, len : 6, def : ' ' },
834 REC : {start : 7, len : 6, def : ' ' }
839 SCO : {start : 18, len : 2, def : ' ' },
840 REC : {start : 18, len : 2, def : ' ' }
843 SCO : {start : 1, len : 2, def : ' ' },
844 REC : {start : 1, len : 2, def : ' ' }
849 MAP : {start : 25, len : 1, def : ' ' }
852 MAP : {start : 8, len : 1, def : ' ' }
857 BKS : {start : 15, len : 3, def : ' ' },
858 SER : {start : 15, len : 3, def : ' ' },
859 VIS : {start : 15, len : 3, def : ' ' },
860 MIX : {start : 15, len : 3, def : ' ' },
861 MAP : {start : 15, len : 3, def : ' ' },
862 SCO : {start : 15, len : 3, def : ' ' },
863 REC : {start : 15, len : 3, def : ' ' },
864 COM : {start : 15, len : 3, def : ' ' }
869 BKS : {start : 35, len : 3, def : ' ' },
870 SER : {start : 35, len : 3, def : ' ' },
871 VIS : {start : 35, len : 3, def : ' ' },
872 MIX : {start : 35, len : 3, def : ' ' },
873 MAP : {start : 35, len : 3, def : ' ' },
874 SCO : {start : 35, len : 3, def : ' ' },
875 REC : {start : 35, len : 3, def : ' ' },
876 COM : {start : 35, len : 3, def : ' ' }
881 BKS : {start : 38, len : 1, def : ' ' },
882 SER : {start : 38, len : 1, def : ' ' },
883 VIS : {start : 38, len : 1, def : ' ' },
884 MIX : {start : 38, len : 1, def : ' ' },
885 MAP : {start : 38, len : 1, def : ' ' },
886 SCO : {start : 38, len : 1, def : ' ' },
887 REC : {start : 38, len : 1, def : ' ' },
888 COM : {start : 38, len : 1, def : ' ' }
893 BKS : {start : 6, len : 1, def : ' ' },
894 SER : {start : 6, len : 1, def : 'c' },
895 VIS : {start : 6, len : 1, def : ' ' },
896 MIX : {start : 6, len : 1, def : ' ' },
897 MAP : {start : 6, len : 1, def : ' ' },
898 SCO : {start : 6, len : 1, def : ' ' },
899 REC : {start : 6, len : 1, def : ' ' },
900 COM : {start : 6, len : 1, def : ' ' }
905 BKS : {start : 6, len : 1, def : 'a' },
906 SER : {start : 6, len : 1, def : 'a' },
907 VIS : {start : 6, len : 1, def : 'g' },
908 MIX : {start : 6, len : 1, def : 'p' },
909 MAP : {start : 6, len : 1, def : 'e' },
910 SCO : {start : 6, len : 1, def : 'c' },
911 REC : {start : 6, len : 1, def : 'i' },
912 COM : {start : 6, len : 1, def : 'm' }
917 BKS : {start : 8, len : 1, def : ' ' },
918 SER : {start : 8, len : 1, def : ' ' },
919 VIS : {start : 8, len : 1, def : ' ' },
920 MIX : {start : 8, len : 1, def : ' ' },
921 MAP : {start : 8, len : 1, def : ' ' },
922 SCO : {start : 8, len : 1, def : ' ' },
923 REC : {start : 8, len : 1, def : ' ' },
924 COM : {start : 8, len : 1, def : ' ' }
929 BKS : {start : 7, len : 1, def : 'm' },
930 SER : {start : 7, len : 1, def : 's' },
931 VIS : {start : 7, len : 1, def : 'm' },
932 MIX : {start : 7, len : 1, def : 'c' },
933 MAP : {start : 7, len : 1, def : 'm' },
934 SCO : {start : 7, len : 1, def : 'm' },
935 REC : {start : 7, len : 1, def : 'm' },
936 COM : {start : 7, len : 1, def : 'm' }
941 BKS : {start : 18, len : 1, def : ' ' },
942 SER : {start : 18, len : 1, def : ' ' },
943 VIS : {start : 18, len : 1, def : ' ' },
944 MIX : {start : 18, len : 1, def : ' ' },
945 MAP : {start : 18, len : 1, def : ' ' },
946 SCO : {start : 18, len : 1, def : ' ' },
947 REC : {start : 18, len : 1, def : ' ' },
948 COM : {start : 18, len : 1, def : ' ' }
953 BKS : {start : 17, len : 1, def : ' ' },
954 SER : {start : 17, len : 1, def : ' ' },
955 VIS : {start : 17, len : 1, def : ' ' },
956 MIX : {start : 17, len : 1, def : ' ' },
957 MAP : {start : 17, len : 1, def : ' ' },
958 SCO : {start : 17, len : 1, def : ' ' },
959 REC : {start : 17, len : 1, def : ' ' },
960 COM : {start : 17, len : 1, def : ' ' }
965 BKS : {start : 31, len : 1, def : '0' },
966 MAP : {start : 31, len : 1, def : '0' }
969 BKS : {start : 14, len : 1, def : '0' },
970 MAP : {start : 14, len : 1, def : '0' }
975 BKS : {start : 7, len : 4, def : ' ' },
976 SER : {start : 7, len : 4, def : ' ' },
977 VIS : {start : 7, len : 4, def : ' ' },
978 MIX : {start : 7, len : 4, def : ' ' },
979 MAP : {start : 7, len : 4, def : ' ' },
980 SCO : {start : 7, len : 4, def : ' ' },
981 REC : {start : 7, len : 4, def : ' ' },
982 COM : {start : 7, len : 4, def : ' ' }
987 BKS : {start : 11, len : 4, def : ' ' },
988 SER : {start : 11, len : 4, def : '9' },
989 VIS : {start : 11, len : 4, def : ' ' },
990 MIX : {start : 11, len : 4, def : ' ' },
991 MAP : {start : 11, len : 4, def : ' ' },
992 SCO : {start : 11, len : 4, def : ' ' },
993 REC : {start : 11, len : 4, def : ' ' },
994 COM : {start : 11, len : 4, def : ' ' }
999 BKS : {start : 33, len : 1, def : '0' }
1002 BKS : {start : 16, len : 1, def : '0' }
1007 BKS : {start : 34, len : 1, def : ' ' }
1010 BKS : {start : 17, len : 1, def : ' ' }
1015 BKS : {start : 18, len : 4, def : ' ' }
1018 BKS : {start : 1, len : 4, def : ' ' }
1023 BKS : {start : 30, len : 1, def : '0' }
1026 BKS : {start : 13, len : 1, def : '0' }
1031 BKS : {start : 29, len : 1, def : '0' },
1032 SER : {start : 29, len : 1, def : '0' }
1035 BKS : {start : 12, len : 1, def : '0' },
1036 SER : {start : 12, len : 1, def : '0' }
1041 BKS : {start : 24, len : 4, def : ' ' },
1042 SER : {start : 25, len : 3, def : ' ' }
1045 BKS : {start : 7, len : 4, def : ' ' },
1046 SER : {start : 8, len : 3, def : ' ' }
1051 BKS : {start : 28, len : 1, def : ' ' },
1052 SER : {start : 28, len : 1, def : ' ' },
1053 VIS : {start : 28, len : 1, def : ' ' },
1054 MAP : {start : 28, len : 1, def : ' ' },
1055 COM : {start : 28, len : 1, def : ' ' }
1058 BKS : {start : 11, len : 1, def : ' ' },
1059 SER : {start : 11, len : 1, def : ' ' },
1060 VIS : {start : 11, len : 1, def : ' ' },
1061 MAP : {start : 11, len : 1, def : ' ' },
1062 COM : {start : 11, len : 1, def : ' ' }
1067 BKS : {start : 22, len : 1, def : ' ' },
1068 SER : {start : 22, len : 1, def : ' ' },
1069 VIS : {start : 22, len : 1, def : ' ' },
1070 SCO : {start : 22, len : 1, def : ' ' },
1071 REC : {start : 22, len : 1, def : ' ' },
1072 COM : {start : 22, len : 1, def : ' ' }
1075 BKS : {start : 5, len : 1, def : ' ' },
1076 SER : {start : 5, len : 1, def : ' ' },
1077 VIS : {start : 5, len : 1, def : ' ' },
1078 SCO : {start : 5, len : 1, def : ' ' },
1079 REC : {start : 5, len : 1, def : ' ' },
1080 COM : {start : 5, len : 1, def : ' ' }
1085 BKS : {start : 23, len : 1, def : ' ' },
1086 SER : {start : 23, len : 1, def : ' ' },
1087 VIS : {start : 29, len : 1, def : ' ' },
1088 MIX : {start : 23, len : 1, def : ' ' },
1089 MAP : {start : 29, len : 1, def : ' ' },
1090 SCO : {start : 23, len : 1, def : ' ' },
1091 REC : {start : 23, len : 1, def : ' ' }
1094 BKS : {start : 6, len : 1, def : ' ' },
1095 SER : {start : 6, len : 1, def : ' ' },
1096 VIS : {start : 12, len : 1, def : ' ' },
1097 MIX : {start : 6, len : 1, def : ' ' },
1098 MAP : {start : 12, len : 1, def : ' ' },
1099 SCO : {start : 6, len : 1, def : ' ' },
1100 REC : {start : 6, len : 1, def : ' ' }
1105 SER : {start : 34, len : 1, def : '0' }
1108 SER : {start : 17, len : 1, def : '0' }
1113 SER : {start : 33, len : 1, def : ' ' }
1116 SER : {start : 16, len : 1, def : ' ' }
1121 function recordType (rec) {
1123 var _l = rec.leader.toString();
1125 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1126 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1128 for (var t in rec_type) {
1129 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1130 document.getElementById('recordTypeLabel').value = t;
1136 // in case we don't have a valid record type ...
1137 _record_type = 'BKS';
1138 return _record_type;
1141 alert('FIXME, MARC Editor, recordType: ' + E);
1145 function toggleFFE () {
1146 var grid = document.getElementById('leaderGrid');
1148 grid.hidden = false;
1155 function changeFFEditor (type) {
1156 var grid = document.getElementById('leaderGrid');
1157 grid.setAttribute('type',type);
1159 // Hide FFEditor rows that we don't need for our current type
1160 // Again, this would be easier with dojo
1161 var row_list = grid.childNodes;
1163 for (var i = 0; i < row_list.length; i++) {
1164 if (row_list[i].nodeType && row_list[i].tagName == 'rows') {
1169 // If all of the labels for a given row do not include our
1170 // desired type in their set attribute, we can hide that row
1171 row_list = rows.childNodes;
1172 for (var i = 0; i < row_list.length; i++) {
1173 if (row_list[i].nodeType && row_list[i].tagName == 'row') {
1174 var label_list = row_list[i].childNodes;
1175 var found_type = false;
1176 for (var j = 0; j < label_list.length; j++) {
1177 if (label_list[j].nodeType &&
1178 label_list[j].tagName == 'label' &&
1179 label_list[j].getAttribute('set').indexOf(type) != -1) {
1184 row_list[i].hidden = true;
1190 function fillFixedFields (rec) {
1192 var grid = document.getElementById('leaderGrid');
1194 var rtype = _record_type;
1196 var _l = rec.leader.toString();
1197 var _6 = rec.controlfield.(@tag=='006').toString();
1198 var _7 = rec.controlfield.(@tag=='007').toString();
1199 var _8 = rec.controlfield.(@tag=='008').toString();
1202 var pre_list = grid.getElementsByTagName('label');
1203 for (var i in pre_list) {
1204 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1205 list.push( pre_list[i] );
1209 for (var i in list) {
1210 var name = list[i].getAttribute('name');
1216 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1217 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1219 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1220 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1222 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1223 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1225 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1226 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1231 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1232 d = ff_pos[name].ldr[rtype].def;
1236 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1237 d = ff_pos[name]._8[rtype].def;
1241 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1242 d = ff_pos[name]._6[rtype].def;
1246 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1247 d = ff_pos[name]._7[rtype].def;
1252 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1258 list[i].nextSibling.value = value;
1263 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1267 function updateFixedFields (element) {
1268 var grid = document.getElementById('leaderGrid');
1269 var recGrid = document.getElementById('recGrid');
1271 var rtype = _record_type;
1272 var new_value = element.value;
1275 ldr : _record.leader,
1276 _6 : _record.controlfield.(@tag=='006'),
1277 _7 : _record.controlfield.(@tag=='007'),
1278 _8 : _record.controlfield.(@tag=='008')
1281 var name = element.getAttribute('name');
1282 for (var i in ff_pos[name]) {
1284 if (!ff_pos[name][i][rtype]) continue;
1286 // we're missing the required field. Add it now.
1289 if (i == '_6') newfield = '006';
1290 else if (i == '_7') newfield = '007';
1291 else if (i == '_8') newfield = '008';
1294 createControlField(newfield,' ');
1295 parts[i] = _record.controlfield.(@tag==newfield);
1298 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1299 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1301 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1302 new_value += ff_pos[name][i][rtype].def;
1305 parts[i].setChildren( before + new_value + after );
1306 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1312 function marcLeader (leader) {
1313 var row = createRow(
1314 { class : 'marcLeaderRow',
1319 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1322 class : 'marcInd1' } ),
1325 class : 'marcInd2' } ),
1327 { value : leader.text(),
1328 class : 'marcLeader' } )
1334 function marcControlfield (field) {
1335 tagname = field.@tag.toString().substr(2);
1337 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1339 { class : 'marcControlfieldRow',
1340 tag : '_' + tagname },
1342 { value : field.@tag,
1344 context : 'tags_popup',
1345 onmouseover : 'getTooltip(this, "tag");',
1346 tooltipid : 'tag' + field.@tag } ),
1348 { value : field.@ind1,
1350 onmouseover : 'getTooltip(this, "ind1");',
1351 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1353 { value : field.@ind2,
1355 onmouseover : 'getTooltip(this, "ind2");',
1356 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1359 { value : field.text(),
1360 class : 'plain marcEditableControlfield',
1361 name : 'CONTROL' + tagname,
1362 context : 'clipboard',
1368 { class : 'marcControlfieldRow',
1369 tag : '_' + tagname },
1371 { value : field.@tag,
1373 onmouseover : 'getTooltip(this, "tag");',
1374 tooltipid : 'tag' + field.@tag } ),
1376 { value : field.@ind1,
1378 onmouseover : 'getTooltip(this, "ind1");',
1379 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1381 { value : field.@ind2,
1383 onmouseover : 'getTooltip(this, "ind2");',
1384 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1386 { value : field.text(),
1387 class : 'marcControlfield' } )
1394 function stackSubfields(checkbox) {
1395 var list = document.getElementsByAttribute('name','sf_box');
1398 if (!checkbox.checked) o = 'horizontal';
1400 for (var i = 0; i < list.length; i++) {
1401 if (list[i]) list[i].setAttribute('orient',o);
1405 function fastItemAdd_toggle(checkbox) {
1406 var x = document.getElementById('fastItemAdd_textboxes');
1407 if (checkbox.checked) {
1409 document.getElementById('fastItemAdd_callnumber').focus();
1410 document.getElementById('fastItemAdd_callnumber').select();
1416 function fastItemAdd_attempt(doc_id) {
1418 if (typeof window.xulG.fast_add_item != 'function') { return; }
1419 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1420 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1421 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1422 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1423 document.getElementById('fastItemAdd_barcode').value = '';
1425 alert('fastItemAdd_attempt: ' + E);
1429 function save_attempt(xml_string) {
1431 var result = window.xulG.save.func( xml_string );
1433 if (result.id) fastItemAdd_attempt(result.id);
1434 if (typeof result.on_complete == 'function') result.on_complete();
1437 alert('save_attempt: ' + E);
1441 function marcDatafield (field) {
1442 var row = createRow(
1443 { class : 'marcDatafieldRow' },
1446 { value : field.@tag,
1447 class : 'plain marcTag',
1449 context : 'tags_popup',
1450 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1453 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1456 { value : field.@ind1,
1457 class : 'plain marcInd1',
1459 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1462 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1463 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1466 { value : field.@ind2,
1467 class : 'plain marcInd2',
1469 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1472 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1473 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1474 createHbox({ name : 'sf_box' })
1477 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1478 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1479 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1481 var sf_box = row.lastChild;
1482 if (document.getElementById('stackSubfields').checked)
1483 sf_box.setAttribute('orient','vertical');
1485 sf_box.addEventListener(
1488 if (sf_box === e.target) {
1489 sf_box.lastChild.lastChild.focus();
1490 } else if (e.target.parentNode === sf_box) {
1491 e.target.lastChild.focus();
1498 for (var i in field.subfield) {
1499 var sf = field.subfield[i];
1504 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1505 current_focus = sf_box.lastChild.childNodes[1];
1511 function marcSubfield (sf) {
1513 { class : 'marcSubfieldBox' },
1516 class : 'plain marcSubfieldDelimiter',
1517 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1518 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1519 //onclick : 'this.nextSibling.focus();',
1520 onfocus : 'this.nextSibling.focus();',
1525 class : 'plain marcSubfieldCode',
1526 name : 'marcSubfieldCode',
1527 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1528 oncontextmenu : 'getContextMenu(this, "subfield");',
1529 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1534 { value : sf.text(),
1535 name : sf.parent().@tag + ':' + sf.@code,
1536 class : 'plain marcSubfield',
1537 onmouseover : 'getTooltip(this, "subfield");',
1538 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1539 size : new String(sf.text()).length + 2,
1540 oninput : "this.setAttribute('size', this.value.length + 2);"
1545 function loadRecord(rec) {
1548 var grid_rows = document.getElementById('recGrid').lastChild;
1550 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1552 grid_rows.appendChild( marcLeader( rec.leader ) );
1554 for (var i in rec.controlfield) {
1555 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1558 for (var i in rec.datafield) {
1559 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1562 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1563 changeFFEditor(recordType(rec));
1564 fillFixedFields(rec);
1566 alert('FIXME, MARC Editor, loadRecord: ' + E);
1571 function genToolTips () {
1572 for (var i in bib_data.field) {
1573 var f = bib_data.field[i];
1575 tag_menu.appendChild(
1579 'current_focus.value = "' + f.@tag + '";' +
1580 'var e = document.createEvent("MutationEvents");' +
1581 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1582 'current_focus.inputField.dispatchEvent(e);',
1583 disabled : f.@tag < '010' ? "true" : "false",
1584 tooltiptext : f.description }
1588 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1589 context_menus.appendChild( i1_popup );
1591 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1592 context_menus.appendChild( i2_popup );
1594 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1595 context_menus.appendChild( sf_popup );
1597 tooltip_hash['tag' + f.@tag] = f.description;
1598 for (var j in f.indicator) {
1599 var ind = f.indicator[j];
1600 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1602 if (ind.@position == 1) {
1603 i1_popup.appendChild(
1605 { label : ind.@value,
1607 'current_focus.value = "' + ind.@value + '";' +
1608 'var e = document.createEvent("MutationEvents");' +
1609 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1610 'current_focus.inputField.dispatchEvent(e);',
1611 tooltiptext : ind.description }
1616 if (ind.@position == 2) {
1617 i2_popup.appendChild(
1619 { label : ind.@value,
1621 'current_focus.value = "' + ind.@value + '";' +
1622 'var e = document.createEvent("MutationEvents");' +
1623 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1624 'current_focus.inputField.dispatchEvent(e);',
1625 tooltiptext : ind.description }
1631 for (var j in f.subfield) {
1632 var sf = f.subfield[j];
1633 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1635 sf_popup.appendChild(
1639 'current_focus.value = "' + sf.@code + '";' +
1640 'var e = document.createEvent("MutationEvents");' +
1641 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1642 'current_focus.inputField.dispatchEvent(e);',
1643 tooltiptext : sf.description
1651 function getTooltip (target, type) {
1654 if (type == 'subfield')
1655 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1658 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1661 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1664 tt = 'tag' + target.parentNode.firstChild.value;
1666 if (!document.getElementById( tt )) {
1671 orient : 'vertical',
1672 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1673 class : 'tooltip' },
1674 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1679 target.tooltip = tt;
1683 function getContextMenu (target, type) {
1686 if (type == 'subfield')
1687 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1690 tt = 't' + target.parentNode.firstChild.value + 'i1';
1693 tt = 't' + target.parentNode.firstChild.value + 'i2';
1695 target.setAttribute('context', tt);
1699 var authority_tag_map = {
1700 100 : ['[100,400,500,700]',100],
1701 400 : ['[100,400,500,700]',100],
1702 700 : ['[100,400,500,700]',100],
1703 800 : ['[100,400,500,700]',100],
1704 110 : ['[110,410,510,710]',110],
1705 410 : ['[110,410,510,710]',110],
1706 710 : ['[110,410,510,710]',110],
1707 810 : ['[110,410,510,710]',110],
1708 111 : ['[111,411,511,711]',111],
1709 411 : ['[111,411,511,711]',111],
1710 711 : ['[111,411,511,711]',111],
1711 811 : ['[111,411,511,711]',111],
1712 240 : ['[130,430,530,730]',130],
1713 440 : ['[130,430,530,730]',130],
1714 130 : ['[130,430,530,730]',130],
1715 730 : ['[130,430,530,730]',130],
1716 830 : ['[130,430,530,730]',130],
1717 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1718 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1719 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1720 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1723 function getAuthorityContextMenu (target, sf) {
1724 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1726 var old = document.getElementById( menu_id );
1727 if (old) old.parentNode.removeChild(old);
1729 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1730 context_menus.appendChild( sf_popup );
1732 if (!authority_tag_map[sf.parent().@tag]) {
1733 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1734 target.setAttribute('context', 'clipboard');
1738 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1740 var res = new XML( auth_data.responseText );
1744 var recs = res.gw::payload.gw::array.gw::string;
1745 for (var i in recs) {
1747 var xml = new XML(x.toString());
1748 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1750 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1753 for (var i in main) {
1754 if (main_text) main_text += ' / ';
1755 main_text += main[i];
1758 rec_list.push( [ main_text, xml ] );
1761 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1763 var main_text = rec_list[i][0];
1764 var xml = rec_list[i][1];
1765 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1767 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1769 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1770 grid.setAttribute('name','-none-');
1771 grid.setAttribute('style','overflow:scroll');
1774 var submenu = createMenu( { label : main_text } );
1776 var popup = createMenuPopup({ flex : "1" });
1777 submenu.appendChild(popup);
1779 var fields = xml.datafield;
1780 for (var j in fields) {
1782 var row = createRow(
1784 createLabel( { value : fields[j].@tag } ),
1785 createLabel( { value : fields[j].@ind1 } ),
1786 createLabel( { value : fields[j].@ind2 } )
1789 var sf_box = createHbox();
1791 var subfields = fields[j].subfield;
1792 for (var k in subfields) {
1795 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1796 subfield : subfields[k].@code,
1797 tag : subfields[k].parent().@tag,
1798 value : subfields[k]
1802 row.appendChild(sf_box);
1805 grid.lastChild.appendChild(row);
1808 grid.hidden = false;
1809 popup.appendChild( grid );
1813 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1814 command : function (event) {
1815 applyAuthority(event.target.previousSibling, target, sf);
1822 sf_popup.appendChild( submenu );
1825 if (sf_popup.childNodes.length == 0)
1826 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1828 target.setAttribute('context', menu_id);
1832 function applyAuthority ( target, ui_sf, e4x_sf ) {
1834 var new_vals = target.getElementsByAttribute('checked','true');
1835 var field = e4x_sf.parent();
1837 for (var i = 0; i < new_vals.length; i++) {
1839 var sf_list = field.subfield;
1840 for (var j in sf_list) {
1842 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1843 sf_list[j] = new_vals[i].getAttribute('value');
1844 new_vals[i].setAttribute('subfield','');
1850 for (var i = 0; i < new_vals.length; i++) {
1851 if (!new_vals[i].getAttribute('subfield')) continue;
1853 var val = new_vals[i].getAttribute('value');
1855 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1856 sf.@code = new_vals[i].getAttribute('subfield');
1858 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1861 var row = marcDatafield( field );
1864 while (node.nodeName != 'row') {
1865 node = node.parentNode;
1868 node.parentNode.replaceChild( row, node );
1874 'a' : { 100 : 'a' },
1875 'd' : { 100 : 'd' },
1879 'a' : { 110 : 'a' },
1883 'a' : { 111 : 'a' },
1887 'a' : { 130 : 'a' },
1891 'a' : { 130 : 'a' },
1895 'a' : { 100 : 'a' },
1899 'a' : { 110 : 'a' },
1903 'a' : { 111 : 'a' },
1907 'a' : { 130 : 'a' },
1908 'n' : { 130 : 'n' },
1912 'a' : { 100 : 'a' },
1913 'd' : { 100 : 'd' },
1914 'q' : { 100 : 'q' },
1918 'a' : { 110 : 'a' },
1922 'a' : { 111 : 'a' },
1926 'a' : { 130 : 'a' },
1930 'a' : { 100 : 'a' },
1934 'a' : { 110 : 'a' },
1938 'a' : { 111 : 'a' },
1942 'a' : { 130 : 'a' },
1946 'a' : { 100 : 'a' },
1947 'd' : { 100 : 'd' },
1948 'q' : { 100 : 'q' },
1949 't' : { 100 : 't' },
1976 'a' : { 110 : 'a' },
1977 'd' : { 110 : 'd' },
1978 't' : { 110 : 't' },
2005 'a' : { 111 : 'a' },
2006 'd' : { 111 : 'd' },
2007 't' : { 111 : 't' },
2034 'a' : { 130 : 'a' },
2038 'a' : { 150 : 'a' },
2039 'b' : { 150 : 'b' },
2066 'a' : { 151 : 'a' },
2093 'a' : { 155 : 'a' },
2121 function validateAuthority (button) {
2122 var grid = document.getElementById('recGrid');
2123 var label = button.getAttribute('label');
2126 var rows = grid.lastChild.childNodes;
2127 for (var i = 0; i < rows.length; i++) {
2129 var tag = row.firstChild;
2131 if (!control_map[tag.value]) continue
2132 button.setAttribute('label', label + ' - ' + tag.value);
2134 var ind1 = tag.nextSibling;
2135 var ind2 = ind1.nextSibling;
2136 var subfields = ind2.nextSibling.childNodes;
2140 for (var j = 0; j < subfields.length; j++) {
2141 var sf = subfields[j];
2142 var sf_code = sf.childNodes[1].value;
2143 var sf_value = sf.childNodes[2].value;
2145 if (!control_map[tag.value][sf_code]) continue;
2148 for (var a_tag in control_map[tag.value][sf_code]) {
2149 if (!tags[a_tag]) tags[a_tag] = [];
2150 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2155 for (var val_tag in tags) {
2156 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2157 var res = new XML( auth_data.responseText );
2158 found = parseInt(res.gw::payload.gw::string.toString());
2162 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2163 for (var j = 0; j < subfields.length; j++) {
2164 var sf = subfields[j];
2166 sf.childNodes[2].inputField.style.color = 'red';
2168 sf.childNodes[2].inputField.style.color = 'black';
2173 button.setAttribute('label', label);
2179 function validateBibField (tags, searches) {
2180 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2181 url += '¶m="tags"¶m=' + js2JSON(tags);
2182 url += '¶m="searches"¶m=' + js2JSON(searches);
2185 var req = new XMLHttpRequest();
2186 req.open('GET',url,false);
2192 function searchAuthority (term, tag, sf, limit) {
2193 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2194 url += '¶m="term"¶m="' + term + '"';
2195 url += '¶m="limit"¶m=' + limit;
2196 url += '¶m="tag"¶m=' + tag;
2197 url += '¶m="subfield"¶m="' + sf + '"';
2200 var req = new XMLHttpRequest();
2201 req.open('GET',url,false);