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 wrap_long_fields (node) {
82 var text_size = dojo.attr(node, 'size');
84 if (text_size > hard_width) {
85 dojo.attr(node, 'multiline', 'true');
86 dojo.attr(node, 'cols', hard_width);
87 var text_rows = (text_size / hard_width) + 1;
88 dojo.attr(node, 'rows', text_rows);
92 function swap_editors () {
94 dojo.require('MARC.Record');
96 var xe = $('xul-editor');
97 var te = $('text-editor');
99 te.hidden = te.hidden ? false : true;
100 xe.hidden = xe.hidden ? false : true;
103 // get the marcxml from the text box
104 var xml_string = new MARC.Record({
105 marcbreaker : $('text-editor-box').value,
109 // reset the xml record and rerender it
110 xml_record = new XML( xml_string );
111 loadRecord(xml_record);
113 var xml_string = xml_record.toXMLString();
115 // push the xml record into the textbox
116 var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
117 $('text-editor-box').value = rec.toBreaker();
124 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
125 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
126 JSAN.errorLevel = "die"; // none, warn, or die
127 JSAN.addRepository('/xul/server/');
129 // Fake xulG for standalone...
134 window.xulG.record = {};
135 window.xulG.save = {};
137 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
138 window.xulG.save.func = function (r) { alert(r); }
141 var _rid = cgi.param('record');
143 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
146 // End faking part...
148 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
149 document.getElementById('save-button').setAttribute('oncommand',
150 'if ($("xul-editor").hidden) swap_editors(); ' +
152 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
153 'save_attempt( xml_string ); ' +
154 'loadRecord(xml_record);'
157 if (window.xulG.record.url) {
158 var req = new XMLHttpRequest();
159 req.open('POST',window.xulG.record.url,false);
161 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
164 xml_record = new XML( window.xulG.record.marc );
165 if (xml_record..record[0]) xml_record = xml_record..record[0];
167 // Get the tooltip xml all async like
168 req = new XMLHttpRequest();
170 // Set a default locale in case preferences fail us
171 var locale = "en-US";
173 // Try to get the locale from our preferences
174 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
176 const Cc = Components.classes;
177 const Ci = Components.interfaces;
178 locale = Cc["@mozilla.org/preferences-service;1"].
179 getService(Ci.nsIPrefBranch).
180 getCharPref("general.useragent.locale");
184 // TODO: We should send a HEAD request to check for the existence of the desired file
185 // then fall back to the default locale if preferred locale is not necessary;
186 // however, for now we have a simplistic check:
188 // we currently have translations for only two locales; in the absence of a
189 // valid locale, default to the almighty en-US
190 if (locale != 'en-US' && locale != 'fr-CA') {
194 // Get the locale-specific tooltips
195 req.open('GET','/xul/server/locale/' + locale + '/marcedit-tooltips.xml',true);
197 context_menus = createComplexXULElement('popupset');
198 document.documentElement.appendChild( context_menus );
200 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
201 context_menus.appendChild( tag_menu );
203 tag_menu.appendChild(
205 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
207 'var e = document.createEvent("KeyEvents");' +
208 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
209 'current_focus.inputField.dispatchEvent(e);'
214 tag_menu.appendChild(
216 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
218 'var e = document.createEvent("KeyEvents");' +
219 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
220 'current_focus.inputField.dispatchEvent(e);'
225 tag_menu.appendChild(
227 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
229 'var e = document.createEvent("KeyEvents");' +
230 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
231 'current_focus.inputField.dispatchEvent(e);'
236 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
238 tag_menu.appendChild(
240 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
242 'var e = document.createEvent("KeyEvents");' +
243 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
244 'current_focus.inputField.dispatchEvent(e);'
249 tag_menu.appendChild(
251 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
253 'var e = document.createEvent("KeyEvents");' +
254 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
255 'current_focus.inputField.dispatchEvent(e);'
260 tag_menu.appendChild(
262 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
264 'var e = document.createEvent("KeyEvents");' +
265 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
266 'current_focus.inputField.dispatchEvent(e);'
271 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
273 p = createComplexXULElement('popupset');
274 document.documentElement.appendChild( p );
276 req.onreadystatechange = function () {
277 if (req.readyState == 4) {
278 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
284 loadRecord(xml_record);
286 if (! xulG.fast_add_item) {
287 document.getElementById('fastItemAdd_checkbox').hidden = true;
289 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
292 alert('FIXME, MARC Editor, my_init: ' + E);
297 function createComplexHTMLElement (e, attrs, objects, text) {
298 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
301 for (var i in attrs) l.setAttribute(i,attrs[i]);
305 for ( var i in objects ) l.appendChild( objects[i] );
309 l.appendChild( document.createTextNode(text) )
315 function createComplexXULElement (e, attrs, objects) {
316 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
319 for (var i in attrs) {
320 if (typeof attrs[i] == 'function') {
321 l.addEventListener( i, attrs[i], true );
323 l.setAttribute(i,attrs[i]);
329 for ( var i in objects ) l.appendChild( objects[i] );
335 function createDescription (attrs) {
336 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
339 function createTooltip (attrs) {
340 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
343 function createLabel (attrs) {
344 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
347 function createVbox (attrs) {
348 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
351 function createHbox (attrs) {
352 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
355 function createRow (attrs) {
356 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
359 function createTextbox (attrs) {
360 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
363 function createMenu (attrs) {
364 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
367 function createMenuPopup (attrs) {
368 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
371 function createPopup (attrs) {
372 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
375 function createMenuitem (attrs) {
376 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
379 function createCheckbox (attrs) {
380 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
383 // Find the next textbox that we can use for a focus point
384 // For control fields, use the first editable text box
385 // For data fields, focus on the first subfield text box
386 function setFocusToNextTag (row, direction) {
387 while (direction == 'up' ? row = row.previousSibling : row = row.nextSibling) {
388 var children = row.childNodes;
389 for (var i = 0; i < children.length; i++) {
390 // This would be way cleaner with dojo.query()
391 if (row.className == 'marcDatafieldRow') {
392 // marcSubfield lives in hbox.hbox.textbox
393 var hboxKids = children[i].childNodes;
394 if (children[i].tagName == 'hbox') {
395 for (var j = 0; j < hboxKids.length; j++) {
396 var msfBoxKids = hboxKids[j].childNodes;
397 if (hboxKids[j].className == 'marcSubfieldBox') {
398 for (var k = 0; k < msfBoxKids.length; k++) {
399 if (msfBoxKids[k].className == 'plain marcSubfield') {
400 msfBoxKids[k].focus();
409 if (children[i].tagName == 'textbox') {
420 function createMARCTextbox (element,attrs) {
422 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
423 box.onkeypress = function (event) {
426 while(node = node.parent()) {
430 var row = event.target;
431 while (row.tagName != 'row') row = row.parentNode;
433 if (element.nodeKind() == 'attribute') element[0]=box.value;
434 else element.setChildren( box.value );
436 if (element.localName() != 'controlfield') {
437 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
439 var index_sf, target, move_data;
440 if (element.localName() == 'subfield') {
442 target = event.target.parentNode;
444 var start = event.target.selectionStart;
445 var end = event.target.selectionEnd - event.target.selectionStart ?
446 event.target.selectionEnd :
447 event.target.value.length;
449 move_data = event.target.value.substring(start,end);
450 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
451 event.target.setAttribute('size', event.target.value.length + 2);
453 element.setChildren( event.target.value );
455 } else if (element.localName() == 'code') {
456 index_sf = element.parent();
457 target = event.target.parentNode;
458 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
459 index_sf = element.parent().children()[element.parent().children().length() - 1];
460 target = event.target.parentNode.lastChild.lastChild;
463 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
465 index_sf.parent().insertChildAfter( index_sf, sf );
467 var new_sf = marcSubfield(sf);
469 if (target === target.parentNode.lastChild) {
470 target.parentNode.appendChild( new_sf );
472 target.parentNode.insertBefore( new_sf, target.nextSibling );
475 new_sf.firstChild.nextSibling.focus();
477 event.preventDefault();
480 } else if (event.keyCode == 13 || event.keyCode == 77) {
481 if (event.ctrlKey) { // ctrl+enter
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 df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
492 if (event.shiftKey) { // ctrl+shift+enter
493 index.parent().insertChildBefore( index, df );
495 index.parent().insertChildAfter( index, df );
498 var new_df = marcDatafield(df);
500 if (row.parentNode.lastChild === row) {
501 row.parentNode.appendChild( new_df );
503 if (event.shiftKey) { // ctrl+shift+enter
504 row.parentNode.insertBefore( new_df, row );
506 row.parentNode.insertBefore( new_df, row.nextSibling );
510 new_df.firstChild.focus();
512 event.preventDefault();
515 } else if (event.shiftKey) {
516 if (row.previousSibling.className.match('marcDatafieldRow'))
517 row.previousSibling.firstChild.focus();
519 row.nextSibling.firstChild.focus();
522 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
523 if (event.ctrlKey) { // CTRL key: copy the field
525 if (element.localName() == 'subfield') index = element.parent();
526 if (element.localName() == 'code') index = element.parent().parent();
527 if (element.localName() == 'tag') index = element.parent();
528 if (element.localName() == 'ind1') index = element.parent();
529 if (element.localName() == 'ind2') index = element.parent();
531 var copyField = index.copy();
533 if (event.keyCode == 38) { // ctrl+up-arrow
534 index.parent().insertChildBefore( index, copyField );
536 index.parent().insertChildAfter( index, copyField );
539 var new_df = marcDatafield(copyField);
541 if (row.parentNode.lastChild === row) {
542 row.parentNode.appendChild( new_df );
544 if (event.keyCode == 38) { // ctrl+up-arrow
545 row.parentNode.insertBefore( new_df, row );
546 } else { // ctrl+down-arrow
547 row.parentNode.insertBefore( new_df, row.nextSibling );
551 new_df.firstChild.focus();
553 event.preventDefault();
557 if (event.keyCode == 38) {
558 return setFocusToNextTag(row, 'up');
560 if (event.keyCode == 40) {
561 return setFocusToNextTag(row, 'down');
566 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
569 if (element.localName() == 'subfield') index = element.parent();
570 if (element.localName() == 'code') index = element.parent().parent();
571 if (element.localName() == 'tag') index = element.parent();
572 if (element.localName() == 'ind1') index = element.parent();
573 if (element.localName() == 'ind2') index = element.parent();
575 for (var i in index.parent().children()) {
576 if (index === index.parent().children()[i]) {
577 delete index.parent().children()[i];
582 row.previousSibling.firstChild.focus();
583 row.parentNode.removeChild(row);
585 event.preventDefault();
588 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
591 if (element.localName() == 'subfield') index = element;
592 if (element.localName() == 'code') index = element.parent();
595 for (var i in index.parent().children()) {
596 if (index === index.parent().children()[i]) {
597 delete index.parent().children()[i];
602 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
603 event.target.parentNode.previousSibling.lastChild.focus();
605 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
608 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
610 event.preventDefault();
613 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
614 createControlField('006',' ');
615 loadRecord(xml_record);
616 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
617 createControlField('007',' ');
618 loadRecord(xml_record);
619 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
620 createControlField('008',' ');
621 loadRecord(xml_record);
626 } else { // event on a control field
627 if (event.keyCode == 38) {
628 return setFocusToNextTag(row, 'up');
629 } else if (event.keyCode == 40) {
630 return setFocusToNextTag(row, 'down');
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.nodeKind() == 'attribute') element[0]=box.value;
659 else element.setChildren( box.value );
665 box.addEventListener(
668 if (element.localName() == 'controlfield')
669 eval('fillFixedFields(xml_record);');
678 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
679 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
680 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
681 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
682 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
683 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
684 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
685 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
691 SCO : {start : 33, len : 1, def : ' ' },
692 REC : {start : 33, len : 1, def : 'n' }
695 SCO : {start : 16, len : 1, def : ' ' },
696 REC : {start : 16, len : 1, def : 'n' }
701 VIS : {start : 33, len : 1, def : ' ' }
704 VIS : {start : 16, len : 1, def : ' ' }
709 VIS : {start : 18, len : 3, def : ' ' }
712 VIS : {start : 1, len : 3, def : ' ' }
717 VIS : {start : 34, len : 1, def : 'n' }
720 VIS : {start : 17, len : 1, def : 'n' }
725 SER : {start : 21, len : 1, def : ' ' }
728 SER : {start : 4, len : 1, def : ' ' }
733 BKS : {start : 39, len : 1, def : 'd' },
734 SER : {start : 39, len : 1, def : 'd' },
735 VIS : {start : 39, len : 1, def : 'd' },
736 MIX : {start : 39, len : 1, def : 'd' },
737 MAP : {start : 39, len : 1, def : 'd' },
738 SCO : {start : 39, len : 1, def : 'd' },
739 REC : {start : 39, len : 1, def : 'd' },
740 COM : {start : 39, len : 1, def : 'd' }
745 MAP : {start : 33, len : 2, def : ' ' }
748 MAP : {start : 16, len : 2, def : ' ' }
753 MAP : {start : 18, len : 4, def : ' ' }
756 MAP : {start : 1, len : 4, def : ' ' }
761 SER : {start : 19, len : 1, def : ' ' }
764 SER : {start : 2, len : 1, def : ' ' }
769 MAP : {start : 22, len : 2, def : ' ' }
772 MAP : {start : 5, len : 2, def : ' ' }
777 SCO : {start : 21, len : 1, def : ' ' },
778 REC : {start : 21, len : 1, def : 'n' }
781 SCO : {start : 4, len : 1, def : ' ' },
782 REC : {start : 4, len : 1, def : 'n' }
787 SER : {start : 22, len : 1, def : ' ' }
790 SER : {start : 5, len : 1, def : ' ' }
795 SCO : {start : 30, len : 2, def : ' ' },
796 REC : {start : 30, len : 2, def : ' ' }
799 SCO : {start : 13, len : 2, def : ' ' },
800 REC : {start : 13, len : 2, def : ' ' }
805 SER : {start : 18, len : 1, def : ' ' }
808 SER : {start : 1, len : 1, def : ' ' }
813 SCO : {start : 20, len : 1, def : ' ' },
814 REC : {start : 20, len : 1, def : 'n' }
817 SCO : {start : 3, len : 1, def : ' ' },
818 REC : {start : 3, len : 1, def : 'n' }
823 COM : {start : 26, len : 1, def : 'u' }
826 COM : {start : 9, len : 1, def : 'u' }
831 SER : {start : 24, len : 1, def : ' ' }
834 SER : {start : 7, len : 1, def : ' ' }
839 SCO : {start : 24, len : 6, def : ' ' },
840 REC : {start : 24, len : 6, def : ' ' }
843 SCO : {start : 7, len : 6, def : ' ' },
844 REC : {start : 7, len : 6, def : ' ' }
849 SCO : {start : 18, len : 2, def : ' ' },
850 REC : {start : 18, len : 2, def : ' ' }
853 SCO : {start : 1, len : 2, def : ' ' },
854 REC : {start : 1, len : 2, def : ' ' }
859 MAP : {start : 25, len : 1, def : ' ' }
862 MAP : {start : 8, len : 1, def : ' ' }
867 BKS : {start : 15, len : 3, def : ' ' },
868 SER : {start : 15, len : 3, def : ' ' },
869 VIS : {start : 15, len : 3, def : ' ' },
870 MIX : {start : 15, len : 3, def : ' ' },
871 MAP : {start : 15, len : 3, def : ' ' },
872 SCO : {start : 15, len : 3, def : ' ' },
873 REC : {start : 15, len : 3, def : ' ' },
874 COM : {start : 15, len : 3, def : ' ' }
879 BKS : {start : 35, len : 3, def : ' ' },
880 SER : {start : 35, len : 3, def : ' ' },
881 VIS : {start : 35, len : 3, def : ' ' },
882 MIX : {start : 35, len : 3, def : ' ' },
883 MAP : {start : 35, len : 3, def : ' ' },
884 SCO : {start : 35, len : 3, def : ' ' },
885 REC : {start : 35, len : 3, def : ' ' },
886 COM : {start : 35, len : 3, def : ' ' }
891 BKS : {start : 38, len : 1, def : ' ' },
892 SER : {start : 38, len : 1, def : ' ' },
893 VIS : {start : 38, len : 1, def : ' ' },
894 MIX : {start : 38, len : 1, def : ' ' },
895 MAP : {start : 38, len : 1, def : ' ' },
896 SCO : {start : 38, len : 1, def : ' ' },
897 REC : {start : 38, len : 1, def : ' ' },
898 COM : {start : 38, len : 1, def : ' ' }
903 BKS : {start : 6, len : 1, def : ' ' },
904 SER : {start : 6, len : 1, def : 'c' },
905 VIS : {start : 6, len : 1, def : ' ' },
906 MIX : {start : 6, len : 1, def : ' ' },
907 MAP : {start : 6, len : 1, def : ' ' },
908 SCO : {start : 6, len : 1, def : ' ' },
909 REC : {start : 6, len : 1, def : ' ' },
910 COM : {start : 6, len : 1, def : ' ' }
915 BKS : {start : 6, len : 1, def : 'a' },
916 SER : {start : 6, len : 1, def : 'a' },
917 VIS : {start : 6, len : 1, def : 'g' },
918 MIX : {start : 6, len : 1, def : 'p' },
919 MAP : {start : 6, len : 1, def : 'e' },
920 SCO : {start : 6, len : 1, def : 'c' },
921 REC : {start : 6, len : 1, def : 'i' },
922 COM : {start : 6, len : 1, def : 'm' }
927 BKS : {start : 8, len : 1, def : ' ' },
928 SER : {start : 8, len : 1, def : ' ' },
929 VIS : {start : 8, len : 1, def : ' ' },
930 MIX : {start : 8, len : 1, def : ' ' },
931 MAP : {start : 8, len : 1, def : ' ' },
932 SCO : {start : 8, len : 1, def : ' ' },
933 REC : {start : 8, len : 1, def : ' ' },
934 COM : {start : 8, len : 1, def : ' ' }
939 BKS : {start : 7, len : 1, def : 'm' },
940 SER : {start : 7, len : 1, def : 's' },
941 VIS : {start : 7, len : 1, def : 'm' },
942 MIX : {start : 7, len : 1, def : 'c' },
943 MAP : {start : 7, len : 1, def : 'm' },
944 SCO : {start : 7, len : 1, def : 'm' },
945 REC : {start : 7, len : 1, def : 'm' },
946 COM : {start : 7, len : 1, def : 'm' }
951 BKS : {start : 18, len : 1, def : ' ' },
952 SER : {start : 18, len : 1, def : ' ' },
953 VIS : {start : 18, len : 1, def : ' ' },
954 MIX : {start : 18, len : 1, def : ' ' },
955 MAP : {start : 18, len : 1, def : ' ' },
956 SCO : {start : 18, len : 1, def : ' ' },
957 REC : {start : 18, len : 1, def : ' ' },
958 COM : {start : 18, len : 1, def : ' ' }
963 BKS : {start : 17, len : 1, def : ' ' },
964 SER : {start : 17, len : 1, def : ' ' },
965 VIS : {start : 17, len : 1, def : ' ' },
966 MIX : {start : 17, len : 1, def : ' ' },
967 MAP : {start : 17, len : 1, def : ' ' },
968 SCO : {start : 17, len : 1, def : ' ' },
969 REC : {start : 17, len : 1, def : ' ' },
970 COM : {start : 17, len : 1, def : ' ' }
975 BKS : {start : 31, len : 1, def : '0' },
976 MAP : {start : 31, len : 1, def : '0' }
979 BKS : {start : 14, len : 1, def : '0' },
980 MAP : {start : 14, len : 1, def : '0' }
985 BKS : {start : 7, len : 4, def : ' ' },
986 SER : {start : 7, len : 4, def : ' ' },
987 VIS : {start : 7, len : 4, def : ' ' },
988 MIX : {start : 7, len : 4, def : ' ' },
989 MAP : {start : 7, len : 4, def : ' ' },
990 SCO : {start : 7, len : 4, def : ' ' },
991 REC : {start : 7, len : 4, def : ' ' },
992 COM : {start : 7, len : 4, def : ' ' }
997 BKS : {start : 11, len : 4, def : ' ' },
998 SER : {start : 11, len : 4, def : '9' },
999 VIS : {start : 11, len : 4, def : ' ' },
1000 MIX : {start : 11, len : 4, def : ' ' },
1001 MAP : {start : 11, len : 4, def : ' ' },
1002 SCO : {start : 11, len : 4, def : ' ' },
1003 REC : {start : 11, len : 4, def : ' ' },
1004 COM : {start : 11, len : 4, def : ' ' }
1009 BKS : {start : 33, len : 1, def : '0' }
1012 BKS : {start : 16, len : 1, def : '0' }
1017 BKS : {start : 34, len : 1, def : ' ' }
1020 BKS : {start : 17, len : 1, def : ' ' }
1025 BKS : {start : 18, len : 4, def : ' ' }
1028 BKS : {start : 1, len : 4, def : ' ' }
1033 BKS : {start : 30, len : 1, def : '0' }
1036 BKS : {start : 13, len : 1, def : '0' }
1041 BKS : {start : 29, len : 1, def : '0' },
1042 SER : {start : 29, len : 1, def : '0' }
1045 BKS : {start : 12, len : 1, def : '0' },
1046 SER : {start : 12, len : 1, def : '0' }
1051 BKS : {start : 24, len : 4, def : ' ' },
1052 SER : {start : 25, len : 3, def : ' ' }
1055 BKS : {start : 7, len : 4, def : ' ' },
1056 SER : {start : 8, len : 3, def : ' ' }
1061 BKS : {start : 28, len : 1, def : ' ' },
1062 SER : {start : 28, len : 1, def : ' ' },
1063 VIS : {start : 28, len : 1, def : ' ' },
1064 MAP : {start : 28, len : 1, def : ' ' },
1065 COM : {start : 28, len : 1, def : ' ' }
1068 BKS : {start : 11, len : 1, def : ' ' },
1069 SER : {start : 11, len : 1, def : ' ' },
1070 VIS : {start : 11, len : 1, def : ' ' },
1071 MAP : {start : 11, len : 1, def : ' ' },
1072 COM : {start : 11, len : 1, def : ' ' }
1077 BKS : {start : 22, len : 1, def : ' ' },
1078 SER : {start : 22, len : 1, def : ' ' },
1079 VIS : {start : 22, len : 1, def : ' ' },
1080 SCO : {start : 22, len : 1, def : ' ' },
1081 REC : {start : 22, len : 1, def : ' ' },
1082 COM : {start : 22, len : 1, def : ' ' }
1085 BKS : {start : 5, len : 1, def : ' ' },
1086 SER : {start : 5, len : 1, def : ' ' },
1087 VIS : {start : 5, len : 1, def : ' ' },
1088 SCO : {start : 5, len : 1, def : ' ' },
1089 REC : {start : 5, len : 1, def : ' ' },
1090 COM : {start : 5, len : 1, def : ' ' }
1095 BKS : {start : 23, len : 1, def : ' ' },
1096 SER : {start : 23, len : 1, def : ' ' },
1097 VIS : {start : 29, len : 1, def : ' ' },
1098 MIX : {start : 23, len : 1, def : ' ' },
1099 MAP : {start : 29, len : 1, def : ' ' },
1100 SCO : {start : 23, len : 1, def : ' ' },
1101 REC : {start : 23, len : 1, def : ' ' }
1104 BKS : {start : 6, len : 1, def : ' ' },
1105 SER : {start : 6, len : 1, def : ' ' },
1106 VIS : {start : 12, len : 1, def : ' ' },
1107 MIX : {start : 6, len : 1, def : ' ' },
1108 MAP : {start : 12, len : 1, def : ' ' },
1109 SCO : {start : 6, len : 1, def : ' ' },
1110 REC : {start : 6, len : 1, def : ' ' }
1115 SER : {start : 34, len : 1, def : '0' }
1118 SER : {start : 17, len : 1, def : '0' }
1123 SER : {start : 33, len : 1, def : ' ' }
1126 SER : {start : 16, len : 1, def : ' ' }
1131 function recordType (rec) {
1133 var _l = rec.leader.toString();
1135 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1136 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1138 for (var t in rec_type) {
1139 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1140 document.getElementById('recordTypeLabel').value = t;
1146 // in case we don't have a valid record type ...
1147 _record_type = 'BKS';
1148 return _record_type;
1151 alert('FIXME, MARC Editor, recordType: ' + E);
1155 function toggleFFE () {
1156 var grid = document.getElementById('leaderGrid');
1158 grid.hidden = false;
1165 function changeFFEditor (type) {
1166 var grid = document.getElementById('leaderGrid');
1167 grid.setAttribute('type',type);
1169 // Hide FFEditor rows that we don't need for our current type
1170 // Again, this would be easier with dojo
1171 var row_list = grid.childNodes;
1173 for (var i = 0; i < row_list.length; i++) {
1174 if (row_list[i].nodeType && row_list[i].tagName == 'rows') {
1179 // If all of the labels for a given row do not include our
1180 // desired type in their set attribute, we can hide that row
1181 row_list = rows.childNodes;
1182 for (var i = 0; i < row_list.length; i++) {
1183 if (row_list[i].nodeType && row_list[i].tagName == 'row') {
1184 var label_list = row_list[i].childNodes;
1185 var found_type = false;
1186 for (var j = 0; j < label_list.length; j++) {
1187 if (label_list[j].nodeType &&
1188 label_list[j].tagName == 'label' &&
1189 label_list[j].getAttribute('set').indexOf(type) != -1) {
1194 row_list[i].hidden = true;
1200 function fillFixedFields (rec) {
1202 var grid = document.getElementById('leaderGrid');
1204 var rtype = _record_type;
1206 var _l = rec.leader.toString();
1207 var _6 = rec.controlfield.(@tag=='006').toString();
1208 var _7 = rec.controlfield.(@tag=='007').toString();
1209 var _8 = rec.controlfield.(@tag=='008').toString();
1212 var pre_list = grid.getElementsByTagName('label');
1213 for (var i in pre_list) {
1214 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1215 list.push( pre_list[i] );
1219 for (var i in list) {
1220 var name = list[i].getAttribute('name');
1226 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1227 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1229 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1230 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1232 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1233 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1235 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1236 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1241 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1242 d = ff_pos[name].ldr[rtype].def;
1246 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1247 d = ff_pos[name]._8[rtype].def;
1251 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1252 d = ff_pos[name]._6[rtype].def;
1256 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1257 d = ff_pos[name]._7[rtype].def;
1262 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1268 list[i].nextSibling.value = value;
1273 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1277 function updateFixedFields (element) {
1278 var grid = document.getElementById('leaderGrid');
1279 var recGrid = document.getElementById('recGrid');
1281 var rtype = _record_type;
1282 var new_value = element.value;
1285 ldr : _record.leader,
1286 _6 : _record.controlfield.(@tag=='006'),
1287 _7 : _record.controlfield.(@tag=='007'),
1288 _8 : _record.controlfield.(@tag=='008')
1291 var name = element.getAttribute('name');
1292 for (var i in ff_pos[name]) {
1294 if (!ff_pos[name][i][rtype]) continue;
1296 // we're missing the required field. Add it now.
1299 if (i == '_6') newfield = '006';
1300 else if (i == '_7') newfield = '007';
1301 else if (i == '_8') newfield = '008';
1304 createControlField(newfield,' ');
1305 parts[i] = _record.controlfield.(@tag==newfield);
1308 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1309 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1311 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1312 new_value += ff_pos[name][i][rtype].def;
1315 parts[i].setChildren( before + new_value + after );
1316 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1322 function marcLeader (leader) {
1323 var row = createRow(
1324 { class : 'marcLeaderRow',
1329 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1332 class : 'marcInd1' } ),
1335 class : 'marcInd2' } ),
1337 { value : leader.text(),
1338 class : 'marcLeader' } )
1344 function marcControlfield (field) {
1345 tagname = field.@tag.toString().substr(2);
1347 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1349 { class : 'marcControlfieldRow',
1350 tag : '_' + tagname },
1352 { value : field.@tag,
1354 context : 'tags_popup',
1355 onmouseover : 'getTooltip(this, "tag");',
1356 tooltipid : 'tag' + field.@tag } ),
1358 { value : field.@ind1,
1360 onmouseover : 'getTooltip(this, "ind1");',
1361 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1363 { value : field.@ind2,
1365 onmouseover : 'getTooltip(this, "ind2");',
1366 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1369 { value : field.text(),
1370 class : 'plain marcEditableControlfield',
1371 name : 'CONTROL' + tagname,
1372 context : 'clipboard',
1378 { class : 'marcControlfieldRow',
1379 tag : '_' + tagname },
1381 { value : field.@tag,
1383 onmouseover : 'getTooltip(this, "tag");',
1384 tooltipid : 'tag' + field.@tag } ),
1386 { value : field.@ind1,
1388 onmouseover : 'getTooltip(this, "ind1");',
1389 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1391 { value : field.@ind2,
1393 onmouseover : 'getTooltip(this, "ind2");',
1394 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1396 { value : field.text(),
1397 class : 'marcControlfield' } )
1404 function stackSubfields(checkbox) {
1405 var list = document.getElementsByAttribute('name','sf_box');
1408 if (!checkbox.checked) o = 'horizontal';
1410 for (var i = 0; i < list.length; i++) {
1411 if (list[i]) list[i].setAttribute('orient',o);
1415 function fastItemAdd_toggle(checkbox) {
1416 var x = document.getElementById('fastItemAdd_textboxes');
1417 if (checkbox.checked) {
1419 document.getElementById('fastItemAdd_callnumber').focus();
1420 document.getElementById('fastItemAdd_callnumber').select();
1426 function fastItemAdd_attempt(doc_id) {
1428 if (typeof window.xulG.fast_add_item != 'function') { return; }
1429 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1430 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1431 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1432 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1433 document.getElementById('fastItemAdd_barcode').value = '';
1435 alert('fastItemAdd_attempt: ' + E);
1439 function save_attempt(xml_string) {
1441 var result = window.xulG.save.func( xml_string );
1443 if (result.id) fastItemAdd_attempt(result.id);
1444 if (typeof result.on_complete == 'function') result.on_complete();
1447 alert('save_attempt: ' + E);
1451 function marcDatafield (field) {
1452 var row = createRow(
1453 { class : 'marcDatafieldRow' },
1456 { value : field.@tag,
1457 class : 'plain marcTag',
1459 context : 'tags_popup',
1460 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1463 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1466 { value : field.@ind1,
1467 class : 'plain marcInd1',
1469 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1472 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1473 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1476 { value : field.@ind2,
1477 class : 'plain marcInd2',
1479 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1482 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1483 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1484 createHbox({ name : 'sf_box' })
1487 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1488 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1489 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1491 var sf_box = row.lastChild;
1492 if (document.getElementById('stackSubfields').checked)
1493 sf_box.setAttribute('orient','vertical');
1495 sf_box.addEventListener(
1498 if (sf_box === e.target) {
1499 sf_box.lastChild.lastChild.focus();
1500 } else if (e.target.parentNode === sf_box) {
1501 e.target.lastChild.focus();
1508 for (var i in field.subfield) {
1509 var sf = field.subfield[i];
1514 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1516 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1517 current_focus = sf_box.lastChild.childNodes[1];
1523 function marcSubfield (sf) {
1525 { class : 'marcSubfieldBox' },
1528 class : 'plain marcSubfieldDelimiter',
1529 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1530 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1531 //onclick : 'this.nextSibling.focus();',
1532 onfocus : 'this.nextSibling.focus();',
1537 class : 'plain marcSubfieldCode',
1538 name : 'marcSubfieldCode',
1539 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1540 oncontextmenu : 'getContextMenu(this, "subfield");',
1541 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1546 { value : sf.text(),
1547 name : sf.parent().@tag + ':' + sf.@code,
1548 class : 'plain marcSubfield',
1549 onmouseover : 'getTooltip(this, "subfield");',
1550 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1551 size : new String(sf.text()).length + 2,
1552 oninput : "this.setAttribute('size', this.value.length + 2);"
1557 function loadRecord(rec) {
1560 var grid_rows = document.getElementById('recGrid').lastChild;
1562 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1564 grid_rows.appendChild( marcLeader( rec.leader ) );
1566 for (var i in rec.controlfield) {
1567 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1570 for (var i in rec.datafield) {
1571 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1574 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1575 changeFFEditor(recordType(rec));
1576 fillFixedFields(rec);
1578 alert('FIXME, MARC Editor, loadRecord: ' + E);
1583 function genToolTips () {
1584 for (var i in bib_data.field) {
1585 var f = bib_data.field[i];
1587 tag_menu.appendChild(
1591 'current_focus.value = "' + f.@tag + '";' +
1592 'var e = document.createEvent("MutationEvents");' +
1593 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1594 'current_focus.inputField.dispatchEvent(e);',
1595 disabled : f.@tag < '010' ? "true" : "false",
1596 tooltiptext : f.description }
1600 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1601 context_menus.appendChild( i1_popup );
1603 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1604 context_menus.appendChild( i2_popup );
1606 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1607 context_menus.appendChild( sf_popup );
1609 tooltip_hash['tag' + f.@tag] = f.description;
1610 for (var j in f.indicator) {
1611 var ind = f.indicator[j];
1612 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1614 if (ind.@position == 1) {
1615 i1_popup.appendChild(
1617 { label : ind.@value,
1619 'current_focus.value = "' + ind.@value + '";' +
1620 'var e = document.createEvent("MutationEvents");' +
1621 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1622 'current_focus.inputField.dispatchEvent(e);',
1623 tooltiptext : ind.description }
1628 if (ind.@position == 2) {
1629 i2_popup.appendChild(
1631 { label : ind.@value,
1633 'current_focus.value = "' + ind.@value + '";' +
1634 'var e = document.createEvent("MutationEvents");' +
1635 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1636 'current_focus.inputField.dispatchEvent(e);',
1637 tooltiptext : ind.description }
1643 for (var j in f.subfield) {
1644 var sf = f.subfield[j];
1645 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1647 sf_popup.appendChild(
1651 'current_focus.value = "' + sf.@code + '";' +
1652 'var e = document.createEvent("MutationEvents");' +
1653 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1654 'current_focus.inputField.dispatchEvent(e);',
1655 tooltiptext : sf.description
1663 function getTooltip (target, type) {
1666 if (type == 'subfield')
1667 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1670 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1673 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1676 tt = 'tag' + target.parentNode.firstChild.value;
1678 if (!document.getElementById( tt )) {
1683 orient : 'vertical',
1684 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1685 class : 'tooltip' },
1686 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1691 target.tooltip = tt;
1695 function getContextMenu (target, type) {
1698 if (type == 'subfield')
1699 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1702 tt = 't' + target.parentNode.firstChild.value + 'i1';
1705 tt = 't' + target.parentNode.firstChild.value + 'i2';
1707 target.setAttribute('context', tt);
1711 var authority_tag_map = {
1712 100 : ['[100,400,500,700]',100],
1713 400 : ['[100,400,500,700]',100],
1714 700 : ['[100,400,500,700]',100],
1715 800 : ['[100,400,500,700]',100],
1716 110 : ['[110,410,510,710]',110],
1717 410 : ['[110,410,510,710]',110],
1718 710 : ['[110,410,510,710]',110],
1719 810 : ['[110,410,510,710]',110],
1720 111 : ['[111,411,511,711]',111],
1721 411 : ['[111,411,511,711]',111],
1722 711 : ['[111,411,511,711]',111],
1723 811 : ['[111,411,511,711]',111],
1724 240 : ['[130,430,530,730]',130],
1725 440 : ['[130,430,530,730]',130],
1726 130 : ['[130,430,530,730]',130],
1727 730 : ['[130,430,530,730]',130],
1728 830 : ['[130,430,530,730]',130],
1729 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1730 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1731 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1732 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1735 function getAuthorityContextMenu (target, sf) {
1736 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1738 var old = document.getElementById( menu_id );
1739 if (old) old.parentNode.removeChild(old);
1741 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1742 context_menus.appendChild( sf_popup );
1744 if (!authority_tag_map[sf.parent().@tag]) {
1745 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1746 target.setAttribute('context', 'clipboard');
1750 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1752 var res = new XML( auth_data.responseText );
1756 var recs = res.gw::payload.gw::array.gw::string;
1757 for (var i in recs) {
1759 var xml = new XML(x.toString());
1760 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1762 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1765 for (var i in main) {
1766 if (main_text) main_text += ' / ';
1767 main_text += main[i];
1770 rec_list.push( [ main_text, xml ] );
1773 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1775 var main_text = rec_list[i][0];
1776 var xml = rec_list[i][1];
1777 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1779 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1781 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1782 grid.setAttribute('name','-none-');
1783 grid.setAttribute('style','overflow:scroll');
1786 var submenu = createMenu( { label : main_text } );
1788 var popup = createMenuPopup({ flex : "1" });
1789 submenu.appendChild(popup);
1791 var fields = xml.datafield;
1792 for (var j in fields) {
1794 var row = createRow(
1796 createLabel( { value : fields[j].@tag } ),
1797 createLabel( { value : fields[j].@ind1 } ),
1798 createLabel( { value : fields[j].@ind2 } )
1801 var sf_box = createHbox();
1803 var subfields = fields[j].subfield;
1804 for (var k in subfields) {
1807 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1808 subfield : subfields[k].@code,
1809 tag : subfields[k].parent().@tag,
1810 value : subfields[k]
1814 row.appendChild(sf_box);
1817 grid.lastChild.appendChild(row);
1820 grid.hidden = false;
1821 popup.appendChild( grid );
1825 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1826 command : function (event) {
1827 applyAuthority(event.target.previousSibling, target, sf);
1834 sf_popup.appendChild( submenu );
1837 if (sf_popup.childNodes.length == 0)
1838 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1840 target.setAttribute('context', menu_id);
1844 function applyAuthority ( target, ui_sf, e4x_sf ) {
1846 var new_vals = target.getElementsByAttribute('checked','true');
1847 var field = e4x_sf.parent();
1849 for (var i = 0; i < new_vals.length; i++) {
1851 var sf_list = field.subfield;
1852 for (var j in sf_list) {
1854 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1855 sf_list[j] = new_vals[i].getAttribute('value');
1856 new_vals[i].setAttribute('subfield','');
1862 for (var i = 0; i < new_vals.length; i++) {
1863 if (!new_vals[i].getAttribute('subfield')) continue;
1865 var val = new_vals[i].getAttribute('value');
1867 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1868 sf.@code = new_vals[i].getAttribute('subfield');
1870 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1873 var row = marcDatafield( field );
1876 while (node.nodeName != 'row') {
1877 node = node.parentNode;
1880 node.parentNode.replaceChild( row, node );
1886 'a' : { 100 : 'a' },
1887 'd' : { 100 : 'd' },
1891 'a' : { 110 : 'a' },
1895 'a' : { 111 : 'a' },
1899 'a' : { 130 : 'a' },
1903 'a' : { 130 : 'a' },
1907 'a' : { 100 : 'a' },
1911 'a' : { 110 : 'a' },
1915 'a' : { 111 : 'a' },
1919 'a' : { 130 : 'a' },
1920 'n' : { 130 : 'n' },
1924 'a' : { 100 : 'a' },
1925 'd' : { 100 : 'd' },
1926 'q' : { 100 : 'q' },
1930 'a' : { 110 : 'a' },
1934 'a' : { 111 : 'a' },
1938 'a' : { 130 : 'a' },
1942 'a' : { 100 : 'a' },
1946 'a' : { 110 : 'a' },
1950 'a' : { 111 : 'a' },
1954 'a' : { 130 : 'a' },
1958 'a' : { 100 : 'a' },
1959 'd' : { 100 : 'd' },
1960 'q' : { 100 : 'q' },
1961 't' : { 100 : 't' },
1988 'a' : { 110 : 'a' },
1989 'd' : { 110 : 'd' },
1990 't' : { 110 : 't' },
2017 'a' : { 111 : 'a' },
2018 'd' : { 111 : 'd' },
2019 't' : { 111 : 't' },
2046 'a' : { 130 : 'a' },
2050 'a' : { 150 : 'a' },
2051 'b' : { 150 : 'b' },
2078 'a' : { 151 : 'a' },
2105 'a' : { 155 : 'a' },
2133 function validateAuthority (button) {
2134 var grid = document.getElementById('recGrid');
2135 var label = button.getAttribute('label');
2138 var rows = grid.lastChild.childNodes;
2139 for (var i = 0; i < rows.length; i++) {
2141 var tag = row.firstChild;
2143 if (!control_map[tag.value]) continue
2144 button.setAttribute('label', label + ' - ' + tag.value);
2146 var ind1 = tag.nextSibling;
2147 var ind2 = ind1.nextSibling;
2148 var subfields = ind2.nextSibling.childNodes;
2152 for (var j = 0; j < subfields.length; j++) {
2153 var sf = subfields[j];
2154 var sf_code = sf.childNodes[1].value;
2155 var sf_value = sf.childNodes[2].value;
2157 if (!control_map[tag.value][sf_code]) continue;
2160 for (var a_tag in control_map[tag.value][sf_code]) {
2161 if (!tags[a_tag]) tags[a_tag] = [];
2162 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2167 for (var val_tag in tags) {
2168 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2169 var res = new XML( auth_data.responseText );
2170 found = parseInt(res.gw::payload.gw::string.toString());
2174 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2175 for (var j = 0; j < subfields.length; j++) {
2176 var sf = subfields[j];
2178 sf.childNodes[2].inputField.style.color = 'red';
2180 sf.childNodes[2].inputField.style.color = 'black';
2185 button.setAttribute('label', label);
2191 function validateBibField (tags, searches) {
2192 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2193 url += '¶m="tags"¶m=' + js2JSON(tags);
2194 url += '¶m="searches"¶m=' + js2JSON(searches);
2197 var req = new XMLHttpRequest();
2198 req.open('GET',url,false);
2204 function searchAuthority (term, tag, sf, limit) {
2205 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2206 url += '¶m="term"¶m="' + term + '"';
2207 url += '¶m="limit"¶m=' + limit;
2208 url += '¶m="tag"¶m=' + tag;
2209 url += '¶m="subfield"¶m="' + sf + '"';
2212 var req = new XMLHttpRequest();
2213 req.open('GET',url,false);