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 m = '0' + m if (m < 10);
23 var d = now.getUTCDate();
24 d = '0' + d if (d < 10);
26 var H = now.getUTCHours();
27 H = '0' + H if (H < 10);
29 var M = now.getUTCMinutes();
30 M = '0' + M if (M < 10);
32 var S = now.getUTCSeconds();
33 S = '0' + S if (S < 10);
36 var stamp = '' + y + m + d + H + M + S + '.0';
38 var new_005 = <controlfield tag="005" xmlns="http://www.loc.gov/MARC21/slim">{ stamp }</controlfield>;
40 // first, remove the old field, if any;
41 var edit_field = xml_record.controlfield.(@tag == '005');
42 for (var i in edit_field) xml_record.removeChild(edit_field[i]);
45 // then, find the right position and insert it
47 var cfields = xml_record.controfield;
48 for (var i in cfields) {
49 if (Number(cfield[i].@tag) > 5) {
50 xml_record.insertBefore( new_005, cfields[i]);
55 if (!done) xml_record.insertBefore( new_005, xml_record.datafield[0] );
61 // Fake xulG for standalone...
66 window.xulG.record = {};
67 window.xulG.save = {};
69 window.xulG.save.label = 'Save Record';
70 window.xulG.save.func = function (r) { alert(r); }
73 var _rid = cgi.param('record');
75 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
80 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
81 document.getElementById('save-button').setAttribute('oncommand', 'mangle_005(); window.xulG.save.func(xml_record.toXMLString());');
83 if (window.xulG.record.url) {
84 var req = new XMLHttpRequest();
85 req.open('GET',window.xulG.record.url,false);
87 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
90 xml_record = new XML( window.xulG.record.marc );
91 if (xml_record..record[0]) xml_record = xml_record..record[0];
93 // Get the tooltip xml all async like
94 req = new XMLHttpRequest();
95 req.open('GET','marcedit-tooltips.xml',true);
96 req.onreadystatechange = function () {
97 if (req.readyState == 4) {
98 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
104 loadRecord(xml_record);
106 alert('FIXME, MARC Editor, my_init: ' + E);
111 function createComplexHTMLElement (e, attrs, objects, text) {
112 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
115 for (var i in attrs) l.setAttribute(i,attrs[i]);
119 for ( var i in objects ) l.appendChild( objects[i] );
123 l.appendChild( document.createTextNode(text) )
129 function createComplexXULElement (e, attrs, objects) {
130 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
133 for (var i in attrs) {
134 if (typeof attrs[i] == 'function') {
135 l.addEventListener( i, attrs[i], true );
137 l.setAttribute(i,attrs[i]);
143 for ( var i in objects ) l.appendChild( objects[i] );
149 function createDescription (attrs) {
150 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
153 function createTooltip (attrs) {
154 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
157 function createLabel (attrs) {
158 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
161 function createVbox (attrs) {
162 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
165 function createHbox (attrs) {
166 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
169 function createRow (attrs) {
170 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
173 function createTextbox (attrs) {
174 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
177 function createMenu (attrs) {
178 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
181 function createMenuPopup (attrs) {
182 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
185 function createPopup (attrs) {
186 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
189 function createMenuitem (attrs) {
190 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
193 function createCheckbox (attrs) {
194 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
197 function createMARCTextbox (element,attrs) {
199 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
200 box.onkeypress = function (event) {
203 while(node = node.parent()) {
207 var row = event.target;
208 while (row.tagName != 'row') row = row.parentNode;
210 if (element.nodeKind() == 'attribute') element[0]=box.value;
211 else element.setChildren( box.value );
213 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
215 var index_sf, target, move_data;
216 if (element.localName() == 'subfield') {
218 target = event.target.parentNode;
220 var start = event.target.selectionStart;
221 var end = event.target.selectionEnd - event.target.selectionStart ?
222 event.target.selectionEnd :
223 event.target.value.length;
225 move_data = event.target.value.substring(start,end);
226 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
227 event.target.setAttribute('size', event.target.value.length + 2);
229 element.setChildren( event.target.value );
231 } else if (element.localName() == 'code') {
232 index_sf = element.parent();
233 target = event.target.parentNode;
234 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
235 index_sf = element.parent().children()[element.parent().children().length() - 1];
236 target = event.target.parentNode.lastChild.lastChild;
239 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
241 index_sf.parent().insertChildAfter( index_sf, sf );
243 var new_sf = marcSubfield(sf);
245 if (target === target.parentNode.lastChild) {
246 target.parentNode.appendChild( new_sf );
248 target.parentNode.insertBefore( new_sf, target.nextSibling );
251 new_sf.firstChild.nextSibling.focus();
253 event.preventDefault();
256 } else if (event.keyCode == 13 || event.keyCode == 77) {
257 if (event.ctrlKey) { // ctrl+enter
260 if (element.localName() == 'subfield') index = element.parent();
261 if (element.localName() == 'code') index = element.parent().parent();
262 if (element.localName() == 'tag') index = element.parent();
263 if (element.localName() == 'ind1') index = element.parent();
264 if (element.localName() == 'ind2') index = element.parent();
266 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
268 index.parent().insertChildAfter( index, df );
270 var new_df = marcDatafield(df);
272 if (row.parentNode.lastChild === row) {
273 row.parentNode.appendChild( new_df );
275 row.parentNode.insertBefore( new_df, row.nextSibling );
278 new_df.firstChild.focus();
280 event.preventDefault();
283 } else if (event.shiftKey) {
284 if (row.previousSibling.className.match('marcDatafieldRow'))
285 row.previousSibling.firstChild.focus();
287 row.nextSibling.firstChild.focus();
290 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
293 if (element.localName() == 'subfield') index = element.parent();
294 if (element.localName() == 'code') index = element.parent().parent();
295 if (element.localName() == 'tag') index = element.parent();
296 if (element.localName() == 'ind1') index = element.parent();
297 if (element.localName() == 'ind2') index = element.parent();
299 for (var i in index.parent().children()) {
300 if (index === index.parent().children()[i]) {
301 delete index.parent().children()[i];
306 row.previousSibling.firstChild.focus();
307 row.parentNode.removeChild(row);
309 event.preventDefault();
312 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
315 if (element.localName() == 'subfield') index = element;
316 if (element.localName() == 'code') index = element.parent();
319 for (var i in index.parent().children()) {
320 if (index === index.parent().children()[i]) {
321 delete index.parent().children()[i];
326 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
327 event.target.parentNode.previousSibling.lastChild.focus();
329 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
332 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
334 event.preventDefault();
341 box.addEventListener(
344 if (element.nodeKind() == 'attribute') element[0]=box.value;
345 else element.setChildren( box.value );
351 box.addEventListener(
354 if (element.nodeKind() == 'attribute') element[0]=box.value;
355 else element.setChildren( box.value );
361 box.addEventListener(
364 if (element.nodeKind() == 'attribute') element[0]=box.value;
365 else element.setChildren( box.value );
375 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
376 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
377 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
378 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
379 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
380 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
381 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
382 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
388 BKS : {start : 15, len : 3, def : ' ' },
389 SER : {start : 15, len : 3, def : ' ' },
390 VIS : {start : 15, len : 3, def : ' ' },
391 MIX : {start : 15, len : 3, def : ' ' },
392 MAP : {start : 15, len : 3, def : ' ' },
393 SCO : {start : 15, len : 3, def : ' ' },
394 REC : {start : 15, len : 3, def : ' ' },
395 COM : {start : 15, len : 3, def : ' ' },
400 BKS : {start : 35, len : 3, def : ' ' },
401 SER : {start : 35, len : 3, def : ' ' },
402 VIS : {start : 35, len : 3, def : ' ' },
403 MIX : {start : 35, len : 3, def : ' ' },
404 MAP : {start : 35, len : 3, def : ' ' },
405 SCO : {start : 35, len : 3, def : ' ' },
406 REC : {start : 35, len : 3, def : ' ' },
407 COM : {start : 35, len : 3, def : ' ' },
412 BKS : {start : 38, len : 1, def : ' ' },
413 SER : {start : 38, len : 1, def : ' ' },
414 VIS : {start : 38, len : 1, def : ' ' },
415 MIX : {start : 38, len : 1, def : ' ' },
416 MAP : {start : 38, len : 1, def : ' ' },
417 SCO : {start : 38, len : 1, def : ' ' },
418 REC : {start : 38, len : 1, def : ' ' },
419 COM : {start : 38, len : 1, def : ' ' },
424 BKS : {start : 6, len : 1, def : ' ' },
425 SER : {start : 6, len : 1, def : 'c' },
426 VIS : {start : 6, len : 1, def : ' ' },
427 MIX : {start : 6, len : 1, def : ' ' },
428 MAP : {start : 6, len : 1, def : ' ' },
429 SCO : {start : 6, len : 1, def : ' ' },
430 REC : {start : 6, len : 1, def : ' ' },
431 COM : {start : 6, len : 1, def : ' ' },
436 BKS : {start : 6, len : 1, def : 'a' },
437 SER : {start : 6, len : 1, def : 'a' },
438 VIS : {start : 6, len : 1, def : 'g' },
439 MIX : {start : 6, len : 1, def : 'p' },
440 MAP : {start : 6, len : 1, def : 'e' },
441 SCO : {start : 6, len : 1, def : 'c' },
442 REC : {start : 6, len : 1, def : 'i' },
443 COM : {start : 6, len : 1, def : 'm' },
448 BKS : {start : 8, len : 1, def : ' ' },
449 SER : {start : 8, len : 1, def : ' ' },
450 VIS : {start : 8, len : 1, def : ' ' },
451 MIX : {start : 8, len : 1, def : ' ' },
452 MAP : {start : 8, len : 1, def : ' ' },
453 SCO : {start : 8, len : 1, def : ' ' },
454 REC : {start : 8, len : 1, def : ' ' },
455 COM : {start : 8, len : 1, def : ' ' },
460 BKS : {start : 7, len : 1, def : 'm' },
461 SER : {start : 7, len : 1, def : 's' },
462 VIS : {start : 7, len : 1, def : 'm' },
463 MIX : {start : 7, len : 1, def : 'c' },
464 MAP : {start : 7, len : 1, def : 'm' },
465 SCO : {start : 7, len : 1, def : 'm' },
466 REC : {start : 7, len : 1, def : 'm' },
467 COM : {start : 7, len : 1, def : 'm' },
472 BKS : {start : 18, len : 1, def : ' ' },
473 SER : {start : 18, len : 1, def : ' ' },
474 VIS : {start : 18, len : 1, def : ' ' },
475 MIX : {start : 18, len : 1, def : ' ' },
476 MAP : {start : 18, len : 1, def : ' ' },
477 SCO : {start : 18, len : 1, def : ' ' },
478 REC : {start : 18, len : 1, def : ' ' },
479 COM : {start : 18, len : 1, def : ' ' },
484 BKS : {start : 17, len : 1, def : ' ' },
485 SER : {start : 17, len : 1, def : ' ' },
486 VIS : {start : 17, len : 1, def : ' ' },
487 MIX : {start : 17, len : 1, def : ' ' },
488 MAP : {start : 17, len : 1, def : ' ' },
489 SCO : {start : 17, len : 1, def : ' ' },
490 REC : {start : 17, len : 1, def : ' ' },
491 COM : {start : 17, len : 1, def : ' ' },
496 BKS : {start : 31, len : 1, def : '0' },
497 MAP : {start : 31, len : 1, def : '0' },
500 BKS : {start : 14, len : 1, def : '0' },
501 MAP : {start : 14, len : 1, def : '0' },
506 BKS : {start : 7, len : 4, def : ' ' },
507 SER : {start : 7, len : 4, def : ' ' },
508 VIS : {start : 7, len : 4, def : ' ' },
509 MIX : {start : 7, len : 4, def : ' ' },
510 MAP : {start : 7, len : 4, def : ' ' },
511 SCO : {start : 7, len : 4, def : ' ' },
512 REC : {start : 7, len : 4, def : ' ' },
513 COM : {start : 7, len : 4, def : ' ' },
518 BKS : {start : 11, len : 4, def : ' ' },
519 SER : {start : 11, len : 4, def : '9' },
520 VIS : {start : 11, len : 4, def : ' ' },
521 MIX : {start : 11, len : 4, def : ' ' },
522 MAP : {start : 11, len : 4, def : ' ' },
523 SCO : {start : 11, len : 4, def : ' ' },
524 REC : {start : 11, len : 4, def : ' ' },
525 COM : {start : 11, len : 4, def : ' ' },
530 BKS : {start : 33, len : 1, def : '0' },
533 BKS : {start : 16, len : 1, def : '0' },
538 BKS : {start : 34, len : 1, def : ' ' },
541 BKS : {start : 17, len : 1, def : ' ' },
546 BKS : {start : 18, len : 4, def : ' ' },
549 BKS : {start : 1, len : 4, def : ' ' },
554 BKS : {start : 30, len : 1, def : '0' },
557 BKS : {start : 13, len : 1, def : '0' },
562 BKS : {start : 24, len : 4, def : ' ' },
563 SER : {start : 25, len : 3, def : ' ' },
566 BKS : {start : 7, len : 4, def : ' ' },
567 SER : {start : 8, len : 3, def : ' ' },
572 BKS : {start : 28, len : 1, def : ' ' },
573 SER : {start : 28, len : 1, def : ' ' },
574 VIS : {start : 28, len : 1, def : ' ' },
575 MAP : {start : 28, len : 1, def : ' ' },
576 COM : {start : 28, len : 1, def : ' ' },
579 BKS : {start : 11, len : 1, def : ' ' },
580 SER : {start : 11, len : 1, def : ' ' },
581 VIS : {start : 11, len : 1, def : ' ' },
582 MAP : {start : 11, len : 1, def : ' ' },
583 COM : {start : 11, len : 1, def : ' ' },
588 BKS : {start : 22, len : 1, def : ' ' },
589 SER : {start : 22, len : 1, def : ' ' },
590 VIS : {start : 22, len : 1, def : ' ' },
591 SCO : {start : 22, len : 1, def : ' ' },
592 REC : {start : 22, len : 1, def : ' ' },
593 COM : {start : 22, len : 1, def : ' ' },
596 BKS : {start : 5, len : 1, def : ' ' },
597 SER : {start : 5, len : 1, def : ' ' },
598 VIS : {start : 5, len : 1, def : ' ' },
599 SCO : {start : 5, len : 1, def : ' ' },
600 REC : {start : 5, len : 1, def : ' ' },
601 COM : {start : 5, len : 1, def : ' ' },
606 BKS : {start : 23, len : 1, def : ' ' },
607 SER : {start : 23, len : 1, def : ' ' },
608 VIS : {start : 29, len : 1, def : ' ' },
609 MIX : {start : 23, len : 1, def : ' ' },
610 MAP : {start : 29, len : 1, def : ' ' },
611 SCO : {start : 23, len : 1, def : ' ' },
612 REC : {start : 23, len : 1, def : ' ' },
615 BKS : {start : 6, len : 1, def : ' ' },
616 SER : {start : 6, len : 1, def : ' ' },
617 VIS : {start : 12, len : 1, def : ' ' },
618 MIX : {start : 6, len : 1, def : ' ' },
619 MAP : {start : 12, len : 1, def : ' ' },
620 SCO : {start : 6, len : 1, def : ' ' },
621 REC : {start : 6, len : 1, def : ' ' },
626 SER : {start : 34, len : 1, def : '0' },
629 SER : {start : 17, len : 1, def : '0' },
634 SER : {start : 33, len : 1, def : ' ' },
637 SER : {start : 16, len : 1, def : ' ' },
642 function recordType (rec) {
644 var _l = rec.leader.toString();
646 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
647 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
649 for (var t in rec_type) {
650 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
651 document.getElementById('recordTypeLabel').value = t;
657 alert('FIXME, MARC Editor, recordType: ' + E);
661 function toggleFFE () {
662 var grid = document.getElementById('leaderGrid');
671 function changeFFEditor (type) {
672 var grid = document.getElementById('leaderGrid');
673 grid.setAttribute('type',type);
676 function fillFixedFields (rec) {
678 var grid = document.getElementById('leaderGrid');
680 var rtype = _record_type;
682 var _l = rec.leader.toString();
683 var _6 = rec.controlfield.(@tag=='006').toString();
684 var _7 = rec.controlfield.(@tag=='007').toString();
685 var _8 = rec.controlfield.(@tag=='008').toString();
688 var pre_list = grid.getElementsByTagName('label');
689 for (var i in pre_list) {
690 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
691 list.push( pre_list[i] );
695 for (var i in list) {
696 var name = list[i].getAttribute('name');
702 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
703 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
705 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
706 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
708 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
709 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
711 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
712 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
717 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
718 d = ff_pos[name].ldr[rtype].def;
722 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
723 d = ff_pos[name]._8[rtype].def;
727 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
728 d = ff_pos[name]._6[rtype].def;
732 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
733 d = ff_pos[name]._7[rtype].def;
738 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
744 list[i].nextSibling.value = value;
749 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
753 function updateFixedFields (element) {
754 var grid = document.getElementById('leaderGrid');
755 var recGrid = document.getElementById('recGrid');
757 var rtype = _record_type;
758 var new_value = element.value;
761 ldr : _record.leader,
762 _6 : _record.controlfield.(@tag=='006'),
763 _7 : _record.controlfield.(@tag=='007'),
764 _8 : _record.controlfield.(@tag=='008'),
767 var name = element.getAttribute('name');
768 for (var i in ff_pos[name]) {
770 if (!ff_pos[name][i][rtype]) continue;
771 if (!parts[i]) continue;
773 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
774 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
776 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
777 new_value += ff_pos[name][i][rtype].def;
780 parts[i].setChildren( before + new_value + after );
781 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
787 function marcLeader (leader) {
789 { class : 'marcLeaderRow',
794 tooltiptext : "MARC Leader" } ),
797 class : 'marcInd1' } ),
800 class : 'marcInd2' } ),
802 { value : leader.text(),
803 class : 'marcLeader' } )
809 function marcControlfield (field) {
810 tagname = field.@tag.toString().substr(2);
812 { class : 'marcControlfieldRow',
813 tag : '_' + tagname },
815 { value : field.@tag,
817 onmouseover : 'getTooltip(this, "tag");',
818 tooltipid : 'tag' + field.@tag } ),
820 { value : field.@ind1,
822 onmouseover : 'getTooltip(this, "ind1");',
823 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
825 { value : field.@ind2,
827 onmouseover : 'getTooltip(this, "ind2");',
828 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
830 { value : field.text(),
831 class : 'marcControlfield' } )
837 function stackSubfields(checkbox) {
838 var list = document.getElementsByAttribute('name','sf_box');
841 if (checkbox.checked) o = 'horizontal';
843 for (var i = 0; i < list.length; i++) {
844 if (list[i]) list[i].setAttribute('orient',o);
848 function marcDatafield (field) {
850 { class : 'marcDatafieldRow' },
853 { value : field.@tag,
854 class : 'plain marcTag',
856 context : 'tags_popup',
857 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
860 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
863 { value : field.@ind1,
864 class : 'plain marcInd1',
866 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
869 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
870 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
873 { value : field.@ind2,
874 class : 'plain marcInd2',
876 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
879 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
880 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
881 createHbox({ name : 'sf_box' })
884 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
885 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
886 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
888 var sf_box = row.lastChild;
889 if (document.getElementById('stackSubfields').checked)
890 sf_box.setAttribute('orient','vertical');
892 sf_box.addEventListener(
895 if (sf_box === e.target) {
896 sf_box.lastChild.lastChild.focus();
897 } else if (e.target.parentNode === sf_box) {
898 e.target.lastChild.focus();
905 for (var i in field.subfield) {
906 var sf = field.subfield[i];
911 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
912 current_focus = sf_box.lastChild.childNodes[1];
918 function marcSubfield (sf) {
920 { class : 'marcSubfieldBox' },
923 class : 'plain marcSubfieldDelimiter',
924 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
925 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
926 //onclick : 'this.nextSibling.focus();',
927 onfocus : 'this.nextSibling.focus();',
932 class : 'plain marcSubfieldCode',
933 name : 'marcSubfieldCode',
934 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
935 oncontextmenu : 'getContextMenu(this, "subfield");',
936 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
942 name : sf.parent().@tag + ':' + sf.@code,
943 class : 'plain marcSubfield',
944 onmouseover : 'getTooltip(this, "subfield");',
945 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
946 size : new String(sf.text()).length + 2,
947 oninput : "this.setAttribute('size', this.value.length + 2);",
952 function loadRecord(rec) {
955 var grid_rows = document.getElementById('recGrid').lastChild;
957 grid_rows.appendChild( marcLeader( rec.leader ) );
959 for (var i in rec.controlfield) {
960 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
963 for (var i in rec.datafield) {
964 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
967 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
968 changeFFEditor(recordType(rec));
969 fillFixedFields(rec);
971 alert('FIXME, MARC Editor, loadRecord: ' + E);
975 var context_menus = createComplexXULElement('popupset');
976 document.documentElement.appendChild( context_menus );
978 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
979 context_menus.appendChild( tag_menu );
981 tag_menu.appendChild(
985 'var e = document.createEvent("KeyEvents");' +
986 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
987 'current_focus.inputField.dispatchEvent(e);',
992 tag_menu.appendChild(
994 { label : 'Remove Row',
996 'var e = document.createEvent("KeyEvents");' +
997 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
998 'current_focus.inputField.dispatchEvent(e);',
1003 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1007 function genToolTips () {
1008 for (var i in bib_data.field) {
1009 var f = bib_data.field[i];
1011 tag_menu.appendChild(
1015 'current_focus.value = "' + f.@tag + '";' +
1016 'var e = document.createEvent("MutationEvents");' +
1017 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1018 'current_focus.inputField.dispatchEvent(e);',
1019 disabled : f.@tag < '010' ? "true" : "false",
1020 tooltiptext : f.description }
1024 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1025 context_menus.appendChild( i1_popup );
1027 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1028 context_menus.appendChild( i2_popup );
1030 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1031 context_menus.appendChild( sf_popup );
1033 tooltip_hash['tag' + f.@tag] = f.description;
1034 for (var j in f.indicator) {
1035 var ind = f.indicator[j];
1036 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1038 if (ind.@position == 1) {
1039 i1_popup.appendChild(
1041 { label : ind.@value,
1043 'current_focus.value = "' + ind.@value + '";' +
1044 'var e = document.createEvent("MutationEvents");' +
1045 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1046 'current_focus.inputField.dispatchEvent(e);',
1047 tooltiptext : ind.description }
1052 if (ind.@position == 2) {
1053 i2_popup.appendChild(
1055 { label : ind.@value,
1057 'current_focus.value = "' + ind.@value + '";' +
1058 'var e = document.createEvent("MutationEvents");' +
1059 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1060 'current_focus.inputField.dispatchEvent(e);',
1061 tooltiptext : ind.description }
1067 for (var j in f.subfield) {
1068 var sf = f.subfield[j];
1069 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1071 sf_popup.appendChild(
1075 'current_focus.value = "' + sf.@code + '";' +
1076 'var e = document.createEvent("MutationEvents");' +
1077 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1078 'current_focus.inputField.dispatchEvent(e);',
1079 tooltiptext : sf.description,
1087 var p = createComplexXULElement('popupset');
1088 document.documentElement.appendChild( p );
1090 function getTooltip (target, type) {
1093 if (type == 'subfield')
1094 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1097 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1100 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1103 tt = 'tag' + target.parentNode.firstChild.value;
1105 if (!document.getElementById( tt )) {
1110 orient : 'vertical',
1111 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1112 class : 'tooltip' },
1113 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1118 target.tooltip = tt;
1122 function getContextMenu (target, type) {
1125 if (type == 'subfield')
1126 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1129 tt = 't' + target.parentNode.firstChild.value + 'i1';
1132 tt = 't' + target.parentNode.firstChild.value + 'i2';
1134 target.setAttribute('context', tt);
1138 var authority_tag_map = {
1139 100 : ['[100,400,500,700]',100],
1140 400 : ['[100,400,500,700]',100],
1141 700 : ['[100,400,500,700]',100],
1142 800 : ['[100,400,500,700]',100],
1143 110 : ['[110,410,510,710]',110],
1144 410 : ['[110,410,510,710]',110],
1145 710 : ['[110,410,510,710]',110],
1146 810 : ['[110,410,510,710]',110],
1147 111 : ['[111,411,511,711]',111],
1148 411 : ['[111,411,511,711]',111],
1149 711 : ['[111,411,511,711]',111],
1150 811 : ['[111,411,511,711]',111],
1151 240 : ['[130,430,530,730]',130],
1152 440 : ['[130,430,530,730]',130],
1153 130 : ['[130,430,530,730]',130],
1154 730 : ['[130,430,530,730]',130],
1155 830 : ['[130,430,530,730]',130],
1156 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1157 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1158 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1159 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1162 function getAuthorityContextMenu (target, sf) {
1163 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1165 var old = document.getElementById( menu_id );
1166 if (old) old.parentNode.removeChild(old);
1168 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1169 context_menus.appendChild( sf_popup );
1171 if (!authority_tag_map[sf.parent().@tag]) {
1172 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1173 target.setAttribute('context', menu_id);
1177 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1179 var res = new XML( auth_data.responseText );
1183 var recs = res.gw::payload.gw::array.gw::string;
1184 for (var i in recs) {
1186 var xml = new XML(x.toString());
1187 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1189 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1192 for (var i in main) {
1193 if (main_text) main_text += ' / ';
1194 main_text += main[i];
1197 rec_list.push( [ main_text, xml ] );
1200 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1202 var main_text = rec_list[i][0];
1203 var xml = rec_list[i][1];
1204 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1206 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1208 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1209 grid.setAttribute('name','-none-');
1210 grid.setAttribute('style','overflow:scroll');
1213 var submenu = createMenu( { label : main_text } );
1215 var popup = createMenuPopup({ flex : "1" });
1216 submenu.appendChild(popup);
1218 var fields = xml.datafield;
1219 for (var j in fields) {
1221 var row = createRow(
1223 createLabel( { value : fields[j].@tag } ),
1224 createLabel( { value : fields[j].@ind1 } ),
1225 createLabel( { value : fields[j].@ind2 } )
1228 var sf_box = createHbox();
1230 var subfields = fields[j].subfield;
1231 for (var k in subfields) {
1234 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1235 subfield : subfields[k].@code,
1236 tag : subfields[k].parent().@tag,
1237 value : subfields[k]
1241 row.appendChild(sf_box);
1244 grid.lastChild.appendChild(row);
1247 grid.hidden = false;
1248 popup.appendChild( grid );
1252 { label : 'Apply Selected',
1253 command : function (event) {
1254 applyAuthority(event.target.previousSibling, target, sf);
1261 sf_popup.appendChild( submenu );
1264 if (sf_popup.childNodes.length == 0)
1265 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1267 target.setAttribute('context', menu_id);
1271 function applyAuthority ( target, ui_sf, e4x_sf ) {
1273 var new_vals = target.getElementsByAttribute('checked','true');
1274 var field = e4x_sf.parent();
1276 for (var i = 0; i < new_vals.length; i++) {
1278 var sf_list = field.subfield;
1279 for (var j in sf_list) {
1281 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1282 sf_list[j] = new_vals[i].getAttribute('value');
1283 new_vals[i].setAttribute('subfield','');
1289 for (var i = 0; i < new_vals.length; i++) {
1290 if (!new_vals[i].getAttribute('subfield')) continue;
1292 var val = new_vals[i].getAttribute('value');
1294 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1295 sf.@code = new_vals[i].getAttribute('subfield');
1297 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1300 var row = marcDatafield( field );
1303 while (node.nodeName != 'row') {
1304 node = node.parentNode;
1307 node.parentNode.replaceChild( row, node );
1313 'a' : { 100 : 'a' },
1314 'd' : { 100 : 'd' },
1317 'a' : { 110 : 'a' },
1318 'd' : { 110 : 'd' },
1321 'a' : { 111 : 'a' },
1322 'd' : { 111 : 'd' },
1325 'a' : { 130 : 'a' },
1326 'd' : { 130 : 'd' },
1329 'a' : { 130 : 'a' },
1330 'd' : { 130 : 'd' },
1333 'a' : { 100 : 'a' },
1334 'd' : { 100 : 'd' },
1337 'a' : { 110 : 'a' },
1338 'd' : { 110 : 'd' },
1341 'a' : { 111 : 'a' },
1342 'd' : { 111 : 'd' },
1345 'a' : { 130 : 'a' },
1346 'n' : { 130 : 'n' },
1347 'p' : { 130 : 'p' },
1350 'a' : { 100 : 'a' },
1351 'd' : { 100 : 'd' },
1354 'a' : { 110 : 'a' },
1355 'd' : { 110 : 'd' },
1358 'a' : { 111 : 'a' },
1359 'd' : { 111 : 'd' },
1362 'a' : { 130 : 'a' },
1363 'd' : { 130 : 'd' },
1366 'a' : { 100 : 'a' },
1367 'd' : { 100 : 'd' },
1370 'a' : { 110 : 'a' },
1371 'd' : { 110 : 'd' },
1374 'a' : { 111 : 'a' },
1375 'd' : { 111 : 'd' },
1378 'a' : { 130 : 'a' },
1379 'd' : { 130 : 'd' },
1382 'a' : { 100 : 'a' },
1383 'd' : { 100 : 'd' },
1384 't' : { 100 : 't' },
1411 'a' : { 150 : 'a' },
1412 'b' : { 150 : 'b' },
1439 'a' : { 151 : 'a' },
1466 'a' : { 155 : 'a' },
1494 function validateAuthority (button) {
1495 var grid = document.getElementById('recGrid');
1496 var label = button.getAttribute('label');
1499 var rows = grid.lastChild.childNodes;
1500 for (var i = 0; i < rows.length; i++) {
1502 var tag = row.firstChild;
1504 if (!control_map[tag.value]) continue
1506 var ind1 = tag.nextSibling;
1507 var ind2 = ind1.nextSibling;
1508 var subfields = ind2.nextSibling.childNodes;
1510 for (var j = 0; j < subfields.length; j++) {
1511 var sf = subfields[j];
1513 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1515 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1518 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1519 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1520 var res = new XML( x.responseText );
1522 if (res.gw::payload.gw::array.gw::string.length()) {
1529 sf.childNodes[2].inputField.style.color = 'red';
1531 sf.childNodes[2].inputField.style.color = 'black';
1536 button.setAttribute('label', label);
1542 function searchAuthority (term, tag, sf, limit) {
1543 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1544 url += '¶m="term"¶m="' + term + '"';
1545 url += '¶m="limit"¶m=' + limit;
1546 url += '¶m="tag"¶m=' + tag;
1547 url += '¶m="subfield"¶m="' + sf + '"';
1550 var req = new XMLHttpRequest();
1551 req.open('GET',url,false);