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 // We need whitespace in MARC fields, so disable ignoring it
22 XML.ignoreWhitespace = false;
23 // Pretty printing kills whitespace too, so disable it.
24 XML.prettyPrinting = false;
25 var xmlDeclaration = /^<\?xml version[^>]+?>/;
27 var serializer = new XMLSerializer();
28 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
29 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
30 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
31 default xml namespace = marcns;
33 var tooltip_hash = {};
45 var show_auth_menu = false;
47 function $(id) { return document.getElementById(id); }
49 var acs; // AuthorityControlSet
51 function mangle_005() {
53 var y = now.getUTCFullYear();
55 var m = now.getUTCMonth() + 1;
56 if (m < 10) m = '0' + m;
58 var d = now.getUTCDate();
59 if (d < 10) d = '0' + d;
61 var H = now.getUTCHours();
62 if (H < 10) H = '0' + H;
64 var M = now.getUTCMinutes();
65 if (M < 10) M = '0' + M;
67 var S = now.getUTCSeconds();
68 if (S < 10) S = '0' + S;
71 var stamp = '' + y + m + d + H + M + S + '.0';
72 createControlField('005',stamp);
76 function createControlField (tag,data) {
77 // first, remove the old field, if any;
78 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
80 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
83 // then, find the right position and insert it
85 var cfields = xml_record.controlfield;
86 var base = Number(tag.substring(2));
87 for (var i in cfields) {
88 var t = Number(cfields[i].@tag.toString().substring(2));
90 xml_record.insertChildBefore( cfields[i], cf );
96 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
101 function xml_escape_unicode ( str ) {
103 /([\u0080-\ufffe])/g,
104 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
108 function wrap_long_fields (node) {
109 var text_size = dojo.attr(node, 'size');
110 var hard_width = 100;
111 if (text_size > hard_width) {
112 dojo.attr(node, 'multiline', 'true');
113 dojo.attr(node, 'cols', hard_width);
114 var text_rows = (text_size / hard_width) + 1;
115 dojo.attr(node, 'rows', text_rows);
119 function set_flat_editor (useFlatText) {
121 var xe = $('xul-editor');
122 var te = $('text-editor');
125 if (xe.hidden) { return; }
129 if (te.hidden) { return; }
135 // get the marcxml from the text box
136 var xml_string = new MARC.Record({
137 marcbreaker : $('text-editor-box').value,
141 // reset the xml record and rerender it
142 xml_record = new XML( xml_string );
143 if (xml_record..record[0]) xml_record = xml_record..record[0];
146 var xml_string = xml_record.toXMLString();
148 // push the xml record into the textbox
149 var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
150 $('text-editor-box').value = rec.toBreaker();
157 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
158 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
159 JSAN.errorLevel = "die"; // none, warn, or die
160 JSAN.addRepository('/xul/server/');
162 dojo.require('openils.AuthorityControlSet');
163 acs = new openils.AuthorityControlSet ();
165 // Fake xulG for standalone...
170 window.xulG.record = {};
171 window.xulG.save = {};
172 window.xulG.marc_control_number_identifier = 'CONS';
174 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
175 window.xulG.save.func = function (r) { alert(r); }
178 var _rid = cgi.param('record');
180 window.xulG.record.id = _rid;
181 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
185 // End faking part...
187 /* Check for an explicitly passed record type
188 * This is not the same as the fixed-field record type; we can't trust
189 * the fixed fields when making modifications to the attributes for a
190 * given record (in particular, config.bib_source only applies for bib
191 * records, but an auth or MFHD record with the same ID and bad fixed
192 * fields could trample the config.bib_source value for the
193 * corresponding bib record if we're not careful.
195 * are = authority record
196 * sre = serial record (MFHD)
197 * bre = bibliographic record
199 if (!window.xulG.record.rtype) {
201 window.xulG.record.rtype = cgi.param('rtype') || false;
204 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
205 document.getElementById('save-button').setAttribute('oncommand',
206 'if ($("xul-editor").hidden) set_flat_editor(false); ' +
208 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
209 'save_attempt( xml_string ); ' +
213 if (window.xulG.record.url) {
214 var req = new XMLHttpRequest();
215 req.open('POST',window.xulG.record.url,false);
217 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
220 xml_record = new XML( window.xulG.record.marc );
221 if (xml_record..record[0]) xml_record = xml_record..record[0];
223 // Get the tooltip xml all async like
224 req = new XMLHttpRequest();
226 // Set a default locale in case preferences fail us
227 var locale = "en-US";
229 // Try to get the locale from our preferences
230 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
232 const Cc = Components.classes;
233 const Ci = Components.interfaces;
234 locale = Cc["@mozilla.org/preferences-service;1"].
235 getService(Ci.nsIPrefBranch).
236 getCharPref("general.useragent.locale");
240 // TODO: We should send a HEAD request to check for the existence of the desired file
241 // then fall back to the default locale if preferred locale is not necessary;
242 // however, for now we have a simplistic check:
244 // we currently have translations for only two locales; in the absence of a
245 // valid locale, default to the almighty en-US
246 if (locale != 'en-US' && locale != 'fr-CA') {
250 // grab the right tooltip based on MARC type
251 var tooltip_doc = 'marcedit-tooltips.xml';
252 switch (window.xulG.record.rtype) {
254 tooltip_doc = 'marcedit-tooltips.xml';
257 tooltip_doc = 'marcedit-tooltips-authority.xml';
258 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
261 tooltip_doc = 'marcedit-tooltips-mfhd.xml';
262 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
265 tooltip_doc = 'marcedit-tooltips.xml';
268 // Get the locale-specific tooltips
269 req.open('GET','/xul/server/locale/' + locale + '/' + tooltip_doc,true);
271 context_menus = createComplexXULElement('popupset');
272 document.documentElement.appendChild( context_menus );
274 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
275 context_menus.appendChild( tag_menu );
277 tag_menu.appendChild(
279 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
281 'var e = document.createEvent("KeyEvents");' +
282 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
283 'current_focus.inputField.dispatchEvent(e);'
288 tag_menu.appendChild(
290 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
292 'var e = document.createEvent("KeyEvents");' +
293 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
294 'current_focus.inputField.dispatchEvent(e);'
299 tag_menu.appendChild(
301 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
303 'var e = document.createEvent("KeyEvents");' +
304 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
305 'current_focus.inputField.dispatchEvent(e);'
310 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
312 tag_menu.appendChild(
314 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
316 'var e = document.createEvent("KeyEvents");' +
317 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
318 'current_focus.inputField.dispatchEvent(e);'
323 tag_menu.appendChild(
325 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
327 'var e = document.createEvent("KeyEvents");' +
328 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
329 'current_focus.inputField.dispatchEvent(e);'
334 tag_menu.appendChild(
336 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
338 'var e = document.createEvent("KeyEvents");' +
339 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
340 'current_focus.inputField.dispatchEvent(e);'
345 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
347 p = createComplexXULElement('popupset');
348 document.documentElement.appendChild( p );
350 req.onreadystatechange = function () {
351 if (req.readyState == 4) {
352 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
360 if (! xulG.fast_add_item) {
361 document.getElementById('fastItemAdd_checkbox').hidden = true;
363 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
365 // Only show bib sources for bib records that already exist in the database
366 if (xulG.record.rtype == 'bre' && xulG.record.id) {
367 dojo.require('openils.PermaCrud');
368 var authtoken = ses();
369 // Retrieve the current record attributes
370 var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
372 // Remember the current bib source of the record
373 xulG.record.bre = bib;
375 buildBibSourceList(authtoken, xulG.record.id);
378 dojo.require('MARC.FixedFields');
381 alert('FIXME, MARC Editor, my_init: ' + E);
386 function createComplexHTMLElement (e, attrs, objects, text) {
387 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
390 for (var i in attrs) l.setAttribute(i,attrs[i]);
394 for ( var i in objects ) l.appendChild( objects[i] );
398 l.appendChild( document.createTextNode(text) )
404 function createComplexXULElement (e, attrs, objects) {
405 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
408 for (var i in attrs) {
409 if (typeof attrs[i] == 'function') {
410 l.addEventListener( i, attrs[i], true );
412 l.setAttribute(i,attrs[i]);
418 for ( var i in objects ) l.appendChild( objects[i] );
424 function createDescription (attrs) {
425 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
428 function createTooltip (attrs) {
429 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
432 function createLabel (attrs) {
433 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
436 function createVbox (attrs) {
437 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
440 function createHbox (attrs) {
441 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
444 function createRow (attrs) {
445 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
448 function createTextbox (attrs) {
449 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
452 function createMenu (attrs) {
453 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
456 function createMenuPopup (attrs) {
457 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
460 function createPopup (attrs) {
461 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
464 function createMenuitem (attrs) {
465 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
468 function createCheckbox (attrs) {
469 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
472 // Find the next textbox that we can use for a focus point
473 // For control fields, use the first editable text box
474 // For data fields, focus on the first subfield text box
475 function setFocusToNextTag (row, direction) {
476 var keep_looking = true;
477 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
478 // Is it a datafield?
479 dojo.query('hbox hbox textbox', row).forEach(function(node, index, arr) {
481 keep_looking = false;
484 // No, it's a control field; use the first textbox
486 dojo.query('textbox', row).forEach(function(node, index, arr) {
488 keep_looking = false;
497 function createMARCTextbox (element,attrs) {
499 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
500 box.addEventListener('keypress',function(ev) { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); if (!(ev.altKey || ev.ctrlKey || ev.metaKey)) { oils_lock_page(); } },false);
501 box.onkeypress = function (event) {
504 while(node = node.parent()) {
508 var row = event.target;
509 while (row.tagName != 'row') row = row.parentNode;
511 if (element.nodeKind() == 'attribute') element[0]=box.value;
512 else element.setChildren( box.value );
514 if (element.localName() != 'controlfield') {
515 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
517 var index_sf, target, move_data;
518 if (element.localName() == 'subfield') {
520 target = event.target.parentNode;
522 var start = event.target.selectionStart;
523 var end = event.target.selectionEnd - event.target.selectionStart ?
524 event.target.selectionEnd :
525 event.target.value.length;
527 move_data = event.target.value.substring(start,end);
528 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
529 event.target.setAttribute('size', event.target.value.length + 2);
531 element.setChildren( event.target.value );
533 } else if (element.localName() == 'code') {
534 index_sf = element.parent();
535 target = event.target.parentNode;
536 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
537 index_sf = element.parent().children()[element.parent().children().length() - 1];
538 target = event.target.parentNode.lastChild.lastChild;
541 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
543 index_sf.parent().insertChildAfter( index_sf, sf );
545 var new_sf = marcSubfield(sf);
547 if (target === target.parentNode.lastChild) {
548 target.parentNode.appendChild( new_sf );
550 target.parentNode.insertBefore( new_sf, target.nextSibling );
553 new_sf.firstChild.nextSibling.focus();
555 event.preventDefault();
558 } else if (event.keyCode == 13 || event.keyCode == 77) {
559 if (event.ctrlKey) { // ctrl+enter
562 if (element.localName() == 'subfield') index = element.parent();
563 if (element.localName() == 'code') index = element.parent().parent();
564 if (element.localName() == 'tag') index = element.parent();
565 if (element.localName() == 'ind1') index = element.parent();
566 if (element.localName() == 'ind2') index = element.parent();
568 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
570 if (event.shiftKey) { // ctrl+shift+enter
571 index.parent().insertChildBefore( index, df );
573 index.parent().insertChildAfter( index, df );
576 var new_df = marcDatafield(df);
578 if (row.parentNode.lastChild === row) {
579 row.parentNode.appendChild( new_df );
581 if (event.shiftKey) { // ctrl+shift+enter
582 row.parentNode.insertBefore( new_df, row );
584 row.parentNode.insertBefore( new_df, row.nextSibling );
588 new_df.firstChild.focus();
590 event.preventDefault();
593 } else if (event.shiftKey) {
594 if (row.previousSibling.className.match('marcDatafieldRow'))
595 row.previousSibling.firstChild.focus();
597 row.nextSibling.firstChild.focus();
600 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
601 if (event.ctrlKey) { // CTRL key: copy the field
603 if (element.localName() == 'subfield') index = element.parent();
604 if (element.localName() == 'code') index = element.parent().parent();
605 if (element.localName() == 'tag') index = element.parent();
606 if (element.localName() == 'ind1') index = element.parent();
607 if (element.localName() == 'ind2') index = element.parent();
609 var copyField = index.copy();
611 if (event.keyCode == 38) { // ctrl+up-arrow
612 index.parent().insertChildBefore( index, copyField );
614 index.parent().insertChildAfter( index, copyField );
617 var new_df = marcDatafield(copyField);
619 if (row.parentNode.lastChild === row) {
620 row.parentNode.appendChild( new_df );
622 if (event.keyCode == 38) { // ctrl+up-arrow
623 row.parentNode.insertBefore( new_df, row );
624 } else { // ctrl+down-arrow
625 row.parentNode.insertBefore( new_df, row.nextSibling );
629 new_df.firstChild.focus();
631 event.preventDefault();
635 if (event.keyCode == 38) {
636 return setFocusToNextTag(row, 'up');
638 if (event.keyCode == 40) {
639 return setFocusToNextTag(row, 'down');
644 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
647 if (element.localName() == 'subfield') index = element.parent();
648 if (element.localName() == 'code') index = element.parent().parent();
649 if (element.localName() == 'tag') index = element.parent();
650 if (element.localName() == 'ind1') index = element.parent();
651 if (element.localName() == 'ind2') index = element.parent();
653 for (var i in index.parent().children()) {
654 if (index === index.parent().children()[i]) {
655 delete index.parent().children()[i];
660 row.previousSibling.firstChild.focus();
661 row.parentNode.removeChild(row);
663 event.preventDefault();
666 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
669 if (element.localName() == 'subfield') index = element;
670 if (element.localName() == 'code') index = element.parent();
673 for (var i in index.parent().children()) {
674 if (index === index.parent().children()[i]) {
675 delete index.parent().children()[i];
680 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
681 event.target.parentNode.previousSibling.lastChild.focus();
683 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
686 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
688 event.preventDefault();
691 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
692 createControlField('006',' ');
694 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
695 createControlField('007',' ');
697 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
698 createControlField('008',' ');
704 } else { // event on a control field
705 if (event.keyCode == 38) {
706 return setFocusToNextTag(row, 'up');
707 } else if (event.keyCode == 40) {
708 return setFocusToNextTag(row, 'down');
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 box.addEventListener(
736 if (element.nodeKind() == 'attribute') element[0]=box.value;
737 else element.setChildren( box.value );
743 // 'input' event catches the box value after the keypress
744 box.addEventListener(
747 if (element.nodeKind() == 'attribute') element[0]=box.value;
748 else element.setChildren( box.value );
754 box.addEventListener(
757 if (element.localName() == 'controlfield')
758 eval('fillFixedFields();');
766 function toggleFFE () {
767 var grid = document.getElementById('leaderGrid');
776 function changeFFEditor (type) {
777 var grid = document.getElementById('leaderGrid');
778 grid.setAttribute('type',type);
779 document.getElementById('recordTypeLabel').setAttribute('value',type);
781 // Hide FFEditor rows that we don't need for our current type
782 // If all of the labels for a given row do not include our
783 // desired type in their set attribute, we can hide that row
784 dojo.query('rows row', grid).forEach(function(node, index, arr) {
785 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
792 function fillFixedFields () {
794 var grid = document.getElementById('leaderGrid');
795 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
798 var pre_list = grid.getElementsByTagName('label');
799 for (var i in pre_list) {
800 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
801 list.push( pre_list[i] );
805 for (var i in list) {
806 var name = list[i].getAttribute('name');
807 var value = marc_rec.extractFixedField(name, true);
809 if (value === null) continue;
811 list[i].nextSibling.value = value;
816 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
820 function updateFixedFields (element) {
821 var grid = document.getElementById('leaderGrid');
822 var recGrid = document.getElementById('recGrid');
823 var new_value = element.value;
824 // Don't take focus away/adjust the record on partial changes
825 var length = element.getAttribute('maxlength');
826 if(new_value.length < length) return true;
828 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
829 marc_rec.setFixedField(element.getAttribute('name'), new_value);
831 var xml_string = marc_rec.toXmlString();
832 xml_record = new XML( xml_string );
833 if (xml_record..record[0]) xml_record = xml_record..record[0];
839 function marcLeader (leader) {
841 { class : 'marcLeaderRow',
846 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
849 class : 'marcInd1' } ),
852 class : 'marcInd2' } ),
854 { value : leader.text(),
855 class : 'marcLeader' } )
861 function marcControlfield (field) {
862 tagname = field.@tag.toString().substr(2);
864 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
866 { class : 'marcControlfieldRow',
867 tag : '_' + tagname },
869 { value : field.@tag,
871 context : 'tags_popup',
872 onmouseover : 'getTooltip(this, "tag");',
873 tooltipid : 'tag' + field.@tag } ),
875 { value : field.@ind1,
877 onmouseover : 'getTooltip(this, "ind1");',
878 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
880 { value : field.@ind2,
882 onmouseover : 'getTooltip(this, "ind2");',
883 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
886 { value : field.text(),
887 class : 'plain marcEditableControlfield',
888 name : 'CONTROL' + tagname,
889 context : 'clipboard',
895 { class : 'marcControlfieldRow',
896 tag : '_' + tagname },
898 { value : field.@tag,
900 onmouseover : 'getTooltip(this, "tag");',
901 tooltipid : 'tag' + field.@tag } ),
903 { value : field.@ind1,
905 onmouseover : 'getTooltip(this, "ind1");',
906 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
908 { value : field.@ind2,
910 onmouseover : 'getTooltip(this, "ind2");',
911 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
913 { value : field.text(),
914 class : 'marcControlfield' } )
921 function stackSubfields(checkbox) {
922 var list = document.getElementsByAttribute('name','sf_box');
925 if (!checkbox.checked) o = 'horizontal';
927 for (var i = 0; i < list.length; i++) {
928 if (list[i]) list[i].setAttribute('orient',o);
932 function fastItemAdd_toggle(checkbox) {
933 var x = document.getElementById('fastItemAdd_textboxes');
934 if (checkbox.checked) {
936 document.getElementById('fastItemAdd_callnumber').focus();
937 document.getElementById('fastItemAdd_callnumber').select();
943 function fastItemAdd_attempt(doc_id) {
945 if (typeof window.xulG.fast_add_item != 'function') { return; }
946 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
947 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
948 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
949 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
950 document.getElementById('fastItemAdd_barcode').value = '';
952 alert('fastItemAdd_attempt: ' + E);
956 function save_attempt(xml_string) {
958 var result = window.xulG.save.func( xml_string );
961 if (result.id) fastItemAdd_attempt(result.id);
962 if (typeof result.on_complete == 'function') result.on_complete();
965 alert('save_attempt: ' + E);
969 function marcDatafield (field) {
971 { class : 'marcDatafieldRow' },
974 { value : field.@tag,
975 class : 'plain marcTag',
977 context : 'tags_popup',
978 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
981 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
984 { value : field.@ind1,
985 class : 'plain marcInd1',
987 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
990 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
991 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
994 { value : field.@ind2,
995 class : 'plain marcInd2',
997 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1000 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1001 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1002 createHbox({ name : 'sf_box' })
1005 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1006 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1007 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1009 var sf_box = row.lastChild;
1010 if (document.getElementById('stackSubfields').checked)
1011 sf_box.setAttribute('orient','vertical');
1013 sf_box.addEventListener(
1016 if (sf_box === e.target) {
1017 sf_box.lastChild.lastChild.focus();
1018 } else if (e.target.parentNode === sf_box) {
1019 e.target.lastChild.focus();
1026 for (var i in field.subfield) {
1027 var sf = field.subfield[i];
1032 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1034 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1035 current_focus = sf_box.lastChild.childNodes[1];
1041 function marcSubfield (sf) {
1043 { class : 'marcSubfieldBox' },
1046 class : 'plain marcSubfieldDelimiter',
1047 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1048 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1049 //onclick : 'this.nextSibling.focus();',
1050 onfocus : 'this.nextSibling.focus();',
1055 class : 'plain marcSubfieldCode',
1056 name : 'marcSubfieldCode',
1057 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1058 oncontextmenu : 'getContextMenu(this, "subfield");',
1059 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1064 { value : sf.text(),
1065 name : sf.parent().@tag + ':' + sf.@code,
1066 class : 'plain marcSubfield',
1067 onmouseover : 'getTooltip(this, "subfield");',
1068 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1069 size : new String(sf.text()).length + 2,
1070 oninput : "this.setAttribute('size', this.value.length + 2);"
1075 function loadRecord() {
1077 var grid_rows = document.getElementById('recGrid').lastChild;
1079 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1081 grid_rows.appendChild( marcLeader( xml_record.leader ) );
1083 for (var i in xml_record.controlfield) {
1084 grid_rows.appendChild( marcControlfield( xml_record.controlfield[i] ) );
1087 for (var i in xml_record.datafield) {
1088 grid_rows.appendChild( marcDatafield( xml_record.datafield[i] ) );
1091 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1093 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
1094 changeFFEditor(marc_rec.recordType());
1097 alert('FIXME, MARC Editor, loadRecord: ' + E);
1102 function genToolTips () {
1103 for (var i in bib_data.field) {
1104 var f = bib_data.field[i];
1106 tag_menu.appendChild(
1110 'current_focus.value = "' + f.@tag + '";' +
1111 'var e = document.createEvent("MutationEvents");' +
1112 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1113 'current_focus.inputField.dispatchEvent(e);',
1114 disabled : f.@tag < '010' ? "true" : "false",
1115 tooltiptext : f.description }
1119 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1120 context_menus.appendChild( i1_popup );
1122 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1123 context_menus.appendChild( i2_popup );
1125 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1126 context_menus.appendChild( sf_popup );
1128 tooltip_hash['tag' + f.@tag] = f.description;
1129 for (var j in f.indicator) {
1130 var ind = f.indicator[j];
1131 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1133 if (ind.@position == 1) {
1134 i1_popup.appendChild(
1136 { label : ind.@value,
1138 'current_focus.value = "' + ind.@value + '";' +
1139 'var e = document.createEvent("MutationEvents");' +
1140 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1141 'current_focus.inputField.dispatchEvent(e);',
1142 tooltiptext : ind.description }
1147 if (ind.@position == 2) {
1148 i2_popup.appendChild(
1150 { label : ind.@value,
1152 'current_focus.value = "' + ind.@value + '";' +
1153 'var e = document.createEvent("MutationEvents");' +
1154 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1155 'current_focus.inputField.dispatchEvent(e);',
1156 tooltiptext : ind.description }
1162 for (var j in f.subfield) {
1163 var sf = f.subfield[j];
1164 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1166 sf_popup.appendChild(
1170 'current_focus.value = "' + sf.@code + '";' +
1171 'var e = document.createEvent("MutationEvents");' +
1172 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1173 'current_focus.inputField.dispatchEvent(e);',
1174 tooltiptext : sf.description
1182 function getTooltip (target, type) {
1185 if (type == 'subfield')
1186 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1189 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1192 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1195 tt = 'tag' + target.parentNode.firstChild.value;
1197 if (!document.getElementById( tt )) {
1202 orient : 'vertical',
1203 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1204 class : 'tooltip' },
1205 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1210 target.tooltip = tt;
1214 function getContextMenu (target, type) {
1217 if (type == 'subfield')
1218 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1221 tt = 't' + target.parentNode.firstChild.value + 'i1';
1224 tt = 't' + target.parentNode.firstChild.value + 'i2';
1226 target.setAttribute('context', tt);
1232 'a' : { 100 : 'a' },
1233 'd' : { 100 : 'd' },
1234 'e' : { 100 : 'e' },
1238 'a' : { 110 : 'a' },
1242 'a' : { 111 : 'a' },
1246 'a' : { 130 : 'a' },
1250 'a' : { 130 : 'a' },
1254 'a' : { 100 : 'a' },
1258 'a' : { 110 : 'a' },
1262 'a' : { 111 : 'a' },
1266 'a' : { 130 : 'a' },
1267 'n' : { 130 : 'n' },
1271 'a' : { 100 : 'a' },
1272 'd' : { 100 : 'd' },
1273 'q' : { 100 : 'q' },
1277 'a' : { 110 : 'a' },
1281 'a' : { 111 : 'a' },
1282 'c' : { 111 : 'c' },
1286 'a' : { 130 : 'a' },
1290 'a' : { 100 : 'a' },
1294 'a' : { 110 : 'a' },
1298 'a' : { 111 : 'a' },
1302 'a' : { 130 : 'a' },
1306 'a' : { 100 : 'a' },
1307 'd' : { 100 : 'd' },
1308 'q' : { 100 : 'q' },
1309 't' : { 100 : 't' },
1336 'a' : { 110 : 'a' },
1337 'd' : { 110 : 'd' },
1338 't' : { 110 : 't' },
1365 'a' : { 111 : 'a' },
1366 'd' : { 111 : 'd' },
1367 't' : { 111 : 't' },
1394 'a' : { 130 : 'a' },
1398 'a' : { 148 : 'a' },
1399 'v' : { 148 : 'v' },
1400 'x' : { 148 : 'x' },
1401 'y' : { 148 : 'y' },
1405 'a' : { 150 : 'a' },
1406 'b' : { 150 : 'b' },
1433 'a' : { 151 : 'a' },
1460 'a' : { 155 : 'a' },
1488 function getAuthorityContextMenu (target, sf) {
1489 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1492 var old = dojo.byId( menu_id );
1494 page = auth_pages[menu_id];
1495 old.parentNode.removeChild(old);
1497 auth_pages[menu_id] = 0;
1500 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1502 sf_popup.addEventListener("popuphiding", function(event) {
1503 if (show_auth_menu) {
1504 show_auth_menu = false;
1505 getAuthorityContextMenu(target, sf);
1506 dojo.byId(menu_id).openPopup();
1510 context_menus.appendChild( sf_popup );
1513 dojo.forEach( acs.controlSetList(), function (acs_id) {
1514 if (acs.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
1517 if (!found_acs.length) {
1518 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1519 target.setAttribute('context', 'clipboard');
1523 if (sf.toString().replace(/\s*/, '')) {
1524 return browseAuthority(sf_popup, menu_id, target, sf, 20, page);
1530 /* Apply the complete 1xx */
1531 function applyFullAuthority ( target, ui_sf, e4x_sf ) {
1532 var new_vals = dojo.query('*[tag^="1"]', target);
1533 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1536 function applySelectedAuthority ( target, ui_sf, e4x_sf ) {
1537 var new_vals = target.getElementsByAttribute('checked','true');
1538 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1541 function applyAuthority ( target, ui_sf, e4x_sf, new_vals ) {
1542 var field = e4x_sf.parent();
1544 for (var i = 0; i < new_vals.length; i++) {
1546 var sf_list = field.subfield;
1547 for (var j in sf_list) {
1549 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1550 sf_list[j] = new_vals[i].getAttribute('value');
1551 new_vals[i].setAttribute('subfield','');
1557 for (var i = 0; i < new_vals.length; i++) {
1559 /* indicators for the authority datafield are carried over in the main entry linking subfield */
1560 if (new_vals[i].getAttribute('subfield') == '0') {
1561 field.@ind1 = new_vals[i].getAttribute('ind1');
1562 field.@ind2 = new_vals[i].getAttribute('ind2');
1565 if (!new_vals[i].getAttribute('subfield')) continue;
1567 var val = new_vals[i].getAttribute('value');
1569 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1570 sf.@code = new_vals[i].getAttribute('subfield');
1572 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1575 var row = marcDatafield( field );
1578 while (node.nodeName != 'row') {
1579 node = node.parentNode;
1582 node.parentNode.replaceChild( row, node );
1586 function validateAuthority (button) {
1587 var grid = document.getElementById('recGrid');
1588 var label = button.getAttribute('label');
1591 var rows = grid.lastChild.childNodes;
1592 for (var i = 0; i < rows.length; i++) {
1594 var tag = row.firstChild;
1597 dojo.forEach(acs.controlSetList(), function (acs_id) {
1599 var control_map = acs.controlSet(acs_id).control_map;
1601 if (!control_map[tag.value]) return;
1602 button.setAttribute('label', label + ' - ' + tag.value);
1604 var ind1 = tag.nextSibling;
1605 var ind2 = ind1.nextSibling;
1606 var subfields = ind2.nextSibling.childNodes;
1609 for (var j = 0; j < subfields.length; j++) {
1610 var sf = subfields[j];
1611 sf_list.push( sf.childNodes[1].value );
1612 sf_list.push( sf.childNodes[2].value );
1615 var matches = acs.findMatchingAuthorities(
1618 'subfields' : sf_list
1622 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1623 for (var j = 0; j < subfields.length; j++) {
1624 var sf = subfields[j];
1625 if (!matches.length) {
1626 dojo.removeClass(sf.childNodes[2], 'marcValidated');
1627 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
1629 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
1630 dojo.addClass(sf.childNodes[2], 'marcValidated');
1634 if (matches.length) done = true;
1638 button.setAttribute('label', label);
1645 function validateBibField (tags, searches) {
1646 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1647 url += '¶m="tags"¶m=' + js2JSON(tags);
1648 url += '¶m="searches"¶m=' + js2JSON(searches);
1651 var req = new XMLHttpRequest();
1652 req.open('GET',url,false);
1660 function searchAuthority (term, tag, sf, limit) {
1661 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1662 url += '¶m="term"¶m="' + term + '"';
1663 url += '¶m="limit"¶m=' + limit;
1664 url += '¶m="tag"¶m=' + tag;
1665 url += '¶m="subfield"¶m="' + sf + '"';
1668 var req = new XMLHttpRequest();
1669 req.open('GET',url,false);
1676 /* TODO new authority browse support for context sets, and use that here */
1677 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
1678 dojo.require('dojox.xml.parser');
1680 // map tag + subfield to the appropriate authority browse axis:
1681 // currently authority.author, authority.subject, authority.title, authority.topic
1682 // based on mappings in OpenILS::Application::SuperCat, though Authority Control
1683 // Sets will change that
1685 var axis_list = acs.bibFieldBrowseAxes( sf.parent().@tag.toString() );
1687 // No matching tag means no authorities to search - shortcut
1688 if (axis_list.length == 0) {
1689 target.setAttribute('context', 'clipboard');
1693 var type = 'authority.' + axis_list[0]; // Just take the first for now
1694 // TODO support multiple axes ... loop?
1703 var url = '/opac/extras/browse/marcxml/'
1705 + '/1' // OU - currently unscoped
1706 + '/' + sf.toString()
1711 // would be good to carve this out into a separate function
1712 dojo.xhrGet({"url":url, "sync": true, "preventCache": true, "handleAs":"xml", "load": function(records) {
1713 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
1715 var cm_popup = create_menu.appendChild(
1719 cm_popup.appendChild(
1720 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
1721 command : function() {
1722 // Call middle-layer function to create and save the new authority
1723 var source_f = summarizeField(sf);
1724 var new_auth = fieldmapper.standardRequest(
1725 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
1726 [source_f, xulG.marc_control_number_identifier, ses()]
1728 if (new_auth && new_auth.id()) {
1729 addNewAuthorityID(new_auth, sf, target);
1735 cm_popup.appendChild(
1736 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
1737 command : function() {
1738 // Generate the new authority by calling the new middle-layer
1739 // function (a non-saving variant), then display in another
1741 var source_f = summarizeField(sf);
1742 var authtoken = ses();
1743 dojo.require('openils.PermaCrud');
1744 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
1745 var rec = fieldmapper.standardRequest(
1746 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
1747 { "params": [source_f, xulG.marc_control_number_identifier] }
1749 loadMarcEditor(pcrud, rec, target, sf);
1754 sf_popup.appendChild(create_menu);
1755 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1757 // append "Previous page" results browser
1758 sf_popup.appendChild(
1759 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
1760 command : function(event) {
1761 auth_pages[menu_id] -= 1;
1762 show_auth_menu = true;
1766 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1768 dojo.query('record', records).forEach(function(record) {
1772 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"] subfield[code="c"]', record)[0]);
1773 var auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
1775 // Grab the fields with tags beginning with 1 (main entries) and iterate through the subfields
1776 dojo.query('datafield[tag^="1"]', record).forEach(function(field) {
1777 dojo.query('subfield', field).forEach(function(subfield) {
1781 main_text += dojox.xml.parser.textContent(subfield);
1785 // Grab the fields with tags beginning with 4 (see from entries) and iterate through the subfields
1786 dojo.query('datafield[tag^="4"]', record).forEach(function(field) {
1788 dojo.query('subfield', field).forEach(function(subfield) {
1792 see_text += dojox.xml.parser.textContent(subfield);
1794 see_from.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_from', [see_text]));
1797 // Grab the fields with tags beginning with 5 (see also entries) and iterate through the subfields
1798 dojo.query('datafield[tag^="5"]', record).forEach(function(field) {
1800 dojo.query('subfield', field).forEach(function(subfield) {
1804 see_text += dojox.xml.parser.textContent(subfield);
1806 see_also.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_also', [see_text]));
1809 buildAuthorityPopup(main_text, record, auth_org, auth_id, sf_popup, target, sf);
1811 dojo.forEach(see_from, function(entry_text) {
1812 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1815 // To-do: instead of launching the standard selector menu, invoke
1816 // a new authority search using the 5XX entry text
1817 dojo.forEach(see_also, function(entry_text) {
1818 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1823 if (sf_popup.childNodes.length == 0) {
1824 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1826 // append "Next page" results browser
1827 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1828 sf_popup.appendChild(
1829 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
1830 command : function(event) {
1831 auth_pages[menu_id] += 1;
1832 show_auth_menu = true;
1838 target.setAttribute('context', menu_id);
1844 function buildAuthorityPopup (entry_text, record, auth_org, auth_id, sf_popup, target, sf, style) {
1845 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
1846 grid.setAttribute('name','-none-');
1847 grid.setAttribute('style','overflow:scroll');
1849 var submenu = createMenu( { "label": entry_text } );
1851 var popup = createMenuPopup({ "flex": "1" });
1853 submenu.setAttribute('style', style);
1854 popup.setAttribute('style', 'font-style: normal; margin-left: 0em;');
1856 submenu.appendChild(popup);
1858 dojo.query('datafield[tag^="1"], datafield[tag^="4"], datafield[tag^="5"]', record).forEach(function(field) {
1859 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1862 grid.hidden = false;
1863 popup.appendChild( grid );
1867 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1868 command : function (event) {
1869 applySelectedAuthority(event.target.previousSibling, target, sf);
1876 popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1880 { label : $('catStrings').getString('staff.cat.marcedit.apply_full.label'),
1881 command : function (event) {
1882 applyFullAuthority(event.target.previousSibling.previousSibling.previousSibling, target, sf);
1889 sf_popup.appendChild( submenu );
1892 function buildAuthorityPopupSelector (field, grid, auth_org, auth_id) {
1893 var row = createRow(
1895 createLabel( { "value" : dojo.attr(field, 'tag') } ),
1896 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
1897 createLabel( { "value" : dojo.attr(field, 'ind2') } )
1900 var sf_box = createHbox();
1901 dojo.query('subfield', field).forEach(function(subfield) {
1904 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
1905 "subfield" : dojo.attr(subfield, 'code'),
1906 "tag" : dojo.attr(field, 'tag'),
1907 "value" : dojox.xml.parser.textContent(subfield)
1911 row.appendChild(sf_box);
1914 // Append the authority linking subfield only for main entries
1915 if (dojo.attr(field, 'tag').charAt(0) == '1') {
1918 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
1920 "tag" : dojo.attr(field, 'tag'),
1921 "ind1" : dojo.attr(field, 'ind1'),
1922 "ind2" : dojo.attr(field, 'ind2'),
1923 "value" : '(' + auth_org + ')' + auth_id
1928 row.appendChild(sf_box);
1930 grid.lastChild.appendChild(row);
1933 function summarizeField(sf) {
1941 source_f.tag = sf.parent().@tag.toString();
1942 source_f.ind1 = sf.parent().@ind1.toString();
1943 source_f.ind2 = sf.parent().@ind2.toString();
1946 dojo.forEach( acs.controlSetList(), function (acs_id) {
1947 if (acs.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
1951 if (!found_acs.length) {
1954 cmap = acs.controlSet(found_acs[0]).control_map;
1957 for (var i = 0; i < sf.parent().subfield.length(); i++) {
1958 var sf_iter = sf.parent().subfield[i];
1960 /* Filter out subfields that are not controlled for this tag */
1961 if (!cmap[source_f.tag][sf_iter.@code.toString()]) {
1965 source_f.subfields.push([sf_iter.@code.toString(), sf_iter.toString()]);
1971 function buildBibSourceList (authtoken, recId) {
1972 /* TODO: Work out how to set the bib source of the bre that does not yet
1973 * exist - this is specifically in the case of Z39.50 imports. Right now
1974 * we just avoid populating and showing the config.bib_source list
1980 var bib = xulG.record.bre;
1982 dojo.require('openils.PermaCrud');
1984 // cbsList = the XUL menulist that contains the available bib sources
1985 var cbsList = dojo.byId('bib-source-list');
1987 // bibSources = an array containing all of the bib source objects
1988 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
1990 // A tad ugly, but gives us the index of the bib source ID in cbsList
1992 var cbsListArr = [];
1993 dojo.forEach(bibSources, function (item) {
1994 cbsList.appendItem(item.source(), item.id());
1995 cbsListArr[item.id()] = x;
1999 // Show the current value of the bib source for this record
2000 cbsList.selectedIndex = cbsListArr[bib.source()];
2002 // Display the bib source selection widget
2003 dojo.byId('bib-source-list-caption').hidden = false;
2004 dojo.byId('bib-source-list').hidden = false;
2005 dojo.byId('bib-source-list-button').disabled = true;
2006 dojo.byId('bib-source-list-button').hidden = false;
2009 // Fired when the "Update Source" button is clicked
2010 // Updates the value of the bib source for the current record
2011 function updateBibSource() {
2012 var authtoken = ses();
2013 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2014 var recId = xulG.record.id;
2015 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2016 var bib = pcrud.retrieve('bre', recId);
2017 if (bib.source() != cbs) {
2019 bib.ischanged = true;
2024 function onBibSourceSelect() {
2025 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2026 var bib = xulG.record.bre;
2027 if (bib.source() != cbs) {
2028 dojo.byId('bib-source-list-button').disabled = false;
2030 dojo.byId('bib-source-list-button').disabled = true;
2034 function addNewAuthorityID(authority, sf, target) {
2035 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){authority.id()}</subfield>;
2036 sf.parent().appendChild(id_sf);
2037 var new_sf = marcSubfield(id_sf);
2040 while (dojo.attr(node, 'name') != 'sf_box') {
2041 node = node.parentNode;
2043 node.appendChild( new_sf );
2045 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2048 function loadMarcEditor(pcrud, marcxml, target, sf) {
2050 To run in Firefox directly, must set signed.applets.codebase_principal_support
2051 to true in about:config
2053 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
2054 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
2056 // Match marc2are.pl last_xact_id format, roughly
2058 var xact_id = 'IMPORT-' + Date.parse(now);
2061 "record": {"marc": marcxml, "rtype": "are"},
2063 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2064 "func": function(xmlString) {
2065 var rec = new are();
2066 rec.marc(xmlString);
2067 rec.last_xact_id(xact_id);
2070 "oncomplete": function (r, objs) {
2071 var new_rec = objs[0];
2076 addNewAuthorityID(new_rec, sf, target);