3 * Copyright (C) 2004-2008 Georgia Public Library Service
4 * Copyright (C) 2008-2010 Equinox Software, Inc.
5 * Mike Rylander <miker@esilibrary.com>
7 * Copyright (C) 2010 Dan Scott <dan@coffeecode.net>
8 * Copyright (C) 2010 Internationaal Instituut voor Sociale Geschiedenis <info@iisg.nl>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 var xmlDeclaration = /^<\?xml version[^>]+?>/;
23 var serializer = new XMLSerializer();
24 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
25 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
26 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
27 default xml namespace = marcns;
29 var tooltip_hash = {};
41 var show_auth_menu = false;
43 function $(id) { return document.getElementById(id); }
45 var acs; // AuthorityControlSet
47 function mangle_005() {
49 var y = now.getUTCFullYear();
51 var m = now.getUTCMonth() + 1;
52 if (m < 10) m = '0' + m;
54 var d = now.getUTCDate();
55 if (d < 10) d = '0' + d;
57 var H = now.getUTCHours();
58 if (H < 10) H = '0' + H;
60 var M = now.getUTCMinutes();
61 if (M < 10) M = '0' + M;
63 var S = now.getUTCSeconds();
64 if (S < 10) S = '0' + S;
67 var stamp = '' + y + m + d + H + M + S + '.0';
68 createControlField('005',stamp);
72 function createControlField (tag,data) {
73 // first, remove the old field, if any;
74 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
76 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
79 // then, find the right position and insert it
81 var cfields = xml_record.controlfield;
82 var base = Number(tag.substring(2));
83 for (var i in cfields) {
84 var t = Number(cfields[i].@tag.toString().substring(2));
86 xml_record.insertChildBefore( cfields[i], cf );
92 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
97 function xml_escape_unicode ( str ) {
100 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
104 function wrap_long_fields (node) {
105 var text_size = dojo.attr(node, 'size');
106 var hard_width = 100;
107 if (text_size > hard_width) {
108 dojo.attr(node, 'multiline', 'true');
109 dojo.attr(node, 'cols', hard_width);
110 var text_rows = (text_size / hard_width) + 1;
111 dojo.attr(node, 'rows', text_rows);
115 function set_flat_editor (useFlatText) {
117 var xe = $('xul-editor');
118 var te = $('text-editor');
121 if (xe.hidden) { return; }
125 if (te.hidden) { return; }
131 // get the marcxml from the text box
132 var xml_string = new MARC.Record({
133 marcbreaker : $('text-editor-box').value,
137 // reset the xml record and rerender it
138 xml_record = new XML( xml_string );
139 if (xml_record..record[0]) xml_record = xml_record..record[0];
142 var xml_string = xml_record.toXMLString();
144 // push the xml record into the textbox
145 var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
146 $('text-editor-box').value = rec.toBreaker();
153 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
154 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
155 JSAN.errorLevel = "die"; // none, warn, or die
156 JSAN.addRepository('/xul/server/');
158 dojo.require('openils.AuthorityControlSet');
159 acs = new openils.AuthorityControlSet ();
161 // Fake xulG for standalone...
166 window.xulG.record = {};
167 window.xulG.save = {};
168 window.xulG.marc_control_number_identifier = 'CONS';
170 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
171 window.xulG.save.func = function (r) { alert(r); }
174 var _rid = cgi.param('record');
176 window.xulG.record.id = _rid;
177 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
181 // End faking part...
183 /* Check for an explicitly passed record type
184 * This is not the same as the fixed-field record type; we can't trust
185 * the fixed fields when making modifications to the attributes for a
186 * given record (in particular, config.bib_source only applies for bib
187 * records, but an auth or MFHD record with the same ID and bad fixed
188 * fields could trample the config.bib_source value for the
189 * corresponding bib record if we're not careful.
191 * are = authority record
192 * sre = serial record (MFHD)
193 * bre = bibliographic record
195 if (!window.xulG.record.rtype) {
197 window.xulG.record.rtype = cgi.param('rtype') || false;
200 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
201 document.getElementById('save-button').setAttribute('oncommand',
202 'if ($("xul-editor").hidden) set_flat_editor(false); ' +
204 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
205 'save_attempt( xml_string ); ' +
209 if (window.xulG.record.url) {
210 var req = new XMLHttpRequest();
211 req.open('POST',window.xulG.record.url,false);
213 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
216 xml_record = new XML( window.xulG.record.marc );
217 if (xml_record..record[0]) xml_record = xml_record..record[0];
219 // Get the tooltip xml all async like
220 req = new XMLHttpRequest();
222 // Set a default locale in case preferences fail us
223 var locale = "en-US";
225 // Try to get the locale from our preferences
226 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
228 const Cc = Components.classes;
229 const Ci = Components.interfaces;
230 locale = Cc["@mozilla.org/preferences-service;1"].
231 getService(Ci.nsIPrefBranch).
232 getCharPref("general.useragent.locale");
236 // TODO: We should send a HEAD request to check for the existence of the desired file
237 // then fall back to the default locale if preferred locale is not necessary;
238 // however, for now we have a simplistic check:
240 // we currently have translations for only two locales; in the absence of a
241 // valid locale, default to the almighty en-US
242 if (locale != 'en-US' && locale != 'fr-CA') {
246 // grab the right tooltip based on MARC type
247 var tooltip_doc = 'marcedit-tooltips.xml';
248 switch (window.xulG.record.rtype) {
250 tooltip_doc = 'marcedit-tooltips.xml';
253 tooltip_doc = 'marcedit-tooltips-authority.xml';
254 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
257 tooltip_doc = 'marcedit-tooltips-mfhd.xml';
258 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
261 tooltip_doc = 'marcedit-tooltips.xml';
264 // Get the locale-specific tooltips
265 req.open('GET','/xul/server/locale/' + locale + '/' + tooltip_doc,true);
267 context_menus = createComplexXULElement('popupset');
268 document.documentElement.appendChild( context_menus );
270 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
271 context_menus.appendChild( tag_menu );
273 tag_menu.appendChild(
275 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
277 'var e = document.createEvent("KeyEvents");' +
278 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
279 'current_focus.inputField.dispatchEvent(e);'
284 tag_menu.appendChild(
286 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
288 'var e = document.createEvent("KeyEvents");' +
289 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
290 'current_focus.inputField.dispatchEvent(e);'
295 tag_menu.appendChild(
297 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
299 'var e = document.createEvent("KeyEvents");' +
300 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
301 'current_focus.inputField.dispatchEvent(e);'
306 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
308 tag_menu.appendChild(
310 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
312 'var e = document.createEvent("KeyEvents");' +
313 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
314 'current_focus.inputField.dispatchEvent(e);'
319 tag_menu.appendChild(
321 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
323 'var e = document.createEvent("KeyEvents");' +
324 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
325 'current_focus.inputField.dispatchEvent(e);'
330 tag_menu.appendChild(
332 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
334 'var e = document.createEvent("KeyEvents");' +
335 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
336 'current_focus.inputField.dispatchEvent(e);'
341 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
343 p = createComplexXULElement('popupset');
344 document.documentElement.appendChild( p );
346 req.onreadystatechange = function () {
347 if (req.readyState == 4) {
348 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
356 if (! xulG.fast_add_item) {
357 document.getElementById('fastItemAdd_checkbox').hidden = true;
359 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
361 // Only show bib sources for bib records that already exist in the database
362 if (xulG.record.rtype == 'bre' && xulG.record.id) {
363 dojo.require('openils.PermaCrud');
364 var authtoken = ses();
365 // Retrieve the current record attributes
366 var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
368 // Remember the current bib source of the record
369 xulG.record.bre = bib;
371 buildBibSourceList(authtoken, xulG.record.id);
374 dojo.require('MARC.FixedFields');
377 alert('FIXME, MARC Editor, my_init: ' + E);
382 function createComplexHTMLElement (e, attrs, objects, text) {
383 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
386 for (var i in attrs) l.setAttribute(i,attrs[i]);
390 for ( var i in objects ) l.appendChild( objects[i] );
394 l.appendChild( document.createTextNode(text) )
400 function createComplexXULElement (e, attrs, objects) {
401 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
404 for (var i in attrs) {
405 if (typeof attrs[i] == 'function') {
406 l.addEventListener( i, attrs[i], true );
408 l.setAttribute(i,attrs[i]);
414 for ( var i in objects ) l.appendChild( objects[i] );
420 function createDescription (attrs) {
421 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
424 function createTooltip (attrs) {
425 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
428 function createLabel (attrs) {
429 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
432 function createVbox (attrs) {
433 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
436 function createHbox (attrs) {
437 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
440 function createRow (attrs) {
441 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
444 function createTextbox (attrs) {
445 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
448 function createMenu (attrs) {
449 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
452 function createMenuPopup (attrs) {
453 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
456 function createPopup (attrs) {
457 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
460 function createMenuitem (attrs) {
461 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
464 function createCheckbox (attrs) {
465 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
468 // Find the next textbox that we can use for a focus point
469 // For control fields, use the first editable text box
470 // For data fields, focus on the first subfield text box
471 function setFocusToNextTag (row, direction) {
472 var keep_looking = true;
473 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
474 // Is it a datafield?
475 dojo.query('hbox hbox textbox', row).forEach(function(node, index, arr) {
477 keep_looking = false;
480 // No, it's a control field; use the first textbox
482 dojo.query('textbox', row).forEach(function(node, index, arr) {
484 keep_looking = false;
493 function createMARCTextbox (element,attrs) {
495 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
496 box.addEventListener('keypress',function(ev) { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); if (!(ev.altKey || ev.ctrlKey || ev.metaKey)) { oils_lock_page(); } },false);
497 box.onkeypress = function (event) {
500 while(node = node.parent()) {
504 var row = event.target;
505 while (row.tagName != 'row') row = row.parentNode;
507 if (element.nodeKind() == 'attribute') element[0]=box.value;
508 else element.setChildren( box.value );
510 if (element.localName() != 'controlfield') {
511 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
513 var index_sf, target, move_data;
514 if (element.localName() == 'subfield') {
516 target = event.target.parentNode;
518 var start = event.target.selectionStart;
519 var end = event.target.selectionEnd - event.target.selectionStart ?
520 event.target.selectionEnd :
521 event.target.value.length;
523 move_data = event.target.value.substring(start,end);
524 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
525 event.target.setAttribute('size', event.target.value.length + 2);
527 element.setChildren( event.target.value );
529 } else if (element.localName() == 'code') {
530 index_sf = element.parent();
531 target = event.target.parentNode;
532 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
533 index_sf = element.parent().children()[element.parent().children().length() - 1];
534 target = event.target.parentNode.lastChild.lastChild;
537 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
539 index_sf.parent().insertChildAfter( index_sf, sf );
541 var new_sf = marcSubfield(sf);
543 if (target === target.parentNode.lastChild) {
544 target.parentNode.appendChild( new_sf );
546 target.parentNode.insertBefore( new_sf, target.nextSibling );
549 new_sf.firstChild.nextSibling.focus();
551 event.preventDefault();
554 } else if (event.keyCode == 13 || event.keyCode == 77) {
555 if (event.ctrlKey) { // ctrl+enter
558 if (element.localName() == 'subfield') index = element.parent();
559 if (element.localName() == 'code') index = element.parent().parent();
560 if (element.localName() == 'tag') index = element.parent();
561 if (element.localName() == 'ind1') index = element.parent();
562 if (element.localName() == 'ind2') index = element.parent();
564 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
566 if (event.shiftKey) { // ctrl+shift+enter
567 index.parent().insertChildBefore( index, df );
569 index.parent().insertChildAfter( index, df );
572 var new_df = marcDatafield(df);
574 if (row.parentNode.lastChild === row) {
575 row.parentNode.appendChild( new_df );
577 if (event.shiftKey) { // ctrl+shift+enter
578 row.parentNode.insertBefore( new_df, row );
580 row.parentNode.insertBefore( new_df, row.nextSibling );
584 new_df.firstChild.focus();
586 event.preventDefault();
589 } else if (event.shiftKey) {
590 if (row.previousSibling.className.match('marcDatafieldRow'))
591 row.previousSibling.firstChild.focus();
593 row.nextSibling.firstChild.focus();
596 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
597 if (event.ctrlKey) { // CTRL key: copy the field
599 if (element.localName() == 'subfield') index = element.parent();
600 if (element.localName() == 'code') index = element.parent().parent();
601 if (element.localName() == 'tag') index = element.parent();
602 if (element.localName() == 'ind1') index = element.parent();
603 if (element.localName() == 'ind2') index = element.parent();
605 var copyField = index.copy();
607 if (event.keyCode == 38) { // ctrl+up-arrow
608 index.parent().insertChildBefore( index, copyField );
610 index.parent().insertChildAfter( index, copyField );
613 var new_df = marcDatafield(copyField);
615 if (row.parentNode.lastChild === row) {
616 row.parentNode.appendChild( new_df );
618 if (event.keyCode == 38) { // ctrl+up-arrow
619 row.parentNode.insertBefore( new_df, row );
620 } else { // ctrl+down-arrow
621 row.parentNode.insertBefore( new_df, row.nextSibling );
625 new_df.firstChild.focus();
627 event.preventDefault();
631 if (event.keyCode == 38) {
632 return setFocusToNextTag(row, 'up');
634 if (event.keyCode == 40) {
635 return setFocusToNextTag(row, 'down');
640 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
643 if (element.localName() == 'subfield') index = element.parent();
644 if (element.localName() == 'code') index = element.parent().parent();
645 if (element.localName() == 'tag') index = element.parent();
646 if (element.localName() == 'ind1') index = element.parent();
647 if (element.localName() == 'ind2') index = element.parent();
649 for (var i in index.parent().children()) {
650 if (index === index.parent().children()[i]) {
651 delete index.parent().children()[i];
656 row.previousSibling.firstChild.focus();
657 row.parentNode.removeChild(row);
659 event.preventDefault();
662 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
665 if (element.localName() == 'subfield') index = element;
666 if (element.localName() == 'code') index = element.parent();
669 for (var i in index.parent().children()) {
670 if (index === index.parent().children()[i]) {
671 delete index.parent().children()[i];
676 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
677 event.target.parentNode.previousSibling.lastChild.focus();
679 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
682 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
684 event.preventDefault();
687 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
688 createControlField('006',' ');
690 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
691 createControlField('007',' ');
693 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
694 createControlField('008',' ');
700 } else { // event on a control field
701 if (event.keyCode == 38) {
702 return setFocusToNextTag(row, 'up');
703 } else if (event.keyCode == 40) {
704 return setFocusToNextTag(row, 'down');
709 box.addEventListener(
712 if (element.nodeKind() == 'attribute') element[0]=box.value;
713 else element.setChildren( box.value );
719 box.addEventListener(
722 if (element.nodeKind() == 'attribute') element[0]=box.value;
723 else element.setChildren( box.value );
729 box.addEventListener(
732 if (element.nodeKind() == 'attribute') element[0]=box.value;
733 else element.setChildren( box.value );
739 // 'input' event catches the box value after the keypress
740 box.addEventListener(
743 if (element.nodeKind() == 'attribute') element[0]=box.value;
744 else element.setChildren( box.value );
750 box.addEventListener(
753 if (element.localName() == 'controlfield')
754 eval('fillFixedFields();');
762 function toggleFFE () {
763 var grid = document.getElementById('leaderGrid');
772 function changeFFEditor (type) {
773 var grid = document.getElementById('leaderGrid');
774 grid.setAttribute('type',type);
775 document.getElementById('recordTypeLabel').setAttribute('value',type);
777 // Hide FFEditor rows that we don't need for our current type
778 // If all of the labels for a given row do not include our
779 // desired type in their set attribute, we can hide that row
780 dojo.query('rows row', grid).forEach(function(node, index, arr) {
781 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
788 function fillFixedFields () {
790 var grid = document.getElementById('leaderGrid');
791 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
794 var pre_list = grid.getElementsByTagName('label');
795 for (var i in pre_list) {
796 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
797 list.push( pre_list[i] );
801 for (var i in list) {
802 var name = list[i].getAttribute('name');
803 var value = marc_rec.extractFixedField(name, true);
805 if (value === null) continue;
807 list[i].nextSibling.value = value;
812 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
816 function updateFixedFields (element) {
817 var grid = document.getElementById('leaderGrid');
818 var recGrid = document.getElementById('recGrid');
819 var new_value = element.value;
820 // Don't take focus away/adjust the record on partial changes
821 var length = element.getAttribute('maxlength');
822 if(new_value.length < length) return true;
824 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
825 marc_rec.setFixedField(element.getAttribute('name'), new_value);
827 var xml_string = marc_rec.toXmlString();
828 xml_record = new XML( xml_string );
829 if (xml_record..record[0]) xml_record = xml_record..record[0];
835 function marcLeader (leader) {
837 { class : 'marcLeaderRow',
842 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
845 class : 'marcInd1' } ),
848 class : 'marcInd2' } ),
850 { value : leader.text(),
851 class : 'marcLeader' } )
857 function marcControlfield (field) {
858 tagname = field.@tag.toString().substr(2);
860 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
862 { class : 'marcControlfieldRow',
863 tag : '_' + tagname },
865 { value : field.@tag,
867 context : 'tags_popup',
868 onmouseover : 'getTooltip(this, "tag");',
869 tooltipid : 'tag' + field.@tag } ),
871 { value : field.@ind1,
873 onmouseover : 'getTooltip(this, "ind1");',
874 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
876 { value : field.@ind2,
878 onmouseover : 'getTooltip(this, "ind2");',
879 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
882 { value : field.text(),
883 class : 'plain marcEditableControlfield',
884 name : 'CONTROL' + tagname,
885 context : 'clipboard',
891 { class : 'marcControlfieldRow',
892 tag : '_' + tagname },
894 { value : field.@tag,
896 onmouseover : 'getTooltip(this, "tag");',
897 tooltipid : 'tag' + field.@tag } ),
899 { value : field.@ind1,
901 onmouseover : 'getTooltip(this, "ind1");',
902 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
904 { value : field.@ind2,
906 onmouseover : 'getTooltip(this, "ind2");',
907 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
909 { value : field.text(),
910 class : 'marcControlfield' } )
917 function stackSubfields(checkbox) {
918 var list = document.getElementsByAttribute('name','sf_box');
921 if (!checkbox.checked) o = 'horizontal';
923 for (var i = 0; i < list.length; i++) {
924 if (list[i]) list[i].setAttribute('orient',o);
928 function fastItemAdd_toggle(checkbox) {
929 var x = document.getElementById('fastItemAdd_textboxes');
930 if (checkbox.checked) {
932 document.getElementById('fastItemAdd_callnumber').focus();
933 document.getElementById('fastItemAdd_callnumber').select();
939 function fastItemAdd_attempt(doc_id) {
941 if (typeof window.xulG.fast_add_item != 'function') { return; }
942 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
943 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
944 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
945 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
946 document.getElementById('fastItemAdd_barcode').value = '';
948 alert('fastItemAdd_attempt: ' + E);
952 function save_attempt(xml_string) {
954 var result = window.xulG.save.func( xml_string );
957 if (result.id) fastItemAdd_attempt(result.id);
958 if (typeof result.on_complete == 'function') result.on_complete();
961 alert('save_attempt: ' + E);
965 function marcDatafield (field) {
967 { class : 'marcDatafieldRow' },
970 { value : field.@tag,
971 class : 'plain marcTag',
973 context : 'tags_popup',
974 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
977 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
980 { value : field.@ind1,
981 class : 'plain marcInd1',
983 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
986 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
987 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
990 { value : field.@ind2,
991 class : 'plain marcInd2',
993 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
996 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
997 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
998 createHbox({ name : 'sf_box' })
1001 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1002 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1003 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1005 var sf_box = row.lastChild;
1006 if (document.getElementById('stackSubfields').checked)
1007 sf_box.setAttribute('orient','vertical');
1009 sf_box.addEventListener(
1012 if (sf_box === e.target) {
1013 sf_box.lastChild.lastChild.focus();
1014 } else if (e.target.parentNode === sf_box) {
1015 e.target.lastChild.focus();
1022 for (var i in field.subfield) {
1023 var sf = field.subfield[i];
1028 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1030 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1031 current_focus = sf_box.lastChild.childNodes[1];
1037 function marcSubfield (sf) {
1039 { class : 'marcSubfieldBox' },
1042 class : 'plain marcSubfieldDelimiter',
1043 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1044 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1045 //onclick : 'this.nextSibling.focus();',
1046 onfocus : 'this.nextSibling.focus();',
1051 class : 'plain marcSubfieldCode',
1052 name : 'marcSubfieldCode',
1053 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1054 oncontextmenu : 'getContextMenu(this, "subfield");',
1055 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1060 { value : sf.text(),
1061 name : sf.parent().@tag + ':' + sf.@code,
1062 class : 'plain marcSubfield',
1063 onmouseover : 'getTooltip(this, "subfield");',
1064 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1065 size : new String(sf.text()).length + 2,
1066 oninput : "this.setAttribute('size', this.value.length + 2);"
1071 function loadRecord() {
1073 var grid_rows = document.getElementById('recGrid').lastChild;
1075 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1077 grid_rows.appendChild( marcLeader( xml_record.leader ) );
1079 for (var i in xml_record.controlfield) {
1080 grid_rows.appendChild( marcControlfield( xml_record.controlfield[i] ) );
1083 for (var i in xml_record.datafield) {
1084 grid_rows.appendChild( marcDatafield( xml_record.datafield[i] ) );
1087 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1089 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
1090 changeFFEditor(marc_rec.recordType());
1093 alert('FIXME, MARC Editor, loadRecord: ' + E);
1098 function genToolTips () {
1099 for (var i in bib_data.field) {
1100 var f = bib_data.field[i];
1102 tag_menu.appendChild(
1106 'current_focus.value = "' + f.@tag + '";' +
1107 'var e = document.createEvent("MutationEvents");' +
1108 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1109 'current_focus.inputField.dispatchEvent(e);',
1110 disabled : f.@tag < '010' ? "true" : "false",
1111 tooltiptext : f.description }
1115 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1116 context_menus.appendChild( i1_popup );
1118 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1119 context_menus.appendChild( i2_popup );
1121 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1122 context_menus.appendChild( sf_popup );
1124 tooltip_hash['tag' + f.@tag] = f.description;
1125 for (var j in f.indicator) {
1126 var ind = f.indicator[j];
1127 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1129 if (ind.@position == 1) {
1130 i1_popup.appendChild(
1132 { label : ind.@value,
1134 'current_focus.value = "' + ind.@value + '";' +
1135 'var e = document.createEvent("MutationEvents");' +
1136 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1137 'current_focus.inputField.dispatchEvent(e);',
1138 tooltiptext : ind.description }
1143 if (ind.@position == 2) {
1144 i2_popup.appendChild(
1146 { label : ind.@value,
1148 'current_focus.value = "' + ind.@value + '";' +
1149 'var e = document.createEvent("MutationEvents");' +
1150 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1151 'current_focus.inputField.dispatchEvent(e);',
1152 tooltiptext : ind.description }
1158 for (var j in f.subfield) {
1159 var sf = f.subfield[j];
1160 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1162 sf_popup.appendChild(
1166 'current_focus.value = "' + sf.@code + '";' +
1167 'var e = document.createEvent("MutationEvents");' +
1168 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1169 'current_focus.inputField.dispatchEvent(e);',
1170 tooltiptext : sf.description
1178 function getTooltip (target, type) {
1181 if (type == 'subfield')
1182 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1185 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1188 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1191 tt = 'tag' + target.parentNode.firstChild.value;
1193 if (!document.getElementById( tt )) {
1198 orient : 'vertical',
1199 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1200 class : 'tooltip' },
1201 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1206 target.tooltip = tt;
1210 function getContextMenu (target, type) {
1213 if (type == 'subfield')
1214 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1217 tt = 't' + target.parentNode.firstChild.value + 'i1';
1220 tt = 't' + target.parentNode.firstChild.value + 'i2';
1222 target.setAttribute('context', tt);
1228 'a' : { 100 : 'a' },
1229 'd' : { 100 : 'd' },
1230 'e' : { 100 : 'e' },
1234 'a' : { 110 : 'a' },
1238 'a' : { 111 : 'a' },
1242 'a' : { 130 : 'a' },
1246 'a' : { 130 : 'a' },
1250 'a' : { 100 : 'a' },
1254 'a' : { 110 : 'a' },
1258 'a' : { 111 : 'a' },
1262 'a' : { 130 : 'a' },
1263 'n' : { 130 : 'n' },
1267 'a' : { 100 : 'a' },
1268 'd' : { 100 : 'd' },
1269 'q' : { 100 : 'q' },
1273 'a' : { 110 : 'a' },
1277 'a' : { 111 : 'a' },
1278 'c' : { 111 : 'c' },
1282 'a' : { 130 : 'a' },
1286 'a' : { 100 : 'a' },
1290 'a' : { 110 : 'a' },
1294 'a' : { 111 : 'a' },
1298 'a' : { 130 : 'a' },
1302 'a' : { 100 : 'a' },
1303 'd' : { 100 : 'd' },
1304 'q' : { 100 : 'q' },
1305 't' : { 100 : 't' },
1332 'a' : { 110 : 'a' },
1333 'd' : { 110 : 'd' },
1334 't' : { 110 : 't' },
1361 'a' : { 111 : 'a' },
1362 'd' : { 111 : 'd' },
1363 't' : { 111 : 't' },
1390 'a' : { 130 : 'a' },
1394 'a' : { 148 : 'a' },
1395 'v' : { 148 : 'v' },
1396 'x' : { 148 : 'x' },
1397 'y' : { 148 : 'y' },
1401 'a' : { 150 : 'a' },
1402 'b' : { 150 : 'b' },
1429 'a' : { 151 : 'a' },
1456 'a' : { 155 : 'a' },
1484 function getAuthorityContextMenu (target, sf) {
1485 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1488 var old = dojo.byId( menu_id );
1490 page = auth_pages[menu_id];
1491 old.parentNode.removeChild(old);
1493 auth_pages[menu_id] = 0;
1496 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1498 sf_popup.addEventListener("popuphiding", function(event) {
1499 if (show_auth_menu) {
1500 show_auth_menu = false;
1501 getAuthorityContextMenu(target, sf);
1502 dojo.byId(menu_id).openPopup();
1506 context_menus.appendChild( sf_popup );
1509 dojo.forEach( acs.controlSetList(), function (acs_id) {
1510 if (acs.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
1513 if (!found_acs.length) {
1514 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1515 target.setAttribute('context', 'clipboard');
1519 if (sf.toString().replace(/\s*/, '')) {
1520 return browseAuthority(sf_popup, menu_id, target, sf, 20, page);
1526 /* Apply the complete 1xx */
1527 function applyFullAuthority ( target, ui_sf, e4x_sf ) {
1528 var new_vals = dojo.query('*[tag^="1"]', target);
1529 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1532 function applySelectedAuthority ( target, ui_sf, e4x_sf ) {
1533 var new_vals = target.getElementsByAttribute('checked','true');
1534 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1537 function applyAuthority ( target, ui_sf, e4x_sf, new_vals ) {
1538 var field = e4x_sf.parent();
1540 for (var i = 0; i < new_vals.length; i++) {
1542 var sf_list = field.subfield;
1543 for (var j in sf_list) {
1545 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1546 sf_list[j] = new_vals[i].getAttribute('value');
1547 new_vals[i].setAttribute('subfield','');
1553 for (var i = 0; i < new_vals.length; i++) {
1555 /* indicators for the authority datafield are carried over in the main entry linking subfield */
1556 if (new_vals[i].getAttribute('subfield') == '0') {
1557 field.@ind1 = new_vals[i].getAttribute('ind1');
1558 field.@ind2 = new_vals[i].getAttribute('ind2');
1561 if (!new_vals[i].getAttribute('subfield')) continue;
1563 var val = new_vals[i].getAttribute('value');
1565 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1566 sf.@code = new_vals[i].getAttribute('subfield');
1568 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1571 var row = marcDatafield( field );
1574 while (node.nodeName != 'row') {
1575 node = node.parentNode;
1578 node.parentNode.replaceChild( row, node );
1582 function validateAuthority (button) {
1583 var grid = document.getElementById('recGrid');
1584 var label = button.getAttribute('label');
1587 var rows = grid.lastChild.childNodes;
1588 for (var i = 0; i < rows.length; i++) {
1590 var tag = row.firstChild;
1593 dojo.forEach(acs.controlSetList(), function (acs_id) {
1595 var control_map = acs.controlSet(acs_id).control_map;
1597 if (!control_map[tag.value]) return;
1598 button.setAttribute('label', label + ' - ' + tag.value);
1600 var ind1 = tag.nextSibling;
1601 var ind2 = ind1.nextSibling;
1602 var subfields = ind2.nextSibling.childNodes;
1605 for (var j = 0; j < subfields.length; j++) {
1606 var sf = subfields[j];
1607 sf_list.push( sf.childNodes[1].value );
1608 sf_list.push( sf.childNodes[2].value );
1611 var matches = acs.findMatchingAuthorities(
1614 'subfields' : sf_list
1618 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1619 for (var j = 0; j < subfields.length; j++) {
1620 var sf = subfields[j];
1621 if (!matches.length) {
1622 dojo.removeClass(sf.childNodes[2], 'marcValidated');
1623 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
1625 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
1626 dojo.addClass(sf.childNodes[2], 'marcValidated');
1630 if (matches.length) done = true;
1634 button.setAttribute('label', label);
1641 function validateBibField (tags, searches) {
1642 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1643 url += '¶m="tags"¶m=' + js2JSON(tags);
1644 url += '¶m="searches"¶m=' + js2JSON(searches);
1647 var req = new XMLHttpRequest();
1648 req.open('GET',url,false);
1656 function searchAuthority (term, tag, sf, limit) {
1657 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1658 url += '¶m="term"¶m="' + term + '"';
1659 url += '¶m="limit"¶m=' + limit;
1660 url += '¶m="tag"¶m=' + tag;
1661 url += '¶m="subfield"¶m="' + sf + '"';
1664 var req = new XMLHttpRequest();
1665 req.open('GET',url,false);
1672 /* TODO new authority browse support for context sets, and use that here */
1673 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
1674 dojo.require('dojox.xml.parser');
1676 // map tag + subfield to the appropriate authority browse axis:
1677 // currently authority.author, authority.subject, authority.title, authority.topic
1678 // based on mappings in OpenILS::Application::SuperCat, though Authority Control
1679 // Sets will change that
1681 var axis_list = acs.bibFieldBrowseAxes( sf.parent().@tag.toString() );
1683 // No matching tag means no authorities to search - shortcut
1684 if (axis_list.length == 0) {
1685 target.setAttribute('context', 'clipboard');
1689 var type = 'authority.' + axis_list[0]; // Just take the first for now
1690 // TODO support multiple axes ... loop?
1699 var url = '/opac/extras/browse/marcxml/'
1701 + '/1' // OU - currently unscoped
1702 + '/' + sf.toString()
1707 // would be good to carve this out into a separate function
1708 dojo.xhrGet({"url":url, "sync": true, "preventCache": true, "handleAs":"xml", "load": function(records) {
1709 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
1711 var cm_popup = create_menu.appendChild(
1715 cm_popup.appendChild(
1716 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
1717 command : function() {
1718 // Call middle-layer function to create and save the new authority
1719 var source_f = summarizeField(sf);
1720 var new_auth = fieldmapper.standardRequest(
1721 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
1722 [source_f, xulG.marc_control_number_identifier, ses()]
1724 if (new_auth && new_auth.id()) {
1725 addNewAuthorityID(new_auth, sf, target);
1731 cm_popup.appendChild(
1732 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
1733 command : function() {
1734 // Generate the new authority by calling the new middle-layer
1735 // function (a non-saving variant), then display in another
1737 var source_f = summarizeField(sf);
1738 var authtoken = ses();
1739 dojo.require('openils.PermaCrud');
1740 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
1741 var rec = fieldmapper.standardRequest(
1742 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
1743 { "params": [source_f, xulG.marc_control_number_identifier] }
1745 loadMarcEditor(pcrud, rec, target, sf);
1750 sf_popup.appendChild(create_menu);
1751 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1753 // append "Previous page" results browser
1754 sf_popup.appendChild(
1755 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
1756 command : function(event) {
1757 auth_pages[menu_id] -= 1;
1758 show_auth_menu = true;
1762 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1764 dojo.query('record', records).forEach(function(record) {
1768 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"] subfield[code="c"]', record)[0]);
1769 var auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
1771 // Grab the fields with tags beginning with 1 (main entries) and iterate through the subfields
1772 dojo.query('datafield[tag^="1"]', record).forEach(function(field) {
1773 dojo.query('subfield', field).forEach(function(subfield) {
1777 main_text += dojox.xml.parser.textContent(subfield);
1781 // Grab the fields with tags beginning with 4 (see from entries) and iterate through the subfields
1782 dojo.query('datafield[tag^="4"]', record).forEach(function(field) {
1784 dojo.query('subfield', field).forEach(function(subfield) {
1788 see_text += dojox.xml.parser.textContent(subfield);
1790 see_from.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_from', [see_text]));
1793 // Grab the fields with tags beginning with 5 (see also entries) and iterate through the subfields
1794 dojo.query('datafield[tag^="5"]', record).forEach(function(field) {
1796 dojo.query('subfield', field).forEach(function(subfield) {
1800 see_text += dojox.xml.parser.textContent(subfield);
1802 see_also.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_also', [see_text]));
1805 buildAuthorityPopup(main_text, record, auth_org, auth_id, sf_popup, target, sf);
1807 dojo.forEach(see_from, function(entry_text) {
1808 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1811 // To-do: instead of launching the standard selector menu, invoke
1812 // a new authority search using the 5XX entry text
1813 dojo.forEach(see_also, function(entry_text) {
1814 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1819 if (sf_popup.childNodes.length == 0) {
1820 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1822 // append "Next page" results browser
1823 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1824 sf_popup.appendChild(
1825 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
1826 command : function(event) {
1827 auth_pages[menu_id] += 1;
1828 show_auth_menu = true;
1834 target.setAttribute('context', menu_id);
1840 function buildAuthorityPopup (entry_text, record, auth_org, auth_id, sf_popup, target, sf, style) {
1841 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
1842 grid.setAttribute('name','-none-');
1843 grid.setAttribute('style','overflow:scroll');
1845 var submenu = createMenu( { "label": entry_text } );
1847 var popup = createMenuPopup({ "flex": "1" });
1849 submenu.setAttribute('style', style);
1850 popup.setAttribute('style', 'font-style: normal; margin-left: 0em;');
1852 submenu.appendChild(popup);
1854 dojo.query('datafield[tag^="1"], datafield[tag^="4"], datafield[tag^="5"]', record).forEach(function(field) {
1855 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1858 grid.hidden = false;
1859 popup.appendChild( grid );
1863 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1864 command : function (event) {
1865 applySelectedAuthority(event.target.previousSibling, target, sf);
1872 popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1876 { label : $('catStrings').getString('staff.cat.marcedit.apply_full.label'),
1877 command : function (event) {
1878 applyFullAuthority(event.target.previousSibling.previousSibling.previousSibling, target, sf);
1885 sf_popup.appendChild( submenu );
1888 function buildAuthorityPopupSelector (field, grid, auth_org, auth_id) {
1889 var row = createRow(
1891 createLabel( { "value" : dojo.attr(field, 'tag') } ),
1892 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
1893 createLabel( { "value" : dojo.attr(field, 'ind2') } )
1896 var sf_box = createHbox();
1897 dojo.query('subfield', field).forEach(function(subfield) {
1900 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
1901 "subfield" : dojo.attr(subfield, 'code'),
1902 "tag" : dojo.attr(field, 'tag'),
1903 "value" : dojox.xml.parser.textContent(subfield)
1907 row.appendChild(sf_box);
1910 // Append the authority linking subfield only for main entries
1911 if (dojo.attr(field, 'tag').charAt(0) == '1') {
1914 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
1916 "tag" : dojo.attr(field, 'tag'),
1917 "ind1" : dojo.attr(field, 'ind1'),
1918 "ind2" : dojo.attr(field, 'ind2'),
1919 "value" : '(' + auth_org + ')' + auth_id
1924 row.appendChild(sf_box);
1926 grid.lastChild.appendChild(row);
1929 function summarizeField(sf) {
1937 source_f.tag = sf.parent().@tag.toString();
1938 source_f.ind1 = sf.parent().@ind1.toString();
1939 source_f.ind2 = sf.parent().@ind2.toString();
1942 dojo.forEach( acs.controlSetList(), function (acs_id) {
1943 if (acs.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
1947 if (!found_acs.length) {
1950 cmap = acs.controlSet(found_acs[0]).control_map;
1953 for (var i = 0; i < sf.parent().subfield.length(); i++) {
1954 var sf_iter = sf.parent().subfield[i];
1956 /* Filter out subfields that are not controlled for this tag */
1957 if (!cmap[source_f.tag][sf_iter.@code.toString()]) {
1961 source_f.subfields.push([sf_iter.@code.toString(), sf_iter.toString()]);
1967 function buildBibSourceList (authtoken, recId) {
1968 /* TODO: Work out how to set the bib source of the bre that does not yet
1969 * exist - this is specifically in the case of Z39.50 imports. Right now
1970 * we just avoid populating and showing the config.bib_source list
1976 var bib = xulG.record.bre;
1978 dojo.require('openils.PermaCrud');
1980 // cbsList = the XUL menulist that contains the available bib sources
1981 var cbsList = dojo.byId('bib-source-list');
1983 // bibSources = an array containing all of the bib source objects
1984 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
1986 // A tad ugly, but gives us the index of the bib source ID in cbsList
1988 var cbsListArr = [];
1989 dojo.forEach(bibSources, function (item) {
1990 cbsList.appendItem(item.source(), item.id());
1991 cbsListArr[item.id()] = x;
1995 // Show the current value of the bib source for this record
1996 cbsList.selectedIndex = cbsListArr[bib.source()];
1998 // Display the bib source selection widget
1999 dojo.byId('bib-source-list-caption').hidden = false;
2000 dojo.byId('bib-source-list').hidden = false;
2001 dojo.byId('bib-source-list-button').disabled = true;
2002 dojo.byId('bib-source-list-button').hidden = false;
2005 // Fired when the "Update Source" button is clicked
2006 // Updates the value of the bib source for the current record
2007 function updateBibSource() {
2008 var authtoken = ses();
2009 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2010 var recId = xulG.record.id;
2011 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2012 var bib = pcrud.retrieve('bre', recId);
2013 if (bib.source() != cbs) {
2015 bib.ischanged = true;
2020 function onBibSourceSelect() {
2021 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2022 var bib = xulG.record.bre;
2023 if (bib.source() != cbs) {
2024 dojo.byId('bib-source-list-button').disabled = false;
2026 dojo.byId('bib-source-list-button').disabled = true;
2030 function addNewAuthorityID(authority, sf, target) {
2031 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){authority.id()}</subfield>;
2032 sf.parent().appendChild(id_sf);
2033 var new_sf = marcSubfield(id_sf);
2036 while (dojo.attr(node, 'name') != 'sf_box') {
2037 node = node.parentNode;
2039 node.appendChild( new_sf );
2041 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2044 function loadMarcEditor(pcrud, marcxml, target, sf) {
2046 To run in Firefox directly, must set signed.applets.codebase_principal_support
2047 to true in about:config
2049 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
2050 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
2052 // Match marc2are.pl last_xact_id format, roughly
2054 var xact_id = 'IMPORT-' + Date.parse(now);
2057 "record": {"marc": marcxml, "rtype": "are"},
2059 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2060 "func": function(xmlString) {
2061 var rec = new are();
2062 rec.marc(xmlString);
2063 rec.last_xact_id(xact_id);
2066 "oncomplete": function (r, objs) {
2067 var new_rec = objs[0];
2072 addNewAuthorityID(new_rec, sf, target);