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 = {};
145 window.xulG.marc_control_number_identifier = 'CONS';
147 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
148 window.xulG.save.func = function (r) { alert(r); }
151 var _rid = cgi.param('record');
153 window.xulG.record.id = _rid;
154 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
158 // End faking part...
160 /* Check for an explicitly passed record type
161 * This is not the same as the fixed-field record type; we can't trust
162 * the fixed fields when making modifications to the attributes for a
163 * given record (in particular, config.bib_source only applies for bib
164 * records, but an auth or MFHD record with the same ID and bad fixed
165 * fields could trample the config.bib_source value for the
166 * corresponding bib record if we're not careful.
168 * are = authority record
169 * sre = serial record (MFHD)
170 * bre = bibliographic record
172 if (!window.xulG.record.rtype) {
174 window.xulG.record.rtype = cgi.param('rtype') || false;
177 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
178 document.getElementById('save-button').setAttribute('oncommand',
179 'if ($("xul-editor").hidden) set_flat_editor(false); ' +
181 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
182 'save_attempt( xml_string ); ' +
183 'loadRecord(xml_record);'
186 if (window.xulG.record.url) {
187 var req = new XMLHttpRequest();
188 req.open('POST',window.xulG.record.url,false);
190 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
193 xml_record = new XML( window.xulG.record.marc );
194 if (xml_record..record[0]) xml_record = xml_record..record[0];
196 // Get the tooltip xml all async like
197 req = new XMLHttpRequest();
199 // Set a default locale in case preferences fail us
200 var locale = "en-US";
202 // Try to get the locale from our preferences
203 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
205 const Cc = Components.classes;
206 const Ci = Components.interfaces;
207 locale = Cc["@mozilla.org/preferences-service;1"].
208 getService(Ci.nsIPrefBranch).
209 getCharPref("general.useragent.locale");
213 // TODO: We should send a HEAD request to check for the existence of the desired file
214 // then fall back to the default locale if preferred locale is not necessary;
215 // however, for now we have a simplistic check:
217 // we currently have translations for only two locales; in the absence of a
218 // valid locale, default to the almighty en-US
219 if (locale != 'en-US' && locale != 'fr-CA') {
223 // grab the right tooltip based on MARC type
224 var tooltip_doc = 'marcedit-tooltips.xml';
225 switch (window.xulG.record.rtype) {
227 tooltip_doc = 'marcedit-tooltips.xml';
230 tooltip_doc = 'marcedit-tooltips-authority.xml';
231 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
234 tooltip_doc = 'marcedit-tooltips-mfhd.xml';
235 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
238 tooltip_doc = 'marcedit-tooltips.xml';
241 // Get the locale-specific tooltips
242 req.open('GET','/xul/server/locale/' + locale + '/' + tooltip_doc,true);
244 context_menus = createComplexXULElement('popupset');
245 document.documentElement.appendChild( context_menus );
247 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
248 context_menus.appendChild( tag_menu );
250 tag_menu.appendChild(
252 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
254 'var e = document.createEvent("KeyEvents");' +
255 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
256 'current_focus.inputField.dispatchEvent(e);'
261 tag_menu.appendChild(
263 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
265 'var e = document.createEvent("KeyEvents");' +
266 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
267 'current_focus.inputField.dispatchEvent(e);'
272 tag_menu.appendChild(
274 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
276 'var e = document.createEvent("KeyEvents");' +
277 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
278 'current_focus.inputField.dispatchEvent(e);'
283 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
285 tag_menu.appendChild(
287 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
289 'var e = document.createEvent("KeyEvents");' +
290 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
291 'current_focus.inputField.dispatchEvent(e);'
296 tag_menu.appendChild(
298 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
300 'var e = document.createEvent("KeyEvents");' +
301 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
302 'current_focus.inputField.dispatchEvent(e);'
307 tag_menu.appendChild(
309 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
311 'var e = document.createEvent("KeyEvents");' +
312 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
313 'current_focus.inputField.dispatchEvent(e);'
318 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
320 p = createComplexXULElement('popupset');
321 document.documentElement.appendChild( p );
323 req.onreadystatechange = function () {
324 if (req.readyState == 4) {
325 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
331 loadRecord(xml_record);
333 if (! xulG.fast_add_item) {
334 document.getElementById('fastItemAdd_checkbox').hidden = true;
336 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
338 // Only show bib sources for bib records that already exist in the database
339 if (xulG.record.rtype == 'bre' && xulG.record.id) {
340 dojo.require('openils.PermaCrud');
341 var authtoken = ses();
342 // Retrieve the current record attributes
343 var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
345 // Remember the current bib source of the record
346 xulG.record.bre = bib;
348 buildBibSourceList(authtoken, xulG.record.id);
352 alert('FIXME, MARC Editor, my_init: ' + E);
357 function createComplexHTMLElement (e, attrs, objects, text) {
358 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
361 for (var i in attrs) l.setAttribute(i,attrs[i]);
365 for ( var i in objects ) l.appendChild( objects[i] );
369 l.appendChild( document.createTextNode(text) )
375 function createComplexXULElement (e, attrs, objects) {
376 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
379 for (var i in attrs) {
380 if (typeof attrs[i] == 'function') {
381 l.addEventListener( i, attrs[i], true );
383 l.setAttribute(i,attrs[i]);
389 for ( var i in objects ) l.appendChild( objects[i] );
395 function createDescription (attrs) {
396 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
399 function createTooltip (attrs) {
400 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
403 function createLabel (attrs) {
404 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
407 function createVbox (attrs) {
408 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
411 function createHbox (attrs) {
412 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
415 function createRow (attrs) {
416 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
419 function createTextbox (attrs) {
420 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
423 function createMenu (attrs) {
424 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
427 function createMenuPopup (attrs) {
428 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
431 function createPopup (attrs) {
432 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
435 function createMenuitem (attrs) {
436 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
439 function createCheckbox (attrs) {
440 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
443 // Find the next textbox that we can use for a focus point
444 // For control fields, use the first editable text box
445 // For data fields, focus on the first subfield text box
446 function setFocusToNextTag (row, direction) {
447 var keep_looking = true;
448 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
449 // Is it a datafield?
450 dojo.query('hbox hbox textbox', row).forEach(function(node, index, arr) {
452 keep_looking = false;
455 // No, it's a control field; use the first textbox
457 dojo.query('textbox', row).forEach(function(node, index, arr) {
459 keep_looking = false;
468 function createMARCTextbox (element,attrs) {
470 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
471 box.onkeypress = function (event) {
474 while(node = node.parent()) {
478 var row = event.target;
479 while (row.tagName != 'row') row = row.parentNode;
481 if (element.nodeKind() == 'attribute') element[0]=box.value;
482 else element.setChildren( box.value );
484 if (element.localName() != 'controlfield') {
485 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
487 var index_sf, target, move_data;
488 if (element.localName() == 'subfield') {
490 target = event.target.parentNode;
492 var start = event.target.selectionStart;
493 var end = event.target.selectionEnd - event.target.selectionStart ?
494 event.target.selectionEnd :
495 event.target.value.length;
497 move_data = event.target.value.substring(start,end);
498 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
499 event.target.setAttribute('size', event.target.value.length + 2);
501 element.setChildren( event.target.value );
503 } else if (element.localName() == 'code') {
504 index_sf = element.parent();
505 target = event.target.parentNode;
506 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
507 index_sf = element.parent().children()[element.parent().children().length() - 1];
508 target = event.target.parentNode.lastChild.lastChild;
511 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
513 index_sf.parent().insertChildAfter( index_sf, sf );
515 var new_sf = marcSubfield(sf);
517 if (target === target.parentNode.lastChild) {
518 target.parentNode.appendChild( new_sf );
520 target.parentNode.insertBefore( new_sf, target.nextSibling );
523 new_sf.firstChild.nextSibling.focus();
525 event.preventDefault();
528 } else if (event.keyCode == 13 || event.keyCode == 77) {
529 if (event.ctrlKey) { // ctrl+enter
532 if (element.localName() == 'subfield') index = element.parent();
533 if (element.localName() == 'code') index = element.parent().parent();
534 if (element.localName() == 'tag') index = element.parent();
535 if (element.localName() == 'ind1') index = element.parent();
536 if (element.localName() == 'ind2') index = element.parent();
538 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
540 if (event.shiftKey) { // ctrl+shift+enter
541 index.parent().insertChildBefore( index, df );
543 index.parent().insertChildAfter( index, df );
546 var new_df = marcDatafield(df);
548 if (row.parentNode.lastChild === row) {
549 row.parentNode.appendChild( new_df );
551 if (event.shiftKey) { // ctrl+shift+enter
552 row.parentNode.insertBefore( new_df, row );
554 row.parentNode.insertBefore( new_df, row.nextSibling );
558 new_df.firstChild.focus();
560 event.preventDefault();
563 } else if (event.shiftKey) {
564 if (row.previousSibling.className.match('marcDatafieldRow'))
565 row.previousSibling.firstChild.focus();
567 row.nextSibling.firstChild.focus();
570 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
571 if (event.ctrlKey) { // CTRL key: copy the field
573 if (element.localName() == 'subfield') index = element.parent();
574 if (element.localName() == 'code') index = element.parent().parent();
575 if (element.localName() == 'tag') index = element.parent();
576 if (element.localName() == 'ind1') index = element.parent();
577 if (element.localName() == 'ind2') index = element.parent();
579 var copyField = index.copy();
581 if (event.keyCode == 38) { // ctrl+up-arrow
582 index.parent().insertChildBefore( index, copyField );
584 index.parent().insertChildAfter( index, copyField );
587 var new_df = marcDatafield(copyField);
589 if (row.parentNode.lastChild === row) {
590 row.parentNode.appendChild( new_df );
592 if (event.keyCode == 38) { // ctrl+up-arrow
593 row.parentNode.insertBefore( new_df, row );
594 } else { // ctrl+down-arrow
595 row.parentNode.insertBefore( new_df, row.nextSibling );
599 new_df.firstChild.focus();
601 event.preventDefault();
605 if (event.keyCode == 38) {
606 return setFocusToNextTag(row, 'up');
608 if (event.keyCode == 40) {
609 return setFocusToNextTag(row, 'down');
614 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
617 if (element.localName() == 'subfield') index = element.parent();
618 if (element.localName() == 'code') index = element.parent().parent();
619 if (element.localName() == 'tag') index = element.parent();
620 if (element.localName() == 'ind1') index = element.parent();
621 if (element.localName() == 'ind2') index = element.parent();
623 for (var i in index.parent().children()) {
624 if (index === index.parent().children()[i]) {
625 delete index.parent().children()[i];
630 row.previousSibling.firstChild.focus();
631 row.parentNode.removeChild(row);
633 event.preventDefault();
636 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
639 if (element.localName() == 'subfield') index = element;
640 if (element.localName() == 'code') index = element.parent();
643 for (var i in index.parent().children()) {
644 if (index === index.parent().children()[i]) {
645 delete index.parent().children()[i];
650 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
651 event.target.parentNode.previousSibling.lastChild.focus();
653 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
656 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
658 event.preventDefault();
661 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
662 createControlField('006',' ');
663 loadRecord(xml_record);
664 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
665 createControlField('007',' ');
666 loadRecord(xml_record);
667 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
668 createControlField('008',' ');
669 loadRecord(xml_record);
674 } else { // event on a control field
675 if (event.keyCode == 38) {
676 return setFocusToNextTag(row, 'up');
677 } else if (event.keyCode == 40) {
678 return setFocusToNextTag(row, 'down');
683 box.addEventListener(
686 if (element.nodeKind() == 'attribute') element[0]=box.value;
687 else element.setChildren( box.value );
693 box.addEventListener(
696 if (element.nodeKind() == 'attribute') element[0]=box.value;
697 else element.setChildren( box.value );
703 box.addEventListener(
706 if (element.nodeKind() == 'attribute') element[0]=box.value;
707 else element.setChildren( box.value );
713 // 'input' event catches the box value after the keypress
714 box.addEventListener(
717 if (element.nodeKind() == 'attribute') element[0]=box.value;
718 else element.setChildren( box.value );
724 box.addEventListener(
727 if (element.localName() == 'controlfield')
728 eval('fillFixedFields(xml_record);');
737 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
738 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
739 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
740 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
741 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
742 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
743 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
744 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ },
745 AUT : { Type : /[z]{1}/, BLvl : /.{1}/ },
746 MFHD : { Type : /[uvxy]{1}/, BLvl : /.{1}/ }
752 SCO : {start : 33, len : 1, def : ' ' },
753 REC : {start : 33, len : 1, def : 'n' }
756 SCO : {start : 16, len : 1, def : ' ' },
757 REC : {start : 16, len : 1, def : 'n' }
762 VIS : {start : 33, len : 1, def : ' ' }
765 VIS : {start : 16, len : 1, def : ' ' }
770 VIS : {start : 18, len : 3, def : ' ' }
773 VIS : {start : 1, len : 3, def : ' ' }
778 VIS : {start : 34, len : 1, def : 'n' }
781 VIS : {start : 17, len : 1, def : 'n' }
786 SER : {start : 21, len : 1, def : ' ' }
789 SER : {start : 4, len : 1, def : ' ' }
794 BKS : {start : 39, len : 1, def : 'd' },
795 SER : {start : 39, len : 1, def : 'd' },
796 VIS : {start : 39, len : 1, def : 'd' },
797 MIX : {start : 39, len : 1, def : 'd' },
798 MAP : {start : 39, len : 1, def : 'd' },
799 SCO : {start : 39, len : 1, def : 'd' },
800 REC : {start : 39, len : 1, def : 'd' },
801 COM : {start : 39, len : 1, def : 'd' }
806 MAP : {start : 33, len : 2, def : ' ' }
809 MAP : {start : 16, len : 2, def : ' ' }
814 MAP : {start : 18, len : 4, def : ' ' }
817 MAP : {start : 1, len : 4, def : ' ' }
822 SER : {start : 19, len : 1, def : ' ' }
825 SER : {start : 2, len : 1, def : ' ' }
830 MAP : {start : 22, len : 2, def : ' ' }
833 MAP : {start : 5, len : 2, def : ' ' }
838 SCO : {start : 21, len : 1, def : ' ' },
839 REC : {start : 21, len : 1, def : 'n' }
842 SCO : {start : 4, len : 1, def : ' ' },
843 REC : {start : 4, len : 1, def : 'n' }
848 SER : {start : 22, len : 1, def : ' ' }
851 SER : {start : 5, len : 1, def : ' ' }
856 SCO : {start : 30, len : 2, def : ' ' },
857 REC : {start : 30, len : 2, def : ' ' }
860 SCO : {start : 13, len : 2, def : ' ' },
861 REC : {start : 13, len : 2, def : ' ' }
866 SER : {start : 18, len : 1, def : ' ' }
869 SER : {start : 1, len : 1, def : ' ' }
874 SCO : {start : 20, len : 1, def : ' ' },
875 REC : {start : 20, len : 1, def : 'n' }
878 SCO : {start : 3, len : 1, def : ' ' },
879 REC : {start : 3, len : 1, def : 'n' }
884 COM : {start : 26, len : 1, def : 'u' }
887 COM : {start : 9, len : 1, def : 'u' }
892 SER : {start : 24, len : 1, def : ' ' }
895 SER : {start : 7, len : 1, def : ' ' }
900 SCO : {start : 24, len : 6, def : ' ' },
901 REC : {start : 24, len : 6, def : ' ' }
904 SCO : {start : 7, len : 6, def : ' ' },
905 REC : {start : 7, len : 6, def : ' ' }
910 SCO : {start : 18, len : 2, def : ' ' },
911 REC : {start : 18, len : 2, def : ' ' }
914 SCO : {start : 1, len : 2, def : ' ' },
915 REC : {start : 1, len : 2, def : ' ' }
920 MAP : {start : 25, len : 1, def : ' ' }
923 MAP : {start : 8, len : 1, def : ' ' }
928 BKS : {start : 15, len : 3, def : ' ' },
929 SER : {start : 15, len : 3, def : ' ' },
930 VIS : {start : 15, len : 3, def : ' ' },
931 MIX : {start : 15, len : 3, def : ' ' },
932 MAP : {start : 15, len : 3, def : ' ' },
933 SCO : {start : 15, len : 3, def : ' ' },
934 REC : {start : 15, len : 3, def : ' ' },
935 COM : {start : 15, len : 3, def : ' ' }
940 BKS : {start : 35, len : 3, def : ' ' },
941 SER : {start : 35, len : 3, def : ' ' },
942 VIS : {start : 35, len : 3, def : ' ' },
943 MIX : {start : 35, len : 3, def : ' ' },
944 MAP : {start : 35, len : 3, def : ' ' },
945 SCO : {start : 35, len : 3, def : ' ' },
946 REC : {start : 35, len : 3, def : ' ' },
947 COM : {start : 35, len : 3, def : ' ' }
952 BKS : {start : 38, len : 1, def : ' ' },
953 SER : {start : 38, len : 1, def : ' ' },
954 VIS : {start : 38, len : 1, def : ' ' },
955 MIX : {start : 38, len : 1, def : ' ' },
956 MAP : {start : 38, len : 1, def : ' ' },
957 SCO : {start : 38, len : 1, def : ' ' },
958 REC : {start : 38, len : 1, def : ' ' },
959 COM : {start : 38, len : 1, def : ' ' }
964 BKS : {start : 6, len : 1, def : ' ' },
965 SER : {start : 6, len : 1, def : 'c' },
966 VIS : {start : 6, len : 1, def : ' ' },
967 MIX : {start : 6, len : 1, def : ' ' },
968 MAP : {start : 6, len : 1, def : ' ' },
969 SCO : {start : 6, len : 1, def : ' ' },
970 REC : {start : 6, len : 1, def : ' ' },
971 COM : {start : 6, len : 1, def : ' ' }
976 BKS : {start : 6, len : 1, def : 'a' },
977 SER : {start : 6, len : 1, def : 'a' },
978 VIS : {start : 6, len : 1, def : 'g' },
979 MIX : {start : 6, len : 1, def : 'p' },
980 MAP : {start : 6, len : 1, def : 'e' },
981 SCO : {start : 6, len : 1, def : 'c' },
982 REC : {start : 6, len : 1, def : 'i' },
983 COM : {start : 6, len : 1, def : 'm' },
984 AUT : {start : 6, len : 1, def : 'z' },
985 MFHD : {start : 6, len : 1, def : 'y' }
990 BKS : {start : 8, len : 1, def : ' ' },
991 SER : {start : 8, len : 1, def : ' ' },
992 VIS : {start : 8, len : 1, def : ' ' },
993 MIX : {start : 8, len : 1, def : ' ' },
994 MAP : {start : 8, len : 1, def : ' ' },
995 SCO : {start : 8, len : 1, def : ' ' },
996 REC : {start : 8, len : 1, def : ' ' },
997 COM : {start : 8, len : 1, def : ' ' }
1002 BKS : {start : 7, len : 1, def : 'm' },
1003 SER : {start : 7, len : 1, def : 's' },
1004 VIS : {start : 7, len : 1, def : 'm' },
1005 MIX : {start : 7, len : 1, def : 'c' },
1006 MAP : {start : 7, len : 1, def : 'm' },
1007 SCO : {start : 7, len : 1, def : 'm' },
1008 REC : {start : 7, len : 1, def : 'm' },
1009 COM : {start : 7, len : 1, def : 'm' }
1014 BKS : {start : 18, len : 1, def : ' ' },
1015 SER : {start : 18, len : 1, def : ' ' },
1016 VIS : {start : 18, len : 1, def : ' ' },
1017 MIX : {start : 18, len : 1, def : ' ' },
1018 MAP : {start : 18, len : 1, def : ' ' },
1019 SCO : {start : 18, len : 1, def : ' ' },
1020 REC : {start : 18, len : 1, def : ' ' },
1021 COM : {start : 18, len : 1, def : 'i' }
1026 MFHD : {start : 18, len : 1, def : 'i' }
1031 BKS : {start : 17, len : 1, def : ' ' },
1032 SER : {start : 17, len : 1, def : ' ' },
1033 VIS : {start : 17, len : 1, def : ' ' },
1034 MIX : {start : 17, len : 1, def : ' ' },
1035 MAP : {start : 17, len : 1, def : ' ' },
1036 SCO : {start : 17, len : 1, def : ' ' },
1037 REC : {start : 17, len : 1, def : ' ' },
1038 COM : {start : 17, len : 1, def : ' ' },
1039 AUT : {start : 17, len : 1, def : 'n' },
1040 MFHD : {start : 17, len : 1, def : 'u' }
1045 BKS : {start : 31, len : 1, def : '0' },
1046 MAP : {start : 31, len : 1, def : '0' }
1049 BKS : {start : 14, len : 1, def : '0' },
1050 MAP : {start : 14, len : 1, def : '0' }
1055 BKS : {start : 7, len : 4, def : ' ' },
1056 SER : {start : 7, len : 4, def : ' ' },
1057 VIS : {start : 7, len : 4, def : ' ' },
1058 MIX : {start : 7, len : 4, def : ' ' },
1059 MAP : {start : 7, len : 4, def : ' ' },
1060 SCO : {start : 7, len : 4, def : ' ' },
1061 REC : {start : 7, len : 4, def : ' ' },
1062 COM : {start : 7, len : 4, def : ' ' }
1067 BKS : {start : 11, len : 4, def : ' ' },
1068 SER : {start : 11, len : 4, def : '9' },
1069 VIS : {start : 11, len : 4, def : ' ' },
1070 MIX : {start : 11, len : 4, def : ' ' },
1071 MAP : {start : 11, len : 4, def : ' ' },
1072 SCO : {start : 11, len : 4, def : ' ' },
1073 REC : {start : 11, len : 4, def : ' ' },
1074 COM : {start : 11, len : 4, def : ' ' }
1079 BKS : {start : 33, len : 1, def : '0' }
1082 BKS : {start : 16, len : 1, def : '0' }
1087 BKS : {start : 34, len : 1, def : ' ' }
1090 BKS : {start : 17, len : 1, def : ' ' }
1095 BKS : {start : 18, len : 4, def : ' ' }
1098 BKS : {start : 1, len : 4, def : ' ' }
1103 BKS : {start : 30, len : 1, def : '0' }
1106 BKS : {start : 13, len : 1, def : '0' }
1111 BKS : {start : 29, len : 1, def : '0' },
1112 SER : {start : 29, len : 1, def : '0' }
1115 BKS : {start : 12, len : 1, def : '0' },
1116 SER : {start : 12, len : 1, def : '0' }
1121 BKS : {start : 24, len : 4, def : ' ' },
1122 SER : {start : 25, len : 3, def : ' ' }
1125 BKS : {start : 7, len : 4, def : ' ' },
1126 SER : {start : 8, len : 3, def : ' ' }
1131 BKS : {start : 28, len : 1, def : ' ' },
1132 SER : {start : 28, len : 1, def : ' ' },
1133 VIS : {start : 28, len : 1, def : ' ' },
1134 MAP : {start : 28, len : 1, def : ' ' },
1135 COM : {start : 28, len : 1, def : ' ' }
1138 BKS : {start : 11, len : 1, def : ' ' },
1139 SER : {start : 11, len : 1, def : ' ' },
1140 VIS : {start : 11, len : 1, def : ' ' },
1141 MAP : {start : 11, len : 1, def : ' ' },
1142 COM : {start : 11, len : 1, def : ' ' }
1147 BKS : {start : 22, len : 1, def : ' ' },
1148 SER : {start : 22, len : 1, def : ' ' },
1149 VIS : {start : 22, len : 1, def : ' ' },
1150 SCO : {start : 22, len : 1, def : ' ' },
1151 REC : {start : 22, len : 1, def : ' ' },
1152 COM : {start : 22, len : 1, def : ' ' }
1155 BKS : {start : 5, len : 1, def : ' ' },
1156 SER : {start : 5, len : 1, def : ' ' },
1157 VIS : {start : 5, len : 1, def : ' ' },
1158 SCO : {start : 5, len : 1, def : ' ' },
1159 REC : {start : 5, len : 1, def : ' ' },
1160 COM : {start : 5, len : 1, def : ' ' }
1165 BKS : {start : 23, len : 1, def : ' ' },
1166 SER : {start : 23, len : 1, def : ' ' },
1167 VIS : {start : 29, len : 1, def : ' ' },
1168 MIX : {start : 23, len : 1, def : ' ' },
1169 MAP : {start : 29, len : 1, def : ' ' },
1170 SCO : {start : 23, len : 1, def : ' ' },
1171 REC : {start : 23, len : 1, def : ' ' }
1174 BKS : {start : 6, len : 1, def : ' ' },
1175 SER : {start : 6, len : 1, def : ' ' },
1176 VIS : {start : 12, len : 1, def : ' ' },
1177 MIX : {start : 6, len : 1, def : ' ' },
1178 MAP : {start : 12, len : 1, def : ' ' },
1179 SCO : {start : 6, len : 1, def : ' ' },
1180 REC : {start : 6, len : 1, def : ' ' }
1185 SER : {start : 34, len : 1, def : '0' }
1188 SER : {start : 17, len : 1, def : '0' }
1193 SER : {start : 33, len : 1, def : ' ' }
1196 SER : {start : 16, len : 1, def : ' ' }
1201 "AUT" : {"start" : 6, "len" : 1, "def" : ' ' }
1206 "AUT" : {"start" : 7, "len" : 1, "def" : ' ' }
1211 "AUT" : {"start" : 8, "len" : 1, "def" : ' ' }
1216 "AUT" : {"start" : 9, "len" : 1, "def" : ' ' }
1221 "AUT" : {"start" : 10, "len" : 1, "def" : ' ' }
1226 "AUT" : {"start" : 11, "len" : 1, "def" : ' ' }
1231 "AUT" : {"start" : 12, "len" : 1, "def" : ' ' }
1236 "AUT" : {"start" : 13, "len" : 1, "def" : ' ' }
1241 "AUT" : {"start" : 14, "len" : 1, "def" : ' ' }
1246 "AUT" : {"start" : 15, "len" : 1, "def" : ' ' }
1251 "AUT" : {"start" : 16, "len" : 1, "def" : ' ' }
1256 "AUT" : {"start" : 17, "len" : 1, "def" : ' ' }
1261 "AUT" : {"start" : 28, "len" : 1, "def" : ' ' }
1266 "AUT" : {"start" : 29, "len" : 1, "def" : ' ' }
1271 "AUT" : {"start" : 31, "len" : 1, "def" : ' ' }
1276 "AUT" : {"start" : 32, "len" : 1, "def" : ' ' }
1281 "AUT" : {"start" : 33, "len" : 1, "def" : ' ' }
1286 "AUT" : {"start" : 38, "len" : 1, "def" : ' ' }
1291 "AUT" : {"start" : 39, "len" : 1, "def" : ' ' }
1296 function recordType (rec) {
1298 var _l = rec.leader.toString();
1300 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1301 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1303 for (var t in rec_type) {
1304 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1305 document.getElementById('recordTypeLabel').value = t;
1311 // in case we don't have a valid record type ...
1312 _record_type = 'BKS';
1313 return _record_type;
1316 alert('FIXME, MARC Editor, recordType: ' + E);
1320 function toggleFFE () {
1321 var grid = document.getElementById('leaderGrid');
1323 grid.hidden = false;
1330 function changeFFEditor (type) {
1331 var grid = document.getElementById('leaderGrid');
1332 grid.setAttribute('type',type);
1334 // Hide FFEditor rows that we don't need for our current type
1335 // If all of the labels for a given row do not include our
1336 // desired type in their set attribute, we can hide that row
1337 dojo.query('rows row', grid).forEach(function(node, index, arr) {
1338 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
1345 function fillFixedFields (rec) {
1347 var grid = document.getElementById('leaderGrid');
1349 var rtype = _record_type;
1351 var _l = rec.leader.toString();
1352 var _6 = rec.controlfield.(@tag=='006').toString();
1353 var _7 = rec.controlfield.(@tag=='007').toString();
1354 var _8 = rec.controlfield.(@tag=='008').toString();
1357 var pre_list = grid.getElementsByTagName('label');
1358 for (var i in pre_list) {
1359 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1360 list.push( pre_list[i] );
1364 for (var i in list) {
1365 var name = list[i].getAttribute('name');
1371 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1372 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1374 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1375 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1377 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1378 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1380 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1381 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1386 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1387 d = ff_pos[name].ldr[rtype].def;
1391 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1392 d = ff_pos[name]._8[rtype].def;
1396 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1397 d = ff_pos[name]._6[rtype].def;
1401 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1402 d = ff_pos[name]._7[rtype].def;
1407 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1413 list[i].nextSibling.value = value;
1418 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1422 function updateFixedFields (element) {
1423 var grid = document.getElementById('leaderGrid');
1424 var recGrid = document.getElementById('recGrid');
1426 var rtype = _record_type;
1427 var new_value = element.value;
1430 ldr : _record.leader,
1431 _6 : _record.controlfield.(@tag=='006'),
1432 _7 : _record.controlfield.(@tag=='007'),
1433 _8 : _record.controlfield.(@tag=='008')
1436 var name = element.getAttribute('name');
1437 for (var i in ff_pos[name]) {
1439 if (!ff_pos[name][i][rtype]) continue;
1441 // we're missing the required field. Add it now.
1444 if (i == '_6') newfield = '006';
1445 else if (i == '_7') newfield = '007';
1446 else if (i == '_8') newfield = '008';
1449 createControlField(newfield,' ');
1450 parts[i] = _record.controlfield.(@tag==newfield);
1453 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1454 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1456 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1457 new_value += ff_pos[name][i][rtype].def;
1460 parts[i].setChildren( before + new_value + after );
1461 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1467 function marcLeader (leader) {
1468 var row = createRow(
1469 { class : 'marcLeaderRow',
1474 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1477 class : 'marcInd1' } ),
1480 class : 'marcInd2' } ),
1482 { value : leader.text(),
1483 class : 'marcLeader' } )
1489 function marcControlfield (field) {
1490 tagname = field.@tag.toString().substr(2);
1492 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1494 { class : 'marcControlfieldRow',
1495 tag : '_' + tagname },
1497 { value : field.@tag,
1499 context : 'tags_popup',
1500 onmouseover : 'getTooltip(this, "tag");',
1501 tooltipid : 'tag' + field.@tag } ),
1503 { value : field.@ind1,
1505 onmouseover : 'getTooltip(this, "ind1");',
1506 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1508 { value : field.@ind2,
1510 onmouseover : 'getTooltip(this, "ind2");',
1511 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1514 { value : field.text(),
1515 class : 'plain marcEditableControlfield',
1516 name : 'CONTROL' + tagname,
1517 context : 'clipboard',
1523 { class : 'marcControlfieldRow',
1524 tag : '_' + tagname },
1526 { value : field.@tag,
1528 onmouseover : 'getTooltip(this, "tag");',
1529 tooltipid : 'tag' + field.@tag } ),
1531 { value : field.@ind1,
1533 onmouseover : 'getTooltip(this, "ind1");',
1534 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1536 { value : field.@ind2,
1538 onmouseover : 'getTooltip(this, "ind2");',
1539 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1541 { value : field.text(),
1542 class : 'marcControlfield' } )
1549 function stackSubfields(checkbox) {
1550 var list = document.getElementsByAttribute('name','sf_box');
1553 if (!checkbox.checked) o = 'horizontal';
1555 for (var i = 0; i < list.length; i++) {
1556 if (list[i]) list[i].setAttribute('orient',o);
1560 function fastItemAdd_toggle(checkbox) {
1561 var x = document.getElementById('fastItemAdd_textboxes');
1562 if (checkbox.checked) {
1564 document.getElementById('fastItemAdd_callnumber').focus();
1565 document.getElementById('fastItemAdd_callnumber').select();
1571 function fastItemAdd_attempt(doc_id) {
1573 if (typeof window.xulG.fast_add_item != 'function') { return; }
1574 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1575 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1576 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1577 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1578 document.getElementById('fastItemAdd_barcode').value = '';
1580 alert('fastItemAdd_attempt: ' + E);
1584 function save_attempt(xml_string) {
1586 var result = window.xulG.save.func( xml_string );
1588 if (result.id) fastItemAdd_attempt(result.id);
1589 if (typeof result.on_complete == 'function') result.on_complete();
1592 alert('save_attempt: ' + E);
1596 function marcDatafield (field) {
1597 var row = createRow(
1598 { class : 'marcDatafieldRow' },
1601 { value : field.@tag,
1602 class : 'plain marcTag',
1604 context : 'tags_popup',
1605 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1608 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1611 { value : field.@ind1,
1612 class : 'plain marcInd1',
1614 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1617 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1618 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1621 { value : field.@ind2,
1622 class : 'plain marcInd2',
1624 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1627 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1628 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1629 createHbox({ name : 'sf_box' })
1632 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1633 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1634 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1636 var sf_box = row.lastChild;
1637 if (document.getElementById('stackSubfields').checked)
1638 sf_box.setAttribute('orient','vertical');
1640 sf_box.addEventListener(
1643 if (sf_box === e.target) {
1644 sf_box.lastChild.lastChild.focus();
1645 } else if (e.target.parentNode === sf_box) {
1646 e.target.lastChild.focus();
1653 for (var i in field.subfield) {
1654 var sf = field.subfield[i];
1659 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1661 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1662 current_focus = sf_box.lastChild.childNodes[1];
1668 function marcSubfield (sf) {
1670 { class : 'marcSubfieldBox' },
1673 class : 'plain marcSubfieldDelimiter',
1674 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1675 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1676 //onclick : 'this.nextSibling.focus();',
1677 onfocus : 'this.nextSibling.focus();',
1682 class : 'plain marcSubfieldCode',
1683 name : 'marcSubfieldCode',
1684 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1685 oncontextmenu : 'getContextMenu(this, "subfield");',
1686 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1691 { value : sf.text(),
1692 name : sf.parent().@tag + ':' + sf.@code,
1693 class : 'plain marcSubfield',
1694 onmouseover : 'getTooltip(this, "subfield");',
1695 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1696 size : new String(sf.text()).length + 2,
1697 oninput : "this.setAttribute('size', this.value.length + 2);"
1702 function loadRecord(rec) {
1705 var grid_rows = document.getElementById('recGrid').lastChild;
1707 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1709 grid_rows.appendChild( marcLeader( rec.leader ) );
1711 for (var i in rec.controlfield) {
1712 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1715 for (var i in rec.datafield) {
1716 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1719 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1720 changeFFEditor(recordType(rec));
1721 fillFixedFields(rec);
1723 alert('FIXME, MARC Editor, loadRecord: ' + E);
1728 function genToolTips () {
1729 for (var i in bib_data.field) {
1730 var f = bib_data.field[i];
1732 tag_menu.appendChild(
1736 'current_focus.value = "' + f.@tag + '";' +
1737 'var e = document.createEvent("MutationEvents");' +
1738 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1739 'current_focus.inputField.dispatchEvent(e);',
1740 disabled : f.@tag < '010' ? "true" : "false",
1741 tooltiptext : f.description }
1745 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1746 context_menus.appendChild( i1_popup );
1748 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1749 context_menus.appendChild( i2_popup );
1751 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1752 context_menus.appendChild( sf_popup );
1754 tooltip_hash['tag' + f.@tag] = f.description;
1755 for (var j in f.indicator) {
1756 var ind = f.indicator[j];
1757 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1759 if (ind.@position == 1) {
1760 i1_popup.appendChild(
1762 { label : ind.@value,
1764 'current_focus.value = "' + ind.@value + '";' +
1765 'var e = document.createEvent("MutationEvents");' +
1766 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1767 'current_focus.inputField.dispatchEvent(e);',
1768 tooltiptext : ind.description }
1773 if (ind.@position == 2) {
1774 i2_popup.appendChild(
1776 { label : ind.@value,
1778 'current_focus.value = "' + ind.@value + '";' +
1779 'var e = document.createEvent("MutationEvents");' +
1780 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1781 'current_focus.inputField.dispatchEvent(e);',
1782 tooltiptext : ind.description }
1788 for (var j in f.subfield) {
1789 var sf = f.subfield[j];
1790 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1792 sf_popup.appendChild(
1796 'current_focus.value = "' + sf.@code + '";' +
1797 'var e = document.createEvent("MutationEvents");' +
1798 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1799 'current_focus.inputField.dispatchEvent(e);',
1800 tooltiptext : sf.description
1808 function getTooltip (target, type) {
1811 if (type == 'subfield')
1812 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1815 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1818 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1821 tt = 'tag' + target.parentNode.firstChild.value;
1823 if (!document.getElementById( tt )) {
1828 orient : 'vertical',
1829 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1830 class : 'tooltip' },
1831 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1836 target.tooltip = tt;
1840 function getContextMenu (target, type) {
1843 if (type == 'subfield')
1844 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1847 tt = 't' + target.parentNode.firstChild.value + 'i1';
1850 tt = 't' + target.parentNode.firstChild.value + 'i2';
1852 target.setAttribute('context', tt);
1856 var authority_tag_map = {
1857 100 : ['[100,400,500,700]',100],
1858 400 : ['[100,400,500,700]',100],
1859 700 : ['[100,400,500,700]',100],
1860 800 : ['[100,400,500,700]',100],
1861 110 : ['[110,410,510,710]',110],
1862 410 : ['[110,410,510,710]',110],
1863 710 : ['[110,410,510,710]',110],
1864 810 : ['[110,410,510,710]',110],
1865 111 : ['[111,411,511,711]',111],
1866 411 : ['[111,411,511,711]',111],
1867 711 : ['[111,411,511,711]',111],
1868 811 : ['[111,411,511,711]',111],
1869 240 : ['[130,430,530,730]',130],
1870 440 : ['[130,430,530,730]',130],
1871 130 : ['[130,430,530,730]',130],
1872 730 : ['[130,430,530,730]',130],
1873 830 : ['[130,430,530,730]',130],
1874 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1875 630 : ['[130,430,530,730]',130],
1876 648 : ['[148,448,548]',148],
1877 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1878 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1879 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1882 function getAuthorityContextMenu (target, sf) {
1883 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1886 var old = dojo.byId( menu_id );
1888 page = auth_pages[menu_id];
1889 old.parentNode.removeChild(old);
1891 auth_pages[menu_id] = 0;
1894 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1896 sf_popup.addEventListener("popuphiding", function(event) {
1897 if (show_auth_menu) {
1898 show_auth_menu = false;
1899 getAuthorityContextMenu(target, sf);
1900 dojo.byId(menu_id).openPopup();
1904 context_menus.appendChild( sf_popup );
1906 if (!authority_tag_map[sf.parent().@tag]) {
1907 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1908 target.setAttribute('context', 'clipboard');
1912 browseAuthority( sf_popup, menu_id, target, sf, 20, page);
1917 function applyAuthority ( target, ui_sf, e4x_sf ) {
1919 var new_vals = target.getElementsByAttribute('checked','true');
1920 var field = e4x_sf.parent();
1922 for (var i = 0; i < new_vals.length; i++) {
1924 var sf_list = field.subfield;
1925 for (var j in sf_list) {
1927 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1928 sf_list[j] = new_vals[i].getAttribute('value');
1929 new_vals[i].setAttribute('subfield','');
1935 for (var i = 0; i < new_vals.length; i++) {
1936 if (!new_vals[i].getAttribute('subfield')) continue;
1938 var val = new_vals[i].getAttribute('value');
1940 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1941 sf.@code = new_vals[i].getAttribute('subfield');
1943 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1946 var row = marcDatafield( field );
1949 while (node.nodeName != 'row') {
1950 node = node.parentNode;
1953 node.parentNode.replaceChild( row, node );
1959 'a' : { 100 : 'a' },
1960 'd' : { 100 : 'd' },
1961 'e' : { 100 : 'e' },
1965 'a' : { 110 : 'a' },
1969 'a' : { 111 : 'a' },
1973 'a' : { 130 : 'a' },
1977 'a' : { 130 : 'a' },
1981 'a' : { 100 : 'a' },
1985 'a' : { 110 : 'a' },
1989 'a' : { 111 : 'a' },
1993 'a' : { 130 : 'a' },
1994 'n' : { 130 : 'n' },
1998 'a' : { 100 : 'a' },
1999 'd' : { 100 : 'd' },
2000 'q' : { 100 : 'q' },
2004 'a' : { 110 : 'a' },
2008 'a' : { 111 : 'a' },
2009 'c' : { 111 : 'c' },
2013 'a' : { 130 : 'a' },
2017 'a' : { 100 : 'a' },
2021 'a' : { 110 : 'a' },
2025 'a' : { 111 : 'a' },
2029 'a' : { 130 : 'a' },
2033 'a' : { 100 : 'a' },
2034 'd' : { 100 : 'd' },
2035 'q' : { 100 : 'q' },
2036 't' : { 100 : 't' },
2063 'a' : { 110 : 'a' },
2064 'd' : { 110 : 'd' },
2065 't' : { 110 : 't' },
2092 'a' : { 111 : 'a' },
2093 'd' : { 111 : 'd' },
2094 't' : { 111 : 't' },
2121 'a' : { 130 : 'a' },
2125 'a' : { 148 : 'a' },
2126 'v' : { 148 : 'v' },
2127 'x' : { 148 : 'x' },
2128 'y' : { 148 : 'y' },
2132 'a' : { 150 : 'a' },
2133 'b' : { 150 : 'b' },
2160 'a' : { 151 : 'a' },
2187 'a' : { 155 : 'a' },
2215 function validateAuthority (button) {
2216 var grid = document.getElementById('recGrid');
2217 var label = button.getAttribute('label');
2220 var rows = grid.lastChild.childNodes;
2221 for (var i = 0; i < rows.length; i++) {
2223 var tag = row.firstChild;
2225 if (!control_map[tag.value]) continue
2226 button.setAttribute('label', label + ' - ' + tag.value);
2228 var ind1 = tag.nextSibling;
2229 var ind2 = ind1.nextSibling;
2230 var subfields = ind2.nextSibling.childNodes;
2234 for (var j = 0; j < subfields.length; j++) {
2235 var sf = subfields[j];
2236 var sf_code = sf.childNodes[1].value;
2237 var sf_value = sf.childNodes[2].value;
2239 if (!control_map[tag.value][sf_code]) continue;
2242 for (var a_tag in control_map[tag.value][sf_code]) {
2243 if (!tags[a_tag]) tags[a_tag] = [];
2244 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2249 for (var val_tag in tags) {
2250 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2251 var res = new XML( auth_data.responseText );
2252 found = parseInt(res.gw::payload.gw::string.toString());
2256 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2257 for (var j = 0; j < subfields.length; j++) {
2258 var sf = subfields[j];
2260 dojo.removeClass(sf.childNodes[2], 'marcValidated');
2261 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
2263 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
2264 dojo.addClass(sf.childNodes[2], 'marcValidated');
2269 button.setAttribute('label', label);
2275 function validateBibField (tags, searches) {
2276 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2277 url += '¶m="tags"¶m=' + js2JSON(tags);
2278 url += '¶m="searches"¶m=' + js2JSON(searches);
2281 var req = new XMLHttpRequest();
2282 req.open('GET',url,false);
2288 function searchAuthority (term, tag, sf, limit) {
2289 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2290 url += '¶m="term"¶m="' + term + '"';
2291 url += '¶m="limit"¶m=' + limit;
2292 url += '¶m="tag"¶m=' + tag;
2293 url += '¶m="subfield"¶m="' + sf + '"';
2296 var req = new XMLHttpRequest();
2297 req.open('GET',url,false);
2304 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
2305 dojo.require('dojox.xml.parser');
2307 // map tag + subfield to the appropriate authority browse axis:
2308 // currently authority.author, authority.subject, authority.title, authority.topic
2309 // based on mappings in OpenILS::Application::SuperCat
2313 // Map based on replacing the first char of the selected tag with '1'
2314 switch ('1' + (sf.parent().@tag.toString()).substring(1)) {
2316 type = 'authority.title';
2322 type = 'authority.author';
2326 type = 'authority.topic';
2332 type = 'authority.subject';
2335 // No matching tag means no authorities to search - shortcut
2348 var url = '/opac/extras/startwith/marcxml/'
2350 + '/1' // OU - currently unscoped
2351 + '/' + sf.toString()
2356 // would be good to carve this out into a separate function
2357 dojo.xhrGet({"url":url, "sync": true, "preventCache": true, "handleAs":"xml", "load": function(records) {
2358 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
2360 var cm_popup = create_menu.appendChild(
2364 cm_popup.appendChild(
2365 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
2366 command : function() {
2367 // Call middle-layer function to create and save the new authority
2368 var source_f = summarizeField(sf);
2369 var new_auth = fieldmapper.standardRequest(
2370 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
2373 if (new_auth && new_auth.id()) {
2374 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){new_auth.id()}</subfield>;
2375 sf.parent().appendChild(id_sf);
2376 var new_sf = marcSubfield(id_sf);
2377 target.parentNode.appendChild(new_sf);
2378 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2384 cm_popup.appendChild(
2385 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
2386 command : function() {
2387 // Generate the new authority by calling the new middle-layer
2388 // function (a non-saving variant), then display in another
2390 var source_f = summarizeField(sf);
2391 var authtoken = ses();
2392 dojo.require('openils.PermaCrud');
2393 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2394 var rec = fieldmapper.standardRequest(
2395 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
2396 { "params": [source_f] }
2398 loadMarcEditor(pcrud, rec, target, sf);
2403 sf_popup.appendChild(create_menu);
2404 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2406 // append "Previous page" results browser
2407 sf_popup.appendChild(
2408 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
2409 command : function(event) {
2410 auth_pages[menu_id] -= 1;
2411 show_auth_menu = true;
2415 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2417 dojo.query('record', records).forEach(function(record) {
2419 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"] subfield[code="c"]', record)[0]);
2420 var auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
2421 // we have grabbed the fields with tags beginning with 1 or 5 and iterate through the subfields
2422 dojo.query('datafield[tag^="1"], datafield[tag^="5"]', record).forEach(function(field) {
2423 dojo.query('subfield', field).forEach(function(subfield) {
2427 main_text += dojox.xml.parser.textContent(subfield);
2433 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) return;
2436 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
2437 grid.setAttribute('name','-none-');
2438 grid.setAttribute('style','overflow:scroll');
2440 var submenu = createMenu( { label : main_text } );
2442 var popup = createMenuPopup({ flex : "1" });
2443 submenu.appendChild(popup);
2445 dojo.query('datafield[tag^="1"], datafield[tag^="5"]', record).forEach(function(field) {
2446 var row = createRow(
2448 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
2449 createLabel( { "value" : dojo.attr(field, 'ind2') } )
2452 var sf_box = createHbox();
2453 dojo.query('subfield', field).forEach(function(subfield) {
2456 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
2457 "subfield" : dojo.attr(subfield, 'code'),
2458 "tag" : dojo.attr(field, 'tag'),
2459 "value" : dojox.xml.parser.textContent(subfield)
2463 row.appendChild(sf_box);
2466 // Append the authority linking subfield
2469 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
2471 "tag" : dojo.attr(field, 'tag'),
2472 "value" : '(' + auth_org + ')' + auth_id
2476 row.appendChild(sf_box);
2478 grid.lastChild.appendChild(row);
2481 grid.hidden = false;
2482 popup.appendChild( grid );
2486 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
2487 command : function (event) {
2488 applyAuthority(event.target.previousSibling, target, sf);
2495 sf_popup.appendChild( submenu );
2498 if (sf_popup.childNodes.length == 0) {
2499 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
2501 // append "Next page" results browser
2502 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2503 sf_popup.appendChild(
2504 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
2505 command : function(event) {
2506 auth_pages[menu_id] += 1;
2507 show_auth_menu = true;
2513 target.setAttribute('context', menu_id);
2519 function summarizeField(sf) {
2526 for (var i = 0; i < sf.parent().subfield.length(); i++) {
2527 source_f.subfields.push([sf.parent().subfield[i].@code.toString(), sf.parent().subfield[i].toString()]);
2529 source_f.tag = sf.parent().@tag.toString();
2530 source_f.ind1 = sf.parent().@ind1.toString();
2531 source_f.ind1 = sf.parent().@ind2.toString();
2536 function buildBibSourceList (authtoken, recId) {
2537 /* TODO: Work out how to set the bib source of the bre that does not yet
2538 * exist - this is specifically in the case of Z39.50 imports. Right now
2539 * we just avoid populating and showing the config.bib_source list
2545 var bib = xulG.record.bre;
2547 dojo.require('openils.PermaCrud');
2549 // cbsList = the XUL menulist that contains the available bib sources
2550 var cbsList = dojo.byId('bib-source-list');
2552 // bibSources = an array containing all of the bib source objects
2553 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
2555 // A tad ugly, but gives us the index of the bib source ID in cbsList
2557 var cbsListArr = [];
2558 dojo.forEach(bibSources, function (item) {
2559 cbsList.appendItem(item.source(), item.id());
2560 cbsListArr[item.id()] = x;
2564 // Show the current value of the bib source for this record
2565 cbsList.selectedIndex = cbsListArr[bib.source()];
2567 // Display the bib source selection widget
2568 dojo.byId('bib-source-list-caption').hidden = false;
2569 dojo.byId('bib-source-list').hidden = false;
2570 dojo.byId('bib-source-list-button').disabled = true;
2571 dojo.byId('bib-source-list-button').hidden = false;
2574 // Fired when the "Update Source" button is clicked
2575 // Updates the value of the bib source for the current record
2576 function updateBibSource() {
2577 var authtoken = ses();
2578 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2579 var recId = xulG.record.id;
2580 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2581 var bib = pcrud.retrieve('bre', recId);
2582 if (bib.source() != cbs) {
2584 bib.ischanged = true;
2589 function onBibSourceSelect() {
2590 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2591 var bib = xulG.record.bre;
2592 if (bib.source() != cbs) {
2593 dojo.byId('bib-source-list-button').disabled = false;
2595 dojo.byId('bib-source-list-button').disabled = true;
2599 function loadMarcEditor(pcrud, marcxml, target, sf) {
2601 To run in Firefox directly, must set signed.applets.codebase_principal_support
2602 to true in about:config
2604 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
2605 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
2607 // Match marc2are.pl last_xact_id format, roughly
2609 var xact_id = 'IMPORT-' + Date.parse(now);
2612 "record": {"marc": marcxml, "rtype": "are"},
2614 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2615 "func": function(xmlString) {
2616 var rec = new are();
2617 rec.marc(xmlString);
2618 rec.last_xact_id(xact_id);
2621 "oncomplete": function (r, objs) {
2622 var new_rec = objs[0];
2626 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){new_rec.id()}</subfield>;
2627 sf.parent().appendChild(id_sf);
2628 var new_sf = marcSubfield(id_sf);
2629 target.parentNode.appendChild(new_sf);
2630 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));