1 var xmlDeclaration = /^<\?xml version[^>]+?>/;
3 var serializer = new XMLSerializer();
4 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
5 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
6 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
7 default xml namespace = marcns;
16 function mangle_005() {
18 var y = now.getUTCFullYear();
20 var m = now.getUTCMonth() + 1;
21 if (m < 10) m = '0' + m;
23 var d = now.getUTCDate();
24 if (d < 10) d = '0' + d;
26 var H = now.getUTCHours();
27 if (H < 10) H = '0' + H;
29 var M = now.getUTCMinutes();
30 if (M < 10) M = '0' + M;
32 var S = now.getUTCSeconds();
33 if (S < 10) S = '0' + S;
36 var stamp = '' + y + m + d + H + M + S + '.0';
37 createControlField('005',stamp);
41 function createControlField (tag,data) {
42 // first, remove the old field, if any;
43 for (var i in xml_record.controlfield.(@tag == tag)) delete xml_record.controlfield.(@tag == tag)[i];
45 var cf = <controlfield tag="" xmlns="http://www.loc.gov/MARC21/slim">{ data }</controlfield>;
48 // then, find the right position and insert it
50 var cfields = xml_record.controlfield;
51 var base = Number(tag.substring(2));
52 for (var i in cfields) {
53 var t = Number(cfields[i].@tag.toString().substring(2));
55 xml_record.insertChildBefore( cfields[i], cf );
61 if (!done) xml_record.insertChildBefore( xml_record.datafield[0], cf );
66 function xml_escape_unicode ( str ) {
69 function (r,s) { return "&#x" + s.charCodeAt(0).toString(16) + ";"; }
75 // Fake xulG for standalone...
80 window.xulG.record = {};
81 window.xulG.save = {};
83 window.xulG.save.label = 'Save Record';
84 window.xulG.save.func = function (r) { alert(r); }
87 var _rid = cgi.param('record');
89 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
94 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
95 document.getElementById('save-button').setAttribute('oncommand',
97 'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' +
98 'window.xulG.save.func( xml_string ); ' +
99 'loadRecord(xml_record);'
102 if (window.xulG.record.url) {
103 var req = new XMLHttpRequest();
104 req.open('GET',window.xulG.record.url,false);
106 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
109 xml_record = new XML( window.xulG.record.marc );
110 if (xml_record..record[0]) xml_record = xml_record..record[0];
112 // Get the tooltip xml all async like
113 req = new XMLHttpRequest();
114 req.open('GET','marcedit-tooltips.xml',true);
115 req.onreadystatechange = function () {
116 if (req.readyState == 4) {
117 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
123 loadRecord(xml_record);
125 alert('FIXME, MARC Editor, my_init: ' + E);
130 function createComplexHTMLElement (e, attrs, objects, text) {
131 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
134 for (var i in attrs) l.setAttribute(i,attrs[i]);
138 for ( var i in objects ) l.appendChild( objects[i] );
142 l.appendChild( document.createTextNode(text) )
148 function createComplexXULElement (e, attrs, objects) {
149 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
152 for (var i in attrs) {
153 if (typeof attrs[i] == 'function') {
154 l.addEventListener( i, attrs[i], true );
156 l.setAttribute(i,attrs[i]);
162 for ( var i in objects ) l.appendChild( objects[i] );
168 function createDescription (attrs) {
169 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
172 function createTooltip (attrs) {
173 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
176 function createLabel (attrs) {
177 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
180 function createVbox (attrs) {
181 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
184 function createHbox (attrs) {
185 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
188 function createRow (attrs) {
189 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
192 function createTextbox (attrs) {
193 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
196 function createMenu (attrs) {
197 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
200 function createMenuPopup (attrs) {
201 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
204 function createPopup (attrs) {
205 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
208 function createMenuitem (attrs) {
209 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
212 function createCheckbox (attrs) {
213 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
216 function createMARCTextbox (element,attrs) {
218 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
219 box.onkeypress = function (event) {
222 while(node = node.parent()) {
226 var row = event.target;
227 while (row.tagName != 'row') row = row.parentNode;
229 if (element.nodeKind() == 'attribute') element[0]=box.value;
230 else element.setChildren( box.value );
232 if (element.localName() != 'controlfield') {
233 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
235 var index_sf, target, move_data;
236 if (element.localName() == 'subfield') {
238 target = event.target.parentNode;
240 var start = event.target.selectionStart;
241 var end = event.target.selectionEnd - event.target.selectionStart ?
242 event.target.selectionEnd :
243 event.target.value.length;
245 move_data = event.target.value.substring(start,end);
246 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
247 event.target.setAttribute('size', event.target.value.length + 2);
249 element.setChildren( event.target.value );
251 } else if (element.localName() == 'code') {
252 index_sf = element.parent();
253 target = event.target.parentNode;
254 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
255 index_sf = element.parent().children()[element.parent().children().length() - 1];
256 target = event.target.parentNode.lastChild.lastChild;
259 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
261 index_sf.parent().insertChildAfter( index_sf, sf );
263 var new_sf = marcSubfield(sf);
265 if (target === target.parentNode.lastChild) {
266 target.parentNode.appendChild( new_sf );
268 target.parentNode.insertBefore( new_sf, target.nextSibling );
271 new_sf.firstChild.nextSibling.focus();
273 event.preventDefault();
276 } else if (event.keyCode == 13 || event.keyCode == 77) {
277 if (event.ctrlKey) { // ctrl+enter
280 if (element.localName() == 'subfield') index = element.parent();
281 if (element.localName() == 'code') index = element.parent().parent();
282 if (element.localName() == 'tag') index = element.parent();
283 if (element.localName() == 'ind1') index = element.parent();
284 if (element.localName() == 'ind2') index = element.parent();
286 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
288 if (event.shiftKey) { // ctrl+shift+enter
289 index.parent().insertChildBefore( index, df );
291 index.parent().insertChildAfter( index, df );
294 var new_df = marcDatafield(df);
296 if (row.parentNode.lastChild === row) {
297 row.parentNode.appendChild( new_df );
299 if (event.shiftKey) { // ctrl+shift+enter
300 row.parentNode.insertBefore( new_df, row );
302 row.parentNode.insertBefore( new_df, row.nextSibling );
306 new_df.firstChild.focus();
308 event.preventDefault();
311 } else if (event.shiftKey) {
312 if (row.previousSibling.className.match('marcDatafieldRow'))
313 row.previousSibling.firstChild.focus();
315 row.nextSibling.firstChild.focus();
318 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
321 if (element.localName() == 'subfield') index = element.parent();
322 if (element.localName() == 'code') index = element.parent().parent();
323 if (element.localName() == 'tag') index = element.parent();
324 if (element.localName() == 'ind1') index = element.parent();
325 if (element.localName() == 'ind2') 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 row.previousSibling.firstChild.focus();
335 row.parentNode.removeChild(row);
337 event.preventDefault();
340 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
343 if (element.localName() == 'subfield') index = element;
344 if (element.localName() == 'code') index = element.parent();
347 for (var i in index.parent().children()) {
348 if (index === index.parent().children()[i]) {
349 delete index.parent().children()[i];
354 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
355 event.target.parentNode.previousSibling.lastChild.focus();
357 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
360 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
362 event.preventDefault();
365 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
366 createControlField('006','');
367 loadRecord(xml_record);
368 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
369 createControlField('007','');
370 loadRecord(xml_record);
371 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
372 createControlField('008','');
373 loadRecord(xml_record);
379 box.addEventListener(
382 if (element.nodeKind() == 'attribute') element[0]=box.value;
383 else element.setChildren( box.value );
389 box.addEventListener(
392 if (element.nodeKind() == 'attribute') element[0]=box.value;
393 else element.setChildren( box.value );
399 box.addEventListener(
402 if (element.nodeKind() == 'attribute') element[0]=box.value;
403 else element.setChildren( box.value );
409 box.addEventListener(
412 if (element.localName() == 'controlfield')
413 eval('fillFixedFields(xml_record);');
422 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
423 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
424 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
425 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
426 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
427 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
428 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
429 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
435 BKS : {start : 15, len : 3, def : ' ' },
436 SER : {start : 15, len : 3, def : ' ' },
437 VIS : {start : 15, len : 3, def : ' ' },
438 MIX : {start : 15, len : 3, def : ' ' },
439 MAP : {start : 15, len : 3, def : ' ' },
440 SCO : {start : 15, len : 3, def : ' ' },
441 REC : {start : 15, len : 3, def : ' ' },
442 COM : {start : 15, len : 3, def : ' ' },
447 BKS : {start : 35, len : 3, def : ' ' },
448 SER : {start : 35, len : 3, def : ' ' },
449 VIS : {start : 35, len : 3, def : ' ' },
450 MIX : {start : 35, len : 3, def : ' ' },
451 MAP : {start : 35, len : 3, def : ' ' },
452 SCO : {start : 35, len : 3, def : ' ' },
453 REC : {start : 35, len : 3, def : ' ' },
454 COM : {start : 35, len : 3, def : ' ' },
459 BKS : {start : 38, len : 1, def : ' ' },
460 SER : {start : 38, len : 1, def : ' ' },
461 VIS : {start : 38, len : 1, def : ' ' },
462 MIX : {start : 38, len : 1, def : ' ' },
463 MAP : {start : 38, len : 1, def : ' ' },
464 SCO : {start : 38, len : 1, def : ' ' },
465 REC : {start : 38, len : 1, def : ' ' },
466 COM : {start : 38, len : 1, def : ' ' },
471 BKS : {start : 6, len : 1, def : ' ' },
472 SER : {start : 6, len : 1, def : 'c' },
473 VIS : {start : 6, len : 1, def : ' ' },
474 MIX : {start : 6, len : 1, def : ' ' },
475 MAP : {start : 6, len : 1, def : ' ' },
476 SCO : {start : 6, len : 1, def : ' ' },
477 REC : {start : 6, len : 1, def : ' ' },
478 COM : {start : 6, len : 1, def : ' ' },
483 BKS : {start : 6, len : 1, def : 'a' },
484 SER : {start : 6, len : 1, def : 'a' },
485 VIS : {start : 6, len : 1, def : 'g' },
486 MIX : {start : 6, len : 1, def : 'p' },
487 MAP : {start : 6, len : 1, def : 'e' },
488 SCO : {start : 6, len : 1, def : 'c' },
489 REC : {start : 6, len : 1, def : 'i' },
490 COM : {start : 6, len : 1, def : 'm' },
495 BKS : {start : 8, len : 1, def : ' ' },
496 SER : {start : 8, len : 1, def : ' ' },
497 VIS : {start : 8, len : 1, def : ' ' },
498 MIX : {start : 8, len : 1, def : ' ' },
499 MAP : {start : 8, len : 1, def : ' ' },
500 SCO : {start : 8, len : 1, def : ' ' },
501 REC : {start : 8, len : 1, def : ' ' },
502 COM : {start : 8, len : 1, def : ' ' },
507 BKS : {start : 7, len : 1, def : 'm' },
508 SER : {start : 7, len : 1, def : 's' },
509 VIS : {start : 7, len : 1, def : 'm' },
510 MIX : {start : 7, len : 1, def : 'c' },
511 MAP : {start : 7, len : 1, def : 'm' },
512 SCO : {start : 7, len : 1, def : 'm' },
513 REC : {start : 7, len : 1, def : 'm' },
514 COM : {start : 7, len : 1, def : 'm' },
519 BKS : {start : 18, len : 1, def : ' ' },
520 SER : {start : 18, len : 1, def : ' ' },
521 VIS : {start : 18, len : 1, def : ' ' },
522 MIX : {start : 18, len : 1, def : ' ' },
523 MAP : {start : 18, len : 1, def : ' ' },
524 SCO : {start : 18, len : 1, def : ' ' },
525 REC : {start : 18, len : 1, def : ' ' },
526 COM : {start : 18, len : 1, def : ' ' },
531 BKS : {start : 17, len : 1, def : ' ' },
532 SER : {start : 17, len : 1, def : ' ' },
533 VIS : {start : 17, len : 1, def : ' ' },
534 MIX : {start : 17, len : 1, def : ' ' },
535 MAP : {start : 17, len : 1, def : ' ' },
536 SCO : {start : 17, len : 1, def : ' ' },
537 REC : {start : 17, len : 1, def : ' ' },
538 COM : {start : 17, len : 1, def : ' ' },
543 BKS : {start : 31, len : 1, def : '0' },
544 MAP : {start : 31, len : 1, def : '0' },
547 BKS : {start : 14, len : 1, def : '0' },
548 MAP : {start : 14, len : 1, def : '0' },
553 BKS : {start : 7, len : 4, def : ' ' },
554 SER : {start : 7, len : 4, def : ' ' },
555 VIS : {start : 7, len : 4, def : ' ' },
556 MIX : {start : 7, len : 4, def : ' ' },
557 MAP : {start : 7, len : 4, def : ' ' },
558 SCO : {start : 7, len : 4, def : ' ' },
559 REC : {start : 7, len : 4, def : ' ' },
560 COM : {start : 7, len : 4, def : ' ' },
565 BKS : {start : 11, len : 4, def : ' ' },
566 SER : {start : 11, len : 4, def : '9' },
567 VIS : {start : 11, len : 4, def : ' ' },
568 MIX : {start : 11, len : 4, def : ' ' },
569 MAP : {start : 11, len : 4, def : ' ' },
570 SCO : {start : 11, len : 4, def : ' ' },
571 REC : {start : 11, len : 4, def : ' ' },
572 COM : {start : 11, len : 4, def : ' ' },
577 BKS : {start : 33, len : 1, def : '0' },
580 BKS : {start : 16, len : 1, def : '0' },
585 BKS : {start : 34, len : 1, def : ' ' },
588 BKS : {start : 17, len : 1, def : ' ' },
593 BKS : {start : 18, len : 4, def : ' ' },
596 BKS : {start : 1, len : 4, def : ' ' },
601 BKS : {start : 30, len : 1, def : '0' },
604 BKS : {start : 13, len : 1, def : '0' },
609 BKS : {start : 29, len : 1, def : '0' },
610 SER : {start : 29, len : 1, def : '0' },
613 BKS : {start : 12, len : 1, def : '0' },
614 SER : {start : 12, len : 1, def : '0' },
619 BKS : {start : 24, len : 4, def : ' ' },
620 SER : {start : 25, len : 3, def : ' ' },
623 BKS : {start : 7, len : 4, def : ' ' },
624 SER : {start : 8, len : 3, def : ' ' },
629 BKS : {start : 28, len : 1, def : ' ' },
630 SER : {start : 28, len : 1, def : ' ' },
631 VIS : {start : 28, len : 1, def : ' ' },
632 MAP : {start : 28, len : 1, def : ' ' },
633 COM : {start : 28, len : 1, def : ' ' },
636 BKS : {start : 11, len : 1, def : ' ' },
637 SER : {start : 11, len : 1, def : ' ' },
638 VIS : {start : 11, len : 1, def : ' ' },
639 MAP : {start : 11, len : 1, def : ' ' },
640 COM : {start : 11, len : 1, def : ' ' },
645 BKS : {start : 22, len : 1, def : ' ' },
646 SER : {start : 22, len : 1, def : ' ' },
647 VIS : {start : 22, len : 1, def : ' ' },
648 SCO : {start : 22, len : 1, def : ' ' },
649 REC : {start : 22, len : 1, def : ' ' },
650 COM : {start : 22, len : 1, def : ' ' },
653 BKS : {start : 5, len : 1, def : ' ' },
654 SER : {start : 5, len : 1, def : ' ' },
655 VIS : {start : 5, len : 1, def : ' ' },
656 SCO : {start : 5, len : 1, def : ' ' },
657 REC : {start : 5, len : 1, def : ' ' },
658 COM : {start : 5, len : 1, def : ' ' },
663 BKS : {start : 23, len : 1, def : ' ' },
664 SER : {start : 23, len : 1, def : ' ' },
665 VIS : {start : 29, len : 1, def : ' ' },
666 MIX : {start : 23, len : 1, def : ' ' },
667 MAP : {start : 29, len : 1, def : ' ' },
668 SCO : {start : 23, len : 1, def : ' ' },
669 REC : {start : 23, len : 1, def : ' ' },
672 BKS : {start : 6, len : 1, def : ' ' },
673 SER : {start : 6, len : 1, def : ' ' },
674 VIS : {start : 12, len : 1, def : ' ' },
675 MIX : {start : 6, len : 1, def : ' ' },
676 MAP : {start : 12, len : 1, def : ' ' },
677 SCO : {start : 6, len : 1, def : ' ' },
678 REC : {start : 6, len : 1, def : ' ' },
683 SER : {start : 34, len : 1, def : '0' },
686 SER : {start : 17, len : 1, def : '0' },
691 SER : {start : 33, len : 1, def : ' ' },
694 SER : {start : 16, len : 1, def : ' ' },
699 function recordType (rec) {
701 var _l = rec.leader.toString();
703 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
704 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
706 for (var t in rec_type) {
707 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
708 document.getElementById('recordTypeLabel').value = t;
714 alert('FIXME, MARC Editor, recordType: ' + E);
718 function toggleFFE () {
719 var grid = document.getElementById('leaderGrid');
728 function changeFFEditor (type) {
729 var grid = document.getElementById('leaderGrid');
730 grid.setAttribute('type',type);
733 function fillFixedFields (rec) {
735 var grid = document.getElementById('leaderGrid');
737 var rtype = _record_type;
739 var _l = rec.leader.toString();
740 var _6 = rec.controlfield.(@tag=='006').toString();
741 var _7 = rec.controlfield.(@tag=='007').toString();
742 var _8 = rec.controlfield.(@tag=='008').toString();
745 var pre_list = grid.getElementsByTagName('label');
746 for (var i in pre_list) {
747 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
748 list.push( pre_list[i] );
752 for (var i in list) {
753 var name = list[i].getAttribute('name');
759 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
760 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
762 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
763 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
765 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
766 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
768 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
769 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
774 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
775 d = ff_pos[name].ldr[rtype].def;
779 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
780 d = ff_pos[name]._8[rtype].def;
784 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
785 d = ff_pos[name]._6[rtype].def;
789 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
790 d = ff_pos[name]._7[rtype].def;
795 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
801 list[i].nextSibling.value = value;
806 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
810 function updateFixedFields (element) {
811 var grid = document.getElementById('leaderGrid');
812 var recGrid = document.getElementById('recGrid');
814 var rtype = _record_type;
815 var new_value = element.value;
818 ldr : _record.leader,
819 _6 : _record.controlfield.(@tag=='006'),
820 _7 : _record.controlfield.(@tag=='007'),
821 _8 : _record.controlfield.(@tag=='008'),
824 var name = element.getAttribute('name');
825 for (var i in ff_pos[name]) {
827 if (!ff_pos[name][i][rtype]) continue;
828 if (!parts[i]) continue;
830 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
831 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
833 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
834 new_value += ff_pos[name][i][rtype].def;
837 parts[i].setChildren( before + new_value + after );
838 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
844 function marcLeader (leader) {
846 { class : 'marcLeaderRow',
851 tooltiptext : "MARC Leader" } ),
854 class : 'marcInd1' } ),
857 class : 'marcInd2' } ),
859 { value : leader.text(),
860 class : 'marcLeader' } )
866 function marcControlfield (field) {
867 tagname = field.@tag.toString().substr(2);
869 if (tagname == '6' || tagname == '7' || tagname == '8') {
871 { class : 'marcControlfieldRow',
872 tag : '_' + tagname },
874 { value : field.@tag,
876 context : 'tags_popup',
877 onmouseover : 'getTooltip(this, "tag");',
878 tooltipid : 'tag' + field.@tag } ),
880 { value : field.@ind1,
882 onmouseover : 'getTooltip(this, "ind1");',
883 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
885 { value : field.@ind2,
887 onmouseover : 'getTooltip(this, "ind2");',
888 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
891 { value : field.text(),
892 class : 'plain marcEditableControlfield',
893 name : 'CONTROL' + tagname,
894 oncontext : 'return false();',
900 { class : 'marcControlfieldRow',
901 tag : '_' + tagname },
903 { value : field.@tag,
905 onmouseover : 'getTooltip(this, "tag");',
906 tooltipid : 'tag' + field.@tag } ),
908 { value : field.@ind1,
910 onmouseover : 'getTooltip(this, "ind1");',
911 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
913 { value : field.@ind2,
915 onmouseover : 'getTooltip(this, "ind2");',
916 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
918 { value : field.text(),
919 class : 'marcControlfield' } )
926 function stackSubfields(checkbox) {
927 var list = document.getElementsByAttribute('name','sf_box');
930 if (checkbox.checked) o = 'horizontal';
932 for (var i = 0; i < list.length; i++) {
933 if (list[i]) list[i].setAttribute('orient',o);
937 function marcDatafield (field) {
939 { class : 'marcDatafieldRow' },
942 { value : field.@tag,
943 class : 'plain marcTag',
945 context : 'tags_popup',
946 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
949 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
952 { value : field.@ind1,
953 class : 'plain marcInd1',
955 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
958 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
959 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
962 { value : field.@ind2,
963 class : 'plain marcInd2',
965 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
968 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
969 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
970 createHbox({ name : 'sf_box' })
973 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
974 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
975 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
977 var sf_box = row.lastChild;
978 if (document.getElementById('stackSubfields').checked)
979 sf_box.setAttribute('orient','vertical');
981 sf_box.addEventListener(
984 if (sf_box === e.target) {
985 sf_box.lastChild.lastChild.focus();
986 } else if (e.target.parentNode === sf_box) {
987 e.target.lastChild.focus();
994 for (var i in field.subfield) {
995 var sf = field.subfield[i];
1000 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1001 current_focus = sf_box.lastChild.childNodes[1];
1007 function marcSubfield (sf) {
1009 { class : 'marcSubfieldBox' },
1012 class : 'plain marcSubfieldDelimiter',
1013 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1014 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1015 //onclick : 'this.nextSibling.focus();',
1016 onfocus : 'this.nextSibling.focus();',
1021 class : 'plain marcSubfieldCode',
1022 name : 'marcSubfieldCode',
1023 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1024 oncontextmenu : 'getContextMenu(this, "subfield");',
1025 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1030 { value : sf.text(),
1031 name : sf.parent().@tag + ':' + sf.@code,
1032 class : 'plain marcSubfield',
1033 onmouseover : 'getTooltip(this, "subfield");',
1034 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1035 size : new String(sf.text()).length + 2,
1036 oninput : "this.setAttribute('size', this.value.length + 2);",
1041 function loadRecord(rec) {
1044 var grid_rows = document.getElementById('recGrid').lastChild;
1046 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1048 grid_rows.appendChild( marcLeader( rec.leader ) );
1050 for (var i in rec.controlfield) {
1051 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1054 for (var i in rec.datafield) {
1055 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1058 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1059 changeFFEditor(recordType(rec));
1060 fillFixedFields(rec);
1062 alert('FIXME, MARC Editor, loadRecord: ' + E);
1066 var context_menus = createComplexXULElement('popupset');
1067 document.documentElement.appendChild( context_menus );
1069 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
1070 context_menus.appendChild( tag_menu );
1072 tag_menu.appendChild(
1074 { label : 'Add Row',
1076 'var e = document.createEvent("KeyEvents");' +
1077 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
1078 'current_focus.inputField.dispatchEvent(e);',
1083 tag_menu.appendChild(
1085 { label : 'Remove Row',
1087 'var e = document.createEvent("KeyEvents");' +
1088 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
1089 'current_focus.inputField.dispatchEvent(e);',
1094 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1096 tag_menu.appendChild(
1098 { label : 'Add/Replace 006',
1100 'var e = document.createEvent("KeyEvents");' +
1101 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
1102 'current_focus.inputField.dispatchEvent(e);',
1107 tag_menu.appendChild(
1109 { label : 'Add/Replace 007',
1111 'var e = document.createEvent("KeyEvents");' +
1112 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
1113 'current_focus.inputField.dispatchEvent(e);',
1118 tag_menu.appendChild(
1120 { label : 'Add/Replace 008',
1122 'var e = document.createEvent("KeyEvents");' +
1123 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
1124 'current_focus.inputField.dispatchEvent(e);',
1129 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1133 function genToolTips () {
1134 for (var i in bib_data.field) {
1135 var f = bib_data.field[i];
1137 tag_menu.appendChild(
1141 'current_focus.value = "' + f.@tag + '";' +
1142 'var e = document.createEvent("MutationEvents");' +
1143 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1144 'current_focus.inputField.dispatchEvent(e);',
1145 disabled : f.@tag < '010' ? "true" : "false",
1146 tooltiptext : f.description }
1150 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1151 context_menus.appendChild( i1_popup );
1153 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1154 context_menus.appendChild( i2_popup );
1156 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1157 context_menus.appendChild( sf_popup );
1159 tooltip_hash['tag' + f.@tag] = f.description;
1160 for (var j in f.indicator) {
1161 var ind = f.indicator[j];
1162 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1164 if (ind.@position == 1) {
1165 i1_popup.appendChild(
1167 { label : ind.@value,
1169 'current_focus.value = "' + ind.@value + '";' +
1170 'var e = document.createEvent("MutationEvents");' +
1171 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1172 'current_focus.inputField.dispatchEvent(e);',
1173 tooltiptext : ind.description }
1178 if (ind.@position == 2) {
1179 i2_popup.appendChild(
1181 { label : ind.@value,
1183 'current_focus.value = "' + ind.@value + '";' +
1184 'var e = document.createEvent("MutationEvents");' +
1185 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1186 'current_focus.inputField.dispatchEvent(e);',
1187 tooltiptext : ind.description }
1193 for (var j in f.subfield) {
1194 var sf = f.subfield[j];
1195 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1197 sf_popup.appendChild(
1201 'current_focus.value = "' + sf.@code + '";' +
1202 'var e = document.createEvent("MutationEvents");' +
1203 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1204 'current_focus.inputField.dispatchEvent(e);',
1205 tooltiptext : sf.description,
1213 var p = createComplexXULElement('popupset');
1214 document.documentElement.appendChild( p );
1216 function getTooltip (target, type) {
1219 if (type == 'subfield')
1220 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1223 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1226 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1229 tt = 'tag' + target.parentNode.firstChild.value;
1231 if (!document.getElementById( tt )) {
1236 orient : 'vertical',
1237 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1238 class : 'tooltip' },
1239 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1244 target.tooltip = tt;
1248 function getContextMenu (target, type) {
1251 if (type == 'subfield')
1252 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1255 tt = 't' + target.parentNode.firstChild.value + 'i1';
1258 tt = 't' + target.parentNode.firstChild.value + 'i2';
1260 target.setAttribute('context', tt);
1264 var authority_tag_map = {
1265 100 : ['[100,400,500,700]',100],
1266 400 : ['[100,400,500,700]',100],
1267 700 : ['[100,400,500,700]',100],
1268 800 : ['[100,400,500,700]',100],
1269 110 : ['[110,410,510,710]',110],
1270 410 : ['[110,410,510,710]',110],
1271 710 : ['[110,410,510,710]',110],
1272 810 : ['[110,410,510,710]',110],
1273 111 : ['[111,411,511,711]',111],
1274 411 : ['[111,411,511,711]',111],
1275 711 : ['[111,411,511,711]',111],
1276 811 : ['[111,411,511,711]',111],
1277 240 : ['[130,430,530,730]',130],
1278 440 : ['[130,430,530,730]',130],
1279 130 : ['[130,430,530,730]',130],
1280 730 : ['[130,430,530,730]',130],
1281 830 : ['[130,430,530,730]',130],
1282 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1283 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1284 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1285 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1288 function getAuthorityContextMenu (target, sf) {
1289 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1291 var old = document.getElementById( menu_id );
1292 if (old) old.parentNode.removeChild(old);
1294 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1295 context_menus.appendChild( sf_popup );
1297 if (!authority_tag_map[sf.parent().@tag]) {
1298 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1299 target.setAttribute('context', menu_id);
1303 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1305 var res = new XML( auth_data.responseText );
1309 var recs = res.gw::payload.gw::array.gw::string;
1310 for (var i in recs) {
1312 var xml = new XML(x.toString());
1313 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1315 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1318 for (var i in main) {
1319 if (main_text) main_text += ' / ';
1320 main_text += main[i];
1323 rec_list.push( [ main_text, xml ] );
1326 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1328 var main_text = rec_list[i][0];
1329 var xml = rec_list[i][1];
1330 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1332 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1334 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1335 grid.setAttribute('name','-none-');
1336 grid.setAttribute('style','overflow:scroll');
1339 var submenu = createMenu( { label : main_text } );
1341 var popup = createMenuPopup({ flex : "1" });
1342 submenu.appendChild(popup);
1344 var fields = xml.datafield;
1345 for (var j in fields) {
1347 var row = createRow(
1349 createLabel( { value : fields[j].@tag } ),
1350 createLabel( { value : fields[j].@ind1 } ),
1351 createLabel( { value : fields[j].@ind2 } )
1354 var sf_box = createHbox();
1356 var subfields = fields[j].subfield;
1357 for (var k in subfields) {
1360 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1361 subfield : subfields[k].@code,
1362 tag : subfields[k].parent().@tag,
1363 value : subfields[k]
1367 row.appendChild(sf_box);
1370 grid.lastChild.appendChild(row);
1373 grid.hidden = false;
1374 popup.appendChild( grid );
1378 { label : 'Apply Selected',
1379 command : function (event) {
1380 applyAuthority(event.target.previousSibling, target, sf);
1387 sf_popup.appendChild( submenu );
1390 if (sf_popup.childNodes.length == 0)
1391 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1393 target.setAttribute('context', menu_id);
1397 function applyAuthority ( target, ui_sf, e4x_sf ) {
1399 var new_vals = target.getElementsByAttribute('checked','true');
1400 var field = e4x_sf.parent();
1402 for (var i = 0; i < new_vals.length; i++) {
1404 var sf_list = field.subfield;
1405 for (var j in sf_list) {
1407 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1408 sf_list[j] = new_vals[i].getAttribute('value');
1409 new_vals[i].setAttribute('subfield','');
1415 for (var i = 0; i < new_vals.length; i++) {
1416 if (!new_vals[i].getAttribute('subfield')) continue;
1418 var val = new_vals[i].getAttribute('value');
1420 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1421 sf.@code = new_vals[i].getAttribute('subfield');
1423 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1426 var row = marcDatafield( field );
1429 while (node.nodeName != 'row') {
1430 node = node.parentNode;
1433 node.parentNode.replaceChild( row, node );
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 'd' : { 130 : 'd' },
1455 'a' : { 130 : 'a' },
1456 'd' : { 130 : 'd' },
1459 'a' : { 100 : 'a' },
1460 'd' : { 100 : 'd' },
1463 'a' : { 110 : 'a' },
1464 'd' : { 110 : 'd' },
1467 'a' : { 111 : 'a' },
1468 'd' : { 111 : 'd' },
1471 'a' : { 130 : 'a' },
1472 'n' : { 130 : 'n' },
1473 'p' : { 130 : 'p' },
1476 'a' : { 100 : 'a' },
1477 'd' : { 100 : 'd' },
1480 'a' : { 110 : 'a' },
1481 'd' : { 110 : 'd' },
1484 'a' : { 111 : 'a' },
1485 'd' : { 111 : 'd' },
1488 'a' : { 130 : 'a' },
1489 'd' : { 130 : 'd' },
1492 'a' : { 100 : 'a' },
1493 'd' : { 100 : 'd' },
1496 'a' : { 110 : 'a' },
1497 'd' : { 110 : 'd' },
1500 'a' : { 111 : 'a' },
1501 'd' : { 111 : 'd' },
1504 'a' : { 130 : 'a' },
1505 'd' : { 130 : 'd' },
1508 'a' : { 100 : 'a' },
1509 'd' : { 100 : 'd' },
1510 't' : { 100 : 't' },
1537 'a' : { 150 : 'a' },
1538 'b' : { 150 : 'b' },
1565 'a' : { 151 : 'a' },
1592 'a' : { 155 : 'a' },
1620 function validateAuthority (button) {
1621 var grid = document.getElementById('recGrid');
1622 var label = button.getAttribute('label');
1625 var rows = grid.lastChild.childNodes;
1626 for (var i = 0; i < rows.length; i++) {
1628 var tag = row.firstChild;
1630 if (!control_map[tag.value]) continue
1632 var ind1 = tag.nextSibling;
1633 var ind2 = ind1.nextSibling;
1634 var subfields = ind2.nextSibling.childNodes;
1636 for (var j = 0; j < subfields.length; j++) {
1637 var sf = subfields[j];
1639 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1641 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1644 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1645 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1646 var res = new XML( x.responseText );
1648 if (res.gw::payload.gw::array.gw::string.length()) {
1655 sf.childNodes[2].inputField.style.color = 'red';
1657 sf.childNodes[2].inputField.style.color = 'black';
1662 button.setAttribute('label', label);
1668 function searchAuthority (term, tag, sf, limit) {
1669 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1670 url += '¶m="term"¶m="' + term + '"';
1671 url += '¶m="limit"¶m=' + limit;
1672 url += '¶m="tag"¶m=' + tag;
1673 url += '¶m="subfield"¶m="' + sf + '"';
1676 var req = new XMLHttpRequest();
1677 req.open('GET',url,false);