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 );
68 // Fake xulG for standalone...
73 window.xulG.record = {};
74 window.xulG.save = {};
76 window.xulG.save.label = 'Save Record';
77 window.xulG.save.func = function (r) { alert(r); }
80 var _rid = cgi.param('record');
82 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
87 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
88 document.getElementById('save-button').setAttribute('oncommand', 'mangle_005(); window.xulG.save.func(xml_record.toXMLString()); loadRecord(xml_record);');
90 if (window.xulG.record.url) {
91 var req = new XMLHttpRequest();
92 req.open('GET',window.xulG.record.url,false);
94 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
97 xml_record = new XML( window.xulG.record.marc );
98 if (xml_record..record[0]) xml_record = xml_record..record[0];
100 // Get the tooltip xml all async like
101 req = new XMLHttpRequest();
102 req.open('GET','marcedit-tooltips.xml',true);
103 req.onreadystatechange = function () {
104 if (req.readyState == 4) {
105 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
111 loadRecord(xml_record);
113 alert('FIXME, MARC Editor, my_init: ' + E);
118 function createComplexHTMLElement (e, attrs, objects, text) {
119 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
122 for (var i in attrs) l.setAttribute(i,attrs[i]);
126 for ( var i in objects ) l.appendChild( objects[i] );
130 l.appendChild( document.createTextNode(text) )
136 function createComplexXULElement (e, attrs, objects) {
137 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
140 for (var i in attrs) {
141 if (typeof attrs[i] == 'function') {
142 l.addEventListener( i, attrs[i], true );
144 l.setAttribute(i,attrs[i]);
150 for ( var i in objects ) l.appendChild( objects[i] );
156 function createDescription (attrs) {
157 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
160 function createTooltip (attrs) {
161 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
164 function createLabel (attrs) {
165 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
168 function createVbox (attrs) {
169 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
172 function createHbox (attrs) {
173 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
176 function createRow (attrs) {
177 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
180 function createTextbox (attrs) {
181 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
184 function createMenu (attrs) {
185 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
188 function createMenuPopup (attrs) {
189 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
192 function createPopup (attrs) {
193 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
196 function createMenuitem (attrs) {
197 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
200 function createCheckbox (attrs) {
201 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
204 function createMARCTextbox (element,attrs) {
206 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
207 box.onkeypress = function (event) {
210 while(node = node.parent()) {
214 var row = event.target;
215 while (row.tagName != 'row') row = row.parentNode;
217 if (element.nodeKind() == 'attribute') element[0]=box.value;
218 else element.setChildren( box.value );
220 if (element.localName() != 'controlfield') {
221 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
223 var index_sf, target, move_data;
224 if (element.localName() == 'subfield') {
226 target = event.target.parentNode;
228 var start = event.target.selectionStart;
229 var end = event.target.selectionEnd - event.target.selectionStart ?
230 event.target.selectionEnd :
231 event.target.value.length;
233 move_data = event.target.value.substring(start,end);
234 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
235 event.target.setAttribute('size', event.target.value.length + 2);
237 element.setChildren( event.target.value );
239 } else if (element.localName() == 'code') {
240 index_sf = element.parent();
241 target = event.target.parentNode;
242 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
243 index_sf = element.parent().children()[element.parent().children().length() - 1];
244 target = event.target.parentNode.lastChild.lastChild;
247 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
249 index_sf.parent().insertChildAfter( index_sf, sf );
251 var new_sf = marcSubfield(sf);
253 if (target === target.parentNode.lastChild) {
254 target.parentNode.appendChild( new_sf );
256 target.parentNode.insertBefore( new_sf, target.nextSibling );
259 new_sf.firstChild.nextSibling.focus();
261 event.preventDefault();
264 } else if (event.keyCode == 13 || event.keyCode == 77) {
265 if (event.ctrlKey) { // ctrl+enter
268 if (element.localName() == 'subfield') index = element.parent();
269 if (element.localName() == 'code') index = element.parent().parent();
270 if (element.localName() == 'tag') index = element.parent();
271 if (element.localName() == 'ind1') index = element.parent();
272 if (element.localName() == 'ind2') index = element.parent();
274 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
276 index.parent().insertChildAfter( index, df );
278 var new_df = marcDatafield(df);
280 if (row.parentNode.lastChild === row) {
281 row.parentNode.appendChild( new_df );
283 row.parentNode.insertBefore( new_df, row.nextSibling );
286 new_df.firstChild.focus();
288 event.preventDefault();
291 } else if (event.shiftKey) {
292 if (row.previousSibling.className.match('marcDatafieldRow'))
293 row.previousSibling.firstChild.focus();
295 row.nextSibling.firstChild.focus();
298 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
301 if (element.localName() == 'subfield') index = element.parent();
302 if (element.localName() == 'code') index = element.parent().parent();
303 if (element.localName() == 'tag') index = element.parent();
304 if (element.localName() == 'ind1') index = element.parent();
305 if (element.localName() == 'ind2') index = element.parent();
307 for (var i in index.parent().children()) {
308 if (index === index.parent().children()[i]) {
309 delete index.parent().children()[i];
314 row.previousSibling.firstChild.focus();
315 row.parentNode.removeChild(row);
317 event.preventDefault();
320 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
323 if (element.localName() == 'subfield') index = element;
324 if (element.localName() == 'code') 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 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
335 event.target.parentNode.previousSibling.lastChild.focus();
337 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
340 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
342 event.preventDefault();
345 } else if (event.keyCode == 64 && event.ctrlKey) { // ctrl + F6
346 createControlField('006','');
347 loadRecord(xml_record);
348 } else if (event.keyCode == 65 && event.ctrlKey) { // ctrl + F7
349 createControlField('007','');
350 loadRecord(xml_record);
351 } else if (event.keyCode == 66 && event.ctrlKey) { // ctrl + F8
352 createControlField('008','');
353 loadRecord(xml_record);
359 box.addEventListener(
362 if (element.nodeKind() == 'attribute') element[0]=box.value;
363 else element.setChildren( box.value );
369 box.addEventListener(
372 if (element.nodeKind() == 'attribute') element[0]=box.value;
373 else element.setChildren( box.value );
379 box.addEventListener(
382 if (element.nodeKind() == 'attribute') element[0]=box.value;
383 else element.setChildren( box.value );
389 box.addEventListener(
392 if (element.localName() == 'controlfield')
393 eval('fillFixedFields(xml_record);');
402 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
403 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
404 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
405 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
406 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
407 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
408 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
409 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
415 BKS : {start : 15, len : 3, def : ' ' },
416 SER : {start : 15, len : 3, def : ' ' },
417 VIS : {start : 15, len : 3, def : ' ' },
418 MIX : {start : 15, len : 3, def : ' ' },
419 MAP : {start : 15, len : 3, def : ' ' },
420 SCO : {start : 15, len : 3, def : ' ' },
421 REC : {start : 15, len : 3, def : ' ' },
422 COM : {start : 15, len : 3, def : ' ' },
427 BKS : {start : 35, len : 3, def : ' ' },
428 SER : {start : 35, len : 3, def : ' ' },
429 VIS : {start : 35, len : 3, def : ' ' },
430 MIX : {start : 35, len : 3, def : ' ' },
431 MAP : {start : 35, len : 3, def : ' ' },
432 SCO : {start : 35, len : 3, def : ' ' },
433 REC : {start : 35, len : 3, def : ' ' },
434 COM : {start : 35, len : 3, def : ' ' },
439 BKS : {start : 38, len : 1, def : ' ' },
440 SER : {start : 38, len : 1, def : ' ' },
441 VIS : {start : 38, len : 1, def : ' ' },
442 MIX : {start : 38, len : 1, def : ' ' },
443 MAP : {start : 38, len : 1, def : ' ' },
444 SCO : {start : 38, len : 1, def : ' ' },
445 REC : {start : 38, len : 1, def : ' ' },
446 COM : {start : 38, len : 1, def : ' ' },
451 BKS : {start : 6, len : 1, def : ' ' },
452 SER : {start : 6, len : 1, def : 'c' },
453 VIS : {start : 6, len : 1, def : ' ' },
454 MIX : {start : 6, len : 1, def : ' ' },
455 MAP : {start : 6, len : 1, def : ' ' },
456 SCO : {start : 6, len : 1, def : ' ' },
457 REC : {start : 6, len : 1, def : ' ' },
458 COM : {start : 6, len : 1, def : ' ' },
463 BKS : {start : 6, len : 1, def : 'a' },
464 SER : {start : 6, len : 1, def : 'a' },
465 VIS : {start : 6, len : 1, def : 'g' },
466 MIX : {start : 6, len : 1, def : 'p' },
467 MAP : {start : 6, len : 1, def : 'e' },
468 SCO : {start : 6, len : 1, def : 'c' },
469 REC : {start : 6, len : 1, def : 'i' },
470 COM : {start : 6, len : 1, def : 'm' },
475 BKS : {start : 8, len : 1, def : ' ' },
476 SER : {start : 8, len : 1, def : ' ' },
477 VIS : {start : 8, len : 1, def : ' ' },
478 MIX : {start : 8, len : 1, def : ' ' },
479 MAP : {start : 8, len : 1, def : ' ' },
480 SCO : {start : 8, len : 1, def : ' ' },
481 REC : {start : 8, len : 1, def : ' ' },
482 COM : {start : 8, len : 1, def : ' ' },
487 BKS : {start : 7, len : 1, def : 'm' },
488 SER : {start : 7, len : 1, def : 's' },
489 VIS : {start : 7, len : 1, def : 'm' },
490 MIX : {start : 7, len : 1, def : 'c' },
491 MAP : {start : 7, len : 1, def : 'm' },
492 SCO : {start : 7, len : 1, def : 'm' },
493 REC : {start : 7, len : 1, def : 'm' },
494 COM : {start : 7, len : 1, def : 'm' },
499 BKS : {start : 18, len : 1, def : ' ' },
500 SER : {start : 18, len : 1, def : ' ' },
501 VIS : {start : 18, len : 1, def : ' ' },
502 MIX : {start : 18, len : 1, def : ' ' },
503 MAP : {start : 18, len : 1, def : ' ' },
504 SCO : {start : 18, len : 1, def : ' ' },
505 REC : {start : 18, len : 1, def : ' ' },
506 COM : {start : 18, len : 1, def : ' ' },
511 BKS : {start : 17, len : 1, def : ' ' },
512 SER : {start : 17, len : 1, def : ' ' },
513 VIS : {start : 17, len : 1, def : ' ' },
514 MIX : {start : 17, len : 1, def : ' ' },
515 MAP : {start : 17, len : 1, def : ' ' },
516 SCO : {start : 17, len : 1, def : ' ' },
517 REC : {start : 17, len : 1, def : ' ' },
518 COM : {start : 17, len : 1, def : ' ' },
523 BKS : {start : 31, len : 1, def : '0' },
524 MAP : {start : 31, len : 1, def : '0' },
527 BKS : {start : 14, len : 1, def : '0' },
528 MAP : {start : 14, len : 1, def : '0' },
533 BKS : {start : 7, len : 4, def : ' ' },
534 SER : {start : 7, len : 4, def : ' ' },
535 VIS : {start : 7, len : 4, def : ' ' },
536 MIX : {start : 7, len : 4, def : ' ' },
537 MAP : {start : 7, len : 4, def : ' ' },
538 SCO : {start : 7, len : 4, def : ' ' },
539 REC : {start : 7, len : 4, def : ' ' },
540 COM : {start : 7, len : 4, def : ' ' },
545 BKS : {start : 11, len : 4, def : ' ' },
546 SER : {start : 11, len : 4, def : '9' },
547 VIS : {start : 11, len : 4, def : ' ' },
548 MIX : {start : 11, len : 4, def : ' ' },
549 MAP : {start : 11, len : 4, def : ' ' },
550 SCO : {start : 11, len : 4, def : ' ' },
551 REC : {start : 11, len : 4, def : ' ' },
552 COM : {start : 11, len : 4, def : ' ' },
557 BKS : {start : 33, len : 1, def : '0' },
560 BKS : {start : 16, len : 1, def : '0' },
565 BKS : {start : 34, len : 1, def : ' ' },
568 BKS : {start : 17, len : 1, def : ' ' },
573 BKS : {start : 18, len : 4, def : ' ' },
576 BKS : {start : 1, len : 4, def : ' ' },
581 BKS : {start : 30, len : 1, def : '0' },
584 BKS : {start : 13, len : 1, def : '0' },
589 BKS : {start : 24, len : 4, def : ' ' },
590 SER : {start : 25, len : 3, def : ' ' },
593 BKS : {start : 7, len : 4, def : ' ' },
594 SER : {start : 8, len : 3, def : ' ' },
599 BKS : {start : 28, len : 1, def : ' ' },
600 SER : {start : 28, len : 1, def : ' ' },
601 VIS : {start : 28, len : 1, def : ' ' },
602 MAP : {start : 28, len : 1, def : ' ' },
603 COM : {start : 28, len : 1, def : ' ' },
606 BKS : {start : 11, len : 1, def : ' ' },
607 SER : {start : 11, len : 1, def : ' ' },
608 VIS : {start : 11, len : 1, def : ' ' },
609 MAP : {start : 11, len : 1, def : ' ' },
610 COM : {start : 11, len : 1, def : ' ' },
615 BKS : {start : 22, len : 1, def : ' ' },
616 SER : {start : 22, len : 1, def : ' ' },
617 VIS : {start : 22, len : 1, def : ' ' },
618 SCO : {start : 22, len : 1, def : ' ' },
619 REC : {start : 22, len : 1, def : ' ' },
620 COM : {start : 22, len : 1, def : ' ' },
623 BKS : {start : 5, len : 1, def : ' ' },
624 SER : {start : 5, len : 1, def : ' ' },
625 VIS : {start : 5, len : 1, def : ' ' },
626 SCO : {start : 5, len : 1, def : ' ' },
627 REC : {start : 5, len : 1, def : ' ' },
628 COM : {start : 5, len : 1, def : ' ' },
633 BKS : {start : 23, len : 1, def : ' ' },
634 SER : {start : 23, len : 1, def : ' ' },
635 VIS : {start : 29, len : 1, def : ' ' },
636 MIX : {start : 23, len : 1, def : ' ' },
637 MAP : {start : 29, len : 1, def : ' ' },
638 SCO : {start : 23, len : 1, def : ' ' },
639 REC : {start : 23, len : 1, def : ' ' },
642 BKS : {start : 6, len : 1, def : ' ' },
643 SER : {start : 6, len : 1, def : ' ' },
644 VIS : {start : 12, len : 1, def : ' ' },
645 MIX : {start : 6, len : 1, def : ' ' },
646 MAP : {start : 12, len : 1, def : ' ' },
647 SCO : {start : 6, len : 1, def : ' ' },
648 REC : {start : 6, len : 1, def : ' ' },
653 SER : {start : 34, len : 1, def : '0' },
656 SER : {start : 17, len : 1, def : '0' },
661 SER : {start : 33, len : 1, def : ' ' },
664 SER : {start : 16, len : 1, def : ' ' },
669 function recordType (rec) {
671 var _l = rec.leader.toString();
673 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
674 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
676 for (var t in rec_type) {
677 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
678 document.getElementById('recordTypeLabel').value = t;
684 alert('FIXME, MARC Editor, recordType: ' + E);
688 function toggleFFE () {
689 var grid = document.getElementById('leaderGrid');
698 function changeFFEditor (type) {
699 var grid = document.getElementById('leaderGrid');
700 grid.setAttribute('type',type);
703 function fillFixedFields (rec) {
705 var grid = document.getElementById('leaderGrid');
707 var rtype = _record_type;
709 var _l = rec.leader.toString();
710 var _6 = rec.controlfield.(@tag=='006').toString();
711 var _7 = rec.controlfield.(@tag=='007').toString();
712 var _8 = rec.controlfield.(@tag=='008').toString();
715 var pre_list = grid.getElementsByTagName('label');
716 for (var i in pre_list) {
717 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
718 list.push( pre_list[i] );
722 for (var i in list) {
723 var name = list[i].getAttribute('name');
729 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
730 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
732 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
733 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
735 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
736 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
738 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
739 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
744 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
745 d = ff_pos[name].ldr[rtype].def;
749 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
750 d = ff_pos[name]._8[rtype].def;
754 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
755 d = ff_pos[name]._6[rtype].def;
759 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
760 d = ff_pos[name]._7[rtype].def;
765 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
771 list[i].nextSibling.value = value;
776 alert('FIXME, MARC Editor, fillFixedFields: ' + E);
780 function updateFixedFields (element) {
781 var grid = document.getElementById('leaderGrid');
782 var recGrid = document.getElementById('recGrid');
784 var rtype = _record_type;
785 var new_value = element.value;
788 ldr : _record.leader,
789 _6 : _record.controlfield.(@tag=='006'),
790 _7 : _record.controlfield.(@tag=='007'),
791 _8 : _record.controlfield.(@tag=='008'),
794 var name = element.getAttribute('name');
795 for (var i in ff_pos[name]) {
797 if (!ff_pos[name][i][rtype]) continue;
798 if (!parts[i]) continue;
800 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
801 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
803 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
804 new_value += ff_pos[name][i][rtype].def;
807 parts[i].setChildren( before + new_value + after );
808 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
814 function marcLeader (leader) {
816 { class : 'marcLeaderRow',
821 tooltiptext : "MARC Leader" } ),
824 class : 'marcInd1' } ),
827 class : 'marcInd2' } ),
829 { value : leader.text(),
830 class : 'marcLeader' } )
836 function marcControlfield (field) {
837 tagname = field.@tag.toString().substr(2);
839 if (tagname == '6' || tagname == '7' || tagname == '8') {
841 { class : 'marcControlfieldRow',
842 tag : '_' + tagname },
844 { value : field.@tag,
846 context : 'tags_popup',
847 onmouseover : 'getTooltip(this, "tag");',
848 tooltipid : 'tag' + field.@tag } ),
850 { value : field.@ind1,
852 onmouseover : 'getTooltip(this, "ind1");',
853 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
855 { value : field.@ind2,
857 onmouseover : 'getTooltip(this, "ind2");',
858 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
861 { value : field.text(),
862 class : 'plain marcEditableControlfield',
863 name : 'CONTROL' + tagname,
864 oncontext : 'return false();',
870 { class : 'marcControlfieldRow',
871 tag : '_' + tagname },
873 { value : field.@tag,
875 onmouseover : 'getTooltip(this, "tag");',
876 tooltipid : 'tag' + field.@tag } ),
878 { value : field.@ind1,
880 onmouseover : 'getTooltip(this, "ind1");',
881 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
883 { value : field.@ind2,
885 onmouseover : 'getTooltip(this, "ind2");',
886 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
888 { value : field.text(),
889 class : 'marcControlfield' } )
896 function stackSubfields(checkbox) {
897 var list = document.getElementsByAttribute('name','sf_box');
900 if (checkbox.checked) o = 'horizontal';
902 for (var i = 0; i < list.length; i++) {
903 if (list[i]) list[i].setAttribute('orient',o);
907 function marcDatafield (field) {
909 { class : 'marcDatafieldRow' },
912 { value : field.@tag,
913 class : 'plain marcTag',
915 context : 'tags_popup',
916 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
919 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
922 { value : field.@ind1,
923 class : 'plain marcInd1',
925 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
928 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
929 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
932 { value : field.@ind2,
933 class : 'plain marcInd2',
935 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
938 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
939 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
940 createHbox({ name : 'sf_box' })
943 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
944 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
945 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
947 var sf_box = row.lastChild;
948 if (document.getElementById('stackSubfields').checked)
949 sf_box.setAttribute('orient','vertical');
951 sf_box.addEventListener(
954 if (sf_box === e.target) {
955 sf_box.lastChild.lastChild.focus();
956 } else if (e.target.parentNode === sf_box) {
957 e.target.lastChild.focus();
964 for (var i in field.subfield) {
965 var sf = field.subfield[i];
970 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
971 current_focus = sf_box.lastChild.childNodes[1];
977 function marcSubfield (sf) {
979 { class : 'marcSubfieldBox' },
982 class : 'plain marcSubfieldDelimiter',
983 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
984 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
985 //onclick : 'this.nextSibling.focus();',
986 onfocus : 'this.nextSibling.focus();',
991 class : 'plain marcSubfieldCode',
992 name : 'marcSubfieldCode',
993 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
994 oncontextmenu : 'getContextMenu(this, "subfield");',
995 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
1000 { value : sf.text(),
1001 name : sf.parent().@tag + ':' + sf.@code,
1002 class : 'plain marcSubfield',
1003 onmouseover : 'getTooltip(this, "subfield");',
1004 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
1005 size : new String(sf.text()).length + 2,
1006 oninput : "this.setAttribute('size', this.value.length + 2);",
1011 function loadRecord(rec) {
1014 var grid_rows = document.getElementById('recGrid').lastChild;
1016 while (grid_rows.firstChild) grid_rows.removeChild(grid_rows.firstChild);
1018 grid_rows.appendChild( marcLeader( rec.leader ) );
1020 for (var i in rec.controlfield) {
1021 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
1024 for (var i in rec.datafield) {
1025 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
1028 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
1029 changeFFEditor(recordType(rec));
1030 fillFixedFields(rec);
1032 alert('FIXME, MARC Editor, loadRecord: ' + E);
1036 var context_menus = createComplexXULElement('popupset');
1037 document.documentElement.appendChild( context_menus );
1039 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
1040 context_menus.appendChild( tag_menu );
1042 tag_menu.appendChild(
1044 { label : 'Add Row',
1046 'var e = document.createEvent("KeyEvents");' +
1047 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
1048 'current_focus.inputField.dispatchEvent(e);',
1053 tag_menu.appendChild(
1055 { label : 'Remove Row',
1057 'var e = document.createEvent("KeyEvents");' +
1058 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
1059 'current_focus.inputField.dispatchEvent(e);',
1064 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1066 tag_menu.appendChild(
1068 { label : 'Add/Replace 006',
1070 'var e = document.createEvent("KeyEvents");' +
1071 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,64,0);' +
1072 'current_focus.inputField.dispatchEvent(e);',
1077 tag_menu.appendChild(
1079 { label : 'Add/Replace 007',
1081 'var e = document.createEvent("KeyEvents");' +
1082 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,65,0);' +
1083 'current_focus.inputField.dispatchEvent(e);',
1088 tag_menu.appendChild(
1090 { label : 'Add/Replace 008',
1092 'var e = document.createEvent("KeyEvents");' +
1093 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,66,0);' +
1094 'current_focus.inputField.dispatchEvent(e);',
1099 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
1103 function genToolTips () {
1104 for (var i in bib_data.field) {
1105 var f = bib_data.field[i];
1107 tag_menu.appendChild(
1111 'current_focus.value = "' + f.@tag + '";' +
1112 'var e = document.createEvent("MutationEvents");' +
1113 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1114 'current_focus.inputField.dispatchEvent(e);',
1115 disabled : f.@tag < '010' ? "true" : "false",
1116 tooltiptext : f.description }
1120 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
1121 context_menus.appendChild( i1_popup );
1123 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
1124 context_menus.appendChild( i2_popup );
1126 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
1127 context_menus.appendChild( sf_popup );
1129 tooltip_hash['tag' + f.@tag] = f.description;
1130 for (var j in f.indicator) {
1131 var ind = f.indicator[j];
1132 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
1134 if (ind.@position == 1) {
1135 i1_popup.appendChild(
1137 { label : ind.@value,
1139 'current_focus.value = "' + ind.@value + '";' +
1140 'var e = document.createEvent("MutationEvents");' +
1141 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1142 'current_focus.inputField.dispatchEvent(e);',
1143 tooltiptext : ind.description }
1148 if (ind.@position == 2) {
1149 i2_popup.appendChild(
1151 { label : ind.@value,
1153 'current_focus.value = "' + ind.@value + '";' +
1154 'var e = document.createEvent("MutationEvents");' +
1155 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1156 'current_focus.inputField.dispatchEvent(e);',
1157 tooltiptext : ind.description }
1163 for (var j in f.subfield) {
1164 var sf = f.subfield[j];
1165 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1167 sf_popup.appendChild(
1171 'current_focus.value = "' + sf.@code + '";' +
1172 'var e = document.createEvent("MutationEvents");' +
1173 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1174 'current_focus.inputField.dispatchEvent(e);',
1175 tooltiptext : sf.description,
1183 var p = createComplexXULElement('popupset');
1184 document.documentElement.appendChild( p );
1186 function getTooltip (target, type) {
1189 if (type == 'subfield')
1190 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1193 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1196 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1199 tt = 'tag' + target.parentNode.firstChild.value;
1201 if (!document.getElementById( tt )) {
1206 orient : 'vertical',
1207 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1208 class : 'tooltip' },
1209 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1214 target.tooltip = tt;
1218 function getContextMenu (target, type) {
1221 if (type == 'subfield')
1222 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1225 tt = 't' + target.parentNode.firstChild.value + 'i1';
1228 tt = 't' + target.parentNode.firstChild.value + 'i2';
1230 target.setAttribute('context', tt);
1234 var authority_tag_map = {
1235 100 : ['[100,400,500,700]',100],
1236 400 : ['[100,400,500,700]',100],
1237 700 : ['[100,400,500,700]',100],
1238 800 : ['[100,400,500,700]',100],
1239 110 : ['[110,410,510,710]',110],
1240 410 : ['[110,410,510,710]',110],
1241 710 : ['[110,410,510,710]',110],
1242 810 : ['[110,410,510,710]',110],
1243 111 : ['[111,411,511,711]',111],
1244 411 : ['[111,411,511,711]',111],
1245 711 : ['[111,411,511,711]',111],
1246 811 : ['[111,411,511,711]',111],
1247 240 : ['[130,430,530,730]',130],
1248 440 : ['[130,430,530,730]',130],
1249 130 : ['[130,430,530,730]',130],
1250 730 : ['[130,430,530,730]',130],
1251 830 : ['[130,430,530,730]',130],
1252 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1253 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1254 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1255 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1258 function getAuthorityContextMenu (target, sf) {
1259 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1261 var old = document.getElementById( menu_id );
1262 if (old) old.parentNode.removeChild(old);
1264 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1265 context_menus.appendChild( sf_popup );
1267 if (!authority_tag_map[sf.parent().@tag]) {
1268 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1269 target.setAttribute('context', menu_id);
1273 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1275 var res = new XML( auth_data.responseText );
1279 var recs = res.gw::payload.gw::array.gw::string;
1280 for (var i in recs) {
1282 var xml = new XML(x.toString());
1283 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1285 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1288 for (var i in main) {
1289 if (main_text) main_text += ' / ';
1290 main_text += main[i];
1293 rec_list.push( [ main_text, xml ] );
1296 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1298 var main_text = rec_list[i][0];
1299 var xml = rec_list[i][1];
1300 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1302 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1304 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1305 grid.setAttribute('name','-none-');
1306 grid.setAttribute('style','overflow:scroll');
1309 var submenu = createMenu( { label : main_text } );
1311 var popup = createMenuPopup({ flex : "1" });
1312 submenu.appendChild(popup);
1314 var fields = xml.datafield;
1315 for (var j in fields) {
1317 var row = createRow(
1319 createLabel( { value : fields[j].@tag } ),
1320 createLabel( { value : fields[j].@ind1 } ),
1321 createLabel( { value : fields[j].@ind2 } )
1324 var sf_box = createHbox();
1326 var subfields = fields[j].subfield;
1327 for (var k in subfields) {
1330 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1331 subfield : subfields[k].@code,
1332 tag : subfields[k].parent().@tag,
1333 value : subfields[k]
1337 row.appendChild(sf_box);
1340 grid.lastChild.appendChild(row);
1343 grid.hidden = false;
1344 popup.appendChild( grid );
1348 { label : 'Apply Selected',
1349 command : function (event) {
1350 applyAuthority(event.target.previousSibling, target, sf);
1357 sf_popup.appendChild( submenu );
1360 if (sf_popup.childNodes.length == 0)
1361 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1363 target.setAttribute('context', menu_id);
1367 function applyAuthority ( target, ui_sf, e4x_sf ) {
1369 var new_vals = target.getElementsByAttribute('checked','true');
1370 var field = e4x_sf.parent();
1372 for (var i = 0; i < new_vals.length; i++) {
1374 var sf_list = field.subfield;
1375 for (var j in sf_list) {
1377 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1378 sf_list[j] = new_vals[i].getAttribute('value');
1379 new_vals[i].setAttribute('subfield','');
1385 for (var i = 0; i < new_vals.length; i++) {
1386 if (!new_vals[i].getAttribute('subfield')) continue;
1388 var val = new_vals[i].getAttribute('value');
1390 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1391 sf.@code = new_vals[i].getAttribute('subfield');
1393 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1396 var row = marcDatafield( field );
1399 while (node.nodeName != 'row') {
1400 node = node.parentNode;
1403 node.parentNode.replaceChild( row, node );
1409 'a' : { 100 : 'a' },
1410 'd' : { 100 : 'd' },
1413 'a' : { 110 : 'a' },
1414 'd' : { 110 : 'd' },
1417 'a' : { 111 : 'a' },
1418 'd' : { 111 : 'd' },
1421 'a' : { 130 : 'a' },
1422 'd' : { 130 : 'd' },
1425 'a' : { 130 : 'a' },
1426 'd' : { 130 : 'd' },
1429 'a' : { 100 : 'a' },
1430 'd' : { 100 : 'd' },
1433 'a' : { 110 : 'a' },
1434 'd' : { 110 : 'd' },
1437 'a' : { 111 : 'a' },
1438 'd' : { 111 : 'd' },
1441 'a' : { 130 : 'a' },
1442 'n' : { 130 : 'n' },
1443 'p' : { 130 : 'p' },
1446 'a' : { 100 : 'a' },
1447 'd' : { 100 : 'd' },
1450 'a' : { 110 : 'a' },
1451 'd' : { 110 : 'd' },
1454 'a' : { 111 : 'a' },
1455 'd' : { 111 : 'd' },
1458 'a' : { 130 : 'a' },
1459 'd' : { 130 : 'd' },
1462 'a' : { 100 : 'a' },
1463 'd' : { 100 : 'd' },
1466 'a' : { 110 : 'a' },
1467 'd' : { 110 : 'd' },
1470 'a' : { 111 : 'a' },
1471 'd' : { 111 : 'd' },
1474 'a' : { 130 : 'a' },
1475 'd' : { 130 : 'd' },
1478 'a' : { 100 : 'a' },
1479 'd' : { 100 : 'd' },
1480 't' : { 100 : 't' },
1507 'a' : { 150 : 'a' },
1508 'b' : { 150 : 'b' },
1535 'a' : { 151 : 'a' },
1562 'a' : { 155 : 'a' },
1590 function validateAuthority (button) {
1591 var grid = document.getElementById('recGrid');
1592 var label = button.getAttribute('label');
1595 var rows = grid.lastChild.childNodes;
1596 for (var i = 0; i < rows.length; i++) {
1598 var tag = row.firstChild;
1600 if (!control_map[tag.value]) continue
1602 var ind1 = tag.nextSibling;
1603 var ind2 = ind1.nextSibling;
1604 var subfields = ind2.nextSibling.childNodes;
1606 for (var j = 0; j < subfields.length; j++) {
1607 var sf = subfields[j];
1609 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1611 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1614 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1615 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1616 var res = new XML( x.responseText );
1618 if (res.gw::payload.gw::array.gw::string.length()) {
1625 sf.childNodes[2].inputField.style.color = 'red';
1627 sf.childNodes[2].inputField.style.color = 'black';
1632 button.setAttribute('label', label);
1638 function searchAuthority (term, tag, sf, limit) {
1639 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1640 url += '¶m="term"¶m="' + term + '"';
1641 url += '¶m="limit"¶m=' + limit;
1642 url += '¶m="tag"¶m=' + tag;
1643 url += '¶m="subfield"¶m="' + sf + '"';
1646 var req = new XMLHttpRequest();
1647 req.open('GET',url,false);