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);
776 // Hide FFEditor rows that we don't need for our current type
777 // If all of the labels for a given row do not include our
778 // desired type in their set attribute, we can hide that row
779 dojo.query('rows row', grid).forEach(function(node, index, arr) {
780 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
787 function fillFixedFields () {
789 var grid = document.getElementById('leaderGrid');
790 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
793 var pre_list = grid.getElementsByTagName('label');
794 for (var i in pre_list) {
795 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
796 list.push( pre_list[i] );
800 for (var i in list) {
801 var name = list[i].getAttribute('name');
802 var value = marc_rec.extractFixedField(name, true);
804 if (value === null) continue;
806 list[i].nextSibling.value = value;
811 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
815 function updateFixedFields (element) {
816 var grid = document.getElementById('leaderGrid');
817 var recGrid = document.getElementById('recGrid');
818 var new_value = element.value;
820 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
821 marc_rec.setFixedField(element.getAttribute('name'), new_value);
823 var xml_string = marc_rec.toXmlString();
824 xml_record = new XML( xml_string );
825 if (xml_record..record[0]) xml_record = xml_record..record[0];
831 function marcLeader (leader) {
833 { class : 'marcLeaderRow',
838 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
841 class : 'marcInd1' } ),
844 class : 'marcInd2' } ),
846 { value : leader.text(),
847 class : 'marcLeader' } )
853 function marcControlfield (field) {
854 tagname = field.@tag.toString().substr(2);
856 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
858 { class : 'marcControlfieldRow',
859 tag : '_' + tagname },
861 { value : field.@tag,
863 context : 'tags_popup',
864 onmouseover : 'getTooltip(this, "tag");',
865 tooltipid : 'tag' + field.@tag } ),
867 { value : field.@ind1,
869 onmouseover : 'getTooltip(this, "ind1");',
870 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
872 { value : field.@ind2,
874 onmouseover : 'getTooltip(this, "ind2");',
875 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
878 { value : field.text(),
879 class : 'plain marcEditableControlfield',
880 name : 'CONTROL' + tagname,
881 context : 'clipboard',
887 { class : 'marcControlfieldRow',
888 tag : '_' + tagname },
890 { value : field.@tag,
892 onmouseover : 'getTooltip(this, "tag");',
893 tooltipid : 'tag' + field.@tag } ),
895 { value : field.@ind1,
897 onmouseover : 'getTooltip(this, "ind1");',
898 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
900 { value : field.@ind2,
902 onmouseover : 'getTooltip(this, "ind2");',
903 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
905 { value : field.text(),
906 class : 'marcControlfield' } )
913 function stackSubfields(checkbox) {
914 var list = document.getElementsByAttribute('name','sf_box');
917 if (!checkbox.checked) o = 'horizontal';
919 for (var i = 0; i < list.length; i++) {
920 if (list[i]) list[i].setAttribute('orient',o);
924 function fastItemAdd_toggle(checkbox) {
925 var x = document.getElementById('fastItemAdd_textboxes');
926 if (checkbox.checked) {
928 document.getElementById('fastItemAdd_callnumber').focus();
929 document.getElementById('fastItemAdd_callnumber').select();
935 function fastItemAdd_attempt(doc_id) {
937 if (typeof window.xulG.fast_add_item != 'function') { return; }
938 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
939 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
940 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
941 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
942 document.getElementById('fastItemAdd_barcode').value = '';
944 alert('fastItemAdd_attempt: ' + E);
948 function save_attempt(xml_string) {
950 var result = window.xulG.save.func( xml_string );
953 if (result.id) fastItemAdd_attempt(result.id);
954 if (typeof result.on_complete == 'function') result.on_complete();
957 alert('save_attempt: ' + E);
961 function marcDatafield (field) {
963 { class : 'marcDatafieldRow' },
966 { value : field.@tag,
967 class : 'plain marcTag',
969 context : 'tags_popup',
970 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
973 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
976 { value : field.@ind1,
977 class : 'plain marcInd1',
979 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
982 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
983 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
986 { value : field.@ind2,
987 class : 'plain marcInd2',
989 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
992 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
993 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
994 createHbox({ name : 'sf_box' })
997 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
998 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
999 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1001 var sf_box = row.lastChild;
1002 if (document.getElementById('stackSubfields').checked)
1003 sf_box.setAttribute('orient','vertical');
1005 sf_box.addEventListener(
1008 if (sf_box === e.target) {
1009 sf_box.lastChild.lastChild.focus();
1010 } else if (e.target.parentNode === sf_box) {
1011 e.target.lastChild.focus();
1018 for (var i in field.subfield) {
1019 var sf = field.subfield[i];
1024 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1026 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1027 current_focus = sf_box.lastChild.childNodes[1];
1033 function marcSubfield (sf) {
1035 { class : 'marcSubfieldBox' },
1038 class : 'plain marcSubfieldDelimiter',
1039 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1040 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1041 //onclick : 'this.nextSibling.focus();',
1042 onfocus : 'this.nextSibling.focus();',
1047 class : 'plain marcSubfieldCode',
1048 name : 'marcSubfieldCode',
1049 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1050 oncontextmenu : 'getContextMenu(this, "subfield");',
1051 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1056 { value : sf.text(),
1057 name : sf.parent().@tag + ':' + sf.@code,
1058 class : 'plain marcSubfield',
1059 onmouseover : 'getTooltip(this, "subfield");',
1060 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1061 size : new String(sf.text()).length + 2,
1062 oninput : "this.setAttribute('size', this.value.length + 2);"
1067 function loadRecord() {
1069 var grid_rows = document.getElementById('recGrid').lastChild;
1071 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1073 grid_rows.appendChild( marcLeader( xml_record.leader ) );
1075 for (var i in xml_record.controlfield) {
1076 grid_rows.appendChild( marcControlfield( xml_record.controlfield[i] ) );
1079 for (var i in xml_record.datafield) {
1080 grid_rows.appendChild( marcDatafield( xml_record.datafield[i] ) );
1083 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1085 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
1086 changeFFEditor(marc_rec.recordType());
1089 alert('FIXME, MARC Editor, loadRecord: ' + E);
1094 function genToolTips () {
1095 for (var i in bib_data.field) {
1096 var f = bib_data.field[i];
1098 tag_menu.appendChild(
1102 'current_focus.value = "' + f.@tag + '";' +
1103 'var e = document.createEvent("MutationEvents");' +
1104 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1105 'current_focus.inputField.dispatchEvent(e);',
1106 disabled : f.@tag < '010' ? "true" : "false",
1107 tooltiptext : f.description }
1111 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1112 context_menus.appendChild( i1_popup );
1114 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1115 context_menus.appendChild( i2_popup );
1117 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1118 context_menus.appendChild( sf_popup );
1120 tooltip_hash['tag' + f.@tag] = f.description;
1121 for (var j in f.indicator) {
1122 var ind = f.indicator[j];
1123 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1125 if (ind.@position == 1) {
1126 i1_popup.appendChild(
1128 { label : ind.@value,
1130 'current_focus.value = "' + ind.@value + '";' +
1131 'var e = document.createEvent("MutationEvents");' +
1132 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1133 'current_focus.inputField.dispatchEvent(e);',
1134 tooltiptext : ind.description }
1139 if (ind.@position == 2) {
1140 i2_popup.appendChild(
1142 { label : ind.@value,
1144 'current_focus.value = "' + ind.@value + '";' +
1145 'var e = document.createEvent("MutationEvents");' +
1146 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1147 'current_focus.inputField.dispatchEvent(e);',
1148 tooltiptext : ind.description }
1154 for (var j in f.subfield) {
1155 var sf = f.subfield[j];
1156 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1158 sf_popup.appendChild(
1162 'current_focus.value = "' + sf.@code + '";' +
1163 'var e = document.createEvent("MutationEvents");' +
1164 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1165 'current_focus.inputField.dispatchEvent(e);',
1166 tooltiptext : sf.description
1174 function getTooltip (target, type) {
1177 if (type == 'subfield')
1178 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1181 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1184 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1187 tt = 'tag' + target.parentNode.firstChild.value;
1189 if (!document.getElementById( tt )) {
1194 orient : 'vertical',
1195 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1196 class : 'tooltip' },
1197 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1202 target.tooltip = tt;
1206 function getContextMenu (target, type) {
1209 if (type == 'subfield')
1210 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1213 tt = 't' + target.parentNode.firstChild.value + 'i1';
1216 tt = 't' + target.parentNode.firstChild.value + 'i2';
1218 target.setAttribute('context', tt);
1224 'a' : { 100 : 'a' },
1225 'd' : { 100 : 'd' },
1226 'e' : { 100 : 'e' },
1230 'a' : { 110 : 'a' },
1234 'a' : { 111 : 'a' },
1238 'a' : { 130 : 'a' },
1242 'a' : { 130 : 'a' },
1246 'a' : { 100 : 'a' },
1250 'a' : { 110 : 'a' },
1254 'a' : { 111 : 'a' },
1258 'a' : { 130 : 'a' },
1259 'n' : { 130 : 'n' },
1263 'a' : { 100 : 'a' },
1264 'd' : { 100 : 'd' },
1265 'q' : { 100 : 'q' },
1269 'a' : { 110 : 'a' },
1273 'a' : { 111 : 'a' },
1274 'c' : { 111 : 'c' },
1278 'a' : { 130 : 'a' },
1282 'a' : { 100 : 'a' },
1286 'a' : { 110 : 'a' },
1290 'a' : { 111 : 'a' },
1294 'a' : { 130 : 'a' },
1298 'a' : { 100 : 'a' },
1299 'd' : { 100 : 'd' },
1300 'q' : { 100 : 'q' },
1301 't' : { 100 : 't' },
1328 'a' : { 110 : 'a' },
1329 'd' : { 110 : 'd' },
1330 't' : { 110 : 't' },
1357 'a' : { 111 : 'a' },
1358 'd' : { 111 : 'd' },
1359 't' : { 111 : 't' },
1386 'a' : { 130 : 'a' },
1390 'a' : { 148 : 'a' },
1391 'v' : { 148 : 'v' },
1392 'x' : { 148 : 'x' },
1393 'y' : { 148 : 'y' },
1397 'a' : { 150 : 'a' },
1398 'b' : { 150 : 'b' },
1425 'a' : { 151 : 'a' },
1452 'a' : { 155 : 'a' },
1480 function getAuthorityContextMenu (target, sf) {
1481 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1484 var old = dojo.byId( menu_id );
1486 page = auth_pages[menu_id];
1487 old.parentNode.removeChild(old);
1489 auth_pages[menu_id] = 0;
1492 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1494 sf_popup.addEventListener("popuphiding", function(event) {
1495 if (show_auth_menu) {
1496 show_auth_menu = false;
1497 getAuthorityContextMenu(target, sf);
1498 dojo.byId(menu_id).openPopup();
1502 context_menus.appendChild( sf_popup );
1505 dojo.forEach( acs.controlSetList(), function (acs_id) {
1506 if (acs.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
1509 if (!found_acs.length) {
1510 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1511 target.setAttribute('context', 'clipboard');
1515 if (sf.toString().replace(/\s*/, '')) {
1516 return browseAuthority(sf_popup, menu_id, target, sf, 20, page);
1522 /* Apply the complete 1xx */
1523 function applyFullAuthority ( target, ui_sf, e4x_sf ) {
1524 var new_vals = dojo.query('*[tag^="1"]', target);
1525 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1528 function applySelectedAuthority ( target, ui_sf, e4x_sf ) {
1529 var new_vals = target.getElementsByAttribute('checked','true');
1530 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1533 function applyAuthority ( target, ui_sf, e4x_sf, new_vals ) {
1534 var field = e4x_sf.parent();
1536 for (var i = 0; i < new_vals.length; i++) {
1538 var sf_list = field.subfield;
1539 for (var j in sf_list) {
1541 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1542 sf_list[j] = new_vals[i].getAttribute('value');
1543 new_vals[i].setAttribute('subfield','');
1549 for (var i = 0; i < new_vals.length; i++) {
1550 if (!new_vals[i].getAttribute('subfield')) continue;
1552 var val = new_vals[i].getAttribute('value');
1554 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1555 sf.@code = new_vals[i].getAttribute('subfield');
1557 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1560 var row = marcDatafield( field );
1563 while (node.nodeName != 'row') {
1564 node = node.parentNode;
1567 node.parentNode.replaceChild( row, node );
1571 function validateAuthority (button) {
1572 var grid = document.getElementById('recGrid');
1573 var label = button.getAttribute('label');
1576 var rows = grid.lastChild.childNodes;
1577 for (var i = 0; i < rows.length; i++) {
1579 var tag = row.firstChild;
1582 dojo.forEach(acs.controlSetList(), function (acs_id) {
1584 var control_map = acs.controlSet(acs_id).control_map;
1586 if (!control_map[tag.value]) return;
1587 button.setAttribute('label', label + ' - ' + tag.value);
1589 var ind1 = tag.nextSibling;
1590 var ind2 = ind1.nextSibling;
1591 var subfields = ind2.nextSibling.childNodes;
1594 for (var j = 0; j < subfields.length; j++) {
1595 var sf = subfields[j];
1596 sf_list.push( sf.childNodes[1].value );
1597 sf_list.push( sf.childNodes[2].value );
1600 var matches = acs.findMatchingAuthorities(
1603 'subfields' : sf_list
1607 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1608 for (var j = 0; j < subfields.length; j++) {
1609 var sf = subfields[j];
1610 if (!matches.length) {
1611 dojo.removeClass(sf.childNodes[2], 'marcValidated');
1612 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
1614 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
1615 dojo.addClass(sf.childNodes[2], 'marcValidated');
1619 if (matches.length) done = true;
1623 button.setAttribute('label', label);
1630 function validateBibField (tags, searches) {
1631 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1632 url += '¶m="tags"¶m=' + js2JSON(tags);
1633 url += '¶m="searches"¶m=' + js2JSON(searches);
1636 var req = new XMLHttpRequest();
1637 req.open('GET',url,false);
1645 function searchAuthority (term, tag, sf, limit) {
1646 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1647 url += '¶m="term"¶m="' + term + '"';
1648 url += '¶m="limit"¶m=' + limit;
1649 url += '¶m="tag"¶m=' + tag;
1650 url += '¶m="subfield"¶m="' + sf + '"';
1653 var req = new XMLHttpRequest();
1654 req.open('GET',url,false);
1661 /* TODO new authority browse support for context sets, and use that here */
1662 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
1663 dojo.require('dojox.xml.parser');
1665 // map tag + subfield to the appropriate authority browse axis:
1666 // currently authority.author, authority.subject, authority.title, authority.topic
1667 // based on mappings in OpenILS::Application::SuperCat, though Authority Control
1668 // Sets will change that
1670 var axis_list = acs.bibFieldBrowseAxes( sf.parent().@tag.toString() );
1672 // No matching tag means no authorities to search - shortcut
1673 if (axis_list.length == 0) {
1674 target.setAttribute('context', 'clipboard');
1678 var type = 'authority.' + axis_list[0]; // Just take the first for now
1679 // TODO support multiple axes ... loop?
1688 var url = '/opac/extras/browse/marcxml/'
1690 + '/1' // OU - currently unscoped
1691 + '/' + sf.toString()
1696 // would be good to carve this out into a separate function
1697 dojo.xhrGet({"url":url, "sync": true, "preventCache": true, "handleAs":"xml", "load": function(records) {
1698 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
1700 var cm_popup = create_menu.appendChild(
1704 cm_popup.appendChild(
1705 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
1706 command : function() {
1707 // Call middle-layer function to create and save the new authority
1708 var source_f = summarizeField(sf);
1709 var new_auth = fieldmapper.standardRequest(
1710 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
1711 [source_f, xulG.marc_control_number_identifier, ses()]
1713 if (new_auth && new_auth.id()) {
1714 addNewAuthorityID(new_auth, sf, target);
1720 cm_popup.appendChild(
1721 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
1722 command : function() {
1723 // Generate the new authority by calling the new middle-layer
1724 // function (a non-saving variant), then display in another
1726 var source_f = summarizeField(sf);
1727 var authtoken = ses();
1728 dojo.require('openils.PermaCrud');
1729 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
1730 var rec = fieldmapper.standardRequest(
1731 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
1732 { "params": [source_f, xulG.marc_control_number_identifier] }
1734 loadMarcEditor(pcrud, rec, target, sf);
1739 sf_popup.appendChild(create_menu);
1740 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1742 // append "Previous page" results browser
1743 sf_popup.appendChild(
1744 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
1745 command : function(event) {
1746 auth_pages[menu_id] -= 1;
1747 show_auth_menu = true;
1751 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1753 dojo.query('record', records).forEach(function(record) {
1757 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"] subfield[code="c"]', record)[0]);
1758 var auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
1760 // Grab the fields with tags beginning with 1 (main entries) and iterate through the subfields
1761 dojo.query('datafield[tag^="1"]', record).forEach(function(field) {
1762 dojo.query('subfield', field).forEach(function(subfield) {
1766 main_text += dojox.xml.parser.textContent(subfield);
1770 // Grab the fields with tags beginning with 4 (see from entries) and iterate through the subfields
1771 dojo.query('datafield[tag^="4"]', record).forEach(function(field) {
1773 dojo.query('subfield', field).forEach(function(subfield) {
1777 see_text += dojox.xml.parser.textContent(subfield);
1779 see_from.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_from', [see_text]));
1782 // Grab the fields with tags beginning with 5 (see also entries) and iterate through the subfields
1783 dojo.query('datafield[tag^="5"]', record).forEach(function(field) {
1785 dojo.query('subfield', field).forEach(function(subfield) {
1789 see_text += dojox.xml.parser.textContent(subfield);
1791 see_also.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_also', [see_text]));
1794 buildAuthorityPopup(main_text, record, auth_org, auth_id, sf_popup, target, sf);
1796 dojo.forEach(see_from, function(entry_text) {
1797 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1800 // To-do: instead of launching the standard selector menu, invoke
1801 // a new authority search using the 5XX entry text
1802 dojo.forEach(see_also, function(entry_text) {
1803 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1808 if (sf_popup.childNodes.length == 0) {
1809 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1811 // append "Next page" results browser
1812 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1813 sf_popup.appendChild(
1814 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
1815 command : function(event) {
1816 auth_pages[menu_id] += 1;
1817 show_auth_menu = true;
1823 target.setAttribute('context', menu_id);
1829 function buildAuthorityPopup (entry_text, record, auth_org, auth_id, sf_popup, target, sf, style) {
1830 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
1831 grid.setAttribute('name','-none-');
1832 grid.setAttribute('style','overflow:scroll');
1834 var submenu = createMenu( { "label": entry_text } );
1836 var popup = createMenuPopup({ "flex": "1" });
1838 submenu.setAttribute('style', style);
1839 popup.setAttribute('style', 'font-style: normal; margin-left: 0em;');
1841 submenu.appendChild(popup);
1843 dojo.query('datafield[tag^="1"], datafield[tag^="4"], datafield[tag^="5"]', record).forEach(function(field) {
1844 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1847 grid.hidden = false;
1848 popup.appendChild( grid );
1852 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1853 command : function (event) {
1854 applySelectedAuthority(event.target.previousSibling, target, sf);
1861 popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1865 { label : $('catStrings').getString('staff.cat.marcedit.apply_full.label'),
1866 command : function (event) {
1867 applyFullAuthority(event.target.previousSibling.previousSibling.previousSibling, target, sf);
1874 sf_popup.appendChild( submenu );
1877 function buildAuthorityPopupSelector (field, grid, auth_org, auth_id) {
1878 var row = createRow(
1880 createLabel( { "value" : dojo.attr(field, 'tag') } ),
1881 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
1882 createLabel( { "value" : dojo.attr(field, 'ind2') } )
1885 var sf_box = createHbox();
1886 dojo.query('subfield', field).forEach(function(subfield) {
1889 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
1890 "subfield" : dojo.attr(subfield, 'code'),
1891 "tag" : dojo.attr(field, 'tag'),
1892 "value" : dojox.xml.parser.textContent(subfield)
1896 row.appendChild(sf_box);
1899 // Append the authority linking subfield only for main entries
1900 if (dojo.attr(field, 'tag').charAt(0) == '1') {
1903 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
1905 "tag" : dojo.attr(field, 'tag'),
1906 "value" : '(' + auth_org + ')' + auth_id
1911 row.appendChild(sf_box);
1913 grid.lastChild.appendChild(row);
1916 function summarizeField(sf) {
1924 source_f.tag = sf.parent().@tag.toString();
1925 source_f.ind1 = sf.parent().@ind1.toString();
1926 source_f.ind1 = sf.parent().@ind2.toString();
1928 for (var i = 0; i < sf.parent().subfield.length(); i++) {
1929 var sf_iter = sf.parent().subfield[i];
1931 /* Filter out subfields that are not controlled for this tag */
1932 if (!control_map[source_f.tag][sf_iter.@code.toString()]) {
1936 source_f.subfields.push([sf_iter.@code.toString(), sf_iter.toString()]);
1942 function buildBibSourceList (authtoken, recId) {
1943 /* TODO: Work out how to set the bib source of the bre that does not yet
1944 * exist - this is specifically in the case of Z39.50 imports. Right now
1945 * we just avoid populating and showing the config.bib_source list
1951 var bib = xulG.record.bre;
1953 dojo.require('openils.PermaCrud');
1955 // cbsList = the XUL menulist that contains the available bib sources
1956 var cbsList = dojo.byId('bib-source-list');
1958 // bibSources = an array containing all of the bib source objects
1959 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
1961 // A tad ugly, but gives us the index of the bib source ID in cbsList
1963 var cbsListArr = [];
1964 dojo.forEach(bibSources, function (item) {
1965 cbsList.appendItem(item.source(), item.id());
1966 cbsListArr[item.id()] = x;
1970 // Show the current value of the bib source for this record
1971 cbsList.selectedIndex = cbsListArr[bib.source()];
1973 // Display the bib source selection widget
1974 dojo.byId('bib-source-list-caption').hidden = false;
1975 dojo.byId('bib-source-list').hidden = false;
1976 dojo.byId('bib-source-list-button').disabled = true;
1977 dojo.byId('bib-source-list-button').hidden = false;
1980 // Fired when the "Update Source" button is clicked
1981 // Updates the value of the bib source for the current record
1982 function updateBibSource() {
1983 var authtoken = ses();
1984 var cbs = dojo.byId('bib-source-list').selectedItem.value;
1985 var recId = xulG.record.id;
1986 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
1987 var bib = pcrud.retrieve('bre', recId);
1988 if (bib.source() != cbs) {
1990 bib.ischanged = true;
1995 function onBibSourceSelect() {
1996 var cbs = dojo.byId('bib-source-list').selectedItem.value;
1997 var bib = xulG.record.bre;
1998 if (bib.source() != cbs) {
1999 dojo.byId('bib-source-list-button').disabled = false;
2001 dojo.byId('bib-source-list-button').disabled = true;
2005 function addNewAuthorityID(authority, sf, target) {
2006 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){authority.id()}</subfield>;
2007 sf.parent().appendChild(id_sf);
2008 var new_sf = marcSubfield(id_sf);
2011 while (dojo.attr(node, 'name') != 'sf_box') {
2012 node = node.parentNode;
2014 node.appendChild( new_sf );
2016 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2019 function loadMarcEditor(pcrud, marcxml, target, sf) {
2021 To run in Firefox directly, must set signed.applets.codebase_principal_support
2022 to true in about:config
2024 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
2025 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
2027 // Match marc2are.pl last_xact_id format, roughly
2029 var xact_id = 'IMPORT-' + Date.parse(now);
2032 "record": {"marc": marcxml, "rtype": "are"},
2034 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2035 "func": function(xmlString) {
2036 var rec = new are();
2037 rec.marc(xmlString);
2038 rec.last_xact_id(xact_id);
2041 "oncomplete": function (r, objs) {
2042 var new_rec = objs[0];
2047 addNewAuthorityID(new_rec, sf, target);