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 SCO : {start : 33, len : 1, def : ' ' },
436 REC : {start : 33, len : 1, def : 'n' },
439 SCO : {start : 16, len : 1, def : ' ' },
440 REC : {start : 16, len : 1, def : 'n' },
445 VIS : {start : 33, len : 1, def : ' ' },
448 VIS : {start : 16, len : 1, def : ' ' },
453 VIS : {start : 18, len : 3, def : ' ' },
456 VIS : {start : 1, len : 3, def : ' ' },
461 VIS : {start : 34, len : 1, def : 'n' },
464 VIS : {start : 17, len : 1, def : 'n' },
469 SER : {start : 21, len : 1, def : ' ' },
472 SER : {start : 4, len : 1, def : ' ' },
477 BKS : {start : 39, len : 1, def : 'd' },
478 SER : {start : 39, len : 1, def : 'd' },
479 VIS : {start : 39, len : 1, def : 'd' },
480 MIX : {start : 39, len : 1, def : 'd' },
481 MAP : {start : 39, len : 1, def : 'd' },
482 SCO : {start : 39, len : 1, def : 'd' },
483 REC : {start : 39, len : 1, def : 'd' },
484 COM : {start : 39, len : 1, def : 'd' },
489 MAP : {start : 33, len : 2, def : ' ' },
492 MAP : {start : 16, len : 2, def : ' ' },
497 MAP : {start : 18, len : 4, def : ' ' },
500 MAP : {start : 1, len : 4, def : ' ' },
505 SER : {start : 19, len : 1, def : ' ' },
508 SER : {start : 2, len : 1, def : ' ' },
513 MAP : {start : 22, len : 2, def : ' ' },
516 MAP : {start : 5, len : 2, def : ' ' },
521 SCO : {start : 21, len : 1, def : ' ' },
522 REC : {start : 21, len : 1, def : 'n' },
525 SCO : {start : 4, len : 1, def : ' ' },
526 REC : {start : 4, len : 1, def : 'n' },
531 SER : {start : 22, len : 1, def : ' ' },
534 SER : {start : 5, len : 1, def : ' ' },
539 SCO : {start : 30, len : 2, def : ' ' },
540 REC : {start : 30, len : 2, def : ' ' },
543 SCO : {start : 13, len : 2, def : ' ' },
544 REC : {start : 13, len : 2, def : ' ' },
549 SER : {start : 18, len : 1, def : ' ' },
552 SER : {start : 1, len : 1, def : ' ' },
557 SCO : {start : 20, len : 1, def : ' ' },
558 REC : {start : 20, len : 1, def : 'n' },
561 SCO : {start : 3, len : 1, def : ' ' },
562 REC : {start : 3, len : 1, def : 'n' },
567 COM : {start : 26, len : 1, def : 'u' },
570 COM : {start : 9, len : 1, def : 'u' },
575 SER : {start : 24, len : 1, def : ' ' },
578 SER : {start : 7, len : 1, def : ' ' },
583 SCO : {start : 24, len : 6, def : ' ' },
584 REC : {start : 24, len : 6, def : ' ' },
587 SCO : {start : 7, len : 6, def : ' ' },
588 REC : {start : 7, len : 6, def : ' ' },
593 SCO : {start : 18, len : 2, def : ' ' },
594 REC : {start : 18, len : 2, def : ' ' },
597 SCO : {start : 1, len : 2, def : ' ' },
598 REC : {start : 1, len : 2, def : ' ' },
603 MAP : {start : 25, len : 1, def : ' ' },
606 MAP : {start : 8, len : 1, def : ' ' },
611 BKS : {start : 15, len : 3, def : ' ' },
612 SER : {start : 15, len : 3, def : ' ' },
613 VIS : {start : 15, len : 3, def : ' ' },
614 MIX : {start : 15, len : 3, def : ' ' },
615 MAP : {start : 15, len : 3, def : ' ' },
616 SCO : {start : 15, len : 3, def : ' ' },
617 REC : {start : 15, len : 3, def : ' ' },
618 COM : {start : 15, len : 3, def : ' ' },
623 BKS : {start : 35, len : 3, def : ' ' },
624 SER : {start : 35, len : 3, def : ' ' },
625 VIS : {start : 35, len : 3, def : ' ' },
626 MIX : {start : 35, len : 3, def : ' ' },
627 MAP : {start : 35, len : 3, def : ' ' },
628 SCO : {start : 35, len : 3, def : ' ' },
629 REC : {start : 35, len : 3, def : ' ' },
630 COM : {start : 35, len : 3, def : ' ' },
635 BKS : {start : 38, len : 1, def : ' ' },
636 SER : {start : 38, len : 1, def : ' ' },
637 VIS : {start : 38, len : 1, def : ' ' },
638 MIX : {start : 38, len : 1, def : ' ' },
639 MAP : {start : 38, len : 1, def : ' ' },
640 SCO : {start : 38, len : 1, def : ' ' },
641 REC : {start : 38, len : 1, def : ' ' },
642 COM : {start : 38, len : 1, def : ' ' },
647 BKS : {start : 6, len : 1, def : ' ' },
648 SER : {start : 6, len : 1, def : 'c' },
649 VIS : {start : 6, len : 1, def : ' ' },
650 MIX : {start : 6, len : 1, def : ' ' },
651 MAP : {start : 6, len : 1, def : ' ' },
652 SCO : {start : 6, len : 1, def : ' ' },
653 REC : {start : 6, len : 1, def : ' ' },
654 COM : {start : 6, len : 1, def : ' ' },
659 BKS : {start : 6, len : 1, def : 'a' },
660 SER : {start : 6, len : 1, def : 'a' },
661 VIS : {start : 6, len : 1, def : 'g' },
662 MIX : {start : 6, len : 1, def : 'p' },
663 MAP : {start : 6, len : 1, def : 'e' },
664 SCO : {start : 6, len : 1, def : 'c' },
665 REC : {start : 6, len : 1, def : 'i' },
666 COM : {start : 6, len : 1, def : 'm' },
671 BKS : {start : 8, len : 1, def : ' ' },
672 SER : {start : 8, len : 1, def : ' ' },
673 VIS : {start : 8, len : 1, def : ' ' },
674 MIX : {start : 8, len : 1, def : ' ' },
675 MAP : {start : 8, len : 1, def : ' ' },
676 SCO : {start : 8, len : 1, def : ' ' },
677 REC : {start : 8, len : 1, def : ' ' },
678 COM : {start : 8, len : 1, def : ' ' },
683 BKS : {start : 7, len : 1, def : 'm' },
684 SER : {start : 7, len : 1, def : 's' },
685 VIS : {start : 7, len : 1, def : 'm' },
686 MIX : {start : 7, len : 1, def : 'c' },
687 MAP : {start : 7, len : 1, def : 'm' },
688 SCO : {start : 7, len : 1, def : 'm' },
689 REC : {start : 7, len : 1, def : 'm' },
690 COM : {start : 7, len : 1, def : 'm' },
695 BKS : {start : 18, len : 1, def : ' ' },
696 SER : {start : 18, len : 1, def : ' ' },
697 VIS : {start : 18, len : 1, def : ' ' },
698 MIX : {start : 18, len : 1, def : ' ' },
699 MAP : {start : 18, len : 1, def : ' ' },
700 SCO : {start : 18, len : 1, def : ' ' },
701 REC : {start : 18, len : 1, def : ' ' },
702 COM : {start : 18, len : 1, def : ' ' },
707 BKS : {start : 17, len : 1, def : ' ' },
708 SER : {start : 17, len : 1, def : ' ' },
709 VIS : {start : 17, len : 1, def : ' ' },
710 MIX : {start : 17, len : 1, def : ' ' },
711 MAP : {start : 17, len : 1, def : ' ' },
712 SCO : {start : 17, len : 1, def : ' ' },
713 REC : {start : 17, len : 1, def : ' ' },
714 COM : {start : 17, len : 1, def : ' ' },
719 BKS : {start : 31, len : 1, def : '0' },
720 MAP : {start : 31, len : 1, def : '0' },
723 BKS : {start : 14, len : 1, def : '0' },
724 MAP : {start : 14, len : 1, def : '0' },
729 BKS : {start : 7, len : 4, def : ' ' },
730 SER : {start : 7, len : 4, def : ' ' },
731 VIS : {start : 7, len : 4, def : ' ' },
732 MIX : {start : 7, len : 4, def : ' ' },
733 MAP : {start : 7, len : 4, def : ' ' },
734 SCO : {start : 7, len : 4, def : ' ' },
735 REC : {start : 7, len : 4, def : ' ' },
736 COM : {start : 7, len : 4, def : ' ' },
741 BKS : {start : 11, len : 4, def : ' ' },
742 SER : {start : 11, len : 4, def : '9' },
743 VIS : {start : 11, len : 4, def : ' ' },
744 MIX : {start : 11, len : 4, def : ' ' },
745 MAP : {start : 11, len : 4, def : ' ' },
746 SCO : {start : 11, len : 4, def : ' ' },
747 REC : {start : 11, len : 4, def : ' ' },
748 COM : {start : 11, len : 4, def : ' ' },
753 BKS : {start : 33, len : 1, def : '0' },
756 BKS : {start : 16, len : 1, def : '0' },
761 BKS : {start : 34, len : 1, def : ' ' },
764 BKS : {start : 17, len : 1, def : ' ' },
769 BKS : {start : 18, len : 4, def : ' ' },
772 BKS : {start : 1, len : 4, def : ' ' },
777 BKS : {start : 30, len : 1, def : '0' },
780 BKS : {start : 13, len : 1, def : '0' },
785 BKS : {start : 29, len : 1, def : '0' },
786 SER : {start : 29, len : 1, def : '0' },
789 BKS : {start : 12, len : 1, def : '0' },
790 SER : {start : 12, len : 1, def : '0' },
795 BKS : {start : 24, len : 4, def : ' ' },
796 SER : {start : 25, len : 3, def : ' ' },
799 BKS : {start : 7, len : 4, def : ' ' },
800 SER : {start : 8, len : 3, def : ' ' },
805 BKS : {start : 28, len : 1, def : ' ' },
806 SER : {start : 28, len : 1, def : ' ' },
807 VIS : {start : 28, len : 1, def : ' ' },
808 MAP : {start : 28, len : 1, def : ' ' },
809 COM : {start : 28, len : 1, def : ' ' },
812 BKS : {start : 11, len : 1, def : ' ' },
813 SER : {start : 11, len : 1, def : ' ' },
814 VIS : {start : 11, len : 1, def : ' ' },
815 MAP : {start : 11, len : 1, def : ' ' },
816 COM : {start : 11, len : 1, def : ' ' },
821 BKS : {start : 22, len : 1, def : ' ' },
822 SER : {start : 22, len : 1, def : ' ' },
823 VIS : {start : 22, len : 1, def : ' ' },
824 SCO : {start : 22, len : 1, def : ' ' },
825 REC : {start : 22, len : 1, def : ' ' },
826 COM : {start : 22, len : 1, def : ' ' },
829 BKS : {start : 5, len : 1, def : ' ' },
830 SER : {start : 5, len : 1, def : ' ' },
831 VIS : {start : 5, len : 1, def : ' ' },
832 SCO : {start : 5, len : 1, def : ' ' },
833 REC : {start : 5, len : 1, def : ' ' },
834 COM : {start : 5, len : 1, def : ' ' },
839 BKS : {start : 23, len : 1, def : ' ' },
840 SER : {start : 23, len : 1, def : ' ' },
841 VIS : {start : 29, len : 1, def : ' ' },
842 MIX : {start : 23, len : 1, def : ' ' },
843 MAP : {start : 29, len : 1, def : ' ' },
844 SCO : {start : 23, len : 1, def : ' ' },
845 REC : {start : 23, len : 1, def : ' ' },
848 BKS : {start : 6, len : 1, def : ' ' },
849 SER : {start : 6, len : 1, def : ' ' },
850 VIS : {start : 12, len : 1, def : ' ' },
851 MIX : {start : 6, len : 1, def : ' ' },
852 MAP : {start : 12, len : 1, def : ' ' },
853 SCO : {start : 6, len : 1, def : ' ' },
854 REC : {start : 6, len : 1, def : ' ' },
859 SER : {start : 34, len : 1, def : '0' },
862 SER : {start : 17, len : 1, def : '0' },
867 SER : {start : 33, len : 1, def : ' ' },
870 SER : {start : 16, len : 1, def : ' ' },
875 function recordType (rec) {
877 var _l = rec.leader.toString();
879 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
880 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
882 for (var t in rec_type) {
883 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
884 document.getElementById('recordTypeLabel').value = t;
890 alert('FIXME, MARC Editor, recordType: ' + E);
894 function toggleFFE () {
895 var grid = document.getElementById('leaderGrid');
904 function changeFFEditor (type) {
905 var grid = document.getElementById('leaderGrid');
906 grid.setAttribute('type',type);
909 function fillFixedFields (rec) {
911 var grid = document.getElementById('leaderGrid');
913 var rtype = _record_type;
915 var _l = rec.leader.toString();
916 var _6 = rec.controlfield.(@tag=='006').toString();
917 var _7 = rec.controlfield.(@tag=='007').toString();
918 var _8 = rec.controlfield.(@tag=='008').toString();
921 var pre_list = grid.getElementsByTagName('label');
922 for (var i in pre_list) {
923 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
924 list.push( pre_list[i] );
928 for (var i in list) {
929 var name = list[i].getAttribute('name');
935 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
936 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
938 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
939 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
941 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
942 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
944 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
945 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
950 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
951 d = ff_pos[name].ldr[rtype].def;
955 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
956 d = ff_pos[name]._8[rtype].def;
960 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
961 d = ff_pos[name]._6[rtype].def;
965 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
966 d = ff_pos[name]._7[rtype].def;
971 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
977 list[i].nextSibling.value = value;
982 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
986 function updateFixedFields (element) {
987 var grid = document.getElementById('leaderGrid');
988 var recGrid = document.getElementById('recGrid');
990 var rtype = _record_type;
991 var new_value = element.value;
994 ldr : _record.leader,
995 _6 : _record.controlfield.(@tag=='006'),
996 _7 : _record.controlfield.(@tag=='007'),
997 _8 : _record.controlfield.(@tag=='008'),
1000 var name = element.getAttribute('name');
1001 for (var i in ff_pos[name]) {
1003 if (!ff_pos[name][i][rtype]) continue;
1004 if (!parts[i]) continue;
1006 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
1007 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
1009 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
1010 new_value += ff_pos[name][i][rtype].def;
1013 parts[i].setChildren( before + new_value + after );
1014 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
1020 function marcLeader (leader) {
1021 var row = createRow(
1022 { class : 'marcLeaderRow',
1027 tooltiptext : "MARC Leader" } ),
1030 class : 'marcInd1' } ),
1033 class : 'marcInd2' } ),
1035 { value : leader.text(),
1036 class : 'marcLeader' } )
1042 function marcControlfield (field) {
1043 tagname = field.@tag.toString().substr(2);
1045 if (tagname == '6' || tagname == '7' || tagname == '8') {
1047 { class : 'marcControlfieldRow',
1048 tag : '_' + tagname },
1050 { value : field.@tag,
1052 context : 'tags_popup',
1053 onmouseover : 'getTooltip(this, "tag");',
1054 tooltipid : 'tag' + field.@tag } ),
1056 { value : field.@ind1,
1058 onmouseover : 'getTooltip(this, "ind1");',
1059 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1061 { value : field.@ind2,
1063 onmouseover : 'getTooltip(this, "ind2");',
1064 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1067 { value : field.text(),
1068 class : 'plain marcEditableControlfield',
1069 name : 'CONTROL' + tagname,
1070 oncontext : 'return false();',
1076 { class : 'marcControlfieldRow',
1077 tag : '_' + tagname },
1079 { value : field.@tag,
1081 onmouseover : 'getTooltip(this, "tag");',
1082 tooltipid : 'tag' + field.@tag } ),
1084 { value : field.@ind1,
1086 onmouseover : 'getTooltip(this, "ind1");',
1087 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
1089 { value : field.@ind2,
1091 onmouseover : 'getTooltip(this, "ind2");',
1092 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
1094 { value : field.text(),
1095 class : 'marcControlfield' } )
1102 function stackSubfields(checkbox) {
1103 var list = document.getElementsByAttribute('name','sf_box');
1106 if (checkbox.checked) o = 'horizontal';
1108 for (var i = 0; i < list.length; i++) {
1109 if (list[i]) list[i].setAttribute('orient',o);
1113 function marcDatafield (field) {
1114 var row = createRow(
1115 { class : 'marcDatafieldRow' },
1118 { value : field.@tag,
1119 class : 'plain marcTag',
1121 context : 'tags_popup',
1122 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
1125 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
1128 { value : field.@ind1,
1129 class : 'plain marcInd1',
1131 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1134 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
1135 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
1138 { value : field.@ind2,
1139 class : 'plain marcInd2',
1141 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
1144 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
1145 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
1146 createHbox({ name : 'sf_box' })
1149 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
1150 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
1151 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
1153 var sf_box = row.lastChild;
1154 if (document.getElementById('stackSubfields').checked)
1155 sf_box.setAttribute('orient','vertical');
1157 sf_box.addEventListener(
1160 if (sf_box === e.target) {
1161 sf_box.lastChild.lastChild.focus();
1162 } else if (e.target.parentNode === sf_box) {
1163 e.target.lastChild.focus();
1170 for (var i in field.subfield) {
1171 var sf = field.subfield[i];
1176 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
1177 current_focus = sf_box.lastChild.childNodes[1];
1183 function marcSubfield (sf) {
1185 { class : 'marcSubfieldBox' },
1188 class : 'plain marcSubfieldDelimiter',
1189 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
1190 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
1191 //onclick : 'this.nextSibling.focus();',
1192 onfocus : 'this.nextSibling.focus();',
1197 class : 'plain marcSubfieldCode',
1198 name : 'marcSubfieldCode',
1199 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
1200 oncontextmenu : 'getContextMenu(this, "subfield");',
1201 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1206 { value : sf.text(),
1207 name : sf.parent().@tag + ':' + sf.@code,
1208 class : 'plain marcSubfield',
1209 onmouseover : 'getTooltip(this, "subfield");',
1210 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1211 size : new String(sf.text()).length + 2,
1212 oninput : "this.setAttribute('size', this.value.length + 2);",
1217 function loadRecord(rec) {
1220 var grid_rows = document.getElementById('recGrid').lastChild;
1222 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1224 grid_rows.appendChild( marcLeader( rec.leader ) );
1226 for (var i in rec.controlfield) {
1227 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1230 for (var i in rec.datafield) {
1231 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1234 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1235 changeFFEditor(recordType(rec));
1236 fillFixedFields(rec);
1238 alert('FIXME, MARC Editor, loadRecord: ' + E);
1242 var context_menus = createComplexXULElement('popupset');
1243 document.documentElement.appendChild( context_menus );
1245 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
1246 context_menus.appendChild( tag_menu );
1248 tag_menu.appendChild(
1250 { label : 'Add Row',
1252 'var e = document.createEvent("KeyEvents");' +
1253 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
1254 'current_focus.inputField.dispatchEvent(e);',
1259 tag_menu.appendChild(
1261 { label : 'Remove Row',
1263 'var e = document.createEvent("KeyEvents");' +
1264 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
1265 'current_focus.inputField.dispatchEvent(e);',
1270 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1272 tag_menu.appendChild(
1274 { label : 'Add/Replace 006',
1276 'var e = document.createEvent("KeyEvents");' +
1277 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
1278 'current_focus.inputField.dispatchEvent(e);',
1283 tag_menu.appendChild(
1285 { label : 'Add/Replace 007',
1287 'var e = document.createEvent("KeyEvents");' +
1288 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
1289 'current_focus.inputField.dispatchEvent(e);',
1294 tag_menu.appendChild(
1296 { label : 'Add/Replace 008',
1298 'var e = document.createEvent("KeyEvents");' +
1299 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
1300 'current_focus.inputField.dispatchEvent(e);',
1305 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1309 function genToolTips () {
1310 for (var i in bib_data.field) {
1311 var f = bib_data.field[i];
1313 tag_menu.appendChild(
1317 'current_focus.value = "' + f.@tag + '";' +
1318 'var e = document.createEvent("MutationEvents");' +
1319 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1320 'current_focus.inputField.dispatchEvent(e);',
1321 disabled : f.@tag < '010' ? "true" : "false",
1322 tooltiptext : f.description }
1326 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1327 context_menus.appendChild( i1_popup );
1329 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1330 context_menus.appendChild( i2_popup );
1332 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1333 context_menus.appendChild( sf_popup );
1335 tooltip_hash['tag' + f.@tag] = f.description;
1336 for (var j in f.indicator) {
1337 var ind = f.indicator[j];
1338 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1340 if (ind.@position == 1) {
1341 i1_popup.appendChild(
1343 { label : ind.@value,
1345 'current_focus.value = "' + ind.@value + '";' +
1346 'var e = document.createEvent("MutationEvents");' +
1347 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1348 'current_focus.inputField.dispatchEvent(e);',
1349 tooltiptext : ind.description }
1354 if (ind.@position == 2) {
1355 i2_popup.appendChild(
1357 { label : ind.@value,
1359 'current_focus.value = "' + ind.@value + '";' +
1360 'var e = document.createEvent("MutationEvents");' +
1361 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1362 'current_focus.inputField.dispatchEvent(e);',
1363 tooltiptext : ind.description }
1369 for (var j in f.subfield) {
1370 var sf = f.subfield[j];
1371 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1373 sf_popup.appendChild(
1377 'current_focus.value = "' + sf.@code + '";' +
1378 'var e = document.createEvent("MutationEvents");' +
1379 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1380 'current_focus.inputField.dispatchEvent(e);',
1381 tooltiptext : sf.description,
1389 var p = createComplexXULElement('popupset');
1390 document.documentElement.appendChild( p );
1392 function getTooltip (target, type) {
1395 if (type == 'subfield')
1396 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1399 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1402 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1405 tt = 'tag' + target.parentNode.firstChild.value;
1407 if (!document.getElementById( tt )) {
1412 orient : 'vertical',
1413 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1414 class : 'tooltip' },
1415 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1420 target.tooltip = tt;
1424 function getContextMenu (target, type) {
1427 if (type == 'subfield')
1428 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1431 tt = 't' + target.parentNode.firstChild.value + 'i1';
1434 tt = 't' + target.parentNode.firstChild.value + 'i2';
1436 target.setAttribute('context', tt);
1440 var authority_tag_map = {
1441 100 : ['[100,400,500,700]',100],
1442 400 : ['[100,400,500,700]',100],
1443 700 : ['[100,400,500,700]',100],
1444 800 : ['[100,400,500,700]',100],
1445 110 : ['[110,410,510,710]',110],
1446 410 : ['[110,410,510,710]',110],
1447 710 : ['[110,410,510,710]',110],
1448 810 : ['[110,410,510,710]',110],
1449 111 : ['[111,411,511,711]',111],
1450 411 : ['[111,411,511,711]',111],
1451 711 : ['[111,411,511,711]',111],
1452 811 : ['[111,411,511,711]',111],
1453 240 : ['[130,430,530,730]',130],
1454 440 : ['[130,430,530,730]',130],
1455 130 : ['[130,430,530,730]',130],
1456 730 : ['[130,430,530,730]',130],
1457 830 : ['[130,430,530,730]',130],
1458 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1459 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1460 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1461 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1464 function getAuthorityContextMenu (target, sf) {
1465 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1467 var old = document.getElementById( menu_id );
1468 if (old) old.parentNode.removeChild(old);
1470 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1471 context_menus.appendChild( sf_popup );
1473 if (!authority_tag_map[sf.parent().@tag]) {
1474 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1475 target.setAttribute('context', menu_id);
1479 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1481 var res = new XML( auth_data.responseText );
1485 var recs = res.gw::payload.gw::array.gw::string;
1486 for (var i in recs) {
1488 var xml = new XML(x.toString());
1489 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1491 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1494 for (var i in main) {
1495 if (main_text) main_text += ' / ';
1496 main_text += main[i];
1499 rec_list.push( [ main_text, xml ] );
1502 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1504 var main_text = rec_list[i][0];
1505 var xml = rec_list[i][1];
1506 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1508 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1510 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1511 grid.setAttribute('name','-none-');
1512 grid.setAttribute('style','overflow:scroll');
1515 var submenu = createMenu( { label : main_text } );
1517 var popup = createMenuPopup({ flex : "1" });
1518 submenu.appendChild(popup);
1520 var fields = xml.datafield;
1521 for (var j in fields) {
1523 var row = createRow(
1525 createLabel( { value : fields[j].@tag } ),
1526 createLabel( { value : fields[j].@ind1 } ),
1527 createLabel( { value : fields[j].@ind2 } )
1530 var sf_box = createHbox();
1532 var subfields = fields[j].subfield;
1533 for (var k in subfields) {
1536 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1537 subfield : subfields[k].@code,
1538 tag : subfields[k].parent().@tag,
1539 value : subfields[k]
1543 row.appendChild(sf_box);
1546 grid.lastChild.appendChild(row);
1549 grid.hidden = false;
1550 popup.appendChild( grid );
1554 { label : 'Apply Selected',
1555 command : function (event) {
1556 applyAuthority(event.target.previousSibling, target, sf);
1563 sf_popup.appendChild( submenu );
1566 if (sf_popup.childNodes.length == 0)
1567 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1569 target.setAttribute('context', menu_id);
1573 function applyAuthority ( target, ui_sf, e4x_sf ) {
1575 var new_vals = target.getElementsByAttribute('checked','true');
1576 var field = e4x_sf.parent();
1578 for (var i = 0; i < new_vals.length; i++) {
1580 var sf_list = field.subfield;
1581 for (var j in sf_list) {
1583 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1584 sf_list[j] = new_vals[i].getAttribute('value');
1585 new_vals[i].setAttribute('subfield','');
1591 for (var i = 0; i < new_vals.length; i++) {
1592 if (!new_vals[i].getAttribute('subfield')) continue;
1594 var val = new_vals[i].getAttribute('value');
1596 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1597 sf.@code = new_vals[i].getAttribute('subfield');
1599 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1602 var row = marcDatafield( field );
1605 while (node.nodeName != 'row') {
1606 node = node.parentNode;
1609 node.parentNode.replaceChild( row, node );
1615 'a' : { 100 : 'a' },
1616 'd' : { 100 : 'd' },
1619 'a' : { 110 : 'a' },
1620 'd' : { 110 : 'd' },
1623 'a' : { 111 : 'a' },
1624 'd' : { 111 : 'd' },
1627 'a' : { 130 : 'a' },
1628 'd' : { 130 : 'd' },
1631 'a' : { 130 : 'a' },
1632 'd' : { 130 : 'd' },
1635 'a' : { 100 : 'a' },
1636 'd' : { 100 : 'd' },
1639 'a' : { 110 : 'a' },
1640 'd' : { 110 : 'd' },
1643 'a' : { 111 : 'a' },
1644 'd' : { 111 : 'd' },
1647 'a' : { 130 : 'a' },
1648 'n' : { 130 : 'n' },
1649 'p' : { 130 : 'p' },
1652 'a' : { 100 : 'a' },
1653 'd' : { 100 : 'd' },
1656 'a' : { 110 : 'a' },
1657 'd' : { 110 : 'd' },
1660 'a' : { 111 : 'a' },
1661 'd' : { 111 : 'd' },
1664 'a' : { 130 : 'a' },
1665 'd' : { 130 : 'd' },
1668 'a' : { 100 : 'a' },
1669 'd' : { 100 : 'd' },
1672 'a' : { 110 : 'a' },
1673 'd' : { 110 : 'd' },
1676 'a' : { 111 : 'a' },
1677 'd' : { 111 : 'd' },
1680 'a' : { 130 : 'a' },
1681 'd' : { 130 : 'd' },
1684 'a' : { 100 : 'a' },
1685 'd' : { 100 : 'd' },
1686 't' : { 100 : 't' },
1713 'a' : { 150 : 'a' },
1714 'b' : { 150 : 'b' },
1741 'a' : { 151 : 'a' },
1768 'a' : { 155 : 'a' },
1796 function validateAuthority (button) {
1797 var grid = document.getElementById('recGrid');
1798 var label = button.getAttribute('label');
1801 var rows = grid.lastChild.childNodes;
1802 for (var i = 0; i < rows.length; i++) {
1804 var tag = row.firstChild;
1806 if (!control_map[tag.value]) continue
1808 var ind1 = tag.nextSibling;
1809 var ind2 = ind1.nextSibling;
1810 var subfields = ind2.nextSibling.childNodes;
1812 for (var j = 0; j < subfields.length; j++) {
1813 var sf = subfields[j];
1815 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1817 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1820 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1821 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1822 var res = new XML( x.responseText );
1824 if (res.gw::payload.gw::array.gw::string.length()) {
1831 sf.childNodes[2].inputField.style.color = 'red';
1833 sf.childNodes[2].inputField.style.color = 'black';
1838 button.setAttribute('label', label);
1844 function searchAuthority (term, tag, sf, limit) {
1845 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1846 url += '¶m="term"¶m="' + term + '"';
1847 url += '¶m="limit"¶m=' + limit;
1848 url += '¶m="tag"¶m=' + tag;
1849 url += '¶m="subfield"¶m="' + sf + '"';
1852 var req = new XMLHttpRequest();
1853 req.open('GET',url,false);