3 * Copyright (C) 2004-2008 Georgia Public Library Service
4 * Copyright (C) 2008-2010 Equinox Software, Inc.
5 * Mike Rylander <miker@esilibrary.com>
7 * Copyright (C) 2010 Dan Scott <dan@coffeecode.net>
8 * Copyright (C) 2010 Internationaal Instituut voor Sociale Geschiedenis <info@iisg.nl>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 var xmlDeclaration = /^<\?xml version[^>]+?>/;
23 var serializer = new XMLSerializer();
24 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
25 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
26 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
27 default xml namespace = marcns;
29 var tooltip_hash = {};
41 var show_auth_menu = false;
43 function $(id) { return document.getElementById(id); }
45 function mangle_005() {
47 var y = now.getUTCFullYear();
49 var m = now.getUTCMonth() + 1;
50 if (m < 10) m = '0' + m;
52 var d = now.getUTCDate();
53 if (d < 10) d = '0' + d;
55 var H = now.getUTCHours();
56 if (H < 10) H = '0' + H;
58 var M = now.getUTCMinutes();
59 if (M < 10) M = '0' + M;
61 var S = now.getUTCSeconds();
62 if (S < 10) S = '0' + S;
65 var stamp = '' + y + m + d + H + M + S + '.0';
66 createControlField('005',stamp);
70 function createControlField (tag,data) {
71 // first, remove the old field, if any;
72 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
74 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
77 // then, find the right position and insert it
79 var cfields = xml_record.controlfield;
80 var base = Number(tag.substring(2));
81 for (var i in cfields) {
82 var t = Number(cfields[i].@tag.toString().substring(2));
84 xml_record.insertChildBefore( cfields[i], cf );
90 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
95 function xml_escape_unicode ( str ) {
98 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
102 function wrap_long_fields (node) {
103 var text_size = dojo.attr(node, 'size');
104 var hard_width = 100;
105 if (text_size > hard_width) {
106 dojo.attr(node, 'multiline', 'true');
107 dojo.attr(node, 'cols', hard_width);
108 var text_rows = (text_size / hard_width) + 1;
109 dojo.attr(node, 'rows', text_rows);
113 function set_flat_editor (useFlatText) {
115 dojo.require('MARC.Record');
117 var xe = $('xul-editor');
118 var te = $('text-editor');
121 if (xe.hidden) { return; }
125 if (te.hidden) { return; }
131 // get the marcxml from the text box
132 var xml_string = new MARC.Record({
133 marcbreaker : $('text-editor-box').value,
137 // reset the xml record and rerender it
138 xml_record = new XML( xml_string );
139 loadRecord(xml_record);
141 var xml_string = xml_record.toXMLString();
143 // push the xml record into the textbox
144 var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
145 $('text-editor-box').value = rec.toBreaker();
152 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
153 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
154 JSAN.errorLevel = "die"; // none, warn, or die
155 JSAN.addRepository('/xul/server/');
157 // Fake xulG for standalone...
162 window.xulG.record = {};
163 window.xulG.save = {};
164 window.xulG.marc_control_number_identifier = 'CONS';
166 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
167 window.xulG.save.func = function (r) { alert(r); }
170 var _rid = cgi.param('record');
172 window.xulG.record.id = _rid;
173 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
177 // End faking part...
179 /* Check for an explicitly passed record type
180 * This is not the same as the fixed-field record type; we can't trust
181 * the fixed fields when making modifications to the attributes for a
182 * given record (in particular, config.bib_source only applies for bib
183 * records, but an auth or MFHD record with the same ID and bad fixed
184 * fields could trample the config.bib_source value for the
185 * corresponding bib record if we're not careful.
187 * are = authority record
188 * sre = serial record (MFHD)
189 * bre = bibliographic record
191 if (!window.xulG.record.rtype) {
193 window.xulG.record.rtype = cgi.param('rtype') || false;
196 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
197 document.getElementById('save-button').setAttribute('oncommand',
198 'if ($("xul-editor").hidden) set_flat_editor(false); ' +
200 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
201 'save_attempt( xml_string ); ' +
202 'loadRecord(xml_record);'
205 if (window.xulG.record.url) {
206 var req = new XMLHttpRequest();
207 req.open('POST',window.xulG.record.url,false);
209 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
212 xml_record = new XML( window.xulG.record.marc );
213 if (xml_record..record[0]) xml_record = xml_record..record[0];
215 // Get the tooltip xml all async like
216 req = new XMLHttpRequest();
218 // Set a default locale in case preferences fail us
219 var locale = "en-US";
221 // Try to get the locale from our preferences
222 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
224 const Cc = Components.classes;
225 const Ci = Components.interfaces;
226 locale = Cc["@mozilla.org/preferences-service;1"].
227 getService(Ci.nsIPrefBranch).
228 getCharPref("general.useragent.locale");
232 // TODO: We should send a HEAD request to check for the existence of the desired file
233 // then fall back to the default locale if preferred locale is not necessary;
234 // however, for now we have a simplistic check:
236 // we currently have translations for only two locales; in the absence of a
237 // valid locale, default to the almighty en-US
238 if (locale != 'en-US' && locale != 'fr-CA') {
242 // grab the right tooltip based on MARC type
243 var tooltip_doc = 'marcedit-tooltips.xml';
244 switch (window.xulG.record.rtype) {
246 tooltip_doc = 'marcedit-tooltips.xml';
249 tooltip_doc = 'marcedit-tooltips-authority.xml';
250 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
253 tooltip_doc = 'marcedit-tooltips-mfhd.xml';
254 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
257 tooltip_doc = 'marcedit-tooltips.xml';
260 // Get the locale-specific tooltips
261 req.open('GET','/xul/server/locale/' + locale + '/' + tooltip_doc,true);
263 context_menus = createComplexXULElement('popupset');
264 document.documentElement.appendChild( context_menus );
266 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
267 context_menus.appendChild( tag_menu );
269 tag_menu.appendChild(
271 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
273 'var e = document.createEvent("KeyEvents");' +
274 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
275 'current_focus.inputField.dispatchEvent(e);'
280 tag_menu.appendChild(
282 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
284 'var e = document.createEvent("KeyEvents");' +
285 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
286 'current_focus.inputField.dispatchEvent(e);'
291 tag_menu.appendChild(
293 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
295 'var e = document.createEvent("KeyEvents");' +
296 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
297 'current_focus.inputField.dispatchEvent(e);'
302 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
304 tag_menu.appendChild(
306 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
308 'var e = document.createEvent("KeyEvents");' +
309 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
310 'current_focus.inputField.dispatchEvent(e);'
315 tag_menu.appendChild(
317 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
319 'var e = document.createEvent("KeyEvents");' +
320 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
321 'current_focus.inputField.dispatchEvent(e);'
326 tag_menu.appendChild(
328 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
330 'var e = document.createEvent("KeyEvents");' +
331 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
332 'current_focus.inputField.dispatchEvent(e);'
337 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
339 p = createComplexXULElement('popupset');
340 document.documentElement.appendChild( p );
342 req.onreadystatechange = function () {
343 if (req.readyState == 4) {
344 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
350 loadRecord(xml_record);
352 if (! xulG.fast_add_item) {
353 document.getElementById('fastItemAdd_checkbox').hidden = true;
355 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
357 // Only show bib sources for bib records that already exist in the database
358 if (xulG.record.rtype == 'bre' && xulG.record.id) {
359 dojo.require('openils.PermaCrud');
360 var authtoken = ses();
361 // Retrieve the current record attributes
362 var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
364 // Remember the current bib source of the record
365 xulG.record.bre = bib;
367 buildBibSourceList(authtoken, xulG.record.id);
371 alert('FIXME, MARC Editor, my_init: ' + E);
376 function createComplexHTMLElement (e, attrs, objects, text) {
377 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
380 for (var i in attrs) l.setAttribute(i,attrs[i]);
384 for ( var i in objects ) l.appendChild( objects[i] );
388 l.appendChild( document.createTextNode(text) )
394 function createComplexXULElement (e, attrs, objects) {
395 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
398 for (var i in attrs) {
399 if (typeof attrs[i] == 'function') {
400 l.addEventListener( i, attrs[i], true );
402 l.setAttribute(i,attrs[i]);
408 for ( var i in objects ) l.appendChild( objects[i] );
414 function createDescription (attrs) {
415 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
418 function createTooltip (attrs) {
419 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
422 function createLabel (attrs) {
423 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
426 function createVbox (attrs) {
427 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
430 function createHbox (attrs) {
431 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
434 function createRow (attrs) {
435 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
438 function createTextbox (attrs) {
439 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
442 function createMenu (attrs) {
443 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
446 function createMenuPopup (attrs) {
447 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
450 function createPopup (attrs) {
451 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
454 function createMenuitem (attrs) {
455 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
458 function createCheckbox (attrs) {
459 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
462 // Find the next textbox that we can use for a focus point
463 // For control fields, use the first editable text box
464 // For data fields, focus on the first subfield text box
465 function setFocusToNextTag (row, direction) {
466 var keep_looking = true;
467 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
468 // Is it a datafield?
469 dojo.query('hbox hbox textbox', row).forEach(function(node, index, arr) {
471 keep_looking = false;
474 // No, it's a control field; use the first textbox
476 dojo.query('textbox', row).forEach(function(node, index, arr) {
478 keep_looking = false;
487 function createMARCTextbox (element,attrs) {
489 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
490 box.addEventListener('change',function(ev) { oils_lock_page(); },false);
491 box.onkeypress = function (event) {
494 while(node = node.parent()) {
498 var row = event.target;
499 while (row.tagName != 'row') row = row.parentNode;
501 if (element.nodeKind() == 'attribute') element[0]=box.value;
502 else element.setChildren( box.value );
504 if (element.localName() != 'controlfield') {
505 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
507 var index_sf, target, move_data;
508 if (element.localName() == 'subfield') {
510 target = event.target.parentNode;
512 var start = event.target.selectionStart;
513 var end = event.target.selectionEnd - event.target.selectionStart ?
514 event.target.selectionEnd :
515 event.target.value.length;
517 move_data = event.target.value.substring(start,end);
518 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
519 event.target.setAttribute('size', event.target.value.length + 2);
521 element.setChildren( event.target.value );
523 } else if (element.localName() == 'code') {
524 index_sf = element.parent();
525 target = event.target.parentNode;
526 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
527 index_sf = element.parent().children()[element.parent().children().length() - 1];
528 target = event.target.parentNode.lastChild.lastChild;
531 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
533 index_sf.parent().insertChildAfter( index_sf, sf );
535 var new_sf = marcSubfield(sf);
537 if (target === target.parentNode.lastChild) {
538 target.parentNode.appendChild( new_sf );
540 target.parentNode.insertBefore( new_sf, target.nextSibling );
543 new_sf.firstChild.nextSibling.focus();
545 event.preventDefault();
548 } else if (event.keyCode == 13 || event.keyCode == 77) {
549 if (event.ctrlKey) { // ctrl+enter
552 if (element.localName() == 'subfield') index = element.parent();
553 if (element.localName() == 'code') index = element.parent().parent();
554 if (element.localName() == 'tag') index = element.parent();
555 if (element.localName() == 'ind1') index = element.parent();
556 if (element.localName() == 'ind2') index = element.parent();
558 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
560 if (event.shiftKey) { // ctrl+shift+enter
561 index.parent().insertChildBefore( index, df );
563 index.parent().insertChildAfter( index, df );
566 var new_df = marcDatafield(df);
568 if (row.parentNode.lastChild === row) {
569 row.parentNode.appendChild( new_df );
571 if (event.shiftKey) { // ctrl+shift+enter
572 row.parentNode.insertBefore( new_df, row );
574 row.parentNode.insertBefore( new_df, row.nextSibling );
578 new_df.firstChild.focus();
580 event.preventDefault();
583 } else if (event.shiftKey) {
584 if (row.previousSibling.className.match('marcDatafieldRow'))
585 row.previousSibling.firstChild.focus();
587 row.nextSibling.firstChild.focus();
590 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
591 if (event.ctrlKey) { // CTRL key: copy the field
593 if (element.localName() == 'subfield') index = element.parent();
594 if (element.localName() == 'code') index = element.parent().parent();
595 if (element.localName() == 'tag') index = element.parent();
596 if (element.localName() == 'ind1') index = element.parent();
597 if (element.localName() == 'ind2') index = element.parent();
599 var copyField = index.copy();
601 if (event.keyCode == 38) { // ctrl+up-arrow
602 index.parent().insertChildBefore( index, copyField );
604 index.parent().insertChildAfter( index, copyField );
607 var new_df = marcDatafield(copyField);
609 if (row.parentNode.lastChild === row) {
610 row.parentNode.appendChild( new_df );
612 if (event.keyCode == 38) { // ctrl+up-arrow
613 row.parentNode.insertBefore( new_df, row );
614 } else { // ctrl+down-arrow
615 row.parentNode.insertBefore( new_df, row.nextSibling );
619 new_df.firstChild.focus();
621 event.preventDefault();
625 if (event.keyCode == 38) {
626 return setFocusToNextTag(row, 'up');
628 if (event.keyCode == 40) {
629 return setFocusToNextTag(row, 'down');
634 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
637 if (element.localName() == 'subfield') index = element.parent();
638 if (element.localName() == 'code') index = element.parent().parent();
639 if (element.localName() == 'tag') index = element.parent();
640 if (element.localName() == 'ind1') index = element.parent();
641 if (element.localName() == 'ind2') 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 row.previousSibling.firstChild.focus();
651 row.parentNode.removeChild(row);
653 event.preventDefault();
656 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
659 if (element.localName() == 'subfield') index = element;
660 if (element.localName() == 'code') index = element.parent();
663 for (var i in index.parent().children()) {
664 if (index === index.parent().children()[i]) {
665 delete index.parent().children()[i];
670 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
671 event.target.parentNode.previousSibling.lastChild.focus();
673 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
676 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
678 event.preventDefault();
681 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
682 createControlField('006',' ');
683 loadRecord(xml_record);
684 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
685 createControlField('007',' ');
686 loadRecord(xml_record);
687 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
688 createControlField('008',' ');
689 loadRecord(xml_record);
694 } else { // event on a control field
695 if (event.keyCode == 38) {
696 return setFocusToNextTag(row, 'up');
697 } else if (event.keyCode == 40) {
698 return setFocusToNextTag(row, 'down');
703 box.addEventListener(
706 if (element.nodeKind() == 'attribute') element[0]=box.value;
707 else element.setChildren( box.value );
713 box.addEventListener(
716 if (element.nodeKind() == 'attribute') element[0]=box.value;
717 else element.setChildren( box.value );
723 box.addEventListener(
726 if (element.nodeKind() == 'attribute') element[0]=box.value;
727 else element.setChildren( box.value );
733 // 'input' event catches the box value after the keypress
734 box.addEventListener(
737 if (element.nodeKind() == 'attribute') element[0]=box.value;
738 else element.setChildren( box.value );
744 box.addEventListener(
747 if (element.localName() == 'controlfield')
748 eval('fillFixedFields(xml_record);');
757 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
758 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
759 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
760 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
761 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
762 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
763 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
764 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ },
765 AUT : { Type : /[z]{1}/, BLvl : /.{1}/ },
766 MFHD : { Type : /[uvxy]{1}/, BLvl : /.{1}/ }
772 SCO : {start : 33, len : 1, def : ' ' },
773 REC : {start : 33, len : 1, def : 'n' }
776 SCO : {start : 16, len : 1, def : ' ' },
777 REC : {start : 16, len : 1, def : 'n' }
782 VIS : {start : 33, len : 1, def : ' ' }
785 VIS : {start : 16, len : 1, def : ' ' }
790 VIS : {start : 18, len : 3, def : ' ' }
793 VIS : {start : 1, len : 3, def : ' ' }
798 VIS : {start : 34, len : 1, def : 'n' }
801 VIS : {start : 17, len : 1, def : 'n' }
806 SER : {start : 21, len : 1, def : ' ' }
809 SER : {start : 4, len : 1, def : ' ' }
814 BKS : {start : 39, len : 1, def : 'd' },
815 SER : {start : 39, len : 1, def : 'd' },
816 VIS : {start : 39, len : 1, def : 'd' },
817 MIX : {start : 39, len : 1, def : 'd' },
818 MAP : {start : 39, len : 1, def : 'd' },
819 SCO : {start : 39, len : 1, def : 'd' },
820 REC : {start : 39, len : 1, def : 'd' },
821 COM : {start : 39, len : 1, def : 'd' }
826 MAP : {start : 33, len : 2, def : ' ' }
829 MAP : {start : 16, len : 2, def : ' ' }
834 MAP : {start : 18, len : 4, def : ' ' }
837 MAP : {start : 1, len : 4, def : ' ' }
842 SER : {start : 19, len : 1, def : ' ' }
845 SER : {start : 2, len : 1, def : ' ' }
850 MAP : {start : 22, len : 2, def : ' ' }
853 MAP : {start : 5, len : 2, def : ' ' }
858 SCO : {start : 21, len : 1, def : ' ' },
859 REC : {start : 21, len : 1, def : 'n' }
862 SCO : {start : 4, len : 1, def : ' ' },
863 REC : {start : 4, len : 1, def : 'n' }
868 SER : {start : 22, len : 1, def : ' ' }
871 SER : {start : 5, len : 1, def : ' ' }
876 SCO : {start : 30, len : 2, def : ' ' },
877 REC : {start : 30, len : 2, def : ' ' }
880 SCO : {start : 13, len : 2, def : ' ' },
881 REC : {start : 13, len : 2, def : ' ' }
886 SER : {start : 18, len : 1, def : ' ' }
889 SER : {start : 1, len : 1, def : ' ' }
894 SCO : {start : 20, len : 1, def : ' ' },
895 REC : {start : 20, len : 1, def : 'n' }
898 SCO : {start : 3, len : 1, def : ' ' },
899 REC : {start : 3, len : 1, def : 'n' }
904 COM : {start : 26, len : 1, def : 'u' }
907 COM : {start : 9, len : 1, def : 'u' }
912 SER : {start : 24, len : 1, def : ' ' }
915 SER : {start : 7, len : 1, def : ' ' }
920 SCO : {start : 24, len : 6, def : ' ' },
921 REC : {start : 24, len : 6, def : ' ' }
924 SCO : {start : 7, len : 6, def : ' ' },
925 REC : {start : 7, len : 6, def : ' ' }
930 SCO : {start : 18, len : 2, def : ' ' },
931 REC : {start : 18, len : 2, def : ' ' }
934 SCO : {start : 1, len : 2, def : ' ' },
935 REC : {start : 1, len : 2, def : ' ' }
940 MAP : {start : 25, len : 1, def : ' ' }
943 MAP : {start : 8, len : 1, def : ' ' }
948 BKS : {start : 15, len : 3, def : ' ' },
949 SER : {start : 15, len : 3, def : ' ' },
950 VIS : {start : 15, len : 3, def : ' ' },
951 MIX : {start : 15, len : 3, def : ' ' },
952 MAP : {start : 15, len : 3, def : ' ' },
953 SCO : {start : 15, len : 3, def : ' ' },
954 REC : {start : 15, len : 3, def : ' ' },
955 COM : {start : 15, len : 3, def : ' ' }
960 BKS : {start : 35, len : 3, def : ' ' },
961 SER : {start : 35, len : 3, def : ' ' },
962 VIS : {start : 35, len : 3, def : ' ' },
963 MIX : {start : 35, len : 3, def : ' ' },
964 MAP : {start : 35, len : 3, def : ' ' },
965 SCO : {start : 35, len : 3, def : ' ' },
966 REC : {start : 35, len : 3, def : ' ' },
967 COM : {start : 35, len : 3, def : ' ' }
972 BKS : {start : 38, len : 1, def : ' ' },
973 SER : {start : 38, len : 1, def : ' ' },
974 VIS : {start : 38, len : 1, def : ' ' },
975 MIX : {start : 38, len : 1, def : ' ' },
976 MAP : {start : 38, len : 1, def : ' ' },
977 SCO : {start : 38, len : 1, def : ' ' },
978 REC : {start : 38, len : 1, def : ' ' },
979 COM : {start : 38, len : 1, def : ' ' }
984 BKS : {start : 6, len : 1, def : ' ' },
985 SER : {start : 6, len : 1, def : 'c' },
986 VIS : {start : 6, len : 1, def : ' ' },
987 MIX : {start : 6, len : 1, def : ' ' },
988 MAP : {start : 6, len : 1, def : ' ' },
989 SCO : {start : 6, len : 1, def : ' ' },
990 REC : {start : 6, len : 1, def : ' ' },
991 COM : {start : 6, len : 1, def : ' ' }
996 BKS : {start : 6, len : 1, def : 'a' },
997 SER : {start : 6, len : 1, def : 'a' },
998 VIS : {start : 6, len : 1, def : 'g' },
999 MIX : {start : 6, len : 1, def : 'p' },
1000 MAP : {start : 6, len : 1, def : 'e' },
1001 SCO : {start : 6, len : 1, def : 'c' },
1002 REC : {start : 6, len : 1, def : 'i' },
1003 COM : {start : 6, len : 1, def : 'm' },
1004 AUT : {start : 6, len : 1, def : 'z' },
1005 MFHD : {start : 6, len : 1, def : 'y' }
1010 BKS : {start : 8, len : 1, def : ' ' },
1011 SER : {start : 8, len : 1, def : ' ' },
1012 VIS : {start : 8, len : 1, def : ' ' },
1013 MIX : {start : 8, len : 1, def : ' ' },
1014 MAP : {start : 8, len : 1, def : ' ' },
1015 SCO : {start : 8, len : 1, def : ' ' },
1016 REC : {start : 8, len : 1, def : ' ' },
1017 COM : {start : 8, len : 1, def : ' ' }
1022 BKS : {start : 7, len : 1, def : 'm' },
1023 SER : {start : 7, len : 1, def : 's' },
1024 VIS : {start : 7, len : 1, def : 'm' },
1025 MIX : {start : 7, len : 1, def : 'c' },
1026 MAP : {start : 7, len : 1, def : 'm' },
1027 SCO : {start : 7, len : 1, def : 'm' },
1028 REC : {start : 7, len : 1, def : 'm' },
1029 COM : {start : 7, len : 1, def : 'm' }
1034 BKS : {start : 18, len : 1, def : ' ' },
1035 SER : {start : 18, len : 1, def : ' ' },
1036 VIS : {start : 18, len : 1, def : ' ' },
1037 MIX : {start : 18, len : 1, def : ' ' },
1038 MAP : {start : 18, len : 1, def : ' ' },
1039 SCO : {start : 18, len : 1, def : ' ' },
1040 REC : {start : 18, len : 1, def : ' ' },
1041 COM : {start : 18, len : 1, def : 'i' }
1046 MFHD : {start : 18, len : 1, def : 'i' }
1051 BKS : {start : 17, len : 1, def : ' ' },
1052 SER : {start : 17, len : 1, def : ' ' },
1053 VIS : {start : 17, len : 1, def : ' ' },
1054 MIX : {start : 17, len : 1, def : ' ' },
1055 MAP : {start : 17, len : 1, def : ' ' },
1056 SCO : {start : 17, len : 1, def : ' ' },
1057 REC : {start : 17, len : 1, def : ' ' },
1058 COM : {start : 17, len : 1, def : ' ' },
1059 AUT : {start : 17, len : 1, def : 'n' },
1060 MFHD : {start : 17, len : 1, def : 'u' }
1065 BKS : {start : 31, len : 1, def : '0' },
1066 MAP : {start : 31, len : 1, def : '0' }
1069 BKS : {start : 14, len : 1, def : '0' },
1070 MAP : {start : 14, len : 1, def : '0' }
1075 BKS : {start : 7, len : 4, def : ' ' },
1076 SER : {start : 7, len : 4, def : ' ' },
1077 VIS : {start : 7, len : 4, def : ' ' },
1078 MIX : {start : 7, len : 4, def : ' ' },
1079 MAP : {start : 7, len : 4, def : ' ' },
1080 SCO : {start : 7, len : 4, def : ' ' },
1081 REC : {start : 7, len : 4, def : ' ' },
1082 COM : {start : 7, len : 4, def : ' ' }
1087 BKS : {start : 11, len : 4, def : ' ' },
1088 SER : {start : 11, len : 4, def : '9' },
1089 VIS : {start : 11, len : 4, def : ' ' },
1090 MIX : {start : 11, len : 4, def : ' ' },
1091 MAP : {start : 11, len : 4, def : ' ' },
1092 SCO : {start : 11, len : 4, def : ' ' },
1093 REC : {start : 11, len : 4, def : ' ' },
1094 COM : {start : 11, len : 4, def : ' ' }
1099 BKS : {start : 33, len : 1, def : '0' }
1102 BKS : {start : 16, len : 1, def : '0' }
1107 BKS : {start : 34, len : 1, def : ' ' }
1110 BKS : {start : 17, len : 1, def : ' ' }
1115 BKS : {start : 18, len : 4, def : ' ' }
1118 BKS : {start : 1, len : 4, def : ' ' }
1123 BKS : {start : 30, len : 1, def : '0' }
1126 BKS : {start : 13, len : 1, def : '0' }
1131 BKS : {start : 29, len : 1, def : '0' },
1132 SER : {start : 29, len : 1, def : '0' }
1135 BKS : {start : 12, len : 1, def : '0' },
1136 SER : {start : 12, len : 1, def : '0' }
1141 BKS : {start : 24, len : 4, def : ' ' },
1142 SER : {start : 25, len : 3, def : ' ' }
1145 BKS : {start : 7, len : 4, def : ' ' },
1146 SER : {start : 8, len : 3, def : ' ' }
1151 BKS : {start : 28, len : 1, def : ' ' },
1152 SER : {start : 28, len : 1, def : ' ' },
1153 VIS : {start : 28, len : 1, def : ' ' },
1154 MAP : {start : 28, len : 1, def : ' ' },
1155 COM : {start : 28, len : 1, def : ' ' }
1158 BKS : {start : 11, len : 1, def : ' ' },
1159 SER : {start : 11, len : 1, def : ' ' },
1160 VIS : {start : 11, len : 1, def : ' ' },
1161 MAP : {start : 11, len : 1, def : ' ' },
1162 COM : {start : 11, len : 1, def : ' ' }
1167 BKS : {start : 22, len : 1, def : ' ' },
1168 SER : {start : 22, len : 1, def : ' ' },
1169 VIS : {start : 22, len : 1, def : ' ' },
1170 SCO : {start : 22, len : 1, def : ' ' },
1171 REC : {start : 22, len : 1, def : ' ' },
1172 COM : {start : 22, len : 1, def : ' ' }
1175 BKS : {start : 5, len : 1, def : ' ' },
1176 SER : {start : 5, len : 1, def : ' ' },
1177 VIS : {start : 5, len : 1, def : ' ' },
1178 SCO : {start : 5, len : 1, def : ' ' },
1179 REC : {start : 5, len : 1, def : ' ' },
1180 COM : {start : 5, len : 1, def : ' ' }
1185 BKS : {start : 23, len : 1, def : ' ' },
1186 SER : {start : 23, len : 1, def : ' ' },
1187 VIS : {start : 29, len : 1, def : ' ' },
1188 MIX : {start : 23, len : 1, def : ' ' },
1189 MAP : {start : 29, len : 1, def : ' ' },
1190 SCO : {start : 23, len : 1, def : ' ' },
1191 REC : {start : 23, len : 1, def : ' ' }
1194 BKS : {start : 6, len : 1, def : ' ' },
1195 SER : {start : 6, len : 1, def : ' ' },
1196 VIS : {start : 12, len : 1, def : ' ' },
1197 MIX : {start : 6, len : 1, def : ' ' },
1198 MAP : {start : 12, len : 1, def : ' ' },
1199 SCO : {start : 6, len : 1, def : ' ' },
1200 REC : {start : 6, len : 1, def : ' ' }
1205 SER : {start : 34, len : 1, def : '0' }
1208 SER : {start : 17, len : 1, def : '0' }
1213 SER : {start : 33, len : 1, def : ' ' }
1216 SER : {start : 16, len : 1, def : ' ' }
1221 "AUT" : {"start" : 6, "len" : 1, "def" : ' ' }
1226 "AUT" : {"start" : 7, "len" : 1, "def" : ' ' }
1231 "AUT" : {"start" : 8, "len" : 1, "def" : ' ' }
1236 "AUT" : {"start" : 9, "len" : 1, "def" : ' ' }
1241 "AUT" : {"start" : 10, "len" : 1, "def" : ' ' }
1246 "AUT" : {"start" : 11, "len" : 1, "def" : ' ' }
1251 "AUT" : {"start" : 12, "len" : 1, "def" : ' ' }
1256 "AUT" : {"start" : 13, "len" : 1, "def" : ' ' }
1261 "AUT" : {"start" : 14, "len" : 1, "def" : ' ' }
1266 "AUT" : {"start" : 15, "len" : 1, "def" : ' ' }
1271 "AUT" : {"start" : 16, "len" : 1, "def" : ' ' }
1276 "AUT" : {"start" : 17, "len" : 1, "def" : ' ' }
1281 "AUT" : {"start" : 28, "len" : 1, "def" : ' ' }
1286 "AUT" : {"start" : 29, "len" : 1, "def" : ' ' }
1291 "AUT" : {"start" : 31, "len" : 1, "def" : ' ' }
1296 "AUT" : {"start" : 32, "len" : 1, "def" : ' ' }
1301 "AUT" : {"start" : 33, "len" : 1, "def" : ' ' }
1306 "AUT" : {"start" : 38, "len" : 1, "def" : ' ' }
1311 "AUT" : {"start" : 39, "len" : 1, "def" : ' ' }
1316 function recordType (rec) {
1318 var _l = rec.leader.toString();
1320 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
1321 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
1323 for (var t in rec_type) {
1324 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
1325 document.getElementById('recordTypeLabel').value = t;
1331 // in case we don't have a valid record type ...
1332 _record_type = 'BKS';
1333 return _record_type;
1336 alert('FIXME, MARC Editor, recordType: ' + E);
1340 function toggleFFE () {
1341 var grid = document.getElementById('leaderGrid');
1343 grid.hidden = false;
1350 function changeFFEditor (type) {
1351 var grid = document.getElementById('leaderGrid');
1352 grid.setAttribute('type',type);
1354 // Hide FFEditor rows that we don't need for our current type
1355 // If all of the labels for a given row do not include our
1356 // desired type in their set attribute, we can hide that row
1357 dojo.query('rows row', grid).forEach(function(node, index, arr) {
1358 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
1365 function fillFixedFields (rec) {
1367 var grid = document.getElementById('leaderGrid');
1369 var rtype = _record_type;
1371 var _l = rec.leader.toString();
1372 var _6 = rec.controlfield.(@tag=='006').toString();
1373 var _7 = rec.controlfield.(@tag=='007').toString();
1374 var _8 = rec.controlfield.(@tag=='008').toString();
1377 var pre_list = grid.getElementsByTagName('label');
1378 for (var i in pre_list) {
1379 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
1380 list.push( pre_list[i] );
1384 for (var i in list) {
1385 var name = list[i].getAttribute('name');
1391 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
1392 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
1394 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
1395 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
1397 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
1398 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
1400 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
1401 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
1406 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
1407 d = ff_pos[name].ldr[rtype].def;
1411 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
1412 d = ff_pos[name]._8[rtype].def;
1416 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
1417 d = ff_pos[name]._6[rtype].def;
1421 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
1422 d = ff_pos[name]._7[rtype].def;
1427 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
1433 list[i].nextSibling.value = value;
1438 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
1442 function updateFixedFields (element) {
1443 var grid = document.getElementById('leaderGrid');
1444 var recGrid = document.getElementById('recGrid');
1446 var rtype = _record_type;
1447 var new_value = element.value;
1450 ldr : _record.leader,
1451 _6 : _record.controlfield.(@tag=='006'),
1452 _7 : _record.controlfield.(@tag=='007'),
1453 _8 : _record.controlfield.(@tag=='008')
1456 var name = element.getAttribute('name');
1457 for (var i in ff_pos[name]) {
1459 if (!ff_pos[name][i][rtype]) continue;
1461 // we're missing the required field. Add it now.
1464 if (i == '_6') newfield = '006';
1465 else if (i == '_7') newfield = '007';
1466 else if (i == '_8') newfield = '008';
1469 createControlField(newfield,' ');
1470 parts[i] = _record.controlfield.(@tag==newfield);
1473 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1474 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1476 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1477 new_value += ff_pos[name][i][rtype].def;
1480 parts[i].setChildren( before + new_value + after );
1481 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1487 function marcLeader (leader) {
1488 var row = createRow(
1489 { class : 'marcLeaderRow',
1494 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
1497 class : 'marcInd1' } ),
1500 class : 'marcInd2' } ),
1502 { value : leader.text(),
1503 class : 'marcLeader' } )
1509 function marcControlfield (field) {
1510 tagname = field.@tag.toString().substr(2);
1512 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
1514 { class : 'marcControlfieldRow',
1515 tag : '_' + tagname },
1517 { value : field.@tag,
1519 context : 'tags_popup',
1520 onmouseover : 'getTooltip(this, "tag");',
1521 tooltipid : 'tag' + field.@tag } ),
1523 { value : field.@ind1,
1525 onmouseover : 'getTooltip(this, "ind1");',
1526 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1528 { value : field.@ind2,
1530 onmouseover : 'getTooltip(this, "ind2");',
1531 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1534 { value : field.text(),
1535 class : 'plain marcEditableControlfield',
1536 name : 'CONTROL' + tagname,
1537 context : 'clipboard',
1543 { class : 'marcControlfieldRow',
1544 tag : '_' + tagname },
1546 { value : field.@tag,
1548 onmouseover : 'getTooltip(this, "tag");',
1549 tooltipid : 'tag' + field.@tag } ),
1551 { value : field.@ind1,
1553 onmouseover : 'getTooltip(this, "ind1");',
1554 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1556 { value : field.@ind2,
1558 onmouseover : 'getTooltip(this, "ind2");',
1559 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1561 { value : field.text(),
1562 class : 'marcControlfield' } )
1569 function stackSubfields(checkbox) {
1570 var list = document.getElementsByAttribute('name','sf_box');
1573 if (!checkbox.checked) o = 'horizontal';
1575 for (var i = 0; i < list.length; i++) {
1576 if (list[i]) list[i].setAttribute('orient',o);
1580 function fastItemAdd_toggle(checkbox) {
1581 var x = document.getElementById('fastItemAdd_textboxes');
1582 if (checkbox.checked) {
1584 document.getElementById('fastItemAdd_callnumber').focus();
1585 document.getElementById('fastItemAdd_callnumber').select();
1591 function fastItemAdd_attempt(doc_id) {
1593 if (typeof window.xulG.fast_add_item != 'function') { return; }
1594 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1595 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1596 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1597 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1598 document.getElementById('fastItemAdd_barcode').value = '';
1600 alert('fastItemAdd_attempt: ' + E);
1604 function save_attempt(xml_string) {
1606 var result = window.xulG.save.func( xml_string );
1609 if (result.id) fastItemAdd_attempt(result.id);
1610 if (typeof result.on_complete == 'function') result.on_complete();
1613 alert('save_attempt: ' + E);
1617 function marcDatafield (field) {
1618 var row = createRow(
1619 { class : 'marcDatafieldRow' },
1622 { value : field.@tag,
1623 class : 'plain marcTag',
1625 context : 'tags_popup',
1626 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1629 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1632 { value : field.@ind1,
1633 class : 'plain marcInd1',
1635 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1638 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1639 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1642 { value : field.@ind2,
1643 class : 'plain marcInd2',
1645 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1648 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1649 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1650 createHbox({ name : 'sf_box' })
1653 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1654 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1655 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1657 var sf_box = row.lastChild;
1658 if (document.getElementById('stackSubfields').checked)
1659 sf_box.setAttribute('orient','vertical');
1661 sf_box.addEventListener(
1664 if (sf_box === e.target) {
1665 sf_box.lastChild.lastChild.focus();
1666 } else if (e.target.parentNode === sf_box) {
1667 e.target.lastChild.focus();
1674 for (var i in field.subfield) {
1675 var sf = field.subfield[i];
1680 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1682 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1683 current_focus = sf_box.lastChild.childNodes[1];
1689 function marcSubfield (sf) {
1691 { class : 'marcSubfieldBox' },
1694 class : 'plain marcSubfieldDelimiter',
1695 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1696 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1697 //onclick : 'this.nextSibling.focus();',
1698 onfocus : 'this.nextSibling.focus();',
1703 class : 'plain marcSubfieldCode',
1704 name : 'marcSubfieldCode',
1705 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1706 oncontextmenu : 'getContextMenu(this, "subfield");',
1707 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1712 { value : sf.text(),
1713 name : sf.parent().@tag + ':' + sf.@code,
1714 class : 'plain marcSubfield',
1715 onmouseover : 'getTooltip(this, "subfield");',
1716 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1717 size : new String(sf.text()).length + 2,
1718 oninput : "this.setAttribute('size', this.value.length + 2);"
1723 function loadRecord(rec) {
1726 var grid_rows = document.getElementById('recGrid').lastChild;
1728 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1730 grid_rows.appendChild( marcLeader( rec.leader ) );
1732 for (var i in rec.controlfield) {
1733 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1736 for (var i in rec.datafield) {
1737 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1740 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1741 changeFFEditor(recordType(rec));
1742 fillFixedFields(rec);
1744 alert('FIXME, MARC Editor, loadRecord: ' + E);
1749 function genToolTips () {
1750 for (var i in bib_data.field) {
1751 var f = bib_data.field[i];
1753 tag_menu.appendChild(
1757 'current_focus.value = "' + f.@tag + '";' +
1758 'var e = document.createEvent("MutationEvents");' +
1759 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1760 'current_focus.inputField.dispatchEvent(e);',
1761 disabled : f.@tag < '010' ? "true" : "false",
1762 tooltiptext : f.description }
1766 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1767 context_menus.appendChild( i1_popup );
1769 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1770 context_menus.appendChild( i2_popup );
1772 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1773 context_menus.appendChild( sf_popup );
1775 tooltip_hash['tag' + f.@tag] = f.description;
1776 for (var j in f.indicator) {
1777 var ind = f.indicator[j];
1778 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1780 if (ind.@position == 1) {
1781 i1_popup.appendChild(
1783 { label : ind.@value,
1785 'current_focus.value = "' + ind.@value + '";' +
1786 'var e = document.createEvent("MutationEvents");' +
1787 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1788 'current_focus.inputField.dispatchEvent(e);',
1789 tooltiptext : ind.description }
1794 if (ind.@position == 2) {
1795 i2_popup.appendChild(
1797 { label : ind.@value,
1799 'current_focus.value = "' + ind.@value + '";' +
1800 'var e = document.createEvent("MutationEvents");' +
1801 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1802 'current_focus.inputField.dispatchEvent(e);',
1803 tooltiptext : ind.description }
1809 for (var j in f.subfield) {
1810 var sf = f.subfield[j];
1811 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1813 sf_popup.appendChild(
1817 'current_focus.value = "' + sf.@code + '";' +
1818 'var e = document.createEvent("MutationEvents");' +
1819 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1820 'current_focus.inputField.dispatchEvent(e);',
1821 tooltiptext : sf.description
1829 function getTooltip (target, type) {
1832 if (type == 'subfield')
1833 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1836 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1839 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1842 tt = 'tag' + target.parentNode.firstChild.value;
1844 if (!document.getElementById( tt )) {
1849 orient : 'vertical',
1850 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1851 class : 'tooltip' },
1852 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1857 target.tooltip = tt;
1861 function getContextMenu (target, type) {
1864 if (type == 'subfield')
1865 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1868 tt = 't' + target.parentNode.firstChild.value + 'i1';
1871 tt = 't' + target.parentNode.firstChild.value + 'i2';
1873 target.setAttribute('context', tt);
1877 var authority_tag_map = {
1878 100 : ['[100,400,500,700]',100],
1879 400 : ['[100,400,500,700]',100],
1880 700 : ['[100,400,500,700]',100],
1881 800 : ['[100,400,500,700]',100],
1882 110 : ['[110,410,510,710]',110],
1883 410 : ['[110,410,510,710]',110],
1884 710 : ['[110,410,510,710]',110],
1885 810 : ['[110,410,510,710]',110],
1886 111 : ['[111,411,511,711]',111],
1887 411 : ['[111,411,511,711]',111],
1888 711 : ['[111,411,511,711]',111],
1889 811 : ['[111,411,511,711]',111],
1890 240 : ['[130,430,530,730]',130],
1891 440 : ['[130,430,530,730]',130],
1892 130 : ['[130,430,530,730]',130],
1893 730 : ['[130,430,530,730]',130],
1894 830 : ['[130,430,530,730]',130],
1895 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1896 630 : ['[130,430,530,730]',130],
1897 648 : ['[148,448,548]',148],
1898 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1899 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1900 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155]
1903 function getAuthorityContextMenu (target, sf) {
1904 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1907 var old = dojo.byId( menu_id );
1909 page = auth_pages[menu_id];
1910 old.parentNode.removeChild(old);
1912 auth_pages[menu_id] = 0;
1915 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1917 sf_popup.addEventListener("popuphiding", function(event) {
1918 if (show_auth_menu) {
1919 show_auth_menu = false;
1920 getAuthorityContextMenu(target, sf);
1921 dojo.byId(menu_id).openPopup();
1925 context_menus.appendChild( sf_popup );
1927 if (!authority_tag_map[sf.parent().@tag]) {
1928 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1929 target.setAttribute('context', 'clipboard');
1933 browseAuthority( sf_popup, menu_id, target, sf, 20, page);
1938 /* Apply the complete 1xx */
1939 function applyFullAuthority ( target, ui_sf, e4x_sf ) {
1940 var new_vals = dojo.query('*[tag^="1"]', target);
1941 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1944 function applySelectedAuthority ( target, ui_sf, e4x_sf ) {
1945 var new_vals = target.getElementsByAttribute('checked','true');
1946 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1949 function applyAuthority ( target, ui_sf, e4x_sf, new_vals ) {
1950 var field = e4x_sf.parent();
1952 for (var i = 0; i < new_vals.length; i++) {
1954 var sf_list = field.subfield;
1955 for (var j in sf_list) {
1957 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1958 sf_list[j] = new_vals[i].getAttribute('value');
1959 new_vals[i].setAttribute('subfield','');
1965 for (var i = 0; i < new_vals.length; i++) {
1966 if (!new_vals[i].getAttribute('subfield')) continue;
1968 var val = new_vals[i].getAttribute('value');
1970 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1971 sf.@code = new_vals[i].getAttribute('subfield');
1973 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1976 var row = marcDatafield( field );
1979 while (node.nodeName != 'row') {
1980 node = node.parentNode;
1983 node.parentNode.replaceChild( row, node );
1989 'a' : { 100 : 'a' },
1990 'd' : { 100 : 'd' },
1991 'e' : { 100 : 'e' },
1995 'a' : { 110 : 'a' },
1999 'a' : { 111 : 'a' },
2003 'a' : { 130 : 'a' },
2007 'a' : { 130 : 'a' },
2011 'a' : { 100 : 'a' },
2015 'a' : { 110 : 'a' },
2019 'a' : { 111 : 'a' },
2023 'a' : { 130 : 'a' },
2024 'n' : { 130 : 'n' },
2028 'a' : { 100 : 'a' },
2029 'd' : { 100 : 'd' },
2030 'q' : { 100 : 'q' },
2034 'a' : { 110 : 'a' },
2038 'a' : { 111 : 'a' },
2039 'c' : { 111 : 'c' },
2043 'a' : { 130 : 'a' },
2047 'a' : { 100 : 'a' },
2051 'a' : { 110 : 'a' },
2055 'a' : { 111 : 'a' },
2059 'a' : { 130 : 'a' },
2063 'a' : { 100 : 'a' },
2064 'd' : { 100 : 'd' },
2065 'q' : { 100 : 'q' },
2066 't' : { 100 : 't' },
2093 'a' : { 110 : 'a' },
2094 'd' : { 110 : 'd' },
2095 't' : { 110 : 't' },
2122 'a' : { 111 : 'a' },
2123 'd' : { 111 : 'd' },
2124 't' : { 111 : 't' },
2151 'a' : { 130 : 'a' },
2155 'a' : { 148 : 'a' },
2156 'v' : { 148 : 'v' },
2157 'x' : { 148 : 'x' },
2158 'y' : { 148 : 'y' },
2162 'a' : { 150 : 'a' },
2163 'b' : { 150 : 'b' },
2190 'a' : { 151 : 'a' },
2217 'a' : { 155 : 'a' },
2245 function validateAuthority (button) {
2246 var grid = document.getElementById('recGrid');
2247 var label = button.getAttribute('label');
2250 var rows = grid.lastChild.childNodes;
2251 for (var i = 0; i < rows.length; i++) {
2253 var tag = row.firstChild;
2255 if (!control_map[tag.value]) continue
2256 button.setAttribute('label', label + ' - ' + tag.value);
2258 var ind1 = tag.nextSibling;
2259 var ind2 = ind1.nextSibling;
2260 var subfields = ind2.nextSibling.childNodes;
2264 for (var j = 0; j < subfields.length; j++) {
2265 var sf = subfields[j];
2266 var sf_code = sf.childNodes[1].value;
2267 var sf_value = sf.childNodes[2].value;
2269 if (!control_map[tag.value][sf_code]) continue;
2272 for (var a_tag in control_map[tag.value][sf_code]) {
2273 if (!tags[a_tag]) tags[a_tag] = [];
2274 tags[a_tag].push({ term : sf_value, subfield : sf_code });
2279 for (var val_tag in tags) {
2280 var auth_data = validateBibField( [val_tag], tags[val_tag]);
2281 var res = new XML( auth_data.responseText );
2282 found = parseInt(res.gw::payload.gw::string.toString());
2286 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
2287 for (var j = 0; j < subfields.length; j++) {
2288 var sf = subfields[j];
2290 dojo.removeClass(sf.childNodes[2], 'marcValidated');
2291 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
2293 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
2294 dojo.addClass(sf.childNodes[2], 'marcValidated');
2299 button.setAttribute('label', label);
2305 function validateBibField (tags, searches) {
2306 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
2307 url += '¶m="tags"¶m=' + js2JSON(tags);
2308 url += '¶m="searches"¶m=' + js2JSON(searches);
2311 var req = new XMLHttpRequest();
2312 req.open('GET',url,false);
2318 function searchAuthority (term, tag, sf, limit) {
2319 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
2320 url += '¶m="term"¶m="' + term + '"';
2321 url += '¶m="limit"¶m=' + limit;
2322 url += '¶m="tag"¶m=' + tag;
2323 url += '¶m="subfield"¶m="' + sf + '"';
2326 var req = new XMLHttpRequest();
2327 req.open('GET',url,false);
2334 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
2335 dojo.require('dojox.xml.parser');
2337 // map tag + subfield to the appropriate authority browse axis:
2338 // currently authority.author, authority.subject, authority.title, authority.topic
2339 // based on mappings in OpenILS::Application::SuperCat
2343 // Map based on replacing the first char of the selected tag with '1'
2344 switch ('1' + (sf.parent().@tag.toString()).substring(1)) {
2346 type = 'authority.title';
2352 type = 'authority.author';
2356 type = 'authority.topic';
2362 type = 'authority.subject';
2365 // No matching tag means no authorities to search - shortcut
2378 var url = '/opac/extras/browse/marcxml/'
2380 + '/1' // OU - currently unscoped
2381 + '/' + sf.toString()
2386 // would be good to carve this out into a separate function
2387 dojo.xhrGet({"url":url, "sync": true, "preventCache": true, "handleAs":"xml", "load": function(records) {
2388 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
2390 var cm_popup = create_menu.appendChild(
2394 cm_popup.appendChild(
2395 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
2396 command : function() {
2397 // Call middle-layer function to create and save the new authority
2398 var source_f = summarizeField(sf);
2399 var new_auth = fieldmapper.standardRequest(
2400 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
2401 [source_f, xulG.marc_control_number_identifier, ses()]
2403 if (new_auth && new_auth.id()) {
2404 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){new_auth.id()}</subfield>;
2405 sf.parent().appendChild(id_sf);
2406 var new_sf = marcSubfield(id_sf);
2407 target.parentNode.appendChild(new_sf);
2408 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2414 cm_popup.appendChild(
2415 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
2416 command : function() {
2417 // Generate the new authority by calling the new middle-layer
2418 // function (a non-saving variant), then display in another
2420 var source_f = summarizeField(sf);
2421 var authtoken = ses();
2422 dojo.require('openils.PermaCrud');
2423 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2424 var rec = fieldmapper.standardRequest(
2425 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
2426 { "params": [source_f, xulG.marc_control_number_identifier] }
2428 loadMarcEditor(pcrud, rec, target, sf);
2433 sf_popup.appendChild(create_menu);
2434 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2436 // append "Previous page" results browser
2437 sf_popup.appendChild(
2438 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
2439 command : function(event) {
2440 auth_pages[menu_id] -= 1;
2441 show_auth_menu = true;
2445 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2447 dojo.query('record', records).forEach(function(record) {
2449 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"] subfield[code="c"]', record)[0]);
2450 var auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
2451 // we have grabbed the fields with tags beginning with 1 or 5 and iterate through the subfields
2452 dojo.query('datafield[tag^="1"], datafield[tag^="5"]', record).forEach(function(field) {
2453 dojo.query('subfield', field).forEach(function(subfield) {
2457 main_text += dojox.xml.parser.textContent(subfield);
2463 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) return;
2466 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
2467 grid.setAttribute('name','-none-');
2468 grid.setAttribute('style','overflow:scroll');
2470 var submenu = createMenu( { label : main_text } );
2472 var popup = createMenuPopup({ flex : "1" });
2473 submenu.appendChild(popup);
2475 dojo.query('datafield[tag^="1"], datafield[tag^="5"]', record).forEach(function(field) {
2476 var row = createRow(
2478 createLabel( { "value" : dojo.attr(field, 'tag') } ),
2479 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
2480 createLabel( { "value" : dojo.attr(field, 'ind2') } )
2483 var sf_box = createHbox();
2484 dojo.query('subfield', field).forEach(function(subfield) {
2487 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
2488 "subfield" : dojo.attr(subfield, 'code'),
2489 "tag" : dojo.attr(field, 'tag'),
2490 "value" : dojox.xml.parser.textContent(subfield)
2494 row.appendChild(sf_box);
2497 // Append the authority linking subfield
2500 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
2502 "tag" : dojo.attr(field, 'tag'),
2503 "value" : '(' + auth_org + ')' + auth_id
2507 row.appendChild(sf_box);
2509 grid.lastChild.appendChild(row);
2512 grid.hidden = false;
2513 popup.appendChild( grid );
2517 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
2518 command : function (event) {
2519 applySelectedAuthority(event.target.previousSibling, target, sf);
2526 popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2530 { label : $('catStrings').getString('staff.cat.marcedit.apply_full.label'),
2531 command : function (event) {
2532 applyFullAuthority(event.target.previousSibling.previousSibling.previousSibling, target, sf);
2539 sf_popup.appendChild( submenu );
2542 if (sf_popup.childNodes.length == 0) {
2543 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
2545 // append "Next page" results browser
2546 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2547 sf_popup.appendChild(
2548 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
2549 command : function(event) {
2550 auth_pages[menu_id] += 1;
2551 show_auth_menu = true;
2557 target.setAttribute('context', menu_id);
2563 function summarizeField(sf) {
2570 for (var i = 0; i < sf.parent().subfield.length(); i++) {
2571 source_f.subfields.push([sf.parent().subfield[i].@code.toString(), sf.parent().subfield[i].toString()]);
2573 source_f.tag = sf.parent().@tag.toString();
2574 source_f.ind1 = sf.parent().@ind1.toString();
2575 source_f.ind1 = sf.parent().@ind2.toString();
2580 function buildBibSourceList (authtoken, recId) {
2581 /* TODO: Work out how to set the bib source of the bre that does not yet
2582 * exist - this is specifically in the case of Z39.50 imports. Right now
2583 * we just avoid populating and showing the config.bib_source list
2589 var bib = xulG.record.bre;
2591 dojo.require('openils.PermaCrud');
2593 // cbsList = the XUL menulist that contains the available bib sources
2594 var cbsList = dojo.byId('bib-source-list');
2596 // bibSources = an array containing all of the bib source objects
2597 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
2599 // A tad ugly, but gives us the index of the bib source ID in cbsList
2601 var cbsListArr = [];
2602 dojo.forEach(bibSources, function (item) {
2603 cbsList.appendItem(item.source(), item.id());
2604 cbsListArr[item.id()] = x;
2608 // Show the current value of the bib source for this record
2609 cbsList.selectedIndex = cbsListArr[bib.source()];
2611 // Display the bib source selection widget
2612 dojo.byId('bib-source-list-caption').hidden = false;
2613 dojo.byId('bib-source-list').hidden = false;
2614 dojo.byId('bib-source-list-button').disabled = true;
2615 dojo.byId('bib-source-list-button').hidden = false;
2618 // Fired when the "Update Source" button is clicked
2619 // Updates the value of the bib source for the current record
2620 function updateBibSource() {
2621 var authtoken = ses();
2622 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2623 var recId = xulG.record.id;
2624 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2625 var bib = pcrud.retrieve('bre', recId);
2626 if (bib.source() != cbs) {
2628 bib.ischanged = true;
2633 function onBibSourceSelect() {
2634 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2635 var bib = xulG.record.bre;
2636 if (bib.source() != cbs) {
2637 dojo.byId('bib-source-list-button').disabled = false;
2639 dojo.byId('bib-source-list-button').disabled = true;
2643 function loadMarcEditor(pcrud, marcxml, target, sf) {
2645 To run in Firefox directly, must set signed.applets.codebase_principal_support
2646 to true in about:config
2648 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
2649 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
2651 // Match marc2are.pl last_xact_id format, roughly
2653 var xact_id = 'IMPORT-' + Date.parse(now);
2656 "record": {"marc": marcxml, "rtype": "are"},
2658 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2659 "func": function(xmlString) {
2660 var rec = new are();
2661 rec.marc(xmlString);
2662 rec.last_xact_id(xact_id);
2665 "oncomplete": function (r, objs) {
2666 var new_rec = objs[0];
2670 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){new_rec.id()}</subfield>;
2671 sf.parent().appendChild(id_sf);
2672 var new_sf = marcSubfield(id_sf);
2673 target.parentNode.appendChild(new_sf);
2674 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));