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 MFHD : { Type : /[uvxy]{1}/, BLvl : /.{1}/ }
680 SCO : {start : 33, len : 1, def : ' ' },
681 REC : {start : 33, len : 1, def : 'n' }
684 SCO : {start : 16, len : 1, def : ' ' },
685 REC : {start : 16, len : 1, def : 'n' }
690 VIS : {start : 33, len : 1, def : ' ' }
693 VIS : {start : 16, len : 1, def : ' ' }
698 VIS : {start : 18, len : 3, def : ' ' }
701 VIS : {start : 1, len : 3, def : ' ' }
706 VIS : {start : 34, len : 1, def : 'n' }
709 VIS : {start : 17, len : 1, def : 'n' }
714 SER : {start : 21, len : 1, def : ' ' }
717 SER : {start : 4, len : 1, def : ' ' }
722 BKS : {start : 39, len : 1, def : 'd' },
723 SER : {start : 39, len : 1, def : 'd' },
724 VIS : {start : 39, len : 1, def : 'd' },
725 MIX : {start : 39, len : 1, def : 'd' },
726 MAP : {start : 39, len : 1, def : 'd' },
727 SCO : {start : 39, len : 1, def : 'd' },
728 REC : {start : 39, len : 1, def : 'd' },
729 COM : {start : 39, len : 1, def : 'd' }
734 MAP : {start : 33, len : 2, def : ' ' }
737 MAP : {start : 16, len : 2, def : ' ' }
742 MAP : {start : 18, len : 4, def : ' ' }
745 MAP : {start : 1, len : 4, def : ' ' }
750 SER : {start : 19, len : 1, def : ' ' }
753 SER : {start : 2, len : 1, def : ' ' }
758 MAP : {start : 22, len : 2, def : ' ' }
761 MAP : {start : 5, len : 2, def : ' ' }
766 SCO : {start : 21, len : 1, def : ' ' },
767 REC : {start : 21, len : 1, def : 'n' }
770 SCO : {start : 4, len : 1, def : ' ' },
771 REC : {start : 4, len : 1, def : 'n' }
776 SER : {start : 22, len : 1, def : ' ' }
779 SER : {start : 5, len : 1, def : ' ' }
784 SCO : {start : 30, len : 2, def : ' ' },
785 REC : {start : 30, len : 2, def : ' ' }
788 SCO : {start : 13, len : 2, def : ' ' },
789 REC : {start : 13, len : 2, def : ' ' }
794 SER : {start : 18, len : 1, def : ' ' }
797 SER : {start : 1, len : 1, def : ' ' }
802 SCO : {start : 20, len : 1, def : ' ' },
803 REC : {start : 20, len : 1, def : 'n' }
806 SCO : {start : 3, len : 1, def : ' ' },
807 REC : {start : 3, len : 1, def : 'n' }
812 COM : {start : 26, len : 1, def : 'u' }
815 COM : {start : 9, len : 1, def : 'u' }
820 SER : {start : 24, len : 1, def : ' ' }
823 SER : {start : 7, len : 1, def : ' ' }
828 SCO : {start : 24, len : 6, def : ' ' },
829 REC : {start : 24, len : 6, def : ' ' }
832 SCO : {start : 7, len : 6, def : ' ' },
833 REC : {start : 7, len : 6, def : ' ' }
838 SCO : {start : 18, len : 2, def : ' ' },
839 REC : {start : 18, len : 2, def : ' ' }
842 SCO : {start : 1, len : 2, def : ' ' },
843 REC : {start : 1, len : 2, def : ' ' }
848 MAP : {start : 25, len : 1, def : ' ' }
851 MAP : {start : 8, len : 1, def : ' ' }
856 BKS : {start : 15, len : 3, def : ' ' },
857 SER : {start : 15, len : 3, def : ' ' },
858 VIS : {start : 15, len : 3, def : ' ' },
859 MIX : {start : 15, len : 3, def : ' ' },
860 MAP : {start : 15, len : 3, def : ' ' },
861 SCO : {start : 15, len : 3, def : ' ' },
862 REC : {start : 15, len : 3, def : ' ' },
863 COM : {start : 15, len : 3, def : ' ' }
868 BKS : {start : 35, len : 3, def : ' ' },
869 SER : {start : 35, len : 3, def : ' ' },
870 VIS : {start : 35, len : 3, def : ' ' },
871 MIX : {start : 35, len : 3, def : ' ' },
872 MAP : {start : 35, len : 3, def : ' ' },
873 SCO : {start : 35, len : 3, def : ' ' },
874 REC : {start : 35, len : 3, def : ' ' },
875 COM : {start : 35, len : 3, def : ' ' }
880 BKS : {start : 38, len : 1, def : ' ' },
881 SER : {start : 38, len : 1, def : ' ' },
882 VIS : {start : 38, len : 1, def : ' ' },
883 MIX : {start : 38, len : 1, def : ' ' },
884 MAP : {start : 38, len : 1, def : ' ' },
885 SCO : {start : 38, len : 1, def : ' ' },
886 REC : {start : 38, len : 1, def : ' ' },
887 COM : {start : 38, len : 1, def : ' ' }
892 BKS : {start : 6, len : 1, def : ' ' },
893 SER : {start : 6, len : 1, def : 'c' },
894 VIS : {start : 6, len : 1, def : ' ' },
895 MIX : {start : 6, len : 1, def : ' ' },
896 MAP : {start : 6, len : 1, def : ' ' },
897 SCO : {start : 6, len : 1, def : ' ' },
898 REC : {start : 6, len : 1, def : ' ' },
899 COM : {start : 6, len : 1, def : ' ' }
904 BKS : {start : 6, len : 1, def : 'a' },
905 SER : {start : 6, len : 1, def : 'a' },
906 VIS : {start : 6, len : 1, def : 'g' },
907 MIX : {start : 6, len : 1, def : 'p' },
908 MAP : {start : 6, len : 1, def : 'e' },
909 SCO : {start : 6, len : 1, def : 'c' },
910 REC : {start : 6, len : 1, def : 'i' },
911 COM : {start : 6, len : 1, def : 'm' },
912 MFHD : {start : 6, len : 1, def : 'y' }
917 BKS : {start : 8, len : 1, def : ' ' },
918 SER : {start : 8, len : 1, def : ' ' },
919 VIS : {start : 8, len : 1, def : ' ' },
920 MIX : {start : 8, len : 1, def : ' ' },
921 MAP : {start : 8, len : 1, def : ' ' },
922 SCO : {start : 8, len : 1, def : ' ' },
923 REC : {start : 8, len : 1, def : ' ' },
924 COM : {start : 8, len : 1, def : ' ' }
929 BKS : {start : 7, len : 1, def : 'm' },
930 SER : {start : 7, len : 1, def : 's' },
931 VIS : {start : 7, len : 1, def : 'm' },
932 MIX : {start : 7, len : 1, def : 'c' },
933 MAP : {start : 7, len : 1, def : 'm' },
934 SCO : {start : 7, len : 1, def : 'm' },
935 REC : {start : 7, len : 1, def : 'm' },
936 COM : {start : 7, len : 1, def : 'm' }
941 BKS : {start : 18, len : 1, def : ' ' },
942 SER : {start : 18, len : 1, def : ' ' },
943 VIS : {start : 18, len : 1, def : ' ' },
944 MIX : {start : 18, len : 1, def : ' ' },
945 MAP : {start : 18, len : 1, def : ' ' },
946 SCO : {start : 18, len : 1, def : ' ' },
947 REC : {start : 18, len : 1, def : ' ' },
948 COM : {start : 18, len : 1, def : 'i' }
953 MFHD : {start : 18, len : 1, def : 'i' }
958 BKS : {start : 17, len : 1, def : ' ' },
959 SER : {start : 17, len : 1, def : ' ' },
960 VIS : {start : 17, len : 1, def : ' ' },
961 MIX : {start : 17, len : 1, def : ' ' },
962 MAP : {start : 17, len : 1, def : ' ' },
963 SCO : {start : 17, len : 1, def : ' ' },
964 REC : {start : 17, len : 1, def : ' ' },
965 COM : {start : 17, len : 1, def : ' ' },
966 MFHD : {start : 17, len : 1, def : 'u' }
971 BKS : {start : 31, len : 1, def : '0' },
972 MAP : {start : 31, len : 1, def : '0' }
975 BKS : {start : 14, len : 1, def : '0' },
976 MAP : {start : 14, len : 1, def : '0' }
981 BKS : {start : 7, len : 4, def : ' ' },
982 SER : {start : 7, len : 4, def : ' ' },
983 VIS : {start : 7, len : 4, def : ' ' },
984 MIX : {start : 7, len : 4, def : ' ' },
985 MAP : {start : 7, len : 4, def : ' ' },
986 SCO : {start : 7, len : 4, def : ' ' },
987 REC : {start : 7, len : 4, def : ' ' },
988 COM : {start : 7, len : 4, def : ' ' }
993 BKS : {start : 11, len : 4, def : ' ' },
994 SER : {start : 11, len : 4, def : '9' },
995 VIS : {start : 11, len : 4, def : ' ' },
996 MIX : {start : 11, len : 4, def : ' ' },
997 MAP : {start : 11, len : 4, def : ' ' },
998 SCO : {start : 11, len : 4, def : ' ' },
999 REC : {start : 11, len : 4, def : ' ' },
1000 COM : {start : 11, len : 4, def : ' ' }
1005 BKS : {start : 33, len : 1, def : '0' }
1008 BKS : {start : 16, len : 1, def : '0' }
1013 BKS : {start : 34, len : 1, def : ' ' }
1016 BKS : {start : 17, len : 1, def : ' ' }
1021 BKS : {start : 18, len : 4, def : ' ' }
1024 BKS : {start : 1, len : 4, def : ' ' }
1029 BKS : {start : 30, len : 1, def : '0' }
1032 BKS : {start : 13, len : 1, def : '0' }
1037 BKS : {start : 29, len : 1, def : '0' },
1038 SER : {start : 29, len : 1, def : '0' }
1041 BKS : {start : 12, len : 1, def : '0' },
1042 SER : {start : 12, len : 1, def : '0' }
1047 BKS : {start : 24, len : 4, def : ' ' },
1048 SER : {start : 25, len : 3, def : ' ' }
1051 BKS : {start : 7, len : 4, def : ' ' },
1052 SER : {start : 8, len : 3, def : ' ' }
1057 BKS : {start : 28, len : 1, def : ' ' },
1058 SER : {start : 28, len : 1, def : ' ' },
1059 VIS : {start : 28, len : 1, def : ' ' },
1060 MAP : {start : 28, len : 1, def : ' ' },
1061 COM : {start : 28, len : 1, def : ' ' }
1064 BKS : {start : 11, len : 1, def : ' ' },
1065 SER : {start : 11, len : 1, def : ' ' },
1066 VIS : {start : 11, len : 1, def : ' ' },
1067 MAP : {start : 11, len : 1, def : ' ' },
1068 COM : {start : 11, len : 1, def : ' ' }
1073 BKS : {start : 22, len : 1, def : ' ' },
1074 SER : {start : 22, len : 1, def : ' ' },
1075 VIS : {start : 22, len : 1, def : ' ' },
1076 SCO : {start : 22, len : 1, def : ' ' },
1077 REC : {start : 22, len : 1, def : ' ' },
1078 COM : {start : 22, len : 1, def : ' ' }
1081 BKS : {start : 5, len : 1, def : ' ' },
1082 SER : {start : 5, len : 1, def : ' ' },
1083 VIS : {start : 5, len : 1, def : ' ' },
1084 SCO : {start : 5, len : 1, def : ' ' },
1085 REC : {start : 5, len : 1, def : ' ' },
1086 COM : {start : 5, len : 1, def : ' ' }
1091 BKS : {start : 23, len : 1, def : ' ' },
1092 SER : {start : 23, len : 1, def : ' ' },
1093 VIS : {start : 29, len : 1, def : ' ' },
1094 MIX : {start : 23, len : 1, def : ' ' },
1095 MAP : {start : 29, len : 1, def : ' ' },
1096 SCO : {start : 23, len : 1, def : ' ' },
1097 REC : {start : 23, len : 1, def : ' ' }
1100 BKS : {start : 6, len : 1, def : ' ' },
1101 SER : {start : 6, len : 1, def : ' ' },
1102 VIS : {start : 12, len : 1, def : ' ' },
1103 MIX : {start : 6, len : 1, def : ' ' },
1104 MAP : {start : 12, len : 1, def : ' ' },
1105 SCO : {start : 6, len : 1, def : ' ' },
1106 REC : {start : 6, len : 1, def : ' ' }
1111 SER : {start : 34, len : 1, def : '0' }
1114 SER : {start : 17, len : 1, def : '0' }
1119 SER : {start : 33, len : 1, def : ' ' }
1122 SER : {start : 16, len : 1, def : ' ' }
1127 function recordType (rec) {
1129 var _l = rec.leader.toString();
1131 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1132 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1134 for (var t in rec_type) {
1135 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1136 document.getElementById('recordTypeLabel').value = t;
1142 // in case we don't have a valid record type ...
1143 _record_type = 'BKS';
1144 return _record_type;
1147 alert('FIXME, MARC Editor, recordType: ' + E);
1151 function toggleFFE () {
1152 var grid = document.getElementById('leaderGrid');
1154 grid.hidden = false;
1161 function changeFFEditor (type) {
1162 var grid = document.getElementById('leaderGrid');
1163 grid.setAttribute('type',type);
1165 // Hide FFEditor rows that we don't need for our current type
1166 // If all of the labels for a given row do not include our
1167 // desired type in their set attribute, we can hide that row
1168 dojo.query('rows row', grid).forEach(function(node, index, arr) {
1169 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
1176 function fillFixedFields (rec) {
1178 var grid = document.getElementById('leaderGrid');
1180 var rtype = _record_type;
1182 var _l = rec.leader.toString();
1183 var _6 = rec.controlfield.(@tag=='006').toString();
1184 var _7 = rec.controlfield.(@tag=='007').toString();
1185 var _8 = rec.controlfield.(@tag=='008').toString();
1188 var pre_list = grid.getElementsByTagName('label');
1189 for (var i in pre_list) {
1190 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1191 list.push( pre_list[i] );
1195 for (var i in list) {
1196 var name = list[i].getAttribute('name');
1202 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1203 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1205 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1206 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1208 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1209 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1211 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1212 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1217 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1218 d = ff_pos[name].ldr[rtype].def;
1222 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1223 d = ff_pos[name]._8[rtype].def;
1227 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1228 d = ff_pos[name]._6[rtype].def;
1232 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1233 d = ff_pos[name]._7[rtype].def;
1238 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1244 list[i].nextSibling.value = value;
1249 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1253 function updateFixedFields (element) {
1254 var grid = document.getElementById('leaderGrid');
1255 var recGrid = document.getElementById('recGrid');
1257 var rtype = _record_type;
1258 var new_value = element.value;
1261 ldr : _record.leader,
1262 _6 : _record.controlfield.(@tag=='006'),
1263 _7 : _record.controlfield.(@tag=='007'),
1264 _8 : _record.controlfield.(@tag=='008')
1267 var name = element.getAttribute('name');
1268 for (var i in ff_pos[name]) {
1270 if (!ff_pos[name][i][rtype]) continue;
1272 // we're missing the required field. Add it now.
1275 if (i == '_6') newfield = '006';
1276 else if (i == '_7') newfield = '007';
1277 else if (i == '_8') newfield = '008';
1280 createControlField(newfield,' ');
1281 parts[i] = _record.controlfield.(@tag==newfield);
1284 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1285 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1287 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1288 new_value += ff_pos[name][i][rtype].def;
1291 parts[i].setChildren( before + new_value + after );
1292 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1298 function marcLeader (leader) {
1299 var row = createRow(
1300 { class : 'marcLeaderRow',
1305 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1308 class : 'marcInd1' } ),
1311 class : 'marcInd2' } ),
1313 { value : leader.text(),
1314 class : 'marcLeader' } )
1320 function marcControlfield (field) {
1321 tagname = field.@tag.toString().substr(2);
1323 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1325 { class : 'marcControlfieldRow',
1326 tag : '_' + tagname },
1328 { value : field.@tag,
1330 context : 'tags_popup',
1331 onmouseover : 'getTooltip(this, "tag");',
1332 tooltipid : 'tag' + field.@tag } ),
1334 { value : field.@ind1,
1336 onmouseover : 'getTooltip(this, "ind1");',
1337 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1339 { value : field.@ind2,
1341 onmouseover : 'getTooltip(this, "ind2");',
1342 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1345 { value : field.text(),
1346 class : 'plain marcEditableControlfield',
1347 name : 'CONTROL' + tagname,
1348 context : 'clipboard',
1354 { class : 'marcControlfieldRow',
1355 tag : '_' + tagname },
1357 { value : field.@tag,
1359 onmouseover : 'getTooltip(this, "tag");',
1360 tooltipid : 'tag' + field.@tag } ),
1362 { value : field.@ind1,
1364 onmouseover : 'getTooltip(this, "ind1");',
1365 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1367 { value : field.@ind2,
1369 onmouseover : 'getTooltip(this, "ind2");',
1370 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1372 { value : field.text(),
1373 class : 'marcControlfield' } )
1380 function stackSubfields(checkbox) {
1381 var list = document.getElementsByAttribute('name','sf_box');
1384 if (!checkbox.checked) o = 'horizontal';
1386 for (var i = 0; i < list.length; i++) {
1387 if (list[i]) list[i].setAttribute('orient',o);
1391 function fastItemAdd_toggle(checkbox) {
1392 var x = document.getElementById('fastItemAdd_textboxes');
1393 if (checkbox.checked) {
1395 document.getElementById('fastItemAdd_callnumber').focus();
1396 document.getElementById('fastItemAdd_callnumber').select();
1402 function fastItemAdd_attempt(doc_id) {
1404 if (typeof window.xulG.fast_add_item != 'function') { return; }
1405 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1406 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1407 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1408 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1409 document.getElementById('fastItemAdd_barcode').value = '';
1411 alert('fastItemAdd_attempt: ' + E);
1415 function save_attempt(xml_string) {
1417 var result = window.xulG.save.func( xml_string );
1419 if (result.id) fastItemAdd_attempt(result.id);
1420 if (typeof result.on_complete == 'function') result.on_complete();
1423 alert('save_attempt: ' + E);
1427 function marcDatafield (field) {
1428 var row = createRow(
1429 { class : 'marcDatafieldRow' },
1432 { value : field.@tag,
1433 class : 'plain marcTag',
1435 context : 'tags_popup',
1436 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1439 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1442 { value : field.@ind1,
1443 class : 'plain marcInd1',
1445 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1448 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1449 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1452 { value : field.@ind2,
1453 class : 'plain marcInd2',
1455 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1458 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1459 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1460 createHbox({ name : 'sf_box' })
1463 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1464 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1465 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1467 var sf_box = row.lastChild;
1468 if (document.getElementById('stackSubfields').checked)
1469 sf_box.setAttribute('orient','vertical');
1471 sf_box.addEventListener(
1474 if (sf_box === e.target) {
1475 sf_box.lastChild.lastChild.focus();
1476 } else if (e.target.parentNode === sf_box) {
1477 e.target.lastChild.focus();
1484 for (var i in field.subfield) {
1485 var sf = field.subfield[i];
1490 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1492 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1493 current_focus = sf_box.lastChild.childNodes[1];
1499 function marcSubfield (sf) {
1501 { class : 'marcSubfieldBox' },
1504 class : 'plain marcSubfieldDelimiter',
1505 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1506 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1507 //onclick : 'this.nextSibling.focus();',
1508 onfocus : 'this.nextSibling.focus();',
1513 class : 'plain marcSubfieldCode',
1514 name : 'marcSubfieldCode',
1515 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1516 oncontextmenu : 'getContextMenu(this, "subfield");',
1517 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1522 { value : sf.text(),
1523 name : sf.parent().@tag + ':' + sf.@code,
1524 class : 'plain marcSubfield',
1525 onmouseover : 'getTooltip(this, "subfield");',
1526 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1527 size : new String(sf.text()).length + 2,
1528 oninput : "this.setAttribute('size', this.value.length + 2);"
1533 function loadRecord(rec) {
1536 var grid_rows = document.getElementById('recGrid').lastChild;
1538 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1540 grid_rows.appendChild( marcLeader( rec.leader ) );
1542 for (var i in rec.controlfield) {
1543 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1546 for (var i in rec.datafield) {
1547 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1550 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1551 changeFFEditor(recordType(rec));
1552 fillFixedFields(rec);
1554 alert('FIXME, MARC Editor, loadRecord: ' + E);
1559 function genToolTips () {
1560 for (var i in bib_data.field) {
1561 var f = bib_data.field[i];
1563 tag_menu.appendChild(
1567 'current_focus.value = "' + f.@tag + '";' +
1568 'var e = document.createEvent("MutationEvents");' +
1569 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1570 'current_focus.inputField.dispatchEvent(e);',
1571 disabled : f.@tag < '010' ? "true" : "false",
1572 tooltiptext : f.description }
1576 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1577 context_menus.appendChild( i1_popup );
1579 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1580 context_menus.appendChild( i2_popup );
1582 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1583 context_menus.appendChild( sf_popup );
1585 tooltip_hash['tag' + f.@tag] = f.description;
1586 for (var j in f.indicator) {
1587 var ind = f.indicator[j];
1588 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1590 if (ind.@position == 1) {
1591 i1_popup.appendChild(
1593 { label : ind.@value,
1595 'current_focus.value = "' + ind.@value + '";' +
1596 'var e = document.createEvent("MutationEvents");' +
1597 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1598 'current_focus.inputField.dispatchEvent(e);',
1599 tooltiptext : ind.description }
1604 if (ind.@position == 2) {
1605 i2_popup.appendChild(
1607 { label : ind.@value,
1609 'current_focus.value = "' + ind.@value + '";' +
1610 'var e = document.createEvent("MutationEvents");' +
1611 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1612 'current_focus.inputField.dispatchEvent(e);',
1613 tooltiptext : ind.description }
1619 for (var j in f.subfield) {
1620 var sf = f.subfield[j];
1621 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1623 sf_popup.appendChild(
1627 'current_focus.value = "' + sf.@code + '";' +
1628 'var e = document.createEvent("MutationEvents");' +
1629 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1630 'current_focus.inputField.dispatchEvent(e);',
1631 tooltiptext : sf.description
1639 function getTooltip (target, type) {
1642 if (type == 'subfield')
1643 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1646 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1649 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1652 tt = 'tag' + target.parentNode.firstChild.value;
1654 if (!document.getElementById( tt )) {
1659 orient : 'vertical',
1660 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1661 class : 'tooltip' },
1662 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1667 target.tooltip = tt;
1671 function getContextMenu (target, type) {
1674 if (type == 'subfield')
1675 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1678 tt = 't' + target.parentNode.firstChild.value + 'i1';
1681 tt = 't' + target.parentNode.firstChild.value + 'i2';
1683 target.setAttribute('context', tt);
1687 var authority_tag_map = {
1688 100 : ['[100,400,500,700]',100],
1689 400 : ['[100,400,500,700]',100],
1690 700 : ['[100,400,500,700]',100],
1691 800 : ['[100,400,500,700]',100],
1692 110 : ['[110,410,510,710]',110],
1693 410 : ['[110,410,510,710]',110],
1694 710 : ['[110,410,510,710]',110],
1695 810 : ['[110,410,510,710]',110],
1696 111 : ['[111,411,511,711]',111],
1697 411 : ['[111,411,511,711]',111],
1698 711 : ['[111,411,511,711]',111],
1699 811 : ['[111,411,511,711]',111],
1700 240 : ['[130,430,530,730]',130],
1701 440 : ['[130,430,530,730]',130],
1702 130 : ['[130,430,530,730]',130],
1703 730 : ['[130,430,530,730]',130],
1704 830 : ['[130,430,530,730]',130],
1705 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1706 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1707 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1708 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1711 function getAuthorityContextMenu (target, sf) {
1712 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1714 var old = document.getElementById( menu_id );
1715 if (old) old.parentNode.removeChild(old);
1717 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1718 context_menus.appendChild( sf_popup );
1720 if (!authority_tag_map[sf.parent().@tag]) {
1721 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1722 target.setAttribute('context', 'clipboard');
1726 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1728 var res = new XML( auth_data.responseText );
1732 var recs = res.gw::payload.gw::array.gw::string;
1733 for (var i in recs) {
1735 var xml = new XML(x.toString());
1736 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1738 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1741 for (var i in main) {
1742 if (main_text) main_text += ' / ';
1743 main_text += main[i];
1746 rec_list.push( [ main_text, xml ] );
1749 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1751 var main_text = rec_list[i][0];
1752 var xml = rec_list[i][1];
1753 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1755 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1757 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1758 grid.setAttribute('name','-none-');
1759 grid.setAttribute('style','overflow:scroll');
1762 var submenu = createMenu( { label : main_text } );
1764 var popup = createMenuPopup({ flex : "1" });
1765 submenu.appendChild(popup);
1767 var fields = xml.datafield;
1768 for (var j in fields) {
1770 var row = createRow(
1772 createLabel( { value : fields[j].@tag } ),
1773 createLabel( { value : fields[j].@ind1 } ),
1774 createLabel( { value : fields[j].@ind2 } )
1777 var sf_box = createHbox();
1779 var subfields = fields[j].subfield;
1780 for (var k in subfields) {
1783 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1784 subfield : subfields[k].@code,
1785 tag : subfields[k].parent().@tag,
1786 value : subfields[k]
1790 row.appendChild(sf_box);
1793 grid.lastChild.appendChild(row);
1796 grid.hidden = false;
1797 popup.appendChild( grid );
1801 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1802 command : function (event) {
1803 applyAuthority(event.target.previousSibling, target, sf);
1810 sf_popup.appendChild( submenu );
1813 if (sf_popup.childNodes.length == 0)
1814 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1816 target.setAttribute('context', menu_id);
1820 function applyAuthority ( target, ui_sf, e4x_sf ) {
1822 var new_vals = target.getElementsByAttribute('checked','true');
1823 var field = e4x_sf.parent();
1825 for (var i = 0; i < new_vals.length; i++) {
1827 var sf_list = field.subfield;
1828 for (var j in sf_list) {
1830 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1831 sf_list[j] = new_vals[i].getAttribute('value');
1832 new_vals[i].setAttribute('subfield','');
1838 for (var i = 0; i < new_vals.length; i++) {
1839 if (!new_vals[i].getAttribute('subfield')) continue;
1841 var val = new_vals[i].getAttribute('value');
1843 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1844 sf.@code = new_vals[i].getAttribute('subfield');
1846 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1849 var row = marcDatafield( field );
1852 while (node.nodeName != 'row') {
1853 node = node.parentNode;
1856 node.parentNode.replaceChild( row, node );
1862 'a' : { 100 : 'a' },
1863 'd' : { 100 : 'd' },
1864 'e' : { 100 : 'e' },
1868 'a' : { 110 : 'a' },
1872 'a' : { 111 : 'a' },
1876 'a' : { 130 : 'a' },
1880 'a' : { 130 : 'a' },
1884 'a' : { 100 : 'a' },
1888 'a' : { 110 : 'a' },
1892 'a' : { 111 : 'a' },
1896 'a' : { 130 : 'a' },
1897 'n' : { 130 : 'n' },
1901 'a' : { 100 : 'a' },
1902 'd' : { 100 : 'd' },
1903 'q' : { 100 : 'q' },
1907 'a' : { 110 : 'a' },
1911 'a' : { 111 : 'a' },
1912 'c' : { 111 : 'c' },
1916 'a' : { 130 : 'a' },
1920 'a' : { 100 : 'a' },
1924 'a' : { 110 : 'a' },
1928 'a' : { 111 : 'a' },
1932 'a' : { 130 : 'a' },
1936 'a' : { 100 : 'a' },
1937 'd' : { 100 : 'd' },
1938 'q' : { 100 : 'q' },
1939 't' : { 100 : 't' },
1966 'a' : { 110 : 'a' },
1967 'd' : { 110 : 'd' },
1968 't' : { 110 : 't' },
1995 'a' : { 111 : 'a' },
1996 'd' : { 111 : 'd' },
1997 't' : { 111 : 't' },
2024 'a' : { 130 : 'a' },
2028 'a' : { 150 : 'a' },
2029 'b' : { 150 : 'b' },
2056 'a' : { 151 : 'a' },
2083 'a' : { 155 : 'a' },
2111 function validateAuthority (button) {
2112 var grid = document.getElementById('recGrid');
2113 var label = button.getAttribute('label');
2116 var rows = grid.lastChild.childNodes;
2117 for (var i = 0; i < rows.length; i++) {
2119 var tag = row.firstChild;
2121 if (!control_map[tag.value]) continue
2122 button.setAttribute('label', label + ' - ' + tag.value);
2124 var ind1 = tag.nextSibling;
2125 var ind2 = ind1.nextSibling;
2126 var subfields = ind2.nextSibling.childNodes;
2130 for (var j = 0; j < subfields.length; j++) {
2131 var sf = subfields[j];
2132 var sf_code = sf.childNodes[1].value;
2133 var sf_value = sf.childNodes[2].value;
2135 if (!control_map[tag.value][sf_code]) continue;
2138 for (var a_tag in control_map[tag.value][sf_code]) {
2139 if (!tags[a_tag]) tags[a_tag] = [];
2140 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2145 for (var val_tag in tags) {
2146 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2147 var res = new XML( auth_data.responseText );
2148 found = parseInt(res.gw::payload.gw::string.toString());
2152 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2153 for (var j = 0; j < subfields.length; j++) {
2154 var sf = subfields[j];
2156 sf.childNodes[2].inputField.style.color = 'red';
2158 sf.childNodes[2].inputField.style.color = 'black';
2163 button.setAttribute('label', label);
2169 function validateBibField (tags, searches) {
2170 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2171 url += '¶m="tags"¶m=' + js2JSON(tags);
2172 url += '¶m="searches"¶m=' + js2JSON(searches);
2175 var req = new XMLHttpRequest();
2176 req.open('GET',url,false);
2182 function searchAuthority (term, tag, sf, limit) {
2183 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2184 url += '¶m="term"¶m="' + term + '"';
2185 url += '¶m="limit"¶m=' + limit;
2186 url += '¶m="tag"¶m=' + tag;
2187 url += '¶m="subfield"¶m="' + sf + '"';
2190 var req = new XMLHttpRequest();
2191 req.open('GET',url,false);