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 // Pretty printing kills whitespace too, so disable it.
22 XML.prettyPrinting = false;
23 var xmlDeclaration = /^<\?xml version[^>]+?>/;
25 var serializer = new XMLSerializer();
26 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
27 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
28 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
29 default xml namespace = marcns;
31 var tooltip_hash = {};
43 var show_auth_menu = false;
45 function $(id) { return document.getElementById(id); }
47 var acs; // AuthorityControlSet
49 function mangle_005() {
51 var y = now.getUTCFullYear();
53 var m = now.getUTCMonth() + 1;
54 if (m < 10) m = '0' + m;
56 var d = now.getUTCDate();
57 if (d < 10) d = '0' + d;
59 var H = now.getUTCHours();
60 if (H < 10) H = '0' + H;
62 var M = now.getUTCMinutes();
63 if (M < 10) M = '0' + M;
65 var S = now.getUTCSeconds();
66 if (S < 10) S = '0' + S;
69 var stamp = '' + y + m + d + H + M + S + '.0';
70 createControlField('005',stamp);
74 function createControlField (tag,data) {
75 // first, remove the old field, if any;
76 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
78 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
81 // then, find the right position and insert it
83 var cfields = xml_record.controlfield;
84 var base = Number(tag.substring(2));
85 for (var i in cfields) {
86 var t = Number(cfields[i].@tag.toString().substring(2));
88 xml_record.insertChildBefore( cfields[i], cf );
94 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
99 function xml_escape_unicode ( str ) {
101 /([\u0080-\ufffe])/g,
102 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
106 function wrap_long_fields (node) {
107 var text_size = dojo.attr(node, 'size');
108 var hard_width = 100;
109 if (text_size > hard_width) {
110 dojo.attr(node, 'multiline', 'true');
111 dojo.attr(node, 'cols', hard_width);
112 var text_rows = (text_size / hard_width) + 1;
113 dojo.attr(node, 'rows', text_rows);
117 function set_flat_editor (useFlatText) {
119 var xe = $('xul-editor');
120 var te = $('text-editor');
123 if (xe.hidden) { return; }
127 if (te.hidden) { return; }
133 // get the marcxml from the text box
134 var xml_string = new MARC.Record({
135 marcbreaker : $('text-editor-box').value,
139 // reset the xml record and rerender it
140 xml_record = new XML( xml_string );
141 if (xml_record..record[0]) xml_record = xml_record..record[0];
144 var xml_string = xml_record.toXMLString();
146 // push the xml record into the textbox
147 var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
148 $('text-editor-box').value = rec.toBreaker();
155 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
156 JSAN.errorLevel = "die"; // none, warn, or die
157 JSAN.addRepository('/xul/server/');
159 dojo.require('openils.AuthorityControlSet');
160 acs = new openils.AuthorityControlSet ();
162 // Fake xulG for standalone...
167 window.xulG.record = {};
168 window.xulG.save = {};
169 window.xulG.marc_control_number_identifier = 'CONS';
171 window.xulG.save.label = $('catStrings').getString('staff.cat.marcedit.save.label');
172 window.xulG.save.func = function (r) { alert(r); }
175 var _rid = cgi.param('record');
177 window.xulG.record.id = _rid;
178 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
182 // End faking part...
184 /* Check for an explicitly passed record type
185 * This is not the same as the fixed-field record type; we can't trust
186 * the fixed fields when making modifications to the attributes for a
187 * given record (in particular, config.bib_source only applies for bib
188 * records, but an auth or MFHD record with the same ID and bad fixed
189 * fields could trample the config.bib_source value for the
190 * corresponding bib record if we're not careful.
192 * are = authority record
193 * sre = serial record (MFHD)
194 * bre = bibliographic record
196 if (!window.xulG.record.rtype) {
198 window.xulG.record.rtype = cgi.param('rtype') || false;
201 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
202 document.getElementById('save-button').setAttribute('oncommand',
203 'if ($("xul-editor").hidden) set_flat_editor(false); ' +
205 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
206 'save_attempt( xml_string ); ' +
210 if (window.xulG.record.url) {
211 var req = new XMLHttpRequest();
212 req.open('POST',window.xulG.record.url,false);
214 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
217 xml_record = new XML( window.xulG.record.marc );
218 if (xml_record..record[0]) xml_record = xml_record..record[0];
220 // Get the tooltip xml all async like
221 req = new XMLHttpRequest();
223 // Set a default locale in case preferences fail us
224 var locale = "en-US";
226 // Try to get the locale from our preferences
228 const Cc = Components.classes;
229 const Ci = Components.interfaces;
230 locale = Cc["@mozilla.org/preferences-service;1"].
231 getService(Ci.nsIPrefBranch).
232 getCharPref("general.useragent.locale");
236 // TODO: We should send a HEAD request to check for the existence of the desired file
237 // then fall back to the default locale if preferred locale is not necessary;
238 // however, for now we have a simplistic check:
240 // we currently have translations for only three locales; in the absence of a
241 // valid locale, default to the almighty en-US
242 if (locale != 'en-US' && locale != 'fr-CA' && locale != 'fi-FI') {
246 // grab the right tooltip based on MARC type
247 var tooltip_doc = 'marcedit-tooltips.xml';
248 switch (window.xulG.record.rtype) {
250 tooltip_doc = 'marcedit-tooltips.xml';
253 tooltip_doc = 'marcedit-tooltips-authority.xml';
254 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
257 tooltip_doc = 'marcedit-tooltips-mfhd.xml';
258 locale = 'en-US'; // FIXME - note TODO above; at moment only en-US has this
261 tooltip_doc = 'marcedit-tooltips.xml';
264 // Get the locale-specific tooltips
265 req.open('GET','/xul/server/locale/' + locale + '/' + tooltip_doc,true);
267 context_menus = createComplexXULElement('popupset');
268 document.documentElement.appendChild( context_menus );
270 tag_menu = createMenuPopup({position : 'after_start', id : 'tags_popup'});
271 context_menus.appendChild( tag_menu );
273 tag_menu.appendChild(
275 { label : $('catStrings').getString('staff.cat.marcedit.add_row.label'),
277 'var e = document.createEvent("KeyEvents");' +
278 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
279 'current_focus.inputField.dispatchEvent(e);'
284 tag_menu.appendChild(
286 { label : $('catStrings').getString('staff.cat.marcedit.insert_row.label'),
288 'var e = document.createEvent("KeyEvents");' +
289 'e.initKeyEvent("keypress",1,1,null,1,0,1,0,13,0);' +
290 'current_focus.inputField.dispatchEvent(e);'
295 tag_menu.appendChild(
297 { label : $('catStrings').getString('staff.cat.marcedit.remove_row.label'),
299 'var e = document.createEvent("KeyEvents");' +
300 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
301 'current_focus.inputField.dispatchEvent(e);'
306 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
308 tag_menu.appendChild(
310 { label : $('catStrings').getString('staff.cat.marcedit.replace_006.label'),
312 'var e = document.createEvent("KeyEvents");' +
313 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,117,0);' +
314 'current_focus.inputField.dispatchEvent(e);'
319 tag_menu.appendChild(
321 { label : $('catStrings').getString('staff.cat.marcedit.replace_007.label'),
323 'var e = document.createEvent("KeyEvents");' +
324 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,118,0);' +
325 'current_focus.inputField.dispatchEvent(e);'
330 tag_menu.appendChild(
332 { label : $('catStrings').getString('staff.cat.marcedit.replace_008.label'),
334 'var e = document.createEvent("KeyEvents");' +
335 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,119,0);' +
336 'current_focus.inputField.dispatchEvent(e);'
341 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
343 p = createComplexXULElement('popupset');
344 document.documentElement.appendChild( p );
346 req.onreadystatechange = function () {
347 if (req.readyState == 4) {
348 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
356 if (! xulG.fast_add_item) {
357 document.getElementById('fastItemAdd_checkbox').hidden = true;
359 document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
361 // Only show bib sources for bib records that already exist in the database
362 if (xulG.record.rtype == 'bre' && xulG.record.id) {
363 dojo.require('openils.PermaCrud');
364 var authtoken = ses();
365 // Retrieve the current record attributes
366 var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
368 // Remember the current bib source of the record
369 xulG.record.bre = bib;
371 buildBibSourceList(authtoken, xulG.record.id);
374 dojo.require('MARC.FixedFields');
377 alert('FIXME, MARC Editor, my_init: ' + E);
382 function createComplexHTMLElement (e, attrs, objects, text) {
383 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
386 for (var i in attrs) l.setAttribute(i,attrs[i]);
390 for ( var i in objects ) l.appendChild( objects[i] );
394 l.appendChild( document.createTextNode(text) )
400 function createComplexXULElement (e, attrs, objects) {
401 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
404 for (var i in attrs) {
405 if (typeof attrs[i] == 'function') {
406 l.addEventListener( i, attrs[i], true );
408 l.setAttribute(i,attrs[i]);
414 for ( var i in objects ) l.appendChild( objects[i] );
420 function createDescription (attrs) {
421 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
424 function createTooltip (attrs) {
425 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
428 function createLabel (attrs) {
429 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
432 function createVbox (attrs) {
433 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
436 function createHbox (attrs) {
437 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
440 function createRow (attrs) {
441 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
444 function createTextbox (attrs) {
445 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
448 function createMenu (attrs) {
449 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
452 function createMenuPopup (attrs) {
453 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
456 function createPopup (attrs) {
457 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
460 function createMenuitem (attrs) {
461 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
464 function createCheckbox (attrs) {
465 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
468 // Find the next textbox that we can use for a focus point
469 // For control fields, use the first editable text box
470 // For data fields, focus on the first subfield text box
471 function setFocusToNextTag (row, direction) {
472 var keep_looking = true;
473 while (keep_looking && (direction == 'up' ? row = row.previousSibling : row = row.nextSibling)) {
474 // Is it a datafield?
475 dojo.query('hbox', row).query('hbox').query('textbox').forEach(function(node, index, arr) {
477 keep_looking = false;
480 // No, it's a control field; use the first textbox
482 dojo.query('textbox', row).forEach(function(node, index, arr) {
484 keep_looking = false;
492 function set_lock_on_keypress(ev) {
494 //dump('keypress: isChar = ' + ev.isChar + ' char = ' + ev.char + ' charCode = ' + ev.charCode + ' key = ' + ev.key + ' keyCode = ' + ev.keyCode + '\n');
499 || ev.keyCode == ev.DOM_VK_F1
500 || ev.keyCode == ev.DOM_VK_F2
501 || ev.keyCode == ev.DOM_VK_F3
502 || ev.keyCode == ev.DOM_VK_F4
503 || ev.keyCode == ev.DOM_VK_F5
504 || ev.keyCode == ev.DOM_VK_F6
505 || ev.keyCode == ev.DOM_VK_F7
506 || ev.keyCode == ev.DOM_VK_F8
507 || ev.keyCode == ev.DOM_VK_F9
508 || ev.keyCode == ev.DOM_VK_F10
509 || ev.keyCode == ev.DOM_VK_F11
510 || ev.keyCode == ev.DOM_VK_F12
511 || ev.keyCode == ev.DOM_VK_F13
512 || ev.keyCode == ev.DOM_VK_F14
513 || ev.keyCode == ev.DOM_VK_F15
514 || ev.keyCode == ev.DOM_VK_F16
515 || ev.keyCode == ev.DOM_VK_F17
516 || ev.keyCode == ev.DOM_VK_F18
517 || ev.keyCode == ev.DOM_VK_F19
518 || ev.keyCode == ev.DOM_VK_F20
519 || ev.keyCode == ev.DOM_VK_F21
520 || ev.keyCode == ev.DOM_VK_F22
521 || ev.keyCode == ev.DOM_VK_F23
522 || ev.keyCode == ev.DOM_VK_F24
531 function createMARCTextbox (element,attrs) {
533 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
534 box.addEventListener(
536 set_lock_on_keypress,
539 box.onkeypress = function (event) {
542 while(node = node.parent()) {
546 var row = event.target;
547 while (row.tagName != 'row') row = row.parentNode;
549 if (element.nodeKind() == 'attribute') element[0]=box.value;
550 else element.setChildren( box.value );
552 if (element.localName() != 'controlfield') {
553 if ((event.charCode == 100 || event.charCode == 105) && event.ctrlKey) { // ctrl+d or ctrl+i
555 var index_sf, target, move_data;
556 if (element.localName() == 'subfield') {
558 target = event.target.parentNode;
560 var start = event.target.selectionStart;
561 var end = event.target.selectionEnd - event.target.selectionStart ?
562 event.target.selectionEnd :
563 event.target.value.length;
565 move_data = event.target.value.substring(start,end);
566 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
567 event.target.setAttribute('size', event.target.value.length + 2);
569 element.setChildren( event.target.value );
571 } else if (element.localName() == 'code') {
572 index_sf = element.parent();
573 target = event.target.parentNode;
574 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
575 index_sf = element.parent().children()[element.parent().children().length() - 1];
576 target = event.target.parentNode.lastChild.lastChild;
579 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
581 index_sf.parent().insertChildAfter( index_sf, sf );
583 var new_sf = marcSubfield(sf);
585 if (target === target.parentNode.lastChild) {
586 target.parentNode.appendChild( new_sf );
588 target.parentNode.insertBefore( new_sf, target.nextSibling );
591 new_sf.firstChild.nextSibling.focus();
593 event.preventDefault();
596 } else if (event.keyCode == 13 || event.keyCode == 77) {
597 if (event.ctrlKey) { // ctrl+enter
600 if (element.localName() == 'subfield') index = element.parent();
601 if (element.localName() == 'code') index = element.parent().parent();
602 if (element.localName() == 'tag') index = element.parent();
603 if (element.localName() == 'ind1') index = element.parent();
604 if (element.localName() == 'ind2') index = element.parent();
606 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
608 if (event.shiftKey) { // ctrl+shift+enter
609 index.parent().insertChildBefore( index, df );
611 index.parent().insertChildAfter( index, df );
614 var new_df = marcDatafield(df);
616 if (row.parentNode.lastChild === row) {
617 row.parentNode.appendChild( new_df );
619 if (event.shiftKey) { // ctrl+shift+enter
620 row.parentNode.insertBefore( new_df, row );
622 row.parentNode.insertBefore( new_df, row.nextSibling );
626 new_df.firstChild.focus();
628 event.preventDefault();
631 } else if (event.shiftKey) {
632 if (row.previousSibling.className.match('marcDatafieldRow'))
633 row.previousSibling.firstChild.focus();
635 row.nextSibling.firstChild.focus();
638 } else if (event.keyCode == 38 || event.keyCode == 40) { // up-arrow or down-arrow
639 if (event.ctrlKey) { // CTRL key: copy the field
641 if (element.localName() == 'subfield') index = element.parent();
642 if (element.localName() == 'code') index = element.parent().parent();
643 if (element.localName() == 'tag') index = element.parent();
644 if (element.localName() == 'ind1') index = element.parent();
645 if (element.localName() == 'ind2') index = element.parent();
647 var copyField = index.copy();
649 if (event.keyCode == 38) { // ctrl+up-arrow
650 index.parent().insertChildBefore( index, copyField );
652 index.parent().insertChildAfter( index, copyField );
655 var new_df = marcDatafield(copyField);
657 if (row.parentNode.lastChild === row) {
658 row.parentNode.appendChild( new_df );
660 if (event.keyCode == 38) { // ctrl+up-arrow
661 row.parentNode.insertBefore( new_df, row );
662 } else { // ctrl+down-arrow
663 row.parentNode.insertBefore( new_df, row.nextSibling );
667 new_df.firstChild.focus();
669 event.preventDefault();
673 if (event.keyCode == 38) {
674 return setFocusToNextTag(row, 'up');
676 if (event.keyCode == 40) {
677 return setFocusToNextTag(row, 'down');
682 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
685 if (element.localName() == 'subfield') index = element.parent();
686 if (element.localName() == 'code') index = element.parent().parent();
687 if (element.localName() == 'tag') index = element.parent();
688 if (element.localName() == 'ind1') index = element.parent();
689 if (element.localName() == 'ind2') index = element.parent();
691 for (var i in index.parent().children()) {
692 if (index === index.parent().children()[i]) {
693 delete index.parent().children()[i];
698 row.previousSibling.firstChild.focus();
699 row.parentNode.removeChild(row);
701 event.preventDefault();
704 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
707 if (element.localName() == 'subfield') index = element;
708 if (element.localName() == 'code') index = element.parent();
711 for (var i in index.parent().children()) {
712 if (index === index.parent().children()[i]) {
713 delete index.parent().children()[i];
718 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
719 event.target.parentNode.previousSibling.lastChild.focus();
721 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
724 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
726 event.preventDefault();
729 } else if (event.keyCode == 117 && event.ctrlKey) { // ctrl + F6
731 createControlField('006',' ');
733 } else if (event.keyCode == 118 && event.ctrlKey) { // ctrl + F7
735 createControlField('007',' ');
737 } else if (event.keyCode == 119 && event.ctrlKey) { // ctrl + F8
739 createControlField('008',' ');
745 } else { // event on a control field
746 if (event.keyCode == 38) {
747 return setFocusToNextTag(row, 'up');
748 } else if (event.keyCode == 40) {
749 return setFocusToNextTag(row, 'down');
754 box.addEventListener(
757 if (element.nodeKind() == 'attribute') element[0]=box.value;
758 else element.setChildren( box.value );
764 box.addEventListener(
767 if (element.nodeKind() == 'attribute') element[0]=box.value;
768 else element.setChildren( box.value );
774 box.addEventListener(
777 if (element.nodeKind() == 'attribute') element[0]=box.value;
778 else element.setChildren( box.value );
784 // 'input' event catches the box value after the keypress
785 box.addEventListener(
788 if (element.nodeKind() == 'attribute') element[0]=box.value;
789 else element.setChildren( box.value );
795 box.addEventListener(
798 if (element.localName() == 'controlfield')
799 eval('fillFixedFields();');
807 function toggleFFE () {
808 var grid = document.getElementById('leaderGrid');
817 function changeFFEditor (type) {
818 var grid = document.getElementById('leaderGrid');
819 grid.setAttribute('type',type);
820 document.getElementById('recordTypeLabel').setAttribute('value',type);
822 // Hide FFEditor rows that we don't need for our current type
823 // If all of the labels for a given row do not include our
824 // desired type in their set attribute, we can hide that row
825 dojo.query('rows', grid).query('row').forEach(function(node, index, arr) {
826 if (dojo.query('label[set~=' + type + ']', node).length == 0) {
833 function fillFixedFields () {
835 var grid = document.getElementById('leaderGrid');
836 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
839 var pre_list = grid.getElementsByTagName('label');
840 for (var i in pre_list) {
841 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
842 list.push( pre_list[i] );
846 for (var i in list) {
847 var name = list[i].getAttribute('name');
848 var value = marc_rec.extractFixedField(name, true);
850 if (value === null) continue;
852 list[i].nextSibling.value = value;
857 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
861 function updateFixedFields (element) {
862 var grid = document.getElementById('leaderGrid');
863 var recGrid = document.getElementById('recGrid');
864 var new_value = element.value;
865 // Don't take focus away/adjust the record on partial changes
866 var length = element.getAttribute('maxlength');
867 if(new_value.length < length) return true;
869 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
870 marc_rec.setFixedField(element.getAttribute('name'), new_value);
872 var xml_string = marc_rec.toXmlString();
873 xml_record = new XML( xml_string );
874 if (xml_record..record[0]) xml_record = xml_record..record[0];
876 // Put the cursor back to the current fixed field
882 function marcLeader (leader) {
884 { class : 'marcLeaderRow',
889 tooltiptext : $('catStrings').getString('staff.cat.marcedit.marcTag.LDR.label') } ),
892 class : 'marcInd1' } ),
895 class : 'marcInd2' } ),
897 { value : leader.text(),
898 class : 'marcLeader' } )
904 function marcControlfield (field) {
905 tagname = field.@tag.toString().substr(2);
907 if (tagname == '1' || tagname == '3' || tagname == '6' || tagname == '7' || tagname == '8') {
909 { class : 'marcControlfieldRow',
910 tag : '_' + tagname },
912 { value : field.@tag,
914 context : 'tags_popup',
915 onmouseover : 'getTooltip(this, "tag");',
916 tooltipid : 'tag' + field.@tag } ),
918 { value : field.@ind1,
920 onmouseover : 'getTooltip(this, "ind1");',
921 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
923 { value : field.@ind2,
925 onmouseover : 'getTooltip(this, "ind2");',
926 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
929 { value : field.text(),
930 class : 'plain marcEditableControlfield',
931 name : 'CONTROL' + tagname,
932 context : 'clipboard',
938 { class : 'marcControlfieldRow',
939 tag : '_' + tagname },
941 { value : field.@tag,
943 onmouseover : 'getTooltip(this, "tag");',
944 tooltipid : 'tag' + field.@tag } ),
946 { value : field.@ind1,
948 onmouseover : 'getTooltip(this, "ind1");',
949 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
951 { value : field.@ind2,
953 onmouseover : 'getTooltip(this, "ind2");',
954 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
956 { value : field.text(),
957 class : 'marcControlfield' } )
964 function stackSubfields(checkbox) {
965 var list = document.getElementsByAttribute('name','sf_box');
968 if (!checkbox.checked) o = 'horizontal';
970 for (var i = 0; i < list.length; i++) {
971 if (list[i]) list[i].setAttribute('orient',o);
975 function fastItemAdd_toggle(checkbox) {
976 var x = document.getElementById('fastItemAdd_textboxes');
977 if (checkbox.checked) {
979 document.getElementById('fastItemAdd_callnumber').focus();
980 document.getElementById('fastItemAdd_callnumber').select();
986 function fastItemAdd_attempt(doc_id) {
988 if (typeof window.xulG.fast_add_item != 'function') { return; }
989 if (!document.getElementById('fastItemAdd_checkbox').checked) { return; }
990 if (!document.getElementById('fastItemAdd_callnumber').value) { return; }
991 if (!document.getElementById('fastItemAdd_barcode').value) { return; }
992 window.xulG.fast_add_item( doc_id, document.getElementById('fastItemAdd_callnumber').value, document.getElementById('fastItemAdd_barcode').value );
993 document.getElementById('fastItemAdd_barcode').value = '';
996 alert('fastItemAdd_attempt: ' + E);
1000 function save_attempt(xml_string) {
1002 var result = window.xulG.save.func( xml_string );
1003 // I'd prefer to pass on_complete on through to fast_item_add,
1004 // but with the way these window scopes get destroyed with
1005 // tab replacement, maybe not a good idea
1006 var replace_on_complete = false;
1010 replace_on_complete = fastItemAdd_attempt(result.id);
1012 if (!replace_on_complete && typeof result.on_complete == 'function') {
1013 result.on_complete();
1017 alert('save_attempt: ' + E);
1021 function marcDatafield (field) {
1022 var row = createRow(
1023 { class : 'marcDatafieldRow' },
1026 { value : field.@tag,
1027 class : 'plain marcTag',
1029 context : 'tags_popup',
1030 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1033 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1036 { value : field.@ind1,
1037 class : 'plain marcInd1',
1039 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1042 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1043 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1046 { value : field.@ind2,
1047 class : 'plain marcInd2',
1049 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1052 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1053 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1054 createHbox({ name : 'sf_box' })
1057 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1058 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1059 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1061 var sf_box = row.lastChild;
1062 if (document.getElementById('stackSubfields').checked)
1063 sf_box.setAttribute('orient','vertical');
1065 sf_box.addEventListener(
1068 if (sf_box === e.target) {
1069 sf_box.lastChild.lastChild.focus();
1070 } else if (e.target.parentNode === sf_box) {
1071 e.target.lastChild.focus();
1078 for (var i in field.subfield) {
1079 var sf = field.subfield[i];
1084 dojo.query('.marcSubfield', sf_box).forEach(wrap_long_fields);
1086 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1087 current_focus = sf_box.lastChild.childNodes[1];
1093 function marcSubfield (sf) {
1095 { class : 'marcSubfieldBox' },
1098 class : 'plain marcSubfieldDelimiter',
1099 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1100 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1101 //onclick : 'this.nextSibling.focus();',
1102 onfocus : 'this.nextSibling.focus();',
1107 class : 'plain marcSubfieldCode',
1109 name : 'marcSubfieldCode',
1110 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1111 oncontextmenu : 'getContextMenu(this, "subfield");',
1112 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1117 { value : sf.text(),
1118 name : sf.parent().@tag + ':' + sf.@code,
1119 class : 'plain marcSubfield',
1121 onmouseover : 'getTooltip(this, "subfield");',
1122 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1123 size : new String(sf.text()).length + 2,
1124 oninput : "this.setAttribute('size', this.value.length + 2);"
1129 function loadRecord() {
1131 var grid_rows = document.getElementById('recGrid').lastChild;
1133 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1135 grid_rows.appendChild( marcLeader( xml_record.leader ) );
1137 for (var i in xml_record.controlfield) {
1138 grid_rows.appendChild( marcControlfield( xml_record.controlfield[i] ) );
1141 for (var i in xml_record.datafield) {
1142 grid_rows.appendChild( marcDatafield( xml_record.datafield[i] ) );
1145 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1147 var marc_rec = new MARC.Record ({ delimiter : '$', marcxml : xml_record.toXMLString() });
1148 changeFFEditor(marc_rec.recordType());
1151 alert('FIXME, MARC Editor, loadRecord: ' + E);
1156 function genToolTips () {
1157 for (var i in bib_data.field) {
1158 var f = bib_data.field[i];
1160 tag_menu.appendChild(
1164 'current_focus.value = "' + f.@tag + '";' +
1165 'var e = document.createEvent("MutationEvents");' +
1166 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1167 'current_focus.inputField.dispatchEvent(e);',
1168 disabled : f.@tag < '010' ? "true" : "false",
1169 tooltiptext : f.description }
1173 var i1_popup = createMenuPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1174 context_menus.appendChild( i1_popup );
1176 var i2_popup = createMenuPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1177 context_menus.appendChild( i2_popup );
1179 var sf_popup = createMenuPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1180 context_menus.appendChild( sf_popup );
1182 tooltip_hash['tag' + f.@tag] = f.description;
1183 for (var j in f.indicator) {
1184 var ind = f.indicator[j];
1185 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1187 if (ind.@position == 1) {
1188 i1_popup.appendChild(
1190 { label : ind.@value,
1192 'current_focus.value = "' + ind.@value + '";' +
1193 'var e = document.createEvent("MutationEvents");' +
1194 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1195 'current_focus.inputField.dispatchEvent(e);',
1196 tooltiptext : ind.description }
1201 if (ind.@position == 2) {
1202 i2_popup.appendChild(
1204 { label : ind.@value,
1206 'current_focus.value = "' + ind.@value + '";' +
1207 'var e = document.createEvent("MutationEvents");' +
1208 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1209 'current_focus.inputField.dispatchEvent(e);',
1210 tooltiptext : ind.description }
1216 for (var j in f.subfield) {
1217 var sf = f.subfield[j];
1218 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1220 sf_popup.appendChild(
1224 'current_focus.value = "' + sf.@code + '";' +
1225 'var e = document.createEvent("MutationEvents");' +
1226 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1227 'current_focus.inputField.dispatchEvent(e);',
1228 tooltiptext : sf.description
1236 function getTooltip (target, type) {
1239 if (type == 'subfield')
1240 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1243 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1246 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1249 tt = 'tag' + target.parentNode.firstChild.value;
1251 if (!document.getElementById( tt )) {
1256 orient : 'vertical',
1257 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1258 class : 'tooltip' },
1259 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1264 target.tooltip = tt;
1268 function getContextMenu (target, type) {
1271 if (type == 'subfield')
1272 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1275 tt = 't' + target.parentNode.firstChild.value + 'i1';
1278 tt = 't' + target.parentNode.firstChild.value + 'i2';
1280 target.setAttribute('context', tt);
1286 'a' : { 100 : 'a' },
1287 'd' : { 100 : 'd' },
1288 'e' : { 100 : 'e' },
1292 'a' : { 110 : 'a' },
1296 'a' : { 111 : 'a' },
1300 'a' : { 130 : 'a' },
1304 'a' : { 130 : 'a' },
1308 'a' : { 100 : 'a' },
1312 'a' : { 110 : 'a' },
1316 'a' : { 111 : 'a' },
1320 'a' : { 130 : 'a' },
1321 'n' : { 130 : 'n' },
1325 'a' : { 100 : 'a' },
1326 'd' : { 100 : 'd' },
1327 'q' : { 100 : 'q' },
1331 'a' : { 110 : 'a' },
1335 'a' : { 111 : 'a' },
1336 'c' : { 111 : 'c' },
1340 'a' : { 130 : 'a' },
1344 'a' : { 100 : 'a' },
1348 'a' : { 110 : 'a' },
1352 'a' : { 111 : 'a' },
1356 'a' : { 130 : 'a' },
1360 'a' : { 100 : 'a' },
1361 'd' : { 100 : 'd' },
1362 'q' : { 100 : 'q' },
1363 't' : { 100 : 't' },
1390 'a' : { 110 : 'a' },
1391 'd' : { 110 : 'd' },
1392 't' : { 110 : 't' },
1419 'a' : { 111 : 'a' },
1420 'd' : { 111 : 'd' },
1421 't' : { 111 : 't' },
1448 'a' : { 130 : 'a' },
1452 'a' : { 148 : 'a' },
1453 'v' : { 148 : 'v' },
1454 'x' : { 148 : 'x' },
1455 'y' : { 148 : 'y' },
1459 'a' : { 150 : 'a' },
1460 'b' : { 150 : 'b' },
1487 'a' : { 151 : 'a' },
1514 'a' : { 155 : 'a' },
1542 function getAuthorityContextMenu (target, sf) {
1543 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1546 var old = dojo.byId( menu_id );
1548 page = auth_pages[menu_id];
1549 old.parentNode.removeChild(old);
1551 auth_pages[menu_id] = 0;
1554 var sf_popup = createMenuPopup({ id : menu_id, flex : 1 });
1556 sf_popup.addEventListener("popuphiding", function(event) {
1557 if (show_auth_menu) {
1558 show_auth_menu = false;
1559 getAuthorityContextMenu(target, sf);
1560 dojo.byId(menu_id).openPopup();
1564 context_menus.appendChild( sf_popup );
1567 dojo.forEach( acs.controlSetList(), function (acs_id) {
1568 if (acs.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
1571 if (!found_acs.length) {
1572 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.not_authority_field.label') } ) );
1573 target.setAttribute('context', 'clipboard');
1577 if (sf.toString().replace(/\s*/, '')) {
1578 return browseAuthority(sf_popup, menu_id, target, sf, 20, page);
1584 /* Apply the complete 1xx */
1585 function applyFullAuthority ( target, ui_sf, e4x_sf ) {
1586 var new_vals = dojo.query('*[tag^="1"]', target);
1587 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1590 function applySelectedAuthority ( target, ui_sf, e4x_sf ) {
1591 var new_vals = target.getElementsByAttribute('checked','true');
1592 return applyAuthority( target, ui_sf, e4x_sf, new_vals );
1595 function applyAuthority ( target, ui_sf, e4x_sf, new_vals ) {
1596 var field = e4x_sf.parent();
1598 for (var i = 0; i < new_vals.length; i++) {
1600 var sf_list = field.subfield;
1601 for (var j in sf_list) {
1603 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1604 sf_list[j] = new_vals[i].getAttribute('value');
1605 new_vals[i].setAttribute('subfield','');
1611 for (var i = 0; i < new_vals.length; i++) {
1613 /* indicators for the authority datafield are carried over in the main entry linking subfield */
1614 if (new_vals[i].getAttribute('subfield') == '0') {
1615 field.@ind1 = new_vals[i].getAttribute('ind1');
1616 field.@ind2 = new_vals[i].getAttribute('ind2');
1619 if (!new_vals[i].getAttribute('subfield')) continue;
1621 var val = new_vals[i].getAttribute('value');
1623 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1624 sf.@code = new_vals[i].getAttribute('subfield');
1626 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1629 var row = marcDatafield( field );
1632 while (node.nodeName != 'row') {
1633 node = node.parentNode;
1636 node.parentNode.replaceChild( row, node );
1640 function validateAuthority (button) {
1641 var grid = document.getElementById('recGrid');
1642 var label = button.getAttribute('label');
1645 var rows = grid.lastChild.childNodes;
1646 for (var i = 0; i < rows.length; i++) {
1648 var tag = row.firstChild;
1651 dojo.forEach(acs.controlSetList(), function (acs_id) {
1653 var control_map = acs.controlSet(acs_id).control_map;
1655 if (!control_map[tag.value]) return;
1656 button.setAttribute('label', label + ' - ' + tag.value);
1658 var ind1 = tag.nextSibling;
1659 var ind2 = ind1.nextSibling;
1660 var subfields = ind2.nextSibling.childNodes;
1663 for (var j = 0; j < subfields.length; j++) {
1664 var sf = subfields[j];
1665 sf_list.push( [ sf.childNodes[1].value, sf.childNodes[2].value ] );
1668 var matches = acs.findMatchingAuthorities(
1671 'subfields' : sf_list
1675 // matches = [ { "$csetId" : [ ... ] } ]
1678 if (matches[0]) { // probably set
1679 for (var cset in matches[0]) {
1680 var arr = matches[0][cset];
1682 // protect against errant empty string values
1683 if (arr.length == 1 && arr[0] == '')
1692 // XXX If adt, etc should be validated separately from vxz, etc then move this up into the above for loop
1693 for (var j = 0; j < subfields.length; j++) {
1694 var sf = subfields[j];
1696 dojo.removeClass(sf.childNodes[2], 'marcValidated');
1697 dojo.addClass(sf.childNodes[2], 'marcUnvalidated');
1699 dojo.removeClass(sf.childNodes[2], 'marcUnvalidated');
1700 dojo.addClass(sf.childNodes[2], 'marcValidated');
1704 if (found) done = true;
1708 button.setAttribute('label', label);
1715 function validateBibField (tags, searches) {
1716 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.validate.tag";
1717 url += '¶m="tags"¶m=' + js2JSON(tags);
1718 url += '¶m="searches"¶m=' + js2JSON(searches);
1721 var req = new XMLHttpRequest();
1722 req.open('GET',url,false);
1730 function searchAuthority (term, tag, sf, limit) {
1731 var url = "/gateway?input_format=json&format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1732 url += '¶m="term"¶m="' + term + '"';
1733 url += '¶m="limit"¶m=' + limit;
1734 url += '¶m="tag"¶m=' + tag;
1735 url += '¶m="subfield"¶m="' + sf + '"';
1738 var req = new XMLHttpRequest();
1739 req.open('GET',url,false);
1746 /* TODO new authority browse support for context sets, and use that here */
1747 function browseAuthority (sf_popup, menu_id, target, sf, limit, page) {
1748 dojo.require('dojox.xml.parser');
1750 // map tag + subfield to the appropriate authority browse axis:
1751 // currently authority.author, authority.subject, authority.title, authority.topic
1752 // based on mappings in OpenILS::Application::SuperCat, though Authority Control
1753 // Sets will change that
1755 var axis_list = acs.bibFieldBrowseAxes( sf.parent().@tag.toString() );
1757 // No matching tag means no authorities to search - shortcut
1758 if (axis_list.length == 0) {
1759 target.setAttribute('context', 'clipboard');
1763 var type = 'authority.' + axis_list[0]; // Just take the first for now
1764 // TODO support multiple axes ... loop?
1774 var sf_list = sf.parent().subfield;
1775 for ( var i in sf_list) {
1776 sf_string += sf_list[i].toString() + ' ';
1777 if (sf_list[i] === sf) break;
1780 var url = '/opac/extras/browse/marcxml/'
1782 + '/1' // OU - currently unscoped
1788 // would be good to carve this out into a separate function
1789 dojo.xhrGet({"url":url, "sync": true, "preventCache": true, "handleAs":"xml", "load": function(records) {
1790 var create_menu = createMenu({ label: $('catStrings').getString('staff.cat.marcedit.create_authority.label')});
1792 var cm_popup = create_menu.appendChild(
1796 cm_popup.appendChild(
1797 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_now.label'),
1798 command : function() {
1799 // Call middle-layer function to create and save the new authority
1800 var source_f = summarizeField(sf);
1801 var new_auth = fieldmapper.standardRequest(
1802 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib"],
1803 [source_f, xulG.marc_control_number_identifier, ses()]
1805 if (new_auth && new_auth.id()) {
1806 addNewAuthorityID(new_auth, sf, target);
1812 cm_popup.appendChild(
1813 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.create_authority_edit.label'),
1814 command : function() {
1815 // Generate the new authority by calling the new middle-layer
1816 // function (a non-saving variant), then display in another
1818 var source_f = summarizeField(sf);
1819 var authtoken = ses();
1820 dojo.require('openils.PermaCrud');
1821 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
1822 var rec = fieldmapper.standardRequest(
1823 ["open-ils.cat", "open-ils.cat.authority.record.create_from_bib.readonly"],
1824 { "params": [source_f, xulG.marc_control_number_identifier] }
1826 loadMarcEditor(pcrud, rec, target, sf);
1831 sf_popup.appendChild(create_menu);
1832 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1834 // append "Previous page" results browser
1835 sf_popup.appendChild(
1836 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.previous_page.label'),
1837 command : function(event) {
1838 auth_pages[menu_id] -= 1;
1839 show_auth_menu = true;
1843 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1845 dojo.query('record', records).forEach(function(record) {
1849 var auth_id = dojox.xml.parser.textContent(dojo.query('datafield[tag="901"]', record).query('subfield[code="c"]')[0]);
1850 var auth_org = dojox.xml.parser.textContent(dojo.query('controlfield[tag="003"]', record)[0]);
1852 // Grab the fields with tags beginning with 1 (main entries) and iterate through the subfields
1853 dojo.query('datafield[tag^="1"]', record).forEach(function(field) {
1854 dojo.query('subfield', field).forEach(function(subfield) {
1858 main_text += dojox.xml.parser.textContent(subfield);
1862 // Grab the fields with tags beginning with 4 (see from entries) and iterate through the subfields
1863 dojo.query('datafield[tag^="4"]', record).forEach(function(field) {
1865 dojo.query('subfield', field).forEach(function(subfield) {
1869 see_text += dojox.xml.parser.textContent(subfield);
1871 see_from.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_from', [see_text]));
1874 // Grab the fields with tags beginning with 5 (see also entries) and iterate through the subfields
1875 dojo.query('datafield[tag^="5"]', record).forEach(function(field) {
1877 dojo.query('subfield', field).forEach(function(subfield) {
1881 see_text += dojox.xml.parser.textContent(subfield);
1883 see_also.push($('catStrings').getFormattedString('staff.cat.marcedit.authority_see_also', [see_text]));
1886 buildAuthorityPopup(main_text, record, auth_org, auth_id, sf_popup, target, sf);
1888 dojo.forEach(see_from, function(entry_text) {
1889 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1892 // To-do: instead of launching the standard selector menu, invoke
1893 // a new authority search using the 5XX entry text
1894 dojo.forEach(see_also, function(entry_text) {
1895 buildAuthorityPopup(entry_text, record, auth_org, auth_id, sf_popup, target, sf, "font-style: italic; margin-left: 2em;");
1900 if (sf_popup.childNodes.length == 0) {
1901 sf_popup.appendChild(createLabel( { value : $('catStrings').getString('staff.cat.marcedit.no_authority_match.label') } ) );
1903 // append "Next page" results browser
1904 sf_popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1905 sf_popup.appendChild(
1906 createMenuitem({ label : $('catStrings').getString('staff.cat.marcedit.next_page.label'),
1907 command : function(event) {
1908 auth_pages[menu_id] += 1;
1909 show_auth_menu = true;
1915 target.setAttribute('context', menu_id);
1921 function buildAuthorityPopup (entry_text, record, auth_org, auth_id, sf_popup, target, sf, style) {
1922 var grid = dojo.query('[name="authority-marc-template"]')[0].cloneNode(true);
1923 grid.setAttribute('name','-none-');
1924 grid.setAttribute('style','overflow:scroll');
1926 var submenu = createMenu( { "label": entry_text } );
1928 var popup = createMenuPopup({ "flex": "1" });
1930 submenu.setAttribute('style', style);
1931 popup.setAttribute('style', 'font-style: normal; margin-left: 0em;');
1933 submenu.appendChild(popup);
1935 dojo.query('datafield[tag^="1"]', record).forEach(function(field) {
1936 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1938 dojo.query('datafield[tag^="4"]', record).forEach(function(field) {
1939 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1941 dojo.query('datafield[tag^="5"]', record).forEach(function(field) {
1942 buildAuthorityPopupSelector(field, grid, auth_org, auth_id);
1945 grid.hidden = false;
1946 popup.appendChild( grid );
1950 { label : $('catStrings').getString('staff.cat.marcedit.apply_selected.label'),
1951 command : function (event) {
1952 applySelectedAuthority(event.target.previousSibling, target, sf);
1959 popup.appendChild( createComplexXULElement( 'menuseparator' ) );
1963 { label : $('catStrings').getString('staff.cat.marcedit.apply_full.label'),
1964 command : function (event) {
1965 applyFullAuthority(event.target.previousSibling.previousSibling.previousSibling, target, sf);
1972 sf_popup.appendChild( submenu );
1975 function buildAuthorityPopupSelector (field, grid, auth_org, auth_id) {
1976 var row = createRow(
1978 createLabel( { "value" : dojo.attr(field, 'tag') } ),
1979 createLabel( { "value" : dojo.attr(field, 'ind1') } ),
1980 createLabel( { "value" : dojo.attr(field, 'ind2') } )
1983 var sf_box = createHbox();
1984 dojo.query('subfield', field).forEach(function(subfield) {
1987 { "label" : '\u2021' + dojo.attr(subfield, 'code') + ' ' + dojox.xml.parser.textContent(subfield),
1988 "subfield" : dojo.attr(subfield, 'code'),
1989 "tag" : dojo.attr(field, 'tag'),
1990 "value" : dojox.xml.parser.textContent(subfield)
1994 row.appendChild(sf_box);
1997 // Append the authority linking subfield only for main entries
1998 if (dojo.attr(field, 'tag').charAt(0) == '1') {
2001 { "label" : '\u2021' + '0' + ' (' + auth_org + ')' + auth_id,
2003 "tag" : dojo.attr(field, 'tag'),
2004 "ind1" : dojo.attr(field, 'ind1'),
2005 "ind2" : dojo.attr(field, 'ind2'),
2006 "value" : '(' + auth_org + ')' + auth_id
2011 row.appendChild(sf_box);
2013 grid.lastChild.appendChild(row);
2016 function summarizeField(sf) {
2024 source_f.tag = sf.parent().@tag.toString();
2025 source_f.ind1 = sf.parent().@ind1.toString();
2026 source_f.ind2 = sf.parent().@ind2.toString();
2029 dojo.forEach( acs.controlSetList(), function (acs_id) {
2030 if (acs.controlSet(acs_id).control_map[sf.parent().@tag]) found_acs.push(acs_id);
2034 if (!found_acs.length) {
2037 cmap = acs.controlSet(found_acs[0]).control_map;
2040 for (var i = 0; i < sf.parent().subfield.length(); i++) {
2041 var sf_iter = sf.parent().subfield[i];
2043 /* Filter out subfields that are not controlled for this tag */
2044 if (!cmap[source_f.tag][sf_iter.@code.toString()]) {
2048 source_f.subfields.push([sf_iter.@code.toString(), sf_iter.toString()]);
2054 function buildBibSourceList (authtoken, recId) {
2055 /* TODO: Work out how to set the bib source of the bre that does not yet
2056 * exist - this is specifically in the case of Z39.50 imports. Right now
2057 * we just avoid populating and showing the config.bib_source list
2063 var bib = xulG.record.bre;
2065 dojo.require('openils.PermaCrud');
2067 // cbsList = the XUL menulist that contains the available bib sources
2068 var cbsList = dojo.byId('bib-source-list');
2070 // bibSources = an array containing all of the bib source objects
2071 var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
2073 // A tad ugly, but gives us the index of the bib source ID in cbsList
2075 var cbsListArr = [];
2076 dojo.forEach(bibSources, function (item) {
2077 cbsList.appendItem(item.source(), item.id());
2078 cbsListArr[item.id()] = x;
2082 // Show the current value of the bib source for this record
2083 cbsList.selectedIndex = cbsListArr[bib.source()];
2085 // Display the bib source selection widget
2086 dojo.byId('bib-source-list-caption').hidden = false;
2087 dojo.byId('bib-source-list').hidden = false;
2088 dojo.byId('bib-source-list-button').disabled = true;
2089 dojo.byId('bib-source-list-button').hidden = false;
2092 // Fired when the "Update Source" button is clicked
2093 // Updates the value of the bib source for the current record
2094 function updateBibSource() {
2095 var authtoken = ses();
2096 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2097 var recId = xulG.record.id;
2098 var pcrud = new openils.PermaCrud({"authtoken": authtoken});
2099 var bib = pcrud.retrieve('bre', recId);
2100 if (bib.source() != cbs) {
2102 bib.ischanged = true;
2107 function onBibSourceSelect() {
2108 var cbs = dojo.byId('bib-source-list').selectedItem.value;
2109 var bib = xulG.record.bre;
2110 if (bib.source() != cbs) {
2111 dojo.byId('bib-source-list-button').disabled = false;
2113 dojo.byId('bib-source-list-button').disabled = true;
2117 function addNewAuthorityID(authority, sf, target) {
2118 var id_sf = <subfield code="0" xmlns="http://www.loc.gov/MARC21/slim">({xulG.marc_control_number_identifier}){authority.id()}</subfield>;
2119 sf.parent().appendChild(id_sf);
2120 var new_sf = marcSubfield(id_sf);
2123 while (dojo.attr(node, 'name') != 'sf_box') {
2124 node = node.parentNode;
2126 node.appendChild( new_sf );
2128 alert($('catStrings').getString('staff.cat.marcedit.create_authority_success.label'));
2131 function loadMarcEditor(pcrud, marcxml, target, sf) {
2133 To run in Firefox directly, must set signed.applets.codebase_principal_support
2134 to true in about:config
2136 win = window.open('/xul/server/cat/marcedit.xul', '_blank', 'chrome'); // XXX version?
2138 // Match marc2are.pl last_xact_id format, roughly
2140 var xact_id = 'IMPORT-' + Date.parse(now);
2143 "record": {"marc": marcxml, "rtype": "are"},
2145 "label": $('catStrings').getString('staff.cat.marcedit.save.label'),
2146 "func": function(xmlString) {
2147 var rec = new are();
2148 rec.marc(xmlString);
2149 rec.last_xact_id(xact_id);
2152 "oncomplete": function (r, objs) {
2153 var new_rec = objs[0];
2158 addNewAuthorityID(new_rec, sf, target);