var svg_root_element = null;
var start_element_height = 0;
var reltypes = {};
+var readingdata = {};
function getTextPath() {
var currpath = window.location.pathname;
return path_parts[0];
}
-function getRelationshipURL() {
+function getTextURL( which ) {
var path_parts = getTextPath();
- return path_parts[0] + '/' + path_parts[1] + '/relationships';
+ return path_parts[0] + '/' + path_parts[1] + '/' + which;
+}
+
+function getReadingURL( reading_id ) {
+ var path_parts = getTextPath();
+ return path_parts[0] + '/' + path_parts[1] + '/reading/' + reading_id;
}
// Make an XML ID into a valid selector
$('#update_workspace_button').css('background-position', '0px 44px');
//This is essential to make sure zooming and panning works properly.
$('#svgenlargement ellipse').attr( {stroke:'green', fill:'#b3f36d'} );
+ $('#svgenlargement ellipse').dblclick( node_dblclick_listener );
var graph_svg = $('#svgenlargement svg');
var svg_g = $('#svgenlargement svg g')[0];
if (!svg_g) return;
}
}
- // This might be a little application specific and should be pushed to the backend
- // but... This collapes corrector hands when they agree with the original
- // e.g., P46-*,P46-C becomes simply P46
- $(svg_root).find('text').each(function () {
- var t = $(this).text();
- var ws = t.split(',');
- for (i = 0; i < ws.length; ++i) {
- if (ws[i].indexOf('-*')> -1) {
- var collapse = false;
- var main = $.trim(ws[i].substring(0,ws[i].indexOf('-')));
- for (j = 0; j < ws.length; ++j) {
- if (i != j && ws[j].indexOf('-')> -1) {
- var pair = $.trim(ws[j].substring(0,ws[j].indexOf('-')));
- if (main == pair) {
- collapse = true;
- ws[j] = '';
- }
- }
- }
- if (collapse) ws[i] = main;
- }
- }
- t = '';
- for (i = 0; i < ws.length; ++i) {
- if (ws[i].length) {
- if (t.length>0) t+=', ';
- t+=ws[i];
- }
- }
- $(this).text(t);
- });
-
svg_root.viewBox.baseVal.width = graph_svg.attr( 'width' );
svg_root.viewBox.baseVal.height = graph_svg.attr( 'height' );
//Now set scale and translate so svg height is about 150px and vertically centered in viewbox.
function add_relations( callback_fn ) {
var basepath = getRelativePath();
- var textrelpath = getRelationshipURL();
+ var textrelpath = getTextURL( 'relationships' );
$.getJSON( basepath + '/definitions', function(data) {
var rel_types = data.types.sort();
$.getJSON( textrelpath,
$(self.ellipse).parent().hover( self.enter_node, self.leave_node );
self.reset_elements();
}
-
+
this.cpos = function() {
return { x: self.ellipse.attr('cx'), y: self.ellipse.attr('cy') };
}
return edge_elements;
}
+function node_dblclick_listener( evt ) {
+ // Open the reading dialogue for the given node.
+ // First get the reading info
+ var reading_id = $(this).attr('id');
+ var reading_info = readingdata[reading_id];
+ // and then populate the dialog box with it.
+ // Set the easy properties first
+ $('#reading-form').dialog( 'option', 'title', 'Reading information for "' + reading_info['text'] + '"' );
+ $('#reading_id').val( reading_id );
+ $('#reading_is_nonsense').val( reading_info['is_nonsense'] );
+ $('#reading_grammar_invalid').val( reading_info['grammar_invalid'] );
+ // Use .text as a backup for .normal_form
+ var normal_form = reading_info['normal_form'];
+ if( !normal_form ) {
+ normal_form = reading_info['text'];
+ }
+ $('#reading_normal_form').val( normal_form );
+ // Now do the morphological properties.
+ // and then open the dialog.
+ var form_morph_elements = [];
+ $.each( reading_info['lexemes'], function( idx, lex ) {
+ var morphoptions = [];
+ $.each( lex['wordform_matchlist'], function( tdx, tag ) {
+ var tagstr = stringify_wordform( tag );
+ morphoptions.push( tagstr );
+ });
+ var formtag = 'morphology_' + idx;
+ var formlabel = $('#label_morphology_0').clone();
+ formlabel.attr('id', 'label_' + formtag );
+ formlabel.text( lex['string'] + ': ' );
+ var forminput = $('#reading_morphology_0').clone();
+ forminput.attr('id', 'reading_' + formtag );
+ forminput.attr('name', 'reading_' + formtag );
+ forminput.autocomplete({ source: morphoptions, minLength: 0, disabled: false });
+ //forminput.autocomplete('search', '');
+ if( lex['form'] ) {
+ var formstr = stringify_wordform( lex['form'] );
+ forminput.val( formstr );
+ } else {
+ forminput.val( '' );
+ }
+ form_morph_elements.push( formlabel, forminput, $('<br/>') );
+ });
+ $('#morphology').empty();
+ $.each( form_morph_elements, function( idx, el ) {
+ $('#morphology').append( el );
+ });
+ $('#reading-form').dialog("open");
+}
+
+function stringify_wordform ( tag ) {
+ return tag['lemma'] + ' // ' + tag['morphology'];
+}
+
function relation_factory() {
var self = this;
this.color_memo = null;
'cursor' : '-moz-grab'
});
+ var rdgpath = getTextURL( 'readings' );
+ $.getJSON( rdgpath, function( data ) {
+ readingdata = data;
+ });
$( "#dialog-form" ).dialog({
autoOpen: false,
"Ok": function() {
$('#status').empty();
form_values = $('#collapse_node_form').serialize();
- ncpath = getRelationshipURL();
+ ncpath = getTextURL( 'relationships' );
$(':button :contains("Ok")').attr("disabled", true);
var jqjson = $.post( ncpath, form_values, function(data) {
$.each( data, function(item, source_target) {
$( this ).dialog( "close" );
},
Delete: function() {
- form_values = $('#delete_relation_form').serialize()
- ncpath = getRelationshipURL()
+ form_values = $('#delete_relation_form').serialize();
+ ncpath = getTextURL( 'relationships' );
var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) {
$.each( data, function(item, source_target) {
relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) );
$('#reading-form').dialog({
autoOpen: false,
height: 400,
- width: 200,
+ width: 600,
modal: true,
buttons: {
Cancel: function() {
}
},
create: function() {},
- open: function() {},
+ open: function() {
+ $(".ui-widget-overlay").css("background", "none");
+ $("#dialog_overlay").show();
+ $("#dialog_overlay").height( $("#enlargement_container").height() );
+ $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
+ $("#dialog_overlay").offset( $("#enlargement_container").offset() );
+ },
close: function() {
$("#dialog_overlay").hide();
}