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 // Pretty printing kills whitespace too, so disable it.
22 XML.prettyPrinting = false;
23 var xmlDeclaration = /^<\?xml version[^>]+?>/;
25 var serializer = new XMLSerializer();
26 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
27 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
28 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
29 default xml namespace = marcns;
31 var tooltip_hash = {};
43 var show_auth_menu = false;
45 function $(id) { return document.getElementById(id); }
47 var acs; // AuthorityControlSet
49 function get_new_008() {
52 var y = now.getUTCFullYear().toString().substr(2,2);
53 var m = now.getUTCMonth() + 1;
54 if (m < 10) m = '0' + m;
55 var d = now.getUTCDate();
56 if (d < 10) d = '0' + d;
58 if (xml_record.controlfield.(@tag == '008')) {
59 var field = xml_record.controlfield.(@tag == '008')[0];
60 orig008 = field.text();
63 /* lang code from 041a */
64 var lang = orig008.substr(35, 3);
65 if (xml_record.datafield.(@tag == '041')) {
66 var field = xml_record.datafield.(@tag == '041')[0];
67 if (field && field.subfield.(@code == 'a')) {
68 lang = field.subfield.(@code == 'a')[0];
72 /* country code from 044a */
73 var country = orig008.substr(15, 3);
74 if (xml_record.datafield.(@tag == '044')) {
75 var field = xml_record.datafield.(@tag == '044')[0];
76 if (field && field.subfield.(@code == 'a')) {
77 country = field.subfield.(@code == 'a')[0];
80 while (country.length < 3) country = country + ' ';
81 if (country.length > 3) country = country.substr(0,3);
84 var date1 = now.getUTCFullYear().toString();
85 if (xml_record.datafield.(@tag == '260')) {
86 var field = xml_record.datafield.(@tag == '260')[0];
87 if (field && field.subfield.(@code == 'c')) {
88 var tmpd = field.subfield.(@code == 'c')[0].replace(/[^0-9]/g, '');
89 if (tmpd.match(/^\d\d\d\d/)) {
90 date1 = tmpd.substr(0, 4);
95 var date2 = orig008.substr(11, 4);
96 var datetype = orig008.substr(6, 1);
97 var modded = orig008.substr(38, 1);
98 var catsrc = orig008.substr(39, 1);
100 return '' + y + m + d + datetype + date1 + date2 + country + ' ' + lang + modded + catsrc;
104 function mangle_005() {
105 var now = new Date();
106 var y = now.getUTCFullYear();
108 var m = now.getUTCMonth() + 1;
109 if (m < 10) m = '0' + m;
111 var d = now.getUTCDate();
112 if (d < 10) d = '0' + d;
114 var H = now.getUTCHours();
115 if (H < 10) H = '0' + H;
117 var M = now.getUTCMinutes();
118 if (M < 10) M = '0' + M;
120 var S = now.getUTCSeconds();
121 if (S < 10) S = '0' + S;
124 var stamp = '' + y + m + d + H + M + S + '.0';
125 createControlField('005',stamp);
129 function createControlField (tag,data) {
130 // first, remove the old field, if any;
131 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
133 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
136 // then, find the right position and insert it
138 var cfields = xml_record.controlfield;
139 var base = Number(tag.substring(2));
140 for (var i in cfields) {
141 var t = Number(cfields[i].@tag.toString().substring(2));
143 xml_record.insertChildBefore( cfields[i], cf );
149 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
154 function xml_escape_unicode ( str ) {
156 /([\u0080-\ufffe])/g,
157 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
161 function wrap_long_fields (node) {
162 var text_size = dojo.attr(node, 'size');
163 var hard_width = 100;
164 if (text_size > hard_width) {
165 dojo.attr(node, 'multiline', 'true');
166 dojo.attr(node, 'cols', hard_width);
167 var text_rows = (text_size / hard_width) + 1;
168 dojo.attr(node, 'rows', text_rows);
172 function set_flat_editor (useFlatText) {
174 var xe = $('xul-editor');
175 var te = $('text-editor');
178 if (xe.hidden) { return; }
182 if (te.hidden) { return; }
188 // get the marcxml from the text box
189 var xml_string = new MARC.Record({
190 marcbreaker : $('text-editor-box').value,
194 // reset the xml record and rerender it
195 xml_record = new XML( xml_string );
196 if (xml_record..record[0]) xml_record = xml_record..record[0];
199 var xml_string = xml_record.toXMLString();
201 // push the xml record into the textbox
202 var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
203 $('text-editor-box').value = rec.toBreaker();
210 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
211 JSAN.errorLevel = "die"; // none, warn, or die
212 JSAN.addRepository('/xul/server/');
214 dojo.require('openils.AuthorityControlSet');
215 acs = new openils.AuthorityControlSet ();
217 // Fake xulG for standalone...
222 window.xulG.record = {};
223 window.xulG.save = {};
224 window.xulG.marc_control_number_identifier = 'CONS';
226 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
227 window.xulG.save.func = function (r) { alert(r); }
230 var _rid = cgi.param('record');
232 window.xulG.record.id = _rid;
233 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
237 // End faking part...
239 /* Check for an explicitly passed record type
240 * This is not the same as the fixed-field record type; we can't trust
241 * the fixed fields when making modifications to the attributes for a
242 * given record (in particular, config.bib_source only applies for bib
243 * records, but an auth or MFHD record with the same ID and bad fixed
244 * fields could trample the config.bib_source value for the
245 * corresponding bib record if we're not careful.
247 * are = authority record
248 * sre = serial record (MFHD)
249 * bre = bibliographic record
251 if (!window.xulG.record.rtype) {
253 window.xulG.record.rtype = cgi.param('rtype') || false;
256 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
257 document.getElementById('save-button').setAttribute('oncommand',
258 'if ($("xul-editor").hidden) set_flat_editor(false); ' +
260 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
261 'save_attempt( xml_string ); ' +
265 if (window.xulG.record.url) {
266 var req = new XMLHttpRequest();
267 req.open('POST',window.xulG.record.url,false);
269 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
272 xml_record = new XML( window.xulG.record.marc );
273 if (xml_record..record[0]) xml_record = xml_record..record[0];
275 // Get the tooltip xml all async like
276 req = new XMLHttpRequest();
278 // Set a default locale in case preferences fail us
279 var locale = "en-US";
281 // Try to get the locale from our preferences
283 const Cc = Components.classes;
284 const Ci = Components.interfaces;
285 locale = Cc["@mozilla.org/preferences-service;1"].
286 getService(Ci.nsIPrefBranch).
287 getCharPref("general.useragent.locale");
291 // TODO: We should send a HEAD request to check for the existence of the desired file
292 // then fall back to the default locale if preferred locale is not necessary;
293 // however, for now we have a simplistic check:
295 // we currently have translations for only three locales; in the absence of a
296 // valid locale, default to the almighty en-US
297 if (locale != 'en-US' && locale != 'fr-CA' && locale != 'fi-FI') {
301 // grab the right tooltip based on MARC type
302 var tooltip_doc = 'marcedit-tooltips.xml';
303 switch (window.xulG.record.rtype) {
305 tooltip_doc = 'marcedit-tooltips.xml';
308 tooltip_doc = 'marcedit-tooltips-authority.xml';
309 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
312 tooltip_doc = 'marcedit-tooltips-mfhd.xml';
313 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
316 tooltip_doc = 'marcedit-tooltips.xml';
319 // Get the locale-specific tooltips
320 req.open('GET','/xul/server/locale/' + locale + '/' + tooltip_doc,true);
322 context_menus = createComplexXULElement('popupset');
323 document.documentElement.appendChild( context_menus );
325 tag_menu = createMenuPopup({position : 'after_start', id : 'tags_popup'});
326 context_menus.appendChild( tag_menu );
328 tag_menu.appendChild(
330 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
332 'var e = document.createEvent("KeyEvents");' +
333 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
334 'current_focus.inputField.dispatchEvent(e);'
339 tag_menu.appendChild(
341 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
343 'var e = document.createEvent("KeyEvents");' +
344 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
345 'current_focus.inputField.dispatchEvent(e);'
350 tag_menu.appendChild(
352 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
354 'var e = document.createEvent("KeyEvents");' +
355 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
356 'current_focus.inputField.dispatchEvent(e);'
361 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
363 tag_menu.appendChild(
365 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
367 'var e = document.createEvent("KeyEvents");' +
368 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,117,0);' +
369 'current_focus.inputField.dispatchEvent(e);'
374 tag_menu.appendChild(
376 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
378 'var e = document.createEvent("KeyEvents");' +
379 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,118,0);' +
380 'current_focus.inputField.dispatchEvent(e);'
385 tag_menu.appendChild(
387 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
389 'var e = document.createEvent("KeyEvents");' +
390 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,119,0);' +
391 'current_focus.inputField.dispatchEvent(e);'
396 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
398 p = createComplexXULElement('popupset');
399 document.documentElement.appendChild( p );
401 req.onreadystatechange = function () {
402 if (req.readyState == 4) {
403 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
411 if (! xulG.fast_add_item) {
412 document.getElementById('fastItemAdd_checkbox').hidden = true;
414 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
416 // Only show bib sources for bib records that already exist in the database
417 if (xulG.record.rtype == 'bre' && xulG.record.id) {
418 dojo.require('openils.PermaCrud');
419 var authtoken = ses();
420 // Retrieve the current record attributes
421 var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
423 // Remember the current bib source of the record
424 xulG.record.bre = bib;
426 buildBibSourceList(authtoken, xulG.record.id);
429 dojo.require('MARC.FixedFields');
432 alert('FIXME, MARC Editor, my_init: ' + E);
437 function createComplexHTMLElement (e, attrs, objects, text) {
438 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
441 for (var i in attrs) l.setAttribute(i,attrs[i]);
445 for ( var i in objects ) l.appendChild( objects[i] );
449 l.appendChild( document.createTextNode(text) )
455 function createComplexXULElement (e, attrs, objects) {
456 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
459 for (var i in attrs) {
460 if (typeof attrs[i] == 'function') {
461 l.addEventListener( i, attrs[i], true );
463 l.setAttribute(i,attrs[i]);
469 for ( var i in objects ) l.appendChild( objects[i] );
475 function createDescription (attrs) {
476 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
479 function createTooltip (attrs) {
480 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
483 function createLabel (attrs) {
484 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
487 function createVbox (attrs) {
488 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
491 function createHbox (attrs) {
492 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
495 function createRow (attrs) {
496 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
499 function createTextbox (attrs) {
500 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
503 function createMenu (attrs) {
504 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
507 function createMenuPopup (attrs) {
508 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
511 function createPopup (attrs) {
512 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
515 function createMenuitem (attrs) {
516 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
519 function createCheckbox (attrs) {
520 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
523 // Find the next textbox that we can use for a focus point
524 // For control fields, use the first editable text box
525 // For data fields, focus on the first subfield text box
526 function setFocusToNextTag (row, direction) {
527 var keep_looking = true;
528 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
529 // Is it a datafield?
530 dojo.query('hbox', row).query('hbox').query('textbox').forEach(function(node, index, arr) {
532 keep_looking = false;
535 // No, it's a control field; use the first textbox
537 dojo.query('textbox', row).forEach(function(node, index, arr) {
539 keep_looking = false;
547 function set_lock_on_keypress(ev) {
549 //dump('keypress: isChar = ' + ev.isChar + ' char = ' + ev.char + ' charCode = ' + ev.charCode + ' key = ' + ev.key + ' keyCode = ' + ev.keyCode + '\n');
554 || ev.keyCode == ev.DOM_VK_F1
555 || ev.keyCode == ev.DOM_VK_F2
556 || ev.keyCode == ev.DOM_VK_F3
557 || ev.keyCode == ev.DOM_VK_F4
558 || ev.keyCode == ev.DOM_VK_F5
559 || ev.keyCode == ev.DOM_VK_F6
560 || ev.keyCode == ev.DOM_VK_F7
561 || ev.keyCode == ev.DOM_VK_F8
562 || ev.keyCode == ev.DOM_VK_F9
563 || ev.keyCode == ev.DOM_VK_F10
564 || ev.keyCode == ev.DOM_VK_F11
565 || ev.keyCode == ev.DOM_VK_F12
566 || ev.keyCode == ev.DOM_VK_F13
567 || ev.keyCode == ev.DOM_VK_F14
568 || ev.keyCode == ev.DOM_VK_F15
569 || ev.keyCode == ev.DOM_VK_F16
570 || ev.keyCode == ev.DOM_VK_F17
571 || ev.keyCode == ev.DOM_VK_F18
572 || ev.keyCode == ev.DOM_VK_F19
573 || ev.keyCode == ev.DOM_VK_F20
574 || ev.keyCode == ev.DOM_VK_F21
575 || ev.keyCode == ev.DOM_VK_F22
576 || ev.keyCode == ev.DOM_VK_F23
577 || ev.keyCode == ev.DOM_VK_F24
586 function createMARCTextbox (element,attrs) {
588 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
589 box.addEventListener(
591 set_lock_on_keypress,
594 box.onkeypress = function (event) {
597 while(node = node.parent()) {
601 var row = event.target;
602 while (row.tagName != 'row') row = row.parentNode;
604 if (element.nodeKind() == 'attribute') element[0]=box.value;
605 else element.setChildren( box.value );
607 if (element.localName() != 'controlfield') {
608 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
610 var index_sf, target, move_data;
611 if (element.localName() == 'subfield') {
613 target = event.target.parentNode;
615 var start = event.target.selectionStart;
616 var end = event.target.selectionEnd - event.target.selectionStart ?
617 event.target.selectionEnd :
618 event.target.value.length;
620 move_data = event.target.value.substring(start,end);
621 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
622 event.target.setAttribute('size', event.target.value.length + 2);
624 element.setChildren( event.target.value );
626 } else if (element.localName() == 'code') {
627 index_sf = element.parent();
628 target = event.target.parentNode;
629 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
630 index_sf = element.parent().children()[element.parent().children().length() - 1];
631 target = event.target.parentNode.lastChild.lastChild;
634 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
636 index_sf.parent().insertChildAfter( index_sf, sf );
638 var new_sf = marcSubfield(sf);
640 if (target === target.parentNode.lastChild) {
641 target.parentNode.appendChild( new_sf );
643 target.parentNode.insertBefore( new_sf, target.nextSibling );
646 new_sf.firstChild.nextSibling.focus();
648 event.preventDefault();
651 } else if (event.keyCode == 13 || event.keyCode == 77) {
652 if (event.ctrlKey) { // ctrl+enter
655 if (element.localName() == 'subfield') index = element.parent();
656 if (element.localName() == 'code') index = element.parent().parent();
657 if (element.localName() == 'tag') index = element.parent();
658 if (element.localName() == 'ind1') index = element.parent();
659 if (element.localName() == 'ind2') index = element.parent();
661 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
663 if (event.shiftKey) { // ctrl+shift+enter
664 index.parent().insertChildBefore( index, df );
666 index.parent().insertChildAfter( index, df );
669 var new_df = marcDatafield(df);
671 if (row.parentNode.lastChild === row) {
672 row.parentNode.appendChild( new_df );
674 if (event.shiftKey) { // ctrl+shift+enter
675 row.parentNode.insertBefore( new_df, row );
677 row.parentNode.insertBefore( new_df, row.nextSibling );
681 new_df.firstChild.focus();
683 event.preventDefault();
686 } else if (event.shiftKey) {
687 if (row.previousSibling.className.match('marcDatafieldRow'))
688 row.previousSibling.firstChild.focus();
690 row.nextSibling.firstChild.focus();
693 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
694 if (event.ctrlKey) { // CTRL key: copy the field
696 if (element.localName() == 'subfield') index = element.parent();
697 if (element.localName() == 'code') index = element.parent().parent();
698 if (element.localName() == 'tag') index = element.parent();
699 if (element.localName() == 'ind1') index = element.parent();
700 if (element.localName() == 'ind2') index = element.parent();
702 var copyField = index.copy();
704 if (event.keyCode == 38) { // ctrl+up-arrow
705 index.parent().insertChildBefore( index, copyField );
707 index.parent().insertChildAfter( index, copyField );
710 var new_df = marcDatafield(copyField);
712 if (row.parentNode.lastChild === row) {
713 row.parentNode.appendChild( new_df );
715 if (event.keyCode == 38) { // ctrl+up-arrow
716 row.parentNode.insertBefore( new_df, row );
717 } else { // ctrl+down-arrow
718 row.parentNode.insertBefore( new_df, row.nextSibling );
722 new_df.firstChild.focus();
724 event.preventDefault();
728 if (event.keyCode == 38) {
729 return setFocusToNextTag(row, 'up');
731 if (event.keyCode == 40) {
732 return setFocusToNextTag(row, 'down');
737 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
740 if (element.localName() == 'subfield') index = element.parent();
741 if (element.localName() == 'code') index = element.parent().parent();
742 if (element.localName() == 'tag') index = element.parent();
743 if (element.localName() == 'ind1') index = element.parent();
744 if (element.localName() == 'ind2') index = element.parent();
746 for (var i in index.parent().children()) {
747 if (index === index.parent().children()[i]) {
748 delete index.parent().children()[i];
753 row.previousSibling.firstChild.focus();
754 row.parentNode.removeChild(row);
756 event.preventDefault();
759 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
762 if (element.localName() == 'subfield') index = element;
763 if (element.localName() == 'code') index = element.parent();
766 for (var i in index.parent().children()) {
767 if (index === index.parent().children()[i]) {
768 delete index.parent().children()[i];
773 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
774 event.target.parentNode.previousSibling.lastChild.focus();
776 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
779 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
781 event.preventDefault();
784 } else if (event.keyCode == 117 && event.ctrlKey) { // ctrl + F6
786 createControlField('006',' ');
788 } else if (event.keyCode == 118 && event.ctrlKey) { // ctrl + F7
790 createControlField('007',' ');
792 } else if (event.keyCode == 119 && event.ctrlKey) { // ctrl + F8
794 createControlField('008', get_new_008());
800 } else { // event on a control field
801 if (event.keyCode == 38) {
802 return setFocusToNextTag(row, 'up');
803 } else if (event.keyCode == 40) {
804 return setFocusToNextTag(row, 'down');
809 box.addEventListener(
812 if (element.nodeKind() == 'attribute') element[0]=box.value;
813 else element.setChildren( box.value );
819 box.addEventListener(
822 if (element.nodeKind() == 'attribute') element[0]=box.value;
823 else element.setChildren( box.value );
829 box.addEventListener(
832 if (element.nodeKind() == 'attribute') element[0]=box.value;
833 else element.setChildren( box.value );
839 // 'input' event catches the box value after the keypress
840 box.addEventListener(
843 if (element.nodeKind() == 'attribute') element[0]=box.value;
844 else element.setChildren( box.value );
850 box.addEventListener(
853 if (element.localName() == 'controlfield')
854 eval('fillFixedFields();');
862 function toggleFFE () {
863 var grid = document.getElementById('leaderGrid');
872 function changeFFEditor (type) {
873 var grid = document.getElementById('leaderGrid');
874 grid.setAttribute('type',type);
875 document.getElementById('recordTypeLabel').setAttribute('value',type);
877 // Hide FFEditor rows that we don't need for our current type
878 // If all of the labels for a given row do not include our
879 // desired type in their set attribute, we can hide that row
880 dojo.query('rows', grid).query('row').forEach(function(node, index, arr) {
881 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
888 function fillFixedFields () {
890 var grid = document.getElementById('leaderGrid');
891 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
894 var pre_list = grid.getElementsByTagName('label');
895 for (var i in pre_list) {
896 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
897 list.push( pre_list[i] );
901 for (var i in list) {
902 var name = list[i].getAttribute('name');
903 var value = marc_rec.extractFixedField(name, true);
905 if (value === null) continue;
907 list[i].nextSibling.value = value;
912 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
916 function updateFixedFields (element) {
917 var grid = document.getElementById('leaderGrid');
918 var recGrid = document.getElementById('recGrid');
919 var new_value = element.value;
920 // Don't take focus away/adjust the record on partial changes
921 var length = element.getAttribute('maxlength');
922 if(new_value.length < length) return true;
924 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
925 marc_rec.setFixedField(element.getAttribute('name'), new_value);
927 var xml_string = marc_rec.toXmlString();
928 xml_record = new XML( xml_string );
929 if (xml_record..record[0]) xml_record = xml_record..record[0];
931 // Put the cursor back to the current fixed field
937 function marcLeader (leader) {
939 { class : 'marcLeaderRow',
944 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
947 class : 'marcInd1' } ),
950 class : 'marcInd2' } ),
952 { value : leader.text(),
953 class : 'marcLeader' } )
959 function marcControlfield (field) {
960 tagname = field.@tag.toString().substr(2);
962 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
964 { class : 'marcControlfieldRow',
965 tag : '_' + tagname },
967 { value : field.@tag,
969 context : 'tags_popup',
970 onmouseover : 'getTooltip(this, "tag");',
971 tooltipid : 'tag' + field.@tag } ),
973 { value : field.@ind1,
975 onmouseover : 'getTooltip(this, "ind1");',
976 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
978 { value : field.@ind2,
980 onmouseover : 'getTooltip(this, "ind2");',
981 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
984 { value : field.text(),
985 class : 'plain marcEditableControlfield',
986 name : 'CONTROL' + tagname,
987 context : 'clipboard',
993 { class : 'marcControlfieldRow',
994 tag : '_' + tagname },
996 { value : field.@tag,
998 onmouseover : 'getTooltip(this, "tag");',
999 tooltipid : 'tag' + field.@tag } ),
1001 { value : field.@ind1,
1003 onmouseover : 'getTooltip(this, "ind1");',
1004 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1006 { value : field.@ind2,
1008 onmouseover : 'getTooltip(this, "ind2");',
1009 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1011 { value : field.text(),
1012 class : 'marcControlfield' } )
1019 function stackSubfields(checkbox) {
1020 var list = document.getElementsByAttribute('name','sf_box');
1023 if (!checkbox.checked) o = 'horizontal';
1025 for (var i = 0; i < list.length; i++) {
1026 if (list[i]) list[i].setAttribute('orient',o);
1030 function fastItemAdd_toggle(checkbox) {
1031 var x = document.getElementById('fastItemAdd_textboxes');
1032 if (checkbox.checked) {
1034 document.getElementById('fastItemAdd_callnumber').focus();
1035 document.getElementById('fastItemAdd_callnumber').select();
1041 function fastItemAdd_attempt(doc_id) {
1043 if (typeof window.xulG.fast_add_item != 'function') { return; }
1044 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
1045 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
1046 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
1047 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
1048 document.getElementById('fastItemAdd_barcode').value = '';
1051 alert('fastItemAdd_attempt: ' + E);
1055 function save_attempt(xml_string) {
1057 var result = window.xulG.save.func( xml_string );
1058 // I'd prefer to pass on_complete on through to fast_item_add,
1059 // but with the way these window scopes get destroyed with
1060 // tab replacement, maybe not a good idea
1061 var replace_on_complete = false;
1065 replace_on_complete = fastItemAdd_attempt(result.id);
1067 if (!replace_on_complete && typeof result.on_complete == 'function') {
1068 result.on_complete();
1072 alert('save_attempt: ' + E);
1076 function marcDatafield (field) {
1077 var row = createRow(
1078 { class : 'marcDatafieldRow' },
1081 { value : field.@tag,
1082 class : 'plain marcTag',
1084 context : 'tags_popup',
1085 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1088 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1091 { value : field.@ind1,
1092 class : 'plain marcInd1',
1094 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1097 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1098 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1101 { value : field.@ind2,
1102 class : 'plain marcInd2',
1104 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1107 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1108 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1109 createHbox({ name : 'sf_box' })
1112 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1113 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1114 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1116 var sf_box = row.lastChild;
1117 if (document.getElementById('stackSubfields').checked)
1118 sf_box.setAttribute('orient','vertical');
1120 sf_box.addEventListener(
1123 if (sf_box === e.target) {
1124 sf_box.lastChild.lastChild.focus();
1125 } else if (e.target.parentNode === sf_box) {
1126 e.target.lastChild.focus();
1133 for (var i in field.subfield) {
1134 var sf = field.subfield[i];
1139 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1141 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1142 current_focus = sf_box.lastChild.childNodes[1];
1148 function marcSubfield (sf) {
1150 { class : 'marcSubfieldBox' },
1153 class : 'plain marcSubfieldDelimiter',
1154 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1155 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1156 //onclick : 'this.nextSibling.focus();',
1157 onfocus : 'this.nextSibling.focus();',
1162 class : 'plain marcSubfieldCode',
1164 name : 'marcSubfieldCode',
1165 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1166 oncontextmenu : 'getContextMenu(this, "subfield");',
1167 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1172 { value : sf.text(),
1173 name : sf.parent().@tag + ':' + sf.@code,
1174 class : 'plain marcSubfield',
1176 onmouseover : 'getTooltip(this, "subfield");',
1177 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1178 size : new String(sf.text()).length + 2,
1179 oninput : "this.setAttribute('size', this.value.length + 2);"
1184 function loadRecord() {
1186 var grid_rows = document.getElementById('recGrid').lastChild;
1188 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1190 grid_rows.appendChild( marcLeader( xml_record.leader ) );
1192 for (var i in xml_record.controlfield) {
1193 grid_rows.appendChild( marcControlfield( xml_record.controlfield[i] ) );
1196 for (var i in xml_record.datafield) {
1197 grid_rows.appendChild( marcDatafield( xml_record.datafield[i] ) );
1200 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1202 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
1203 changeFFEditor(marc_rec.recordType());
1206 alert('FIXME, MARC Editor, loadRecord: ' + E);
1211 function genToolTips () {
1212 for (var i in bib_data.field) {
1213 var f = bib_data.field[i];
1215 tag_menu.appendChild(
1219 'current_focus.value = "' + f.@tag + '";' +
1220 'var e = document.createEvent("MutationEvents");' +
1221 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1222 'current_focus.inputField.dispatchEvent(e);',
1223 disabled : f.@tag < '010' ? "true" : "false",
1224 tooltiptext : f.description }
1228 var i1_popup = createMenuPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1229 context_menus.appendChild( i1_popup );
1231 var i2_popup = createMenuPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1232 context_menus.appendChild( i2_popup );
1234 var sf_popup = createMenuPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1235 context_menus.appendChild( sf_popup );
1237 tooltip_hash['tag' + f.@tag] = f.description;
1238 for (var j in f.indicator) {
1239 var ind = f.indicator[j];
1240 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1242 if (ind.@position == 1) {
1243 i1_popup.appendChild(
1245 { label : ind.@value,
1247 'current_focus.value = "' + ind.@value + '";' +
1248 'var e = document.createEvent("MutationEvents");' +
1249 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1250 'current_focus.inputField.dispatchEvent(e);',
1251 tooltiptext : ind.description }
1256 if (ind.@position == 2) {
1257 i2_popup.appendChild(
1259 { label : ind.@value,
1261 'current_focus.value = "' + ind.@value + '";' +
1262 'var e = document.createEvent("MutationEvents");' +
1263 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1264 'current_focus.inputField.dispatchEvent(e);',
1265 tooltiptext : ind.description }
1271 for (var j in f.subfield) {
1272 var sf = f.subfield[j];
1273 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1275 sf_popup.appendChild(
1279 'current_focus.value = "' + sf.@code + '";' +
1280 'var e = document.createEvent("MutationEvents");' +
1281 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1282 'current_focus.inputField.dispatchEvent(e);',
1283 tooltiptext : sf.description
1291 function getTooltip (target, type) {
1294 if (type == 'subfield')
1295 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1298 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1301 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1304 tt = 'tag' + target.parentNode.firstChild.value;
1306 if (!document.getElementById( tt )) {
1311 orient : 'vertical',
1312 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1313 class : 'tooltip' },
1314 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1319 target.tooltip = tt;
1323 function getContextMenu (target, type) {
1326 if (type == 'subfield')
1327 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1330 tt = 't' + target.parentNode.firstChild.value + 'i1';
1333 tt = 't' + target.parentNode.firstChild.value + 'i2';
1335 target.setAttribute('context', tt);
1341 'a' : { 100 : 'a' },
1342 'd' : { 100 : 'd' },
1343 'e' : { 100 : 'e' },
1347 'a' : { 110 : 'a' },
1351 'a' : { 111 : 'a' },
1355 'a' : { 130 : 'a' },
1359 'a' : { 130 : 'a' },
1363 'a' : { 100 : 'a' },
1367 'a' : { 110 : 'a' },
1371 'a' : { 111 : 'a' },
1375 'a' : { 130 : 'a' },
1376 'n' : { 130 : 'n' },
1380 'a' : { 100 : 'a' },
1381 'd' : { 100 : 'd' },
1382 'q' : { 100 : 'q' },
1386 'a' : { 110 : 'a' },
1390 'a' : { 111 : 'a' },
1391 'c' : { 111 : 'c' },
1395 'a' : { 130 : 'a' },
1399 'a' : { 100 : 'a' },
1403 'a' : { 110 : 'a' },
1407 'a' : { 111 : 'a' },
1411 'a' : { 130 : 'a' },
1415 'a' : { 100 : 'a' },
1416 'd' : { 100 : 'd' },
1417 'q' : { 100 : 'q' },
1418 't' : { 100 : 't' },
1445 'a' : { 110 : 'a' },
1446 'd' : { 110 : 'd' },
1447 't' : { 110 : 't' },
1474 'a' : { 111 : 'a' },
1475 'd' : { 111 : 'd' },
1476 't' : { 111 : 't' },
1503 'a' : { 130 : 'a' },
1507 'a' : { 148 : 'a' },
1508 'v' : { 148 : 'v' },
1509 'x' : { 148 : 'x' },
1510 'y' : { 148 : 'y' },
1514 'a' : { 150 : 'a' },
1515 'b' : { 150 : 'b' },
1542 'a' : { 151 : 'a' },
1569 'a' : { 155 : 'a' },
1597 function getAuthorityContextMenu (target, sf) {
1598 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1601 var old = dojo.byId( menu_id );
1603 page = auth_pages[menu_id];
1604 old.parentNode.removeChild(old);
1606 auth_pages[menu_id] = 0;
1609 var sf_popup = createMenuPopup({ id : menu_id, flex : 1 });
1611 sf_popup.addEventListener("popuphiding", function(event) {
1612 if (show_auth_menu) {
1613 show_auth_menu = false;
1614 getAuthorityContextMenu(target, sf);
1615 dojo.byId(menu_id).openPopup();
1619 context_menus.appendChild( sf_popup );
1622 dojo.forEach( acs.controlSetList(), function (acs_id) {
1623 if (acs.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
1626 if (!found_acs.length) {
1627 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1628 target.setAttribute('context', 'clipboard');
1632 if (sf.toString().replace(/\s*/, '')) {
1633 return browseAuthority(sf_popup, menu_id, target, sf, 20, page);
1639 /* Apply the complete 1xx */
1640 function applyFullAuthority ( target, ui_sf, e4x_sf ) {
1641 var new_vals = dojo.query('*[tag^="1"]', target);
1642 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1645 function applySelectedAuthority ( target, ui_sf, e4x_sf ) {
1646 var new_vals = target.getElementsByAttribute('checked','true');
1647 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1650 function applyAuthority ( target, ui_sf, e4x_sf, new_vals ) {
1651 var field = e4x_sf.parent();
1653 for (var i = 0; i < new_vals.length; i++) {
1655 var sf_list = field.subfield;
1656 for (var j in sf_list) {
1658 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1659 sf_list[j] = new_vals[i].getAttribute('value');
1660 new_vals[i].setAttribute('subfield','');
1666 for (var i = 0; i < new_vals.length; i++) {
1668 /* indicators for the authority datafield are carried over in the main entry linking subfield */
1669 if (new_vals[i].getAttribute('subfield') == '0') {
1670 field.@ind1 = new_vals[i].getAttribute('ind1');
1671 field.@ind2 = new_vals[i].getAttribute('ind2');
1674 if (!new_vals[i].getAttribute('subfield')) continue;
1676 var val = new_vals[i].getAttribute('value');
1678 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1679 sf.@code = new_vals[i].getAttribute('subfield');
1681 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1684 var row = marcDatafield( field );
1687 while (node.nodeName != 'row') {
1688 node = node.parentNode;
1691 node.parentNode.replaceChild( row, node );
1695 function validateAuthority (button) {
1696 var grid = document.getElementById('recGrid');
1697 var label = button.getAttribute('label');
1700 var rows = grid.lastChild.childNodes;
1701 for (var i = 0; i < rows.length; i++) {
1703 var tag = row.firstChild;
1706 dojo.forEach(acs.controlSetList(), function (acs_id) {
1708 var control_map = acs.controlSet(acs_id).control_map;
1710 if (!control_map[tag.value]) return;
1711 button.setAttribute('label', label + ' - ' + tag.value);
1713 var ind1 = tag.nextSibling;
1714 var ind2 = ind1.nextSibling;
1715 var subfields = ind2.nextSibling.childNodes;
1718 for (var j = 0; j < subfields.length; j++) {
1719 var sf = subfields[j];
1720 sf_list.push( [ sf.childNodes[1].value, sf.childNodes[2].value ] );
1723 var matches = acs.findMatchingAuthorities(
1726 'subfields' : sf_list
1730 // matches = [ { "$csetId" : [ ... ] } ]
1733 if (matches[0]) { // probably set
1734 for (var cset in matches[0]) {
1735 var arr = matches[0][cset];
1737 // protect against errant empty string values
1738 if (arr.length == 1 && arr[0] == '')
1747 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1748 for (var j = 0; j < subfields.length; j++) {
1749 var sf = subfields[j];
1751 dojo.removeClass(sf.childNodes[2], 'marcValidated');
1752 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
1754 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
1755 dojo.addClass(sf.childNodes[2], 'marcValidated');
1759 if (found) done = true;
1763 button.setAttribute('label', label);
1770 function validateBibField (tags, searches) {
1771 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1772 url += '¶m="tags"¶m=' + js2JSON(tags);
1773 url += '¶m="searches"¶m=' + js2JSON(searches);
1776 var req = new XMLHttpRequest();
1777 req.open('GET',url,false);
1785 function searchAuthority (term, tag, sf, limit) {
1786 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1787 url += '¶m="term"¶m="' + term + '"';
1788 url += '¶m="limit"¶m=' + limit;
1789 url += '¶m="tag"¶m=' + tag;
1790 url += '¶m="subfield"¶m="' + sf + '"';
1793 var req = new XMLHttpRequest();
1794 req.open('GET',url,false);
1801 /* TODO new authority browse support for context sets, and use that here */
1802 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
1803 dojo.require('dojox.xml.parser');
1805 // map tag + subfield to the appropriate authority browse axis:
1806 // currently authority.author, authority.subject, authority.title, authority.topic
1807 // based on mappings in OpenILS::Application::SuperCat, though Authority Control
1808 // Sets will change that
1810 var axis_list = acs.bibFieldBrowseAxes( sf.parent().@tag.toString() );
1812 // No matching tag means no authorities to search - shortcut
1813 if (axis_list.length == 0) {
1814 target.setAttribute('context', 'clipboard');
1818 var type = 'authority.' + axis_list[0]; // Just take the first for now
1819 // TODO support multiple axes ... loop?
1829 var sf_list = sf.parent().subfield;
1830 for ( var i in sf_list) {
1831 sf_string += sf_list[i].toString() + ' ';
1832 if (sf_list[i] === sf) break;
1835 var url = '/opac/extras/browse/marcxml/'
1837 + '/1' // OU - currently unscoped
1843 // would be good to carve this out into a separate function
1844 dojo.xhrGet({"url":url, "sync": true, "preventCache": true, "handleAs":"xml", "load": function(records) {
1845 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
1847 var cm_popup = create_menu.appendChild(
1851 cm_popup.appendChild(
1852 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
1853 command : function() {
1854 // Call middle-layer function to create and save the new authority
1855 var source_f = summarizeField(sf);
1856 var new_auth = fieldmapper.standardRequest(
1857 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
1858 [source_f, xulG.marc_control_number_identifier, ses()]
1860 if (new_auth && new_auth.id()) {
1861 addNewAuthorityID(new_auth, sf, target);
1867 cm_popup.appendChild(
1868 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
1869 command : function() {
1870 // Generate the new authority by calling the new middle-layer
1871 // function (a non-saving variant), then display in another
1873 var source_f = summarizeField(sf);
1874 var authtoken = ses();
1875 dojo.require('openils.PermaCrud');
1876 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
1877 var rec = fieldmapper.standardRequest(
1878 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
1879 { "params": [source_f, xulG.marc_control_number_identifier] }
1881 loadMarcEditor(pcrud, rec, target, sf);
1886 sf_popup.appendChild(create_menu);
1887 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1889 // append "Previous page" results browser
1890 sf_popup.appendChild(
1891 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
1892 command : function(event) {
1893 auth_pages[menu_id] -= 1;
1894 show_auth_menu = true;
1898 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1900 dojo.query('record', records).forEach(function(record) {
1904 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"]', record).query('subfield[code="c"]')[0]);
1906 if (dojo.query('controlfield[tag="003"]', record).length > 0) {
1907 auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
1910 // Grab the fields with tags beginning with 1 (main entries) and iterate through the subfields
1911 dojo.query('datafield[tag^="1"]', record).forEach(function(field) {
1912 dojo.query('subfield', field).forEach(function(subfield) {
1916 main_text += dojox.xml.parser.textContent(subfield);
1920 // Grab the fields with tags beginning with 4 (see from entries) and iterate through the subfields
1921 dojo.query('datafield[tag^="4"]', record).forEach(function(field) {
1923 dojo.query('subfield', field).forEach(function(subfield) {
1927 see_text += dojox.xml.parser.textContent(subfield);
1929 see_from.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_from', [see_text]));
1932 // Grab the fields with tags beginning with 5 (see also entries) and iterate through the subfields
1933 dojo.query('datafield[tag^="5"]', record).forEach(function(field) {
1935 dojo.query('subfield', field).forEach(function(subfield) {
1939 see_text += dojox.xml.parser.textContent(subfield);
1941 see_also.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_also', [see_text]));
1944 buildAuthorityPopup(main_text, record, auth_org, auth_id, sf_popup, target, sf);
1946 dojo.forEach(see_from, function(entry_text) {
1947 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1950 // To-do: instead of launching the standard selector menu, invoke
1951 // a new authority search using the 5XX entry text
1952 dojo.forEach(see_also, function(entry_text) {
1953 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1958 if (sf_popup.childNodes.length == 0) {
1959 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1961 // append "Next page" results browser
1962 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1963 sf_popup.appendChild(
1964 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
1965 command : function(event) {
1966 auth_pages[menu_id] += 1;
1967 show_auth_menu = true;
1973 target.setAttribute('context', menu_id);
1979 function buildAuthorityPopup (entry_text, record, auth_org, auth_id, sf_popup, target, sf, style) {
1980 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
1981 grid.setAttribute('name','-none-');
1982 grid.setAttribute('style','overflow:scroll');
1984 var submenu = createMenu( { "label": entry_text } );
1986 var popup = createMenuPopup({ "flex": "1" });
1988 submenu.setAttribute('style', style);
1989 popup.setAttribute('style', 'font-style: normal; margin-left: 0em;');
1991 submenu.appendChild(popup);
1993 dojo.query('datafield[tag^="1"]', record).forEach(function(field) {
1994 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1996 dojo.query('datafield[tag^="4"]', record).forEach(function(field) {
1997 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1999 dojo.query('datafield[tag^="5"]', record).forEach(function(field) {
2000 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
2003 grid.hidden = false;
2004 popup.appendChild( grid );
2008 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
2009 command : function (event) {
2010 applySelectedAuthority(event.target.previousSibling, target, sf);
2017 popup.appendChild( createComplexXULElement( 'menuseparator' ) );
2021 { label : $('catStrings').getString('staff.cat.marcedit.apply_full.label'),
2022 command : function (event) {
2023 applyFullAuthority(event.target.previousSibling.previousSibling.previousSibling, target, sf);
2030 sf_popup.appendChild( submenu );
2033 function buildAuthorityPopupSelector (field, grid, auth_org, auth_id) {
2034 var row = createRow(
2036 createLabel( { "value" : dojo.attr(field, 'tag') } ),
2037 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
2038 createLabel( { "value" : dojo.attr(field, 'ind2') } )
2041 var sf_box = createHbox();
2042 dojo.query('subfield', field).forEach(function(subfield) {
2045 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
2046 "subfield" : dojo.attr(subfield, 'code'),
2047 "tag" : dojo.attr(field, 'tag'),
2048 "value" : dojox.xml.parser.textContent(subfield)
2052 row.appendChild(sf_box);
2055 // Append the authority linking subfield only for main entries
2056 if (dojo.attr(field, 'tag').charAt(0) == '1') {
2059 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
2061 "tag" : dojo.attr(field, 'tag'),
2062 "ind1" : dojo.attr(field, 'ind1'),
2063 "ind2" : dojo.attr(field, 'ind2'),
2064 "value" : '(' + auth_org + ')' + auth_id
2069 row.appendChild(sf_box);
2071 grid.lastChild.appendChild(row);
2074 function summarizeField(sf) {
2082 source_f.tag = sf.parent().@tag.toString();
2083 source_f.ind1 = sf.parent().@ind1.toString();
2084 source_f.ind2 = sf.parent().@ind2.toString();
2087 dojo.forEach( acs.controlSetList(), function (acs_id) {
2088 if (acs.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
2092 if (!found_acs.length) {
2095 cmap = acs.controlSet(found_acs[0]).control_map;
2098 for (var i = 0; i < sf.parent().subfield.length(); i++) {
2099 var sf_iter = sf.parent().subfield[i];
2101 /* Filter out subfields that are not controlled for this tag */
2102 if (!cmap[source_f.tag][sf_iter.@code.toString()]) {
2106 source_f.subfields.push([sf_iter.@code.toString(), sf_iter.toString()]);
2112 function buildBibSourceList (authtoken, recId) {
2113 /* TODO: Work out how to set the bib source of the bre that does not yet
2114 * exist - this is specifically in the case of Z39.50 imports. Right now
2115 * we just avoid populating and showing the config.bib_source list
2121 var bib = xulG.record.bre;
2123 dojo.require('openils.PermaCrud');
2125 // cbsList = the XUL menulist that contains the available bib sources
2126 var cbsList = dojo.byId('bib-source-list');
2128 // bibSources = an array containing all of the bib source objects
2129 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
2131 // A tad ugly, but gives us the index of the bib source ID in cbsList
2133 var cbsListArr = [];
2134 dojo.forEach(bibSources, function (item) {
2135 cbsList.appendItem(item.source(), item.id());
2136 cbsListArr[item.id()] = x;
2140 // Show the current value of the bib source for this record
2141 cbsList.selectedIndex = cbsListArr[bib.source()];
2143 // Display the bib source selection widget
2144 dojo.byId('bib-source-list-caption').hidden = false;
2145 dojo.byId('bib-source-list').hidden = false;
2146 dojo.byId('bib-source-list-button').disabled = true;
2147 dojo.byId('bib-source-list-button').hidden = false;
2150 // Fired when the "Update Source" button is clicked
2151 // Updates the value of the bib source for the current record
2152 function updateBibSource() {
2153 var authtoken = ses();
2154 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2155 var recId = xulG.record.id;
2156 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2157 var bib = pcrud.retrieve('bre', recId);
2158 if (bib.source() != cbs) {
2160 bib.ischanged = true;
2165 function onBibSourceSelect() {
2166 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2167 var bib = xulG.record.bre;
2168 if (bib.source() != cbs) {
2169 dojo.byId('bib-source-list-button').disabled = false;
2171 dojo.byId('bib-source-list-button').disabled = true;
2175 function addNewAuthorityID(authority, sf, target) {
2176 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){authority.id()}</subfield>;
2177 sf.parent().appendChild(id_sf);
2178 var new_sf = marcSubfield(id_sf);
2181 while (dojo.attr(node, 'name') != 'sf_box') {
2182 node = node.parentNode;
2184 node.appendChild( new_sf );
2186 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2189 function loadMarcEditor(pcrud, marcxml, target, sf) {
2191 To run in Firefox directly, must set signed.applets.codebase_principal_support
2192 to true in about:config
2194 win = window.open('/xul/server/cat/marcedit.xul', '_blank', 'chrome'); // XXX version?
2196 // Match marc2are.pl last_xact_id format, roughly
2198 var xact_id = 'IMPORT-' + Date.parse(now);
2201 "record": {"marc": marcxml, "rtype": "are"},
2203 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2204 "func": function(xmlString) {
2205 var rec = new are();
2206 rec.marc(xmlString);
2207 rec.last_xact_id(xact_id);
2210 "oncomplete": function (r, objs) {
2211 var new_rec = objs[0];
2216 addNewAuthorityID(new_rec, sf, target);