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 var keep_looking = true;
388 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
389 // Is it a datafield?
390 dojo.query('hbox hbox textbox', row).forEach(function(node, index, arr) {
392 keep_looking = false;
395 // No, it's a control field; use the first textbox
397 dojo.query('textbox', row).forEach(function(node, index, arr) {
399 keep_looking = false;
408 function createMARCTextbox (element,attrs) {
410 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
411 box.onkeypress = function (event) {
414 while(node = node.parent()) {
418 var row = event.target;
419 while (row.tagName != 'row') row = row.parentNode;
421 if (element.nodeKind() == 'attribute') element[0]=box.value;
422 else element.setChildren( box.value );
424 if (element.localName() != 'controlfield') {
425 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
427 var index_sf, target, move_data;
428 if (element.localName() == 'subfield') {
430 target = event.target.parentNode;
432 var start = event.target.selectionStart;
433 var end = event.target.selectionEnd - event.target.selectionStart ?
434 event.target.selectionEnd :
435 event.target.value.length;
437 move_data = event.target.value.substring(start,end);
438 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
439 event.target.setAttribute('size', event.target.value.length + 2);
441 element.setChildren( event.target.value );
443 } else if (element.localName() == 'code') {
444 index_sf = element.parent();
445 target = event.target.parentNode;
446 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
447 index_sf = element.parent().children()[element.parent().children().length() - 1];
448 target = event.target.parentNode.lastChild.lastChild;
451 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
453 index_sf.parent().insertChildAfter( index_sf, sf );
455 var new_sf = marcSubfield(sf);
457 if (target === target.parentNode.lastChild) {
458 target.parentNode.appendChild( new_sf );
460 target.parentNode.insertBefore( new_sf, target.nextSibling );
463 new_sf.firstChild.nextSibling.focus();
465 event.preventDefault();
468 } else if (event.keyCode == 13 || event.keyCode == 77) {
469 if (event.ctrlKey) { // ctrl+enter
472 if (element.localName() == 'subfield') index = element.parent();
473 if (element.localName() == 'code') index = element.parent().parent();
474 if (element.localName() == 'tag') index = element.parent();
475 if (element.localName() == 'ind1') index = element.parent();
476 if (element.localName() == 'ind2') index = element.parent();
478 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
480 if (event.shiftKey) { // ctrl+shift+enter
481 index.parent().insertChildBefore( index, df );
483 index.parent().insertChildAfter( index, df );
486 var new_df = marcDatafield(df);
488 if (row.parentNode.lastChild === row) {
489 row.parentNode.appendChild( new_df );
491 if (event.shiftKey) { // ctrl+shift+enter
492 row.parentNode.insertBefore( new_df, row );
494 row.parentNode.insertBefore( new_df, row.nextSibling );
498 new_df.firstChild.focus();
500 event.preventDefault();
503 } else if (event.shiftKey) {
504 if (row.previousSibling.className.match('marcDatafieldRow'))
505 row.previousSibling.firstChild.focus();
507 row.nextSibling.firstChild.focus();
510 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
511 if (event.ctrlKey) { // CTRL key: copy the field
513 if (element.localName() == 'subfield') index = element.parent();
514 if (element.localName() == 'code') index = element.parent().parent();
515 if (element.localName() == 'tag') index = element.parent();
516 if (element.localName() == 'ind1') index = element.parent();
517 if (element.localName() == 'ind2') index = element.parent();
519 var copyField = index.copy();
521 if (event.keyCode == 38) { // ctrl+up-arrow
522 index.parent().insertChildBefore( index, copyField );
524 index.parent().insertChildAfter( index, copyField );
527 var new_df = marcDatafield(copyField);
529 if (row.parentNode.lastChild === row) {
530 row.parentNode.appendChild( new_df );
532 if (event.keyCode == 38) { // ctrl+up-arrow
533 row.parentNode.insertBefore( new_df, row );
534 } else { // ctrl+down-arrow
535 row.parentNode.insertBefore( new_df, row.nextSibling );
539 new_df.firstChild.focus();
541 event.preventDefault();
545 if (event.keyCode == 38) {
546 return setFocusToNextTag(row, 'up');
548 if (event.keyCode == 40) {
549 return setFocusToNextTag(row, 'down');
554 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
557 if (element.localName() == 'subfield') index = element.parent();
558 if (element.localName() == 'code') index = element.parent().parent();
559 if (element.localName() == 'tag') index = element.parent();
560 if (element.localName() == 'ind1') index = element.parent();
561 if (element.localName() == 'ind2') index = element.parent();
563 for (var i in index.parent().children()) {
564 if (index === index.parent().children()[i]) {
565 delete index.parent().children()[i];
570 row.previousSibling.firstChild.focus();
571 row.parentNode.removeChild(row);
573 event.preventDefault();
576 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
579 if (element.localName() == 'subfield') index = element;
580 if (element.localName() == 'code') index = element.parent();
583 for (var i in index.parent().children()) {
584 if (index === index.parent().children()[i]) {
585 delete index.parent().children()[i];
590 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
591 event.target.parentNode.previousSibling.lastChild.focus();
593 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
596 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
598 event.preventDefault();
601 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
602 createControlField('006',' ');
603 loadRecord(xml_record);
604 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
605 createControlField('007',' ');
606 loadRecord(xml_record);
607 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
608 createControlField('008',' ');
609 loadRecord(xml_record);
614 } else { // event on a control field
615 if (event.keyCode == 38) {
616 return setFocusToNextTag(row, 'up');
617 } else if (event.keyCode == 40) {
618 return setFocusToNextTag(row, 'down');
623 box.addEventListener(
626 if (element.nodeKind() == 'attribute') element[0]=box.value;
627 else element.setChildren( box.value );
633 box.addEventListener(
636 if (element.nodeKind() == 'attribute') element[0]=box.value;
637 else element.setChildren( box.value );
643 box.addEventListener(
646 if (element.nodeKind() == 'attribute') element[0]=box.value;
647 else element.setChildren( box.value );
653 box.addEventListener(
656 if (element.localName() == 'controlfield')
657 eval('fillFixedFields(xml_record);');
666 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
667 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
668 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
669 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
670 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
671 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
672 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
673 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ },
674 AUT : { Type : /[z]{1}/, BLvl : /.{1}/ },
675 MFHD : { Type : /[uvxy]{1}/, BLvl : /.{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' },
913 AUT : {start : 6, len : 1, def : 'z' },
914 MFHD : {start : 6, len : 1, def : 'y' }
919 BKS : {start : 8, len : 1, def : ' ' },
920 SER : {start : 8, len : 1, def : ' ' },
921 VIS : {start : 8, len : 1, def : ' ' },
922 MIX : {start : 8, len : 1, def : ' ' },
923 MAP : {start : 8, len : 1, def : ' ' },
924 SCO : {start : 8, len : 1, def : ' ' },
925 REC : {start : 8, len : 1, def : ' ' },
926 COM : {start : 8, len : 1, def : ' ' }
931 BKS : {start : 7, len : 1, def : 'm' },
932 SER : {start : 7, len : 1, def : 's' },
933 VIS : {start : 7, len : 1, def : 'm' },
934 MIX : {start : 7, len : 1, def : 'c' },
935 MAP : {start : 7, len : 1, def : 'm' },
936 SCO : {start : 7, len : 1, def : 'm' },
937 REC : {start : 7, len : 1, def : 'm' },
938 COM : {start : 7, len : 1, def : 'm' }
943 BKS : {start : 18, len : 1, def : ' ' },
944 SER : {start : 18, len : 1, def : ' ' },
945 VIS : {start : 18, len : 1, def : ' ' },
946 MIX : {start : 18, len : 1, def : ' ' },
947 MAP : {start : 18, len : 1, def : ' ' },
948 SCO : {start : 18, len : 1, def : ' ' },
949 REC : {start : 18, len : 1, def : ' ' },
950 COM : {start : 18, len : 1, def : 'i' }
955 MFHD : {start : 18, len : 1, def : 'i' }
960 BKS : {start : 17, len : 1, def : ' ' },
961 SER : {start : 17, len : 1, def : ' ' },
962 VIS : {start : 17, len : 1, def : ' ' },
963 MIX : {start : 17, len : 1, def : ' ' },
964 MAP : {start : 17, len : 1, def : ' ' },
965 SCO : {start : 17, len : 1, def : ' ' },
966 REC : {start : 17, len : 1, def : ' ' },
967 COM : {start : 17, len : 1, def : ' ' },
968 AUT : {start : 17, len : 1, def : 'n' },
969 MFHD : {start : 17, len : 1, def : 'u' }
974 BKS : {start : 31, len : 1, def : '0' },
975 MAP : {start : 31, len : 1, def : '0' }
978 BKS : {start : 14, len : 1, def : '0' },
979 MAP : {start : 14, len : 1, def : '0' }
984 BKS : {start : 7, len : 4, def : ' ' },
985 SER : {start : 7, len : 4, def : ' ' },
986 VIS : {start : 7, len : 4, def : ' ' },
987 MIX : {start : 7, len : 4, def : ' ' },
988 MAP : {start : 7, len : 4, def : ' ' },
989 SCO : {start : 7, len : 4, def : ' ' },
990 REC : {start : 7, len : 4, def : ' ' },
991 COM : {start : 7, len : 4, def : ' ' }
996 BKS : {start : 11, len : 4, def : ' ' },
997 SER : {start : 11, len : 4, def : '9' },
998 VIS : {start : 11, len : 4, def : ' ' },
999 MIX : {start : 11, len : 4, def : ' ' },
1000 MAP : {start : 11, len : 4, def : ' ' },
1001 SCO : {start : 11, len : 4, def : ' ' },
1002 REC : {start : 11, len : 4, def : ' ' },
1003 COM : {start : 11, len : 4, def : ' ' }
1008 BKS : {start : 33, len : 1, def : '0' }
1011 BKS : {start : 16, len : 1, def : '0' }
1016 BKS : {start : 34, len : 1, def : ' ' }
1019 BKS : {start : 17, len : 1, def : ' ' }
1024 BKS : {start : 18, len : 4, def : ' ' }
1027 BKS : {start : 1, len : 4, def : ' ' }
1032 BKS : {start : 30, len : 1, def : '0' }
1035 BKS : {start : 13, len : 1, def : '0' }
1040 BKS : {start : 29, len : 1, def : '0' },
1041 SER : {start : 29, len : 1, def : '0' }
1044 BKS : {start : 12, len : 1, def : '0' },
1045 SER : {start : 12, len : 1, def : '0' }
1050 BKS : {start : 24, len : 4, def : ' ' },
1051 SER : {start : 25, len : 3, def : ' ' }
1054 BKS : {start : 7, len : 4, def : ' ' },
1055 SER : {start : 8, len : 3, def : ' ' }
1060 BKS : {start : 28, len : 1, def : ' ' },
1061 SER : {start : 28, len : 1, def : ' ' },
1062 VIS : {start : 28, len : 1, def : ' ' },
1063 MAP : {start : 28, len : 1, def : ' ' },
1064 COM : {start : 28, len : 1, def : ' ' }
1067 BKS : {start : 11, len : 1, def : ' ' },
1068 SER : {start : 11, len : 1, def : ' ' },
1069 VIS : {start : 11, len : 1, def : ' ' },
1070 MAP : {start : 11, len : 1, def : ' ' },
1071 COM : {start : 11, len : 1, def : ' ' }
1076 BKS : {start : 22, len : 1, def : ' ' },
1077 SER : {start : 22, len : 1, def : ' ' },
1078 VIS : {start : 22, len : 1, def : ' ' },
1079 SCO : {start : 22, len : 1, def : ' ' },
1080 REC : {start : 22, len : 1, def : ' ' },
1081 COM : {start : 22, len : 1, def : ' ' }
1084 BKS : {start : 5, len : 1, def : ' ' },
1085 SER : {start : 5, len : 1, def : ' ' },
1086 VIS : {start : 5, len : 1, def : ' ' },
1087 SCO : {start : 5, len : 1, def : ' ' },
1088 REC : {start : 5, len : 1, def : ' ' },
1089 COM : {start : 5, len : 1, def : ' ' }
1094 BKS : {start : 23, len : 1, def : ' ' },
1095 SER : {start : 23, len : 1, def : ' ' },
1096 VIS : {start : 29, len : 1, def : ' ' },
1097 MIX : {start : 23, len : 1, def : ' ' },
1098 MAP : {start : 29, len : 1, def : ' ' },
1099 SCO : {start : 23, len : 1, def : ' ' },
1100 REC : {start : 23, len : 1, def : ' ' }
1103 BKS : {start : 6, len : 1, def : ' ' },
1104 SER : {start : 6, len : 1, def : ' ' },
1105 VIS : {start : 12, len : 1, def : ' ' },
1106 MIX : {start : 6, len : 1, def : ' ' },
1107 MAP : {start : 12, len : 1, def : ' ' },
1108 SCO : {start : 6, len : 1, def : ' ' },
1109 REC : {start : 6, len : 1, def : ' ' }
1114 SER : {start : 34, len : 1, def : '0' }
1117 SER : {start : 17, len : 1, def : '0' }
1122 SER : {start : 33, len : 1, def : ' ' }
1125 SER : {start : 16, len : 1, def : ' ' }
1130 "AUT" : {"start" : 6, "len" : 1, "def" : ' ' }
1135 "AUT" : {"start" : 7, "len" : 1, "def" : ' ' }
1140 "AUT" : {"start" : 8, "len" : 1, "def" : ' ' }
1145 "AUT" : {"start" : 9, "len" : 1, "def" : ' ' }
1150 "AUT" : {"start" : 10, "len" : 1, "def" : ' ' }
1155 "AUT" : {"start" : 11, "len" : 1, "def" : ' ' }
1160 "AUT" : {"start" : 12, "len" : 1, "def" : ' ' }
1165 "AUT" : {"start" : 13, "len" : 1, "def" : ' ' }
1170 "AUT" : {"start" : 14, "len" : 1, "def" : ' ' }
1175 "AUT" : {"start" : 15, "len" : 1, "def" : ' ' }
1180 "AUT" : {"start" : 16, "len" : 1, "def" : ' ' }
1185 "AUT" : {"start" : 17, "len" : 1, "def" : ' ' }
1190 "AUT" : {"start" : 28, "len" : 1, "def" : ' ' }
1195 "AUT" : {"start" : 29, "len" : 1, "def" : ' ' }
1200 "AUT" : {"start" : 31, "len" : 1, "def" : ' ' }
1205 "AUT" : {"start" : 32, "len" : 1, "def" : ' ' }
1210 "AUT" : {"start" : 33, "len" : 1, "def" : ' ' }
1215 "AUT" : {"start" : 38, "len" : 1, "def" : ' ' }
1220 "AUT" : {"start" : 39, "len" : 1, "def" : ' ' }
1225 function recordType (rec) {
1227 var _l = rec.leader.toString();
1229 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1230 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1232 for (var t in rec_type) {
1233 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1234 document.getElementById('recordTypeLabel').value = t;
1240 // in case we don't have a valid record type ...
1241 _record_type = 'BKS';
1242 return _record_type;
1245 alert('FIXME, MARC Editor, recordType: ' + E);
1249 function toggleFFE () {
1250 var grid = document.getElementById('leaderGrid');
1252 grid.hidden = false;
1259 function changeFFEditor (type) {
1260 var grid = document.getElementById('leaderGrid');
1261 grid.setAttribute('type',type);
1263 // Hide FFEditor rows that we don't need for our current type
1264 // If all of the labels for a given row do not include our
1265 // desired type in their set attribute, we can hide that row
1266 dojo.query('rows row', grid).forEach(function(node, index, arr) {
1267 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
1274 function fillFixedFields (rec) {
1276 var grid = document.getElementById('leaderGrid');
1278 var rtype = _record_type;
1280 var _l = rec.leader.toString();
1281 var _6 = rec.controlfield.(@tag=='006').toString();
1282 var _7 = rec.controlfield.(@tag=='007').toString();
1283 var _8 = rec.controlfield.(@tag=='008').toString();
1286 var pre_list = grid.getElementsByTagName('label');
1287 for (var i in pre_list) {
1288 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1289 list.push( pre_list[i] );
1293 for (var i in list) {
1294 var name = list[i].getAttribute('name');
1300 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1301 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1303 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1304 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1306 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1307 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1309 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1310 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1315 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1316 d = ff_pos[name].ldr[rtype].def;
1320 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1321 d = ff_pos[name]._8[rtype].def;
1325 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1326 d = ff_pos[name]._6[rtype].def;
1330 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1331 d = ff_pos[name]._7[rtype].def;
1336 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1342 list[i].nextSibling.value = value;
1347 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1351 function updateFixedFields (element) {
1352 var grid = document.getElementById('leaderGrid');
1353 var recGrid = document.getElementById('recGrid');
1355 var rtype = _record_type;
1356 var new_value = element.value;
1359 ldr : _record.leader,
1360 _6 : _record.controlfield.(@tag=='006'),
1361 _7 : _record.controlfield.(@tag=='007'),
1362 _8 : _record.controlfield.(@tag=='008')
1365 var name = element.getAttribute('name');
1366 for (var i in ff_pos[name]) {
1368 if (!ff_pos[name][i][rtype]) continue;
1370 // we're missing the required field. Add it now.
1373 if (i == '_6') newfield = '006';
1374 else if (i == '_7') newfield = '007';
1375 else if (i == '_8') newfield = '008';
1378 createControlField(newfield,' ');
1379 parts[i] = _record.controlfield.(@tag==newfield);
1382 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1383 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1385 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1386 new_value += ff_pos[name][i][rtype].def;
1389 parts[i].setChildren( before + new_value + after );
1390 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1396 function marcLeader (leader) {
1397 var row = createRow(
1398 { class : 'marcLeaderRow',
1403 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1406 class : 'marcInd1' } ),
1409 class : 'marcInd2' } ),
1411 { value : leader.text(),
1412 class : 'marcLeader' } )
1418 function marcControlfield (field) {
1419 tagname = field.@tag.toString().substr(2);
1421 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1423 { class : 'marcControlfieldRow',
1424 tag : '_' + tagname },
1426 { value : field.@tag,
1428 context : 'tags_popup',
1429 onmouseover : 'getTooltip(this, "tag");',
1430 tooltipid : 'tag' + field.@tag } ),
1432 { value : field.@ind1,
1434 onmouseover : 'getTooltip(this, "ind1");',
1435 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1437 { value : field.@ind2,
1439 onmouseover : 'getTooltip(this, "ind2");',
1440 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1443 { value : field.text(),
1444 class : 'plain marcEditableControlfield',
1445 name : 'CONTROL' + tagname,
1446 context : 'clipboard',
1452 { class : 'marcControlfieldRow',
1453 tag : '_' + tagname },
1455 { value : field.@tag,
1457 onmouseover : 'getTooltip(this, "tag");',
1458 tooltipid : 'tag' + field.@tag } ),
1460 { value : field.@ind1,
1462 onmouseover : 'getTooltip(this, "ind1");',
1463 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1465 { value : field.@ind2,
1467 onmouseover : 'getTooltip(this, "ind2");',
1468 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1470 { value : field.text(),
1471 class : 'marcControlfield' } )
1478 function stackSubfields(checkbox) {
1479 var list = document.getElementsByAttribute('name','sf_box');
1482 if (!checkbox.checked) o = 'horizontal';
1484 for (var i = 0; i < list.length; i++) {
1485 if (list[i]) list[i].setAttribute('orient',o);
1489 function fastItemAdd_toggle(checkbox) {
1490 var x = document.getElementById('fastItemAdd_textboxes');
1491 if (checkbox.checked) {
1493 document.getElementById('fastItemAdd_callnumber').focus();
1494 document.getElementById('fastItemAdd_callnumber').select();
1500 function fastItemAdd_attempt(doc_id) {
1502 if (typeof window.xulG.fast_add_item != 'function') { return; }
1503 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1504 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1505 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1506 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1507 document.getElementById('fastItemAdd_barcode').value = '';
1509 alert('fastItemAdd_attempt: ' + E);
1513 function save_attempt(xml_string) {
1515 var result = window.xulG.save.func( xml_string );
1517 if (result.id) fastItemAdd_attempt(result.id);
1518 if (typeof result.on_complete == 'function') result.on_complete();
1521 alert('save_attempt: ' + E);
1525 function marcDatafield (field) {
1526 var row = createRow(
1527 { class : 'marcDatafieldRow' },
1530 { value : field.@tag,
1531 class : 'plain marcTag',
1533 context : 'tags_popup',
1534 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1537 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1540 { value : field.@ind1,
1541 class : 'plain marcInd1',
1543 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1546 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1547 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1550 { value : field.@ind2,
1551 class : 'plain marcInd2',
1553 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1556 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1557 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1558 createHbox({ name : 'sf_box' })
1561 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1562 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1563 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1565 var sf_box = row.lastChild;
1566 if (document.getElementById('stackSubfields').checked)
1567 sf_box.setAttribute('orient','vertical');
1569 sf_box.addEventListener(
1572 if (sf_box === e.target) {
1573 sf_box.lastChild.lastChild.focus();
1574 } else if (e.target.parentNode === sf_box) {
1575 e.target.lastChild.focus();
1582 for (var i in field.subfield) {
1583 var sf = field.subfield[i];
1588 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1590 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1591 current_focus = sf_box.lastChild.childNodes[1];
1597 function marcSubfield (sf) {
1599 { class : 'marcSubfieldBox' },
1602 class : 'plain marcSubfieldDelimiter',
1603 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1604 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1605 //onclick : 'this.nextSibling.focus();',
1606 onfocus : 'this.nextSibling.focus();',
1611 class : 'plain marcSubfieldCode',
1612 name : 'marcSubfieldCode',
1613 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1614 oncontextmenu : 'getContextMenu(this, "subfield");',
1615 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1620 { value : sf.text(),
1621 name : sf.parent().@tag + ':' + sf.@code,
1622 class : 'plain marcSubfield',
1623 onmouseover : 'getTooltip(this, "subfield");',
1624 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1625 size : new String(sf.text()).length + 2,
1626 oninput : "this.setAttribute('size', this.value.length + 2);"
1631 function loadRecord(rec) {
1634 var grid_rows = document.getElementById('recGrid').lastChild;
1636 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1638 grid_rows.appendChild( marcLeader( rec.leader ) );
1640 for (var i in rec.controlfield) {
1641 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1644 for (var i in rec.datafield) {
1645 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1648 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1649 changeFFEditor(recordType(rec));
1650 fillFixedFields(rec);
1652 alert('FIXME, MARC Editor, loadRecord: ' + E);
1657 function genToolTips () {
1658 for (var i in bib_data.field) {
1659 var f = bib_data.field[i];
1661 tag_menu.appendChild(
1665 'current_focus.value = "' + f.@tag + '";' +
1666 'var e = document.createEvent("MutationEvents");' +
1667 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1668 'current_focus.inputField.dispatchEvent(e);',
1669 disabled : f.@tag < '010' ? "true" : "false",
1670 tooltiptext : f.description }
1674 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1675 context_menus.appendChild( i1_popup );
1677 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1678 context_menus.appendChild( i2_popup );
1680 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1681 context_menus.appendChild( sf_popup );
1683 tooltip_hash['tag' + f.@tag] = f.description;
1684 for (var j in f.indicator) {
1685 var ind = f.indicator[j];
1686 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1688 if (ind.@position == 1) {
1689 i1_popup.appendChild(
1691 { label : ind.@value,
1693 'current_focus.value = "' + ind.@value + '";' +
1694 'var e = document.createEvent("MutationEvents");' +
1695 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1696 'current_focus.inputField.dispatchEvent(e);',
1697 tooltiptext : ind.description }
1702 if (ind.@position == 2) {
1703 i2_popup.appendChild(
1705 { label : ind.@value,
1707 'current_focus.value = "' + ind.@value + '";' +
1708 'var e = document.createEvent("MutationEvents");' +
1709 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1710 'current_focus.inputField.dispatchEvent(e);',
1711 tooltiptext : ind.description }
1717 for (var j in f.subfield) {
1718 var sf = f.subfield[j];
1719 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1721 sf_popup.appendChild(
1725 'current_focus.value = "' + sf.@code + '";' +
1726 'var e = document.createEvent("MutationEvents");' +
1727 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1728 'current_focus.inputField.dispatchEvent(e);',
1729 tooltiptext : sf.description
1737 function getTooltip (target, type) {
1740 if (type == 'subfield')
1741 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1744 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1747 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1750 tt = 'tag' + target.parentNode.firstChild.value;
1752 if (!document.getElementById( tt )) {
1757 orient : 'vertical',
1758 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1759 class : 'tooltip' },
1760 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1765 target.tooltip = tt;
1769 function getContextMenu (target, type) {
1772 if (type == 'subfield')
1773 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1776 tt = 't' + target.parentNode.firstChild.value + 'i1';
1779 tt = 't' + target.parentNode.firstChild.value + 'i2';
1781 target.setAttribute('context', tt);
1785 var authority_tag_map = {
1786 100 : ['[100,400,500,700]',100],
1787 400 : ['[100,400,500,700]',100],
1788 700 : ['[100,400,500,700]',100],
1789 800 : ['[100,400,500,700]',100],
1790 110 : ['[110,410,510,710]',110],
1791 410 : ['[110,410,510,710]',110],
1792 710 : ['[110,410,510,710]',110],
1793 810 : ['[110,410,510,710]',110],
1794 111 : ['[111,411,511,711]',111],
1795 411 : ['[111,411,511,711]',111],
1796 711 : ['[111,411,511,711]',111],
1797 811 : ['[111,411,511,711]',111],
1798 240 : ['[130,430,530,730]',130],
1799 440 : ['[130,430,530,730]',130],
1800 130 : ['[130,430,530,730]',130],
1801 730 : ['[130,430,530,730]',130],
1802 830 : ['[130,430,530,730]',130],
1803 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1804 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1805 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1806 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1809 function getAuthorityContextMenu (target, sf) {
1810 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1812 var old = document.getElementById( menu_id );
1813 if (old) old.parentNode.removeChild(old);
1815 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1816 context_menus.appendChild( sf_popup );
1818 if (!authority_tag_map[sf.parent().@tag]) {
1819 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1820 target.setAttribute('context', 'clipboard');
1824 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1826 var res = new XML( auth_data.responseText );
1830 var recs = res.gw::payload.gw::array.gw::string;
1831 for (var i in recs) {
1833 var xml = new XML(x.toString());
1834 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1836 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1839 for (var i in main) {
1840 if (main_text) main_text += ' / ';
1841 main_text += main[i];
1844 rec_list.push( [ main_text, xml ] );
1847 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1849 var main_text = rec_list[i][0];
1850 var xml = rec_list[i][1];
1851 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1853 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1855 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1856 grid.setAttribute('name','-none-');
1857 grid.setAttribute('style','overflow:scroll');
1860 var submenu = createMenu( { label : main_text } );
1862 var popup = createMenuPopup({ flex : "1" });
1863 submenu.appendChild(popup);
1865 var fields = xml.datafield;
1866 for (var j in fields) {
1868 var row = createRow(
1870 createLabel( { value : fields[j].@tag } ),
1871 createLabel( { value : fields[j].@ind1 } ),
1872 createLabel( { value : fields[j].@ind2 } )
1875 var sf_box = createHbox();
1877 var subfields = fields[j].subfield;
1878 for (var k in subfields) {
1881 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1882 subfield : subfields[k].@code,
1883 tag : subfields[k].parent().@tag,
1884 value : subfields[k]
1888 row.appendChild(sf_box);
1891 grid.lastChild.appendChild(row);
1894 grid.hidden = false;
1895 popup.appendChild( grid );
1899 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1900 command : function (event) {
1901 applyAuthority(event.target.previousSibling, target, sf);
1908 sf_popup.appendChild( submenu );
1911 if (sf_popup.childNodes.length == 0)
1912 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1914 target.setAttribute('context', menu_id);
1918 function applyAuthority ( target, ui_sf, e4x_sf ) {
1920 var new_vals = target.getElementsByAttribute('checked','true');
1921 var field = e4x_sf.parent();
1923 for (var i = 0; i < new_vals.length; i++) {
1925 var sf_list = field.subfield;
1926 for (var j in sf_list) {
1928 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1929 sf_list[j] = new_vals[i].getAttribute('value');
1930 new_vals[i].setAttribute('subfield','');
1936 for (var i = 0; i < new_vals.length; i++) {
1937 if (!new_vals[i].getAttribute('subfield')) continue;
1939 var val = new_vals[i].getAttribute('value');
1941 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1942 sf.@code = new_vals[i].getAttribute('subfield');
1944 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1947 var row = marcDatafield( field );
1950 while (node.nodeName != 'row') {
1951 node = node.parentNode;
1954 node.parentNode.replaceChild( row, node );
1960 'a' : { 100 : 'a' },
1961 'd' : { 100 : 'd' },
1962 'e' : { 100 : 'e' },
1966 'a' : { 110 : 'a' },
1970 'a' : { 111 : 'a' },
1974 'a' : { 130 : 'a' },
1978 'a' : { 130 : 'a' },
1982 'a' : { 100 : 'a' },
1986 'a' : { 110 : 'a' },
1990 'a' : { 111 : 'a' },
1994 'a' : { 130 : 'a' },
1995 'n' : { 130 : 'n' },
1999 'a' : { 100 : 'a' },
2000 'd' : { 100 : 'd' },
2001 'q' : { 100 : 'q' },
2005 'a' : { 110 : 'a' },
2009 'a' : { 111 : 'a' },
2010 'c' : { 111 : 'c' },
2014 'a' : { 130 : 'a' },
2018 'a' : { 100 : 'a' },
2022 'a' : { 110 : 'a' },
2026 'a' : { 111 : 'a' },
2030 'a' : { 130 : 'a' },
2034 'a' : { 100 : 'a' },
2035 'd' : { 100 : 'd' },
2036 'q' : { 100 : 'q' },
2037 't' : { 100 : 't' },
2064 'a' : { 110 : 'a' },
2065 'd' : { 110 : 'd' },
2066 't' : { 110 : 't' },
2093 'a' : { 111 : 'a' },
2094 'd' : { 111 : 'd' },
2095 't' : { 111 : 't' },
2122 'a' : { 130 : 'a' },
2126 'a' : { 150 : 'a' },
2127 'b' : { 150 : 'b' },
2154 'a' : { 151 : 'a' },
2181 'a' : { 155 : 'a' },
2209 function validateAuthority (button) {
2210 var grid = document.getElementById('recGrid');
2211 var label = button.getAttribute('label');
2214 var rows = grid.lastChild.childNodes;
2215 for (var i = 0; i < rows.length; i++) {
2217 var tag = row.firstChild;
2219 if (!control_map[tag.value]) continue
2220 button.setAttribute('label', label + ' - ' + tag.value);
2222 var ind1 = tag.nextSibling;
2223 var ind2 = ind1.nextSibling;
2224 var subfields = ind2.nextSibling.childNodes;
2228 for (var j = 0; j < subfields.length; j++) {
2229 var sf = subfields[j];
2230 var sf_code = sf.childNodes[1].value;
2231 var sf_value = sf.childNodes[2].value;
2233 if (!control_map[tag.value][sf_code]) continue;
2236 for (var a_tag in control_map[tag.value][sf_code]) {
2237 if (!tags[a_tag]) tags[a_tag] = [];
2238 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2243 for (var val_tag in tags) {
2244 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2245 var res = new XML( auth_data.responseText );
2246 found = parseInt(res.gw::payload.gw::string.toString());
2250 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2251 for (var j = 0; j < subfields.length; j++) {
2252 var sf = subfields[j];
2254 dojo.removeClass(sf.childNodes[2], 'marcValidated');
2255 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
2257 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
2258 dojo.addClass(sf.childNodes[2], 'marcValidated');
2263 button.setAttribute('label', label);
2269 function validateBibField (tags, searches) {
2270 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2271 url += '¶m="tags"¶m=' + js2JSON(tags);
2272 url += '¶m="searches"¶m=' + js2JSON(searches);
2275 var req = new XMLHttpRequest();
2276 req.open('GET',url,false);
2282 function searchAuthority (term, tag, sf, limit) {
2283 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2284 url += '¶m="term"¶m="' + term + '"';
2285 url += '¶m="limit"¶m=' + limit;
2286 url += '¶m="tag"¶m=' + tag;
2287 url += '¶m="subfield"¶m="' + sf + '"';
2290 var req = new XMLHttpRequest();
2291 req.open('GET',url,false);