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 var rtype = marc_rec.recordType();
821 ldr : marc_rec.leader(),
822 _6 : marc_rec.field('006');
823 _7 : marc_rec.field('007');
824 _8 : marc_rec.field('008');
827 var name = element.getAttribute('name');
828 for (var i in MARC.Record._ff_pos[name]) {
830 if (!MARC.Record._ff_pos[name][i][rtype]) continue;
832 // we're missing the required field. Add it now.
835 if (i == '_6') newfield = '006';
836 else if (i == '_7') newfield = '007';
837 else if (i == '_8') newfield = '008';
840 createControlField(newfield,' ');
841 parts[i] = xml_record.controlfield.(@tag==newfield).toString();
844 var before = parts[i].substr(0, MARC.Record._ff_pos[name][i][rtype].start);
845 var after = parts[i].substr(MARC.Record._ff_pos[name][i][rtype].start + MARC.Record._ff_pos[name][i][rtype].len);
847 for (var j = 0; new_value.length < MARC.Record._ff_pos[name][i][rtype].len; j++) {
848 new_value += MARC.Record._ff_pos[name][i][rtype].def;
851 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = before + new_value + after;
857 function marcLeader (leader) {
859 { class : 'marcLeaderRow',
864 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
867 class : 'marcInd1' } ),
870 class : 'marcInd2' } ),
872 { value : leader.text(),
873 class : 'marcLeader' } )
879 function marcControlfield (field) {
880 tagname = field.@tag.toString().substr(2);
882 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
884 { class : 'marcControlfieldRow',
885 tag : '_' + tagname },
887 { value : field.@tag,
889 context : 'tags_popup',
890 onmouseover : 'getTooltip(this, "tag");',
891 tooltipid : 'tag' + field.@tag } ),
893 { value : field.@ind1,
895 onmouseover : 'getTooltip(this, "ind1");',
896 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
898 { value : field.@ind2,
900 onmouseover : 'getTooltip(this, "ind2");',
901 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
904 { value : field.text(),
905 class : 'plain marcEditableControlfield',
906 name : 'CONTROL' + tagname,
907 context : 'clipboard',
913 { class : 'marcControlfieldRow',
914 tag : '_' + tagname },
916 { value : field.@tag,
918 onmouseover : 'getTooltip(this, "tag");',
919 tooltipid : 'tag' + field.@tag } ),
921 { value : field.@ind1,
923 onmouseover : 'getTooltip(this, "ind1");',
924 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
926 { value : field.@ind2,
928 onmouseover : 'getTooltip(this, "ind2");',
929 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
931 { value : field.text(),
932 class : 'marcControlfield' } )
939 function stackSubfields(checkbox) {
940 var list = document.getElementsByAttribute('name','sf_box');
943 if (!checkbox.checked) o = 'horizontal';
945 for (var i = 0; i < list.length; i++) {
946 if (list[i]) list[i].setAttribute('orient',o);
950 function fastItemAdd_toggle(checkbox) {
951 var x = document.getElementById('fastItemAdd_textboxes');
952 if (checkbox.checked) {
954 document.getElementById('fastItemAdd_callnumber').focus();
955 document.getElementById('fastItemAdd_callnumber').select();
961 function fastItemAdd_attempt(doc_id) {
963 if (typeof window.xulG.fast_add_item != 'function') { return; }
964 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
965 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
966 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
967 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
968 document.getElementById('fastItemAdd_barcode').value = '';
970 alert('fastItemAdd_attempt: ' + E);
974 function save_attempt(xml_string) {
976 var result = window.xulG.save.func( xml_string );
979 if (result.id) fastItemAdd_attempt(result.id);
980 if (typeof result.on_complete == 'function') result.on_complete();
983 alert('save_attempt: ' + E);
987 function marcDatafield (field) {
989 { class : 'marcDatafieldRow' },
992 { value : field.@tag,
993 class : 'plain marcTag',
995 context : 'tags_popup',
996 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
999 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1002 { value : field.@ind1,
1003 class : 'plain marcInd1',
1005 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1008 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1009 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1012 { value : field.@ind2,
1013 class : 'plain marcInd2',
1015 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1018 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1019 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1020 createHbox({ name : 'sf_box' })
1023 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1024 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1025 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1027 var sf_box = row.lastChild;
1028 if (document.getElementById('stackSubfields').checked)
1029 sf_box.setAttribute('orient','vertical');
1031 sf_box.addEventListener(
1034 if (sf_box === e.target) {
1035 sf_box.lastChild.lastChild.focus();
1036 } else if (e.target.parentNode === sf_box) {
1037 e.target.lastChild.focus();
1044 for (var i in field.subfield) {
1045 var sf = field.subfield[i];
1050 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1052 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1053 current_focus = sf_box.lastChild.childNodes[1];
1059 function marcSubfield (sf) {
1061 { class : 'marcSubfieldBox' },
1064 class : 'plain marcSubfieldDelimiter',
1065 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1066 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1067 //onclick : 'this.nextSibling.focus();',
1068 onfocus : 'this.nextSibling.focus();',
1073 class : 'plain marcSubfieldCode',
1074 name : 'marcSubfieldCode',
1075 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1076 oncontextmenu : 'getContextMenu(this, "subfield");',
1077 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1082 { value : sf.text(),
1083 name : sf.parent().@tag + ':' + sf.@code,
1084 class : 'plain marcSubfield',
1085 onmouseover : 'getTooltip(this, "subfield");',
1086 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1087 size : new String(sf.text()).length + 2,
1088 oninput : "this.setAttribute('size', this.value.length + 2);"
1093 function loadRecord() {
1095 var grid_rows = document.getElementById('recGrid').lastChild;
1097 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1099 grid_rows.appendChild( marcLeader( xml_record.leader ) );
1101 for (var i in xml_record.controlfield) {
1102 grid_rows.appendChild( marcControlfield( xml_record.controlfield[i] ) );
1105 for (var i in xml_record.datafield) {
1106 grid_rows.appendChild( marcDatafield( xml_record.datafield[i] ) );
1109 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1111 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
1112 changeFFEditor(marc_rec.recordType());
1115 alert('FIXME, MARC Editor, loadRecord: ' + E);
1120 function genToolTips () {
1121 for (var i in bib_data.field) {
1122 var f = bib_data.field[i];
1124 tag_menu.appendChild(
1128 'current_focus.value = "' + f.@tag + '";' +
1129 'var e = document.createEvent("MutationEvents");' +
1130 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1131 'current_focus.inputField.dispatchEvent(e);',
1132 disabled : f.@tag < '010' ? "true" : "false",
1133 tooltiptext : f.description }
1137 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1138 context_menus.appendChild( i1_popup );
1140 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1141 context_menus.appendChild( i2_popup );
1143 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1144 context_menus.appendChild( sf_popup );
1146 tooltip_hash['tag' + f.@tag] = f.description;
1147 for (var j in f.indicator) {
1148 var ind = f.indicator[j];
1149 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1151 if (ind.@position == 1) {
1152 i1_popup.appendChild(
1154 { label : ind.@value,
1156 'current_focus.value = "' + ind.@value + '";' +
1157 'var e = document.createEvent("MutationEvents");' +
1158 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1159 'current_focus.inputField.dispatchEvent(e);',
1160 tooltiptext : ind.description }
1165 if (ind.@position == 2) {
1166 i2_popup.appendChild(
1168 { label : ind.@value,
1170 'current_focus.value = "' + ind.@value + '";' +
1171 'var e = document.createEvent("MutationEvents");' +
1172 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1173 'current_focus.inputField.dispatchEvent(e);',
1174 tooltiptext : ind.description }
1180 for (var j in f.subfield) {
1181 var sf = f.subfield[j];
1182 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1184 sf_popup.appendChild(
1188 'current_focus.value = "' + sf.@code + '";' +
1189 'var e = document.createEvent("MutationEvents");' +
1190 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1191 'current_focus.inputField.dispatchEvent(e);',
1192 tooltiptext : sf.description
1200 function getTooltip (target, type) {
1203 if (type == 'subfield')
1204 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1207 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1210 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1213 tt = 'tag' + target.parentNode.firstChild.value;
1215 if (!document.getElementById( tt )) {
1220 orient : 'vertical',
1221 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1222 class : 'tooltip' },
1223 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1228 target.tooltip = tt;
1232 function getContextMenu (target, type) {
1235 if (type == 'subfield')
1236 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1239 tt = 't' + target.parentNode.firstChild.value + 'i1';
1242 tt = 't' + target.parentNode.firstChild.value + 'i2';
1244 target.setAttribute('context', tt);
1250 'a' : { 100 : 'a' },
1251 'd' : { 100 : 'd' },
1252 'e' : { 100 : 'e' },
1256 'a' : { 110 : 'a' },
1260 'a' : { 111 : 'a' },
1264 'a' : { 130 : 'a' },
1268 'a' : { 130 : 'a' },
1272 'a' : { 100 : 'a' },
1276 'a' : { 110 : 'a' },
1280 'a' : { 111 : 'a' },
1284 'a' : { 130 : 'a' },
1285 'n' : { 130 : 'n' },
1289 'a' : { 100 : 'a' },
1290 'd' : { 100 : 'd' },
1291 'q' : { 100 : 'q' },
1295 'a' : { 110 : 'a' },
1299 'a' : { 111 : 'a' },
1300 'c' : { 111 : 'c' },
1304 'a' : { 130 : 'a' },
1308 'a' : { 100 : 'a' },
1312 'a' : { 110 : 'a' },
1316 'a' : { 111 : 'a' },
1320 'a' : { 130 : 'a' },
1324 'a' : { 100 : 'a' },
1325 'd' : { 100 : 'd' },
1326 'q' : { 100 : 'q' },
1327 't' : { 100 : 't' },
1354 'a' : { 110 : 'a' },
1355 'd' : { 110 : 'd' },
1356 't' : { 110 : 't' },
1383 'a' : { 111 : 'a' },
1384 'd' : { 111 : 'd' },
1385 't' : { 111 : 't' },
1412 'a' : { 130 : 'a' },
1416 'a' : { 148 : 'a' },
1417 'v' : { 148 : 'v' },
1418 'x' : { 148 : 'x' },
1419 'y' : { 148 : 'y' },
1423 'a' : { 150 : 'a' },
1424 'b' : { 150 : 'b' },
1451 'a' : { 151 : 'a' },
1478 'a' : { 155 : 'a' },
1506 function getAuthorityContextMenu (target, sf) {
1507 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1510 var old = dojo.byId( menu_id );
1512 page = auth_pages[menu_id];
1513 old.parentNode.removeChild(old);
1515 auth_pages[menu_id] = 0;
1518 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1520 sf_popup.addEventListener("popuphiding", function(event) {
1521 if (show_auth_menu) {
1522 show_auth_menu = false;
1523 getAuthorityContextMenu(target, sf);
1524 dojo.byId(menu_id).openPopup();
1528 context_menus.appendChild( sf_popup );
1531 dojo.forEach( acs.controlSetList(), function (acs_id) {
1532 if (ac.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
1535 if (!found_acs.length) {
1536 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1537 target.setAttribute('context', 'clipboard');
1541 if (sf.toString().replace(/\s*/, '')) {
1542 browseAuthority(sf_popup, menu_id, target, sf, 20, page);
1548 /* Apply the complete 1xx */
1549 function applyFullAuthority ( target, ui_sf, e4x_sf ) {
1550 var new_vals = dojo.query('*[tag^="1"]', target);
1551 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1554 function applySelectedAuthority ( target, ui_sf, e4x_sf ) {
1555 var new_vals = target.getElementsByAttribute('checked','true');
1556 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1559 function applyAuthority ( target, ui_sf, e4x_sf, new_vals ) {
1560 var field = e4x_sf.parent();
1562 for (var i = 0; i < new_vals.length; i++) {
1564 var sf_list = field.subfield;
1565 for (var j in sf_list) {
1567 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1568 sf_list[j] = new_vals[i].getAttribute('value');
1569 new_vals[i].setAttribute('subfield','');
1575 for (var i = 0; i < new_vals.length; i++) {
1576 if (!new_vals[i].getAttribute('subfield')) continue;
1578 var val = new_vals[i].getAttribute('value');
1580 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1581 sf.@code = new_vals[i].getAttribute('subfield');
1583 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1586 var row = marcDatafield( field );
1589 while (node.nodeName != 'row') {
1590 node = node.parentNode;
1593 node.parentNode.replaceChild( row, node );
1597 function validateAuthority (button) {
1598 var grid = document.getElementById('recGrid');
1599 var label = button.getAttribute('label');
1602 var rows = grid.lastChild.childNodes;
1603 for (var i = 0; i < rows.length; i++) {
1605 var tag = row.firstChild;
1607 for (var acs_id in acs.controlSetList()) {
1608 var control_map = acs.controlSet(acs_id).control_map;
1610 if (!control_map[tag.value]) continue
1611 button.setAttribute('label', label + ' - ' + tag.value);
1613 var ind1 = tag.nextSibling;
1614 var ind2 = ind1.nextSibling;
1615 var subfields = ind2.nextSibling.childNodes;
1619 for (var j = 0; j < subfields.length; j++) {
1620 var sf = subfields[j];
1621 var sf_code = sf.childNodes[1].value;
1622 var sf_value = sf.childNodes[2].value;
1624 if (!control_map[tag.value][sf_code]) continue;
1627 for (var a_tag in control_map[tag.value][sf_code]) {
1628 if (!tags[a_tag]) tags[a_tag] = [];
1629 tags[a_tag].push({ term : sf_value, subfield : sf_code });
1634 for (var val_tag in tags) {
1635 var auth_data = validateBibField( acs_id, [val_tag], tags[val_tag]);
1636 var res = new XML( auth_data.responseText );
1637 found = parseInt(res.gw::payload.gw::string.toString());
1641 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1642 for (var j = 0; j < subfields.length; j++) {
1643 var sf = subfields[j];
1645 dojo.removeClass(sf.childNodes[2], 'marcValidated');
1646 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
1648 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
1649 dojo.addClass(sf.childNodes[2], 'marcValidated');
1657 button.setAttribute('label', label);
1663 function validateBibField (tags, searches) {
1664 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1665 url += '¶m="tags"¶m=' + js2JSON(tags);
1666 url += '¶m="searches"¶m=' + js2JSON(searches);
1669 var req = new XMLHttpRequest();
1670 req.open('GET',url,false);
1676 function searchAuthority (term, tag, sf, limit) {
1677 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1678 url += '¶m="term"¶m="' + term + '"';
1679 url += '¶m="limit"¶m=' + limit;
1680 url += '¶m="tag"¶m=' + tag;
1681 url += '¶m="subfield"¶m="' + sf + '"';
1684 var req = new XMLHttpRequest();
1685 req.open('GET',url,false);
1692 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
1693 dojo.require('dojox.xml.parser');
1695 // map tag + subfield to the appropriate authority browse axis:
1696 // currently authority.author, authority.subject, authority.title, authority.topic
1697 // based on mappings in OpenILS::Application::SuperCat
1701 // Map based on replacing the first char of the selected tag with '1'
1702 switch ('1' + (sf.parent().@tag.toString()).substring(1)) {
1704 type = 'authority.title';
1710 type = 'authority.author';
1714 type = 'authority.topic';
1720 type = 'authority.subject';
1723 // No matching tag means no authorities to search - shortcut
1736 var url = '/opac/extras/browse/marcxml/'
1738 + '/1' // OU - currently unscoped
1739 + '/' + sf.toString()
1744 // would be good to carve this out into a separate function
1745 dojo.xhrGet({"url":url, "sync": true, "preventCache": true, "handleAs":"xml", "load": function(records) {
1746 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
1748 var cm_popup = create_menu.appendChild(
1752 cm_popup.appendChild(
1753 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
1754 command : function() {
1755 // Call middle-layer function to create and save the new authority
1756 var source_f = summarizeField(sf);
1757 var new_auth = fieldmapper.standardRequest(
1758 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
1759 [source_f, xulG.marc_control_number_identifier, ses()]
1761 if (new_auth && new_auth.id()) {
1762 addNewAuthorityID(new_auth, sf, target);
1768 cm_popup.appendChild(
1769 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
1770 command : function() {
1771 // Generate the new authority by calling the new middle-layer
1772 // function (a non-saving variant), then display in another
1774 var source_f = summarizeField(sf);
1775 var authtoken = ses();
1776 dojo.require('openils.PermaCrud');
1777 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
1778 var rec = fieldmapper.standardRequest(
1779 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
1780 { "params": [source_f, xulG.marc_control_number_identifier] }
1782 loadMarcEditor(pcrud, rec, target, sf);
1787 sf_popup.appendChild(create_menu);
1788 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1790 // append "Previous page" results browser
1791 sf_popup.appendChild(
1792 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
1793 command : function(event) {
1794 auth_pages[menu_id] -= 1;
1795 show_auth_menu = true;
1799 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1801 dojo.query('record', records).forEach(function(record) {
1805 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"] subfield[code="c"]', record)[0]);
1806 var auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
1808 // Grab the fields with tags beginning with 1 (main entries) and iterate through the subfields
1809 dojo.query('datafield[tag^="1"]', record).forEach(function(field) {
1810 dojo.query('subfield', field).forEach(function(subfield) {
1814 main_text += dojox.xml.parser.textContent(subfield);
1818 // Grab the fields with tags beginning with 4 (see from entries) and iterate through the subfields
1819 dojo.query('datafield[tag^="4"]', record).forEach(function(field) {
1821 dojo.query('subfield', field).forEach(function(subfield) {
1825 see_text += dojox.xml.parser.textContent(subfield);
1827 see_from.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_from', [see_text]));
1830 // Grab the fields with tags beginning with 5 (see also entries) and iterate through the subfields
1831 dojo.query('datafield[tag^="5"]', record).forEach(function(field) {
1833 dojo.query('subfield', field).forEach(function(subfield) {
1837 see_text += dojox.xml.parser.textContent(subfield);
1839 see_also.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_also', [see_text]));
1842 buildAuthorityPopup(main_text, record, auth_org, auth_id, sf_popup, target, sf);
1844 dojo.forEach(see_from, function(entry_text) {
1845 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1848 // To-do: instead of launching the standard selector menu, invoke
1849 // a new authority search using the 5XX entry text
1850 dojo.forEach(see_also, function(entry_text) {
1851 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1856 if (sf_popup.childNodes.length == 0) {
1857 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1859 // append "Next page" results browser
1860 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1861 sf_popup.appendChild(
1862 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
1863 command : function(event) {
1864 auth_pages[menu_id] += 1;
1865 show_auth_menu = true;
1871 target.setAttribute('context', menu_id);
1877 function buildAuthorityPopup (entry_text, record, auth_org, auth_id, sf_popup, target, sf, style) {
1878 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
1879 grid.setAttribute('name','-none-');
1880 grid.setAttribute('style','overflow:scroll');
1882 var submenu = createMenu( { "label": entry_text } );
1884 var popup = createMenuPopup({ "flex": "1" });
1886 submenu.setAttribute('style', style);
1887 popup.setAttribute('style', 'font-style: normal; margin-left: 0em;');
1889 submenu.appendChild(popup);
1891 dojo.query('datafield[tag^="1"], datafield[tag^="4"], datafield[tag^="5"]', record).forEach(function(field) {
1892 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1895 grid.hidden = false;
1896 popup.appendChild( grid );
1900 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1901 command : function (event) {
1902 applySelectedAuthority(event.target.previousSibling, target, sf);
1909 popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1913 { label : $('catStrings').getString('staff.cat.marcedit.apply_full.label'),
1914 command : function (event) {
1915 applyFullAuthority(event.target.previousSibling.previousSibling.previousSibling, target, sf);
1922 sf_popup.appendChild( submenu );
1925 function buildAuthorityPopupSelector (field, grid, auth_org, auth_id) {
1926 var row = createRow(
1928 createLabel( { "value" : dojo.attr(field, 'tag') } ),
1929 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
1930 createLabel( { "value" : dojo.attr(field, 'ind2') } )
1933 var sf_box = createHbox();
1934 dojo.query('subfield', field).forEach(function(subfield) {
1937 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
1938 "subfield" : dojo.attr(subfield, 'code'),
1939 "tag" : dojo.attr(field, 'tag'),
1940 "value" : dojox.xml.parser.textContent(subfield)
1944 row.appendChild(sf_box);
1947 // Append the authority linking subfield only for main entries
1948 if (dojo.attr(field, 'tag').charAt(0) == '1') {
1951 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
1953 "tag" : dojo.attr(field, 'tag'),
1954 "value" : '(' + auth_org + ')' + auth_id
1959 row.appendChild(sf_box);
1961 grid.lastChild.appendChild(row);
1964 function summarizeField(sf) {
1972 source_f.tag = sf.parent().@tag.toString();
1973 source_f.ind1 = sf.parent().@ind1.toString();
1974 source_f.ind1 = sf.parent().@ind2.toString();
1976 for (var i = 0; i < sf.parent().subfield.length(); i++) {
1977 var sf_iter = sf.parent().subfield[i];
1979 /* Filter out subfields that are not controlled for this tag */
1980 if (!control_map[source_f.tag][sf_iter.@code.toString()]) {
1984 source_f.subfields.push([sf_iter.@code.toString(), sf_iter.toString()]);
1990 function buildBibSourceList (authtoken, recId) {
1991 /* TODO: Work out how to set the bib source of the bre that does not yet
1992 * exist - this is specifically in the case of Z39.50 imports. Right now
1993 * we just avoid populating and showing the config.bib_source list
1999 var bib = xulG.record.bre;
2001 dojo.require('openils.PermaCrud');
2003 // cbsList = the XUL menulist that contains the available bib sources
2004 var cbsList = dojo.byId('bib-source-list');
2006 // bibSources = an array containing all of the bib source objects
2007 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
2009 // A tad ugly, but gives us the index of the bib source ID in cbsList
2011 var cbsListArr = [];
2012 dojo.forEach(bibSources, function (item) {
2013 cbsList.appendItem(item.source(), item.id());
2014 cbsListArr[item.id()] = x;
2018 // Show the current value of the bib source for this record
2019 cbsList.selectedIndex = cbsListArr[bib.source()];
2021 // Display the bib source selection widget
2022 dojo.byId('bib-source-list-caption').hidden = false;
2023 dojo.byId('bib-source-list').hidden = false;
2024 dojo.byId('bib-source-list-button').disabled = true;
2025 dojo.byId('bib-source-list-button').hidden = false;
2028 // Fired when the "Update Source" button is clicked
2029 // Updates the value of the bib source for the current record
2030 function updateBibSource() {
2031 var authtoken = ses();
2032 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2033 var recId = xulG.record.id;
2034 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2035 var bib = pcrud.retrieve('bre', recId);
2036 if (bib.source() != cbs) {
2038 bib.ischanged = true;
2043 function onBibSourceSelect() {
2044 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2045 var bib = xulG.record.bre;
2046 if (bib.source() != cbs) {
2047 dojo.byId('bib-source-list-button').disabled = false;
2049 dojo.byId('bib-source-list-button').disabled = true;
2053 function addNewAuthorityID(authority, sf, target) {
2054 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){authority.id()}</subfield>;
2055 sf.parent().appendChild(id_sf);
2056 var new_sf = marcSubfield(id_sf);
2059 while (dojo.attr(node, 'name') != 'sf_box') {
2060 node = node.parentNode;
2062 node.appendChild( new_sf );
2064 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2067 function loadMarcEditor(pcrud, marcxml, target, sf) {
2069 To run in Firefox directly, must set signed.applets.codebase_principal_support
2070 to true in about:config
2072 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
2073 win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
2075 // Match marc2are.pl last_xact_id format, roughly
2077 var xact_id = 'IMPORT-' + Date.parse(now);
2080 "record": {"marc": marcxml, "rtype": "are"},
2082 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2083 "func": function(xmlString) {
2084 var rec = new are();
2085 rec.marc(xmlString);
2086 rec.last_xact_id(xact_id);
2089 "oncomplete": function (r, objs) {
2090 var new_rec = objs[0];
2095 addNewAuthorityID(new_rec, sf, target);