1 // vim: noet:sw=4:ts=4:
2 var xmlDeclaration = /^<\?xml version[^>]+?>/;
4 var serializer = new XMLSerializer();
5 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
6 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
7 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
8 default xml namespace = marcns;
10 var tooltip_hash = {};
22 function $(id) { return document.getElementById(id); }
24 function mangle_005() {
26 var y = now.getUTCFullYear();
28 var m = now.getUTCMonth() + 1;
29 if (m < 10) m = '0' + m;
31 var d = now.getUTCDate();
32 if (d < 10) d = '0' + d;
34 var H = now.getUTCHours();
35 if (H < 10) H = '0' + H;
37 var M = now.getUTCMinutes();
38 if (M < 10) M = '0' + M;
40 var S = now.getUTCSeconds();
41 if (S < 10) S = '0' + S;
44 var stamp = '' + y + m + d + H + M + S + '.0';
45 createControlField('005',stamp);
49 function createControlField (tag,data) {
50 // first, remove the old field, if any;
51 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
53 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
56 // then, find the right position and insert it
58 var cfields = xml_record.controlfield;
59 var base = Number(tag.substring(2));
60 for (var i in cfields) {
61 var t = Number(cfields[i].@tag.toString().substring(2));
63 xml_record.insertChildBefore( cfields[i], cf );
69 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
74 function xml_escape_unicode ( str ) {
77 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
81 function wrap_long_fields (node) {
82 var text_size = dojo.attr(node, 'size');
84 if (text_size > hard_width) {
85 dojo.attr(node, 'multiline', 'true');
86 dojo.attr(node, 'cols', hard_width);
87 var text_rows = (text_size / hard_width) + 1;
88 dojo.attr(node, 'rows', text_rows);
92 function swap_editors () {
94 dojo.require('MARC.Record');
96 var xe = $('xul-editor');
97 var te = $('text-editor');
99 te.hidden = te.hidden ? false : true;
100 xe.hidden = xe.hidden ? false : true;
103 // get the marcxml from the text box
104 var xml_string = new MARC.Record({
105 marcbreaker : $('text-editor-box').value,
109 // reset the xml record and rerender it
110 xml_record = new XML( xml_string );
111 loadRecord(xml_record);
113 var xml_string = xml_record.toXMLString();
115 // push the xml record into the textbox
116 var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
117 $('text-editor-box').value = rec.toBreaker();
124 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
125 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
126 JSAN.errorLevel = "die"; // none, warn, or die
127 JSAN.addRepository('/xul/server/');
129 // Fake xulG for standalone...
134 window.xulG.record = {};
135 window.xulG.save = {};
137 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
138 window.xulG.save.func = function (r) { alert(r); }
141 var _rid = cgi.param('record');
143 window.xulG.record.id = _rid;
144 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
148 // End faking part...
150 /* Check for an explicitly passed record type
151 * This is not the same as the fixed-field record type; we can't trust
152 * the fixed fields when making modifications to the attributes for a
153 * given record (in particular, config.bib_source only applies for bib
154 * records, but an auth or MFHD record with the same ID and bad fixed
155 * fields could trample the config.bib_source value for the
156 * corresponding bib record if we're not careful.
158 * are = authority record
159 * sre = serial record (MFHD)
160 * bre = bibliographic record
162 if (!window.xulG.record.rtype) {
164 window.xulG.record.rtype = cgi.param('rtype') || false;
167 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
168 document.getElementById('save-button').setAttribute('oncommand',
169 'if ($("xul-editor").hidden) swap_editors(); ' +
171 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
172 'save_attempt( xml_string ); ' +
173 'loadRecord(xml_record);'
176 if (window.xulG.record.url) {
177 var req = new XMLHttpRequest();
178 req.open('POST',window.xulG.record.url,false);
180 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
183 xml_record = new XML( window.xulG.record.marc );
184 if (xml_record..record[0]) xml_record = xml_record..record[0];
186 // Get the tooltip xml all async like
187 req = new XMLHttpRequest();
189 // Set a default locale in case preferences fail us
190 var locale = "en-US";
192 // Try to get the locale from our preferences
193 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
195 const Cc = Components.classes;
196 const Ci = Components.interfaces;
197 locale = Cc["@mozilla.org/preferences-service;1"].
198 getService(Ci.nsIPrefBranch).
199 getCharPref("general.useragent.locale");
203 // TODO: We should send a HEAD request to check for the existence of the desired file
204 // then fall back to the default locale if preferred locale is not necessary;
205 // however, for now we have a simplistic check:
207 // we currently have translations for only two locales; in the absence of a
208 // valid locale, default to the almighty en-US
209 if (locale != 'en-US' && locale != 'fr-CA') {
213 // Get the locale-specific tooltips
214 req.open('GET','/xul/server/locale/' + locale + '/marcedit-tooltips.xml',true);
216 context_menus = createComplexXULElement('popupset');
217 document.documentElement.appendChild( context_menus );
219 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
220 context_menus.appendChild( tag_menu );
222 tag_menu.appendChild(
224 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
226 'var e = document.createEvent("KeyEvents");' +
227 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
228 'current_focus.inputField.dispatchEvent(e);'
233 tag_menu.appendChild(
235 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
237 'var e = document.createEvent("KeyEvents");' +
238 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
239 'current_focus.inputField.dispatchEvent(e);'
244 tag_menu.appendChild(
246 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
248 'var e = document.createEvent("KeyEvents");' +
249 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
250 'current_focus.inputField.dispatchEvent(e);'
255 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
257 tag_menu.appendChild(
259 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
261 'var e = document.createEvent("KeyEvents");' +
262 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
263 'current_focus.inputField.dispatchEvent(e);'
268 tag_menu.appendChild(
270 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
272 'var e = document.createEvent("KeyEvents");' +
273 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
274 'current_focus.inputField.dispatchEvent(e);'
279 tag_menu.appendChild(
281 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
283 'var e = document.createEvent("KeyEvents");' +
284 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
285 'current_focus.inputField.dispatchEvent(e);'
290 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
292 p = createComplexXULElement('popupset');
293 document.documentElement.appendChild( p );
295 req.onreadystatechange = function () {
296 if (req.readyState == 4) {
297 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
303 loadRecord(xml_record);
305 if (! xulG.fast_add_item) {
306 document.getElementById('fastItemAdd_checkbox').hidden = true;
308 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
310 // Only show bib sources for bib records that already exist in the database
311 if (xulG.record.rtype == 'bre' && xulG.record.id) {
312 dojo.require('openils.PermaCrud');
313 var authtoken = ses();
314 // Retrieve the current record attributes
315 var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
317 // Remember the current bib source of the record
318 xulG.record.bre = bib;
320 buildBibSourceList(authtoken, xulG.record.id);
324 alert('FIXME, MARC Editor, my_init: ' + E);
329 function createComplexHTMLElement (e, attrs, objects, text) {
330 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
333 for (var i in attrs) l.setAttribute(i,attrs[i]);
337 for ( var i in objects ) l.appendChild( objects[i] );
341 l.appendChild( document.createTextNode(text) )
347 function createComplexXULElement (e, attrs, objects) {
348 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
351 for (var i in attrs) {
352 if (typeof attrs[i] == 'function') {
353 l.addEventListener( i, attrs[i], true );
355 l.setAttribute(i,attrs[i]);
361 for ( var i in objects ) l.appendChild( objects[i] );
367 function createDescription (attrs) {
368 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
371 function createTooltip (attrs) {
372 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
375 function createLabel (attrs) {
376 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
379 function createVbox (attrs) {
380 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
383 function createHbox (attrs) {
384 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
387 function createRow (attrs) {
388 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
391 function createTextbox (attrs) {
392 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
395 function createMenu (attrs) {
396 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
399 function createMenuPopup (attrs) {
400 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
403 function createPopup (attrs) {
404 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
407 function createMenuitem (attrs) {
408 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
411 function createCheckbox (attrs) {
412 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
415 // Find the next textbox that we can use for a focus point
416 // For control fields, use the first editable text box
417 // For data fields, focus on the first subfield text box
418 function setFocusToNextTag (row, direction) {
419 var keep_looking = true;
420 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
421 // Is it a datafield?
422 dojo.query('hbox hbox textbox', row).forEach(function(node, index, arr) {
424 keep_looking = false;
427 // No, it's a control field; use the first textbox
429 dojo.query('textbox', row).forEach(function(node, index, arr) {
431 keep_looking = false;
440 function createMARCTextbox (element,attrs) {
442 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
443 box.onkeypress = function (event) {
446 while(node = node.parent()) {
450 var row = event.target;
451 while (row.tagName != 'row') row = row.parentNode;
453 if (element.nodeKind() == 'attribute') element[0]=box.value;
454 else element.setChildren( box.value );
456 if (element.localName() != 'controlfield') {
457 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
459 var index_sf, target, move_data;
460 if (element.localName() == 'subfield') {
462 target = event.target.parentNode;
464 var start = event.target.selectionStart;
465 var end = event.target.selectionEnd - event.target.selectionStart ?
466 event.target.selectionEnd :
467 event.target.value.length;
469 move_data = event.target.value.substring(start,end);
470 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
471 event.target.setAttribute('size', event.target.value.length + 2);
473 element.setChildren( event.target.value );
475 } else if (element.localName() == 'code') {
476 index_sf = element.parent();
477 target = event.target.parentNode;
478 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
479 index_sf = element.parent().children()[element.parent().children().length() - 1];
480 target = event.target.parentNode.lastChild.lastChild;
483 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
485 index_sf.parent().insertChildAfter( index_sf, sf );
487 var new_sf = marcSubfield(sf);
489 if (target === target.parentNode.lastChild) {
490 target.parentNode.appendChild( new_sf );
492 target.parentNode.insertBefore( new_sf, target.nextSibling );
495 new_sf.firstChild.nextSibling.focus();
497 event.preventDefault();
500 } else if (event.keyCode == 13 || event.keyCode == 77) {
501 if (event.ctrlKey) { // ctrl+enter
504 if (element.localName() == 'subfield') index = element.parent();
505 if (element.localName() == 'code') index = element.parent().parent();
506 if (element.localName() == 'tag') index = element.parent();
507 if (element.localName() == 'ind1') index = element.parent();
508 if (element.localName() == 'ind2') index = element.parent();
510 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
512 if (event.shiftKey) { // ctrl+shift+enter
513 index.parent().insertChildBefore( index, df );
515 index.parent().insertChildAfter( index, df );
518 var new_df = marcDatafield(df);
520 if (row.parentNode.lastChild === row) {
521 row.parentNode.appendChild( new_df );
523 if (event.shiftKey) { // ctrl+shift+enter
524 row.parentNode.insertBefore( new_df, row );
526 row.parentNode.insertBefore( new_df, row.nextSibling );
530 new_df.firstChild.focus();
532 event.preventDefault();
535 } else if (event.shiftKey) {
536 if (row.previousSibling.className.match('marcDatafieldRow'))
537 row.previousSibling.firstChild.focus();
539 row.nextSibling.firstChild.focus();
542 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
543 if (event.ctrlKey) { // CTRL key: copy the field
545 if (element.localName() == 'subfield') index = element.parent();
546 if (element.localName() == 'code') index = element.parent().parent();
547 if (element.localName() == 'tag') index = element.parent();
548 if (element.localName() == 'ind1') index = element.parent();
549 if (element.localName() == 'ind2') index = element.parent();
551 var copyField = index.copy();
553 if (event.keyCode == 38) { // ctrl+up-arrow
554 index.parent().insertChildBefore( index, copyField );
556 index.parent().insertChildAfter( index, copyField );
559 var new_df = marcDatafield(copyField);
561 if (row.parentNode.lastChild === row) {
562 row.parentNode.appendChild( new_df );
564 if (event.keyCode == 38) { // ctrl+up-arrow
565 row.parentNode.insertBefore( new_df, row );
566 } else { // ctrl+down-arrow
567 row.parentNode.insertBefore( new_df, row.nextSibling );
571 new_df.firstChild.focus();
573 event.preventDefault();
577 if (event.keyCode == 38) {
578 return setFocusToNextTag(row, 'up');
580 if (event.keyCode == 40) {
581 return setFocusToNextTag(row, 'down');
586 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
589 if (element.localName() == 'subfield') index = element.parent();
590 if (element.localName() == 'code') index = element.parent().parent();
591 if (element.localName() == 'tag') index = element.parent();
592 if (element.localName() == 'ind1') index = element.parent();
593 if (element.localName() == 'ind2') index = element.parent();
595 for (var i in index.parent().children()) {
596 if (index === index.parent().children()[i]) {
597 delete index.parent().children()[i];
602 row.previousSibling.firstChild.focus();
603 row.parentNode.removeChild(row);
605 event.preventDefault();
608 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
611 if (element.localName() == 'subfield') index = element;
612 if (element.localName() == 'code') index = element.parent();
615 for (var i in index.parent().children()) {
616 if (index === index.parent().children()[i]) {
617 delete index.parent().children()[i];
622 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
623 event.target.parentNode.previousSibling.lastChild.focus();
625 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
628 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
630 event.preventDefault();
633 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
634 createControlField('006',' ');
635 loadRecord(xml_record);
636 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
637 createControlField('007',' ');
638 loadRecord(xml_record);
639 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
640 createControlField('008',' ');
641 loadRecord(xml_record);
646 } else { // event on a control field
647 if (event.keyCode == 38) {
648 return setFocusToNextTag(row, 'up');
649 } else if (event.keyCode == 40) {
650 return setFocusToNextTag(row, 'down');
655 box.addEventListener(
658 if (element.nodeKind() == 'attribute') element[0]=box.value;
659 else element.setChildren( box.value );
665 box.addEventListener(
668 if (element.nodeKind() == 'attribute') element[0]=box.value;
669 else element.setChildren( box.value );
675 box.addEventListener(
678 if (element.nodeKind() == 'attribute') element[0]=box.value;
679 else element.setChildren( box.value );
685 box.addEventListener(
688 if (element.localName() == 'controlfield')
689 eval('fillFixedFields(xml_record);');
698 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
699 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
700 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
701 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
702 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
703 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
704 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
705 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ },
706 AUT : { Type : /[z]{1}/, BLvl : /.{1}/ },
707 MFHD : { Type : /[uvxy]{1}/, BLvl : /.{1}/ }
713 SCO : {start : 33, len : 1, def : ' ' },
714 REC : {start : 33, len : 1, def : 'n' }
717 SCO : {start : 16, len : 1, def : ' ' },
718 REC : {start : 16, len : 1, def : 'n' }
723 VIS : {start : 33, len : 1, def : ' ' }
726 VIS : {start : 16, len : 1, def : ' ' }
731 VIS : {start : 18, len : 3, def : ' ' }
734 VIS : {start : 1, len : 3, def : ' ' }
739 VIS : {start : 34, len : 1, def : 'n' }
742 VIS : {start : 17, len : 1, def : 'n' }
747 SER : {start : 21, len : 1, def : ' ' }
750 SER : {start : 4, len : 1, def : ' ' }
755 BKS : {start : 39, len : 1, def : 'd' },
756 SER : {start : 39, len : 1, def : 'd' },
757 VIS : {start : 39, len : 1, def : 'd' },
758 MIX : {start : 39, len : 1, def : 'd' },
759 MAP : {start : 39, len : 1, def : 'd' },
760 SCO : {start : 39, len : 1, def : 'd' },
761 REC : {start : 39, len : 1, def : 'd' },
762 COM : {start : 39, len : 1, def : 'd' }
767 MAP : {start : 33, len : 2, def : ' ' }
770 MAP : {start : 16, len : 2, def : ' ' }
775 MAP : {start : 18, len : 4, def : ' ' }
778 MAP : {start : 1, len : 4, def : ' ' }
783 SER : {start : 19, len : 1, def : ' ' }
786 SER : {start : 2, len : 1, def : ' ' }
791 MAP : {start : 22, len : 2, def : ' ' }
794 MAP : {start : 5, len : 2, def : ' ' }
799 SCO : {start : 21, len : 1, def : ' ' },
800 REC : {start : 21, len : 1, def : 'n' }
803 SCO : {start : 4, len : 1, def : ' ' },
804 REC : {start : 4, len : 1, def : 'n' }
809 SER : {start : 22, len : 1, def : ' ' }
812 SER : {start : 5, len : 1, def : ' ' }
817 SCO : {start : 30, len : 2, def : ' ' },
818 REC : {start : 30, len : 2, def : ' ' }
821 SCO : {start : 13, len : 2, def : ' ' },
822 REC : {start : 13, len : 2, def : ' ' }
827 SER : {start : 18, len : 1, def : ' ' }
830 SER : {start : 1, len : 1, def : ' ' }
835 SCO : {start : 20, len : 1, def : ' ' },
836 REC : {start : 20, len : 1, def : 'n' }
839 SCO : {start : 3, len : 1, def : ' ' },
840 REC : {start : 3, len : 1, def : 'n' }
845 COM : {start : 26, len : 1, def : 'u' }
848 COM : {start : 9, len : 1, def : 'u' }
853 SER : {start : 24, len : 1, def : ' ' }
856 SER : {start : 7, len : 1, def : ' ' }
861 SCO : {start : 24, len : 6, def : ' ' },
862 REC : {start : 24, len : 6, def : ' ' }
865 SCO : {start : 7, len : 6, def : ' ' },
866 REC : {start : 7, len : 6, def : ' ' }
871 SCO : {start : 18, len : 2, def : ' ' },
872 REC : {start : 18, len : 2, def : ' ' }
875 SCO : {start : 1, len : 2, def : ' ' },
876 REC : {start : 1, len : 2, def : ' ' }
881 MAP : {start : 25, len : 1, def : ' ' }
884 MAP : {start : 8, len : 1, def : ' ' }
889 BKS : {start : 15, len : 3, def : ' ' },
890 SER : {start : 15, len : 3, def : ' ' },
891 VIS : {start : 15, len : 3, def : ' ' },
892 MIX : {start : 15, len : 3, def : ' ' },
893 MAP : {start : 15, len : 3, def : ' ' },
894 SCO : {start : 15, len : 3, def : ' ' },
895 REC : {start : 15, len : 3, def : ' ' },
896 COM : {start : 15, len : 3, def : ' ' }
901 BKS : {start : 35, len : 3, def : ' ' },
902 SER : {start : 35, len : 3, def : ' ' },
903 VIS : {start : 35, len : 3, def : ' ' },
904 MIX : {start : 35, len : 3, def : ' ' },
905 MAP : {start : 35, len : 3, def : ' ' },
906 SCO : {start : 35, len : 3, def : ' ' },
907 REC : {start : 35, len : 3, def : ' ' },
908 COM : {start : 35, len : 3, def : ' ' }
913 BKS : {start : 38, len : 1, def : ' ' },
914 SER : {start : 38, len : 1, def : ' ' },
915 VIS : {start : 38, len : 1, def : ' ' },
916 MIX : {start : 38, len : 1, def : ' ' },
917 MAP : {start : 38, len : 1, def : ' ' },
918 SCO : {start : 38, len : 1, def : ' ' },
919 REC : {start : 38, len : 1, def : ' ' },
920 COM : {start : 38, len : 1, def : ' ' }
925 BKS : {start : 6, len : 1, def : ' ' },
926 SER : {start : 6, len : 1, def : 'c' },
927 VIS : {start : 6, len : 1, def : ' ' },
928 MIX : {start : 6, len : 1, def : ' ' },
929 MAP : {start : 6, len : 1, def : ' ' },
930 SCO : {start : 6, len : 1, def : ' ' },
931 REC : {start : 6, len : 1, def : ' ' },
932 COM : {start : 6, len : 1, def : ' ' }
937 BKS : {start : 6, len : 1, def : 'a' },
938 SER : {start : 6, len : 1, def : 'a' },
939 VIS : {start : 6, len : 1, def : 'g' },
940 MIX : {start : 6, len : 1, def : 'p' },
941 MAP : {start : 6, len : 1, def : 'e' },
942 SCO : {start : 6, len : 1, def : 'c' },
943 REC : {start : 6, len : 1, def : 'i' },
944 COM : {start : 6, len : 1, def : 'm' },
945 AUT : {start : 6, len : 1, def : 'z' },
946 MFHD : {start : 6, len : 1, def : 'y' }
951 BKS : {start : 8, len : 1, def : ' ' },
952 SER : {start : 8, len : 1, def : ' ' },
953 VIS : {start : 8, len : 1, def : ' ' },
954 MIX : {start : 8, len : 1, def : ' ' },
955 MAP : {start : 8, len : 1, def : ' ' },
956 SCO : {start : 8, len : 1, def : ' ' },
957 REC : {start : 8, len : 1, def : ' ' },
958 COM : {start : 8, len : 1, def : ' ' }
963 BKS : {start : 7, len : 1, def : 'm' },
964 SER : {start : 7, len : 1, def : 's' },
965 VIS : {start : 7, len : 1, def : 'm' },
966 MIX : {start : 7, len : 1, def : 'c' },
967 MAP : {start : 7, len : 1, def : 'm' },
968 SCO : {start : 7, len : 1, def : 'm' },
969 REC : {start : 7, len : 1, def : 'm' },
970 COM : {start : 7, len : 1, def : 'm' }
975 BKS : {start : 18, len : 1, def : ' ' },
976 SER : {start : 18, len : 1, def : ' ' },
977 VIS : {start : 18, len : 1, def : ' ' },
978 MIX : {start : 18, len : 1, def : ' ' },
979 MAP : {start : 18, len : 1, def : ' ' },
980 SCO : {start : 18, len : 1, def : ' ' },
981 REC : {start : 18, len : 1, def : ' ' },
982 COM : {start : 18, len : 1, def : 'i' }
987 MFHD : {start : 18, len : 1, def : 'i' }
992 BKS : {start : 17, len : 1, def : ' ' },
993 SER : {start : 17, len : 1, def : ' ' },
994 VIS : {start : 17, len : 1, def : ' ' },
995 MIX : {start : 17, len : 1, def : ' ' },
996 MAP : {start : 17, len : 1, def : ' ' },
997 SCO : {start : 17, len : 1, def : ' ' },
998 REC : {start : 17, len : 1, def : ' ' },
999 COM : {start : 17, len : 1, def : ' ' },
1000 AUT : {start : 17, len : 1, def : 'n' },
1001 MFHD : {start : 17, len : 1, def : 'u' }
1006 BKS : {start : 31, len : 1, def : '0' },
1007 MAP : {start : 31, len : 1, def : '0' }
1010 BKS : {start : 14, len : 1, def : '0' },
1011 MAP : {start : 14, len : 1, def : '0' }
1016 BKS : {start : 7, len : 4, def : ' ' },
1017 SER : {start : 7, len : 4, def : ' ' },
1018 VIS : {start : 7, len : 4, def : ' ' },
1019 MIX : {start : 7, len : 4, def : ' ' },
1020 MAP : {start : 7, len : 4, def : ' ' },
1021 SCO : {start : 7, len : 4, def : ' ' },
1022 REC : {start : 7, len : 4, def : ' ' },
1023 COM : {start : 7, len : 4, def : ' ' }
1028 BKS : {start : 11, len : 4, def : ' ' },
1029 SER : {start : 11, len : 4, def : '9' },
1030 VIS : {start : 11, len : 4, def : ' ' },
1031 MIX : {start : 11, len : 4, def : ' ' },
1032 MAP : {start : 11, len : 4, def : ' ' },
1033 SCO : {start : 11, len : 4, def : ' ' },
1034 REC : {start : 11, len : 4, def : ' ' },
1035 COM : {start : 11, len : 4, def : ' ' }
1040 BKS : {start : 33, len : 1, def : '0' }
1043 BKS : {start : 16, len : 1, def : '0' }
1048 BKS : {start : 34, len : 1, def : ' ' }
1051 BKS : {start : 17, len : 1, def : ' ' }
1056 BKS : {start : 18, len : 4, def : ' ' }
1059 BKS : {start : 1, len : 4, def : ' ' }
1064 BKS : {start : 30, len : 1, def : '0' }
1067 BKS : {start : 13, len : 1, def : '0' }
1072 BKS : {start : 29, len : 1, def : '0' },
1073 SER : {start : 29, len : 1, def : '0' }
1076 BKS : {start : 12, len : 1, def : '0' },
1077 SER : {start : 12, len : 1, def : '0' }
1082 BKS : {start : 24, len : 4, def : ' ' },
1083 SER : {start : 25, len : 3, def : ' ' }
1086 BKS : {start : 7, len : 4, def : ' ' },
1087 SER : {start : 8, len : 3, def : ' ' }
1092 BKS : {start : 28, len : 1, def : ' ' },
1093 SER : {start : 28, len : 1, def : ' ' },
1094 VIS : {start : 28, len : 1, def : ' ' },
1095 MAP : {start : 28, len : 1, def : ' ' },
1096 COM : {start : 28, len : 1, def : ' ' }
1099 BKS : {start : 11, len : 1, def : ' ' },
1100 SER : {start : 11, len : 1, def : ' ' },
1101 VIS : {start : 11, len : 1, def : ' ' },
1102 MAP : {start : 11, len : 1, def : ' ' },
1103 COM : {start : 11, len : 1, def : ' ' }
1108 BKS : {start : 22, len : 1, def : ' ' },
1109 SER : {start : 22, len : 1, def : ' ' },
1110 VIS : {start : 22, len : 1, def : ' ' },
1111 SCO : {start : 22, len : 1, def : ' ' },
1112 REC : {start : 22, len : 1, def : ' ' },
1113 COM : {start : 22, len : 1, def : ' ' }
1116 BKS : {start : 5, len : 1, def : ' ' },
1117 SER : {start : 5, len : 1, def : ' ' },
1118 VIS : {start : 5, len : 1, def : ' ' },
1119 SCO : {start : 5, len : 1, def : ' ' },
1120 REC : {start : 5, len : 1, def : ' ' },
1121 COM : {start : 5, len : 1, def : ' ' }
1126 BKS : {start : 23, len : 1, def : ' ' },
1127 SER : {start : 23, len : 1, def : ' ' },
1128 VIS : {start : 29, len : 1, def : ' ' },
1129 MIX : {start : 23, len : 1, def : ' ' },
1130 MAP : {start : 29, len : 1, def : ' ' },
1131 SCO : {start : 23, len : 1, def : ' ' },
1132 REC : {start : 23, len : 1, def : ' ' }
1135 BKS : {start : 6, len : 1, def : ' ' },
1136 SER : {start : 6, len : 1, def : ' ' },
1137 VIS : {start : 12, len : 1, def : ' ' },
1138 MIX : {start : 6, len : 1, def : ' ' },
1139 MAP : {start : 12, len : 1, def : ' ' },
1140 SCO : {start : 6, len : 1, def : ' ' },
1141 REC : {start : 6, len : 1, def : ' ' }
1146 SER : {start : 34, len : 1, def : '0' }
1149 SER : {start : 17, len : 1, def : '0' }
1154 SER : {start : 33, len : 1, def : ' ' }
1157 SER : {start : 16, len : 1, def : ' ' }
1162 "AUT" : {"start" : 6, "len" : 1, "def" : ' ' }
1167 "AUT" : {"start" : 7, "len" : 1, "def" : ' ' }
1172 "AUT" : {"start" : 8, "len" : 1, "def" : ' ' }
1177 "AUT" : {"start" : 9, "len" : 1, "def" : ' ' }
1182 "AUT" : {"start" : 10, "len" : 1, "def" : ' ' }
1187 "AUT" : {"start" : 11, "len" : 1, "def" : ' ' }
1192 "AUT" : {"start" : 12, "len" : 1, "def" : ' ' }
1197 "AUT" : {"start" : 13, "len" : 1, "def" : ' ' }
1202 "AUT" : {"start" : 14, "len" : 1, "def" : ' ' }
1207 "AUT" : {"start" : 15, "len" : 1, "def" : ' ' }
1212 "AUT" : {"start" : 16, "len" : 1, "def" : ' ' }
1217 "AUT" : {"start" : 17, "len" : 1, "def" : ' ' }
1222 "AUT" : {"start" : 28, "len" : 1, "def" : ' ' }
1227 "AUT" : {"start" : 29, "len" : 1, "def" : ' ' }
1232 "AUT" : {"start" : 31, "len" : 1, "def" : ' ' }
1237 "AUT" : {"start" : 32, "len" : 1, "def" : ' ' }
1242 "AUT" : {"start" : 33, "len" : 1, "def" : ' ' }
1247 "AUT" : {"start" : 38, "len" : 1, "def" : ' ' }
1252 "AUT" : {"start" : 39, "len" : 1, "def" : ' ' }
1257 function recordType (rec) {
1259 var _l = rec.leader.toString();
1261 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1262 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1264 for (var t in rec_type) {
1265 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1266 document.getElementById('recordTypeLabel').value = t;
1272 // in case we don't have a valid record type ...
1273 _record_type = 'BKS';
1274 return _record_type;
1277 alert('FIXME, MARC Editor, recordType: ' + E);
1281 function toggleFFE () {
1282 var grid = document.getElementById('leaderGrid');
1284 grid.hidden = false;
1291 function changeFFEditor (type) {
1292 var grid = document.getElementById('leaderGrid');
1293 grid.setAttribute('type',type);
1295 // Hide FFEditor rows that we don't need for our current type
1296 // If all of the labels for a given row do not include our
1297 // desired type in their set attribute, we can hide that row
1298 dojo.query('rows row', grid).forEach(function(node, index, arr) {
1299 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
1306 function fillFixedFields (rec) {
1308 var grid = document.getElementById('leaderGrid');
1310 var rtype = _record_type;
1312 var _l = rec.leader.toString();
1313 var _6 = rec.controlfield.(@tag=='006').toString();
1314 var _7 = rec.controlfield.(@tag=='007').toString();
1315 var _8 = rec.controlfield.(@tag=='008').toString();
1318 var pre_list = grid.getElementsByTagName('label');
1319 for (var i in pre_list) {
1320 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1321 list.push( pre_list[i] );
1325 for (var i in list) {
1326 var name = list[i].getAttribute('name');
1332 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1333 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1335 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1336 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1338 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1339 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1341 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1342 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1347 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1348 d = ff_pos[name].ldr[rtype].def;
1352 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1353 d = ff_pos[name]._8[rtype].def;
1357 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1358 d = ff_pos[name]._6[rtype].def;
1362 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1363 d = ff_pos[name]._7[rtype].def;
1368 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1374 list[i].nextSibling.value = value;
1379 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1383 function updateFixedFields (element) {
1384 var grid = document.getElementById('leaderGrid');
1385 var recGrid = document.getElementById('recGrid');
1387 var rtype = _record_type;
1388 var new_value = element.value;
1391 ldr : _record.leader,
1392 _6 : _record.controlfield.(@tag=='006'),
1393 _7 : _record.controlfield.(@tag=='007'),
1394 _8 : _record.controlfield.(@tag=='008')
1397 var name = element.getAttribute('name');
1398 for (var i in ff_pos[name]) {
1400 if (!ff_pos[name][i][rtype]) continue;
1402 // we're missing the required field. Add it now.
1405 if (i == '_6') newfield = '006';
1406 else if (i == '_7') newfield = '007';
1407 else if (i == '_8') newfield = '008';
1410 createControlField(newfield,' ');
1411 parts[i] = _record.controlfield.(@tag==newfield);
1414 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1415 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1417 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1418 new_value += ff_pos[name][i][rtype].def;
1421 parts[i].setChildren( before + new_value + after );
1422 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1428 function marcLeader (leader) {
1429 var row = createRow(
1430 { class : 'marcLeaderRow',
1435 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1438 class : 'marcInd1' } ),
1441 class : 'marcInd2' } ),
1443 { value : leader.text(),
1444 class : 'marcLeader' } )
1450 function marcControlfield (field) {
1451 tagname = field.@tag.toString().substr(2);
1453 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1455 { class : 'marcControlfieldRow',
1456 tag : '_' + tagname },
1458 { value : field.@tag,
1460 context : 'tags_popup',
1461 onmouseover : 'getTooltip(this, "tag");',
1462 tooltipid : 'tag' + field.@tag } ),
1464 { value : field.@ind1,
1466 onmouseover : 'getTooltip(this, "ind1");',
1467 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1469 { value : field.@ind2,
1471 onmouseover : 'getTooltip(this, "ind2");',
1472 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1475 { value : field.text(),
1476 class : 'plain marcEditableControlfield',
1477 name : 'CONTROL' + tagname,
1478 context : 'clipboard',
1484 { class : 'marcControlfieldRow',
1485 tag : '_' + tagname },
1487 { value : field.@tag,
1489 onmouseover : 'getTooltip(this, "tag");',
1490 tooltipid : 'tag' + field.@tag } ),
1492 { value : field.@ind1,
1494 onmouseover : 'getTooltip(this, "ind1");',
1495 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1497 { value : field.@ind2,
1499 onmouseover : 'getTooltip(this, "ind2");',
1500 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1502 { value : field.text(),
1503 class : 'marcControlfield' } )
1510 function stackSubfields(checkbox) {
1511 var list = document.getElementsByAttribute('name','sf_box');
1514 if (!checkbox.checked) o = 'horizontal';
1516 for (var i = 0; i < list.length; i++) {
1517 if (list[i]) list[i].setAttribute('orient',o);
1521 function fastItemAdd_toggle(checkbox) {
1522 var x = document.getElementById('fastItemAdd_textboxes');
1523 if (checkbox.checked) {
1525 document.getElementById('fastItemAdd_callnumber').focus();
1526 document.getElementById('fastItemAdd_callnumber').select();
1532 function fastItemAdd_attempt(doc_id) {
1534 if (typeof window.xulG.fast_add_item != 'function') { return; }
1535 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1536 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1537 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1538 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1539 document.getElementById('fastItemAdd_barcode').value = '';
1541 alert('fastItemAdd_attempt: ' + E);
1545 function save_attempt(xml_string) {
1547 var result = window.xulG.save.func( xml_string );
1549 if (result.id) fastItemAdd_attempt(result.id);
1550 if (typeof result.on_complete == 'function') result.on_complete();
1553 alert('save_attempt: ' + E);
1557 function marcDatafield (field) {
1558 var row = createRow(
1559 { class : 'marcDatafieldRow' },
1562 { value : field.@tag,
1563 class : 'plain marcTag',
1565 context : 'tags_popup',
1566 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1569 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1572 { value : field.@ind1,
1573 class : 'plain marcInd1',
1575 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1578 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1579 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1582 { value : field.@ind2,
1583 class : 'plain marcInd2',
1585 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1588 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1589 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1590 createHbox({ name : 'sf_box' })
1593 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1594 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1595 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1597 var sf_box = row.lastChild;
1598 if (document.getElementById('stackSubfields').checked)
1599 sf_box.setAttribute('orient','vertical');
1601 sf_box.addEventListener(
1604 if (sf_box === e.target) {
1605 sf_box.lastChild.lastChild.focus();
1606 } else if (e.target.parentNode === sf_box) {
1607 e.target.lastChild.focus();
1614 for (var i in field.subfield) {
1615 var sf = field.subfield[i];
1620 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1622 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1623 current_focus = sf_box.lastChild.childNodes[1];
1629 function marcSubfield (sf) {
1631 { class : 'marcSubfieldBox' },
1634 class : 'plain marcSubfieldDelimiter',
1635 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1636 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1637 //onclick : 'this.nextSibling.focus();',
1638 onfocus : 'this.nextSibling.focus();',
1643 class : 'plain marcSubfieldCode',
1644 name : 'marcSubfieldCode',
1645 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1646 oncontextmenu : 'getContextMenu(this, "subfield");',
1647 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1652 { value : sf.text(),
1653 name : sf.parent().@tag + ':' + sf.@code,
1654 class : 'plain marcSubfield',
1655 onmouseover : 'getTooltip(this, "subfield");',
1656 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1657 size : new String(sf.text()).length + 2,
1658 oninput : "this.setAttribute('size', this.value.length + 2);"
1663 function loadRecord(rec) {
1666 var grid_rows = document.getElementById('recGrid').lastChild;
1668 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1670 grid_rows.appendChild( marcLeader( rec.leader ) );
1672 for (var i in rec.controlfield) {
1673 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1676 for (var i in rec.datafield) {
1677 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1680 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1681 changeFFEditor(recordType(rec));
1682 fillFixedFields(rec);
1684 alert('FIXME, MARC Editor, loadRecord: ' + E);
1689 function genToolTips () {
1690 for (var i in bib_data.field) {
1691 var f = bib_data.field[i];
1693 tag_menu.appendChild(
1697 'current_focus.value = "' + f.@tag + '";' +
1698 'var e = document.createEvent("MutationEvents");' +
1699 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1700 'current_focus.inputField.dispatchEvent(e);',
1701 disabled : f.@tag < '010' ? "true" : "false",
1702 tooltiptext : f.description }
1706 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1707 context_menus.appendChild( i1_popup );
1709 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1710 context_menus.appendChild( i2_popup );
1712 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1713 context_menus.appendChild( sf_popup );
1715 tooltip_hash['tag' + f.@tag] = f.description;
1716 for (var j in f.indicator) {
1717 var ind = f.indicator[j];
1718 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1720 if (ind.@position == 1) {
1721 i1_popup.appendChild(
1723 { label : ind.@value,
1725 'current_focus.value = "' + ind.@value + '";' +
1726 'var e = document.createEvent("MutationEvents");' +
1727 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1728 'current_focus.inputField.dispatchEvent(e);',
1729 tooltiptext : ind.description }
1734 if (ind.@position == 2) {
1735 i2_popup.appendChild(
1737 { label : ind.@value,
1739 'current_focus.value = "' + ind.@value + '";' +
1740 'var e = document.createEvent("MutationEvents");' +
1741 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1742 'current_focus.inputField.dispatchEvent(e);',
1743 tooltiptext : ind.description }
1749 for (var j in f.subfield) {
1750 var sf = f.subfield[j];
1751 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1753 sf_popup.appendChild(
1757 'current_focus.value = "' + sf.@code + '";' +
1758 'var e = document.createEvent("MutationEvents");' +
1759 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1760 'current_focus.inputField.dispatchEvent(e);',
1761 tooltiptext : sf.description
1769 function getTooltip (target, type) {
1772 if (type == 'subfield')
1773 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1776 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1779 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1782 tt = 'tag' + target.parentNode.firstChild.value;
1784 if (!document.getElementById( tt )) {
1789 orient : 'vertical',
1790 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1791 class : 'tooltip' },
1792 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1797 target.tooltip = tt;
1801 function getContextMenu (target, type) {
1804 if (type == 'subfield')
1805 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1808 tt = 't' + target.parentNode.firstChild.value + 'i1';
1811 tt = 't' + target.parentNode.firstChild.value + 'i2';
1813 target.setAttribute('context', tt);
1817 var authority_tag_map = {
1818 100 : ['[100,400,500,700]',100],
1819 400 : ['[100,400,500,700]',100],
1820 700 : ['[100,400,500,700]',100],
1821 800 : ['[100,400,500,700]',100],
1822 110 : ['[110,410,510,710]',110],
1823 410 : ['[110,410,510,710]',110],
1824 710 : ['[110,410,510,710]',110],
1825 810 : ['[110,410,510,710]',110],
1826 111 : ['[111,411,511,711]',111],
1827 411 : ['[111,411,511,711]',111],
1828 711 : ['[111,411,511,711]',111],
1829 811 : ['[111,411,511,711]',111],
1830 240 : ['[130,430,530,730]',130],
1831 440 : ['[130,430,530,730]',130],
1832 130 : ['[130,430,530,730]',130],
1833 730 : ['[130,430,530,730]',130],
1834 830 : ['[130,430,530,730]',130],
1835 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1836 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1837 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1838 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1841 function getAuthorityContextMenu (target, sf) {
1842 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1844 var old = document.getElementById( menu_id );
1845 if (old) old.parentNode.removeChild(old);
1847 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1848 context_menus.appendChild( sf_popup );
1850 if (!authority_tag_map[sf.parent().@tag]) {
1851 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1852 target.setAttribute('context', 'clipboard');
1856 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1858 var res = new XML( auth_data.responseText );
1862 var recs = res.gw::payload.gw::array.gw::string;
1863 for (var i in recs) {
1865 var xml = new XML(x.toString());
1866 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1868 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1871 for (var i in main) {
1872 if (main_text) main_text += ' / ';
1873 main_text += main[i];
1876 rec_list.push( [ main_text, xml ] );
1879 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1881 var main_text = rec_list[i][0];
1882 var xml = rec_list[i][1];
1883 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1885 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1887 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1888 grid.setAttribute('name','-none-');
1889 grid.setAttribute('style','overflow:scroll');
1892 var submenu = createMenu( { label : main_text } );
1894 var popup = createMenuPopup({ flex : "1" });
1895 submenu.appendChild(popup);
1897 var fields = xml.datafield;
1898 for (var j in fields) {
1900 /* Restrict options to Heading Information fields (1xx)
1901 * and See Also From fields (5xx) rather than displaying
1902 * every field in the authority record */
1903 var tag = fields[j].@tag;
1904 if (tag.substr(0,1) != 1 && tag.substr(0,1) != 5) {
1908 var row = createRow(
1910 createLabel( { "value" : tag } ),
1911 createLabel( { "value" : fields[j].@ind1 } ),
1912 createLabel( { "value" : fields[j].@ind2 } )
1915 var sf_box = createHbox();
1917 var subfields = fields[j].subfield;
1918 for (var k in subfields) {
1921 { "label" : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1922 "subfield" : subfields[k].@code,
1923 "tag" : subfields[k].parent().@tag,
1924 "value" : subfields[k]
1928 row.appendChild(sf_box);
1931 grid.lastChild.appendChild(row);
1934 grid.hidden = false;
1935 popup.appendChild( grid );
1939 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1940 command : function (event) {
1941 applyAuthority(event.target.previousSibling, target, sf);
1948 sf_popup.appendChild( submenu );
1951 if (sf_popup.childNodes.length == 0)
1952 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1954 target.setAttribute('context', menu_id);
1958 function applyAuthority ( target, ui_sf, e4x_sf ) {
1960 var new_vals = target.getElementsByAttribute('checked','true');
1961 var field = e4x_sf.parent();
1963 for (var i = 0; i < new_vals.length; i++) {
1965 var sf_list = field.subfield;
1966 for (var j in sf_list) {
1968 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1969 sf_list[j] = new_vals[i].getAttribute('value');
1970 new_vals[i].setAttribute('subfield','');
1976 for (var i = 0; i < new_vals.length; i++) {
1977 if (!new_vals[i].getAttribute('subfield')) continue;
1979 var val = new_vals[i].getAttribute('value');
1981 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1982 sf.@code = new_vals[i].getAttribute('subfield');
1984 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1987 var row = marcDatafield( field );
1990 while (node.nodeName != 'row') {
1991 node = node.parentNode;
1994 node.parentNode.replaceChild( row, node );
2000 'a' : { 100 : 'a' },
2001 'd' : { 100 : 'd' },
2002 'e' : { 100 : 'e' },
2006 'a' : { 110 : 'a' },
2010 'a' : { 111 : 'a' },
2014 'a' : { 130 : 'a' },
2018 'a' : { 130 : 'a' },
2022 'a' : { 100 : 'a' },
2026 'a' : { 110 : 'a' },
2030 'a' : { 111 : 'a' },
2034 'a' : { 130 : 'a' },
2035 'n' : { 130 : 'n' },
2039 'a' : { 100 : 'a' },
2040 'd' : { 100 : 'd' },
2041 'q' : { 100 : 'q' },
2045 'a' : { 110 : 'a' },
2049 'a' : { 111 : 'a' },
2050 'c' : { 111 : 'c' },
2054 'a' : { 130 : 'a' },
2058 'a' : { 100 : 'a' },
2062 'a' : { 110 : 'a' },
2066 'a' : { 111 : 'a' },
2070 'a' : { 130 : 'a' },
2074 'a' : { 100 : 'a' },
2075 'd' : { 100 : 'd' },
2076 'q' : { 100 : 'q' },
2077 't' : { 100 : 't' },
2104 'a' : { 110 : 'a' },
2105 'd' : { 110 : 'd' },
2106 't' : { 110 : 't' },
2133 'a' : { 111 : 'a' },
2134 'd' : { 111 : 'd' },
2135 't' : { 111 : 't' },
2162 'a' : { 130 : 'a' },
2166 'a' : { 150 : 'a' },
2167 'b' : { 150 : 'b' },
2194 'a' : { 151 : 'a' },
2221 'a' : { 155 : 'a' },
2249 function validateAuthority (button) {
2250 var grid = document.getElementById('recGrid');
2251 var label = button.getAttribute('label');
2254 var rows = grid.lastChild.childNodes;
2255 for (var i = 0; i < rows.length; i++) {
2257 var tag = row.firstChild;
2259 if (!control_map[tag.value]) continue
2260 button.setAttribute('label', label + ' - ' + tag.value);
2262 var ind1 = tag.nextSibling;
2263 var ind2 = ind1.nextSibling;
2264 var subfields = ind2.nextSibling.childNodes;
2268 for (var j = 0; j < subfields.length; j++) {
2269 var sf = subfields[j];
2270 var sf_code = sf.childNodes[1].value;
2271 var sf_value = sf.childNodes[2].value;
2273 if (!control_map[tag.value][sf_code]) continue;
2276 for (var a_tag in control_map[tag.value][sf_code]) {
2277 if (!tags[a_tag]) tags[a_tag] = [];
2278 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2283 for (var val_tag in tags) {
2284 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2285 var res = new XML( auth_data.responseText );
2286 found = parseInt(res.gw::payload.gw::string.toString());
2290 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2291 for (var j = 0; j < subfields.length; j++) {
2292 var sf = subfields[j];
2294 dojo.removeClass(sf.childNodes[2], 'marcValidated');
2295 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
2297 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
2298 dojo.addClass(sf.childNodes[2], 'marcValidated');
2303 button.setAttribute('label', label);
2309 function validateBibField (tags, searches) {
2310 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2311 url += '¶m="tags"¶m=' + js2JSON(tags);
2312 url += '¶m="searches"¶m=' + js2JSON(searches);
2315 var req = new XMLHttpRequest();
2316 req.open('GET',url,false);
2322 function searchAuthority (term, tag, sf, limit) {
2323 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2324 url += '¶m="term"¶m="' + term + '"';
2325 url += '¶m="limit"¶m=' + limit;
2326 url += '¶m="tag"¶m=' + tag;
2327 url += '¶m="subfield"¶m="' + sf + '"';
2330 var req = new XMLHttpRequest();
2331 req.open('GET',url,false);
2338 function buildBibSourceList (authtoken, recId) {
2339 /* TODO: Work out how to set the bib source of the bre that does not yet
2340 * exist - this is specifically in the case of Z39.50 imports. Right now
2341 * we just avoid populating and showing the config.bib_source list
2347 var bib = xulG.record.bre;
2349 dojo.require('openils.PermaCrud');
2351 // cbsList = the XUL menulist that contains the available bib sources
2352 var cbsList = dojo.byId('bib-source-list');
2354 // bibSources = an array containing all of the bib source objects
2355 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
2357 // A tad ugly, but gives us the index of the bib source ID in cbsList
2359 var cbsListArr = [];
2360 dojo.forEach(bibSources, function (item) {
2361 cbsList.appendItem(item.source(), item.id());
2362 cbsListArr[item.id()] = x;
2366 // Show the current value of the bib source for this record
2367 cbsList.selectedIndex = cbsListArr[bib.source()];
2369 // Display the bib source selection widget
2370 dojo.byId('bib-source-list-caption').hidden = false;
2371 dojo.byId('bib-source-list').hidden = false;
2372 dojo.byId('bib-source-list-button').disabled = true;
2373 dojo.byId('bib-source-list-button').hidden = false;
2376 // Fired when the "Update Source" button is clicked
2377 // Updates the value of the bib source for the current record
2378 function updateBibSource() {
2379 var authtoken = ses();
2380 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2381 var recId = xulG.record.id;
2382 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2383 var bib = pcrud.retrieve('bre', recId);
2384 if (bib.source() != cbs) {
2386 bib.ischanged = true;
2391 function onBibSourceSelect() {
2392 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2393 var bib = xulG.record.bre;
2394 if (bib.source() != cbs) {
2395 dojo.byId('bib-source-list-button').disabled = false;
2397 dojo.byId('bib-source-list-button').disabled = true;