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 var show_auth_menu = false;
24 function $(id) { return document.getElementById(id); }
26 function mangle_005() {
28 var y = now.getUTCFullYear();
30 var m = now.getUTCMonth() + 1;
31 if (m < 10) m = '0' + m;
33 var d = now.getUTCDate();
34 if (d < 10) d = '0' + d;
36 var H = now.getUTCHours();
37 if (H < 10) H = '0' + H;
39 var M = now.getUTCMinutes();
40 if (M < 10) M = '0' + M;
42 var S = now.getUTCSeconds();
43 if (S < 10) S = '0' + S;
46 var stamp = '' + y + m + d + H + M + S + '.0';
47 createControlField('005',stamp);
51 function createControlField (tag,data) {
52 // first, remove the old field, if any;
53 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
55 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
58 // then, find the right position and insert it
60 var cfields = xml_record.controlfield;
61 var base = Number(tag.substring(2));
62 for (var i in cfields) {
63 var t = Number(cfields[i].@tag.toString().substring(2));
65 xml_record.insertChildBefore( cfields[i], cf );
71 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
76 function xml_escape_unicode ( str ) {
79 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
83 function wrap_long_fields (node) {
84 var text_size = dojo.attr(node, 'size');
86 if (text_size > hard_width) {
87 dojo.attr(node, 'multiline', 'true');
88 dojo.attr(node, 'cols', hard_width);
89 var text_rows = (text_size / hard_width) + 1;
90 dojo.attr(node, 'rows', text_rows);
94 function set_flat_editor (useFlatText) {
96 dojo.require('MARC.Record');
98 var xe = $('xul-editor');
99 var te = $('text-editor');
102 if (xe.hidden) { return; }
106 if (te.hidden) { return; }
112 // get the marcxml from the text box
113 var xml_string = new MARC.Record({
114 marcbreaker : $('text-editor-box').value,
118 // reset the xml record and rerender it
119 xml_record = new XML( xml_string );
120 loadRecord(xml_record);
122 var xml_string = xml_record.toXMLString();
124 // push the xml record into the textbox
125 var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
126 $('text-editor-box').value = rec.toBreaker();
133 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
134 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
135 JSAN.errorLevel = "die"; // none, warn, or die
136 JSAN.addRepository('/xul/server/');
138 // Fake xulG for standalone...
143 window.xulG.record = {};
144 window.xulG.save = {};
146 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
147 window.xulG.save.func = function (r) { alert(r); }
150 var _rid = cgi.param('record');
152 window.xulG.record.id = _rid;
153 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
157 // End faking part...
159 /* Check for an explicitly passed record type
160 * This is not the same as the fixed-field record type; we can't trust
161 * the fixed fields when making modifications to the attributes for a
162 * given record (in particular, config.bib_source only applies for bib
163 * records, but an auth or MFHD record with the same ID and bad fixed
164 * fields could trample the config.bib_source value for the
165 * corresponding bib record if we're not careful.
167 * are = authority record
168 * sre = serial record (MFHD)
169 * bre = bibliographic record
171 if (!window.xulG.record.rtype) {
173 window.xulG.record.rtype = cgi.param('rtype') || false;
176 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
177 document.getElementById('save-button').setAttribute('oncommand',
178 'if ($("xul-editor").hidden) set_flat_editor(false); ' +
180 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
181 'save_attempt( xml_string ); ' +
182 'loadRecord(xml_record);'
185 if (window.xulG.record.url) {
186 var req = new XMLHttpRequest();
187 req.open('POST',window.xulG.record.url,false);
189 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
192 xml_record = new XML( window.xulG.record.marc );
193 if (xml_record..record[0]) xml_record = xml_record..record[0];
195 // Get the tooltip xml all async like
196 req = new XMLHttpRequest();
198 // Set a default locale in case preferences fail us
199 var locale = "en-US";
201 // Try to get the locale from our preferences
202 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
204 const Cc = Components.classes;
205 const Ci = Components.interfaces;
206 locale = Cc["@mozilla.org/preferences-service;1"].
207 getService(Ci.nsIPrefBranch).
208 getCharPref("general.useragent.locale");
212 // TODO: We should send a HEAD request to check for the existence of the desired file
213 // then fall back to the default locale if preferred locale is not necessary;
214 // however, for now we have a simplistic check:
216 // we currently have translations for only two locales; in the absence of a
217 // valid locale, default to the almighty en-US
218 if (locale != 'en-US' && locale != 'fr-CA') {
222 // grab the right tooltip based on MARC type
223 var tooltip_doc = 'marcedit-tooltips.xml';
224 switch (window.xulG.record.rtype) {
226 tooltip_doc = 'marcedit-tooltips.xml';
229 tooltip_doc = 'marcedit-tooltips-authority.xml';
230 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
233 tooltip_doc = 'marcedit-tooltips-mfhd.xml';
234 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
237 tooltip_doc = 'marcedit-tooltips.xml';
240 // Get the locale-specific tooltips
241 req.open('GET','/xul/server/locale/' + locale + '/' + tooltip_doc,true);
243 context_menus = createComplexXULElement('popupset');
244 document.documentElement.appendChild( context_menus );
246 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
247 context_menus.appendChild( tag_menu );
249 tag_menu.appendChild(
251 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
253 'var e = document.createEvent("KeyEvents");' +
254 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
255 'current_focus.inputField.dispatchEvent(e);'
260 tag_menu.appendChild(
262 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
264 'var e = document.createEvent("KeyEvents");' +
265 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
266 'current_focus.inputField.dispatchEvent(e);'
271 tag_menu.appendChild(
273 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
275 'var e = document.createEvent("KeyEvents");' +
276 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
277 'current_focus.inputField.dispatchEvent(e);'
282 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
284 tag_menu.appendChild(
286 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
288 'var e = document.createEvent("KeyEvents");' +
289 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
290 'current_focus.inputField.dispatchEvent(e);'
295 tag_menu.appendChild(
297 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
299 'var e = document.createEvent("KeyEvents");' +
300 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
301 'current_focus.inputField.dispatchEvent(e);'
306 tag_menu.appendChild(
308 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
310 'var e = document.createEvent("KeyEvents");' +
311 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
312 'current_focus.inputField.dispatchEvent(e);'
317 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
319 p = createComplexXULElement('popupset');
320 document.documentElement.appendChild( p );
322 req.onreadystatechange = function () {
323 if (req.readyState == 4) {
324 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
330 loadRecord(xml_record);
332 if (! xulG.fast_add_item) {
333 document.getElementById('fastItemAdd_checkbox').hidden = true;
335 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
337 // Only show bib sources for bib records that already exist in the database
338 if (xulG.record.rtype == 'bre' && xulG.record.id) {
339 dojo.require('openils.PermaCrud');
340 var authtoken = ses();
341 // Retrieve the current record attributes
342 var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
344 // Remember the current bib source of the record
345 xulG.record.bre = bib;
347 buildBibSourceList(authtoken, xulG.record.id);
351 alert('FIXME, MARC Editor, my_init: ' + E);
356 function createComplexHTMLElement (e, attrs, objects, text) {
357 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
360 for (var i in attrs) l.setAttribute(i,attrs[i]);
364 for ( var i in objects ) l.appendChild( objects[i] );
368 l.appendChild( document.createTextNode(text) )
374 function createComplexXULElement (e, attrs, objects) {
375 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
378 for (var i in attrs) {
379 if (typeof attrs[i] == 'function') {
380 l.addEventListener( i, attrs[i], true );
382 l.setAttribute(i,attrs[i]);
388 for ( var i in objects ) l.appendChild( objects[i] );
394 function createDescription (attrs) {
395 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
398 function createTooltip (attrs) {
399 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
402 function createLabel (attrs) {
403 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
406 function createVbox (attrs) {
407 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
410 function createHbox (attrs) {
411 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
414 function createRow (attrs) {
415 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
418 function createTextbox (attrs) {
419 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
422 function createMenu (attrs) {
423 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
426 function createMenuPopup (attrs) {
427 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
430 function createPopup (attrs) {
431 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
434 function createMenuitem (attrs) {
435 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
438 function createCheckbox (attrs) {
439 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
442 // Find the next textbox that we can use for a focus point
443 // For control fields, use the first editable text box
444 // For data fields, focus on the first subfield text box
445 function setFocusToNextTag (row, direction) {
446 var keep_looking = true;
447 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
448 // Is it a datafield?
449 dojo.query('hbox hbox textbox', row).forEach(function(node, index, arr) {
451 keep_looking = false;
454 // No, it's a control field; use the first textbox
456 dojo.query('textbox', row).forEach(function(node, index, arr) {
458 keep_looking = false;
467 function createMARCTextbox (element,attrs) {
469 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
470 box.onkeypress = function (event) {
473 while(node = node.parent()) {
477 var row = event.target;
478 while (row.tagName != 'row') row = row.parentNode;
480 if (element.nodeKind() == 'attribute') element[0]=box.value;
481 else element.setChildren( box.value );
483 if (element.localName() != 'controlfield') {
484 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
486 var index_sf, target, move_data;
487 if (element.localName() == 'subfield') {
489 target = event.target.parentNode;
491 var start = event.target.selectionStart;
492 var end = event.target.selectionEnd - event.target.selectionStart ?
493 event.target.selectionEnd :
494 event.target.value.length;
496 move_data = event.target.value.substring(start,end);
497 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
498 event.target.setAttribute('size', event.target.value.length + 2);
500 element.setChildren( event.target.value );
502 } else if (element.localName() == 'code') {
503 index_sf = element.parent();
504 target = event.target.parentNode;
505 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
506 index_sf = element.parent().children()[element.parent().children().length() - 1];
507 target = event.target.parentNode.lastChild.lastChild;
510 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
512 index_sf.parent().insertChildAfter( index_sf, sf );
514 var new_sf = marcSubfield(sf);
516 if (target === target.parentNode.lastChild) {
517 target.parentNode.appendChild( new_sf );
519 target.parentNode.insertBefore( new_sf, target.nextSibling );
522 new_sf.firstChild.nextSibling.focus();
524 event.preventDefault();
527 } else if (event.keyCode == 13 || event.keyCode == 77) {
528 if (event.ctrlKey) { // ctrl+enter
531 if (element.localName() == 'subfield') index = element.parent();
532 if (element.localName() == 'code') index = element.parent().parent();
533 if (element.localName() == 'tag') index = element.parent();
534 if (element.localName() == 'ind1') index = element.parent();
535 if (element.localName() == 'ind2') index = element.parent();
537 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
539 if (event.shiftKey) { // ctrl+shift+enter
540 index.parent().insertChildBefore( index, df );
542 index.parent().insertChildAfter( index, df );
545 var new_df = marcDatafield(df);
547 if (row.parentNode.lastChild === row) {
548 row.parentNode.appendChild( new_df );
550 if (event.shiftKey) { // ctrl+shift+enter
551 row.parentNode.insertBefore( new_df, row );
553 row.parentNode.insertBefore( new_df, row.nextSibling );
557 new_df.firstChild.focus();
559 event.preventDefault();
562 } else if (event.shiftKey) {
563 if (row.previousSibling.className.match('marcDatafieldRow'))
564 row.previousSibling.firstChild.focus();
566 row.nextSibling.firstChild.focus();
569 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
570 if (event.ctrlKey) { // CTRL key: copy the field
572 if (element.localName() == 'subfield') index = element.parent();
573 if (element.localName() == 'code') index = element.parent().parent();
574 if (element.localName() == 'tag') index = element.parent();
575 if (element.localName() == 'ind1') index = element.parent();
576 if (element.localName() == 'ind2') index = element.parent();
578 var copyField = index.copy();
580 if (event.keyCode == 38) { // ctrl+up-arrow
581 index.parent().insertChildBefore( index, copyField );
583 index.parent().insertChildAfter( index, copyField );
586 var new_df = marcDatafield(copyField);
588 if (row.parentNode.lastChild === row) {
589 row.parentNode.appendChild( new_df );
591 if (event.keyCode == 38) { // ctrl+up-arrow
592 row.parentNode.insertBefore( new_df, row );
593 } else { // ctrl+down-arrow
594 row.parentNode.insertBefore( new_df, row.nextSibling );
598 new_df.firstChild.focus();
600 event.preventDefault();
604 if (event.keyCode == 38) {
605 return setFocusToNextTag(row, 'up');
607 if (event.keyCode == 40) {
608 return setFocusToNextTag(row, 'down');
613 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
616 if (element.localName() == 'subfield') index = element.parent();
617 if (element.localName() == 'code') index = element.parent().parent();
618 if (element.localName() == 'tag') index = element.parent();
619 if (element.localName() == 'ind1') index = element.parent();
620 if (element.localName() == 'ind2') index = element.parent();
622 for (var i in index.parent().children()) {
623 if (index === index.parent().children()[i]) {
624 delete index.parent().children()[i];
629 row.previousSibling.firstChild.focus();
630 row.parentNode.removeChild(row);
632 event.preventDefault();
635 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
638 if (element.localName() == 'subfield') index = element;
639 if (element.localName() == 'code') index = element.parent();
642 for (var i in index.parent().children()) {
643 if (index === index.parent().children()[i]) {
644 delete index.parent().children()[i];
649 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
650 event.target.parentNode.previousSibling.lastChild.focus();
652 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
655 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
657 event.preventDefault();
660 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
661 createControlField('006',' ');
662 loadRecord(xml_record);
663 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
664 createControlField('007',' ');
665 loadRecord(xml_record);
666 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
667 createControlField('008',' ');
668 loadRecord(xml_record);
673 } else { // event on a control field
674 if (event.keyCode == 38) {
675 return setFocusToNextTag(row, 'up');
676 } else if (event.keyCode == 40) {
677 return setFocusToNextTag(row, 'down');
682 box.addEventListener(
685 if (element.nodeKind() == 'attribute') element[0]=box.value;
686 else element.setChildren( box.value );
692 box.addEventListener(
695 if (element.nodeKind() == 'attribute') element[0]=box.value;
696 else element.setChildren( box.value );
702 box.addEventListener(
705 if (element.nodeKind() == 'attribute') element[0]=box.value;
706 else element.setChildren( box.value );
712 box.addEventListener(
715 if (element.localName() == 'controlfield')
716 eval('fillFixedFields(xml_record);');
725 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
726 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
727 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
728 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
729 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
730 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
731 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
732 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ },
733 AUT : { Type : /[z]{1}/, BLvl : /.{1}/ },
734 MFHD : { Type : /[uvxy]{1}/, BLvl : /.{1}/ }
740 SCO : {start : 33, len : 1, def : ' ' },
741 REC : {start : 33, len : 1, def : 'n' }
744 SCO : {start : 16, len : 1, def : ' ' },
745 REC : {start : 16, len : 1, def : 'n' }
750 VIS : {start : 33, len : 1, def : ' ' }
753 VIS : {start : 16, len : 1, def : ' ' }
758 VIS : {start : 18, len : 3, def : ' ' }
761 VIS : {start : 1, len : 3, def : ' ' }
766 VIS : {start : 34, len : 1, def : 'n' }
769 VIS : {start : 17, len : 1, def : 'n' }
774 SER : {start : 21, len : 1, def : ' ' }
777 SER : {start : 4, len : 1, def : ' ' }
782 BKS : {start : 39, len : 1, def : 'd' },
783 SER : {start : 39, len : 1, def : 'd' },
784 VIS : {start : 39, len : 1, def : 'd' },
785 MIX : {start : 39, len : 1, def : 'd' },
786 MAP : {start : 39, len : 1, def : 'd' },
787 SCO : {start : 39, len : 1, def : 'd' },
788 REC : {start : 39, len : 1, def : 'd' },
789 COM : {start : 39, len : 1, def : 'd' }
794 MAP : {start : 33, len : 2, def : ' ' }
797 MAP : {start : 16, len : 2, def : ' ' }
802 MAP : {start : 18, len : 4, def : ' ' }
805 MAP : {start : 1, len : 4, def : ' ' }
810 SER : {start : 19, len : 1, def : ' ' }
813 SER : {start : 2, len : 1, def : ' ' }
818 MAP : {start : 22, len : 2, def : ' ' }
821 MAP : {start : 5, len : 2, def : ' ' }
826 SCO : {start : 21, len : 1, def : ' ' },
827 REC : {start : 21, len : 1, def : 'n' }
830 SCO : {start : 4, len : 1, def : ' ' },
831 REC : {start : 4, len : 1, def : 'n' }
836 SER : {start : 22, len : 1, def : ' ' }
839 SER : {start : 5, len : 1, def : ' ' }
844 SCO : {start : 30, len : 2, def : ' ' },
845 REC : {start : 30, len : 2, def : ' ' }
848 SCO : {start : 13, len : 2, def : ' ' },
849 REC : {start : 13, len : 2, def : ' ' }
854 SER : {start : 18, len : 1, def : ' ' }
857 SER : {start : 1, len : 1, def : ' ' }
862 SCO : {start : 20, len : 1, def : ' ' },
863 REC : {start : 20, len : 1, def : 'n' }
866 SCO : {start : 3, len : 1, def : ' ' },
867 REC : {start : 3, len : 1, def : 'n' }
872 COM : {start : 26, len : 1, def : 'u' }
875 COM : {start : 9, len : 1, def : 'u' }
880 SER : {start : 24, len : 1, def : ' ' }
883 SER : {start : 7, len : 1, def : ' ' }
888 SCO : {start : 24, len : 6, def : ' ' },
889 REC : {start : 24, len : 6, def : ' ' }
892 SCO : {start : 7, len : 6, def : ' ' },
893 REC : {start : 7, len : 6, def : ' ' }
898 SCO : {start : 18, len : 2, def : ' ' },
899 REC : {start : 18, len : 2, def : ' ' }
902 SCO : {start : 1, len : 2, def : ' ' },
903 REC : {start : 1, len : 2, def : ' ' }
908 MAP : {start : 25, len : 1, def : ' ' }
911 MAP : {start : 8, len : 1, def : ' ' }
916 BKS : {start : 15, len : 3, def : ' ' },
917 SER : {start : 15, len : 3, def : ' ' },
918 VIS : {start : 15, len : 3, def : ' ' },
919 MIX : {start : 15, len : 3, def : ' ' },
920 MAP : {start : 15, len : 3, def : ' ' },
921 SCO : {start : 15, len : 3, def : ' ' },
922 REC : {start : 15, len : 3, def : ' ' },
923 COM : {start : 15, len : 3, def : ' ' }
928 BKS : {start : 35, len : 3, def : ' ' },
929 SER : {start : 35, len : 3, def : ' ' },
930 VIS : {start : 35, len : 3, def : ' ' },
931 MIX : {start : 35, len : 3, def : ' ' },
932 MAP : {start : 35, len : 3, def : ' ' },
933 SCO : {start : 35, len : 3, def : ' ' },
934 REC : {start : 35, len : 3, def : ' ' },
935 COM : {start : 35, len : 3, def : ' ' }
940 BKS : {start : 38, len : 1, def : ' ' },
941 SER : {start : 38, len : 1, def : ' ' },
942 VIS : {start : 38, len : 1, def : ' ' },
943 MIX : {start : 38, len : 1, def : ' ' },
944 MAP : {start : 38, len : 1, def : ' ' },
945 SCO : {start : 38, len : 1, def : ' ' },
946 REC : {start : 38, len : 1, def : ' ' },
947 COM : {start : 38, len : 1, def : ' ' }
952 BKS : {start : 6, len : 1, def : ' ' },
953 SER : {start : 6, len : 1, def : 'c' },
954 VIS : {start : 6, len : 1, def : ' ' },
955 MIX : {start : 6, len : 1, def : ' ' },
956 MAP : {start : 6, len : 1, def : ' ' },
957 SCO : {start : 6, len : 1, def : ' ' },
958 REC : {start : 6, len : 1, def : ' ' },
959 COM : {start : 6, len : 1, def : ' ' }
964 BKS : {start : 6, len : 1, def : 'a' },
965 SER : {start : 6, len : 1, def : 'a' },
966 VIS : {start : 6, len : 1, def : 'g' },
967 MIX : {start : 6, len : 1, def : 'p' },
968 MAP : {start : 6, len : 1, def : 'e' },
969 SCO : {start : 6, len : 1, def : 'c' },
970 REC : {start : 6, len : 1, def : 'i' },
971 COM : {start : 6, len : 1, def : 'm' },
972 AUT : {start : 6, len : 1, def : 'z' },
973 MFHD : {start : 6, len : 1, def : 'y' }
978 BKS : {start : 8, len : 1, def : ' ' },
979 SER : {start : 8, len : 1, def : ' ' },
980 VIS : {start : 8, len : 1, def : ' ' },
981 MIX : {start : 8, len : 1, def : ' ' },
982 MAP : {start : 8, len : 1, def : ' ' },
983 SCO : {start : 8, len : 1, def : ' ' },
984 REC : {start : 8, len : 1, def : ' ' },
985 COM : {start : 8, len : 1, def : ' ' }
990 BKS : {start : 7, len : 1, def : 'm' },
991 SER : {start : 7, len : 1, def : 's' },
992 VIS : {start : 7, len : 1, def : 'm' },
993 MIX : {start : 7, len : 1, def : 'c' },
994 MAP : {start : 7, len : 1, def : 'm' },
995 SCO : {start : 7, len : 1, def : 'm' },
996 REC : {start : 7, len : 1, def : 'm' },
997 COM : {start : 7, len : 1, def : 'm' }
1002 BKS : {start : 18, len : 1, def : ' ' },
1003 SER : {start : 18, len : 1, def : ' ' },
1004 VIS : {start : 18, len : 1, def : ' ' },
1005 MIX : {start : 18, len : 1, def : ' ' },
1006 MAP : {start : 18, len : 1, def : ' ' },
1007 SCO : {start : 18, len : 1, def : ' ' },
1008 REC : {start : 18, len : 1, def : ' ' },
1009 COM : {start : 18, len : 1, def : 'i' }
1014 MFHD : {start : 18, len : 1, def : 'i' }
1019 BKS : {start : 17, len : 1, def : ' ' },
1020 SER : {start : 17, len : 1, def : ' ' },
1021 VIS : {start : 17, len : 1, def : ' ' },
1022 MIX : {start : 17, len : 1, def : ' ' },
1023 MAP : {start : 17, len : 1, def : ' ' },
1024 SCO : {start : 17, len : 1, def : ' ' },
1025 REC : {start : 17, len : 1, def : ' ' },
1026 COM : {start : 17, len : 1, def : ' ' },
1027 AUT : {start : 17, len : 1, def : 'n' },
1028 MFHD : {start : 17, len : 1, def : 'u' }
1033 BKS : {start : 31, len : 1, def : '0' },
1034 MAP : {start : 31, len : 1, def : '0' }
1037 BKS : {start : 14, len : 1, def : '0' },
1038 MAP : {start : 14, len : 1, def : '0' }
1043 BKS : {start : 7, len : 4, def : ' ' },
1044 SER : {start : 7, len : 4, def : ' ' },
1045 VIS : {start : 7, len : 4, def : ' ' },
1046 MIX : {start : 7, len : 4, def : ' ' },
1047 MAP : {start : 7, len : 4, def : ' ' },
1048 SCO : {start : 7, len : 4, def : ' ' },
1049 REC : {start : 7, len : 4, def : ' ' },
1050 COM : {start : 7, len : 4, def : ' ' }
1055 BKS : {start : 11, len : 4, def : ' ' },
1056 SER : {start : 11, len : 4, def : '9' },
1057 VIS : {start : 11, len : 4, def : ' ' },
1058 MIX : {start : 11, len : 4, def : ' ' },
1059 MAP : {start : 11, len : 4, def : ' ' },
1060 SCO : {start : 11, len : 4, def : ' ' },
1061 REC : {start : 11, len : 4, def : ' ' },
1062 COM : {start : 11, len : 4, def : ' ' }
1067 BKS : {start : 33, len : 1, def : '0' }
1070 BKS : {start : 16, len : 1, def : '0' }
1075 BKS : {start : 34, len : 1, def : ' ' }
1078 BKS : {start : 17, len : 1, def : ' ' }
1083 BKS : {start : 18, len : 4, def : ' ' }
1086 BKS : {start : 1, len : 4, def : ' ' }
1091 BKS : {start : 30, len : 1, def : '0' }
1094 BKS : {start : 13, len : 1, def : '0' }
1099 BKS : {start : 29, len : 1, def : '0' },
1100 SER : {start : 29, len : 1, def : '0' }
1103 BKS : {start : 12, len : 1, def : '0' },
1104 SER : {start : 12, len : 1, def : '0' }
1109 BKS : {start : 24, len : 4, def : ' ' },
1110 SER : {start : 25, len : 3, def : ' ' }
1113 BKS : {start : 7, len : 4, def : ' ' },
1114 SER : {start : 8, len : 3, def : ' ' }
1119 BKS : {start : 28, len : 1, def : ' ' },
1120 SER : {start : 28, len : 1, def : ' ' },
1121 VIS : {start : 28, len : 1, def : ' ' },
1122 MAP : {start : 28, len : 1, def : ' ' },
1123 COM : {start : 28, len : 1, def : ' ' }
1126 BKS : {start : 11, len : 1, def : ' ' },
1127 SER : {start : 11, len : 1, def : ' ' },
1128 VIS : {start : 11, len : 1, def : ' ' },
1129 MAP : {start : 11, len : 1, def : ' ' },
1130 COM : {start : 11, len : 1, def : ' ' }
1135 BKS : {start : 22, len : 1, def : ' ' },
1136 SER : {start : 22, len : 1, def : ' ' },
1137 VIS : {start : 22, len : 1, def : ' ' },
1138 SCO : {start : 22, len : 1, def : ' ' },
1139 REC : {start : 22, len : 1, def : ' ' },
1140 COM : {start : 22, len : 1, def : ' ' }
1143 BKS : {start : 5, len : 1, def : ' ' },
1144 SER : {start : 5, len : 1, def : ' ' },
1145 VIS : {start : 5, len : 1, def : ' ' },
1146 SCO : {start : 5, len : 1, def : ' ' },
1147 REC : {start : 5, len : 1, def : ' ' },
1148 COM : {start : 5, len : 1, def : ' ' }
1153 BKS : {start : 23, len : 1, def : ' ' },
1154 SER : {start : 23, len : 1, def : ' ' },
1155 VIS : {start : 29, len : 1, def : ' ' },
1156 MIX : {start : 23, len : 1, def : ' ' },
1157 MAP : {start : 29, len : 1, def : ' ' },
1158 SCO : {start : 23, len : 1, def : ' ' },
1159 REC : {start : 23, len : 1, def : ' ' }
1162 BKS : {start : 6, len : 1, def : ' ' },
1163 SER : {start : 6, len : 1, def : ' ' },
1164 VIS : {start : 12, len : 1, def : ' ' },
1165 MIX : {start : 6, len : 1, def : ' ' },
1166 MAP : {start : 12, len : 1, def : ' ' },
1167 SCO : {start : 6, len : 1, def : ' ' },
1168 REC : {start : 6, len : 1, def : ' ' }
1173 SER : {start : 34, len : 1, def : '0' }
1176 SER : {start : 17, len : 1, def : '0' }
1181 SER : {start : 33, len : 1, def : ' ' }
1184 SER : {start : 16, len : 1, def : ' ' }
1189 "AUT" : {"start" : 6, "len" : 1, "def" : ' ' }
1194 "AUT" : {"start" : 7, "len" : 1, "def" : ' ' }
1199 "AUT" : {"start" : 8, "len" : 1, "def" : ' ' }
1204 "AUT" : {"start" : 9, "len" : 1, "def" : ' ' }
1209 "AUT" : {"start" : 10, "len" : 1, "def" : ' ' }
1214 "AUT" : {"start" : 11, "len" : 1, "def" : ' ' }
1219 "AUT" : {"start" : 12, "len" : 1, "def" : ' ' }
1224 "AUT" : {"start" : 13, "len" : 1, "def" : ' ' }
1229 "AUT" : {"start" : 14, "len" : 1, "def" : ' ' }
1234 "AUT" : {"start" : 15, "len" : 1, "def" : ' ' }
1239 "AUT" : {"start" : 16, "len" : 1, "def" : ' ' }
1244 "AUT" : {"start" : 17, "len" : 1, "def" : ' ' }
1249 "AUT" : {"start" : 28, "len" : 1, "def" : ' ' }
1254 "AUT" : {"start" : 29, "len" : 1, "def" : ' ' }
1259 "AUT" : {"start" : 31, "len" : 1, "def" : ' ' }
1264 "AUT" : {"start" : 32, "len" : 1, "def" : ' ' }
1269 "AUT" : {"start" : 33, "len" : 1, "def" : ' ' }
1274 "AUT" : {"start" : 38, "len" : 1, "def" : ' ' }
1279 "AUT" : {"start" : 39, "len" : 1, "def" : ' ' }
1284 function recordType (rec) {
1286 var _l = rec.leader.toString();
1288 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1289 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1291 for (var t in rec_type) {
1292 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1293 document.getElementById('recordTypeLabel').value = t;
1299 // in case we don't have a valid record type ...
1300 _record_type = 'BKS';
1301 return _record_type;
1304 alert('FIXME, MARC Editor, recordType: ' + E);
1308 function toggleFFE () {
1309 var grid = document.getElementById('leaderGrid');
1311 grid.hidden = false;
1318 function changeFFEditor (type) {
1319 var grid = document.getElementById('leaderGrid');
1320 grid.setAttribute('type',type);
1322 // Hide FFEditor rows that we don't need for our current type
1323 // If all of the labels for a given row do not include our
1324 // desired type in their set attribute, we can hide that row
1325 dojo.query('rows row', grid).forEach(function(node, index, arr) {
1326 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
1333 function fillFixedFields (rec) {
1335 var grid = document.getElementById('leaderGrid');
1337 var rtype = _record_type;
1339 var _l = rec.leader.toString();
1340 var _6 = rec.controlfield.(@tag=='006').toString();
1341 var _7 = rec.controlfield.(@tag=='007').toString();
1342 var _8 = rec.controlfield.(@tag=='008').toString();
1345 var pre_list = grid.getElementsByTagName('label');
1346 for (var i in pre_list) {
1347 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1348 list.push( pre_list[i] );
1352 for (var i in list) {
1353 var name = list[i].getAttribute('name');
1359 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1360 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1362 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1363 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1365 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1366 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1368 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1369 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1374 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1375 d = ff_pos[name].ldr[rtype].def;
1379 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1380 d = ff_pos[name]._8[rtype].def;
1384 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1385 d = ff_pos[name]._6[rtype].def;
1389 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1390 d = ff_pos[name]._7[rtype].def;
1395 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1401 list[i].nextSibling.value = value;
1406 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1410 function updateFixedFields (element) {
1411 var grid = document.getElementById('leaderGrid');
1412 var recGrid = document.getElementById('recGrid');
1414 var rtype = _record_type;
1415 var new_value = element.value;
1418 ldr : _record.leader,
1419 _6 : _record.controlfield.(@tag=='006'),
1420 _7 : _record.controlfield.(@tag=='007'),
1421 _8 : _record.controlfield.(@tag=='008')
1424 var name = element.getAttribute('name');
1425 for (var i in ff_pos[name]) {
1427 if (!ff_pos[name][i][rtype]) continue;
1429 // we're missing the required field. Add it now.
1432 if (i == '_6') newfield = '006';
1433 else if (i == '_7') newfield = '007';
1434 else if (i == '_8') newfield = '008';
1437 createControlField(newfield,' ');
1438 parts[i] = _record.controlfield.(@tag==newfield);
1441 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1442 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1444 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1445 new_value += ff_pos[name][i][rtype].def;
1448 parts[i].setChildren( before + new_value + after );
1449 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1455 function marcLeader (leader) {
1456 var row = createRow(
1457 { class : 'marcLeaderRow',
1462 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1465 class : 'marcInd1' } ),
1468 class : 'marcInd2' } ),
1470 { value : leader.text(),
1471 class : 'marcLeader' } )
1477 function marcControlfield (field) {
1478 tagname = field.@tag.toString().substr(2);
1480 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1482 { class : 'marcControlfieldRow',
1483 tag : '_' + tagname },
1485 { value : field.@tag,
1487 context : 'tags_popup',
1488 onmouseover : 'getTooltip(this, "tag");',
1489 tooltipid : 'tag' + field.@tag } ),
1491 { value : field.@ind1,
1493 onmouseover : 'getTooltip(this, "ind1");',
1494 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1496 { value : field.@ind2,
1498 onmouseover : 'getTooltip(this, "ind2");',
1499 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1502 { value : field.text(),
1503 class : 'plain marcEditableControlfield',
1504 name : 'CONTROL' + tagname,
1505 context : 'clipboard',
1511 { class : 'marcControlfieldRow',
1512 tag : '_' + tagname },
1514 { value : field.@tag,
1516 onmouseover : 'getTooltip(this, "tag");',
1517 tooltipid : 'tag' + field.@tag } ),
1519 { value : field.@ind1,
1521 onmouseover : 'getTooltip(this, "ind1");',
1522 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1524 { value : field.@ind2,
1526 onmouseover : 'getTooltip(this, "ind2");',
1527 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1529 { value : field.text(),
1530 class : 'marcControlfield' } )
1537 function stackSubfields(checkbox) {
1538 var list = document.getElementsByAttribute('name','sf_box');
1541 if (!checkbox.checked) o = 'horizontal';
1543 for (var i = 0; i < list.length; i++) {
1544 if (list[i]) list[i].setAttribute('orient',o);
1548 function fastItemAdd_toggle(checkbox) {
1549 var x = document.getElementById('fastItemAdd_textboxes');
1550 if (checkbox.checked) {
1552 document.getElementById('fastItemAdd_callnumber').focus();
1553 document.getElementById('fastItemAdd_callnumber').select();
1559 function fastItemAdd_attempt(doc_id) {
1561 if (typeof window.xulG.fast_add_item != 'function') { return; }
1562 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1563 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1564 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1565 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1566 document.getElementById('fastItemAdd_barcode').value = '';
1568 alert('fastItemAdd_attempt: ' + E);
1572 function save_attempt(xml_string) {
1574 var result = window.xulG.save.func( xml_string );
1576 if (result.id) fastItemAdd_attempt(result.id);
1577 if (typeof result.on_complete == 'function') result.on_complete();
1580 alert('save_attempt: ' + E);
1584 function marcDatafield (field) {
1585 var row = createRow(
1586 { class : 'marcDatafieldRow' },
1589 { value : field.@tag,
1590 class : 'plain marcTag',
1592 context : 'tags_popup',
1593 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1596 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1599 { value : field.@ind1,
1600 class : 'plain marcInd1',
1602 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1605 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1606 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1609 { value : field.@ind2,
1610 class : 'plain marcInd2',
1612 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1615 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1616 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1617 createHbox({ name : 'sf_box' })
1620 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1621 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1622 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1624 var sf_box = row.lastChild;
1625 if (document.getElementById('stackSubfields').checked)
1626 sf_box.setAttribute('orient','vertical');
1628 sf_box.addEventListener(
1631 if (sf_box === e.target) {
1632 sf_box.lastChild.lastChild.focus();
1633 } else if (e.target.parentNode === sf_box) {
1634 e.target.lastChild.focus();
1641 for (var i in field.subfield) {
1642 var sf = field.subfield[i];
1647 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1649 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1650 current_focus = sf_box.lastChild.childNodes[1];
1656 function marcSubfield (sf) {
1658 { class : 'marcSubfieldBox' },
1661 class : 'plain marcSubfieldDelimiter',
1662 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1663 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1664 //onclick : 'this.nextSibling.focus();',
1665 onfocus : 'this.nextSibling.focus();',
1670 class : 'plain marcSubfieldCode',
1671 name : 'marcSubfieldCode',
1672 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1673 oncontextmenu : 'getContextMenu(this, "subfield");',
1674 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1679 { value : sf.text(),
1680 name : sf.parent().@tag + ':' + sf.@code,
1681 class : 'plain marcSubfield',
1682 onmouseover : 'getTooltip(this, "subfield");',
1683 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1684 size : new String(sf.text()).length + 2,
1685 oninput : "this.setAttribute('size', this.value.length + 2);"
1690 function loadRecord(rec) {
1693 var grid_rows = document.getElementById('recGrid').lastChild;
1695 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1697 grid_rows.appendChild( marcLeader( rec.leader ) );
1699 for (var i in rec.controlfield) {
1700 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1703 for (var i in rec.datafield) {
1704 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1707 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1708 changeFFEditor(recordType(rec));
1709 fillFixedFields(rec);
1711 alert('FIXME, MARC Editor, loadRecord: ' + E);
1716 function genToolTips () {
1717 for (var i in bib_data.field) {
1718 var f = bib_data.field[i];
1720 tag_menu.appendChild(
1724 'current_focus.value = "' + f.@tag + '";' +
1725 'var e = document.createEvent("MutationEvents");' +
1726 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1727 'current_focus.inputField.dispatchEvent(e);',
1728 disabled : f.@tag < '010' ? "true" : "false",
1729 tooltiptext : f.description }
1733 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1734 context_menus.appendChild( i1_popup );
1736 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1737 context_menus.appendChild( i2_popup );
1739 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1740 context_menus.appendChild( sf_popup );
1742 tooltip_hash['tag' + f.@tag] = f.description;
1743 for (var j in f.indicator) {
1744 var ind = f.indicator[j];
1745 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1747 if (ind.@position == 1) {
1748 i1_popup.appendChild(
1750 { label : ind.@value,
1752 'current_focus.value = "' + ind.@value + '";' +
1753 'var e = document.createEvent("MutationEvents");' +
1754 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1755 'current_focus.inputField.dispatchEvent(e);',
1756 tooltiptext : ind.description }
1761 if (ind.@position == 2) {
1762 i2_popup.appendChild(
1764 { label : ind.@value,
1766 'current_focus.value = "' + ind.@value + '";' +
1767 'var e = document.createEvent("MutationEvents");' +
1768 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1769 'current_focus.inputField.dispatchEvent(e);',
1770 tooltiptext : ind.description }
1776 for (var j in f.subfield) {
1777 var sf = f.subfield[j];
1778 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1780 sf_popup.appendChild(
1784 'current_focus.value = "' + sf.@code + '";' +
1785 'var e = document.createEvent("MutationEvents");' +
1786 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1787 'current_focus.inputField.dispatchEvent(e);',
1788 tooltiptext : sf.description
1796 function getTooltip (target, type) {
1799 if (type == 'subfield')
1800 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1803 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1806 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1809 tt = 'tag' + target.parentNode.firstChild.value;
1811 if (!document.getElementById( tt )) {
1816 orient : 'vertical',
1817 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1818 class : 'tooltip' },
1819 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1824 target.tooltip = tt;
1828 function getContextMenu (target, type) {
1831 if (type == 'subfield')
1832 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1835 tt = 't' + target.parentNode.firstChild.value + 'i1';
1838 tt = 't' + target.parentNode.firstChild.value + 'i2';
1840 target.setAttribute('context', tt);
1844 var authority_tag_map = {
1845 100 : ['[100,400,500,700]',100],
1846 400 : ['[100,400,500,700]',100],
1847 700 : ['[100,400,500,700]',100],
1848 800 : ['[100,400,500,700]',100],
1849 110 : ['[110,410,510,710]',110],
1850 410 : ['[110,410,510,710]',110],
1851 710 : ['[110,410,510,710]',110],
1852 810 : ['[110,410,510,710]',110],
1853 111 : ['[111,411,511,711]',111],
1854 411 : ['[111,411,511,711]',111],
1855 711 : ['[111,411,511,711]',111],
1856 811 : ['[111,411,511,711]',111],
1857 240 : ['[130,430,530,730]',130],
1858 440 : ['[130,430,530,730]',130],
1859 130 : ['[130,430,530,730]',130],
1860 730 : ['[130,430,530,730]',130],
1861 830 : ['[130,430,530,730]',130],
1862 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1863 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1864 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1865 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1868 function getAuthorityContextMenu (target, sf) {
1869 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1872 var old = dojo.byId( menu_id );
1874 page = auth_pages[menu_id];
1875 old.parentNode.removeChild(old);
1877 auth_pages[menu_id] = 0;
1880 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1882 sf_popup.addEventListener("popuphiding", function(event) {
1883 if (show_auth_menu) {
1884 show_auth_menu = false;
1885 getAuthorityContextMenu(target, sf);
1886 dojo.byId(menu_id).openPopup();
1890 context_menus.appendChild( sf_popup );
1892 if (!authority_tag_map[sf.parent().@tag]) {
1893 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1894 target.setAttribute('context', 'clipboard');
1898 browseAuthority( sf_popup, menu_id, target, sf, 20, page);
1903 function applyAuthority ( target, ui_sf, e4x_sf ) {
1905 var new_vals = target.getElementsByAttribute('checked','true');
1906 var field = e4x_sf.parent();
1908 for (var i = 0; i < new_vals.length; i++) {
1910 var sf_list = field.subfield;
1911 for (var j in sf_list) {
1913 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1914 sf_list[j] = new_vals[i].getAttribute('value');
1915 new_vals[i].setAttribute('subfield','');
1921 for (var i = 0; i < new_vals.length; i++) {
1922 if (!new_vals[i].getAttribute('subfield')) continue;
1924 var val = new_vals[i].getAttribute('value');
1926 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1927 sf.@code = new_vals[i].getAttribute('subfield');
1929 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1932 var row = marcDatafield( field );
1935 while (node.nodeName != 'row') {
1936 node = node.parentNode;
1939 node.parentNode.replaceChild( row, node );
1945 'a' : { 100 : 'a' },
1946 'd' : { 100 : 'd' },
1947 'e' : { 100 : 'e' },
1951 'a' : { 110 : 'a' },
1955 'a' : { 111 : 'a' },
1959 'a' : { 130 : 'a' },
1963 'a' : { 130 : 'a' },
1967 'a' : { 100 : 'a' },
1971 'a' : { 110 : 'a' },
1975 'a' : { 111 : 'a' },
1979 'a' : { 130 : 'a' },
1980 'n' : { 130 : 'n' },
1984 'a' : { 100 : 'a' },
1985 'd' : { 100 : 'd' },
1986 'q' : { 100 : 'q' },
1990 'a' : { 110 : 'a' },
1994 'a' : { 111 : 'a' },
1995 'c' : { 111 : 'c' },
1999 'a' : { 130 : 'a' },
2003 'a' : { 100 : 'a' },
2007 'a' : { 110 : 'a' },
2011 'a' : { 111 : 'a' },
2015 'a' : { 130 : 'a' },
2019 'a' : { 100 : 'a' },
2020 'd' : { 100 : 'd' },
2021 'q' : { 100 : 'q' },
2022 't' : { 100 : 't' },
2049 'a' : { 110 : 'a' },
2050 'd' : { 110 : 'd' },
2051 't' : { 110 : 't' },
2078 'a' : { 111 : 'a' },
2079 'd' : { 111 : 'd' },
2080 't' : { 111 : 't' },
2107 'a' : { 130 : 'a' },
2111 'a' : { 150 : 'a' },
2112 'b' : { 150 : 'b' },
2139 'a' : { 151 : 'a' },
2166 'a' : { 155 : 'a' },
2194 function validateAuthority (button) {
2195 var grid = document.getElementById('recGrid');
2196 var label = button.getAttribute('label');
2199 var rows = grid.lastChild.childNodes;
2200 for (var i = 0; i < rows.length; i++) {
2202 var tag = row.firstChild;
2204 if (!control_map[tag.value]) continue
2205 button.setAttribute('label', label + ' - ' + tag.value);
2207 var ind1 = tag.nextSibling;
2208 var ind2 = ind1.nextSibling;
2209 var subfields = ind2.nextSibling.childNodes;
2213 for (var j = 0; j < subfields.length; j++) {
2214 var sf = subfields[j];
2215 var sf_code = sf.childNodes[1].value;
2216 var sf_value = sf.childNodes[2].value;
2218 if (!control_map[tag.value][sf_code]) continue;
2221 for (var a_tag in control_map[tag.value][sf_code]) {
2222 if (!tags[a_tag]) tags[a_tag] = [];
2223 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2228 for (var val_tag in tags) {
2229 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2230 var res = new XML( auth_data.responseText );
2231 found = parseInt(res.gw::payload.gw::string.toString());
2235 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2236 for (var j = 0; j < subfields.length; j++) {
2237 var sf = subfields[j];
2239 dojo.removeClass(sf.childNodes[2], 'marcValidated');
2240 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
2242 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
2243 dojo.addClass(sf.childNodes[2], 'marcValidated');
2248 button.setAttribute('label', label);
2254 function validateBibField (tags, searches) {
2255 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2256 url += '¶m="tags"¶m=' + js2JSON(tags);
2257 url += '¶m="searches"¶m=' + js2JSON(searches);
2260 var req = new XMLHttpRequest();
2261 req.open('GET',url,false);
2267 function searchAuthority (term, tag, sf, limit) {
2268 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2269 url += '¶m="term"¶m="' + term + '"';
2270 url += '¶m="limit"¶m=' + limit;
2271 url += '¶m="tag"¶m=' + tag;
2272 url += '¶m="subfield"¶m="' + sf + '"';
2275 var req = new XMLHttpRequest();
2276 req.open('GET',url,false);
2283 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
2284 dojo.require('dojox.xml.parser');
2286 // map tag + subfield to the appropriate authority browse axis:
2287 // currently authority.author, authority.subject, authority.title, authority.topic
2288 // based on mappings in OpenILS::Application::SuperCat
2292 // Map based on replacing the first char of the selected tag with '1'
2293 switch ('1' + (sf.parent().@tag.toString()).substring(1)) {
2295 type = 'authority.title';
2301 type = 'authority.author';
2305 type = 'authority.topic';
2311 type = 'authority.subject';
2314 // No matching tag means no authorities to search - shortcut
2327 var url = '/opac/extras/startwith/marcxml/'
2329 + '/1' // OU - currently unscoped
2330 + '/' + sf.toString()
2335 // would be good to carve this out into a separate function
2336 dojo.xhrGet({"url":url, "sync": true, "handleAs":"xml", "load": function(records) {
2337 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
2339 var cm_popup = create_menu.appendChild(
2343 cm_popup.appendChild(
2344 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
2345 command : function() {
2346 // Call middle-layer function to create and save the new authority
2347 var source_f = summarizeField(sf);
2348 var new_auth = fieldmapper.standardRequest(
2349 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
2352 if (new_auth && new_auth.id()) {
2353 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">(CONS){new_auth.id()}</subfield>;
2354 sf.parent().appendChild(id_sf);
2355 var new_sf = marcSubfield(id_sf);
2356 target.parentNode.appendChild(new_sf);
2357 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2363 cm_popup.appendChild(
2364 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
2365 command : function() {
2366 // Generate the new authority by calling the new middle-layer
2367 // function (a non-saving variant), then display in another
2369 var source_f = summarizeField(sf);
2370 var authtoken = ses();
2371 dojo.require('openils.PermaCrud');
2372 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2373 var rec = fieldmapper.standardRequest(
2374 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
2375 { "params": [source_f] }
2377 loadMarcEditor(pcrud, rec, target, sf);
2382 sf_popup.appendChild(create_menu);
2383 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2385 // append "Previous page" results browser
2386 sf_popup.appendChild(
2387 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
2388 command : function(event) {
2389 auth_pages[menu_id] -= 1;
2390 show_auth_menu = true;
2394 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2396 dojo.query('record', records).forEach(function(record) {
2398 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"] subfield[code="c"]', record)[0]);
2399 var auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
2400 // we have grabbed the fields with tags beginning with 1 or 5 and iterate through the subfields
2401 dojo.query('datafield[tag^="1"], datafield[tag^="5"]', record).forEach(function(field) {
2402 dojo.query('subfield', field).forEach(function(subfield) {
2406 main_text += dojox.xml.parser.textContent(subfield);
2412 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) return;
2415 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
2416 grid.setAttribute('name','-none-');
2417 grid.setAttribute('style','overflow:scroll');
2419 var submenu = createMenu( { label : main_text } );
2421 var popup = createMenuPopup({ flex : "1" });
2422 submenu.appendChild(popup);
2424 dojo.query('datafield[tag^="1"], datafield[tag^="5"]', record).forEach(function(field) {
2425 var row = createRow(
2427 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
2428 createLabel( { "value" : dojo.attr(field, 'ind2') } )
2431 var sf_box = createHbox();
2432 dojo.query('subfield', field).forEach(function(subfield) {
2435 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
2436 "subfield" : dojo.attr(subfield, 'code'),
2437 "tag" : dojo.attr(field, 'tag'),
2438 "value" : dojox.xml.parser.textContent(subfield)
2442 row.appendChild(sf_box);
2445 // Append the authority linking subfield
2448 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
2450 "tag" : dojo.attr(field, 'tag'),
2451 "value" : '(' + auth_org + ')' + auth_id
2455 row.appendChild(sf_box);
2457 grid.lastChild.appendChild(row);
2460 grid.hidden = false;
2461 popup.appendChild( grid );
2465 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
2466 command : function (event) {
2467 applyAuthority(event.target.previousSibling, target, sf);
2474 sf_popup.appendChild( submenu );
2477 if (sf_popup.childNodes.length == 0) {
2478 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
2480 // append "Next page" results browser
2481 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2482 sf_popup.appendChild(
2483 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
2484 command : function(event) {
2485 auth_pages[menu_id] += 1;
2486 show_auth_menu = true;
2492 target.setAttribute('context', menu_id);
2498 function summarizeField(sf) {
2505 for (var i = 0; i < sf.parent().subfield.length(); i++) {
2506 source_f.subfields.push([sf.parent().subfield[i].@code.toString(), sf.parent().subfield[i].toString()]);
2508 source_f.tag = sf.parent().@tag.toString();
2509 source_f.ind1 = sf.parent().@ind1.toString();
2510 source_f.ind1 = sf.parent().@ind2.toString();
2515 function buildBibSourceList (authtoken, recId) {
2516 /* TODO: Work out how to set the bib source of the bre that does not yet
2517 * exist - this is specifically in the case of Z39.50 imports. Right now
2518 * we just avoid populating and showing the config.bib_source list
2524 var bib = xulG.record.bre;
2526 dojo.require('openils.PermaCrud');
2528 // cbsList = the XUL menulist that contains the available bib sources
2529 var cbsList = dojo.byId('bib-source-list');
2531 // bibSources = an array containing all of the bib source objects
2532 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
2534 // A tad ugly, but gives us the index of the bib source ID in cbsList
2536 var cbsListArr = [];
2537 dojo.forEach(bibSources, function (item) {
2538 cbsList.appendItem(item.source(), item.id());
2539 cbsListArr[item.id()] = x;
2543 // Show the current value of the bib source for this record
2544 cbsList.selectedIndex = cbsListArr[bib.source()];
2546 // Display the bib source selection widget
2547 dojo.byId('bib-source-list-caption').hidden = false;
2548 dojo.byId('bib-source-list').hidden = false;
2549 dojo.byId('bib-source-list-button').disabled = true;
2550 dojo.byId('bib-source-list-button').hidden = false;
2553 // Fired when the "Update Source" button is clicked
2554 // Updates the value of the bib source for the current record
2555 function updateBibSource() {
2556 var authtoken = ses();
2557 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2558 var recId = xulG.record.id;
2559 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2560 var bib = pcrud.retrieve('bre', recId);
2561 if (bib.source() != cbs) {
2563 bib.ischanged = true;
2568 function onBibSourceSelect() {
2569 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2570 var bib = xulG.record.bre;
2571 if (bib.source() != cbs) {
2572 dojo.byId('bib-source-list-button').disabled = false;
2574 dojo.byId('bib-source-list-button').disabled = true;
2578 function loadMarcEditor(pcrud, marcxml, target, sf) {
2580 To run in Firefox directly, must set signed.applets.codebase_principal_support
2581 to true in about:config
2583 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
2584 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
2586 // Match marc2are.pl last_xact_id format, roughly
2588 var xact_id = 'IMPORT-' + Date.parse(now);
2591 "record": {"marc": marcxml, "rtype": "are"},
2593 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2594 "func": function(xmlString) {
2595 var rec = new are();
2596 rec.marc(xmlString);
2597 rec.last_xact_id(xact_id);
2600 "oncomplete": function (r, objs) {
2601 var new_rec = objs[0];
2605 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">(CONS){new_rec.id()}</subfield>;
2606 sf.parent().appendChild(id_sf);
2607 var new_sf = marcSubfield(id_sf);
2608 target.parentNode.appendChild(new_sf);
2609 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));