3 var svg_root_element = null;
4 var start_element_height = 0;
8 function getTextURL( which ) {
9 return basepath + textid + '/' + which;
12 function getReadingURL( reading_id ) {
13 return basepath + textid + '/reading/' + reading_id;
16 // Make an XML ID into a valid selector
18 return '#' + myid.replace(/(:|\.)/g,'\\$1');
21 // Actions for opening the reading panel
22 function node_dblclick_listener( evt ) {
23 // Open the reading dialogue for the given node.
24 // First get the reading info
25 var reading_id = $(this).attr('id');
26 var reading_info = readingdata[reading_id];
27 // and then populate the dialog box with it.
28 // Set the easy properties first
29 $('#reading-form').dialog( 'option', 'title', 'Reading information for "' + reading_info['text'] + '"' );
30 $('#reading_id').val( reading_id );
31 toggle_checkbox( $('#reading_is_nonsense'), reading_info['is_nonsense'] );
32 toggle_checkbox( $('#reading_grammar_invalid'), reading_info['grammar_invalid'] );
33 // Use .text as a backup for .normal_form
34 var normal_form = reading_info['normal_form'];
36 normal_form = reading_info['text'];
39 if( normal_form.length > 9 ) {
40 nfboxsize = normal_form.length + 1;
42 $('#reading_normal_form').attr( 'size', nfboxsize )
43 $('#reading_normal_form').val( normal_form );
45 // Fill in the witnesses for the de-collation box.
46 $('#reading_decollate_witnesses').empty();
47 $.each( reading_info['witnesses'], function( idx, wit ) {
48 $('#reading_decollate_witnesses').append( $('<option/>').attr(
49 'value', wit ).text( wit ) );
52 // Now do the morphological properties.
53 morphology_form( reading_info['lexemes'] );
54 // and then open the dialog.
55 $('#reading-form').dialog("open");
58 function toggle_checkbox( box, value ) {
62 box.attr('checked', value );
65 function morphology_form ( lexlist ) {
66 if( lexlist.length ) {
67 $('#morph_outer').show();
68 $('#morphology').empty();
69 $.each( lexlist, function( idx, lex ) {
70 var morphoptions = [];
71 if( 'wordform_matchlist' in lex ) {
72 $.each( lex['wordform_matchlist'], function( tdx, tag ) {
73 var tagstr = stringify_wordform( tag );
74 morphoptions.push( tagstr );
77 var formtag = 'morphology_' + idx;
80 formstr = stringify_wordform( lex['form'] );
82 var form_morph_elements = morph_elements(
83 formtag, lex['string'], formstr, morphoptions );
84 $.each( form_morph_elements, function( idx, el ) {
85 $('#morphology').append( el );
89 $('#morph_outer').hide();
93 function stringify_wordform ( tag ) {
95 var elements = tag.split(' // ');
96 return elements[1] + ' // ' + elements[2];
101 function morph_elements ( formtag, formtxt, currform, morphoptions ) {
102 var clicktag = '(Click to select)';
106 var formlabel = $('<label/>').attr( 'id', 'label_' + formtag ).attr(
107 'for', 'reading_' + formtag ).text( formtxt + ': ' );
108 var forminput = $('<input/>').attr( 'id', 'reading_' + formtag ).attr(
109 'name', 'reading_' + formtag ).attr( 'size', '50' ).attr(
110 'class', 'reading_morphology' ).val( currform );
111 forminput.autocomplete({ source: morphoptions, minLength: 0 });
112 forminput.focus( function() {
113 if( $(this).val() == clicktag ) {
116 $(this).autocomplete('search', '')
118 var morphel = [ formlabel, forminput, $('<br/>') ];
122 function color_inactive ( el ) {
123 var reading_id = $(el).parent().attr('id');
124 var reading_info = readingdata[reading_id];
125 // If the reading info has any non-disambiguated lexemes, color it yellow;
126 // otherwise color it green.
127 $(el).attr( {stroke:'green', fill:'#b3f36d'} );
129 $.each( reading_info['lexemes'], function ( idx, lex ) {
130 if( !lex['is_disambiguated'] || lex['is_disambiguated'] == 0 ) {
131 $(el).attr( {stroke:'orange', fill:'#fee233'} );
137 function relemmatize () {
138 // Send the reading for a new lemmatization and reopen the form.
139 $('#relemmatize_pending').show();
140 var reading_id = $('#reading_id').val()
141 ncpath = getReadingURL( reading_id );
143 'normal_form': $('#reading_normal_form').val(),
145 var jqjson = $.post( ncpath, form_values, function( data ) {
146 // Update the form with the return
148 // We got back a good answer. Stash it
149 readingdata[reading_id] = data;
150 // and regenerate the morphology form.
151 morphology_form( data['lexemes'] );
153 alert("Could not relemmatize as requested: " + data['error']);
155 $('#relemmatize_pending').hide();
159 // Initialize the SVG once it exists
160 function svgEnlargementLoaded() {
161 //Give some visual evidence that we are working
162 $('#loading_overlay').show();
163 lo_height = $("#enlargement_container").outerHeight();
164 lo_width = $("#enlargement_container").outerWidth();
165 $("#loading_overlay").height( lo_height );
166 $("#loading_overlay").width( lo_width );
167 $("#loading_overlay").offset( $("#enlargement_container").offset() );
168 $("#loading_message").offset(
169 { 'top': lo_height / 2 - $("#loading_message").height() / 2,
170 'left': lo_width / 2 - $("#loading_message").width() / 2 });
172 // Show the update toggle button.
173 $('#update_workspace_button').data('locked', false);
174 $('#update_workspace_button').css('background-position', '0px 44px');
176 var rdgpath = getTextURL( 'readings' );
177 $.getJSON( rdgpath, function( data ) {
179 $('#svgenlargement ellipse').each( function( i, el ) { color_inactive( el ) });
181 $('#svgenlargement ellipse').parent().dblclick( node_dblclick_listener );
182 var graph_svg = $('#svgenlargement svg');
183 var svg_g = $('#svgenlargement svg g')[0];
185 svg_root = graph_svg.svg().svg('get').root();
187 // Find the real root and ignore any text nodes
188 for (i = 0; i < svg_root.childNodes.length; ++i) {
189 if (svg_root.childNodes[i].nodeName != '#text') {
190 svg_root_element = svg_root.childNodes[i];
195 //Set viewbox width and height to width and height of $('#svgenlargement svg').
196 //This is essential to make sure zooming and panning works properly.
197 svg_root.viewBox.baseVal.width = graph_svg.attr( 'width' );
198 svg_root.viewBox.baseVal.height = graph_svg.attr( 'height' );
199 //Now set scale and translate so svg height is about 150px and vertically centered in viewbox.
200 //This is just to create a nice starting enlargement.
201 var initial_svg_height = 250;
202 var scale = initial_svg_height/graph_svg.attr( 'height' );
203 var additional_translate = (graph_svg.attr( 'height' ) - initial_svg_height)/(2*scale);
204 var transform = svg_g.getAttribute('transform');
205 var translate = parseFloat( transform.match( /translate\([^\)]*\)/ )[0].split('(')[1].split(' ')[1].split(')')[0] );
206 translate += additional_translate;
207 var transform = 'rotate(0) scale(' + scale + ') translate(4 ' + translate + ')';
208 svg_g.setAttribute('transform', transform);
209 //used to calculate min and max zoom level:
210 start_element_height = $('#__START__').children('ellipse')[0].getBBox().height;
211 add_relations( function() { $('#loading_overlay').hide(); });
214 function add_relations( callback_fn ) {
215 // Add the relationship types to the keymap list
216 $.each( relationship_types, function(index, typedef) {
217 li_elm = $('<li class="key">').css( "border-color",
218 relation_manager.relation_colors[index] ).text(typedef.name);
219 li_elm.append( $('<div>').attr('class', 'key_tip_container').append(
220 $('<div>').attr('class', 'key_tip').text(typedef.description) ) );
221 $('#keymaplist').append( li_elm );
223 // Now fetch the relationships themselves and add them to the graph
224 var rel_types = $.map( relationship_types, function(t) { return t.name });
225 // Save this list of names to the outer element data so that the relationship
226 // factory can access it
227 $('#keymap').data('relations', rel_types);
228 var textrelpath = getTextURL( 'relationships' );
229 $.getJSON( textrelpath, function(data) {
230 $.each(data, function( index, rel_info ) {
231 var type_index = $.inArray(rel_info.type, rel_types);
232 var source_found = get_ellipse( rel_info.source );
233 var target_found = get_ellipse( rel_info.target );
234 if( type_index != -1 && source_found.size() && target_found.size() ) {
235 var relation = relation_manager.create( rel_info.source, rel_info.target, type_index );
236 relation.data( 'type', rel_info.type );
237 relation.data( 'scope', rel_info.scope );
238 relation.data( 'note', rel_info.note );
240 var node_obj = get_node_obj(rel_info.source);
241 node_obj.set_draggable( false );
242 node_obj.ellipse.data( 'node_obj', null );
243 node_obj = get_node_obj(rel_info.target);
244 node_obj.set_draggable( false );
245 node_obj.ellipse.data( 'node_obj', null );
253 function get_ellipse( node_id ) {
254 return $( jq( node_id ) + ' ellipse');
257 function get_node_obj( node_id ) {
258 var node_ellipse = get_ellipse( node_id );
259 if( node_ellipse.data( 'node_obj' ) == null ) {
260 node_ellipse.data( 'node_obj', new node_obj(node_ellipse) );
262 return node_ellipse.data( 'node_obj' );
265 function node_obj(ellipse) {
266 this.ellipse = ellipse;
273 this.node_elements = node_elements_for(self.ellipse);
275 this.get_id = function() {
276 return $(self.ellipse).parent().attr('id')
279 this.set_draggable = function( draggable ) {
280 if( draggable && editable ) {
281 $(self.ellipse).attr( {stroke:'black', fill:'#fff'} );
282 $(self.ellipse).parent().mousedown( this.mousedown_listener );
283 $(self.ellipse).parent().hover( this.enter_node, this.leave_node );
284 self.ellipse.siblings('text').attr('class', 'noselect draggable');
286 self.ellipse.siblings('text').attr('class', '');
287 $(self.ellipse).parent().unbind( 'mouseenter' ).unbind( 'mouseleave' ).unbind( 'mousedown' );
288 color_inactive( self.ellipse );
292 this.mousedown_listener = function(evt) {
293 evt.stopPropagation();
294 self.x = evt.clientX;
295 self.y = evt.clientY;
296 $('body').mousemove( self.mousemove_listener );
297 $('body').mouseup( self.mouseup_listener );
298 $(self.ellipse).parent().unbind('mouseenter').unbind('mouseleave')
299 self.ellipse.attr( 'fill', '#ff66ff' );
300 first_node_g_element = $("#svgenlargement g .node" ).filter( ":first" );
301 if( first_node_g_element.attr('id') !== self.get_g().attr('id') ) { self.get_g().insertBefore( first_node_g_element ) };
304 this.mousemove_listener = function(evt) {
305 self.dx = (evt.clientX - self.x) / mouse_scale;
306 self.dy = (evt.clientY - self.y) / mouse_scale;
307 self.move_elements();
308 evt.returnValue = false;
309 evt.preventDefault();
313 this.mouseup_listener = function(evt) {
314 if( $('ellipse[fill="#ffccff"]').size() > 0 ) {
315 var source_node_id = $(self.ellipse).parent().attr('id');
316 var source_node_text = self.ellipse.siblings('text').text();
317 var target_node_id = $('ellipse[fill="#ffccff"]').parent().attr('id');
318 var target_node_text = $('ellipse[fill="#ffccff"]').siblings("text").text();
319 $('#source_node_id').val( source_node_id );
320 $('#source_node_text').val( source_node_text );
321 $('#target_node_id').val( target_node_id );
322 $('#target_node_text').val( target_node_text );
323 $('#dialog-form').dialog( 'open' );
325 $('body').unbind('mousemove');
326 $('body').unbind('mouseup');
327 self.ellipse.attr( 'fill', '#fff' );
328 $(self.ellipse).parent().hover( self.enter_node, self.leave_node );
329 self.reset_elements();
332 this.cpos = function() {
333 return { x: self.ellipse.attr('cx'), y: self.ellipse.attr('cy') };
336 this.get_g = function() {
337 return self.ellipse.parent('g');
340 this.enter_node = function(evt) {
341 self.ellipse.attr( 'fill', '#ffccff' );
344 this.leave_node = function(evt) {
345 self.ellipse.attr( 'fill', '#fff' );
348 this.greyout_edges = function() {
349 $.each( self.node_elements, function(index, value) {
350 value.grey_out('.edge');
354 this.ungreyout_edges = function() {
355 $.each( self.node_elements, function(index, value) {
356 value.un_grey_out('.edge');
360 this.move_elements = function() {
361 $.each( self.node_elements, function(index, value) {
362 value.move(self.dx,self.dy);
366 this.reset_elements = function() {
367 $.each( self.node_elements, function(index, value) {
372 this.update_elements = function() {
373 self.node_elements = node_elements_for(self.ellipse);
376 self.set_draggable( true );
379 function svgshape( shape_element ) {
380 this.shape = shape_element;
381 this.move = function(dx,dy) {
382 this.shape.attr( "transform", "translate(" + dx + " " + dy + ")" );
384 this.reset = function() {
385 this.shape.attr( "transform", "translate( 0, 0 )" );
387 this.grey_out = function(filter) {
388 if( this.shape.parent(filter).size() != 0 ) {
389 this.shape.attr({'stroke':'#e5e5e5', 'fill':'#e5e5e5'});
392 this.un_grey_out = function(filter) {
393 if( this.shape.parent(filter).size() != 0 ) {
394 this.shape.attr({'stroke':'#000000', 'fill':'#000000'});
399 function svgpath( path_element, svg_element ) {
400 this.svg_element = svg_element;
401 this.path = path_element;
402 this.x = this.path.x;
403 this.y = this.path.y;
404 this.move = function(dx,dy) {
405 this.path.x = this.x + dx;
406 this.path.y = this.y + dy;
408 this.reset = function() {
409 this.path.x = this.x;
410 this.path.y = this.y;
412 this.grey_out = function(filter) {
413 if( this.svg_element.parent(filter).size() != 0 ) {
414 this.svg_element.attr('stroke', '#e5e5e5');
415 this.svg_element.siblings('text').attr('fill', '#e5e5e5');
416 this.svg_element.siblings('text').attr('class', 'noselect');
419 this.un_grey_out = function(filter) {
420 if( this.svg_element.parent(filter).size() != 0 ) {
421 this.svg_element.attr('stroke', '#000000');
422 this.svg_element.siblings('text').attr('fill', '#000000');
423 this.svg_element.siblings('text').attr('class', '');
428 function node_elements_for( ellipse ) {
429 node_elements = get_edge_elements_for( ellipse );
430 node_elements.push( new svgshape( ellipse.siblings('text') ) );
431 node_elements.push( new svgshape( ellipse ) );
432 return node_elements;
435 function get_edge_elements_for( ellipse ) {
436 edge_elements = new Array();
437 node_id = ellipse.parent().attr('id');
438 edge_in_pattern = new RegExp( node_id + '$' );
439 edge_out_pattern = new RegExp( '^' + node_id );
440 $.each( $('#svgenlargement .edge,#svgenlargement .relation').children('title'), function(index) {
441 title = $(this).text();
442 if( edge_in_pattern.test(title) ) {
443 polygon = $(this).siblings('polygon');
444 if( polygon.size() > 0 ) {
445 edge_elements.push( new svgshape( polygon ) );
447 path_segments = $(this).siblings('path')[0].pathSegList;
448 edge_elements.push( new svgpath( path_segments.getItem(path_segments.numberOfItems - 1), $(this).siblings('path') ) );
450 if( edge_out_pattern.test(title) ) {
451 path_segments = $(this).siblings('path')[0].pathSegList;
452 edge_elements.push( new svgpath( path_segments.getItem(0), $(this).siblings('path') ) );
455 return edge_elements;
458 function relation_factory() {
460 this.color_memo = null;
461 //TODO: colors hard coded for now
462 this.temp_color = '#FFA14F';
463 this.relation_colors = [ "#5CCCCC", "#67E667", "#F9FE72", "#6B90D4", "#FF7673", "#E467B3", "#AA67D5", "#8370D8", "#FFC173" ];
465 this.create_temporary = function( source_node_id, target_node_id ) {
466 var relation_id = get_relation_id( source_node_id, target_node_id );
467 var relation = $( jq( relation_id ) );
468 if( relation.size() == 0 ) {
469 draw_relation( source_node_id, target_node_id, self.temp_color );
471 self.color_memo = relation.children('path').attr( 'stroke' );
472 relation.children('path').attr( 'stroke', self.temp_color );
475 this.remove_temporary = function() {
476 var path_element = $('#svgenlargement .relation').children('path[stroke="' + self.temp_color + '"]');
477 if( self.color_memo != null ) {
478 path_element.attr( 'stroke', self.color_memo );
479 self.color_memo = null;
481 var temporary = path_element.parent('g').remove();
486 this.create = function( source_node_id, target_node_id, color_index ) {
487 //TODO: Protect from (color_)index out of bound..
488 var relation_color = self.relation_colors[ color_index ];
489 var relation = draw_relation( source_node_id, target_node_id, relation_color );
490 get_node_obj( source_node_id ).update_elements();
491 get_node_obj( target_node_id ).update_elements();
494 this.toggle_active = function( relation_id ) {
495 var relation = $( jq( relation_id ) );
496 var relation_path = relation.children('path');
497 if( !relation.data( 'active' ) ) {
498 relation_path.css( {'cursor':'pointer'} );
499 relation_path.mouseenter( function(event) {
500 outerTimer = setTimeout( function() {
501 timer = setTimeout( function() {
502 var related_nodes = get_related_nodes( relation_id );
503 var source_node_id = related_nodes[0];
504 var target_node_id = related_nodes[1];
505 $('#delete_source_node_id').val( source_node_id );
506 $('#delete_target_node_id').val( target_node_id );
507 self.showinfo(relation);
511 relation_path.mouseleave( function(event) {
512 clearTimeout(outerTimer);
513 if( timer != null ) { clearTimeout(timer); }
515 relation.data( 'active', true );
517 relation_path.unbind( 'mouseenter' );
518 relation_path.unbind( 'mouseleave' );
519 relation_path.css( {'cursor':'inherit'} );
520 relation.data( 'active', false );
523 this.showinfo = function(relation) {
524 var htmlstr = 'type: ' + relation.data( 'type' ) + '<br/>scope: ' + relation.data( 'scope' );
525 if( relation.data( 'note' ) ) {
526 htmlstr = htmlstr + '<br/>note: ' + relation.data( 'note' );
528 $('#delete-form-text').html( htmlstr );
529 var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' ');
530 var xs = parseFloat( points[0].split(',')[0] );
531 var xe = parseFloat( points[1].split(',')[0] );
532 var ys = parseFloat( points[0].split(',')[1] );
533 var ye = parseFloat( points[3].split(',')[1] );
534 var p = svg_root.createSVGPoint();
535 p.x = xs + ((xe-xs)*1.1);
536 p.y = ye - ((ye-ys)/2);
537 var ctm = svg_root_element.getScreenCTM();
538 var nx = p.matrixTransform(ctm).x;
539 var ny = p.matrixTransform(ctm).y;
540 var dialog_aria = $ ("div[aria-labelledby='ui-dialog-title-delete-form']");
541 $('#delete-form').dialog( 'open' );
542 dialog_aria.offset({ left: nx, top: ny });
544 this.remove = function( relation_id ) {
548 var relation = $( jq( relation_id ) );
553 // Utility function to create/return the ID of a relation link between
554 // a source and target.
555 function get_relation_id( source_id, target_id ) {
556 var idlist = [ source_id, target_id ];
558 return 'relation-' + idlist[0] + '-...-' + idlist[1];
561 function get_related_nodes( relation_id ) {
562 var srctotarg = relation_id.substr( 9 );
563 return srctotarg.split('-...-');
566 function draw_relation( source_id, target_id, relation_color ) {
567 var source_ellipse = get_ellipse( source_id );
568 var target_ellipse = get_ellipse( target_id );
569 var relation_id = get_relation_id( source_id, target_id );
570 var svg = $('#svgenlargement').children('svg').svg().svg('get');
571 var path = svg.createPath();
572 var sx = parseInt( source_ellipse.attr('cx') );
573 var rx = parseInt( source_ellipse.attr('rx') );
574 var sy = parseInt( source_ellipse.attr('cy') );
575 var ex = parseInt( target_ellipse.attr('cx') );
576 var ey = parseInt( target_ellipse.attr('cy') );
577 var relation = svg.group( $("#svgenlargement svg g"),
578 { 'class':'relation', 'id':relation_id } );
579 svg.title( relation, source_id + '->' + target_id );
580 svg.path( relation, path.move( sx, sy ).curveC( sx + (2*rx), sy, ex + (2*rx), ey, ex, ey ), {fill: 'none', stroke: relation_color, strokeWidth: 4});
581 var relation_element = $('#svgenlargement .relation').filter( ':last' );
582 relation_element.insertBefore( $('#svgenlargement g g').filter(':first') );
583 return relation_element;
587 $(document).ready(function () {
590 relation_manager = new relation_factory();
591 $('#update_workspace_button').data('locked', false);
593 $('#enlargement').mousedown(function (event) {
596 .data('x', event.clientX)
597 .data('y', event.clientY)
598 .data('scrollLeft', this.scrollLeft)
599 stateTf = svg_root_element.getCTM().inverse();
600 var p = svg_root.createSVGPoint();
603 stateOrigin = p.matrixTransform(stateTf);
604 event.returnValue = false;
605 event.preventDefault();
607 }).mouseup(function (event) {
608 $(this).data('down', false);
609 }).mousemove(function (event) {
610 if( timer != null ) { clearTimeout(timer); }
611 if ( ($(this).data('down') == true) && ($('#update_workspace_button').data('locked') == false) ) {
612 var p = svg_root.createSVGPoint();
615 p = p.matrixTransform(stateTf);
616 var matrix = stateTf.inverse().translate(p.x - stateOrigin.x, p.y - stateOrigin.y);
617 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
618 svg_root_element.setAttribute("transform", s);
620 event.returnValue = false;
621 event.preventDefault();
622 }).mousewheel(function (event, delta) {
623 event.returnValue = false;
624 event.preventDefault();
625 if ( $('#update_workspace_button').data('locked') == false ) {
626 if (!delta || delta == null || delta == 0) delta = event.originalEvent.wheelDelta;
627 if (!delta || delta == null || delta == 0) delta = -1 * event.originalEvent.detail;
628 if( delta < -9 ) { delta = -9 };
629 var z = 1 + delta/10;
630 z = delta > 0 ? 1 : -1;
631 var g = svg_root_element;
632 if (g && ((z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>=1 && (g.getScreenCTM().a * start_element_height) < 100))) {
634 var p = root.createSVGPoint();
635 p.x = event.originalEvent.clientX;
636 p.y = event.originalEvent.clientY;
637 p = p.matrixTransform(g.getCTM().inverse());
638 var scaleLevel = 1+(z/20);
639 var k = root.createSVGMatrix().translate(p.x, p.y).scale(scaleLevel).translate(-p.x, -p.y);
640 var matrix = g.getCTM().multiply(k);
641 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
642 g.setAttribute("transform", s);
646 'overflow' : 'hidden',
647 'cursor' : '-moz-grab'
651 $( "#dialog-form" ).dialog({
657 "Ok": function( evt ) {
658 $(evt.target).button("disable");
659 $('#status').empty();
660 form_values = $('#collapse_node_form').serialize();
661 ncpath = getTextURL( 'relationships' );
662 var jqjson = $.post( ncpath, form_values, function(data) {
663 $.each( data, function(item, source_target) {
664 var source_found = get_ellipse( source_target[0] );
665 var target_found = get_ellipse( source_target[1] );
666 var relation_found = $.inArray( source_target[2], $('#keymap').data('relations') );
667 if( source_found.size() && target_found.size() && relation_found > -1 ) {
668 var relation = relation_manager.create( source_target[0], source_target[1], relation_found );
669 relation.data( 'type', source_target[2] );
670 relation.data( 'scope', $('#scope :selected').text() );
671 relation.data( 'note', $('#note').val() );
672 relation_manager.toggle_active( relation.attr('id') );
674 $(evt.target).button("enable");
676 $( "#dialog-form" ).dialog( "close" );
680 $( this ).dialog( "close" );
683 create: function(event, ui) {
684 $(this).data( 'relation_drawn', false );
685 $.each( relationship_types, function(index, typedef) {
686 $('#rel_type').append( $('<option />').attr( "value", typedef.name ).text(typedef.name) );
688 $.each( relationship_scopes, function(index, value) {
689 $('#scope').append( $('<option />').attr( "value", value ).text(value) );
693 relation_manager.create_temporary( $('#source_node_id').val(), $('#target_node_id').val() );
694 $(".ui-widget-overlay").css("background", "none");
695 $("#dialog_overlay").show();
696 $("#dialog_overlay").height( $("#enlargement_container").height() );
697 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
698 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
701 relation_manager.remove_temporary();
702 $( '#status' ).empty();
703 $("#dialog_overlay").hide();
705 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
706 if( ajaxSettings.url == getTextURL('relationships')
707 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
708 var errobj = jQuery.parseJSON( jqXHR.responseText );
709 $('#status').append( '<p class="error">Error: ' + errobj.error + '</br>The relationship cannot be made.</p>' );
711 $(event.target).parent().find('.ui-button').button("enable");
715 $( "#delete-form" ).dialog({
722 $( this ).dialog( "close" );
725 form_values = $('#delete_relation_form').serialize();
726 ncpath = getTextURL( 'relationships' );
727 var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) {
728 $.each( data, function(item, source_target) {
729 relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) );
731 $( "#delete-form" ).dialog( "close" );
732 }, dataType: 'json', type: 'DELETE' });
735 create: function(event, ui) {
736 // Swap out the buttons if we are in readonly mode
738 $( this ).dialog( "option", "buttons",
739 [{ text: "OK", click: function() { $( this ).dialog( "close" ); }}] );
742 // TODO What is this logic doing?
743 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' );
744 buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' );
745 var dialog_aria = $("div[aria-labelledby='ui-dialog-title-delete-form']");
746 dialog_aria.mouseenter( function() {
747 if( mouseWait != null ) { clearTimeout(mouseWait) };
749 dialog_aria.mouseleave( function() {
750 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
754 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
760 // function for reading form dialog should go here;
761 // just hide the element for now if we don't have morphology
762 if( can_morphologize ) {
764 $('#reading_decollate_witnesses').multiselect();
766 $('#decollation').hide();
768 $('#reading-form').dialog({
775 $( this ).dialog( "close" );
777 Update: function( evt ) {
778 // Disable the button
779 $(evt.target).button("disable");
780 $('#reading_status').empty();
781 var reading_id = $('#reading_id').val()
784 'is_nonsense': $('#reading_is_nonsense').is(':checked'),
785 'grammar_invalid': $('#reading_grammar_invalid').is(':checked'),
786 'normal_form': $('#reading_normal_form').val() };
787 // Add the morphology values
788 $('.reading_morphology').each( function() {
789 if( $(this).val() != '(Click to select)' ) {
790 var rmid = $(this).attr('id');
791 rmid = rmid.substring(8);
792 form_values[rmid] = $(this).val();
795 // Make the JSON call
796 ncpath = getReadingURL( reading_id );
797 var reading_element = readingdata[reading_id];
798 // $(':button :contains("Update")').attr("disabled", true);
799 var jqjson = $.post( ncpath, form_values, function(data) {
800 $.each( data, function(key, value) {
801 reading_element[key] = value;
803 if( $('#update_workspace_button').data('locked') == false ) {
804 color_inactive( get_ellipse( reading_id ) );
806 $(evt.target).button("enable");
807 $( "#reading-form" ).dialog( "close" );
809 // Re-color the node if necessary
815 // Get rid of the disallowed editing UI bits
816 $( this ).dialog( "option", "buttons",
817 [{ text: "OK", click: function() { $( this ).dialog( "close" ); }}] );
818 $('#reading_relemmatize').hide();
822 $(".ui-widget-overlay").css("background", "none");
823 $('#reading_decollate_witnesses').multiselect("refresh");
824 $('#reading_decollate_witnesses').multiselect("uncheckAll");
825 $("#dialog_overlay").show();
826 $('#reading_status').empty();
827 $("#dialog_overlay").height( $("#enlargement_container").height() );
828 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
829 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
830 $("#reading-form").parent().find('.ui-button').button("enable");
833 $("#dialog_overlay").hide();
835 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
836 if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1
837 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
838 var errobj = jQuery.parseJSON( jqXHR.responseText );
839 $('#reading_status').append( '<p class="error">Error: ' + errobj.error + '</p>' );
841 $(event.target).parent().find('.ui-button').button("enable");
844 $('#reading-form').hide();
848 $('#update_workspace_button').click( function() {
852 var svg_enlargement = $('#svgenlargement').svg().svg('get').root();
853 mouse_scale = svg_root_element.getScreenCTM().a;
854 if( $(this).data('locked') == true ) {
855 $('#svgenlargement ellipse' ).each( function( index ) {
856 if( $(this).data( 'node_obj' ) != null ) {
857 $(this).data( 'node_obj' ).ungreyout_edges();
858 $(this).data( 'node_obj' ).set_draggable( false );
859 var node_id = $(this).data( 'node_obj' ).get_id();
860 toggle_relation_active( node_id );
861 $(this).data( 'node_obj', null );
864 $(this).data('locked', false);
865 $(this).css('background-position', '0px 44px');
867 var left = $('#enlargement').offset().left;
868 var right = left + $('#enlargement').width();
869 var tf = svg_root_element.getScreenCTM().inverse();
870 var p = svg_root.createSVGPoint();
873 var cx_min = p.matrixTransform(tf).x;
875 var cx_max = p.matrixTransform(tf).x;
876 $('#svgenlargement ellipse').each( function( index ) {
877 var cx = parseInt( $(this).attr('cx') );
878 if( cx > cx_min && cx < cx_max) {
879 if( $(this).data( 'node_obj' ) == null ) {
880 $(this).data( 'node_obj', new node_obj( $(this) ) );
882 $(this).data( 'node_obj' ).set_draggable( true );
884 $(this).data( 'node_obj' ).greyout_edges();
885 var node_id = $(this).data( 'node_obj' ).get_id();
886 toggle_relation_active( node_id );
889 $(this).css('background-position', '0px 0px');
890 $(this).data('locked', true );
895 // Hide the unused elements
896 $('#dialog-form').hide();
897 $('#update_workspace_button').hide();
901 $('.helptag').popupWindow({
910 function toggle_relation_active( node_id ) {
911 $('#svgenlargement .relation').find( "title:contains('" + node_id + "')" ).each( function(index) {
912 matchid = new RegExp( "^" + node_id );
913 if( $(this).text().match( matchid ) != null ) {
914 var relation_id = $(this).parent().attr('id');
915 relation_manager.toggle_active( relation_id );
920 expandFillPageClients();
921 $(window).resize(function() {
922 expandFillPageClients();
928 function expandFillPageClients() {
929 $('.fillPage').each(function () {
930 $(this).height($(window).height() - $(this).offset().top - MARGIN);
934 function loadSVG(svgData) {
935 var svgElement = $('#svgenlargement');
937 $(svgElement).svg('destroy');
941 onLoad : svgEnlargementLoaded
948 function svg_select_callback(topic, data, subscriberData) {
954 var prefs = new gadgets.Prefs();
955 var preferredHeight = parseInt(prefs.getString('height'));
956 if (gadgets.util.hasFeature('dynamic-height')) gadgets.window.adjustHeight(preferredHeight);
957 expandFillPageClients();
960 if (gadgets.util.hasFeature('pubsub-2')) {
961 gadgets.HubSettings.onConnect = function(hum, suc, err) {
962 subId = gadgets.Hub.subscribe("interedition.svg.selected", svg_select_callback);
966 else gadgets.util.registerOnLoadHandler(loaded);