1 var serializer = new XMLSerializer();
2 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
3 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
4 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
5 default xml namespace = marcns;
12 function createComplexHTMLElement (e, attrs, objects, text) {
13 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
16 for (var i in attrs) l.setAttribute(i,attrs[i]);
20 for ( var i in objects ) l.appendChild( objects[i] );
24 l.appendChild( document.createTextNode(text) )
30 function createComplexXULElement (e, attrs, objects) {
31 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
34 for (var i in attrs) {
35 if (typeof attrs[i] == 'function') {
36 l.addEventListener( i, attrs[i], true );
38 l.setAttribute(i,attrs[i]);
44 for ( var i in objects ) l.appendChild( objects[i] );
50 function createDescription (attrs) {
51 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
54 function createTooltip (attrs) {
55 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
58 function createLabel (attrs) {
59 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
62 function createVbox (attrs) {
63 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
66 function createHbox (attrs) {
67 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
70 function createRow (attrs) {
71 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
74 function createTextbox (attrs) {
75 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
78 function createMenu (attrs) {
79 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
82 function createMenuPopup (attrs) {
83 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
86 function createPopup (attrs) {
87 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
90 function createMenuitem (attrs) {
91 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
94 function createCheckbox (attrs) {
95 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
98 function createMARCTextbox (element,attrs) {
100 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
101 box.onkeypress = function (event) {
104 while(node = node.parent()) {
108 var row = event.target;
109 while (row.tagName != 'row') row = row.parentNode;
111 if (element.nodeKind() == 'attribute') element[0]=box.value;
112 else element.setChildren( box.value );
114 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
116 var index_sf, target, move_data;
117 if (element.localName() == 'subfield') {
119 target = event.target.parentNode;
121 var start = event.target.selectionStart;
122 var end = event.target.selectionEnd - event.target.selectionStart ?
123 event.target.selectionEnd :
124 event.target.value.length;
126 move_data = event.target.value.substring(start,end);
127 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
128 event.target.setAttribute('size', event.target.value.length + 2);
130 element.setChildren( event.target.value );
132 } else if (element.localName() == 'code') {
133 index_sf = element.parent();
134 target = event.target.parentNode;
135 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
136 index_sf = element.parent().children()[element.parent().children().length() - 1];
137 target = event.target.parentNode.lastChild.lastChild;
140 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
142 index_sf.parent().insertChildAfter( index_sf, sf );
144 var new_sf = marcSubfield(sf);
146 if (target === target.parentNode.lastChild) {
147 target.parentNode.appendChild( new_sf );
149 target.parentNode.insertBefore( new_sf, target.nextSibling );
152 new_sf.firstChild.nextSibling.focus();
154 event.preventDefault();
157 } else if (event.keyCode == 13 || event.keyCode == 77) {
158 if (event.ctrlKey) { // ctrl+enter
161 if (element.localName() == 'subfield') index = element.parent();
162 if (element.localName() == 'code') index = element.parent().parent();
163 if (element.localName() == 'tag') index = element.parent();
164 if (element.localName() == 'ind1') index = element.parent();
165 if (element.localName() == 'ind2') index = element.parent();
167 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
169 index.parent().insertChildAfter( index, df );
171 var new_df = marcDatafield(df);
173 if (row.parentNode.lastChild === row) {
174 row.parentNode.appendChild( new_df );
176 row.parentNode.insertBefore( new_df, row.nextSibling );
179 new_df.firstChild.focus();
181 event.preventDefault();
184 } else if (event.shiftKey) {
185 if (row.previousSibling.className.match('marcDatafieldRow'))
186 row.previousSibling.firstChild.focus();
188 row.nextSibling.firstChild.focus();
191 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
194 if (element.localName() == 'subfield') index = element.parent();
195 if (element.localName() == 'code') index = element.parent().parent();
196 if (element.localName() == 'tag') index = element.parent();
197 if (element.localName() == 'ind1') index = element.parent();
198 if (element.localName() == 'ind2') index = element.parent();
200 for (var i in index.parent().children()) {
201 if (index === index.parent().children()[i]) {
202 delete index.parent().children()[i];
207 row.previousSibling.firstChild.focus();
208 row.parentNode.removeChild(row);
210 event.preventDefault();
213 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
216 if (element.localName() == 'subfield') index = element;
217 if (element.localName() == 'code') index = element.parent();
220 for (var i in index.parent().children()) {
221 if (index === index.parent().children()[i]) {
222 delete index.parent().children()[i];
227 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
228 event.target.parentNode.previousSibling.lastChild.focus();
230 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
233 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
235 event.preventDefault();
242 box.addEventListener(
245 if (element.nodeKind() == 'attribute') element[0]=box.value;
246 else element.setChildren( box.value );
252 box.addEventListener(
255 if (element.nodeKind() == 'attribute') element[0]=box.value;
256 else element.setChildren( box.value );
262 box.addEventListener(
265 if (element.nodeKind() == 'attribute') element[0]=box.value;
266 else element.setChildren( box.value );
276 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
277 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
278 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
279 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
280 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
281 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
282 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
283 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
289 BKS : {start : 15, len : 3, def : ' ' },
290 SER : {start : 15, len : 3, def : ' ' },
291 VIS : {start : 15, len : 3, def : ' ' },
292 MIX : {start : 15, len : 3, def : ' ' },
293 MAP : {start : 15, len : 3, def : ' ' },
294 SCO : {start : 15, len : 3, def : ' ' },
295 REC : {start : 15, len : 3, def : ' ' },
296 COM : {start : 15, len : 3, def : ' ' },
301 BKS : {start : 35, len : 3, def : ' ' },
302 SER : {start : 35, len : 3, def : ' ' },
303 VIS : {start : 35, len : 3, def : ' ' },
304 MIX : {start : 35, len : 3, def : ' ' },
305 MAP : {start : 35, len : 3, def : ' ' },
306 SCO : {start : 35, len : 3, def : ' ' },
307 REC : {start : 35, len : 3, def : ' ' },
308 COM : {start : 35, len : 3, def : ' ' },
313 BKS : {start : 38, len : 1, def : ' ' },
314 SER : {start : 38, len : 1, def : ' ' },
315 VIS : {start : 38, len : 1, def : ' ' },
316 MIX : {start : 38, len : 1, def : ' ' },
317 MAP : {start : 38, len : 1, def : ' ' },
318 SCO : {start : 38, len : 1, def : ' ' },
319 REC : {start : 38, len : 1, def : ' ' },
320 COM : {start : 38, len : 1, def : ' ' },
325 BKS : {start : 6, len : 1, def : ' ' },
326 SER : {start : 6, len : 1, def : 'c' },
327 VIS : {start : 6, len : 1, def : ' ' },
328 MIX : {start : 6, len : 1, def : ' ' },
329 MAP : {start : 6, len : 1, def : ' ' },
330 SCO : {start : 6, len : 1, def : ' ' },
331 REC : {start : 6, len : 1, def : ' ' },
332 COM : {start : 6, len : 1, def : ' ' },
337 BKS : {start : 6, len : 1, def : 'a' },
338 SER : {start : 6, len : 1, def : 'a' },
339 VIS : {start : 6, len : 1, def : 'g' },
340 MIX : {start : 6, len : 1, def : 'p' },
341 MAP : {start : 6, len : 1, def : 'e' },
342 SCO : {start : 6, len : 1, def : 'c' },
343 REC : {start : 6, len : 1, def : 'i' },
344 COM : {start : 6, len : 1, def : 'm' },
349 BKS : {start : 8, len : 1, def : ' ' },
350 SER : {start : 8, len : 1, def : ' ' },
351 VIS : {start : 8, len : 1, def : ' ' },
352 MIX : {start : 8, len : 1, def : ' ' },
353 MAP : {start : 8, len : 1, def : ' ' },
354 SCO : {start : 8, len : 1, def : ' ' },
355 REC : {start : 8, len : 1, def : ' ' },
356 COM : {start : 8, len : 1, def : ' ' },
361 BKS : {start : 7, len : 1, def : 'm' },
362 SER : {start : 7, len : 1, def : 's' },
363 VIS : {start : 7, len : 1, def : 'm' },
364 MIX : {start : 7, len : 1, def : 'c' },
365 MAP : {start : 7, len : 1, def : 'm' },
366 SCO : {start : 7, len : 1, def : 'm' },
367 REC : {start : 7, len : 1, def : 'm' },
368 COM : {start : 7, len : 1, def : 'm' },
373 BKS : {start : 18, len : 1, def : ' ' },
374 SER : {start : 18, len : 1, def : ' ' },
375 VIS : {start : 18, len : 1, def : ' ' },
376 MIX : {start : 18, len : 1, def : ' ' },
377 MAP : {start : 18, len : 1, def : ' ' },
378 SCO : {start : 18, len : 1, def : ' ' },
379 REC : {start : 18, len : 1, def : ' ' },
380 COM : {start : 18, len : 1, def : ' ' },
385 BKS : {start : 17, len : 1, def : ' ' },
386 SER : {start : 17, len : 1, def : ' ' },
387 VIS : {start : 17, len : 1, def : ' ' },
388 MIX : {start : 17, len : 1, def : ' ' },
389 MAP : {start : 17, len : 1, def : ' ' },
390 SCO : {start : 17, len : 1, def : ' ' },
391 REC : {start : 17, len : 1, def : ' ' },
392 COM : {start : 17, len : 1, def : ' ' },
397 BKS : {start : 31, len : 1, def : '0' },
398 MAP : {start : 31, len : 1, def : '0' },
401 BKS : {start : 14, len : 1, def : '0' },
402 MAP : {start : 14, len : 1, def : '0' },
407 BKS : {start : 7, len : 4, def : ' ' },
408 SER : {start : 7, len : 4, def : ' ' },
409 VIS : {start : 7, len : 4, def : ' ' },
410 MIX : {start : 7, len : 4, def : ' ' },
411 MAP : {start : 7, len : 4, def : ' ' },
412 SCO : {start : 7, len : 4, def : ' ' },
413 REC : {start : 7, len : 4, def : ' ' },
414 COM : {start : 7, len : 4, def : ' ' },
419 BKS : {start : 11, len : 4, def : ' ' },
420 SER : {start : 11, len : 4, def : '9' },
421 VIS : {start : 11, len : 4, def : ' ' },
422 MIX : {start : 11, len : 4, def : ' ' },
423 MAP : {start : 11, len : 4, def : ' ' },
424 SCO : {start : 11, len : 4, def : ' ' },
425 REC : {start : 11, len : 4, def : ' ' },
426 COM : {start : 11, len : 4, def : ' ' },
431 BKS : {start : 33, len : 1, def : '0' },
434 BKS : {start : 16, len : 1, def : '0' },
439 BKS : {start : 34, len : 1, def : ' ' },
442 BKS : {start : 17, len : 1, def : ' ' },
447 BKS : {start : 18, len : 4, def : ' ' },
450 BKS : {start : 1, len : 4, def : ' ' },
455 BKS : {start : 30, len : 1, def : '0' },
458 BKS : {start : 13, len : 1, def : '0' },
463 BKS : {start : 24, len : 4, def : ' ' },
464 SER : {start : 25, len : 3, def : ' ' },
467 BKS : {start : 7, len : 4, def : ' ' },
468 SER : {start : 8, len : 3, def : ' ' },
473 BKS : {start : 28, len : 1, def : ' ' },
474 SER : {start : 28, len : 1, def : ' ' },
475 VIS : {start : 28, len : 1, def : ' ' },
476 MAP : {start : 28, len : 1, def : ' ' },
477 COM : {start : 28, len : 1, def : ' ' },
480 BKS : {start : 11, len : 1, def : ' ' },
481 SER : {start : 11, len : 1, def : ' ' },
482 VIS : {start : 11, len : 1, def : ' ' },
483 MAP : {start : 11, len : 1, def : ' ' },
484 COM : {start : 11, len : 1, def : ' ' },
489 BKS : {start : 22, len : 1, def : ' ' },
490 SER : {start : 22, len : 1, def : ' ' },
491 VIS : {start : 22, len : 1, def : ' ' },
492 SCO : {start : 22, len : 1, def : ' ' },
493 REC : {start : 22, len : 1, def : ' ' },
494 COM : {start : 22, len : 1, def : ' ' },
497 BKS : {start : 5, len : 1, def : ' ' },
498 SER : {start : 5, len : 1, def : ' ' },
499 VIS : {start : 5, len : 1, def : ' ' },
500 SCO : {start : 5, len : 1, def : ' ' },
501 REC : {start : 5, len : 1, def : ' ' },
502 COM : {start : 5, len : 1, def : ' ' },
507 BKS : {start : 23, len : 1, def : ' ' },
508 SER : {start : 23, len : 1, def : ' ' },
509 VIS : {start : 29, len : 1, def : ' ' },
510 MIX : {start : 23, len : 1, def : ' ' },
511 MAP : {start : 29, len : 1, def : ' ' },
512 SCO : {start : 23, len : 1, def : ' ' },
513 REC : {start : 23, len : 1, def : ' ' },
516 BKS : {start : 6, len : 1, def : ' ' },
517 SER : {start : 6, len : 1, def : ' ' },
518 VIS : {start : 12, len : 1, def : ' ' },
519 MIX : {start : 6, len : 1, def : ' ' },
520 MAP : {start : 12, len : 1, def : ' ' },
521 SCO : {start : 6, len : 1, def : ' ' },
522 REC : {start : 6, len : 1, def : ' ' },
527 SER : {start : 34, len : 1, def : '0' },
530 SER : {start : 17, len : 1, def : '0' },
535 SER : {start : 33, len : 1, def : ' ' },
538 SER : {start : 16, len : 1, def : ' ' },
543 function recordType (rec) {
544 var _l = rec.leader.toString();
546 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
547 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
549 for (var t in rec_type) {
550 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
551 document.getElementById('recordTypeLabel').value = t;
558 function toggleFFE () {
559 var grid = document.getElementById('leaderGrid');
568 function changeFFEditor (type) {
569 var grid = document.getElementById('leaderGrid');
570 grid.setAttribute('type',type);
573 function fillFixedFields (rec) {
574 var grid = document.getElementById('leaderGrid');
576 var rtype = _record_type;
578 var _l = rec.leader.toString();
579 var _6 = rec.controlfield.(@tag=='006').toString();
580 var _7 = rec.controlfield.(@tag=='007').toString();
581 var _8 = rec.controlfield.(@tag=='008').toString();
584 var pre_list = grid.getElementsByTagName('label');
585 for (var i in pre_list) {
586 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
587 list.push( pre_list[i] );
591 for (var i in list) {
592 var name = list[i].getAttribute('name');
598 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
599 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
601 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
602 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
604 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
605 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
607 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
608 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
613 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
614 d = ff_pos[name].ldr[rtype].def;
618 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
619 d = ff_pos[name]._8[rtype].def;
623 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
624 d = ff_pos[name]._6[rtype].def;
628 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
629 d = ff_pos[name]._7[rtype].def;
634 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
640 list[i].nextSibling.value = value;
646 function updateFixedFields (element) {
647 var grid = document.getElementById('leaderGrid');
648 var recGrid = document.getElementById('recGrid');
650 var rtype = _record_type;
651 var new_value = element.value;
654 ldr : _record.leader,
655 _6 : _record.controlfield.(@tag=='006'),
656 _7 : _record.controlfield.(@tag=='007'),
657 _8 : _record.controlfield.(@tag=='008'),
660 var name = element.getAttribute('name');
661 for (var i in ff_pos[name]) {
663 if (!ff_pos[name][i][rtype]) continue;
664 if (!parts[i]) continue;
666 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
667 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
669 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
670 new_value += ff_pos[name][i][rtype].def;
673 parts[i].setChildren( before + new_value + after );
674 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
680 function marcLeader (leader) {
682 { class : 'marcLeaderRow',
687 tooltiptext : "MARC Leader" } ),
690 class : 'marcInd1' } ),
693 class : 'marcInd2' } ),
695 { value : leader.text(),
696 class : 'marcLeader' } )
702 function marcControlfield (field) {
703 tagname = field.@tag.toString().substr(2);
705 { class : 'marcControlfieldRow',
706 tag : '_' + tagname },
708 { value : field.@tag,
710 onmouseover : 'getTooltip(this, "tag");',
711 tooltipid : 'tag' + field.@tag } ),
713 { value : field.@ind1,
715 onmouseover : 'getTooltip(this, "ind1");',
716 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
718 { value : field.@ind2,
720 onmouseover : 'getTooltip(this, "ind2");',
721 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
723 { value : field.text(),
724 class : 'marcControlfield' } )
730 function stackSubfields(checkbox) {
731 var list = document.getElementsByAttribute('name','sf_box');
734 if (checkbox.checked) o = 'horizontal';
736 for (var i in list) {
737 if (list[i]) list[i].setAttribute('orient',o);
741 function marcDatafield (field) {
743 { class : 'marcDatafieldRow' },
746 { value : field.@tag,
747 class : 'plain marcTag',
749 context : 'tags_popup',
750 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
753 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
756 { value : field.@ind1,
757 class : 'plain marcInd1',
759 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
762 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
763 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
766 { value : field.@ind2,
767 class : 'plain marcInd2',
769 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
772 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
773 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
774 createHbox({ name : 'sf_box' })
777 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
778 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
779 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
781 var sf_box = row.lastChild;
782 if (document.getElementById('stackSubfields').checked)
783 sf_box.setAttribute('orient','vertical');
785 sf_box.addEventListener(
788 if (sf_box === e.target) {
789 sf_box.lastChild.lastChild.focus();
790 } else if (e.target.parentNode === sf_box) {
791 e.target.lastChild.focus();
798 for (var i in field.subfield) {
799 var sf = field.subfield[i];
804 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
805 current_focus = sf_box.lastChild.childNodes[1];
811 function marcSubfield (sf) {
813 { class : 'marcSubfieldBox' },
816 class : 'plain marcSubfieldDelimiter',
817 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
818 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
819 //onclick : 'this.nextSibling.focus();',
820 onfocus : 'this.nextSibling.focus();',
825 class : 'plain marcSubfieldCode',
826 name : 'marcSubfieldCode',
827 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
828 oncontextmenu : 'getContextMenu(this, "subfield");',
829 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
835 name : sf.parent().@tag + ':' + sf.@code,
836 class : 'plain marcSubfield',
837 onmouseover : 'getTooltip(this, "subfield");',
838 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
839 size : new String(sf.text()).length + 2,
840 oninput : "this.setAttribute('size', this.value.length + 2);",
845 function loadRecord(rec) {
847 var grid_rows = document.getElementById('recGrid').lastChild;
849 grid_rows.appendChild( marcLeader( rec.leader ) );
851 for (var i in rec.controlfield) {
852 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
855 for (var i in rec.datafield) {
856 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
859 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
860 changeFFEditor(recordType(rec));
861 fillFixedFields(rec);
864 var context_menus = createComplexXULElement('popupset');
865 document.documentElement.appendChild( context_menus );
867 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
868 context_menus.appendChild( tag_menu );
870 tag_menu.appendChild(
874 'var e = document.createEvent("KeyEvents");' +
875 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
876 'current_focus.inputField.dispatchEvent(e);',
881 tag_menu.appendChild(
883 { label : 'Remove Row',
885 'var e = document.createEvent("KeyEvents");' +
886 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
887 'current_focus.inputField.dispatchEvent(e);',
892 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
896 function genToolTips () {
897 for (var i in bib_data.field) {
898 var f = bib_data.field[i];
900 tag_menu.appendChild(
904 'current_focus.value = "' + f.@tag + '";' +
905 'var e = document.createEvent("MutationEvents");' +
906 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
907 'current_focus.inputField.dispatchEvent(e);',
908 disabled : f.@tag < '010' ? "true" : "false",
909 tooltiptext : f.description }
913 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
914 context_menus.appendChild( i1_popup );
916 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
917 context_menus.appendChild( i2_popup );
919 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
920 context_menus.appendChild( sf_popup );
922 tooltip_hash['tag' + f.@tag] = f.description;
923 for (var j in f.indicator) {
924 var ind = f.indicator[j];
925 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
927 if (ind.@position == 1) {
928 i1_popup.appendChild(
930 { label : ind.@value,
932 'current_focus.value = "' + ind.@value + '";' +
933 'var e = document.createEvent("MutationEvents");' +
934 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
935 'current_focus.inputField.dispatchEvent(e);',
936 tooltiptext : ind.description }
941 if (ind.@position == 2) {
942 i2_popup.appendChild(
944 { label : ind.@value,
946 'current_focus.value = "' + ind.@value + '";' +
947 'var e = document.createEvent("MutationEvents");' +
948 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
949 'current_focus.inputField.dispatchEvent(e);',
950 tooltiptext : ind.description }
956 for (var j in f.subfield) {
957 var sf = f.subfield[j];
958 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
960 sf_popup.appendChild(
964 'current_focus.value = "' + sf.@code + '";' +
965 'var e = document.createEvent("MutationEvents");' +
966 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
967 'current_focus.inputField.dispatchEvent(e);',
968 tooltiptext : sf.description,
976 var p = createComplexXULElement('popupset');
977 document.documentElement.appendChild( p );
979 function getTooltip (target, type) {
982 if (type == 'subfield')
983 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
986 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
989 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
992 tt = 'tag' + target.parentNode.firstChild.value;
994 if (!document.getElementById( tt )) {
1000 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1001 class : 'tooltip' },
1002 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1007 target.tooltip = tt;
1011 function getContextMenu (target, type) {
1014 if (type == 'subfield')
1015 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1018 tt = 't' + target.parentNode.firstChild.value + 'i1';
1021 tt = 't' + target.parentNode.firstChild.value + 'i2';
1023 target.setAttribute('context', tt);
1027 var authority_tag_map = {
1028 100 : ['[100,400,500,700]',100],
1029 110 : ['[110,410,510,710]',110],
1030 111 : ['[111,411,511,711]',111],
1031 240 : ['[130,430,530,730]',130],
1032 650 : ['[150,450,550,750]',150],
1033 651 : ['[151,451,551,751]',151],
1034 655 : ['[155,455,555,755]',155],
1037 function getAuthorityContextMenu (target, sf) {
1038 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1040 if (!authority_tag_map[sf.parent().@tag]) return false;
1042 var old = document.getElementById( menu_id );
1043 if (old) old.parentNode.removeChild(old);
1045 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1046 context_menus.appendChild( sf_popup );
1048 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 25);
1050 var res = new XML( auth_data.responseText );
1052 var recs = res.gw::payload.gw::array.gw::string;
1053 for (var i in recs) {
1055 var xml = new XML(x.toString());
1056 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1058 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1060 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1061 grid.setAttribute('name','-none-');
1062 grid.setAttribute('style','overflow:scroll');
1065 for (var i in main) {
1066 if (main_text) main_text += ' / ';
1067 main_text += main[i];
1070 var submenu = createMenu( { label : main_text } );
1072 var popup = createMenuPopup({ flex : "1" });
1073 submenu.appendChild(popup);
1075 var fields = xml.datafield;
1076 for (var j in fields) {
1078 var row = createRow(
1080 createLabel( { value : fields[j].@tag } ),
1081 createLabel( { value : fields[j].@ind1 } ),
1082 createLabel( { value : fields[j].@ind2 } )
1085 var sf_box = createHbox();
1087 var subfields = fields[j].subfield;
1088 for (var k in subfields) {
1091 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1092 subfield : subfields[k].@code,
1093 tag : subfields[k].parent().@tag,
1094 value : subfields[k]
1098 row.appendChild(sf_box);
1101 grid.lastChild.appendChild(row);
1104 grid.hidden = false;
1105 popup.appendChild( grid );
1109 { label : 'Apply Selected',
1110 command : function (event) {
1111 applyAuthority(event.target.previousSibling, target, sf);
1118 sf_popup.appendChild( submenu );
1121 target.setAttribute('context', menu_id);
1125 function applyAuthority ( target, ui_sf, e4x_sf ) {
1127 var new_vals = target.getElementsByAttribute('checked','true');
1128 var field = e4x_sf.parent();
1130 for (var i = 0; i < new_vals.length; i++) {
1132 var sf_list = field.subfield;
1133 for (var j in sf_list) {
1135 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1136 sf_list[j] = new_vals[i].getAttribute('value');
1137 new_vals[i].setAttribute('subfield','');
1143 for (var i = 0; i < new_vals.length; i++) {
1144 if (!new_vals[i].getAttribute('subfield')) continue;
1146 var val = new_vals[i].getAttribute('value');
1148 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1149 sf.@code = new_vals[i].getAttribute('subfield');
1151 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1154 var row = marcDatafield( field );
1157 while (node.nodeName != 'row') {
1158 node = node.parentNode;
1161 node.parentNode.replaceChild( row, node );
1165 function searchAuthority (term, tag, sf, limit) {
1166 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1167 url += '¶m="term"¶m="' + term + '"';
1168 url += '¶m="limit"¶m=' + limit;
1169 url += '¶m="tag"¶m=' + tag + '';
1170 url += '¶m="subfield"¶m="' + sf + '"';
1173 var req = new XMLHttpRequest();
1174 req.open('GET',url,false);