1 var xmlDeclaration = /^<\?xml version[^>]+?>/;
3 var serializer = new XMLSerializer();
4 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
5 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
6 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
7 default xml namespace = marcns;
16 function mangle_005() {
18 var y = now.getUTCFullYear();
20 var m = now.getUTCMonth() + 1;
21 if (m < 10) m = '0' + m;
23 var d = now.getUTCDate();
24 if (d < 10) d = '0' + d;
26 var H = now.getUTCHours();
27 if (H < 10) H = '0' + H;
29 var M = now.getUTCMinutes();
30 if (M < 10) M = '0' + M;
32 var S = now.getUTCSeconds();
33 if (S < 10) S = '0' + S;
36 var stamp = '' + y + m + d + H + M + S + '.0';
37 createControlField('005',stamp);
41 function createControlField (tag,data) {
42 // first, remove the old field, if any;
43 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
45 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
48 // then, find the right position and insert it
50 var cfields = xml_record.controlfield;
51 var base = Number(tag.substring(2));
52 for (var i in cfields) {
53 var t = Number(cfields[i].@tag.toString().substring(2));
55 xml_record.insertChildBefore( cfields[i], cf );
61 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
66 function xml_escape_unicode ( str ) {
69 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
75 // Fake xulG for standalone...
80 window.xulG.record = {};
81 window.xulG.save = {};
83 window.xulG.save.label = 'Save Record';
84 window.xulG.save.func = function (r) { alert(r); }
87 var _rid = cgi.param('record');
89 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
94 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
95 document.getElementById('save-button').setAttribute('oncommand',
97 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
98 'window.xulG.save.func( xml_string ); ' +
99 'loadRecord(xml_record);'
102 if (window.xulG.record.url) {
103 var req = new XMLHttpRequest();
104 req.open('GET',window.xulG.record.url,false);
106 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
109 xml_record = new XML( window.xulG.record.marc );
110 if (xml_record..record[0]) xml_record = xml_record..record[0];
112 // Get the tooltip xml all async like
113 req = new XMLHttpRequest();
114 req.open('GET','marcedit-tooltips.xml',true);
115 req.onreadystatechange = function () {
116 if (req.readyState == 4) {
117 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
123 loadRecord(xml_record);
125 alert('FIXME, MARC Editor, my_init: ' + E);
130 function createComplexHTMLElement (e, attrs, objects, text) {
131 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
134 for (var i in attrs) l.setAttribute(i,attrs[i]);
138 for ( var i in objects ) l.appendChild( objects[i] );
142 l.appendChild( document.createTextNode(text) )
148 function createComplexXULElement (e, attrs, objects) {
149 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
152 for (var i in attrs) {
153 if (typeof attrs[i] == 'function') {
154 l.addEventListener( i, attrs[i], true );
156 l.setAttribute(i,attrs[i]);
162 for ( var i in objects ) l.appendChild( objects[i] );
168 function createDescription (attrs) {
169 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
172 function createTooltip (attrs) {
173 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
176 function createLabel (attrs) {
177 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
180 function createVbox (attrs) {
181 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
184 function createHbox (attrs) {
185 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
188 function createRow (attrs) {
189 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
192 function createTextbox (attrs) {
193 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
196 function createMenu (attrs) {
197 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
200 function createMenuPopup (attrs) {
201 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
204 function createPopup (attrs) {
205 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
208 function createMenuitem (attrs) {
209 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
212 function createCheckbox (attrs) {
213 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
216 function createMARCTextbox (element,attrs) {
218 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
219 box.onkeypress = function (event) {
222 while(node = node.parent()) {
226 var row = event.target;
227 while (row.tagName != 'row') row = row.parentNode;
229 if (element.nodeKind() == 'attribute') element[0]=box.value;
230 else element.setChildren( box.value );
232 if (element.localName() != 'controlfield') {
233 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
235 var index_sf, target, move_data;
236 if (element.localName() == 'subfield') {
238 target = event.target.parentNode;
240 var start = event.target.selectionStart;
241 var end = event.target.selectionEnd - event.target.selectionStart ?
242 event.target.selectionEnd :
243 event.target.value.length;
245 move_data = event.target.value.substring(start,end);
246 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
247 event.target.setAttribute('size', event.target.value.length + 2);
249 element.setChildren( event.target.value );
251 } else if (element.localName() == 'code') {
252 index_sf = element.parent();
253 target = event.target.parentNode;
254 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
255 index_sf = element.parent().children()[element.parent().children().length() - 1];
256 target = event.target.parentNode.lastChild.lastChild;
259 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
261 index_sf.parent().insertChildAfter( index_sf, sf );
263 var new_sf = marcSubfield(sf);
265 if (target === target.parentNode.lastChild) {
266 target.parentNode.appendChild( new_sf );
268 target.parentNode.insertBefore( new_sf, target.nextSibling );
271 new_sf.firstChild.nextSibling.focus();
273 event.preventDefault();
276 } else if (event.keyCode == 13 || event.keyCode == 77) {
277 if (event.ctrlKey) { // ctrl+enter
280 if (element.localName() == 'subfield') index = element.parent();
281 if (element.localName() == 'code') index = element.parent().parent();
282 if (element.localName() == 'tag') index = element.parent();
283 if (element.localName() == 'ind1') index = element.parent();
284 if (element.localName() == 'ind2') index = element.parent();
286 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
288 index.parent().insertChildAfter( index, df );
290 var new_df = marcDatafield(df);
292 if (row.parentNode.lastChild === row) {
293 row.parentNode.appendChild( new_df );
295 row.parentNode.insertBefore( new_df, row.nextSibling );
298 new_df.firstChild.focus();
300 event.preventDefault();
303 } else if (event.shiftKey) {
304 if (row.previousSibling.className.match('marcDatafieldRow'))
305 row.previousSibling.firstChild.focus();
307 row.nextSibling.firstChild.focus();
310 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
313 if (element.localName() == 'subfield') index = element.parent();
314 if (element.localName() == 'code') index = element.parent().parent();
315 if (element.localName() == 'tag') index = element.parent();
316 if (element.localName() == 'ind1') index = element.parent();
317 if (element.localName() == 'ind2') index = element.parent();
319 for (var i in index.parent().children()) {
320 if (index === index.parent().children()[i]) {
321 delete index.parent().children()[i];
326 row.previousSibling.firstChild.focus();
327 row.parentNode.removeChild(row);
329 event.preventDefault();
332 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
335 if (element.localName() == 'subfield') index = element;
336 if (element.localName() == 'code') index = element.parent();
339 for (var i in index.parent().children()) {
340 if (index === index.parent().children()[i]) {
341 delete index.parent().children()[i];
346 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
347 event.target.parentNode.previousSibling.lastChild.focus();
349 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
352 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
354 event.preventDefault();
357 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
358 createControlField('006','');
359 loadRecord(xml_record);
360 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
361 createControlField('007','');
362 loadRecord(xml_record);
363 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
364 createControlField('008','');
365 loadRecord(xml_record);
371 box.addEventListener(
374 if (element.nodeKind() == 'attribute') element[0]=box.value;
375 else element.setChildren( box.value );
381 box.addEventListener(
384 if (element.nodeKind() == 'attribute') element[0]=box.value;
385 else element.setChildren( box.value );
391 box.addEventListener(
394 if (element.nodeKind() == 'attribute') element[0]=box.value;
395 else element.setChildren( box.value );
401 box.addEventListener(
404 if (element.localName() == 'controlfield')
405 eval('fillFixedFields(xml_record);');
414 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
415 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
416 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
417 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
418 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
419 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
420 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
421 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
427 BKS : {start : 15, len : 3, def : ' ' },
428 SER : {start : 15, len : 3, def : ' ' },
429 VIS : {start : 15, len : 3, def : ' ' },
430 MIX : {start : 15, len : 3, def : ' ' },
431 MAP : {start : 15, len : 3, def : ' ' },
432 SCO : {start : 15, len : 3, def : ' ' },
433 REC : {start : 15, len : 3, def : ' ' },
434 COM : {start : 15, len : 3, def : ' ' },
439 BKS : {start : 35, len : 3, def : ' ' },
440 SER : {start : 35, len : 3, def : ' ' },
441 VIS : {start : 35, len : 3, def : ' ' },
442 MIX : {start : 35, len : 3, def : ' ' },
443 MAP : {start : 35, len : 3, def : ' ' },
444 SCO : {start : 35, len : 3, def : ' ' },
445 REC : {start : 35, len : 3, def : ' ' },
446 COM : {start : 35, len : 3, def : ' ' },
451 BKS : {start : 38, len : 1, def : ' ' },
452 SER : {start : 38, len : 1, def : ' ' },
453 VIS : {start : 38, len : 1, def : ' ' },
454 MIX : {start : 38, len : 1, def : ' ' },
455 MAP : {start : 38, len : 1, def : ' ' },
456 SCO : {start : 38, len : 1, def : ' ' },
457 REC : {start : 38, len : 1, def : ' ' },
458 COM : {start : 38, len : 1, def : ' ' },
463 BKS : {start : 6, len : 1, def : ' ' },
464 SER : {start : 6, len : 1, def : 'c' },
465 VIS : {start : 6, len : 1, def : ' ' },
466 MIX : {start : 6, len : 1, def : ' ' },
467 MAP : {start : 6, len : 1, def : ' ' },
468 SCO : {start : 6, len : 1, def : ' ' },
469 REC : {start : 6, len : 1, def : ' ' },
470 COM : {start : 6, len : 1, def : ' ' },
475 BKS : {start : 6, len : 1, def : 'a' },
476 SER : {start : 6, len : 1, def : 'a' },
477 VIS : {start : 6, len : 1, def : 'g' },
478 MIX : {start : 6, len : 1, def : 'p' },
479 MAP : {start : 6, len : 1, def : 'e' },
480 SCO : {start : 6, len : 1, def : 'c' },
481 REC : {start : 6, len : 1, def : 'i' },
482 COM : {start : 6, len : 1, def : 'm' },
487 BKS : {start : 8, len : 1, def : ' ' },
488 SER : {start : 8, len : 1, def : ' ' },
489 VIS : {start : 8, len : 1, def : ' ' },
490 MIX : {start : 8, len : 1, def : ' ' },
491 MAP : {start : 8, len : 1, def : ' ' },
492 SCO : {start : 8, len : 1, def : ' ' },
493 REC : {start : 8, len : 1, def : ' ' },
494 COM : {start : 8, len : 1, def : ' ' },
499 BKS : {start : 7, len : 1, def : 'm' },
500 SER : {start : 7, len : 1, def : 's' },
501 VIS : {start : 7, len : 1, def : 'm' },
502 MIX : {start : 7, len : 1, def : 'c' },
503 MAP : {start : 7, len : 1, def : 'm' },
504 SCO : {start : 7, len : 1, def : 'm' },
505 REC : {start : 7, len : 1, def : 'm' },
506 COM : {start : 7, len : 1, def : 'm' },
511 BKS : {start : 18, len : 1, def : ' ' },
512 SER : {start : 18, len : 1, def : ' ' },
513 VIS : {start : 18, len : 1, def : ' ' },
514 MIX : {start : 18, len : 1, def : ' ' },
515 MAP : {start : 18, len : 1, def : ' ' },
516 SCO : {start : 18, len : 1, def : ' ' },
517 REC : {start : 18, len : 1, def : ' ' },
518 COM : {start : 18, len : 1, def : ' ' },
523 BKS : {start : 17, len : 1, def : ' ' },
524 SER : {start : 17, len : 1, def : ' ' },
525 VIS : {start : 17, len : 1, def : ' ' },
526 MIX : {start : 17, len : 1, def : ' ' },
527 MAP : {start : 17, len : 1, def : ' ' },
528 SCO : {start : 17, len : 1, def : ' ' },
529 REC : {start : 17, len : 1, def : ' ' },
530 COM : {start : 17, len : 1, def : ' ' },
535 BKS : {start : 31, len : 1, def : '0' },
536 MAP : {start : 31, len : 1, def : '0' },
539 BKS : {start : 14, len : 1, def : '0' },
540 MAP : {start : 14, len : 1, def : '0' },
545 BKS : {start : 7, len : 4, def : ' ' },
546 SER : {start : 7, len : 4, def : ' ' },
547 VIS : {start : 7, len : 4, def : ' ' },
548 MIX : {start : 7, len : 4, def : ' ' },
549 MAP : {start : 7, len : 4, def : ' ' },
550 SCO : {start : 7, len : 4, def : ' ' },
551 REC : {start : 7, len : 4, def : ' ' },
552 COM : {start : 7, len : 4, def : ' ' },
557 BKS : {start : 11, len : 4, def : ' ' },
558 SER : {start : 11, len : 4, def : '9' },
559 VIS : {start : 11, len : 4, def : ' ' },
560 MIX : {start : 11, len : 4, def : ' ' },
561 MAP : {start : 11, len : 4, def : ' ' },
562 SCO : {start : 11, len : 4, def : ' ' },
563 REC : {start : 11, len : 4, def : ' ' },
564 COM : {start : 11, len : 4, def : ' ' },
569 BKS : {start : 33, len : 1, def : '0' },
572 BKS : {start : 16, len : 1, def : '0' },
577 BKS : {start : 34, len : 1, def : ' ' },
580 BKS : {start : 17, len : 1, def : ' ' },
585 BKS : {start : 18, len : 4, def : ' ' },
588 BKS : {start : 1, len : 4, def : ' ' },
593 BKS : {start : 30, len : 1, def : '0' },
596 BKS : {start : 13, len : 1, def : '0' },
601 BKS : {start : 29, len : 1, def : '0' },
602 SER : {start : 29, len : 1, def : '0' },
605 BKS : {start : 12, len : 1, def : '0' },
606 SER : {start : 12, len : 1, def : '0' },
611 BKS : {start : 24, len : 4, def : ' ' },
612 SER : {start : 25, len : 3, def : ' ' },
615 BKS : {start : 7, len : 4, def : ' ' },
616 SER : {start : 8, len : 3, def : ' ' },
621 BKS : {start : 28, len : 1, def : ' ' },
622 SER : {start : 28, len : 1, def : ' ' },
623 VIS : {start : 28, len : 1, def : ' ' },
624 MAP : {start : 28, len : 1, def : ' ' },
625 COM : {start : 28, len : 1, def : ' ' },
628 BKS : {start : 11, len : 1, def : ' ' },
629 SER : {start : 11, len : 1, def : ' ' },
630 VIS : {start : 11, len : 1, def : ' ' },
631 MAP : {start : 11, len : 1, def : ' ' },
632 COM : {start : 11, len : 1, def : ' ' },
637 BKS : {start : 22, len : 1, def : ' ' },
638 SER : {start : 22, len : 1, def : ' ' },
639 VIS : {start : 22, len : 1, def : ' ' },
640 SCO : {start : 22, len : 1, def : ' ' },
641 REC : {start : 22, len : 1, def : ' ' },
642 COM : {start : 22, len : 1, def : ' ' },
645 BKS : {start : 5, len : 1, def : ' ' },
646 SER : {start : 5, len : 1, def : ' ' },
647 VIS : {start : 5, len : 1, def : ' ' },
648 SCO : {start : 5, len : 1, def : ' ' },
649 REC : {start : 5, len : 1, def : ' ' },
650 COM : {start : 5, len : 1, def : ' ' },
655 BKS : {start : 23, len : 1, def : ' ' },
656 SER : {start : 23, len : 1, def : ' ' },
657 VIS : {start : 29, len : 1, def : ' ' },
658 MIX : {start : 23, len : 1, def : ' ' },
659 MAP : {start : 29, len : 1, def : ' ' },
660 SCO : {start : 23, len : 1, def : ' ' },
661 REC : {start : 23, len : 1, def : ' ' },
664 BKS : {start : 6, len : 1, def : ' ' },
665 SER : {start : 6, len : 1, def : ' ' },
666 VIS : {start : 12, len : 1, def : ' ' },
667 MIX : {start : 6, len : 1, def : ' ' },
668 MAP : {start : 12, len : 1, def : ' ' },
669 SCO : {start : 6, len : 1, def : ' ' },
670 REC : {start : 6, len : 1, def : ' ' },
675 SER : {start : 34, len : 1, def : '0' },
678 SER : {start : 17, len : 1, def : '0' },
683 SER : {start : 33, len : 1, def : ' ' },
686 SER : {start : 16, len : 1, def : ' ' },
691 function recordType (rec) {
693 var _l = rec.leader.toString();
695 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
696 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
698 for (var t in rec_type) {
699 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
700 document.getElementById('recordTypeLabel').value = t;
706 alert('FIXME, MARC Editor, recordType: ' + E);
710 function toggleFFE () {
711 var grid = document.getElementById('leaderGrid');
720 function changeFFEditor (type) {
721 var grid = document.getElementById('leaderGrid');
722 grid.setAttribute('type',type);
725 function fillFixedFields (rec) {
727 var grid = document.getElementById('leaderGrid');
729 var rtype = _record_type;
731 var _l = rec.leader.toString();
732 var _6 = rec.controlfield.(@tag=='006').toString();
733 var _7 = rec.controlfield.(@tag=='007').toString();
734 var _8 = rec.controlfield.(@tag=='008').toString();
737 var pre_list = grid.getElementsByTagName('label');
738 for (var i in pre_list) {
739 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
740 list.push( pre_list[i] );
744 for (var i in list) {
745 var name = list[i].getAttribute('name');
751 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
752 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
754 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
755 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
757 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
758 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
760 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
761 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
766 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
767 d = ff_pos[name].ldr[rtype].def;
771 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
772 d = ff_pos[name]._8[rtype].def;
776 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
777 d = ff_pos[name]._6[rtype].def;
781 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
782 d = ff_pos[name]._7[rtype].def;
787 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
793 list[i].nextSibling.value = value;
798 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
802 function updateFixedFields (element) {
803 var grid = document.getElementById('leaderGrid');
804 var recGrid = document.getElementById('recGrid');
806 var rtype = _record_type;
807 var new_value = element.value;
810 ldr : _record.leader,
811 _6 : _record.controlfield.(@tag=='006'),
812 _7 : _record.controlfield.(@tag=='007'),
813 _8 : _record.controlfield.(@tag=='008'),
816 var name = element.getAttribute('name');
817 for (var i in ff_pos[name]) {
819 if (!ff_pos[name][i][rtype]) continue;
820 if (!parts[i]) continue;
822 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
823 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
825 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
826 new_value += ff_pos[name][i][rtype].def;
829 parts[i].setChildren( before + new_value + after );
830 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
836 function marcLeader (leader) {
838 { class : 'marcLeaderRow',
843 tooltiptext : "MARC Leader" } ),
846 class : 'marcInd1' } ),
849 class : 'marcInd2' } ),
851 { value : leader.text(),
852 class : 'marcLeader' } )
858 function marcControlfield (field) {
859 tagname = field.@tag.toString().substr(2);
861 if (tagname == '6' || tagname == '7' || tagname == '8') {
863 { class : 'marcControlfieldRow',
864 tag : '_' + tagname },
866 { value : field.@tag,
868 context : 'tags_popup',
869 onmouseover : 'getTooltip(this, "tag");',
870 tooltipid : 'tag' + field.@tag } ),
872 { value : field.@ind1,
874 onmouseover : 'getTooltip(this, "ind1");',
875 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
877 { value : field.@ind2,
879 onmouseover : 'getTooltip(this, "ind2");',
880 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
883 { value : field.text(),
884 class : 'plain marcEditableControlfield',
885 name : 'CONTROL' + tagname,
886 oncontext : 'return false();',
892 { class : 'marcControlfieldRow',
893 tag : '_' + tagname },
895 { value : field.@tag,
897 onmouseover : 'getTooltip(this, "tag");',
898 tooltipid : 'tag' + field.@tag } ),
900 { value : field.@ind1,
902 onmouseover : 'getTooltip(this, "ind1");',
903 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
905 { value : field.@ind2,
907 onmouseover : 'getTooltip(this, "ind2");',
908 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
910 { value : field.text(),
911 class : 'marcControlfield' } )
918 function stackSubfields(checkbox) {
919 var list = document.getElementsByAttribute('name','sf_box');
922 if (checkbox.checked) o = 'horizontal';
924 for (var i = 0; i < list.length; i++) {
925 if (list[i]) list[i].setAttribute('orient',o);
929 function marcDatafield (field) {
931 { class : 'marcDatafieldRow' },
934 { value : field.@tag,
935 class : 'plain marcTag',
937 context : 'tags_popup',
938 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
941 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
944 { value : field.@ind1,
945 class : 'plain marcInd1',
947 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
950 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
951 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
954 { value : field.@ind2,
955 class : 'plain marcInd2',
957 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
960 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
961 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
962 createHbox({ name : 'sf_box' })
965 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
966 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
967 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
969 var sf_box = row.lastChild;
970 if (document.getElementById('stackSubfields').checked)
971 sf_box.setAttribute('orient','vertical');
973 sf_box.addEventListener(
976 if (sf_box === e.target) {
977 sf_box.lastChild.lastChild.focus();
978 } else if (e.target.parentNode === sf_box) {
979 e.target.lastChild.focus();
986 for (var i in field.subfield) {
987 var sf = field.subfield[i];
992 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
993 current_focus = sf_box.lastChild.childNodes[1];
999 function marcSubfield (sf) {
1001 { class : 'marcSubfieldBox' },
1004 class : 'plain marcSubfieldDelimiter',
1005 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1006 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1007 //onclick : 'this.nextSibling.focus();',
1008 onfocus : 'this.nextSibling.focus();',
1013 class : 'plain marcSubfieldCode',
1014 name : 'marcSubfieldCode',
1015 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1016 oncontextmenu : 'getContextMenu(this, "subfield");',
1017 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1022 { value : sf.text(),
1023 name : sf.parent().@tag + ':' + sf.@code,
1024 class : 'plain marcSubfield',
1025 onmouseover : 'getTooltip(this, "subfield");',
1026 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1027 size : new String(sf.text()).length + 2,
1028 oninput : "this.setAttribute('size', this.value.length + 2);",
1033 function loadRecord(rec) {
1036 var grid_rows = document.getElementById('recGrid').lastChild;
1038 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1040 grid_rows.appendChild( marcLeader( rec.leader ) );
1042 for (var i in rec.controlfield) {
1043 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1046 for (var i in rec.datafield) {
1047 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1050 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1051 changeFFEditor(recordType(rec));
1052 fillFixedFields(rec);
1054 alert('FIXME, MARC Editor, loadRecord: ' + E);
1058 var context_menus = createComplexXULElement('popupset');
1059 document.documentElement.appendChild( context_menus );
1061 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
1062 context_menus.appendChild( tag_menu );
1064 tag_menu.appendChild(
1066 { label : 'Add Row',
1068 'var e = document.createEvent("KeyEvents");' +
1069 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
1070 'current_focus.inputField.dispatchEvent(e);',
1075 tag_menu.appendChild(
1077 { label : 'Remove Row',
1079 'var e = document.createEvent("KeyEvents");' +
1080 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
1081 'current_focus.inputField.dispatchEvent(e);',
1086 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1088 tag_menu.appendChild(
1090 { label : 'Add/Replace 006',
1092 'var e = document.createEvent("KeyEvents");' +
1093 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
1094 'current_focus.inputField.dispatchEvent(e);',
1099 tag_menu.appendChild(
1101 { label : 'Add/Replace 007',
1103 'var e = document.createEvent("KeyEvents");' +
1104 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
1105 'current_focus.inputField.dispatchEvent(e);',
1110 tag_menu.appendChild(
1112 { label : 'Add/Replace 008',
1114 'var e = document.createEvent("KeyEvents");' +
1115 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
1116 'current_focus.inputField.dispatchEvent(e);',
1121 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1125 function genToolTips () {
1126 for (var i in bib_data.field) {
1127 var f = bib_data.field[i];
1129 tag_menu.appendChild(
1133 'current_focus.value = "' + f.@tag + '";' +
1134 'var e = document.createEvent("MutationEvents");' +
1135 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1136 'current_focus.inputField.dispatchEvent(e);',
1137 disabled : f.@tag < '010' ? "true" : "false",
1138 tooltiptext : f.description }
1142 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1143 context_menus.appendChild( i1_popup );
1145 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1146 context_menus.appendChild( i2_popup );
1148 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1149 context_menus.appendChild( sf_popup );
1151 tooltip_hash['tag' + f.@tag] = f.description;
1152 for (var j in f.indicator) {
1153 var ind = f.indicator[j];
1154 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1156 if (ind.@position == 1) {
1157 i1_popup.appendChild(
1159 { label : ind.@value,
1161 'current_focus.value = "' + ind.@value + '";' +
1162 'var e = document.createEvent("MutationEvents");' +
1163 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1164 'current_focus.inputField.dispatchEvent(e);',
1165 tooltiptext : ind.description }
1170 if (ind.@position == 2) {
1171 i2_popup.appendChild(
1173 { label : ind.@value,
1175 'current_focus.value = "' + ind.@value + '";' +
1176 'var e = document.createEvent("MutationEvents");' +
1177 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1178 'current_focus.inputField.dispatchEvent(e);',
1179 tooltiptext : ind.description }
1185 for (var j in f.subfield) {
1186 var sf = f.subfield[j];
1187 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1189 sf_popup.appendChild(
1193 'current_focus.value = "' + sf.@code + '";' +
1194 'var e = document.createEvent("MutationEvents");' +
1195 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1196 'current_focus.inputField.dispatchEvent(e);',
1197 tooltiptext : sf.description,
1205 var p = createComplexXULElement('popupset');
1206 document.documentElement.appendChild( p );
1208 function getTooltip (target, type) {
1211 if (type == 'subfield')
1212 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1215 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1218 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1221 tt = 'tag' + target.parentNode.firstChild.value;
1223 if (!document.getElementById( tt )) {
1228 orient : 'vertical',
1229 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1230 class : 'tooltip' },
1231 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1236 target.tooltip = tt;
1240 function getContextMenu (target, type) {
1243 if (type == 'subfield')
1244 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1247 tt = 't' + target.parentNode.firstChild.value + 'i1';
1250 tt = 't' + target.parentNode.firstChild.value + 'i2';
1252 target.setAttribute('context', tt);
1256 var authority_tag_map = {
1257 100 : ['[100,400,500,700]',100],
1258 400 : ['[100,400,500,700]',100],
1259 700 : ['[100,400,500,700]',100],
1260 800 : ['[100,400,500,700]',100],
1261 110 : ['[110,410,510,710]',110],
1262 410 : ['[110,410,510,710]',110],
1263 710 : ['[110,410,510,710]',110],
1264 810 : ['[110,410,510,710]',110],
1265 111 : ['[111,411,511,711]',111],
1266 411 : ['[111,411,511,711]',111],
1267 711 : ['[111,411,511,711]',111],
1268 811 : ['[111,411,511,711]',111],
1269 240 : ['[130,430,530,730]',130],
1270 440 : ['[130,430,530,730]',130],
1271 130 : ['[130,430,530,730]',130],
1272 730 : ['[130,430,530,730]',130],
1273 830 : ['[130,430,530,730]',130],
1274 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1275 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1276 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1277 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1280 function getAuthorityContextMenu (target, sf) {
1281 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1283 var old = document.getElementById( menu_id );
1284 if (old) old.parentNode.removeChild(old);
1286 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1287 context_menus.appendChild( sf_popup );
1289 if (!authority_tag_map[sf.parent().@tag]) {
1290 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1291 target.setAttribute('context', menu_id);
1295 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1297 var res = new XML( auth_data.responseText );
1301 var recs = res.gw::payload.gw::array.gw::string;
1302 for (var i in recs) {
1304 var xml = new XML(x.toString());
1305 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1307 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1310 for (var i in main) {
1311 if (main_text) main_text += ' / ';
1312 main_text += main[i];
1315 rec_list.push( [ main_text, xml ] );
1318 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1320 var main_text = rec_list[i][0];
1321 var xml = rec_list[i][1];
1322 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1324 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1326 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1327 grid.setAttribute('name','-none-');
1328 grid.setAttribute('style','overflow:scroll');
1331 var submenu = createMenu( { label : main_text } );
1333 var popup = createMenuPopup({ flex : "1" });
1334 submenu.appendChild(popup);
1336 var fields = xml.datafield;
1337 for (var j in fields) {
1339 var row = createRow(
1341 createLabel( { value : fields[j].@tag } ),
1342 createLabel( { value : fields[j].@ind1 } ),
1343 createLabel( { value : fields[j].@ind2 } )
1346 var sf_box = createHbox();
1348 var subfields = fields[j].subfield;
1349 for (var k in subfields) {
1352 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1353 subfield : subfields[k].@code,
1354 tag : subfields[k].parent().@tag,
1355 value : subfields[k]
1359 row.appendChild(sf_box);
1362 grid.lastChild.appendChild(row);
1365 grid.hidden = false;
1366 popup.appendChild( grid );
1370 { label : 'Apply Selected',
1371 command : function (event) {
1372 applyAuthority(event.target.previousSibling, target, sf);
1379 sf_popup.appendChild( submenu );
1382 if (sf_popup.childNodes.length == 0)
1383 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1385 target.setAttribute('context', menu_id);
1389 function applyAuthority ( target, ui_sf, e4x_sf ) {
1391 var new_vals = target.getElementsByAttribute('checked','true');
1392 var field = e4x_sf.parent();
1394 for (var i = 0; i < new_vals.length; i++) {
1396 var sf_list = field.subfield;
1397 for (var j in sf_list) {
1399 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1400 sf_list[j] = new_vals[i].getAttribute('value');
1401 new_vals[i].setAttribute('subfield','');
1407 for (var i = 0; i < new_vals.length; i++) {
1408 if (!new_vals[i].getAttribute('subfield')) continue;
1410 var val = new_vals[i].getAttribute('value');
1412 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1413 sf.@code = new_vals[i].getAttribute('subfield');
1415 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1418 var row = marcDatafield( field );
1421 while (node.nodeName != 'row') {
1422 node = node.parentNode;
1425 node.parentNode.replaceChild( row, node );
1431 'a' : { 100 : 'a' },
1432 'd' : { 100 : 'd' },
1435 'a' : { 110 : 'a' },
1436 'd' : { 110 : 'd' },
1439 'a' : { 111 : 'a' },
1440 'd' : { 111 : 'd' },
1443 'a' : { 130 : 'a' },
1444 'd' : { 130 : 'd' },
1447 'a' : { 130 : 'a' },
1448 'd' : { 130 : 'd' },
1451 'a' : { 100 : 'a' },
1452 'd' : { 100 : 'd' },
1455 'a' : { 110 : 'a' },
1456 'd' : { 110 : 'd' },
1459 'a' : { 111 : 'a' },
1460 'd' : { 111 : 'd' },
1463 'a' : { 130 : 'a' },
1464 'n' : { 130 : 'n' },
1465 'p' : { 130 : 'p' },
1468 'a' : { 100 : 'a' },
1469 'd' : { 100 : 'd' },
1472 'a' : { 110 : 'a' },
1473 'd' : { 110 : 'd' },
1476 'a' : { 111 : 'a' },
1477 'd' : { 111 : 'd' },
1480 'a' : { 130 : 'a' },
1481 'd' : { 130 : 'd' },
1484 'a' : { 100 : 'a' },
1485 'd' : { 100 : 'd' },
1488 'a' : { 110 : 'a' },
1489 'd' : { 110 : 'd' },
1492 'a' : { 111 : 'a' },
1493 'd' : { 111 : 'd' },
1496 'a' : { 130 : 'a' },
1497 'd' : { 130 : 'd' },
1500 'a' : { 100 : 'a' },
1501 'd' : { 100 : 'd' },
1502 't' : { 100 : 't' },
1529 'a' : { 150 : 'a' },
1530 'b' : { 150 : 'b' },
1557 'a' : { 151 : 'a' },
1584 'a' : { 155 : 'a' },
1612 function validateAuthority (button) {
1613 var grid = document.getElementById('recGrid');
1614 var label = button.getAttribute('label');
1617 var rows = grid.lastChild.childNodes;
1618 for (var i = 0; i < rows.length; i++) {
1620 var tag = row.firstChild;
1622 if (!control_map[tag.value]) continue
1624 var ind1 = tag.nextSibling;
1625 var ind2 = ind1.nextSibling;
1626 var subfields = ind2.nextSibling.childNodes;
1628 for (var j = 0; j < subfields.length; j++) {
1629 var sf = subfields[j];
1631 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1633 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1636 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1637 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1638 var res = new XML( x.responseText );
1640 if (res.gw::payload.gw::array.gw::string.length()) {
1647 sf.childNodes[2].inputField.style.color = 'red';
1649 sf.childNodes[2].inputField.style.color = 'black';
1654 button.setAttribute('label', label);
1660 function searchAuthority (term, tag, sf, limit) {
1661 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1662 url += '¶m="term"¶m="' + term + '"';
1663 url += '¶m="limit"¶m=' + limit;
1664 url += '¶m="tag"¶m=' + tag;
1665 url += '¶m="subfield"¶m="' + sf + '"';
1668 var req = new XMLHttpRequest();
1669 req.open('GET',url,false);