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';
38 var new_005 = <controlfield tag="005" xmlns="http://www.loc.gov/MARC21/slim">{ stamp }</controlfield>;
40 // first, remove the old field, if any;
41 for (var i in xml_record.controlfield.(@tag == '005')) delete xml_record.controlfield.(@tag == '005')[i];
44 // then, find the right position and insert it
46 var cfields = xml_record.controfield;
47 for (var i in cfields) {
48 if (Number(cfield[i].@tag) > 5) {
49 xml_record.insertChildBefore( cfields[i], new_005 );
54 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], new_005 );
60 // Fake xulG for standalone...
65 window.xulG.record = {};
66 window.xulG.save = {};
68 window.xulG.save.label = 'Save Record';
69 window.xulG.save.func = function (r) { alert(r); }
72 var _rid = cgi.param('record');
74 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
79 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
80 document.getElementById('save-button').setAttribute('oncommand', 'mangle_005(); window.xulG.save.func(xml_record.toXMLString()); window.xulG.record.marc = xml_record.toXMLString(); window.xulG.record.url = null; my_init()');
82 if (window.xulG.record.url) {
83 var req = new XMLHttpRequest();
84 req.open('GET',window.xulG.record.url,false);
86 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
89 xml_record = new XML( window.xulG.record.marc );
90 if (xml_record..record[0]) xml_record = xml_record..record[0];
92 // Get the tooltip xml all async like
93 req = new XMLHttpRequest();
94 req.open('GET','marcedit-tooltips.xml',true);
95 req.onreadystatechange = function () {
96 if (req.readyState == 4) {
97 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
103 loadRecord(xml_record);
105 alert('FIXME, MARC Editor, my_init: ' + E);
110 function createComplexHTMLElement (e, attrs, objects, text) {
111 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
114 for (var i in attrs) l.setAttribute(i,attrs[i]);
118 for ( var i in objects ) l.appendChild( objects[i] );
122 l.appendChild( document.createTextNode(text) )
128 function createComplexXULElement (e, attrs, objects) {
129 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
132 for (var i in attrs) {
133 if (typeof attrs[i] == 'function') {
134 l.addEventListener( i, attrs[i], true );
136 l.setAttribute(i,attrs[i]);
142 for ( var i in objects ) l.appendChild( objects[i] );
148 function createDescription (attrs) {
149 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
152 function createTooltip (attrs) {
153 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
156 function createLabel (attrs) {
157 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
160 function createVbox (attrs) {
161 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
164 function createHbox (attrs) {
165 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
168 function createRow (attrs) {
169 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
172 function createTextbox (attrs) {
173 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
176 function createMenu (attrs) {
177 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
180 function createMenuPopup (attrs) {
181 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
184 function createPopup (attrs) {
185 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
188 function createMenuitem (attrs) {
189 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
192 function createCheckbox (attrs) {
193 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
196 function createMARCTextbox (element,attrs) {
198 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
199 box.onkeypress = function (event) {
202 while(node = node.parent()) {
206 var row = event.target;
207 while (row.tagName != 'row') row = row.parentNode;
209 if (element.nodeKind() == 'attribute') element[0]=box.value;
210 else element.setChildren( box.value );
212 if (element.localName() != 'controlfield') {
213 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
215 var index_sf, target, move_data;
216 if (element.localName() == 'subfield') {
218 target = event.target.parentNode;
220 var start = event.target.selectionStart;
221 var end = event.target.selectionEnd - event.target.selectionStart ?
222 event.target.selectionEnd :
223 event.target.value.length;
225 move_data = event.target.value.substring(start,end);
226 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
227 event.target.setAttribute('size', event.target.value.length + 2);
229 element.setChildren( event.target.value );
231 } else if (element.localName() == 'code') {
232 index_sf = element.parent();
233 target = event.target.parentNode;
234 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
235 index_sf = element.parent().children()[element.parent().children().length() - 1];
236 target = event.target.parentNode.lastChild.lastChild;
239 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
241 index_sf.parent().insertChildAfter( index_sf, sf );
243 var new_sf = marcSubfield(sf);
245 if (target === target.parentNode.lastChild) {
246 target.parentNode.appendChild( new_sf );
248 target.parentNode.insertBefore( new_sf, target.nextSibling );
251 new_sf.firstChild.nextSibling.focus();
253 event.preventDefault();
256 } else if (event.keyCode == 13 || event.keyCode == 77) {
257 if (event.ctrlKey) { // ctrl+enter
260 if (element.localName() == 'subfield') index = element.parent();
261 if (element.localName() == 'code') index = element.parent().parent();
262 if (element.localName() == 'tag') index = element.parent();
263 if (element.localName() == 'ind1') index = element.parent();
264 if (element.localName() == 'ind2') index = element.parent();
266 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
268 index.parent().insertChildAfter( index, df );
270 var new_df = marcDatafield(df);
272 if (row.parentNode.lastChild === row) {
273 row.parentNode.appendChild( new_df );
275 row.parentNode.insertBefore( new_df, row.nextSibling );
278 new_df.firstChild.focus();
280 event.preventDefault();
283 } else if (event.shiftKey) {
284 if (row.previousSibling.className.match('marcDatafieldRow'))
285 row.previousSibling.firstChild.focus();
287 row.nextSibling.firstChild.focus();
290 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
293 if (element.localName() == 'subfield') index = element.parent();
294 if (element.localName() == 'code') index = element.parent().parent();
295 if (element.localName() == 'tag') index = element.parent();
296 if (element.localName() == 'ind1') index = element.parent();
297 if (element.localName() == 'ind2') index = element.parent();
299 for (var i in index.parent().children()) {
300 if (index === index.parent().children()[i]) {
301 delete index.parent().children()[i];
306 row.previousSibling.firstChild.focus();
307 row.parentNode.removeChild(row);
309 event.preventDefault();
312 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
315 if (element.localName() == 'subfield') index = element;
316 if (element.localName() == 'code') 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 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
327 event.target.parentNode.previousSibling.lastChild.focus();
329 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
332 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
334 event.preventDefault();
340 if (element.localName() == 'controlfield') fillFixedFields(xml_record);
343 box.addEventListener(
346 if (element.nodeKind() == 'attribute') element[0]=box.value;
347 else element.setChildren( box.value );
348 if (element.localName() == 'controlfield') fillFixedFields(xml_record);
354 box.addEventListener(
357 if (element.nodeKind() == 'attribute') element[0]=box.value;
358 else element.setChildren( box.value );
359 if (element.localName() == 'controlfield') fillFixedFields(xml_record);
365 box.addEventListener(
368 if (element.nodeKind() == 'attribute') element[0]=box.value;
369 else element.setChildren( box.value );
370 if (element.localName() == 'controlfield') fillFixedFields(xml_record);
380 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
381 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
382 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
383 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
384 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
385 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
386 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
387 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
393 BKS : {start : 15, len : 3, def : ' ' },
394 SER : {start : 15, len : 3, def : ' ' },
395 VIS : {start : 15, len : 3, def : ' ' },
396 MIX : {start : 15, len : 3, def : ' ' },
397 MAP : {start : 15, len : 3, def : ' ' },
398 SCO : {start : 15, len : 3, def : ' ' },
399 REC : {start : 15, len : 3, def : ' ' },
400 COM : {start : 15, len : 3, def : ' ' },
405 BKS : {start : 35, len : 3, def : ' ' },
406 SER : {start : 35, len : 3, def : ' ' },
407 VIS : {start : 35, len : 3, def : ' ' },
408 MIX : {start : 35, len : 3, def : ' ' },
409 MAP : {start : 35, len : 3, def : ' ' },
410 SCO : {start : 35, len : 3, def : ' ' },
411 REC : {start : 35, len : 3, def : ' ' },
412 COM : {start : 35, len : 3, def : ' ' },
417 BKS : {start : 38, len : 1, def : ' ' },
418 SER : {start : 38, len : 1, def : ' ' },
419 VIS : {start : 38, len : 1, def : ' ' },
420 MIX : {start : 38, len : 1, def : ' ' },
421 MAP : {start : 38, len : 1, def : ' ' },
422 SCO : {start : 38, len : 1, def : ' ' },
423 REC : {start : 38, len : 1, def : ' ' },
424 COM : {start : 38, len : 1, def : ' ' },
429 BKS : {start : 6, len : 1, def : ' ' },
430 SER : {start : 6, len : 1, def : 'c' },
431 VIS : {start : 6, len : 1, def : ' ' },
432 MIX : {start : 6, len : 1, def : ' ' },
433 MAP : {start : 6, len : 1, def : ' ' },
434 SCO : {start : 6, len : 1, def : ' ' },
435 REC : {start : 6, len : 1, def : ' ' },
436 COM : {start : 6, len : 1, def : ' ' },
441 BKS : {start : 6, len : 1, def : 'a' },
442 SER : {start : 6, len : 1, def : 'a' },
443 VIS : {start : 6, len : 1, def : 'g' },
444 MIX : {start : 6, len : 1, def : 'p' },
445 MAP : {start : 6, len : 1, def : 'e' },
446 SCO : {start : 6, len : 1, def : 'c' },
447 REC : {start : 6, len : 1, def : 'i' },
448 COM : {start : 6, len : 1, def : 'm' },
453 BKS : {start : 8, len : 1, def : ' ' },
454 SER : {start : 8, len : 1, def : ' ' },
455 VIS : {start : 8, len : 1, def : ' ' },
456 MIX : {start : 8, len : 1, def : ' ' },
457 MAP : {start : 8, len : 1, def : ' ' },
458 SCO : {start : 8, len : 1, def : ' ' },
459 REC : {start : 8, len : 1, def : ' ' },
460 COM : {start : 8, len : 1, def : ' ' },
465 BKS : {start : 7, len : 1, def : 'm' },
466 SER : {start : 7, len : 1, def : 's' },
467 VIS : {start : 7, len : 1, def : 'm' },
468 MIX : {start : 7, len : 1, def : 'c' },
469 MAP : {start : 7, len : 1, def : 'm' },
470 SCO : {start : 7, len : 1, def : 'm' },
471 REC : {start : 7, len : 1, def : 'm' },
472 COM : {start : 7, len : 1, def : 'm' },
477 BKS : {start : 18, len : 1, def : ' ' },
478 SER : {start : 18, len : 1, def : ' ' },
479 VIS : {start : 18, len : 1, def : ' ' },
480 MIX : {start : 18, len : 1, def : ' ' },
481 MAP : {start : 18, len : 1, def : ' ' },
482 SCO : {start : 18, len : 1, def : ' ' },
483 REC : {start : 18, len : 1, def : ' ' },
484 COM : {start : 18, len : 1, def : ' ' },
489 BKS : {start : 17, len : 1, def : ' ' },
490 SER : {start : 17, len : 1, def : ' ' },
491 VIS : {start : 17, len : 1, def : ' ' },
492 MIX : {start : 17, len : 1, def : ' ' },
493 MAP : {start : 17, len : 1, def : ' ' },
494 SCO : {start : 17, len : 1, def : ' ' },
495 REC : {start : 17, len : 1, def : ' ' },
496 COM : {start : 17, len : 1, def : ' ' },
501 BKS : {start : 31, len : 1, def : '0' },
502 MAP : {start : 31, len : 1, def : '0' },
505 BKS : {start : 14, len : 1, def : '0' },
506 MAP : {start : 14, len : 1, def : '0' },
511 BKS : {start : 7, len : 4, def : ' ' },
512 SER : {start : 7, len : 4, def : ' ' },
513 VIS : {start : 7, len : 4, def : ' ' },
514 MIX : {start : 7, len : 4, def : ' ' },
515 MAP : {start : 7, len : 4, def : ' ' },
516 SCO : {start : 7, len : 4, def : ' ' },
517 REC : {start : 7, len : 4, def : ' ' },
518 COM : {start : 7, len : 4, def : ' ' },
523 BKS : {start : 11, len : 4, def : ' ' },
524 SER : {start : 11, len : 4, def : '9' },
525 VIS : {start : 11, len : 4, def : ' ' },
526 MIX : {start : 11, len : 4, def : ' ' },
527 MAP : {start : 11, len : 4, def : ' ' },
528 SCO : {start : 11, len : 4, def : ' ' },
529 REC : {start : 11, len : 4, def : ' ' },
530 COM : {start : 11, len : 4, def : ' ' },
535 BKS : {start : 33, len : 1, def : '0' },
538 BKS : {start : 16, len : 1, def : '0' },
543 BKS : {start : 34, len : 1, def : ' ' },
546 BKS : {start : 17, len : 1, def : ' ' },
551 BKS : {start : 18, len : 4, def : ' ' },
554 BKS : {start : 1, len : 4, def : ' ' },
559 BKS : {start : 30, len : 1, def : '0' },
562 BKS : {start : 13, len : 1, def : '0' },
567 BKS : {start : 24, len : 4, def : ' ' },
568 SER : {start : 25, len : 3, def : ' ' },
571 BKS : {start : 7, len : 4, def : ' ' },
572 SER : {start : 8, len : 3, def : ' ' },
577 BKS : {start : 28, len : 1, def : ' ' },
578 SER : {start : 28, len : 1, def : ' ' },
579 VIS : {start : 28, len : 1, def : ' ' },
580 MAP : {start : 28, len : 1, def : ' ' },
581 COM : {start : 28, len : 1, def : ' ' },
584 BKS : {start : 11, len : 1, def : ' ' },
585 SER : {start : 11, len : 1, def : ' ' },
586 VIS : {start : 11, len : 1, def : ' ' },
587 MAP : {start : 11, len : 1, def : ' ' },
588 COM : {start : 11, len : 1, def : ' ' },
593 BKS : {start : 22, len : 1, def : ' ' },
594 SER : {start : 22, len : 1, def : ' ' },
595 VIS : {start : 22, len : 1, def : ' ' },
596 SCO : {start : 22, len : 1, def : ' ' },
597 REC : {start : 22, len : 1, def : ' ' },
598 COM : {start : 22, len : 1, def : ' ' },
601 BKS : {start : 5, len : 1, def : ' ' },
602 SER : {start : 5, len : 1, def : ' ' },
603 VIS : {start : 5, len : 1, def : ' ' },
604 SCO : {start : 5, len : 1, def : ' ' },
605 REC : {start : 5, len : 1, def : ' ' },
606 COM : {start : 5, len : 1, def : ' ' },
611 BKS : {start : 23, len : 1, def : ' ' },
612 SER : {start : 23, len : 1, def : ' ' },
613 VIS : {start : 29, len : 1, def : ' ' },
614 MIX : {start : 23, len : 1, def : ' ' },
615 MAP : {start : 29, len : 1, def : ' ' },
616 SCO : {start : 23, len : 1, def : ' ' },
617 REC : {start : 23, len : 1, def : ' ' },
620 BKS : {start : 6, len : 1, def : ' ' },
621 SER : {start : 6, len : 1, def : ' ' },
622 VIS : {start : 12, len : 1, def : ' ' },
623 MIX : {start : 6, len : 1, def : ' ' },
624 MAP : {start : 12, len : 1, def : ' ' },
625 SCO : {start : 6, len : 1, def : ' ' },
626 REC : {start : 6, len : 1, def : ' ' },
631 SER : {start : 34, len : 1, def : '0' },
634 SER : {start : 17, len : 1, def : '0' },
639 SER : {start : 33, len : 1, def : ' ' },
642 SER : {start : 16, len : 1, def : ' ' },
647 function recordType (rec) {
649 var _l = rec.leader.toString();
651 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
652 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
654 for (var t in rec_type) {
655 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
656 document.getElementById('recordTypeLabel').value = t;
662 alert('FIXME, MARC Editor, recordType: ' + E);
666 function toggleFFE () {
667 var grid = document.getElementById('leaderGrid');
676 function changeFFEditor (type) {
677 var grid = document.getElementById('leaderGrid');
678 grid.setAttribute('type',type);
681 function fillFixedFields (rec) {
683 var grid = document.getElementById('leaderGrid');
685 var rtype = _record_type;
687 var _l = rec.leader.toString();
688 var _6 = rec.controlfield.(@tag=='006').toString();
689 var _7 = rec.controlfield.(@tag=='007').toString();
690 var _8 = rec.controlfield.(@tag=='008').toString();
693 var pre_list = grid.getElementsByTagName('label');
694 for (var i in pre_list) {
695 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
696 list.push( pre_list[i] );
700 for (var i in list) {
701 var name = list[i].getAttribute('name');
707 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
708 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
710 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
711 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
713 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
714 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
716 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
717 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
722 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
723 d = ff_pos[name].ldr[rtype].def;
727 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
728 d = ff_pos[name]._8[rtype].def;
732 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
733 d = ff_pos[name]._6[rtype].def;
737 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
738 d = ff_pos[name]._7[rtype].def;
743 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
749 list[i].nextSibling.value = value;
754 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
758 function updateFixedFields (element) {
759 var grid = document.getElementById('leaderGrid');
760 var recGrid = document.getElementById('recGrid');
762 var rtype = _record_type;
763 var new_value = element.value;
766 ldr : _record.leader,
767 _6 : _record.controlfield.(@tag=='006'),
768 _7 : _record.controlfield.(@tag=='007'),
769 _8 : _record.controlfield.(@tag=='008'),
772 var name = element.getAttribute('name');
773 for (var i in ff_pos[name]) {
775 if (!ff_pos[name][i][rtype]) continue;
776 if (!parts[i]) continue;
778 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
779 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
781 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
782 new_value += ff_pos[name][i][rtype].def;
785 parts[i].setChildren( before + new_value + after );
786 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
792 function marcLeader (leader) {
794 { class : 'marcLeaderRow',
799 tooltiptext : "MARC Leader" } ),
802 class : 'marcInd1' } ),
805 class : 'marcInd2' } ),
807 { value : leader.text(),
808 class : 'marcLeader' } )
814 function marcControlfield (field) {
815 tagname = field.@tag.toString().substr(2);
817 if (tagname == '6' || tagname == '7' || tagname == '8') {
819 { class : 'marcControlfieldRow',
820 tag : '_' + tagname },
822 { value : field.@tag,
824 onmouseover : 'getTooltip(this, "tag");',
825 tooltipid : 'tag' + field.@tag } ),
827 { value : field.@ind1,
829 onmouseover : 'getTooltip(this, "ind1");',
830 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
832 { value : field.@ind2,
834 onmouseover : 'getTooltip(this, "ind2");',
835 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
838 { value : field.text(),
839 class : 'plain marcEditableControlfield',
840 name : 'CONTROL' + tagname,
841 oncontext : 'return false();',
847 { class : 'marcControlfieldRow',
848 tag : '_' + tagname },
850 { value : field.@tag,
852 onmouseover : 'getTooltip(this, "tag");',
853 tooltipid : 'tag' + field.@tag } ),
855 { value : field.@ind1,
857 onmouseover : 'getTooltip(this, "ind1");',
858 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
860 { value : field.@ind2,
862 onmouseover : 'getTooltip(this, "ind2");',
863 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
865 { value : field.text(),
866 class : 'marcControlfield' } )
873 function stackSubfields(checkbox) {
874 var list = document.getElementsByAttribute('name','sf_box');
877 if (checkbox.checked) o = 'horizontal';
879 for (var i = 0; i < list.length; i++) {
880 if (list[i]) list[i].setAttribute('orient',o);
884 function marcDatafield (field) {
886 { class : 'marcDatafieldRow' },
889 { value : field.@tag,
890 class : 'plain marcTag',
892 context : 'tags_popup',
893 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
896 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
899 { value : field.@ind1,
900 class : 'plain marcInd1',
902 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
905 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
906 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
909 { value : field.@ind2,
910 class : 'plain marcInd2',
912 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
915 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
916 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
917 createHbox({ name : 'sf_box' })
920 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
921 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
922 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
924 var sf_box = row.lastChild;
925 if (document.getElementById('stackSubfields').checked)
926 sf_box.setAttribute('orient','vertical');
928 sf_box.addEventListener(
931 if (sf_box === e.target) {
932 sf_box.lastChild.lastChild.focus();
933 } else if (e.target.parentNode === sf_box) {
934 e.target.lastChild.focus();
941 for (var i in field.subfield) {
942 var sf = field.subfield[i];
947 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
948 current_focus = sf_box.lastChild.childNodes[1];
954 function marcSubfield (sf) {
956 { class : 'marcSubfieldBox' },
959 class : 'plain marcSubfieldDelimiter',
960 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
961 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
962 //onclick : 'this.nextSibling.focus();',
963 onfocus : 'this.nextSibling.focus();',
968 class : 'plain marcSubfieldCode',
969 name : 'marcSubfieldCode',
970 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
971 oncontextmenu : 'getContextMenu(this, "subfield");',
972 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
978 name : sf.parent().@tag + ':' + sf.@code,
979 class : 'plain marcSubfield',
980 onmouseover : 'getTooltip(this, "subfield");',
981 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
982 size : new String(sf.text()).length + 2,
983 oninput : "this.setAttribute('size', this.value.length + 2);",
988 function loadRecord(rec) {
991 var grid_rows = document.getElementById('recGrid').lastChild;
993 grid_rows.appendChild( marcLeader( rec.leader ) );
995 for (var i in rec.controlfield) {
996 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
999 for (var i in rec.datafield) {
1000 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1003 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1004 changeFFEditor(recordType(rec));
1005 fillFixedFields(rec);
1007 alert('FIXME, MARC Editor, loadRecord: ' + E);
1011 var context_menus = createComplexXULElement('popupset');
1012 document.documentElement.appendChild( context_menus );
1014 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
1015 context_menus.appendChild( tag_menu );
1017 tag_menu.appendChild(
1019 { label : 'Add Row',
1021 'var e = document.createEvent("KeyEvents");' +
1022 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
1023 'current_focus.inputField.dispatchEvent(e);',
1028 tag_menu.appendChild(
1030 { label : 'Remove Row',
1032 'var e = document.createEvent("KeyEvents");' +
1033 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
1034 'current_focus.inputField.dispatchEvent(e);',
1039 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1043 function genToolTips () {
1044 for (var i in bib_data.field) {
1045 var f = bib_data.field[i];
1047 tag_menu.appendChild(
1051 'current_focus.value = "' + f.@tag + '";' +
1052 'var e = document.createEvent("MutationEvents");' +
1053 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1054 'current_focus.inputField.dispatchEvent(e);',
1055 disabled : f.@tag < '010' ? "true" : "false",
1056 tooltiptext : f.description }
1060 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1061 context_menus.appendChild( i1_popup );
1063 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1064 context_menus.appendChild( i2_popup );
1066 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1067 context_menus.appendChild( sf_popup );
1069 tooltip_hash['tag' + f.@tag] = f.description;
1070 for (var j in f.indicator) {
1071 var ind = f.indicator[j];
1072 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1074 if (ind.@position == 1) {
1075 i1_popup.appendChild(
1077 { label : ind.@value,
1079 'current_focus.value = "' + ind.@value + '";' +
1080 'var e = document.createEvent("MutationEvents");' +
1081 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1082 'current_focus.inputField.dispatchEvent(e);',
1083 tooltiptext : ind.description }
1088 if (ind.@position == 2) {
1089 i2_popup.appendChild(
1091 { label : ind.@value,
1093 'current_focus.value = "' + ind.@value + '";' +
1094 'var e = document.createEvent("MutationEvents");' +
1095 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1096 'current_focus.inputField.dispatchEvent(e);',
1097 tooltiptext : ind.description }
1103 for (var j in f.subfield) {
1104 var sf = f.subfield[j];
1105 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1107 sf_popup.appendChild(
1111 'current_focus.value = "' + sf.@code + '";' +
1112 'var e = document.createEvent("MutationEvents");' +
1113 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1114 'current_focus.inputField.dispatchEvent(e);',
1115 tooltiptext : sf.description,
1123 var p = createComplexXULElement('popupset');
1124 document.documentElement.appendChild( p );
1126 function getTooltip (target, type) {
1129 if (type == 'subfield')
1130 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1133 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1136 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1139 tt = 'tag' + target.parentNode.firstChild.value;
1141 if (!document.getElementById( tt )) {
1146 orient : 'vertical',
1147 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1148 class : 'tooltip' },
1149 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1154 target.tooltip = tt;
1158 function getContextMenu (target, type) {
1161 if (type == 'subfield')
1162 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1165 tt = 't' + target.parentNode.firstChild.value + 'i1';
1168 tt = 't' + target.parentNode.firstChild.value + 'i2';
1170 target.setAttribute('context', tt);
1174 var authority_tag_map = {
1175 100 : ['[100,400,500,700]',100],
1176 400 : ['[100,400,500,700]',100],
1177 700 : ['[100,400,500,700]',100],
1178 800 : ['[100,400,500,700]',100],
1179 110 : ['[110,410,510,710]',110],
1180 410 : ['[110,410,510,710]',110],
1181 710 : ['[110,410,510,710]',110],
1182 810 : ['[110,410,510,710]',110],
1183 111 : ['[111,411,511,711]',111],
1184 411 : ['[111,411,511,711]',111],
1185 711 : ['[111,411,511,711]',111],
1186 811 : ['[111,411,511,711]',111],
1187 240 : ['[130,430,530,730]',130],
1188 440 : ['[130,430,530,730]',130],
1189 130 : ['[130,430,530,730]',130],
1190 730 : ['[130,430,530,730]',130],
1191 830 : ['[130,430,530,730]',130],
1192 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1193 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1194 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1195 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1198 function getAuthorityContextMenu (target, sf) {
1199 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1201 var old = document.getElementById( menu_id );
1202 if (old) old.parentNode.removeChild(old);
1204 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1205 context_menus.appendChild( sf_popup );
1207 if (!authority_tag_map[sf.parent().@tag]) {
1208 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1209 target.setAttribute('context', menu_id);
1213 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1215 var res = new XML( auth_data.responseText );
1219 var recs = res.gw::payload.gw::array.gw::string;
1220 for (var i in recs) {
1222 var xml = new XML(x.toString());
1223 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1225 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1228 for (var i in main) {
1229 if (main_text) main_text += ' / ';
1230 main_text += main[i];
1233 rec_list.push( [ main_text, xml ] );
1236 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1238 var main_text = rec_list[i][0];
1239 var xml = rec_list[i][1];
1240 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1242 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1244 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1245 grid.setAttribute('name','-none-');
1246 grid.setAttribute('style','overflow:scroll');
1249 var submenu = createMenu( { label : main_text } );
1251 var popup = createMenuPopup({ flex : "1" });
1252 submenu.appendChild(popup);
1254 var fields = xml.datafield;
1255 for (var j in fields) {
1257 var row = createRow(
1259 createLabel( { value : fields[j].@tag } ),
1260 createLabel( { value : fields[j].@ind1 } ),
1261 createLabel( { value : fields[j].@ind2 } )
1264 var sf_box = createHbox();
1266 var subfields = fields[j].subfield;
1267 for (var k in subfields) {
1270 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1271 subfield : subfields[k].@code,
1272 tag : subfields[k].parent().@tag,
1273 value : subfields[k]
1277 row.appendChild(sf_box);
1280 grid.lastChild.appendChild(row);
1283 grid.hidden = false;
1284 popup.appendChild( grid );
1288 { label : 'Apply Selected',
1289 command : function (event) {
1290 applyAuthority(event.target.previousSibling, target, sf);
1297 sf_popup.appendChild( submenu );
1300 if (sf_popup.childNodes.length == 0)
1301 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1303 target.setAttribute('context', menu_id);
1307 function applyAuthority ( target, ui_sf, e4x_sf ) {
1309 var new_vals = target.getElementsByAttribute('checked','true');
1310 var field = e4x_sf.parent();
1312 for (var i = 0; i < new_vals.length; i++) {
1314 var sf_list = field.subfield;
1315 for (var j in sf_list) {
1317 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1318 sf_list[j] = new_vals[i].getAttribute('value');
1319 new_vals[i].setAttribute('subfield','');
1325 for (var i = 0; i < new_vals.length; i++) {
1326 if (!new_vals[i].getAttribute('subfield')) continue;
1328 var val = new_vals[i].getAttribute('value');
1330 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1331 sf.@code = new_vals[i].getAttribute('subfield');
1333 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1336 var row = marcDatafield( field );
1339 while (node.nodeName != 'row') {
1340 node = node.parentNode;
1343 node.parentNode.replaceChild( row, node );
1349 'a' : { 100 : 'a' },
1350 'd' : { 100 : 'd' },
1353 'a' : { 110 : 'a' },
1354 'd' : { 110 : 'd' },
1357 'a' : { 111 : 'a' },
1358 'd' : { 111 : 'd' },
1361 'a' : { 130 : 'a' },
1362 'd' : { 130 : 'd' },
1365 'a' : { 130 : 'a' },
1366 'd' : { 130 : 'd' },
1369 'a' : { 100 : 'a' },
1370 'd' : { 100 : 'd' },
1373 'a' : { 110 : 'a' },
1374 'd' : { 110 : 'd' },
1377 'a' : { 111 : 'a' },
1378 'd' : { 111 : 'd' },
1381 'a' : { 130 : 'a' },
1382 'n' : { 130 : 'n' },
1383 'p' : { 130 : 'p' },
1386 'a' : { 100 : 'a' },
1387 'd' : { 100 : 'd' },
1390 'a' : { 110 : 'a' },
1391 'd' : { 110 : 'd' },
1394 'a' : { 111 : 'a' },
1395 'd' : { 111 : 'd' },
1398 'a' : { 130 : 'a' },
1399 'd' : { 130 : 'd' },
1402 'a' : { 100 : 'a' },
1403 'd' : { 100 : 'd' },
1406 'a' : { 110 : 'a' },
1407 'd' : { 110 : 'd' },
1410 'a' : { 111 : 'a' },
1411 'd' : { 111 : 'd' },
1414 'a' : { 130 : 'a' },
1415 'd' : { 130 : 'd' },
1418 'a' : { 100 : 'a' },
1419 'd' : { 100 : 'd' },
1420 't' : { 100 : 't' },
1447 'a' : { 150 : 'a' },
1448 'b' : { 150 : 'b' },
1475 'a' : { 151 : 'a' },
1502 'a' : { 155 : 'a' },
1530 function validateAuthority (button) {
1531 var grid = document.getElementById('recGrid');
1532 var label = button.getAttribute('label');
1535 var rows = grid.lastChild.childNodes;
1536 for (var i = 0; i < rows.length; i++) {
1538 var tag = row.firstChild;
1540 if (!control_map[tag.value]) continue
1542 var ind1 = tag.nextSibling;
1543 var ind2 = ind1.nextSibling;
1544 var subfields = ind2.nextSibling.childNodes;
1546 for (var j = 0; j < subfields.length; j++) {
1547 var sf = subfields[j];
1549 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1551 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1554 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1555 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1556 var res = new XML( x.responseText );
1558 if (res.gw::payload.gw::array.gw::string.length()) {
1565 sf.childNodes[2].inputField.style.color = 'red';
1567 sf.childNodes[2].inputField.style.color = 'black';
1572 button.setAttribute('label', label);
1578 function searchAuthority (term, tag, sf, limit) {
1579 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1580 url += '¶m="term"¶m="' + term + '"';
1581 url += '¶m="limit"¶m=' + limit;
1582 url += '¶m="tag"¶m=' + tag;
1583 url += '¶m="subfield"¶m="' + sf + '"';
1586 var req = new XMLHttpRequest();
1587 req.open('GET',url,false);