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;
18 // Fake xulG for standalone...
23 window.xulG.record = {};
24 window.xulG.save = {};
26 window.xulG.save.label = 'Save Record';
27 window.xulG.save.func = function (r) { alert(r); }
30 var _rid = cgi.param('record');
32 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
37 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
38 document.getElementById('save-button').setAttribute('oncommand', 'window.xulG.save.func(xml_record.toXMLString())');
40 if (window.xulG.record.url) {
41 var req = new XMLHttpRequest();
42 req.open('GET',window.xulG.record.url,false);
44 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
47 xml_record = new XML( window.xulG.record.marc );
48 if (xml_record..record[0]) xml_record = xml_record..record[0];
50 // Get the tooltip xml all async like
51 req = new XMLHttpRequest();
52 req.open('GET','marcedit-tooltips.xml',true);
53 req.onreadystatechange = function () {
54 if (req.readyState == 4) {
55 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
61 loadRecord(xml_record);
63 alert('FIXME, MARC Editor, my_init: ' + E);
68 function createComplexHTMLElement (e, attrs, objects, text) {
69 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
72 for (var i in attrs) l.setAttribute(i,attrs[i]);
76 for ( var i in objects ) l.appendChild( objects[i] );
80 l.appendChild( document.createTextNode(text) )
86 function createComplexXULElement (e, attrs, objects) {
87 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
90 for (var i in attrs) {
91 if (typeof attrs[i] == 'function') {
92 l.addEventListener( i, attrs[i], true );
94 l.setAttribute(i,attrs[i]);
100 for ( var i in objects ) l.appendChild( objects[i] );
106 function createDescription (attrs) {
107 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
110 function createTooltip (attrs) {
111 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
114 function createLabel (attrs) {
115 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
118 function createVbox (attrs) {
119 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
122 function createHbox (attrs) {
123 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
126 function createRow (attrs) {
127 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
130 function createTextbox (attrs) {
131 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
134 function createMenu (attrs) {
135 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
138 function createMenuPopup (attrs) {
139 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
142 function createPopup (attrs) {
143 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
146 function createMenuitem (attrs) {
147 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
150 function createCheckbox (attrs) {
151 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
154 function createMARCTextbox (element,attrs) {
156 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
157 box.onkeypress = function (event) {
160 while(node = node.parent()) {
164 var row = event.target;
165 while (row.tagName != 'row') row = row.parentNode;
167 if (element.nodeKind() == 'attribute') element[0]=box.value;
168 else element.setChildren( box.value );
170 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
172 var index_sf, target, move_data;
173 if (element.localName() == 'subfield') {
175 target = event.target.parentNode;
177 var start = event.target.selectionStart;
178 var end = event.target.selectionEnd - event.target.selectionStart ?
179 event.target.selectionEnd :
180 event.target.value.length;
182 move_data = event.target.value.substring(start,end);
183 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
184 event.target.setAttribute('size', event.target.value.length + 2);
186 element.setChildren( event.target.value );
188 } else if (element.localName() == 'code') {
189 index_sf = element.parent();
190 target = event.target.parentNode;
191 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
192 index_sf = element.parent().children()[element.parent().children().length() - 1];
193 target = event.target.parentNode.lastChild.lastChild;
196 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
198 index_sf.parent().insertChildAfter( index_sf, sf );
200 var new_sf = marcSubfield(sf);
202 if (target === target.parentNode.lastChild) {
203 target.parentNode.appendChild( new_sf );
205 target.parentNode.insertBefore( new_sf, target.nextSibling );
208 new_sf.firstChild.nextSibling.focus();
210 event.preventDefault();
213 } else if (event.keyCode == 13 || event.keyCode == 77) {
214 if (event.ctrlKey) { // ctrl+enter
217 if (element.localName() == 'subfield') index = element.parent();
218 if (element.localName() == 'code') index = element.parent().parent();
219 if (element.localName() == 'tag') index = element.parent();
220 if (element.localName() == 'ind1') index = element.parent();
221 if (element.localName() == 'ind2') index = element.parent();
223 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
225 index.parent().insertChildAfter( index, df );
227 var new_df = marcDatafield(df);
229 if (row.parentNode.lastChild === row) {
230 row.parentNode.appendChild( new_df );
232 row.parentNode.insertBefore( new_df, row.nextSibling );
235 new_df.firstChild.focus();
237 event.preventDefault();
240 } else if (event.shiftKey) {
241 if (row.previousSibling.className.match('marcDatafieldRow'))
242 row.previousSibling.firstChild.focus();
244 row.nextSibling.firstChild.focus();
247 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
250 if (element.localName() == 'subfield') index = element.parent();
251 if (element.localName() == 'code') index = element.parent().parent();
252 if (element.localName() == 'tag') index = element.parent();
253 if (element.localName() == 'ind1') index = element.parent();
254 if (element.localName() == 'ind2') index = element.parent();
256 for (var i in index.parent().children()) {
257 if (index === index.parent().children()[i]) {
258 delete index.parent().children()[i];
263 row.previousSibling.firstChild.focus();
264 row.parentNode.removeChild(row);
266 event.preventDefault();
269 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
272 if (element.localName() == 'subfield') index = element;
273 if (element.localName() == 'code') index = element.parent();
276 for (var i in index.parent().children()) {
277 if (index === index.parent().children()[i]) {
278 delete index.parent().children()[i];
283 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
284 event.target.parentNode.previousSibling.lastChild.focus();
286 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
289 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
291 event.preventDefault();
298 box.addEventListener(
301 if (element.nodeKind() == 'attribute') element[0]=box.value;
302 else element.setChildren( box.value );
308 box.addEventListener(
311 if (element.nodeKind() == 'attribute') element[0]=box.value;
312 else element.setChildren( box.value );
318 box.addEventListener(
321 if (element.nodeKind() == 'attribute') element[0]=box.value;
322 else element.setChildren( box.value );
332 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
333 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
334 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
335 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
336 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
337 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
338 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
339 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
345 BKS : {start : 15, len : 3, def : ' ' },
346 SER : {start : 15, len : 3, def : ' ' },
347 VIS : {start : 15, len : 3, def : ' ' },
348 MIX : {start : 15, len : 3, def : ' ' },
349 MAP : {start : 15, len : 3, def : ' ' },
350 SCO : {start : 15, len : 3, def : ' ' },
351 REC : {start : 15, len : 3, def : ' ' },
352 COM : {start : 15, len : 3, def : ' ' },
357 BKS : {start : 35, len : 3, def : ' ' },
358 SER : {start : 35, len : 3, def : ' ' },
359 VIS : {start : 35, len : 3, def : ' ' },
360 MIX : {start : 35, len : 3, def : ' ' },
361 MAP : {start : 35, len : 3, def : ' ' },
362 SCO : {start : 35, len : 3, def : ' ' },
363 REC : {start : 35, len : 3, def : ' ' },
364 COM : {start : 35, len : 3, def : ' ' },
369 BKS : {start : 38, len : 1, def : ' ' },
370 SER : {start : 38, len : 1, def : ' ' },
371 VIS : {start : 38, len : 1, def : ' ' },
372 MIX : {start : 38, len : 1, def : ' ' },
373 MAP : {start : 38, len : 1, def : ' ' },
374 SCO : {start : 38, len : 1, def : ' ' },
375 REC : {start : 38, len : 1, def : ' ' },
376 COM : {start : 38, len : 1, def : ' ' },
381 BKS : {start : 6, len : 1, def : ' ' },
382 SER : {start : 6, len : 1, def : 'c' },
383 VIS : {start : 6, len : 1, def : ' ' },
384 MIX : {start : 6, len : 1, def : ' ' },
385 MAP : {start : 6, len : 1, def : ' ' },
386 SCO : {start : 6, len : 1, def : ' ' },
387 REC : {start : 6, len : 1, def : ' ' },
388 COM : {start : 6, len : 1, def : ' ' },
393 BKS : {start : 6, len : 1, def : 'a' },
394 SER : {start : 6, len : 1, def : 'a' },
395 VIS : {start : 6, len : 1, def : 'g' },
396 MIX : {start : 6, len : 1, def : 'p' },
397 MAP : {start : 6, len : 1, def : 'e' },
398 SCO : {start : 6, len : 1, def : 'c' },
399 REC : {start : 6, len : 1, def : 'i' },
400 COM : {start : 6, len : 1, def : 'm' },
405 BKS : {start : 8, len : 1, def : ' ' },
406 SER : {start : 8, len : 1, def : ' ' },
407 VIS : {start : 8, len : 1, def : ' ' },
408 MIX : {start : 8, len : 1, def : ' ' },
409 MAP : {start : 8, len : 1, def : ' ' },
410 SCO : {start : 8, len : 1, def : ' ' },
411 REC : {start : 8, len : 1, def : ' ' },
412 COM : {start : 8, len : 1, def : ' ' },
417 BKS : {start : 7, len : 1, def : 'm' },
418 SER : {start : 7, len : 1, def : 's' },
419 VIS : {start : 7, len : 1, def : 'm' },
420 MIX : {start : 7, len : 1, def : 'c' },
421 MAP : {start : 7, len : 1, def : 'm' },
422 SCO : {start : 7, len : 1, def : 'm' },
423 REC : {start : 7, len : 1, def : 'm' },
424 COM : {start : 7, len : 1, def : 'm' },
429 BKS : {start : 18, len : 1, def : ' ' },
430 SER : {start : 18, len : 1, def : ' ' },
431 VIS : {start : 18, len : 1, def : ' ' },
432 MIX : {start : 18, len : 1, def : ' ' },
433 MAP : {start : 18, len : 1, def : ' ' },
434 SCO : {start : 18, len : 1, def : ' ' },
435 REC : {start : 18, len : 1, def : ' ' },
436 COM : {start : 18, len : 1, def : ' ' },
441 BKS : {start : 17, len : 1, def : ' ' },
442 SER : {start : 17, len : 1, def : ' ' },
443 VIS : {start : 17, len : 1, def : ' ' },
444 MIX : {start : 17, len : 1, def : ' ' },
445 MAP : {start : 17, len : 1, def : ' ' },
446 SCO : {start : 17, len : 1, def : ' ' },
447 REC : {start : 17, len : 1, def : ' ' },
448 COM : {start : 17, len : 1, def : ' ' },
453 BKS : {start : 31, len : 1, def : '0' },
454 MAP : {start : 31, len : 1, def : '0' },
457 BKS : {start : 14, len : 1, def : '0' },
458 MAP : {start : 14, len : 1, def : '0' },
463 BKS : {start : 7, len : 4, def : ' ' },
464 SER : {start : 7, len : 4, def : ' ' },
465 VIS : {start : 7, len : 4, def : ' ' },
466 MIX : {start : 7, len : 4, def : ' ' },
467 MAP : {start : 7, len : 4, def : ' ' },
468 SCO : {start : 7, len : 4, def : ' ' },
469 REC : {start : 7, len : 4, def : ' ' },
470 COM : {start : 7, len : 4, def : ' ' },
475 BKS : {start : 11, len : 4, def : ' ' },
476 SER : {start : 11, len : 4, def : '9' },
477 VIS : {start : 11, len : 4, def : ' ' },
478 MIX : {start : 11, len : 4, def : ' ' },
479 MAP : {start : 11, len : 4, def : ' ' },
480 SCO : {start : 11, len : 4, def : ' ' },
481 REC : {start : 11, len : 4, def : ' ' },
482 COM : {start : 11, len : 4, def : ' ' },
487 BKS : {start : 33, len : 1, def : '0' },
490 BKS : {start : 16, len : 1, def : '0' },
495 BKS : {start : 34, len : 1, def : ' ' },
498 BKS : {start : 17, len : 1, def : ' ' },
503 BKS : {start : 18, len : 4, def : ' ' },
506 BKS : {start : 1, len : 4, def : ' ' },
511 BKS : {start : 30, len : 1, def : '0' },
514 BKS : {start : 13, len : 1, def : '0' },
519 BKS : {start : 24, len : 4, def : ' ' },
520 SER : {start : 25, len : 3, def : ' ' },
523 BKS : {start : 7, len : 4, def : ' ' },
524 SER : {start : 8, len : 3, def : ' ' },
529 BKS : {start : 28, len : 1, def : ' ' },
530 SER : {start : 28, len : 1, def : ' ' },
531 VIS : {start : 28, len : 1, def : ' ' },
532 MAP : {start : 28, len : 1, def : ' ' },
533 COM : {start : 28, len : 1, def : ' ' },
536 BKS : {start : 11, len : 1, def : ' ' },
537 SER : {start : 11, len : 1, def : ' ' },
538 VIS : {start : 11, len : 1, def : ' ' },
539 MAP : {start : 11, len : 1, def : ' ' },
540 COM : {start : 11, len : 1, def : ' ' },
545 BKS : {start : 22, len : 1, def : ' ' },
546 SER : {start : 22, len : 1, def : ' ' },
547 VIS : {start : 22, len : 1, def : ' ' },
548 SCO : {start : 22, len : 1, def : ' ' },
549 REC : {start : 22, len : 1, def : ' ' },
550 COM : {start : 22, len : 1, def : ' ' },
553 BKS : {start : 5, len : 1, def : ' ' },
554 SER : {start : 5, len : 1, def : ' ' },
555 VIS : {start : 5, len : 1, def : ' ' },
556 SCO : {start : 5, len : 1, def : ' ' },
557 REC : {start : 5, len : 1, def : ' ' },
558 COM : {start : 5, len : 1, def : ' ' },
563 BKS : {start : 23, len : 1, def : ' ' },
564 SER : {start : 23, len : 1, def : ' ' },
565 VIS : {start : 29, len : 1, def : ' ' },
566 MIX : {start : 23, len : 1, def : ' ' },
567 MAP : {start : 29, len : 1, def : ' ' },
568 SCO : {start : 23, len : 1, def : ' ' },
569 REC : {start : 23, len : 1, def : ' ' },
572 BKS : {start : 6, len : 1, def : ' ' },
573 SER : {start : 6, len : 1, def : ' ' },
574 VIS : {start : 12, len : 1, def : ' ' },
575 MIX : {start : 6, len : 1, def : ' ' },
576 MAP : {start : 12, len : 1, def : ' ' },
577 SCO : {start : 6, len : 1, def : ' ' },
578 REC : {start : 6, len : 1, def : ' ' },
583 SER : {start : 34, len : 1, def : '0' },
586 SER : {start : 17, len : 1, def : '0' },
591 SER : {start : 33, len : 1, def : ' ' },
594 SER : {start : 16, len : 1, def : ' ' },
599 function recordType (rec) {
601 var _l = rec.leader.toString();
603 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
604 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
606 for (var t in rec_type) {
607 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
608 document.getElementById('recordTypeLabel').value = t;
614 alert('FIXME, MARC Editor, recordType: ' + E);
618 function toggleFFE () {
619 var grid = document.getElementById('leaderGrid');
628 function changeFFEditor (type) {
629 var grid = document.getElementById('leaderGrid');
630 grid.setAttribute('type',type);
633 function fillFixedFields (rec) {
635 var grid = document.getElementById('leaderGrid');
637 var rtype = _record_type;
639 var _l = rec.leader.toString();
640 var _6 = rec.controlfield.(@tag=='006').toString();
641 var _7 = rec.controlfield.(@tag=='007').toString();
642 var _8 = rec.controlfield.(@tag=='008').toString();
645 var pre_list = grid.getElementsByTagName('label');
646 for (var i in pre_list) {
647 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
648 list.push( pre_list[i] );
652 for (var i in list) {
653 var name = list[i].getAttribute('name');
659 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
660 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
662 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
663 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
665 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
666 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
668 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
669 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
674 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
675 d = ff_pos[name].ldr[rtype].def;
679 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
680 d = ff_pos[name]._8[rtype].def;
684 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
685 d = ff_pos[name]._6[rtype].def;
689 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
690 d = ff_pos[name]._7[rtype].def;
695 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
701 list[i].nextSibling.value = value;
706 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
710 function updateFixedFields (element) {
711 var grid = document.getElementById('leaderGrid');
712 var recGrid = document.getElementById('recGrid');
714 var rtype = _record_type;
715 var new_value = element.value;
718 ldr : _record.leader,
719 _6 : _record.controlfield.(@tag=='006'),
720 _7 : _record.controlfield.(@tag=='007'),
721 _8 : _record.controlfield.(@tag=='008'),
724 var name = element.getAttribute('name');
725 for (var i in ff_pos[name]) {
727 if (!ff_pos[name][i][rtype]) continue;
728 if (!parts[i]) continue;
730 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
731 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
733 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
734 new_value += ff_pos[name][i][rtype].def;
737 parts[i].setChildren( before + new_value + after );
738 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
744 function marcLeader (leader) {
746 { class : 'marcLeaderRow',
751 tooltiptext : "MARC Leader" } ),
754 class : 'marcInd1' } ),
757 class : 'marcInd2' } ),
759 { value : leader.text(),
760 class : 'marcLeader' } )
766 function marcControlfield (field) {
767 tagname = field.@tag.toString().substr(2);
769 { class : 'marcControlfieldRow',
770 tag : '_' + tagname },
772 { value : field.@tag,
774 onmouseover : 'getTooltip(this, "tag");',
775 tooltipid : 'tag' + field.@tag } ),
777 { value : field.@ind1,
779 onmouseover : 'getTooltip(this, "ind1");',
780 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
782 { value : field.@ind2,
784 onmouseover : 'getTooltip(this, "ind2");',
785 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
787 { value : field.text(),
788 class : 'marcControlfield' } )
794 function stackSubfields(checkbox) {
795 var list = document.getElementsByAttribute('name','sf_box');
798 if (checkbox.checked) o = 'horizontal';
800 for (var i = 0; i < list.length; i++) {
801 if (list[i]) list[i].setAttribute('orient',o);
805 function marcDatafield (field) {
807 { class : 'marcDatafieldRow' },
810 { value : field.@tag,
811 class : 'plain marcTag',
813 context : 'tags_popup',
814 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
817 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
820 { value : field.@ind1,
821 class : 'plain marcInd1',
823 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
826 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
827 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
830 { value : field.@ind2,
831 class : 'plain marcInd2',
833 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
836 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
837 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
838 createHbox({ name : 'sf_box' })
841 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
842 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
843 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
845 var sf_box = row.lastChild;
846 if (document.getElementById('stackSubfields').checked)
847 sf_box.setAttribute('orient','vertical');
849 sf_box.addEventListener(
852 if (sf_box === e.target) {
853 sf_box.lastChild.lastChild.focus();
854 } else if (e.target.parentNode === sf_box) {
855 e.target.lastChild.focus();
862 for (var i in field.subfield) {
863 var sf = field.subfield[i];
868 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
869 current_focus = sf_box.lastChild.childNodes[1];
875 function marcSubfield (sf) {
877 { class : 'marcSubfieldBox' },
880 class : 'plain marcSubfieldDelimiter',
881 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
882 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
883 //onclick : 'this.nextSibling.focus();',
884 onfocus : 'this.nextSibling.focus();',
889 class : 'plain marcSubfieldCode',
890 name : 'marcSubfieldCode',
891 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
892 oncontextmenu : 'getContextMenu(this, "subfield");',
893 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
899 name : sf.parent().@tag + ':' + sf.@code,
900 class : 'plain marcSubfield',
901 onmouseover : 'getTooltip(this, "subfield");',
902 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
903 size : new String(sf.text()).length + 2,
904 oninput : "this.setAttribute('size', this.value.length + 2);",
909 function loadRecord(rec) {
912 var grid_rows = document.getElementById('recGrid').lastChild;
914 grid_rows.appendChild( marcLeader( rec.leader ) );
916 for (var i in rec.controlfield) {
917 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
920 for (var i in rec.datafield) {
921 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
924 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
925 changeFFEditor(recordType(rec));
926 fillFixedFields(rec);
928 alert('FIXME, MARC Editor, loadRecord: ' + E);
932 var context_menus = createComplexXULElement('popupset');
933 document.documentElement.appendChild( context_menus );
935 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
936 context_menus.appendChild( tag_menu );
938 tag_menu.appendChild(
942 'var e = document.createEvent("KeyEvents");' +
943 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
944 'current_focus.inputField.dispatchEvent(e);',
949 tag_menu.appendChild(
951 { label : 'Remove Row',
953 'var e = document.createEvent("KeyEvents");' +
954 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
955 'current_focus.inputField.dispatchEvent(e);',
960 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
964 function genToolTips () {
965 for (var i in bib_data.field) {
966 var f = bib_data.field[i];
968 tag_menu.appendChild(
972 'current_focus.value = "' + f.@tag + '";' +
973 'var e = document.createEvent("MutationEvents");' +
974 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
975 'current_focus.inputField.dispatchEvent(e);',
976 disabled : f.@tag < '010' ? "true" : "false",
977 tooltiptext : f.description }
981 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
982 context_menus.appendChild( i1_popup );
984 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
985 context_menus.appendChild( i2_popup );
987 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
988 context_menus.appendChild( sf_popup );
990 tooltip_hash['tag' + f.@tag] = f.description;
991 for (var j in f.indicator) {
992 var ind = f.indicator[j];
993 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
995 if (ind.@position == 1) {
996 i1_popup.appendChild(
998 { label : ind.@value,
1000 'current_focus.value = "' + ind.@value + '";' +
1001 'var e = document.createEvent("MutationEvents");' +
1002 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1003 'current_focus.inputField.dispatchEvent(e);',
1004 tooltiptext : ind.description }
1009 if (ind.@position == 2) {
1010 i2_popup.appendChild(
1012 { label : ind.@value,
1014 'current_focus.value = "' + ind.@value + '";' +
1015 'var e = document.createEvent("MutationEvents");' +
1016 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1017 'current_focus.inputField.dispatchEvent(e);',
1018 tooltiptext : ind.description }
1024 for (var j in f.subfield) {
1025 var sf = f.subfield[j];
1026 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1028 sf_popup.appendChild(
1032 'current_focus.value = "' + sf.@code + '";' +
1033 'var e = document.createEvent("MutationEvents");' +
1034 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1035 'current_focus.inputField.dispatchEvent(e);',
1036 tooltiptext : sf.description,
1044 var p = createComplexXULElement('popupset');
1045 document.documentElement.appendChild( p );
1047 function getTooltip (target, type) {
1050 if (type == 'subfield')
1051 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1054 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1057 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1060 tt = 'tag' + target.parentNode.firstChild.value;
1062 if (!document.getElementById( tt )) {
1067 orient : 'vertical',
1068 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1069 class : 'tooltip' },
1070 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1075 target.tooltip = tt;
1079 function getContextMenu (target, type) {
1082 if (type == 'subfield')
1083 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1086 tt = 't' + target.parentNode.firstChild.value + 'i1';
1089 tt = 't' + target.parentNode.firstChild.value + 'i2';
1091 target.setAttribute('context', tt);
1095 var authority_tag_map = {
1096 100 : ['[100,400,500,700]',100],
1097 400 : ['[100,400,500,700]',100],
1098 700 : ['[100,400,500,700]',100],
1099 800 : ['[100,400,500,700]',100],
1100 110 : ['[110,410,510,710]',110],
1101 410 : ['[110,410,510,710]',110],
1102 710 : ['[110,410,510,710]',110],
1103 810 : ['[110,410,510,710]',110],
1104 111 : ['[111,411,511,711]',111],
1105 411 : ['[111,411,511,711]',111],
1106 711 : ['[111,411,511,711]',111],
1107 811 : ['[111,411,511,711]',111],
1108 240 : ['[130,430,530,730]',130],
1109 440 : ['[130,430,530,730]',130],
1110 130 : ['[130,430,530,730]',130],
1111 730 : ['[130,430,530,730]',130],
1112 830 : ['[130,430,530,730]',130],
1113 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1114 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1115 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1116 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1119 function getAuthorityContextMenu (target, sf) {
1120 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1122 var old = document.getElementById( menu_id );
1123 if (old) old.parentNode.removeChild(old);
1125 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1126 context_menus.appendChild( sf_popup );
1128 if (!authority_tag_map[sf.parent().@tag]) {
1129 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1130 target.setAttribute('context', menu_id);
1134 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1136 var res = new XML( auth_data.responseText );
1140 var recs = res.gw::payload.gw::array.gw::string;
1141 for (var i in recs) {
1143 var xml = new XML(x.toString());
1144 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1146 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1149 for (var i in main) {
1150 if (main_text) main_text += ' / ';
1151 main_text += main[i];
1154 rec_list.push( [ main_text, xml ] );
1157 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1159 var main_text = rec_list[i][0];
1160 var xml = rec_list[i][1];
1161 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1163 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1165 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1166 grid.setAttribute('name','-none-');
1167 grid.setAttribute('style','overflow:scroll');
1170 var submenu = createMenu( { label : main_text } );
1172 var popup = createMenuPopup({ flex : "1" });
1173 submenu.appendChild(popup);
1175 var fields = xml.datafield;
1176 for (var j in fields) {
1178 var row = createRow(
1180 createLabel( { value : fields[j].@tag } ),
1181 createLabel( { value : fields[j].@ind1 } ),
1182 createLabel( { value : fields[j].@ind2 } )
1185 var sf_box = createHbox();
1187 var subfields = fields[j].subfield;
1188 for (var k in subfields) {
1191 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1192 subfield : subfields[k].@code,
1193 tag : subfields[k].parent().@tag,
1194 value : subfields[k]
1198 row.appendChild(sf_box);
1201 grid.lastChild.appendChild(row);
1204 grid.hidden = false;
1205 popup.appendChild( grid );
1209 { label : 'Apply Selected',
1210 command : function (event) {
1211 applyAuthority(event.target.previousSibling, target, sf);
1218 sf_popup.appendChild( submenu );
1221 if (sf_popup.childNodes.length == 0)
1222 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1224 target.setAttribute('context', menu_id);
1228 function applyAuthority ( target, ui_sf, e4x_sf ) {
1230 var new_vals = target.getElementsByAttribute('checked','true');
1231 var field = e4x_sf.parent();
1233 for (var i = 0; i < new_vals.length; i++) {
1235 var sf_list = field.subfield;
1236 for (var j in sf_list) {
1238 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1239 sf_list[j] = new_vals[i].getAttribute('value');
1240 new_vals[i].setAttribute('subfield','');
1246 for (var i = 0; i < new_vals.length; i++) {
1247 if (!new_vals[i].getAttribute('subfield')) continue;
1249 var val = new_vals[i].getAttribute('value');
1251 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1252 sf.@code = new_vals[i].getAttribute('subfield');
1254 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1257 var row = marcDatafield( field );
1260 while (node.nodeName != 'row') {
1261 node = node.parentNode;
1264 node.parentNode.replaceChild( row, node );
1270 'a' : { 100 : 'a' },
1271 'd' : { 100 : 'd' },
1274 'a' : { 110 : 'a' },
1275 'd' : { 110 : 'd' },
1278 'a' : { 111 : 'a' },
1279 'd' : { 111 : 'd' },
1282 'a' : { 130 : 'a' },
1283 'd' : { 130 : 'd' },
1286 'a' : { 130 : 'a' },
1287 'd' : { 130 : 'd' },
1290 'a' : { 100 : 'a' },
1291 'd' : { 100 : 'd' },
1294 'a' : { 110 : 'a' },
1295 'd' : { 110 : 'd' },
1298 'a' : { 111 : 'a' },
1299 'd' : { 111 : 'd' },
1302 'a' : { 130 : 'a' },
1303 'n' : { 130 : 'n' },
1304 'p' : { 130 : 'p' },
1307 'a' : { 100 : 'a' },
1308 'd' : { 100 : 'd' },
1311 'a' : { 110 : 'a' },
1312 'd' : { 110 : 'd' },
1315 'a' : { 111 : 'a' },
1316 'd' : { 111 : 'd' },
1319 'a' : { 130 : 'a' },
1320 'd' : { 130 : 'd' },
1323 'a' : { 100 : 'a' },
1324 'd' : { 100 : 'd' },
1327 'a' : { 110 : 'a' },
1328 'd' : { 110 : 'd' },
1331 'a' : { 111 : 'a' },
1332 'd' : { 111 : 'd' },
1335 'a' : { 130 : 'a' },
1336 'd' : { 130 : 'd' },
1339 'a' : { 100 : 'a' },
1340 'd' : { 100 : 'd' },
1341 't' : { 100 : 't' },
1368 'a' : { 150 : 'a' },
1369 'b' : { 150 : 'b' },
1396 'a' : { 151 : 'a' },
1423 'a' : { 155 : 'a' },
1451 function validateAuthority (button) {
1452 var grid = document.getElementById('recGrid');
1453 var label = button.getAttribute('label');
1456 var rows = grid.lastChild.childNodes;
1457 for (var i = 0; i < rows.length; i++) {
1459 var tag = row.firstChild;
1461 if (!control_map[tag.value]) continue
1463 var ind1 = tag.nextSibling;
1464 var ind2 = ind1.nextSibling;
1465 var subfields = ind2.nextSibling.childNodes;
1467 for (var j = 0; j < subfields.length; j++) {
1468 var sf = subfields[j];
1470 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1472 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1475 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1476 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1477 var res = new XML( x.responseText );
1479 if (res.gw::payload.gw::array.gw::string.length()) {
1486 sf.childNodes[2].inputField.style.color = 'red';
1488 sf.childNodes[2].inputField.style.color = 'black';
1493 button.setAttribute('label', label);
1499 function searchAuthority (term, tag, sf, limit) {
1500 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1501 url += '¶m="term"¶m="' + term + '"';
1502 url += '¶m="limit"¶m=' + limit;
1503 url += '¶m="tag"¶m=' + tag;
1504 url += '¶m="subfield"¶m="' + sf + '"';
1507 var req = new XMLHttpRequest();
1508 req.open('GET',url,false);