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', 'mangle_005(); window.xulG.save.func(xml_record.toXMLString()); loadRecord(xml_record);');
90 if (window.xulG.record.url) {
91 var req = new XMLHttpRequest();
92 req.open('GET',window.xulG.record.url,false);
94 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
97 xml_record = new XML( window.xulG.record.marc );
98 if (xml_record..record[0]) xml_record = xml_record..record[0];
100 // Get the tooltip xml all async like
101 req = new XMLHttpRequest();
102 req.open('GET','marcedit-tooltips.xml',true);
103 req.onreadystatechange = function () {
104 if (req.readyState == 4) {
105 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
111 loadRecord(xml_record);
113 alert('FIXME, MARC Editor, my_init: ' + E);
118 function createComplexHTMLElement (e, attrs, objects, text) {
119 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
122 for (var i in attrs) l.setAttribute(i,attrs[i]);
126 for ( var i in objects ) l.appendChild( objects[i] );
130 l.appendChild( document.createTextNode(text) )
136 function createComplexXULElement (e, attrs, objects) {
137 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
140 for (var i in attrs) {
141 if (typeof attrs[i] == 'function') {
142 l.addEventListener( i, attrs[i], true );
144 l.setAttribute(i,attrs[i]);
150 for ( var i in objects ) l.appendChild( objects[i] );
156 function createDescription (attrs) {
157 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
160 function createTooltip (attrs) {
161 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
164 function createLabel (attrs) {
165 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
168 function createVbox (attrs) {
169 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
172 function createHbox (attrs) {
173 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
176 function createRow (attrs) {
177 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
180 function createTextbox (attrs) {
181 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
184 function createMenu (attrs) {
185 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
188 function createMenuPopup (attrs) {
189 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
192 function createPopup (attrs) {
193 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
196 function createMenuitem (attrs) {
197 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
200 function createCheckbox (attrs) {
201 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
204 function createMARCTextbox (element,attrs) {
206 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
207 box.onkeypress = function (event) {
210 while(node = node.parent()) {
214 var row = event.target;
215 while (row.tagName != 'row') row = row.parentNode;
217 if (element.nodeKind() == 'attribute') element[0]=box.value;
218 else element.setChildren( box.value );
220 if (element.localName() != 'controlfield') {
221 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
223 var index_sf, target, move_data;
224 if (element.localName() == 'subfield') {
226 target = event.target.parentNode;
228 var start = event.target.selectionStart;
229 var end = event.target.selectionEnd - event.target.selectionStart ?
230 event.target.selectionEnd :
231 event.target.value.length;
233 move_data = event.target.value.substring(start,end);
234 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
235 event.target.setAttribute('size', event.target.value.length + 2);
237 element.setChildren( event.target.value );
239 } else if (element.localName() == 'code') {
240 index_sf = element.parent();
241 target = event.target.parentNode;
242 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
243 index_sf = element.parent().children()[element.parent().children().length() - 1];
244 target = event.target.parentNode.lastChild.lastChild;
247 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
249 index_sf.parent().insertChildAfter( index_sf, sf );
251 var new_sf = marcSubfield(sf);
253 if (target === target.parentNode.lastChild) {
254 target.parentNode.appendChild( new_sf );
256 target.parentNode.insertBefore( new_sf, target.nextSibling );
259 new_sf.firstChild.nextSibling.focus();
261 event.preventDefault();
264 } else if (event.keyCode == 13 || event.keyCode == 77) {
265 if (event.ctrlKey) { // ctrl+enter
268 if (element.localName() == 'subfield') index = element.parent();
269 if (element.localName() == 'code') index = element.parent().parent();
270 if (element.localName() == 'tag') index = element.parent();
271 if (element.localName() == 'ind1') index = element.parent();
272 if (element.localName() == 'ind2') index = element.parent();
274 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
276 index.parent().insertChildAfter( index, df );
278 var new_df = marcDatafield(df);
280 if (row.parentNode.lastChild === row) {
281 row.parentNode.appendChild( new_df );
283 row.parentNode.insertBefore( new_df, row.nextSibling );
286 new_df.firstChild.focus();
288 event.preventDefault();
291 } else if (event.shiftKey) {
292 if (row.previousSibling.className.match('marcDatafieldRow'))
293 row.previousSibling.firstChild.focus();
295 row.nextSibling.firstChild.focus();
298 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
301 if (element.localName() == 'subfield') index = element.parent();
302 if (element.localName() == 'code') index = element.parent().parent();
303 if (element.localName() == 'tag') index = element.parent();
304 if (element.localName() == 'ind1') index = element.parent();
305 if (element.localName() == 'ind2') index = element.parent();
307 for (var i in index.parent().children()) {
308 if (index === index.parent().children()[i]) {
309 delete index.parent().children()[i];
314 row.previousSibling.firstChild.focus();
315 row.parentNode.removeChild(row);
317 event.preventDefault();
320 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
323 if (element.localName() == 'subfield') index = element;
324 if (element.localName() == 'code') index = element.parent();
327 for (var i in index.parent().children()) {
328 if (index === index.parent().children()[i]) {
329 delete index.parent().children()[i];
334 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
335 event.target.parentNode.previousSibling.lastChild.focus();
337 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
340 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
342 event.preventDefault();
345 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
346 createControlField('006','');
347 loadRecord(xml_record);
348 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
349 createControlField('007','');
350 loadRecord(xml_record);
351 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
352 createControlField('008','');
353 loadRecord(xml_record);
359 box.addEventListener(
362 if (element.nodeKind() == 'attribute') element[0]=box.value;
363 else element.setChildren( box.value );
369 box.addEventListener(
372 if (element.nodeKind() == 'attribute') element[0]=box.value;
373 else element.setChildren( box.value );
379 box.addEventListener(
382 if (element.nodeKind() == 'attribute') element[0]=box.value;
383 else element.setChildren( box.value );
389 box.addEventListener(
392 if (element.localName() == 'controlfield')
393 eval('fillFixedFields(xml_record);');
402 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
403 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
404 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
405 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
406 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
407 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
408 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
409 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
415 BKS : {start : 15, len : 3, def : ' ' },
416 SER : {start : 15, len : 3, def : ' ' },
417 VIS : {start : 15, len : 3, def : ' ' },
418 MIX : {start : 15, len : 3, def : ' ' },
419 MAP : {start : 15, len : 3, def : ' ' },
420 SCO : {start : 15, len : 3, def : ' ' },
421 REC : {start : 15, len : 3, def : ' ' },
422 COM : {start : 15, len : 3, def : ' ' },
427 BKS : {start : 35, len : 3, def : ' ' },
428 SER : {start : 35, len : 3, def : ' ' },
429 VIS : {start : 35, len : 3, def : ' ' },
430 MIX : {start : 35, len : 3, def : ' ' },
431 MAP : {start : 35, len : 3, def : ' ' },
432 SCO : {start : 35, len : 3, def : ' ' },
433 REC : {start : 35, len : 3, def : ' ' },
434 COM : {start : 35, len : 3, def : ' ' },
439 BKS : {start : 38, len : 1, def : ' ' },
440 SER : {start : 38, len : 1, def : ' ' },
441 VIS : {start : 38, len : 1, def : ' ' },
442 MIX : {start : 38, len : 1, def : ' ' },
443 MAP : {start : 38, len : 1, def : ' ' },
444 SCO : {start : 38, len : 1, def : ' ' },
445 REC : {start : 38, len : 1, def : ' ' },
446 COM : {start : 38, len : 1, def : ' ' },
451 BKS : {start : 6, len : 1, def : ' ' },
452 SER : {start : 6, len : 1, def : 'c' },
453 VIS : {start : 6, len : 1, def : ' ' },
454 MIX : {start : 6, len : 1, def : ' ' },
455 MAP : {start : 6, len : 1, def : ' ' },
456 SCO : {start : 6, len : 1, def : ' ' },
457 REC : {start : 6, len : 1, def : ' ' },
458 COM : {start : 6, len : 1, def : ' ' },
463 BKS : {start : 6, len : 1, def : 'a' },
464 SER : {start : 6, len : 1, def : 'a' },
465 VIS : {start : 6, len : 1, def : 'g' },
466 MIX : {start : 6, len : 1, def : 'p' },
467 MAP : {start : 6, len : 1, def : 'e' },
468 SCO : {start : 6, len : 1, def : 'c' },
469 REC : {start : 6, len : 1, def : 'i' },
470 COM : {start : 6, len : 1, def : 'm' },
475 BKS : {start : 8, len : 1, def : ' ' },
476 SER : {start : 8, len : 1, def : ' ' },
477 VIS : {start : 8, len : 1, def : ' ' },
478 MIX : {start : 8, len : 1, def : ' ' },
479 MAP : {start : 8, len : 1, def : ' ' },
480 SCO : {start : 8, len : 1, def : ' ' },
481 REC : {start : 8, len : 1, def : ' ' },
482 COM : {start : 8, len : 1, def : ' ' },
487 BKS : {start : 7, len : 1, def : 'm' },
488 SER : {start : 7, len : 1, def : 's' },
489 VIS : {start : 7, len : 1, def : 'm' },
490 MIX : {start : 7, len : 1, def : 'c' },
491 MAP : {start : 7, len : 1, def : 'm' },
492 SCO : {start : 7, len : 1, def : 'm' },
493 REC : {start : 7, len : 1, def : 'm' },
494 COM : {start : 7, len : 1, def : 'm' },
499 BKS : {start : 18, len : 1, def : ' ' },
500 SER : {start : 18, len : 1, def : ' ' },
501 VIS : {start : 18, len : 1, def : ' ' },
502 MIX : {start : 18, len : 1, def : ' ' },
503 MAP : {start : 18, len : 1, def : ' ' },
504 SCO : {start : 18, len : 1, def : ' ' },
505 REC : {start : 18, len : 1, def : ' ' },
506 COM : {start : 18, len : 1, def : ' ' },
511 BKS : {start : 17, len : 1, def : ' ' },
512 SER : {start : 17, len : 1, def : ' ' },
513 VIS : {start : 17, len : 1, def : ' ' },
514 MIX : {start : 17, len : 1, def : ' ' },
515 MAP : {start : 17, len : 1, def : ' ' },
516 SCO : {start : 17, len : 1, def : ' ' },
517 REC : {start : 17, len : 1, def : ' ' },
518 COM : {start : 17, len : 1, def : ' ' },
523 BKS : {start : 31, len : 1, def : '0' },
524 MAP : {start : 31, len : 1, def : '0' },
527 BKS : {start : 14, len : 1, def : '0' },
528 MAP : {start : 14, len : 1, def : '0' },
533 BKS : {start : 7, len : 4, def : ' ' },
534 SER : {start : 7, len : 4, def : ' ' },
535 VIS : {start : 7, len : 4, def : ' ' },
536 MIX : {start : 7, len : 4, def : ' ' },
537 MAP : {start : 7, len : 4, def : ' ' },
538 SCO : {start : 7, len : 4, def : ' ' },
539 REC : {start : 7, len : 4, def : ' ' },
540 COM : {start : 7, len : 4, def : ' ' },
545 BKS : {start : 11, len : 4, def : ' ' },
546 SER : {start : 11, len : 4, def : '9' },
547 VIS : {start : 11, len : 4, def : ' ' },
548 MIX : {start : 11, len : 4, def : ' ' },
549 MAP : {start : 11, len : 4, def : ' ' },
550 SCO : {start : 11, len : 4, def : ' ' },
551 REC : {start : 11, len : 4, def : ' ' },
552 COM : {start : 11, len : 4, def : ' ' },
557 BKS : {start : 33, len : 1, def : '0' },
560 BKS : {start : 16, len : 1, def : '0' },
565 BKS : {start : 34, len : 1, def : ' ' },
568 BKS : {start : 17, len : 1, def : ' ' },
573 BKS : {start : 18, len : 4, def : ' ' },
576 BKS : {start : 1, len : 4, def : ' ' },
581 BKS : {start : 30, len : 1, def : '0' },
584 BKS : {start : 13, len : 1, def : '0' },
589 BKS : {start : 29, len : 1, def : '0' },
590 SER : {start : 29, len : 1, def : '0' },
593 BKS : {start : 12, len : 1, def : '0' },
594 SER : {start : 12, len : 1, def : '0' },
599 BKS : {start : 24, len : 4, def : ' ' },
600 SER : {start : 25, len : 3, def : ' ' },
603 BKS : {start : 7, len : 4, def : ' ' },
604 SER : {start : 8, len : 3, def : ' ' },
609 BKS : {start : 28, len : 1, def : ' ' },
610 SER : {start : 28, len : 1, def : ' ' },
611 VIS : {start : 28, len : 1, def : ' ' },
612 MAP : {start : 28, len : 1, def : ' ' },
613 COM : {start : 28, len : 1, def : ' ' },
616 BKS : {start : 11, len : 1, def : ' ' },
617 SER : {start : 11, len : 1, def : ' ' },
618 VIS : {start : 11, len : 1, def : ' ' },
619 MAP : {start : 11, len : 1, def : ' ' },
620 COM : {start : 11, len : 1, def : ' ' },
625 BKS : {start : 22, len : 1, def : ' ' },
626 SER : {start : 22, len : 1, def : ' ' },
627 VIS : {start : 22, len : 1, def : ' ' },
628 SCO : {start : 22, len : 1, def : ' ' },
629 REC : {start : 22, len : 1, def : ' ' },
630 COM : {start : 22, len : 1, def : ' ' },
633 BKS : {start : 5, len : 1, def : ' ' },
634 SER : {start : 5, len : 1, def : ' ' },
635 VIS : {start : 5, len : 1, def : ' ' },
636 SCO : {start : 5, len : 1, def : ' ' },
637 REC : {start : 5, len : 1, def : ' ' },
638 COM : {start : 5, len : 1, def : ' ' },
643 BKS : {start : 23, len : 1, def : ' ' },
644 SER : {start : 23, len : 1, def : ' ' },
645 VIS : {start : 29, len : 1, def : ' ' },
646 MIX : {start : 23, len : 1, def : ' ' },
647 MAP : {start : 29, len : 1, def : ' ' },
648 SCO : {start : 23, len : 1, def : ' ' },
649 REC : {start : 23, len : 1, def : ' ' },
652 BKS : {start : 6, len : 1, def : ' ' },
653 SER : {start : 6, len : 1, def : ' ' },
654 VIS : {start : 12, len : 1, def : ' ' },
655 MIX : {start : 6, len : 1, def : ' ' },
656 MAP : {start : 12, len : 1, def : ' ' },
657 SCO : {start : 6, len : 1, def : ' ' },
658 REC : {start : 6, len : 1, def : ' ' },
663 SER : {start : 34, len : 1, def : '0' },
666 SER : {start : 17, len : 1, def : '0' },
671 SER : {start : 33, len : 1, def : ' ' },
674 SER : {start : 16, len : 1, def : ' ' },
679 function recordType (rec) {
681 var _l = rec.leader.toString();
683 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
684 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
686 for (var t in rec_type) {
687 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
688 document.getElementById('recordTypeLabel').value = t;
694 alert('FIXME, MARC Editor, recordType: ' + E);
698 function toggleFFE () {
699 var grid = document.getElementById('leaderGrid');
708 function changeFFEditor (type) {
709 var grid = document.getElementById('leaderGrid');
710 grid.setAttribute('type',type);
713 function fillFixedFields (rec) {
715 var grid = document.getElementById('leaderGrid');
717 var rtype = _record_type;
719 var _l = rec.leader.toString();
720 var _6 = rec.controlfield.(@tag=='006').toString();
721 var _7 = rec.controlfield.(@tag=='007').toString();
722 var _8 = rec.controlfield.(@tag=='008').toString();
725 var pre_list = grid.getElementsByTagName('label');
726 for (var i in pre_list) {
727 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
728 list.push( pre_list[i] );
732 for (var i in list) {
733 var name = list[i].getAttribute('name');
739 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
740 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
742 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
743 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
745 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
746 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
748 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
749 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
754 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
755 d = ff_pos[name].ldr[rtype].def;
759 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
760 d = ff_pos[name]._8[rtype].def;
764 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
765 d = ff_pos[name]._6[rtype].def;
769 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
770 d = ff_pos[name]._7[rtype].def;
775 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
781 list[i].nextSibling.value = value;
786 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
790 function updateFixedFields (element) {
791 var grid = document.getElementById('leaderGrid');
792 var recGrid = document.getElementById('recGrid');
794 var rtype = _record_type;
795 var new_value = element.value;
798 ldr : _record.leader,
799 _6 : _record.controlfield.(@tag=='006'),
800 _7 : _record.controlfield.(@tag=='007'),
801 _8 : _record.controlfield.(@tag=='008'),
804 var name = element.getAttribute('name');
805 for (var i in ff_pos[name]) {
807 if (!ff_pos[name][i][rtype]) continue;
808 if (!parts[i]) continue;
810 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
811 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
813 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
814 new_value += ff_pos[name][i][rtype].def;
817 parts[i].setChildren( before + new_value + after );
818 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
824 function marcLeader (leader) {
826 { class : 'marcLeaderRow',
831 tooltiptext : "MARC Leader" } ),
834 class : 'marcInd1' } ),
837 class : 'marcInd2' } ),
839 { value : leader.text(),
840 class : 'marcLeader' } )
846 function marcControlfield (field) {
847 tagname = field.@tag.toString().substr(2);
849 if (tagname == '6' || tagname == '7' || tagname == '8') {
851 { class : 'marcControlfieldRow',
852 tag : '_' + tagname },
854 { value : field.@tag,
856 context : 'tags_popup',
857 onmouseover : 'getTooltip(this, "tag");',
858 tooltipid : 'tag' + field.@tag } ),
860 { value : field.@ind1,
862 onmouseover : 'getTooltip(this, "ind1");',
863 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
865 { value : field.@ind2,
867 onmouseover : 'getTooltip(this, "ind2");',
868 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
871 { value : field.text(),
872 class : 'plain marcEditableControlfield',
873 name : 'CONTROL' + tagname,
874 oncontext : 'return false();',
880 { class : 'marcControlfieldRow',
881 tag : '_' + tagname },
883 { value : field.@tag,
885 onmouseover : 'getTooltip(this, "tag");',
886 tooltipid : 'tag' + field.@tag } ),
888 { value : field.@ind1,
890 onmouseover : 'getTooltip(this, "ind1");',
891 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
893 { value : field.@ind2,
895 onmouseover : 'getTooltip(this, "ind2");',
896 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
898 { value : field.text(),
899 class : 'marcControlfield' } )
906 function stackSubfields(checkbox) {
907 var list = document.getElementsByAttribute('name','sf_box');
910 if (checkbox.checked) o = 'horizontal';
912 for (var i = 0; i < list.length; i++) {
913 if (list[i]) list[i].setAttribute('orient',o);
917 function marcDatafield (field) {
919 { class : 'marcDatafieldRow' },
922 { value : field.@tag,
923 class : 'plain marcTag',
925 context : 'tags_popup',
926 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
929 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
932 { value : field.@ind1,
933 class : 'plain marcInd1',
935 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
938 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
939 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
942 { value : field.@ind2,
943 class : 'plain marcInd2',
945 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
948 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
949 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
950 createHbox({ name : 'sf_box' })
953 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
954 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
955 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
957 var sf_box = row.lastChild;
958 if (document.getElementById('stackSubfields').checked)
959 sf_box.setAttribute('orient','vertical');
961 sf_box.addEventListener(
964 if (sf_box === e.target) {
965 sf_box.lastChild.lastChild.focus();
966 } else if (e.target.parentNode === sf_box) {
967 e.target.lastChild.focus();
974 for (var i in field.subfield) {
975 var sf = field.subfield[i];
980 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
981 current_focus = sf_box.lastChild.childNodes[1];
987 function marcSubfield (sf) {
989 { class : 'marcSubfieldBox' },
992 class : 'plain marcSubfieldDelimiter',
993 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
994 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
995 //onclick : 'this.nextSibling.focus();',
996 onfocus : 'this.nextSibling.focus();',
1001 class : 'plain marcSubfieldCode',
1002 name : 'marcSubfieldCode',
1003 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1004 oncontextmenu : 'getContextMenu(this, "subfield");',
1005 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1010 { value : sf.text(),
1011 name : sf.parent().@tag + ':' + sf.@code,
1012 class : 'plain marcSubfield',
1013 onmouseover : 'getTooltip(this, "subfield");',
1014 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1015 size : new String(sf.text()).length + 2,
1016 oninput : "this.setAttribute('size', this.value.length + 2);",
1021 function loadRecord(rec) {
1024 var grid_rows = document.getElementById('recGrid').lastChild;
1026 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1028 grid_rows.appendChild( marcLeader( rec.leader ) );
1030 for (var i in rec.controlfield) {
1031 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1034 for (var i in rec.datafield) {
1035 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1038 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1039 changeFFEditor(recordType(rec));
1040 fillFixedFields(rec);
1042 alert('FIXME, MARC Editor, loadRecord: ' + E);
1046 var context_menus = createComplexXULElement('popupset');
1047 document.documentElement.appendChild( context_menus );
1049 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
1050 context_menus.appendChild( tag_menu );
1052 tag_menu.appendChild(
1054 { label : 'Add Row',
1056 'var e = document.createEvent("KeyEvents");' +
1057 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
1058 'current_focus.inputField.dispatchEvent(e);',
1063 tag_menu.appendChild(
1065 { label : 'Remove Row',
1067 'var e = document.createEvent("KeyEvents");' +
1068 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
1069 'current_focus.inputField.dispatchEvent(e);',
1074 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1076 tag_menu.appendChild(
1078 { label : 'Add/Replace 006',
1080 'var e = document.createEvent("KeyEvents");' +
1081 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
1082 'current_focus.inputField.dispatchEvent(e);',
1087 tag_menu.appendChild(
1089 { label : 'Add/Replace 007',
1091 'var e = document.createEvent("KeyEvents");' +
1092 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
1093 'current_focus.inputField.dispatchEvent(e);',
1098 tag_menu.appendChild(
1100 { label : 'Add/Replace 008',
1102 'var e = document.createEvent("KeyEvents");' +
1103 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
1104 'current_focus.inputField.dispatchEvent(e);',
1109 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1113 function genToolTips () {
1114 for (var i in bib_data.field) {
1115 var f = bib_data.field[i];
1117 tag_menu.appendChild(
1121 'current_focus.value = "' + f.@tag + '";' +
1122 'var e = document.createEvent("MutationEvents");' +
1123 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1124 'current_focus.inputField.dispatchEvent(e);',
1125 disabled : f.@tag < '010' ? "true" : "false",
1126 tooltiptext : f.description }
1130 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1131 context_menus.appendChild( i1_popup );
1133 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1134 context_menus.appendChild( i2_popup );
1136 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1137 context_menus.appendChild( sf_popup );
1139 tooltip_hash['tag' + f.@tag] = f.description;
1140 for (var j in f.indicator) {
1141 var ind = f.indicator[j];
1142 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1144 if (ind.@position == 1) {
1145 i1_popup.appendChild(
1147 { label : ind.@value,
1149 'current_focus.value = "' + ind.@value + '";' +
1150 'var e = document.createEvent("MutationEvents");' +
1151 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1152 'current_focus.inputField.dispatchEvent(e);',
1153 tooltiptext : ind.description }
1158 if (ind.@position == 2) {
1159 i2_popup.appendChild(
1161 { label : ind.@value,
1163 'current_focus.value = "' + ind.@value + '";' +
1164 'var e = document.createEvent("MutationEvents");' +
1165 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1166 'current_focus.inputField.dispatchEvent(e);',
1167 tooltiptext : ind.description }
1173 for (var j in f.subfield) {
1174 var sf = f.subfield[j];
1175 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1177 sf_popup.appendChild(
1181 'current_focus.value = "' + sf.@code + '";' +
1182 'var e = document.createEvent("MutationEvents");' +
1183 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1184 'current_focus.inputField.dispatchEvent(e);',
1185 tooltiptext : sf.description,
1193 var p = createComplexXULElement('popupset');
1194 document.documentElement.appendChild( p );
1196 function getTooltip (target, type) {
1199 if (type == 'subfield')
1200 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1203 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1206 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1209 tt = 'tag' + target.parentNode.firstChild.value;
1211 if (!document.getElementById( tt )) {
1216 orient : 'vertical',
1217 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1218 class : 'tooltip' },
1219 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1224 target.tooltip = tt;
1228 function getContextMenu (target, type) {
1231 if (type == 'subfield')
1232 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1235 tt = 't' + target.parentNode.firstChild.value + 'i1';
1238 tt = 't' + target.parentNode.firstChild.value + 'i2';
1240 target.setAttribute('context', tt);
1244 var authority_tag_map = {
1245 100 : ['[100,400,500,700]',100],
1246 400 : ['[100,400,500,700]',100],
1247 700 : ['[100,400,500,700]',100],
1248 800 : ['[100,400,500,700]',100],
1249 110 : ['[110,410,510,710]',110],
1250 410 : ['[110,410,510,710]',110],
1251 710 : ['[110,410,510,710]',110],
1252 810 : ['[110,410,510,710]',110],
1253 111 : ['[111,411,511,711]',111],
1254 411 : ['[111,411,511,711]',111],
1255 711 : ['[111,411,511,711]',111],
1256 811 : ['[111,411,511,711]',111],
1257 240 : ['[130,430,530,730]',130],
1258 440 : ['[130,430,530,730]',130],
1259 130 : ['[130,430,530,730]',130],
1260 730 : ['[130,430,530,730]',130],
1261 830 : ['[130,430,530,730]',130],
1262 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1263 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1264 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1265 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1268 function getAuthorityContextMenu (target, sf) {
1269 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1271 var old = document.getElementById( menu_id );
1272 if (old) old.parentNode.removeChild(old);
1274 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1275 context_menus.appendChild( sf_popup );
1277 if (!authority_tag_map[sf.parent().@tag]) {
1278 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1279 target.setAttribute('context', menu_id);
1283 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1285 var res = new XML( auth_data.responseText );
1289 var recs = res.gw::payload.gw::array.gw::string;
1290 for (var i in recs) {
1292 var xml = new XML(x.toString());
1293 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1295 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1298 for (var i in main) {
1299 if (main_text) main_text += ' / ';
1300 main_text += main[i];
1303 rec_list.push( [ main_text, xml ] );
1306 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1308 var main_text = rec_list[i][0];
1309 var xml = rec_list[i][1];
1310 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1312 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1314 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1315 grid.setAttribute('name','-none-');
1316 grid.setAttribute('style','overflow:scroll');
1319 var submenu = createMenu( { label : main_text } );
1321 var popup = createMenuPopup({ flex : "1" });
1322 submenu.appendChild(popup);
1324 var fields = xml.datafield;
1325 for (var j in fields) {
1327 var row = createRow(
1329 createLabel( { value : fields[j].@tag } ),
1330 createLabel( { value : fields[j].@ind1 } ),
1331 createLabel( { value : fields[j].@ind2 } )
1334 var sf_box = createHbox();
1336 var subfields = fields[j].subfield;
1337 for (var k in subfields) {
1340 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1341 subfield : subfields[k].@code,
1342 tag : subfields[k].parent().@tag,
1343 value : subfields[k]
1347 row.appendChild(sf_box);
1350 grid.lastChild.appendChild(row);
1353 grid.hidden = false;
1354 popup.appendChild( grid );
1358 { label : 'Apply Selected',
1359 command : function (event) {
1360 applyAuthority(event.target.previousSibling, target, sf);
1367 sf_popup.appendChild( submenu );
1370 if (sf_popup.childNodes.length == 0)
1371 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1373 target.setAttribute('context', menu_id);
1377 function applyAuthority ( target, ui_sf, e4x_sf ) {
1379 var new_vals = target.getElementsByAttribute('checked','true');
1380 var field = e4x_sf.parent();
1382 for (var i = 0; i < new_vals.length; i++) {
1384 var sf_list = field.subfield;
1385 for (var j in sf_list) {
1387 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1388 sf_list[j] = new_vals[i].getAttribute('value');
1389 new_vals[i].setAttribute('subfield','');
1395 for (var i = 0; i < new_vals.length; i++) {
1396 if (!new_vals[i].getAttribute('subfield')) continue;
1398 var val = new_vals[i].getAttribute('value');
1400 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1401 sf.@code = new_vals[i].getAttribute('subfield');
1403 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1406 var row = marcDatafield( field );
1409 while (node.nodeName != 'row') {
1410 node = node.parentNode;
1413 node.parentNode.replaceChild( row, node );
1419 'a' : { 100 : 'a' },
1420 'd' : { 100 : 'd' },
1423 'a' : { 110 : 'a' },
1424 'd' : { 110 : 'd' },
1427 'a' : { 111 : 'a' },
1428 'd' : { 111 : 'd' },
1431 'a' : { 130 : 'a' },
1432 'd' : { 130 : 'd' },
1435 'a' : { 130 : 'a' },
1436 'd' : { 130 : 'd' },
1439 'a' : { 100 : 'a' },
1440 'd' : { 100 : 'd' },
1443 'a' : { 110 : 'a' },
1444 'd' : { 110 : 'd' },
1447 'a' : { 111 : 'a' },
1448 'd' : { 111 : 'd' },
1451 'a' : { 130 : 'a' },
1452 'n' : { 130 : 'n' },
1453 'p' : { 130 : 'p' },
1456 'a' : { 100 : 'a' },
1457 'd' : { 100 : 'd' },
1460 'a' : { 110 : 'a' },
1461 'd' : { 110 : 'd' },
1464 'a' : { 111 : 'a' },
1465 'd' : { 111 : 'd' },
1468 'a' : { 130 : 'a' },
1469 'd' : { 130 : 'd' },
1472 'a' : { 100 : 'a' },
1473 'd' : { 100 : 'd' },
1476 'a' : { 110 : 'a' },
1477 'd' : { 110 : 'd' },
1480 'a' : { 111 : 'a' },
1481 'd' : { 111 : 'd' },
1484 'a' : { 130 : 'a' },
1485 'd' : { 130 : 'd' },
1488 'a' : { 100 : 'a' },
1489 'd' : { 100 : 'd' },
1490 't' : { 100 : 't' },
1517 'a' : { 150 : 'a' },
1518 'b' : { 150 : 'b' },
1545 'a' : { 151 : 'a' },
1572 'a' : { 155 : 'a' },
1600 function validateAuthority (button) {
1601 var grid = document.getElementById('recGrid');
1602 var label = button.getAttribute('label');
1605 var rows = grid.lastChild.childNodes;
1606 for (var i = 0; i < rows.length; i++) {
1608 var tag = row.firstChild;
1610 if (!control_map[tag.value]) continue
1612 var ind1 = tag.nextSibling;
1613 var ind2 = ind1.nextSibling;
1614 var subfields = ind2.nextSibling.childNodes;
1616 for (var j = 0; j < subfields.length; j++) {
1617 var sf = subfields[j];
1619 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1621 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1624 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1625 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1626 var res = new XML( x.responseText );
1628 if (res.gw::payload.gw::array.gw::string.length()) {
1635 sf.childNodes[2].inputField.style.color = 'red';
1637 sf.childNodes[2].inputField.style.color = 'black';
1642 button.setAttribute('label', label);
1648 function searchAuthority (term, tag, sf, limit) {
1649 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1650 url += '¶m="term"¶m="' + term + '"';
1651 url += '¶m="limit"¶m=' + limit;
1652 url += '¶m="tag"¶m=' + tag;
1653 url += '¶m="subfield"¶m="' + sf + '"';
1656 var req = new XMLHttpRequest();
1657 req.open('GET',url,false);