1 var xmlDeclaration = /^<\?xml version[^>]+?>/;
3 var serializer = new XMLSerializer();
4 var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
5 var gw = new Namespace("http://opensrf.org/-/namespaces/gateway/v1");
6 var xulns = new Namespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
7 default xml namespace = marcns;
18 // Fake xulG for standalone...
23 window.xulG.record = {};
24 window.xulG.save = {};
26 window.xulG.save.label = 'Save Record';
27 window.xulG.save.func = function (r) { alert(r); }
30 var _rid = cgi.param('record');
32 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
37 document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
38 document.getElementById('save-button').setAttribute('oncommand', 'window.xulG.save.func(xml_record.toXMLString())');
40 if (window.xulG.record.url) {
41 var req = new XMLHttpRequest();
42 req.open('GET',window.xulG.record.url,false);
44 window.xulG.record.marc = req.responseText.replace(xmlDeclaration, '');
47 xml_record = new XML( window.xulG.record.marc );
48 xml_record = xml_record..record[0];
50 // Get the tooltip xml all async like
51 req = new XMLHttpRequest();
52 req.open('GET','marcedit-tooltips.xml',true);
53 req.onreadystatechange = function () {
54 if (req.readyState == 4) {
55 bib_data = new XML( req.responseText.replace(xmlDeclaration, '') );
61 loadRecord(xml_record);
63 alert('FIXME, MARC Editor: ' + E);
68 function createComplexHTMLElement (e, attrs, objects, text) {
69 var l = document.createElementNS('http://www.w3.org/1999/xhtml',e);
72 for (var i in attrs) l.setAttribute(i,attrs[i]);
76 for ( var i in objects ) l.appendChild( objects[i] );
80 l.appendChild( document.createTextNode(text) )
86 function createComplexXULElement (e, attrs, objects) {
87 var l = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',e);
90 for (var i in attrs) {
91 if (typeof attrs[i] == 'function') {
92 l.addEventListener( i, attrs[i], true );
94 l.setAttribute(i,attrs[i]);
100 for ( var i in objects ) l.appendChild( objects[i] );
106 function createDescription (attrs) {
107 return createComplexXULElement('description', attrs, Array.prototype.slice.apply(arguments, [1]) );
110 function createTooltip (attrs) {
111 return createComplexXULElement('tooltip', attrs, Array.prototype.slice.apply(arguments, [1]) );
114 function createLabel (attrs) {
115 return createComplexXULElement('label', attrs, Array.prototype.slice.apply(arguments, [1]) );
118 function createVbox (attrs) {
119 return createComplexXULElement('vbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
122 function createHbox (attrs) {
123 return createComplexXULElement('hbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
126 function createRow (attrs) {
127 return createComplexXULElement('row', attrs, Array.prototype.slice.apply(arguments, [1]) );
130 function createTextbox (attrs) {
131 return createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
134 function createMenu (attrs) {
135 return createComplexXULElement('menu', attrs, Array.prototype.slice.apply(arguments, [1]) );
138 function createMenuPopup (attrs) {
139 return createComplexXULElement('menupopup', attrs, Array.prototype.slice.apply(arguments, [1]) );
142 function createPopup (attrs) {
143 return createComplexXULElement('popup', attrs, Array.prototype.slice.apply(arguments, [1]) );
146 function createMenuitem (attrs) {
147 return createComplexXULElement('menuitem', attrs, Array.prototype.slice.apply(arguments, [1]) );
150 function createCheckbox (attrs) {
151 return createComplexXULElement('checkbox', attrs, Array.prototype.slice.apply(arguments, [1]) );
154 function createMARCTextbox (element,attrs) {
156 var box = createComplexXULElement('textbox', attrs, Array.prototype.slice.apply(arguments, [2]) );
157 box.onkeypress = function (event) {
160 while(node = node.parent()) {
164 var row = event.target;
165 while (row.tagName != 'row') row = row.parentNode;
167 if (element.nodeKind() == 'attribute') element[0]=box.value;
168 else element.setChildren( box.value );
170 if (event.charCode == 100 && event.ctrlKey) { // ctrl+d
172 var index_sf, target, move_data;
173 if (element.localName() == 'subfield') {
175 target = event.target.parentNode;
177 var start = event.target.selectionStart;
178 var end = event.target.selectionEnd - event.target.selectionStart ?
179 event.target.selectionEnd :
180 event.target.value.length;
182 move_data = event.target.value.substring(start,end);
183 event.target.value = event.target.value.substring(0,start) + event.target.value.substring(end);
184 event.target.setAttribute('size', event.target.value.length + 2);
186 element.setChildren( event.target.value );
188 } else if (element.localName() == 'code') {
189 index_sf = element.parent();
190 target = event.target.parentNode;
191 } else if (element.localName() == 'tag' || element.localName() == 'ind1' || element.localName() == 'ind2') {
192 index_sf = element.parent().children()[element.parent().children().length() - 1];
193 target = event.target.parentNode.lastChild.lastChild;
196 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{ move_data }</subfield>;
198 index_sf.parent().insertChildAfter( index_sf, sf );
200 var new_sf = marcSubfield(sf);
202 if (target === target.parentNode.lastChild) {
203 target.parentNode.appendChild( new_sf );
205 target.parentNode.insertBefore( new_sf, target.nextSibling );
208 new_sf.firstChild.nextSibling.focus();
210 event.preventDefault();
213 } else if (event.keyCode == 13 || event.keyCode == 77) {
214 if (event.ctrlKey) { // ctrl+enter
217 if (element.localName() == 'subfield') index = element.parent();
218 if (element.localName() == 'code') index = element.parent().parent();
219 if (element.localName() == 'tag') index = element.parent();
220 if (element.localName() == 'ind1') index = element.parent();
221 if (element.localName() == 'ind2') index = element.parent();
223 var df = <datafield tag="" ind1="" ind2="" xmlns="http://www.loc.gov/MARC21/slim"><subfield code="" /></datafield>;
225 index.parent().insertChildAfter( index, df );
227 var new_df = marcDatafield(df);
229 if (row.parentNode.lastChild === row) {
230 row.parentNode.appendChild( new_df );
232 row.parentNode.insertBefore( new_df, row.nextSibling );
235 new_df.firstChild.focus();
237 event.preventDefault();
240 } else if (event.shiftKey) {
241 if (row.previousSibling.className.match('marcDatafieldRow'))
242 row.previousSibling.firstChild.focus();
244 row.nextSibling.firstChild.focus();
247 } else if (event.keyCode == 46 && event.ctrlKey) { // ctrl+del
250 if (element.localName() == 'subfield') index = element.parent();
251 if (element.localName() == 'code') index = element.parent().parent();
252 if (element.localName() == 'tag') index = element.parent();
253 if (element.localName() == 'ind1') index = element.parent();
254 if (element.localName() == 'ind2') index = element.parent();
256 for (var i in index.parent().children()) {
257 if (index === index.parent().children()[i]) {
258 delete index.parent().children()[i];
263 row.previousSibling.firstChild.focus();
264 row.parentNode.removeChild(row);
266 event.preventDefault();
269 } else if (event.keyCode == 46 && event.shiftKey) { // shift+del
272 if (element.localName() == 'subfield') index = element;
273 if (element.localName() == 'code') index = element.parent();
276 for (var i in index.parent().children()) {
277 if (index === index.parent().children()[i]) {
278 delete index.parent().children()[i];
283 if (event.target.parentNode === event.target.parentNode.parentNode.lastChild) {
284 event.target.parentNode.previousSibling.lastChild.focus();
286 event.target.parentNode.nextSibling.firstChild.nextSibling.focus();
289 event.target.parentNode.parentNode.removeChild(event.target.parentNode);
291 event.preventDefault();
298 box.addEventListener(
301 if (element.nodeKind() == 'attribute') element[0]=box.value;
302 else element.setChildren( box.value );
308 box.addEventListener(
311 if (element.nodeKind() == 'attribute') element[0]=box.value;
312 else element.setChildren( box.value );
318 box.addEventListener(
321 if (element.nodeKind() == 'attribute') element[0]=box.value;
322 else element.setChildren( box.value );
332 BKS : { Type : /[at]{1}/, BLvl : /[acdm]{1}/ },
333 SER : { Type : /[a]{1}/, BLvl : /[bs]{1}/ },
334 VIS : { Type : /[gkro]{1}/, BLvl : /[abcdms]{1}/ },
335 MIX : { Type : /[p]{1}/, BLvl : /[cd]{1}/ },
336 MAP : { Type : /[ef]{1}/, BLvl : /[abcdms]{1}/ },
337 SCO : { Type : /[cd]{1}/, BLvl : /[abcdms]{1}/ },
338 REC : { Type : /[ij]{1}/, BLvl : /[abcdms]{1}/ },
339 COM : { Type : /[m]{1}/, BLvl : /[abcdms]{1}/ }
345 BKS : {start : 15, len : 3, def : ' ' },
346 SER : {start : 15, len : 3, def : ' ' },
347 VIS : {start : 15, len : 3, def : ' ' },
348 MIX : {start : 15, len : 3, def : ' ' },
349 MAP : {start : 15, len : 3, def : ' ' },
350 SCO : {start : 15, len : 3, def : ' ' },
351 REC : {start : 15, len : 3, def : ' ' },
352 COM : {start : 15, len : 3, def : ' ' },
357 BKS : {start : 35, len : 3, def : ' ' },
358 SER : {start : 35, len : 3, def : ' ' },
359 VIS : {start : 35, len : 3, def : ' ' },
360 MIX : {start : 35, len : 3, def : ' ' },
361 MAP : {start : 35, len : 3, def : ' ' },
362 SCO : {start : 35, len : 3, def : ' ' },
363 REC : {start : 35, len : 3, def : ' ' },
364 COM : {start : 35, len : 3, def : ' ' },
369 BKS : {start : 38, len : 1, def : ' ' },
370 SER : {start : 38, len : 1, def : ' ' },
371 VIS : {start : 38, len : 1, def : ' ' },
372 MIX : {start : 38, len : 1, def : ' ' },
373 MAP : {start : 38, len : 1, def : ' ' },
374 SCO : {start : 38, len : 1, def : ' ' },
375 REC : {start : 38, len : 1, def : ' ' },
376 COM : {start : 38, len : 1, def : ' ' },
381 BKS : {start : 6, len : 1, def : ' ' },
382 SER : {start : 6, len : 1, def : 'c' },
383 VIS : {start : 6, len : 1, def : ' ' },
384 MIX : {start : 6, len : 1, def : ' ' },
385 MAP : {start : 6, len : 1, def : ' ' },
386 SCO : {start : 6, len : 1, def : ' ' },
387 REC : {start : 6, len : 1, def : ' ' },
388 COM : {start : 6, len : 1, def : ' ' },
393 BKS : {start : 6, len : 1, def : 'a' },
394 SER : {start : 6, len : 1, def : 'a' },
395 VIS : {start : 6, len : 1, def : 'g' },
396 MIX : {start : 6, len : 1, def : 'p' },
397 MAP : {start : 6, len : 1, def : 'e' },
398 SCO : {start : 6, len : 1, def : 'c' },
399 REC : {start : 6, len : 1, def : 'i' },
400 COM : {start : 6, len : 1, def : 'm' },
405 BKS : {start : 8, len : 1, def : ' ' },
406 SER : {start : 8, len : 1, def : ' ' },
407 VIS : {start : 8, len : 1, def : ' ' },
408 MIX : {start : 8, len : 1, def : ' ' },
409 MAP : {start : 8, len : 1, def : ' ' },
410 SCO : {start : 8, len : 1, def : ' ' },
411 REC : {start : 8, len : 1, def : ' ' },
412 COM : {start : 8, len : 1, def : ' ' },
417 BKS : {start : 7, len : 1, def : 'm' },
418 SER : {start : 7, len : 1, def : 's' },
419 VIS : {start : 7, len : 1, def : 'm' },
420 MIX : {start : 7, len : 1, def : 'c' },
421 MAP : {start : 7, len : 1, def : 'm' },
422 SCO : {start : 7, len : 1, def : 'm' },
423 REC : {start : 7, len : 1, def : 'm' },
424 COM : {start : 7, len : 1, def : 'm' },
429 BKS : {start : 18, len : 1, def : ' ' },
430 SER : {start : 18, len : 1, def : ' ' },
431 VIS : {start : 18, len : 1, def : ' ' },
432 MIX : {start : 18, len : 1, def : ' ' },
433 MAP : {start : 18, len : 1, def : ' ' },
434 SCO : {start : 18, len : 1, def : ' ' },
435 REC : {start : 18, len : 1, def : ' ' },
436 COM : {start : 18, len : 1, def : ' ' },
441 BKS : {start : 17, len : 1, def : ' ' },
442 SER : {start : 17, len : 1, def : ' ' },
443 VIS : {start : 17, len : 1, def : ' ' },
444 MIX : {start : 17, len : 1, def : ' ' },
445 MAP : {start : 17, len : 1, def : ' ' },
446 SCO : {start : 17, len : 1, def : ' ' },
447 REC : {start : 17, len : 1, def : ' ' },
448 COM : {start : 17, len : 1, def : ' ' },
453 BKS : {start : 31, len : 1, def : '0' },
454 MAP : {start : 31, len : 1, def : '0' },
457 BKS : {start : 14, len : 1, def : '0' },
458 MAP : {start : 14, len : 1, def : '0' },
463 BKS : {start : 7, len : 4, def : ' ' },
464 SER : {start : 7, len : 4, def : ' ' },
465 VIS : {start : 7, len : 4, def : ' ' },
466 MIX : {start : 7, len : 4, def : ' ' },
467 MAP : {start : 7, len : 4, def : ' ' },
468 SCO : {start : 7, len : 4, def : ' ' },
469 REC : {start : 7, len : 4, def : ' ' },
470 COM : {start : 7, len : 4, def : ' ' },
475 BKS : {start : 11, len : 4, def : ' ' },
476 SER : {start : 11, len : 4, def : '9' },
477 VIS : {start : 11, len : 4, def : ' ' },
478 MIX : {start : 11, len : 4, def : ' ' },
479 MAP : {start : 11, len : 4, def : ' ' },
480 SCO : {start : 11, len : 4, def : ' ' },
481 REC : {start : 11, len : 4, def : ' ' },
482 COM : {start : 11, len : 4, def : ' ' },
487 BKS : {start : 33, len : 1, def : '0' },
490 BKS : {start : 16, len : 1, def : '0' },
495 BKS : {start : 34, len : 1, def : ' ' },
498 BKS : {start : 17, len : 1, def : ' ' },
503 BKS : {start : 18, len : 4, def : ' ' },
506 BKS : {start : 1, len : 4, def : ' ' },
511 BKS : {start : 30, len : 1, def : '0' },
514 BKS : {start : 13, len : 1, def : '0' },
519 BKS : {start : 24, len : 4, def : ' ' },
520 SER : {start : 25, len : 3, def : ' ' },
523 BKS : {start : 7, len : 4, def : ' ' },
524 SER : {start : 8, len : 3, def : ' ' },
529 BKS : {start : 28, len : 1, def : ' ' },
530 SER : {start : 28, len : 1, def : ' ' },
531 VIS : {start : 28, len : 1, def : ' ' },
532 MAP : {start : 28, len : 1, def : ' ' },
533 COM : {start : 28, len : 1, def : ' ' },
536 BKS : {start : 11, len : 1, def : ' ' },
537 SER : {start : 11, len : 1, def : ' ' },
538 VIS : {start : 11, len : 1, def : ' ' },
539 MAP : {start : 11, len : 1, def : ' ' },
540 COM : {start : 11, len : 1, def : ' ' },
545 BKS : {start : 22, len : 1, def : ' ' },
546 SER : {start : 22, len : 1, def : ' ' },
547 VIS : {start : 22, len : 1, def : ' ' },
548 SCO : {start : 22, len : 1, def : ' ' },
549 REC : {start : 22, len : 1, def : ' ' },
550 COM : {start : 22, len : 1, def : ' ' },
553 BKS : {start : 5, len : 1, def : ' ' },
554 SER : {start : 5, len : 1, def : ' ' },
555 VIS : {start : 5, len : 1, def : ' ' },
556 SCO : {start : 5, len : 1, def : ' ' },
557 REC : {start : 5, len : 1, def : ' ' },
558 COM : {start : 5, len : 1, def : ' ' },
563 BKS : {start : 23, len : 1, def : ' ' },
564 SER : {start : 23, len : 1, def : ' ' },
565 VIS : {start : 29, len : 1, def : ' ' },
566 MIX : {start : 23, len : 1, def : ' ' },
567 MAP : {start : 29, len : 1, def : ' ' },
568 SCO : {start : 23, len : 1, def : ' ' },
569 REC : {start : 23, len : 1, def : ' ' },
572 BKS : {start : 6, len : 1, def : ' ' },
573 SER : {start : 6, len : 1, def : ' ' },
574 VIS : {start : 12, len : 1, def : ' ' },
575 MIX : {start : 6, len : 1, def : ' ' },
576 MAP : {start : 12, len : 1, def : ' ' },
577 SCO : {start : 6, len : 1, def : ' ' },
578 REC : {start : 6, len : 1, def : ' ' },
583 SER : {start : 34, len : 1, def : '0' },
586 SER : {start : 17, len : 1, def : '0' },
591 SER : {start : 33, len : 1, def : ' ' },
594 SER : {start : 16, len : 1, def : ' ' },
599 function recordType (rec) {
600 var _l = rec.leader.toString();
602 var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
603 var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
605 for (var t in rec_type) {
606 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
607 document.getElementById('recordTypeLabel').value = t;
614 function toggleFFE () {
615 var grid = document.getElementById('leaderGrid');
624 function changeFFEditor (type) {
625 var grid = document.getElementById('leaderGrid');
626 grid.setAttribute('type',type);
629 function fillFixedFields (rec) {
630 var grid = document.getElementById('leaderGrid');
632 var rtype = _record_type;
634 var _l = rec.leader.toString();
635 var _6 = rec.controlfield.(@tag=='006').toString();
636 var _7 = rec.controlfield.(@tag=='007').toString();
637 var _8 = rec.controlfield.(@tag=='008').toString();
640 var pre_list = grid.getElementsByTagName('label');
641 for (var i in pre_list) {
642 if ( pre_list[i].getAttribute && pre_list[i].getAttribute('set').indexOf(grid.getAttribute('type')) > -1 ) {
643 list.push( pre_list[i] );
647 for (var i in list) {
648 var name = list[i].getAttribute('name');
654 if ( ff_pos[name].ldr && ff_pos[name].ldr[rtype] )
655 value = _l.substr(ff_pos[name].ldr[rtype].start, ff_pos[name].ldr[rtype].len);
657 if ( ff_pos[name]._8 && ff_pos[name]._8[rtype] )
658 value = _8.substr(ff_pos[name]._8[rtype].start, ff_pos[name]._8[rtype].len);
660 if ( !value && ff_pos[name]._6 && ff_pos[name]._6[rtype] )
661 value = _6.substr(ff_pos[name]._6[rtype].start, ff_pos[name]._6[rtype].len);
663 if ( ff_pos[name]._7 && ff_pos[name]._7[rtype] )
664 value = _7.substr(ff_pos[name]._7[rtype].start, ff_pos[name]._7[rtype].len);
669 if (ff_pos[name].ldr && ff_pos[name].ldr[rtype]) {
670 d = ff_pos[name].ldr[rtype].def;
674 if (ff_pos[name]._8 && ff_pos[name]._8[rtype]) {
675 d = ff_pos[name]._8[rtype].def;
679 if (!value && ff_pos[name]._6 && ff_pos[name]._6[rtype]) {
680 d = ff_pos[name]._6[rtype].def;
684 if (ff_pos[name]._7 && ff_pos[name]._7[rtype]) {
685 d = ff_pos[name]._7[rtype].def;
690 for (var j = 0; j < ff_pos[name][p][rtype].len; j++) {
696 list[i].nextSibling.value = value;
702 function updateFixedFields (element) {
703 var grid = document.getElementById('leaderGrid');
704 var recGrid = document.getElementById('recGrid');
706 var rtype = _record_type;
707 var new_value = element.value;
710 ldr : _record.leader,
711 _6 : _record.controlfield.(@tag=='006'),
712 _7 : _record.controlfield.(@tag=='007'),
713 _8 : _record.controlfield.(@tag=='008'),
716 var name = element.getAttribute('name');
717 for (var i in ff_pos[name]) {
719 if (!ff_pos[name][i][rtype]) continue;
720 if (!parts[i]) continue;
722 var before = parts[i].substr(0, ff_pos[name][i][rtype].start);
723 var after = parts[i].substr(ff_pos[name][i][rtype].start + ff_pos[name][i][rtype].len);
725 for (var j = 0; new_value.length < ff_pos[name][i][rtype].len; j++) {
726 new_value += ff_pos[name][i][rtype].def;
729 parts[i].setChildren( before + new_value + after );
730 recGrid.getElementsByAttribute('tag',i)[0].lastChild.value = parts[i].toString();
736 function marcLeader (leader) {
738 { class : 'marcLeaderRow',
743 tooltiptext : "MARC Leader" } ),
746 class : 'marcInd1' } ),
749 class : 'marcInd2' } ),
751 { value : leader.text(),
752 class : 'marcLeader' } )
758 function marcControlfield (field) {
759 tagname = field.@tag.toString().substr(2);
761 { class : 'marcControlfieldRow',
762 tag : '_' + tagname },
764 { value : field.@tag,
766 onmouseover : 'getTooltip(this, "tag");',
767 tooltipid : 'tag' + field.@tag } ),
769 { value : field.@ind1,
771 onmouseover : 'getTooltip(this, "ind1");',
772 tooltipid : 'tag' + field.@tag + 'ind1val' + field.@ind1 } ),
774 { value : field.@ind2,
776 onmouseover : 'getTooltip(this, "ind2");',
777 tooltipid : 'tag' + field.@tag + 'ind2val' + field.@ind2 } ),
779 { value : field.text(),
780 class : 'marcControlfield' } )
786 function stackSubfields(checkbox) {
787 var list = document.getElementsByAttribute('name','sf_box');
790 if (checkbox.checked) o = 'horizontal';
792 for (var i = 0; i < list.length; i++) {
793 if (list[i]) list[i].setAttribute('orient',o);
797 function marcDatafield (field) {
799 { class : 'marcDatafieldRow' },
802 { value : field.@tag,
803 class : 'plain marcTag',
805 context : 'tags_popup',
806 oninput : 'if (this.value.length == 3) { this.nextSibling.focus(); }',
809 onmouseover : 'current_focus = this; getTooltip(this, "tag");' } ),
812 { value : field.@ind1,
813 class : 'plain marcInd1',
815 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
818 onmouseover : 'current_focus = this; getContextMenu(this, "ind1"); getTooltip(this, "ind1");',
819 oncontextmenu : 'getContextMenu(this, "ind1");' } ),
822 { value : field.@ind2,
823 class : 'plain marcInd2',
825 oninput : 'if (this.value.length == 1) { this.nextSibling.firstChild.firstChild.focus(); }',
828 onmouseover : 'current_focus = this; getContextMenu(this, "ind2"); getTooltip(this, "ind2");',
829 oncontextmenu : 'getContextMenu(this, "ind2");' } ),
830 createHbox({ name : 'sf_box' })
833 if (!current_focus && field.@tag == '') current_focus = row.childNodes[0];
834 if (!current_focus && field.@ind1 == '') current_focus = row.childNodes[1];
835 if (!current_focus && field.@ind2 == '') current_focus = row.childNodes[2];
837 var sf_box = row.lastChild;
838 if (document.getElementById('stackSubfields').checked)
839 sf_box.setAttribute('orient','vertical');
841 sf_box.addEventListener(
844 if (sf_box === e.target) {
845 sf_box.lastChild.lastChild.focus();
846 } else if (e.target.parentNode === sf_box) {
847 e.target.lastChild.focus();
854 for (var i in field.subfield) {
855 var sf = field.subfield[i];
860 if (sf.@code == '' && (!current_focus || current_focus.className.match(/Ind/)))
861 current_focus = sf_box.lastChild.childNodes[1];
867 function marcSubfield (sf) {
869 { class : 'marcSubfieldBox' },
872 class : 'plain marcSubfieldDelimiter',
873 onmouseover : 'getTooltip(this.nextSibling, "subfield");',
874 oncontextmenu : 'getContextMenu(this.nextSibling, "subfield");',
875 //onclick : 'this.nextSibling.focus();',
876 onfocus : 'this.nextSibling.focus();',
881 class : 'plain marcSubfieldCode',
882 name : 'marcSubfieldCode',
883 onmouseover : 'current_focus = this; getContextMenu(this, "subfield"); getTooltip(this, "subfield");',
884 oncontextmenu : 'getContextMenu(this, "subfield");',
885 oninput : 'if (this.value.length == 1) { this.nextSibling.focus(); }',
891 name : sf.parent().@tag + ':' + sf.@code,
892 class : 'plain marcSubfield',
893 onmouseover : 'getTooltip(this, "subfield");',
894 contextmenu : function (event) { getAuthorityContextMenu(event.target, sf) },
895 size : new String(sf.text()).length + 2,
896 oninput : "this.setAttribute('size', this.value.length + 2);",
901 function loadRecord(rec) {
903 var grid_rows = document.getElementById('recGrid').lastChild;
905 grid_rows.appendChild( marcLeader( rec.leader ) );
907 for (var i in rec.controlfield) {
908 grid_rows.appendChild( marcControlfield( rec.controlfield[i] ) );
911 for (var i in rec.datafield) {
912 grid_rows.appendChild( marcDatafield( rec.datafield[i] ) );
915 grid_rows.getElementsByAttribute('class','marcDatafieldRow')[0].firstChild.focus();
916 changeFFEditor(recordType(rec));
917 fillFixedFields(rec);
920 var context_menus = createComplexXULElement('popupset');
921 document.documentElement.appendChild( context_menus );
923 var tag_menu = createPopup({position : 'after_start', id : 'tags_popup'});
924 context_menus.appendChild( tag_menu );
926 tag_menu.appendChild(
930 'var e = document.createEvent("KeyEvents");' +
931 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,13,0);' +
932 'current_focus.inputField.dispatchEvent(e);',
937 tag_menu.appendChild(
939 { label : 'Remove Row',
941 'var e = document.createEvent("KeyEvents");' +
942 'e.initKeyEvent("keypress",1,1,null,1,0,0,0,46,0);' +
943 'current_focus.inputField.dispatchEvent(e);',
948 tag_menu.appendChild( createComplexXULElement( 'separator' ) );
952 function genToolTips () {
953 for (var i in bib_data.field) {
954 var f = bib_data.field[i];
956 tag_menu.appendChild(
960 'current_focus.value = "' + f.@tag + '";' +
961 'var e = document.createEvent("MutationEvents");' +
962 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
963 'current_focus.inputField.dispatchEvent(e);',
964 disabled : f.@tag < '010' ? "true" : "false",
965 tooltiptext : f.description }
969 var i1_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i1' });
970 context_menus.appendChild( i1_popup );
972 var i2_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'i2' });
973 context_menus.appendChild( i2_popup );
975 var sf_popup = createPopup({position : 'after_start', id : 't' + f.@tag + 'sf' });
976 context_menus.appendChild( sf_popup );
978 tooltip_hash['tag' + f.@tag] = f.description;
979 for (var j in f.indicator) {
980 var ind = f.indicator[j];
981 tooltip_hash['tag' + f.@tag + 'ind' + ind.@position + 'val' + ind.@value] = ind.description;
983 if (ind.@position == 1) {
984 i1_popup.appendChild(
986 { label : ind.@value,
988 'current_focus.value = "' + ind.@value + '";' +
989 'var e = document.createEvent("MutationEvents");' +
990 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
991 'current_focus.inputField.dispatchEvent(e);',
992 tooltiptext : ind.description }
997 if (ind.@position == 2) {
998 i2_popup.appendChild(
1000 { label : ind.@value,
1002 'current_focus.value = "' + ind.@value + '";' +
1003 'var e = document.createEvent("MutationEvents");' +
1004 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1005 'current_focus.inputField.dispatchEvent(e);',
1006 tooltiptext : ind.description }
1012 for (var j in f.subfield) {
1013 var sf = f.subfield[j];
1014 tooltip_hash['tag' + f.@tag + 'sf' + sf.@code] = sf.description;
1016 sf_popup.appendChild(
1020 'current_focus.value = "' + sf.@code + '";' +
1021 'var e = document.createEvent("MutationEvents");' +
1022 'e.initMutationEvent("change",1,1,null,0,0,0,0);' +
1023 'current_focus.inputField.dispatchEvent(e);',
1024 tooltiptext : sf.description,
1032 var p = createComplexXULElement('popupset');
1033 document.documentElement.appendChild( p );
1035 function getTooltip (target, type) {
1038 if (type == 'subfield')
1039 tt = 'tag' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf' + target.parentNode.childNodes[1].value;
1042 tt = 'tag' + target.parentNode.firstChild.value + 'ind1val' + target.value;
1045 tt = 'tag' + target.parentNode.firstChild.value + 'ind2val' + target.value;
1048 tt = 'tag' + target.parentNode.firstChild.value;
1050 if (!document.getElementById( tt )) {
1055 orient : 'vertical',
1056 onpopupshown : 'this.width = this.firstChild.boxObject.width + 10; this.height = this.firstChild.boxObject.height + 10;',
1057 class : 'tooltip' },
1058 createDescription({}, document.createTextNode( tooltip_hash[tt] ) )
1063 target.tooltip = tt;
1067 function getContextMenu (target, type) {
1070 if (type == 'subfield')
1071 tt = 't' + target.parentNode.parentNode.parentNode.firstChild.value + 'sf';
1074 tt = 't' + target.parentNode.firstChild.value + 'i1';
1077 tt = 't' + target.parentNode.firstChild.value + 'i2';
1079 target.setAttribute('context', tt);
1083 var authority_tag_map = {
1084 100 : ['[100,400,500,700]',100],
1085 400 : ['[100,400,500,700]',100],
1086 700 : ['[100,400,500,700]',100],
1087 800 : ['[100,400,500,700]',100],
1088 110 : ['[110,410,510,710]',110],
1089 410 : ['[110,410,510,710]',110],
1090 710 : ['[110,410,510,710]',110],
1091 810 : ['[110,410,510,710]',110],
1092 111 : ['[111,411,511,711]',111],
1093 411 : ['[111,411,511,711]',111],
1094 711 : ['[111,411,511,711]',111],
1095 811 : ['[111,411,511,711]',111],
1096 240 : ['[130,430,530,730]',130],
1097 440 : ['[130,430,530,730]',130],
1098 130 : ['[130,430,530,730]',130],
1099 730 : ['[130,430,530,730]',130],
1100 830 : ['[130,430,530,730]',130],
1101 600 : ['[100,400,480,481,482,485,500,580,581,582,585,700,780,781,782,785]',100],
1102 650 : ['[150,450,480,481,482,485,550,580,581,582,585,750,780,781,782,785]',150],
1103 651 : ['[151,451,480,481,482,485,551,580,581,582,585,751,780,781,782,785]',151],
1104 655 : ['[155,455,480,481,482,485,555,580,581,582,585,755,780,781,782,785]',155],
1107 function getAuthorityContextMenu (target, sf) {
1108 var menu_id = sf.parent().@tag + ':' + sf.@code + '-authority-context-' + sf;
1110 var old = document.getElementById( menu_id );
1111 if (old) old.parentNode.removeChild(old);
1113 var sf_popup = createPopup({ id : menu_id, flex : 1 });
1114 context_menus.appendChild( sf_popup );
1116 if (!authority_tag_map[sf.parent().@tag]) {
1117 sf_popup.appendChild(createLabel( { value : "Not a controlled subfield" } ) );
1118 target.setAttribute('context', menu_id);
1122 var auth_data = searchAuthority( sf, authority_tag_map[sf.parent().@tag][0], sf.@code, 50);
1124 var res = new XML( auth_data.responseText );
1128 var recs = res.gw::payload.gw::array.gw::string;
1129 for (var i in recs) {
1131 var xml = new XML(x.toString());
1132 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1134 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1137 for (var i in main) {
1138 if (main_text) main_text += ' / ';
1139 main_text += main[i];
1142 rec_list.push( [ main_text, xml ] );
1145 for (var i in rec_list.sort( function (a, b) { if(a[0] > b[0]) return 1; return -1; } )) {
1147 var main_text = rec_list[i][0];
1148 var xml = rec_list[i][1];
1149 var main = xml.datafield.(@tag.toString().match(/^1/)).subfield;
1151 if (! (main[0].parent().@tag == authority_tag_map[sf.parent().@tag][1]) ) continue;
1153 var grid = document.getElementsByAttribute('name','authority-marc-template')[0].cloneNode(true);
1154 grid.setAttribute('name','-none-');
1155 grid.setAttribute('style','overflow:scroll');
1158 var submenu = createMenu( { label : main_text } );
1160 var popup = createMenuPopup({ flex : "1" });
1161 submenu.appendChild(popup);
1163 var fields = xml.datafield;
1164 for (var j in fields) {
1166 var row = createRow(
1168 createLabel( { value : fields[j].@tag } ),
1169 createLabel( { value : fields[j].@ind1 } ),
1170 createLabel( { value : fields[j].@ind2 } )
1173 var sf_box = createHbox();
1175 var subfields = fields[j].subfield;
1176 for (var k in subfields) {
1179 { label : '\u2021' + subfields[k].@code + ' ' + subfields[k],
1180 subfield : subfields[k].@code,
1181 tag : subfields[k].parent().@tag,
1182 value : subfields[k]
1186 row.appendChild(sf_box);
1189 grid.lastChild.appendChild(row);
1192 grid.hidden = false;
1193 popup.appendChild( grid );
1197 { label : 'Apply Selected',
1198 command : function (event) {
1199 applyAuthority(event.target.previousSibling, target, sf);
1206 sf_popup.appendChild( submenu );
1209 if (sf_popup.childNodes.length == 0)
1210 sf_popup.appendChild(createLabel( { value : "No matching authority records found" } ) );
1212 target.setAttribute('context', menu_id);
1216 function applyAuthority ( target, ui_sf, e4x_sf ) {
1218 var new_vals = target.getElementsByAttribute('checked','true');
1219 var field = e4x_sf.parent();
1221 for (var i = 0; i < new_vals.length; i++) {
1223 var sf_list = field.subfield;
1224 for (var j in sf_list) {
1226 if (sf_list[j].@code == new_vals[i].getAttribute('subfield')) {
1227 sf_list[j] = new_vals[i].getAttribute('value');
1228 new_vals[i].setAttribute('subfield','');
1234 for (var i = 0; i < new_vals.length; i++) {
1235 if (!new_vals[i].getAttribute('subfield')) continue;
1237 var val = new_vals[i].getAttribute('value');
1239 var sf = <subfield code="" xmlns="http://www.loc.gov/MARC21/slim">{val}</subfield>;
1240 sf.@code = new_vals[i].getAttribute('subfield');
1242 field.insertChildAfter(field.subfield[field.subfield.length() - 1], sf);
1245 var row = marcDatafield( field );
1248 while (node.nodeName != 'row') {
1249 node = node.parentNode;
1252 node.parentNode.replaceChild( row, node );
1258 'a' : { 100 : 'a' },
1259 'd' : { 100 : 'd' },
1262 'a' : { 110 : 'a' },
1263 'd' : { 110 : 'd' },
1266 'a' : { 111 : 'a' },
1267 'd' : { 111 : 'd' },
1270 'a' : { 130 : 'a' },
1271 'd' : { 130 : 'd' },
1274 'a' : { 130 : 'a' },
1275 'd' : { 130 : 'd' },
1278 'a' : { 100 : 'a' },
1279 'd' : { 100 : 'd' },
1282 'a' : { 110 : 'a' },
1283 'd' : { 110 : 'd' },
1286 'a' : { 111 : 'a' },
1287 'd' : { 111 : 'd' },
1290 'a' : { 130 : 'a' },
1291 'n' : { 130 : 'n' },
1292 'p' : { 130 : 'p' },
1295 'a' : { 100 : 'a' },
1296 'd' : { 100 : 'd' },
1299 'a' : { 110 : 'a' },
1300 'd' : { 110 : 'd' },
1303 'a' : { 111 : 'a' },
1304 'd' : { 111 : 'd' },
1307 'a' : { 130 : 'a' },
1308 'd' : { 130 : 'd' },
1311 'a' : { 100 : 'a' },
1312 'd' : { 100 : 'd' },
1315 'a' : { 110 : 'a' },
1316 'd' : { 110 : 'd' },
1319 'a' : { 111 : 'a' },
1320 'd' : { 111 : 'd' },
1323 'a' : { 130 : 'a' },
1324 'd' : { 130 : 'd' },
1327 'a' : { 100 : 'a' },
1328 'd' : { 100 : 'd' },
1329 't' : { 100 : 't' },
1356 'a' : { 150 : 'a' },
1357 'b' : { 150 : 'b' },
1384 'a' : { 151 : 'a' },
1411 'a' : { 155 : 'a' },
1439 function validateAuthority (button) {
1440 var grid = document.getElementById('recGrid');
1441 var label = button.getAttribute('label');
1444 var rows = grid.lastChild.childNodes;
1445 for (var i = 0; i < rows.length; i++) {
1447 var tag = row.firstChild;
1449 if (!control_map[tag.value]) continue
1451 var ind1 = tag.nextSibling;
1452 var ind2 = ind1.nextSibling;
1453 var subfields = ind2.nextSibling.childNodes;
1455 for (var j = 0; j < subfields.length; j++) {
1456 var sf = subfields[j];
1458 if (!control_map[tag.value][sf.childNodes[1].value]) continue;
1460 button.setAttribute('label', label + ' - ' + tag.value + sf.childNodes[1].value);
1463 for (var k in control_map[tag.value][sf.childNodes[1].value]) {
1464 var x = searchAuthority(sf.childNodes[2].value, k, control_map[tag.value][sf.childNodes[1].value][k], 1);
1465 var res = new XML( x.responseText );
1467 if (res.gw::payload.gw::array.gw::string.length()) {
1474 sf.childNodes[2].inputField.style.color = 'red';
1476 sf.childNodes[2].inputField.style.color = 'black';
1481 button.setAttribute('label', label);
1487 function searchAuthority (term, tag, sf, limit) {
1488 var url = "/gateway?format=xml&service=open-ils.search&method=open-ils.search.authority.fts";
1489 url += '¶m="term"¶m="' + term + '"';
1490 url += '¶m="limit"¶m=' + limit;
1491 url += '¶m="tag"¶m=' + tag;
1492 url += '¶m="subfield"¶m="' + sf + '"';
1495 var req = new XMLHttpRequest();
1496 req.open('GET',url,false);