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 = new openils.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 // Fake xulG for standalone...
163 window.xulG.record = {};
164 window.xulG.save = {};
165 window.xulG.marc_control_number_identifier = 'CONS';
167 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
168 window.xulG.save.func = function (r) { alert(r); }
171 var _rid = cgi.param('record');
173 window.xulG.record.id = _rid;
174 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
178 // End faking part...
180 /* Check for an explicitly passed record type
181 * This is not the same as the fixed-field record type; we can't trust
182 * the fixed fields when making modifications to the attributes for a
183 * given record (in particular, config.bib_source only applies for bib
184 * records, but an auth or MFHD record with the same ID and bad fixed
185 * fields could trample the config.bib_source value for the
186 * corresponding bib record if we're not careful.
188 * are = authority record
189 * sre = serial record (MFHD)
190 * bre = bibliographic record
192 if (!window.xulG.record.rtype) {
194 window.xulG.record.rtype = cgi.param('rtype') || false;
197 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
198 document.getElementById('save-button').setAttribute('oncommand',
199 'if ($("xul-editor").hidden) set_flat_editor(false); ' +
201 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
202 'save_attempt( xml_string ); ' +
206 if (window.xulG.record.url) {
207 var req = new XMLHttpRequest();
208 req.open('POST',window.xulG.record.url,false);
210 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
213 xml_record = new XML( window.xulG.record.marc );
214 if (xml_record..record[0]) xml_record = xml_record..record[0];
216 // Get the tooltip xml all async like
217 req = new XMLHttpRequest();
219 // Set a default locale in case preferences fail us
220 var locale = "en-US";
222 // Try to get the locale from our preferences
223 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
225 const Cc = Components.classes;
226 const Ci = Components.interfaces;
227 locale = Cc["@mozilla.org/preferences-service;1"].
228 getService(Ci.nsIPrefBranch).
229 getCharPref("general.useragent.locale");
233 // TODO: We should send a HEAD request to check for the existence of the desired file
234 // then fall back to the default locale if preferred locale is not necessary;
235 // however, for now we have a simplistic check:
237 // we currently have translations for only two locales; in the absence of a
238 // valid locale, default to the almighty en-US
239 if (locale != 'en-US' && locale != 'fr-CA') {
243 // grab the right tooltip based on MARC type
244 var tooltip_doc = 'marcedit-tooltips.xml';
245 switch (window.xulG.record.rtype) {
247 tooltip_doc = 'marcedit-tooltips.xml';
250 tooltip_doc = 'marcedit-tooltips-authority.xml';
251 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
254 tooltip_doc = 'marcedit-tooltips-mfhd.xml';
255 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
258 tooltip_doc = 'marcedit-tooltips.xml';
261 // Get the locale-specific tooltips
262 req.open('GET','/xul/server/locale/' + locale + '/' + tooltip_doc,true);
264 context_menus = createComplexXULElement('popupset');
265 document.documentElement.appendChild( context_menus );
267 tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
268 context_menus.appendChild( tag_menu );
270 tag_menu.appendChild(
272 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
274 'var e = document.createEvent("KeyEvents");' +
275 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
276 'current_focus.inputField.dispatchEvent(e);'
281 tag_menu.appendChild(
283 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
285 'var e = document.createEvent("KeyEvents");' +
286 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
287 'current_focus.inputField.dispatchEvent(e);'
292 tag_menu.appendChild(
294 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
296 'var e = document.createEvent("KeyEvents");' +
297 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
298 'current_focus.inputField.dispatchEvent(e);'
303 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
305 tag_menu.appendChild(
307 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
309 'var e = document.createEvent("KeyEvents");' +
310 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
311 'current_focus.inputField.dispatchEvent(e);'
316 tag_menu.appendChild(
318 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
320 'var e = document.createEvent("KeyEvents");' +
321 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
322 'current_focus.inputField.dispatchEvent(e);'
327 tag_menu.appendChild(
329 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
331 'var e = document.createEvent("KeyEvents");' +
332 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
333 'current_focus.inputField.dispatchEvent(e);'
338 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
340 p = createComplexXULElement('popupset');
341 document.documentElement.appendChild( p );
343 req.onreadystatechange = function () {
344 if (req.readyState == 4) {
345 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
353 if (! xulG.fast_add_item) {
354 document.getElementById('fastItemAdd_checkbox').hidden = true;
356 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
358 // Only show bib sources for bib records that already exist in the database
359 if (xulG.record.rtype == 'bre' && xulG.record.id) {
360 dojo.require('openils.PermaCrud');
361 var authtoken = ses();
362 // Retrieve the current record attributes
363 var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
365 // Remember the current bib source of the record
366 xulG.record.bre = bib;
368 buildBibSourceList(authtoken, xulG.record.id);
371 dojo.require('MARC.FixedFields');
374 alert('FIXME, MARC Editor, my_init: ' + E);
379 function createComplexHTMLElement (e, attrs, objects, text) {
380 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
383 for (var i in attrs) l.setAttribute(i,attrs[i]);
387 for ( var i in objects ) l.appendChild( objects[i] );
391 l.appendChild( document.createTextNode(text) )
397 function createComplexXULElement (e, attrs, objects) {
398 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
401 for (var i in attrs) {
402 if (typeof attrs[i] == 'function') {
403 l.addEventListener( i, attrs[i], true );
405 l.setAttribute(i,attrs[i]);
411 for ( var i in objects ) l.appendChild( objects[i] );
417 function createDescription (attrs) {
418 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
421 function createTooltip (attrs) {
422 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
425 function createLabel (attrs) {
426 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
429 function createVbox (attrs) {
430 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
433 function createHbox (attrs) {
434 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
437 function createRow (attrs) {
438 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
441 function createTextbox (attrs) {
442 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
445 function createMenu (attrs) {
446 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
449 function createMenuPopup (attrs) {
450 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
453 function createPopup (attrs) {
454 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
457 function createMenuitem (attrs) {
458 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
461 function createCheckbox (attrs) {
462 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
465 // Find the next textbox that we can use for a focus point
466 // For control fields, use the first editable text box
467 // For data fields, focus on the first subfield text box
468 function setFocusToNextTag (row, direction) {
469 var keep_looking = true;
470 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
471 // Is it a datafield?
472 dojo.query('hbox hbox textbox', row).forEach(function(node, index, arr) {
474 keep_looking = false;
477 // No, it's a control field; use the first textbox
479 dojo.query('textbox', row).forEach(function(node, index, arr) {
481 keep_looking = false;
490 function createMARCTextbox (element,attrs) {
492 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
493 box.addEventListener('keypress',function(ev) { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); if (!(ev.altKey || ev.ctrlKey || ev.metaKey)) { oils_lock_page(); } },false);
494 box.onkeypress = function (event) {
497 while(node = node.parent()) {
501 var row = event.target;
502 while (row.tagName != 'row') row = row.parentNode;
504 if (element.nodeKind() == 'attribute') element[0]=box.value;
505 else element.setChildren( box.value );
507 if (element.localName() != 'controlfield') {
508 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
510 var index_sf, target, move_data;
511 if (element.localName() == 'subfield') {
513 target = event.target.parentNode;
515 var start = event.target.selectionStart;
516 var end = event.target.selectionEnd - event.target.selectionStart ?
517 event.target.selectionEnd :
518 event.target.value.length;
520 move_data = event.target.value.substring(start,end);
521 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
522 event.target.setAttribute('size', event.target.value.length + 2);
524 element.setChildren( event.target.value );
526 } else if (element.localName() == 'code') {
527 index_sf = element.parent();
528 target = event.target.parentNode;
529 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
530 index_sf = element.parent().children()[element.parent().children().length() - 1];
531 target = event.target.parentNode.lastChild.lastChild;
534 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
536 index_sf.parent().insertChildAfter( index_sf, sf );
538 var new_sf = marcSubfield(sf);
540 if (target === target.parentNode.lastChild) {
541 target.parentNode.appendChild( new_sf );
543 target.parentNode.insertBefore( new_sf, target.nextSibling );
546 new_sf.firstChild.nextSibling.focus();
548 event.preventDefault();
551 } else if (event.keyCode == 13 || event.keyCode == 77) {
552 if (event.ctrlKey) { // ctrl+enter
555 if (element.localName() == 'subfield') index = element.parent();
556 if (element.localName() == 'code') index = element.parent().parent();
557 if (element.localName() == 'tag') index = element.parent();
558 if (element.localName() == 'ind1') index = element.parent();
559 if (element.localName() == 'ind2') index = element.parent();
561 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
563 if (event.shiftKey) { // ctrl+shift+enter
564 index.parent().insertChildBefore( index, df );
566 index.parent().insertChildAfter( index, df );
569 var new_df = marcDatafield(df);
571 if (row.parentNode.lastChild === row) {
572 row.parentNode.appendChild( new_df );
574 if (event.shiftKey) { // ctrl+shift+enter
575 row.parentNode.insertBefore( new_df, row );
577 row.parentNode.insertBefore( new_df, row.nextSibling );
581 new_df.firstChild.focus();
583 event.preventDefault();
586 } else if (event.shiftKey) {
587 if (row.previousSibling.className.match('marcDatafieldRow'))
588 row.previousSibling.firstChild.focus();
590 row.nextSibling.firstChild.focus();
593 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
594 if (event.ctrlKey) { // CTRL key: copy the field
596 if (element.localName() == 'subfield') index = element.parent();
597 if (element.localName() == 'code') index = element.parent().parent();
598 if (element.localName() == 'tag') index = element.parent();
599 if (element.localName() == 'ind1') index = element.parent();
600 if (element.localName() == 'ind2') index = element.parent();
602 var copyField = index.copy();
604 if (event.keyCode == 38) { // ctrl+up-arrow
605 index.parent().insertChildBefore( index, copyField );
607 index.parent().insertChildAfter( index, copyField );
610 var new_df = marcDatafield(copyField);
612 if (row.parentNode.lastChild === row) {
613 row.parentNode.appendChild( new_df );
615 if (event.keyCode == 38) { // ctrl+up-arrow
616 row.parentNode.insertBefore( new_df, row );
617 } else { // ctrl+down-arrow
618 row.parentNode.insertBefore( new_df, row.nextSibling );
622 new_df.firstChild.focus();
624 event.preventDefault();
628 if (event.keyCode == 38) {
629 return setFocusToNextTag(row, 'up');
631 if (event.keyCode == 40) {
632 return setFocusToNextTag(row, 'down');
637 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
640 if (element.localName() == 'subfield') index = element.parent();
641 if (element.localName() == 'code') index = element.parent().parent();
642 if (element.localName() == 'tag') index = element.parent();
643 if (element.localName() == 'ind1') index = element.parent();
644 if (element.localName() == 'ind2') index = element.parent();
646 for (var i in index.parent().children()) {
647 if (index === index.parent().children()[i]) {
648 delete index.parent().children()[i];
653 row.previousSibling.firstChild.focus();
654 row.parentNode.removeChild(row);
656 event.preventDefault();
659 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
662 if (element.localName() == 'subfield') index = element;
663 if (element.localName() == 'code') index = element.parent();
666 for (var i in index.parent().children()) {
667 if (index === index.parent().children()[i]) {
668 delete index.parent().children()[i];
673 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
674 event.target.parentNode.previousSibling.lastChild.focus();
676 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
679 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
681 event.preventDefault();
684 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
685 createControlField('006',' ');
687 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
688 createControlField('007',' ');
690 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
691 createControlField('008',' ');
697 } else { // event on a control field
698 if (event.keyCode == 38) {
699 return setFocusToNextTag(row, 'up');
700 } else if (event.keyCode == 40) {
701 return setFocusToNextTag(row, 'down');
706 box.addEventListener(
709 if (element.nodeKind() == 'attribute') element[0]=box.value;
710 else element.setChildren( box.value );
716 box.addEventListener(
719 if (element.nodeKind() == 'attribute') element[0]=box.value;
720 else element.setChildren( box.value );
726 box.addEventListener(
729 if (element.nodeKind() == 'attribute') element[0]=box.value;
730 else element.setChildren( box.value );
736 // 'input' event catches the box value after the keypress
737 box.addEventListener(
740 if (element.nodeKind() == 'attribute') element[0]=box.value;
741 else element.setChildren( box.value );
747 box.addEventListener(
750 if (element.localName() == 'controlfield')
751 eval('fillFixedFields();');
759 function toggleFFE () {
760 var grid = document.getElementById('leaderGrid');
769 function changeFFEditor (type) {
770 var grid = document.getElementById('leaderGrid');
771 grid.setAttribute('type',type);
773 // Hide FFEditor rows that we don't need for our current type
774 // If all of the labels for a given row do not include our
775 // desired type in their set attribute, we can hide that row
776 dojo.query('rows row', grid).forEach(function(node, index, arr) {
777 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
784 function fillFixedFields () {
786 var grid = document.getElementById('leaderGrid');
787 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
790 var pre_list = grid.getElementsByTagName('label');
791 for (var i in pre_list) {
792 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
793 list.push( pre_list[i] );
797 for (var i in list) {
798 var name = list[i].getAttribute('name');
799 var value = marc_rec.extractFixedField(name, true);
801 if (value === null) continue;
803 list[i].nextSibling.value = value;
808 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
812 function updateFixedFields (element) {
813 var grid = document.getElementById('leaderGrid');
814 var recGrid = document.getElementById('recGrid');
815 var new_value = element.value;
817 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
818 marc_rec.setFixedField(element.getAttribute('name'), new_value);
820 var xml_string = marc_rec.toXmlString();
821 xml_record = new XML( xml_string );
822 if (xml_record..record[0]) xml_record = xml_record..record[0];
828 function marcLeader (leader) {
830 { class : 'marcLeaderRow',
835 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
838 class : 'marcInd1' } ),
841 class : 'marcInd2' } ),
843 { value : leader.text(),
844 class : 'marcLeader' } )
850 function marcControlfield (field) {
851 tagname = field.@tag.toString().substr(2);
853 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
855 { class : 'marcControlfieldRow',
856 tag : '_' + tagname },
858 { value : field.@tag,
860 context : 'tags_popup',
861 onmouseover : 'getTooltip(this, "tag");',
862 tooltipid : 'tag' + field.@tag } ),
864 { value : field.@ind1,
866 onmouseover : 'getTooltip(this, "ind1");',
867 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
869 { value : field.@ind2,
871 onmouseover : 'getTooltip(this, "ind2");',
872 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
875 { value : field.text(),
876 class : 'plain marcEditableControlfield',
877 name : 'CONTROL' + tagname,
878 context : 'clipboard',
884 { class : 'marcControlfieldRow',
885 tag : '_' + tagname },
887 { value : field.@tag,
889 onmouseover : 'getTooltip(this, "tag");',
890 tooltipid : 'tag' + field.@tag } ),
892 { value : field.@ind1,
894 onmouseover : 'getTooltip(this, "ind1");',
895 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
897 { value : field.@ind2,
899 onmouseover : 'getTooltip(this, "ind2");',
900 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
902 { value : field.text(),
903 class : 'marcControlfield' } )
910 function stackSubfields(checkbox) {
911 var list = document.getElementsByAttribute('name','sf_box');
914 if (!checkbox.checked) o = 'horizontal';
916 for (var i = 0; i < list.length; i++) {
917 if (list[i]) list[i].setAttribute('orient',o);
921 function fastItemAdd_toggle(checkbox) {
922 var x = document.getElementById('fastItemAdd_textboxes');
923 if (checkbox.checked) {
925 document.getElementById('fastItemAdd_callnumber').focus();
926 document.getElementById('fastItemAdd_callnumber').select();
932 function fastItemAdd_attempt(doc_id) {
934 if (typeof window.xulG.fast_add_item != 'function') { return; }
935 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
936 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
937 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
938 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
939 document.getElementById('fastItemAdd_barcode').value = '';
941 alert('fastItemAdd_attempt: ' + E);
945 function save_attempt(xml_string) {
947 var result = window.xulG.save.func( xml_string );
950 if (result.id) fastItemAdd_attempt(result.id);
951 if (typeof result.on_complete == 'function') result.on_complete();
954 alert('save_attempt: ' + E);
958 function marcDatafield (field) {
960 { class : 'marcDatafieldRow' },
963 { value : field.@tag,
964 class : 'plain marcTag',
966 context : 'tags_popup',
967 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
970 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
973 { value : field.@ind1,
974 class : 'plain marcInd1',
976 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
979 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
980 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
983 { value : field.@ind2,
984 class : 'plain marcInd2',
986 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
989 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
990 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
991 createHbox({ name : 'sf_box' })
994 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
995 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
996 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
998 var sf_box = row.lastChild;
999 if (document.getElementById('stackSubfields').checked)
1000 sf_box.setAttribute('orient','vertical');
1002 sf_box.addEventListener(
1005 if (sf_box === e.target) {
1006 sf_box.lastChild.lastChild.focus();
1007 } else if (e.target.parentNode === sf_box) {
1008 e.target.lastChild.focus();
1015 for (var i in field.subfield) {
1016 var sf = field.subfield[i];
1021 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1023 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1024 current_focus = sf_box.lastChild.childNodes[1];
1030 function marcSubfield (sf) {
1032 { class : 'marcSubfieldBox' },
1035 class : 'plain marcSubfieldDelimiter',
1036 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1037 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1038 //onclick : 'this.nextSibling.focus();',
1039 onfocus : 'this.nextSibling.focus();',
1044 class : 'plain marcSubfieldCode',
1045 name : 'marcSubfieldCode',
1046 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1047 oncontextmenu : 'getContextMenu(this, "subfield");',
1048 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1053 { value : sf.text(),
1054 name : sf.parent().@tag + ':' + sf.@code,
1055 class : 'plain marcSubfield',
1056 onmouseover : 'getTooltip(this, "subfield");',
1057 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1058 size : new String(sf.text()).length + 2,
1059 oninput : "this.setAttribute('size', this.value.length + 2);"
1064 function loadRecord() {
1066 var grid_rows = document.getElementById('recGrid').lastChild;
1068 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1070 grid_rows.appendChild( marcLeader( xml_record.leader ) );
1072 for (var i in xml_record.controlfield) {
1073 grid_rows.appendChild( marcControlfield( xml_record.controlfield[i] ) );
1076 for (var i in xml_record.datafield) {
1077 grid_rows.appendChild( marcDatafield( xml_record.datafield[i] ) );
1080 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1082 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
1083 changeFFEditor(marc_rec.recordType());
1086 alert('FIXME, MARC Editor, loadRecord: ' + E);
1091 function genToolTips () {
1092 for (var i in bib_data.field) {
1093 var f = bib_data.field[i];
1095 tag_menu.appendChild(
1099 'current_focus.value = "' + f.@tag + '";' +
1100 'var e = document.createEvent("MutationEvents");' +
1101 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1102 'current_focus.inputField.dispatchEvent(e);',
1103 disabled : f.@tag < '010' ? "true" : "false",
1104 tooltiptext : f.description }
1108 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1109 context_menus.appendChild( i1_popup );
1111 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1112 context_menus.appendChild( i2_popup );
1114 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1115 context_menus.appendChild( sf_popup );
1117 tooltip_hash['tag' + f.@tag] = f.description;
1118 for (var j in f.indicator) {
1119 var ind = f.indicator[j];
1120 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1122 if (ind.@position == 1) {
1123 i1_popup.appendChild(
1125 { label : ind.@value,
1127 'current_focus.value = "' + ind.@value + '";' +
1128 'var e = document.createEvent("MutationEvents");' +
1129 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1130 'current_focus.inputField.dispatchEvent(e);',
1131 tooltiptext : ind.description }
1136 if (ind.@position == 2) {
1137 i2_popup.appendChild(
1139 { label : ind.@value,
1141 'current_focus.value = "' + ind.@value + '";' +
1142 'var e = document.createEvent("MutationEvents");' +
1143 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1144 'current_focus.inputField.dispatchEvent(e);',
1145 tooltiptext : ind.description }
1151 for (var j in f.subfield) {
1152 var sf = f.subfield[j];
1153 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1155 sf_popup.appendChild(
1159 'current_focus.value = "' + sf.@code + '";' +
1160 'var e = document.createEvent("MutationEvents");' +
1161 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1162 'current_focus.inputField.dispatchEvent(e);',
1163 tooltiptext : sf.description
1171 function getTooltip (target, type) {
1174 if (type == 'subfield')
1175 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1178 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1181 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1184 tt = 'tag' + target.parentNode.firstChild.value;
1186 if (!document.getElementById( tt )) {
1191 orient : 'vertical',
1192 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1193 class : 'tooltip' },
1194 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1199 target.tooltip = tt;
1203 function getContextMenu (target, type) {
1206 if (type == 'subfield')
1207 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1210 tt = 't' + target.parentNode.firstChild.value + 'i1';
1213 tt = 't' + target.parentNode.firstChild.value + 'i2';
1215 target.setAttribute('context', tt);
1221 'a' : { 100 : 'a' },
1222 'd' : { 100 : 'd' },
1223 'e' : { 100 : 'e' },
1227 'a' : { 110 : 'a' },
1231 'a' : { 111 : 'a' },
1235 'a' : { 130 : 'a' },
1239 'a' : { 130 : 'a' },
1243 'a' : { 100 : 'a' },
1247 'a' : { 110 : 'a' },
1251 'a' : { 111 : 'a' },
1255 'a' : { 130 : 'a' },
1256 'n' : { 130 : 'n' },
1260 'a' : { 100 : 'a' },
1261 'd' : { 100 : 'd' },
1262 'q' : { 100 : 'q' },
1266 'a' : { 110 : 'a' },
1270 'a' : { 111 : 'a' },
1271 'c' : { 111 : 'c' },
1275 'a' : { 130 : 'a' },
1279 'a' : { 100 : 'a' },
1283 'a' : { 110 : 'a' },
1287 'a' : { 111 : 'a' },
1291 'a' : { 130 : 'a' },
1295 'a' : { 100 : 'a' },
1296 'd' : { 100 : 'd' },
1297 'q' : { 100 : 'q' },
1298 't' : { 100 : 't' },
1325 'a' : { 110 : 'a' },
1326 'd' : { 110 : 'd' },
1327 't' : { 110 : 't' },
1354 'a' : { 111 : 'a' },
1355 'd' : { 111 : 'd' },
1356 't' : { 111 : 't' },
1383 'a' : { 130 : 'a' },
1387 'a' : { 148 : 'a' },
1388 'v' : { 148 : 'v' },
1389 'x' : { 148 : 'x' },
1390 'y' : { 148 : 'y' },
1394 'a' : { 150 : 'a' },
1395 'b' : { 150 : 'b' },
1422 'a' : { 151 : 'a' },
1449 'a' : { 155 : 'a' },
1477 function getAuthorityContextMenu (target, sf) {
1478 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1481 var old = dojo.byId( menu_id );
1483 page = auth_pages[menu_id];
1484 old.parentNode.removeChild(old);
1486 auth_pages[menu_id] = 0;
1489 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1491 sf_popup.addEventListener("popuphiding", function(event) {
1492 if (show_auth_menu) {
1493 show_auth_menu = false;
1494 getAuthorityContextMenu(target, sf);
1495 dojo.byId(menu_id).openPopup();
1499 context_menus.appendChild( sf_popup );
1502 dojo.forEach( acs.controlSetList(), function (acs_id) {
1503 if (ac.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
1506 if (!found_acs.length) {
1507 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1508 target.setAttribute('context', 'clipboard');
1512 if (sf.toString().replace(/\s*/, '')) {
1513 browseAuthority(sf_popup, menu_id, target, sf, 20, page);
1519 /* Apply the complete 1xx */
1520 function applyFullAuthority ( target, ui_sf, e4x_sf ) {
1521 var new_vals = dojo.query('*[tag^="1"]', target);
1522 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1525 function applySelectedAuthority ( target, ui_sf, e4x_sf ) {
1526 var new_vals = target.getElementsByAttribute('checked','true');
1527 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1530 function applyAuthority ( target, ui_sf, e4x_sf, new_vals ) {
1531 var field = e4x_sf.parent();
1533 for (var i = 0; i < new_vals.length; i++) {
1535 var sf_list = field.subfield;
1536 for (var j in sf_list) {
1538 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1539 sf_list[j] = new_vals[i].getAttribute('value');
1540 new_vals[i].setAttribute('subfield','');
1546 for (var i = 0; i < new_vals.length; i++) {
1547 if (!new_vals[i].getAttribute('subfield')) continue;
1549 var val = new_vals[i].getAttribute('value');
1551 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1552 sf.@code = new_vals[i].getAttribute('subfield');
1554 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1557 var row = marcDatafield( field );
1560 while (node.nodeName != 'row') {
1561 node = node.parentNode;
1564 node.parentNode.replaceChild( row, node );
1568 function validateAuthority (button) {
1569 var grid = document.getElementById('recGrid');
1570 var label = button.getAttribute('label');
1573 var rows = grid.lastChild.childNodes;
1574 for (var i = 0; i < rows.length; i++) {
1576 var tag = row.firstChild;
1578 for (var acs_id in acs.controlSetList()) {
1579 var control_map = acs.controlSet(acs_id).control_map;
1581 if (!control_map[tag.value]) continue
1582 button.setAttribute('label', label + ' - ' + tag.value);
1584 var ind1 = tag.nextSibling;
1585 var ind2 = ind1.nextSibling;
1586 var subfields = ind2.nextSibling.childNodes;
1589 for (var j = 0; j < subfields.length; j++) {
1590 var sf = subfields[j];
1591 sf_list.push( sf.childNodes[1].value );
1592 sf_list.push( sf.childNodes[2].value );
1595 var matches = acs.findMatchingAuthorities(
1598 'subfields' : sf_list
1602 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1603 for (var j = 0; j < subfields.length; j++) {
1604 var sf = subfields[j];
1605 if (!matches.length) {
1606 dojo.removeClass(sf.childNodes[2], 'marcValidated');
1607 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
1609 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
1610 dojo.addClass(sf.childNodes[2], 'marcValidated');
1614 if (matches.length) break;
1618 button.setAttribute('label', label);
1625 function validateBibField (tags, searches) {
1626 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1627 url += '¶m="tags"¶m=' + js2JSON(tags);
1628 url += '¶m="searches"¶m=' + js2JSON(searches);
1631 var req = new XMLHttpRequest();
1632 req.open('GET',url,false);
1640 function searchAuthority (term, tag, sf, limit) {
1641 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1642 url += '¶m="term"¶m="' + term + '"';
1643 url += '¶m="limit"¶m=' + limit;
1644 url += '¶m="tag"¶m=' + tag;
1645 url += '¶m="subfield"¶m="' + sf + '"';
1648 var req = new XMLHttpRequest();
1649 req.open('GET',url,false);
1656 /* TODO new authority browse support for context sets, and use that here */
1657 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
1658 dojo.require('dojox.xml.parser');
1660 // map tag + subfield to the appropriate authority browse axis:
1661 // currently authority.author, authority.subject, authority.title, authority.topic
1662 // based on mappings in OpenILS::Application::SuperCat
1666 // Map based on replacing the first char of the selected tag with '1'
1667 switch ('1' + (sf.parent().@tag.toString()).substring(1)) {
1669 type = 'authority.title';
1675 type = 'authority.author';
1679 type = 'authority.topic';
1685 type = 'authority.subject';
1688 // No matching tag means no authorities to search - shortcut
1701 var url = '/opac/extras/browse/marcxml/'
1703 + '/1' // OU - currently unscoped
1704 + '/' + sf.toString()
1709 // would be good to carve this out into a separate function
1710 dojo.xhrGet({"url":url, "sync": true, "preventCache": true, "handleAs":"xml", "load": function(records) {
1711 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
1713 var cm_popup = create_menu.appendChild(
1717 cm_popup.appendChild(
1718 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
1719 command : function() {
1720 // Call middle-layer function to create and save the new authority
1721 var source_f = summarizeField(sf);
1722 var new_auth = fieldmapper.standardRequest(
1723 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
1724 [source_f, xulG.marc_control_number_identifier, ses()]
1726 if (new_auth && new_auth.id()) {
1727 addNewAuthorityID(new_auth, sf, target);
1733 cm_popup.appendChild(
1734 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
1735 command : function() {
1736 // Generate the new authority by calling the new middle-layer
1737 // function (a non-saving variant), then display in another
1739 var source_f = summarizeField(sf);
1740 var authtoken = ses();
1741 dojo.require('openils.PermaCrud');
1742 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
1743 var rec = fieldmapper.standardRequest(
1744 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
1745 { "params": [source_f, xulG.marc_control_number_identifier] }
1747 loadMarcEditor(pcrud, rec, target, sf);
1752 sf_popup.appendChild(create_menu);
1753 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1755 // append "Previous page" results browser
1756 sf_popup.appendChild(
1757 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
1758 command : function(event) {
1759 auth_pages[menu_id] -= 1;
1760 show_auth_menu = true;
1764 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1766 dojo.query('record', records).forEach(function(record) {
1770 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"] subfield[code="c"]', record)[0]);
1771 var auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
1773 // Grab the fields with tags beginning with 1 (main entries) and iterate through the subfields
1774 dojo.query('datafield[tag^="1"]', record).forEach(function(field) {
1775 dojo.query('subfield', field).forEach(function(subfield) {
1779 main_text += dojox.xml.parser.textContent(subfield);
1783 // Grab the fields with tags beginning with 4 (see from entries) and iterate through the subfields
1784 dojo.query('datafield[tag^="4"]', record).forEach(function(field) {
1786 dojo.query('subfield', field).forEach(function(subfield) {
1790 see_text += dojox.xml.parser.textContent(subfield);
1792 see_from.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_from', [see_text]));
1795 // Grab the fields with tags beginning with 5 (see also entries) and iterate through the subfields
1796 dojo.query('datafield[tag^="5"]', record).forEach(function(field) {
1798 dojo.query('subfield', field).forEach(function(subfield) {
1802 see_text += dojox.xml.parser.textContent(subfield);
1804 see_also.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_also', [see_text]));
1807 buildAuthorityPopup(main_text, record, auth_org, auth_id, sf_popup, target, sf);
1809 dojo.forEach(see_from, function(entry_text) {
1810 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1813 // To-do: instead of launching the standard selector menu, invoke
1814 // a new authority search using the 5XX entry text
1815 dojo.forEach(see_also, function(entry_text) {
1816 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1821 if (sf_popup.childNodes.length == 0) {
1822 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1824 // append "Next page" results browser
1825 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1826 sf_popup.appendChild(
1827 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
1828 command : function(event) {
1829 auth_pages[menu_id] += 1;
1830 show_auth_menu = true;
1836 target.setAttribute('context', menu_id);
1842 function buildAuthorityPopup (entry_text, record, auth_org, auth_id, sf_popup, target, sf, style) {
1843 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
1844 grid.setAttribute('name','-none-');
1845 grid.setAttribute('style','overflow:scroll');
1847 var submenu = createMenu( { "label": entry_text } );
1849 var popup = createMenuPopup({ "flex": "1" });
1851 submenu.setAttribute('style', style);
1852 popup.setAttribute('style', 'font-style: normal; margin-left: 0em;');
1854 submenu.appendChild(popup);
1856 dojo.query('datafield[tag^="1"], datafield[tag^="4"], datafield[tag^="5"]', record).forEach(function(field) {
1857 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1860 grid.hidden = false;
1861 popup.appendChild( grid );
1865 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1866 command : function (event) {
1867 applySelectedAuthority(event.target.previousSibling, target, sf);
1874 popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1878 { label : $('catStrings').getString('staff.cat.marcedit.apply_full.label'),
1879 command : function (event) {
1880 applyFullAuthority(event.target.previousSibling.previousSibling.previousSibling, target, sf);
1887 sf_popup.appendChild( submenu );
1890 function buildAuthorityPopupSelector (field, grid, auth_org, auth_id) {
1891 var row = createRow(
1893 createLabel( { "value" : dojo.attr(field, 'tag') } ),
1894 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
1895 createLabel( { "value" : dojo.attr(field, 'ind2') } )
1898 var sf_box = createHbox();
1899 dojo.query('subfield', field).forEach(function(subfield) {
1902 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
1903 "subfield" : dojo.attr(subfield, 'code'),
1904 "tag" : dojo.attr(field, 'tag'),
1905 "value" : dojox.xml.parser.textContent(subfield)
1909 row.appendChild(sf_box);
1912 // Append the authority linking subfield only for main entries
1913 if (dojo.attr(field, 'tag').charAt(0) == '1') {
1916 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
1918 "tag" : dojo.attr(field, 'tag'),
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.ind1 = sf.parent().@ind2.toString();
1941 for (var i = 0; i < sf.parent().subfield.length(); i++) {
1942 var sf_iter = sf.parent().subfield[i];
1944 /* Filter out subfields that are not controlled for this tag */
1945 if (!control_map[source_f.tag][sf_iter.@code.toString()]) {
1949 source_f.subfields.push([sf_iter.@code.toString(), sf_iter.toString()]);
1955 function buildBibSourceList (authtoken, recId) {
1956 /* TODO: Work out how to set the bib source of the bre that does not yet
1957 * exist - this is specifically in the case of Z39.50 imports. Right now
1958 * we just avoid populating and showing the config.bib_source list
1964 var bib = xulG.record.bre;
1966 dojo.require('openils.PermaCrud');
1968 // cbsList = the XUL menulist that contains the available bib sources
1969 var cbsList = dojo.byId('bib-source-list');
1971 // bibSources = an array containing all of the bib source objects
1972 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
1974 // A tad ugly, but gives us the index of the bib source ID in cbsList
1976 var cbsListArr = [];
1977 dojo.forEach(bibSources, function (item) {
1978 cbsList.appendItem(item.source(), item.id());
1979 cbsListArr[item.id()] = x;
1983 // Show the current value of the bib source for this record
1984 cbsList.selectedIndex = cbsListArr[bib.source()];
1986 // Display the bib source selection widget
1987 dojo.byId('bib-source-list-caption').hidden = false;
1988 dojo.byId('bib-source-list').hidden = false;
1989 dojo.byId('bib-source-list-button').disabled = true;
1990 dojo.byId('bib-source-list-button').hidden = false;
1993 // Fired when the "Update Source" button is clicked
1994 // Updates the value of the bib source for the current record
1995 function updateBibSource() {
1996 var authtoken = ses();
1997 var cbs = dojo.byId('bib-source-list').selectedItem.value;
1998 var recId = xulG.record.id;
1999 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2000 var bib = pcrud.retrieve('bre', recId);
2001 if (bib.source() != cbs) {
2003 bib.ischanged = true;
2008 function onBibSourceSelect() {
2009 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2010 var bib = xulG.record.bre;
2011 if (bib.source() != cbs) {
2012 dojo.byId('bib-source-list-button').disabled = false;
2014 dojo.byId('bib-source-list-button').disabled = true;
2018 function addNewAuthorityID(authority, sf, target) {
2019 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){authority.id()}</subfield>;
2020 sf.parent().appendChild(id_sf);
2021 var new_sf = marcSubfield(id_sf);
2024 while (dojo.attr(node, 'name') != 'sf_box') {
2025 node = node.parentNode;
2027 node.appendChild( new_sf );
2029 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2032 function loadMarcEditor(pcrud, marcxml, target, sf) {
2034 To run in Firefox directly, must set signed.applets.codebase_principal_support
2035 to true in about:config
2037 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
2038 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
2040 // Match marc2are.pl last_xact_id format, roughly
2042 var xact_id = 'IMPORT-' + Date.parse(now);
2045 "record": {"marc": marcxml, "rtype": "are"},
2047 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2048 "func": function(xmlString) {
2049 var rec = new are();
2050 rec.marc(xmlString);
2051 rec.last_xact_id(xact_id);
2054 "oncomplete": function (r, objs) {
2055 var new_rec = objs[0];
2060 addNewAuthorityID(new_rec, sf, target);