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 );
68 // Fake xulG for standalone...
73 window.xulG.record = {};
74 window.xulG.save = {};
76 window.xulG.save.label = 'Save Record';
77 window.xulG.save.func = function (r) { alert(r); }
80 var _rid = cgi.param('record');
82 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
87 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
88 document.getElementById('save-button').setAttribute('oncommand',
90 'var xml_string = xml_record.toXMLString(); ' +
91 'xml_string = xml_string.replace( ' +
92 ' /([\\\\u0080-\\\\ufffe])/g, ' +
93 ' function (r,s) { return s.charCodeAt(0).toString(16) } ' +
95 'window.xulG.save.func( xml_record ); ' +
96 'loadRecord(xml_record);'
99 if (window.xulG.record.url) {
100 var req = new XMLHttpRequest();
101 req.open('GET',window.xulG.record.url,false);
103 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
106 xml_record = new XML( window.xulG.record.marc );
107 if (xml_record..record[0]) xml_record = xml_record..record[0];
109 // Get the tooltip xml all async like
110 req = new XMLHttpRequest();
111 req.open('GET','marcedit-tooltips.xml',true);
112 req.onreadystatechange = function () {
113 if (req.readyState == 4) {
114 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
120 loadRecord(xml_record);
122 alert('FIXME, MARC Editor, my_init: ' + E);
127 function createComplexHTMLElement (e, attrs, objects, text) {
128 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
131 for (var i in attrs) l.setAttribute(i,attrs[i]);
135 for ( var i in objects ) l.appendChild( objects[i] );
139 l.appendChild( document.createTextNode(text) )
145 function createComplexXULElement (e, attrs, objects) {
146 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
149 for (var i in attrs) {
150 if (typeof attrs[i] == 'function') {
151 l.addEventListener( i, attrs[i], true );
153 l.setAttribute(i,attrs[i]);
159 for ( var i in objects ) l.appendChild( objects[i] );
165 function createDescription (attrs) {
166 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
169 function createTooltip (attrs) {
170 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
173 function createLabel (attrs) {
174 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
177 function createVbox (attrs) {
178 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
181 function createHbox (attrs) {
182 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
185 function createRow (attrs) {
186 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
189 function createTextbox (attrs) {
190 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
193 function createMenu (attrs) {
194 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
197 function createMenuPopup (attrs) {
198 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
201 function createPopup (attrs) {
202 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
205 function createMenuitem (attrs) {
206 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
209 function createCheckbox (attrs) {
210 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
213 function createMARCTextbox (element,attrs) {
215 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
216 box.onkeypress = function (event) {
219 while(node = node.parent()) {
223 var row = event.target;
224 while (row.tagName != 'row') row = row.parentNode;
226 if (element.nodeKind() == 'attribute') element[0]=box.value;
227 else element.setChildren( box.value );
229 if (element.localName() != 'controlfield') {
230 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
232 var index_sf, target, move_data;
233 if (element.localName() == 'subfield') {
235 target = event.target.parentNode;
237 var start = event.target.selectionStart;
238 var end = event.target.selectionEnd - event.target.selectionStart ?
239 event.target.selectionEnd :
240 event.target.value.length;
242 move_data = event.target.value.substring(start,end);
243 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
244 event.target.setAttribute('size', event.target.value.length + 2);
246 element.setChildren( event.target.value );
248 } else if (element.localName() == 'code') {
249 index_sf = element.parent();
250 target = event.target.parentNode;
251 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
252 index_sf = element.parent().children()[element.parent().children().length() - 1];
253 target = event.target.parentNode.lastChild.lastChild;
256 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
258 index_sf.parent().insertChildAfter( index_sf, sf );
260 var new_sf = marcSubfield(sf);
262 if (target === target.parentNode.lastChild) {
263 target.parentNode.appendChild( new_sf );
265 target.parentNode.insertBefore( new_sf, target.nextSibling );
268 new_sf.firstChild.nextSibling.focus();
270 event.preventDefault();
273 } else if (event.keyCode == 13 || event.keyCode == 77) {
274 if (event.ctrlKey) { // ctrl+enter
277 if (element.localName() == 'subfield') index = element.parent();
278 if (element.localName() == 'code') index = element.parent().parent();
279 if (element.localName() == 'tag') index = element.parent();
280 if (element.localName() == 'ind1') index = element.parent();
281 if (element.localName() == 'ind2') index = element.parent();
283 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
285 index.parent().insertChildAfter( index, df );
287 var new_df = marcDatafield(df);
289 if (row.parentNode.lastChild === row) {
290 row.parentNode.appendChild( new_df );
292 row.parentNode.insertBefore( new_df, row.nextSibling );
295 new_df.firstChild.focus();
297 event.preventDefault();
300 } else if (event.shiftKey) {
301 if (row.previousSibling.className.match('marcDatafieldRow'))
302 row.previousSibling.firstChild.focus();
304 row.nextSibling.firstChild.focus();
307 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
310 if (element.localName() == 'subfield') index = element.parent();
311 if (element.localName() == 'code') index = element.parent().parent();
312 if (element.localName() == 'tag') index = element.parent();
313 if (element.localName() == 'ind1') index = element.parent();
314 if (element.localName() == 'ind2') index = element.parent();
316 for (var i in index.parent().children()) {
317 if (index === index.parent().children()[i]) {
318 delete index.parent().children()[i];
323 row.previousSibling.firstChild.focus();
324 row.parentNode.removeChild(row);
326 event.preventDefault();
329 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
332 if (element.localName() == 'subfield') index = element;
333 if (element.localName() == 'code') index = element.parent();
336 for (var i in index.parent().children()) {
337 if (index === index.parent().children()[i]) {
338 delete index.parent().children()[i];
343 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
344 event.target.parentNode.previousSibling.lastChild.focus();
346 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
349 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
351 event.preventDefault();
354 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
355 createControlField('006','');
356 loadRecord(xml_record);
357 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
358 createControlField('007','');
359 loadRecord(xml_record);
360 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
361 createControlField('008','');
362 loadRecord(xml_record);
368 box.addEventListener(
371 if (element.nodeKind() == 'attribute') element[0]=box.value;
372 else element.setChildren( box.value );
378 box.addEventListener(
381 if (element.nodeKind() == 'attribute') element[0]=box.value;
382 else element.setChildren( box.value );
388 box.addEventListener(
391 if (element.nodeKind() == 'attribute') element[0]=box.value;
392 else element.setChildren( box.value );
398 box.addEventListener(
401 if (element.localName() == 'controlfield')
402 eval('fillFixedFields(xml_record);');
411 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
412 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
413 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
414 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
415 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
416 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
417 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
418 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
424 BKS : {start : 15, len : 3, def : ' ' },
425 SER : {start : 15, len : 3, def : ' ' },
426 VIS : {start : 15, len : 3, def : ' ' },
427 MIX : {start : 15, len : 3, def : ' ' },
428 MAP : {start : 15, len : 3, def : ' ' },
429 SCO : {start : 15, len : 3, def : ' ' },
430 REC : {start : 15, len : 3, def : ' ' },
431 COM : {start : 15, len : 3, def : ' ' },
436 BKS : {start : 35, len : 3, def : ' ' },
437 SER : {start : 35, len : 3, def : ' ' },
438 VIS : {start : 35, len : 3, def : ' ' },
439 MIX : {start : 35, len : 3, def : ' ' },
440 MAP : {start : 35, len : 3, def : ' ' },
441 SCO : {start : 35, len : 3, def : ' ' },
442 REC : {start : 35, len : 3, def : ' ' },
443 COM : {start : 35, len : 3, def : ' ' },
448 BKS : {start : 38, len : 1, def : ' ' },
449 SER : {start : 38, len : 1, def : ' ' },
450 VIS : {start : 38, len : 1, def : ' ' },
451 MIX : {start : 38, len : 1, def : ' ' },
452 MAP : {start : 38, len : 1, def : ' ' },
453 SCO : {start : 38, len : 1, def : ' ' },
454 REC : {start : 38, len : 1, def : ' ' },
455 COM : {start : 38, len : 1, def : ' ' },
460 BKS : {start : 6, len : 1, def : ' ' },
461 SER : {start : 6, len : 1, def : 'c' },
462 VIS : {start : 6, len : 1, def : ' ' },
463 MIX : {start : 6, len : 1, def : ' ' },
464 MAP : {start : 6, len : 1, def : ' ' },
465 SCO : {start : 6, len : 1, def : ' ' },
466 REC : {start : 6, len : 1, def : ' ' },
467 COM : {start : 6, len : 1, def : ' ' },
472 BKS : {start : 6, len : 1, def : 'a' },
473 SER : {start : 6, len : 1, def : 'a' },
474 VIS : {start : 6, len : 1, def : 'g' },
475 MIX : {start : 6, len : 1, def : 'p' },
476 MAP : {start : 6, len : 1, def : 'e' },
477 SCO : {start : 6, len : 1, def : 'c' },
478 REC : {start : 6, len : 1, def : 'i' },
479 COM : {start : 6, len : 1, def : 'm' },
484 BKS : {start : 8, len : 1, def : ' ' },
485 SER : {start : 8, len : 1, def : ' ' },
486 VIS : {start : 8, len : 1, def : ' ' },
487 MIX : {start : 8, len : 1, def : ' ' },
488 MAP : {start : 8, len : 1, def : ' ' },
489 SCO : {start : 8, len : 1, def : ' ' },
490 REC : {start : 8, len : 1, def : ' ' },
491 COM : {start : 8, len : 1, def : ' ' },
496 BKS : {start : 7, len : 1, def : 'm' },
497 SER : {start : 7, len : 1, def : 's' },
498 VIS : {start : 7, len : 1, def : 'm' },
499 MIX : {start : 7, len : 1, def : 'c' },
500 MAP : {start : 7, len : 1, def : 'm' },
501 SCO : {start : 7, len : 1, def : 'm' },
502 REC : {start : 7, len : 1, def : 'm' },
503 COM : {start : 7, len : 1, def : 'm' },
508 BKS : {start : 18, len : 1, def : ' ' },
509 SER : {start : 18, len : 1, def : ' ' },
510 VIS : {start : 18, len : 1, def : ' ' },
511 MIX : {start : 18, len : 1, def : ' ' },
512 MAP : {start : 18, len : 1, def : ' ' },
513 SCO : {start : 18, len : 1, def : ' ' },
514 REC : {start : 18, len : 1, def : ' ' },
515 COM : {start : 18, len : 1, def : ' ' },
520 BKS : {start : 17, len : 1, def : ' ' },
521 SER : {start : 17, len : 1, def : ' ' },
522 VIS : {start : 17, len : 1, def : ' ' },
523 MIX : {start : 17, len : 1, def : ' ' },
524 MAP : {start : 17, len : 1, def : ' ' },
525 SCO : {start : 17, len : 1, def : ' ' },
526 REC : {start : 17, len : 1, def : ' ' },
527 COM : {start : 17, len : 1, def : ' ' },
532 BKS : {start : 31, len : 1, def : '0' },
533 MAP : {start : 31, len : 1, def : '0' },
536 BKS : {start : 14, len : 1, def : '0' },
537 MAP : {start : 14, len : 1, def : '0' },
542 BKS : {start : 7, len : 4, def : ' ' },
543 SER : {start : 7, len : 4, def : ' ' },
544 VIS : {start : 7, len : 4, def : ' ' },
545 MIX : {start : 7, len : 4, def : ' ' },
546 MAP : {start : 7, len : 4, def : ' ' },
547 SCO : {start : 7, len : 4, def : ' ' },
548 REC : {start : 7, len : 4, def : ' ' },
549 COM : {start : 7, len : 4, def : ' ' },
554 BKS : {start : 11, len : 4, def : ' ' },
555 SER : {start : 11, len : 4, def : '9' },
556 VIS : {start : 11, len : 4, def : ' ' },
557 MIX : {start : 11, len : 4, def : ' ' },
558 MAP : {start : 11, len : 4, def : ' ' },
559 SCO : {start : 11, len : 4, def : ' ' },
560 REC : {start : 11, len : 4, def : ' ' },
561 COM : {start : 11, len : 4, def : ' ' },
566 BKS : {start : 33, len : 1, def : '0' },
569 BKS : {start : 16, len : 1, def : '0' },
574 BKS : {start : 34, len : 1, def : ' ' },
577 BKS : {start : 17, len : 1, def : ' ' },
582 BKS : {start : 18, len : 4, def : ' ' },
585 BKS : {start : 1, len : 4, def : ' ' },
590 BKS : {start : 30, len : 1, def : '0' },
593 BKS : {start : 13, len : 1, def : '0' },
598 BKS : {start : 29, len : 1, def : '0' },
599 SER : {start : 29, len : 1, def : '0' },
602 BKS : {start : 12, len : 1, def : '0' },
603 SER : {start : 12, len : 1, def : '0' },
608 BKS : {start : 24, len : 4, def : ' ' },
609 SER : {start : 25, len : 3, def : ' ' },
612 BKS : {start : 7, len : 4, def : ' ' },
613 SER : {start : 8, len : 3, def : ' ' },
618 BKS : {start : 28, len : 1, def : ' ' },
619 SER : {start : 28, len : 1, def : ' ' },
620 VIS : {start : 28, len : 1, def : ' ' },
621 MAP : {start : 28, len : 1, def : ' ' },
622 COM : {start : 28, len : 1, def : ' ' },
625 BKS : {start : 11, len : 1, def : ' ' },
626 SER : {start : 11, len : 1, def : ' ' },
627 VIS : {start : 11, len : 1, def : ' ' },
628 MAP : {start : 11, len : 1, def : ' ' },
629 COM : {start : 11, len : 1, def : ' ' },
634 BKS : {start : 22, len : 1, def : ' ' },
635 SER : {start : 22, len : 1, def : ' ' },
636 VIS : {start : 22, len : 1, def : ' ' },
637 SCO : {start : 22, len : 1, def : ' ' },
638 REC : {start : 22, len : 1, def : ' ' },
639 COM : {start : 22, len : 1, def : ' ' },
642 BKS : {start : 5, len : 1, def : ' ' },
643 SER : {start : 5, len : 1, def : ' ' },
644 VIS : {start : 5, len : 1, def : ' ' },
645 SCO : {start : 5, len : 1, def : ' ' },
646 REC : {start : 5, len : 1, def : ' ' },
647 COM : {start : 5, len : 1, def : ' ' },
652 BKS : {start : 23, len : 1, def : ' ' },
653 SER : {start : 23, len : 1, def : ' ' },
654 VIS : {start : 29, len : 1, def : ' ' },
655 MIX : {start : 23, len : 1, def : ' ' },
656 MAP : {start : 29, len : 1, def : ' ' },
657 SCO : {start : 23, len : 1, def : ' ' },
658 REC : {start : 23, len : 1, def : ' ' },
661 BKS : {start : 6, len : 1, def : ' ' },
662 SER : {start : 6, len : 1, def : ' ' },
663 VIS : {start : 12, len : 1, def : ' ' },
664 MIX : {start : 6, len : 1, def : ' ' },
665 MAP : {start : 12, len : 1, def : ' ' },
666 SCO : {start : 6, len : 1, def : ' ' },
667 REC : {start : 6, len : 1, def : ' ' },
672 SER : {start : 34, len : 1, def : '0' },
675 SER : {start : 17, len : 1, def : '0' },
680 SER : {start : 33, len : 1, def : ' ' },
683 SER : {start : 16, len : 1, def : ' ' },
688 function recordType (rec) {
690 var _l = rec.leader.toString();
692 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
693 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
695 for (var t in rec_type) {
696 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
697 document.getElementById('recordTypeLabel').value = t;
703 alert('FIXME, MARC Editor, recordType: ' + E);
707 function toggleFFE () {
708 var grid = document.getElementById('leaderGrid');
717 function changeFFEditor (type) {
718 var grid = document.getElementById('leaderGrid');
719 grid.setAttribute('type',type);
722 function fillFixedFields (rec) {
724 var grid = document.getElementById('leaderGrid');
726 var rtype = _record_type;
728 var _l = rec.leader.toString();
729 var _6 = rec.controlfield.(@tag=='006').toString();
730 var _7 = rec.controlfield.(@tag=='007').toString();
731 var _8 = rec.controlfield.(@tag=='008').toString();
734 var pre_list = grid.getElementsByTagName('label');
735 for (var i in pre_list) {
736 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
737 list.push( pre_list[i] );
741 for (var i in list) {
742 var name = list[i].getAttribute('name');
748 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
749 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
751 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
752 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
754 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
755 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
757 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
758 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
763 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
764 d = ff_pos[name].ldr[rtype].def;
768 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
769 d = ff_pos[name]._8[rtype].def;
773 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
774 d = ff_pos[name]._6[rtype].def;
778 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
779 d = ff_pos[name]._7[rtype].def;
784 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
790 list[i].nextSibling.value = value;
795 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
799 function updateFixedFields (element) {
800 var grid = document.getElementById('leaderGrid');
801 var recGrid = document.getElementById('recGrid');
803 var rtype = _record_type;
804 var new_value = element.value;
807 ldr : _record.leader,
808 _6 : _record.controlfield.(@tag=='006'),
809 _7 : _record.controlfield.(@tag=='007'),
810 _8 : _record.controlfield.(@tag=='008'),
813 var name = element.getAttribute('name');
814 for (var i in ff_pos[name]) {
816 if (!ff_pos[name][i][rtype]) continue;
817 if (!parts[i]) continue;
819 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
820 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
822 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
823 new_value += ff_pos[name][i][rtype].def;
826 parts[i].setChildren( before + new_value + after );
827 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
833 function marcLeader (leader) {
835 { class : 'marcLeaderRow',
840 tooltiptext : "MARC Leader" } ),
843 class : 'marcInd1' } ),
846 class : 'marcInd2' } ),
848 { value : leader.text(),
849 class : 'marcLeader' } )
855 function marcControlfield (field) {
856 tagname = field.@tag.toString().substr(2);
858 if (tagname == '6' || tagname == '7' || tagname == '8') {
860 { class : 'marcControlfieldRow',
861 tag : '_' + tagname },
863 { value : field.@tag,
865 context : 'tags_popup',
866 onmouseover : 'getTooltip(this, "tag");',
867 tooltipid : 'tag' + field.@tag } ),
869 { value : field.@ind1,
871 onmouseover : 'getTooltip(this, "ind1");',
872 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
874 { value : field.@ind2,
876 onmouseover : 'getTooltip(this, "ind2");',
877 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
880 { value : field.text(),
881 class : 'plain marcEditableControlfield',
882 name : 'CONTROL' + tagname,
883 oncontext : 'return false();',
889 { class : 'marcControlfieldRow',
890 tag : '_' + tagname },
892 { value : field.@tag,
894 onmouseover : 'getTooltip(this, "tag");',
895 tooltipid : 'tag' + field.@tag } ),
897 { value : field.@ind1,
899 onmouseover : 'getTooltip(this, "ind1");',
900 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
902 { value : field.@ind2,
904 onmouseover : 'getTooltip(this, "ind2");',
905 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
907 { value : field.text(),
908 class : 'marcControlfield' } )
915 function stackSubfields(checkbox) {
916 var list = document.getElementsByAttribute('name','sf_box');
919 if (checkbox.checked) o = 'horizontal';
921 for (var i = 0; i < list.length; i++) {
922 if (list[i]) list[i].setAttribute('orient',o);
926 function marcDatafield (field) {
928 { class : 'marcDatafieldRow' },
931 { value : field.@tag,
932 class : 'plain marcTag',
934 context : 'tags_popup',
935 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
938 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
941 { value : field.@ind1,
942 class : 'plain marcInd1',
944 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
947 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
948 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
951 { value : field.@ind2,
952 class : 'plain marcInd2',
954 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
957 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
958 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
959 createHbox({ name : 'sf_box' })
962 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
963 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
964 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
966 var sf_box = row.lastChild;
967 if (document.getElementById('stackSubfields').checked)
968 sf_box.setAttribute('orient','vertical');
970 sf_box.addEventListener(
973 if (sf_box === e.target) {
974 sf_box.lastChild.lastChild.focus();
975 } else if (e.target.parentNode === sf_box) {
976 e.target.lastChild.focus();
983 for (var i in field.subfield) {
984 var sf = field.subfield[i];
989 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
990 current_focus = sf_box.lastChild.childNodes[1];
996 function marcSubfield (sf) {
998 { class : 'marcSubfieldBox' },
1001 class : 'plain marcSubfieldDelimiter',
1002 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1003 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1004 //onclick : 'this.nextSibling.focus();',
1005 onfocus : 'this.nextSibling.focus();',
1010 class : 'plain marcSubfieldCode',
1011 name : 'marcSubfieldCode',
1012 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1013 oncontextmenu : 'getContextMenu(this, "subfield");',
1014 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1019 { value : sf.text(),
1020 name : sf.parent().@tag + ':' + sf.@code,
1021 class : 'plain marcSubfield',
1022 onmouseover : 'getTooltip(this, "subfield");',
1023 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1024 size : new String(sf.text()).length + 2,
1025 oninput : "this.setAttribute('size', this.value.length + 2);",
1030 function loadRecord(rec) {
1033 var grid_rows = document.getElementById('recGrid').lastChild;
1035 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1037 grid_rows.appendChild( marcLeader( rec.leader ) );
1039 for (var i in rec.controlfield) {
1040 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1043 for (var i in rec.datafield) {
1044 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1047 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1048 changeFFEditor(recordType(rec));
1049 fillFixedFields(rec);
1051 alert('FIXME, MARC Editor, loadRecord: ' + E);
1055 var context_menus = createComplexXULElement('popupset');
1056 document.documentElement.appendChild( context_menus );
1058 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
1059 context_menus.appendChild( tag_menu );
1061 tag_menu.appendChild(
1063 { label : 'Add Row',
1065 'var e = document.createEvent("KeyEvents");' +
1066 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
1067 'current_focus.inputField.dispatchEvent(e);',
1072 tag_menu.appendChild(
1074 { label : 'Remove Row',
1076 'var e = document.createEvent("KeyEvents");' +
1077 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
1078 'current_focus.inputField.dispatchEvent(e);',
1083 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1085 tag_menu.appendChild(
1087 { label : 'Add/Replace 006',
1089 'var e = document.createEvent("KeyEvents");' +
1090 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
1091 'current_focus.inputField.dispatchEvent(e);',
1096 tag_menu.appendChild(
1098 { label : 'Add/Replace 007',
1100 'var e = document.createEvent("KeyEvents");' +
1101 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
1102 'current_focus.inputField.dispatchEvent(e);',
1107 tag_menu.appendChild(
1109 { label : 'Add/Replace 008',
1111 'var e = document.createEvent("KeyEvents");' +
1112 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
1113 'current_focus.inputField.dispatchEvent(e);',
1118 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1122 function genToolTips () {
1123 for (var i in bib_data.field) {
1124 var f = bib_data.field[i];
1126 tag_menu.appendChild(
1130 'current_focus.value = "' + f.@tag + '";' +
1131 'var e = document.createEvent("MutationEvents");' +
1132 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1133 'current_focus.inputField.dispatchEvent(e);',
1134 disabled : f.@tag < '010' ? "true" : "false",
1135 tooltiptext : f.description }
1139 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1140 context_menus.appendChild( i1_popup );
1142 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1143 context_menus.appendChild( i2_popup );
1145 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1146 context_menus.appendChild( sf_popup );
1148 tooltip_hash['tag' + f.@tag] = f.description;
1149 for (var j in f.indicator) {
1150 var ind = f.indicator[j];
1151 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1153 if (ind.@position == 1) {
1154 i1_popup.appendChild(
1156 { label : ind.@value,
1158 'current_focus.value = "' + ind.@value + '";' +
1159 'var e = document.createEvent("MutationEvents");' +
1160 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1161 'current_focus.inputField.dispatchEvent(e);',
1162 tooltiptext : ind.description }
1167 if (ind.@position == 2) {
1168 i2_popup.appendChild(
1170 { label : ind.@value,
1172 'current_focus.value = "' + ind.@value + '";' +
1173 'var e = document.createEvent("MutationEvents");' +
1174 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1175 'current_focus.inputField.dispatchEvent(e);',
1176 tooltiptext : ind.description }
1182 for (var j in f.subfield) {
1183 var sf = f.subfield[j];
1184 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1186 sf_popup.appendChild(
1190 'current_focus.value = "' + sf.@code + '";' +
1191 'var e = document.createEvent("MutationEvents");' +
1192 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1193 'current_focus.inputField.dispatchEvent(e);',
1194 tooltiptext : sf.description,
1202 var p = createComplexXULElement('popupset');
1203 document.documentElement.appendChild( p );
1205 function getTooltip (target, type) {
1208 if (type == 'subfield')
1209 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1212 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1215 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1218 tt = 'tag' + target.parentNode.firstChild.value;
1220 if (!document.getElementById( tt )) {
1225 orient : 'vertical',
1226 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1227 class : 'tooltip' },
1228 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1233 target.tooltip = tt;
1237 function getContextMenu (target, type) {
1240 if (type == 'subfield')
1241 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1244 tt = 't' + target.parentNode.firstChild.value + 'i1';
1247 tt = 't' + target.parentNode.firstChild.value + 'i2';
1249 target.setAttribute('context', tt);
1253 var authority_tag_map = {
1254 100 : ['[100,400,500,700]',100],
1255 400 : ['[100,400,500,700]',100],
1256 700 : ['[100,400,500,700]',100],
1257 800 : ['[100,400,500,700]',100],
1258 110 : ['[110,410,510,710]',110],
1259 410 : ['[110,410,510,710]',110],
1260 710 : ['[110,410,510,710]',110],
1261 810 : ['[110,410,510,710]',110],
1262 111 : ['[111,411,511,711]',111],
1263 411 : ['[111,411,511,711]',111],
1264 711 : ['[111,411,511,711]',111],
1265 811 : ['[111,411,511,711]',111],
1266 240 : ['[130,430,530,730]',130],
1267 440 : ['[130,430,530,730]',130],
1268 130 : ['[130,430,530,730]',130],
1269 730 : ['[130,430,530,730]',130],
1270 830 : ['[130,430,530,730]',130],
1271 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1272 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1273 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1274 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1277 function getAuthorityContextMenu (target, sf) {
1278 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1280 var old = document.getElementById( menu_id );
1281 if (old) old.parentNode.removeChild(old);
1283 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1284 context_menus.appendChild( sf_popup );
1286 if (!authority_tag_map[sf.parent().@tag]) {
1287 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1288 target.setAttribute('context', menu_id);
1292 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1294 var res = new XML( auth_data.responseText );
1298 var recs = res.gw::payload.gw::array.gw::string;
1299 for (var i in recs) {
1301 var xml = new XML(x.toString());
1302 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1304 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1307 for (var i in main) {
1308 if (main_text) main_text += ' / ';
1309 main_text += main[i];
1312 rec_list.push( [ main_text, xml ] );
1315 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1317 var main_text = rec_list[i][0];
1318 var xml = rec_list[i][1];
1319 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1321 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1323 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1324 grid.setAttribute('name','-none-');
1325 grid.setAttribute('style','overflow:scroll');
1328 var submenu = createMenu( { label : main_text } );
1330 var popup = createMenuPopup({ flex : "1" });
1331 submenu.appendChild(popup);
1333 var fields = xml.datafield;
1334 for (var j in fields) {
1336 var row = createRow(
1338 createLabel( { value : fields[j].@tag } ),
1339 createLabel( { value : fields[j].@ind1 } ),
1340 createLabel( { value : fields[j].@ind2 } )
1343 var sf_box = createHbox();
1345 var subfields = fields[j].subfield;
1346 for (var k in subfields) {
1349 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1350 subfield : subfields[k].@code,
1351 tag : subfields[k].parent().@tag,
1352 value : subfields[k]
1356 row.appendChild(sf_box);
1359 grid.lastChild.appendChild(row);
1362 grid.hidden = false;
1363 popup.appendChild( grid );
1367 { label : 'Apply Selected',
1368 command : function (event) {
1369 applyAuthority(event.target.previousSibling, target, sf);
1376 sf_popup.appendChild( submenu );
1379 if (sf_popup.childNodes.length == 0)
1380 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1382 target.setAttribute('context', menu_id);
1386 function applyAuthority ( target, ui_sf, e4x_sf ) {
1388 var new_vals = target.getElementsByAttribute('checked','true');
1389 var field = e4x_sf.parent();
1391 for (var i = 0; i < new_vals.length; i++) {
1393 var sf_list = field.subfield;
1394 for (var j in sf_list) {
1396 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1397 sf_list[j] = new_vals[i].getAttribute('value');
1398 new_vals[i].setAttribute('subfield','');
1404 for (var i = 0; i < new_vals.length; i++) {
1405 if (!new_vals[i].getAttribute('subfield')) continue;
1407 var val = new_vals[i].getAttribute('value');
1409 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1410 sf.@code = new_vals[i].getAttribute('subfield');
1412 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1415 var row = marcDatafield( field );
1418 while (node.nodeName != 'row') {
1419 node = node.parentNode;
1422 node.parentNode.replaceChild( row, node );
1428 'a' : { 100 : 'a' },
1429 'd' : { 100 : 'd' },
1432 'a' : { 110 : 'a' },
1433 'd' : { 110 : 'd' },
1436 'a' : { 111 : 'a' },
1437 'd' : { 111 : 'd' },
1440 'a' : { 130 : 'a' },
1441 'd' : { 130 : 'd' },
1444 'a' : { 130 : 'a' },
1445 'd' : { 130 : 'd' },
1448 'a' : { 100 : 'a' },
1449 'd' : { 100 : 'd' },
1452 'a' : { 110 : 'a' },
1453 'd' : { 110 : 'd' },
1456 'a' : { 111 : 'a' },
1457 'd' : { 111 : 'd' },
1460 'a' : { 130 : 'a' },
1461 'n' : { 130 : 'n' },
1462 'p' : { 130 : 'p' },
1465 'a' : { 100 : 'a' },
1466 'd' : { 100 : 'd' },
1469 'a' : { 110 : 'a' },
1470 'd' : { 110 : 'd' },
1473 'a' : { 111 : 'a' },
1474 'd' : { 111 : 'd' },
1477 'a' : { 130 : 'a' },
1478 'd' : { 130 : 'd' },
1481 'a' : { 100 : 'a' },
1482 'd' : { 100 : 'd' },
1485 'a' : { 110 : 'a' },
1486 'd' : { 110 : 'd' },
1489 'a' : { 111 : 'a' },
1490 'd' : { 111 : 'd' },
1493 'a' : { 130 : 'a' },
1494 'd' : { 130 : 'd' },
1497 'a' : { 100 : 'a' },
1498 'd' : { 100 : 'd' },
1499 't' : { 100 : 't' },
1526 'a' : { 150 : 'a' },
1527 'b' : { 150 : 'b' },
1554 'a' : { 151 : 'a' },
1581 'a' : { 155 : 'a' },
1609 function validateAuthority (button) {
1610 var grid = document.getElementById('recGrid');
1611 var label = button.getAttribute('label');
1614 var rows = grid.lastChild.childNodes;
1615 for (var i = 0; i < rows.length; i++) {
1617 var tag = row.firstChild;
1619 if (!control_map[tag.value]) continue
1621 var ind1 = tag.nextSibling;
1622 var ind2 = ind1.nextSibling;
1623 var subfields = ind2.nextSibling.childNodes;
1625 for (var j = 0; j < subfields.length; j++) {
1626 var sf = subfields[j];
1628 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1630 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1633 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1634 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1635 var res = new XML( x.responseText );
1637 if (res.gw::payload.gw::array.gw::string.length()) {
1644 sf.childNodes[2].inputField.style.color = 'red';
1646 sf.childNodes[2].inputField.style.color = 'black';
1651 button.setAttribute('label', label);
1657 function searchAuthority (term, tag, sf, limit) {
1658 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1659 url += '¶m="term"¶m="' + term + '"';
1660 url += '¶m="limit"¶m=' + limit;
1661 url += '¶m="tag"¶m=' + tag;
1662 url += '¶m="subfield"¶m="' + sf + '"';
1665 var req = new XMLHttpRequest();
1666 req.open('GET',url,false);