fix logic bug for admin textinfo edit
[scpubgit/stemmaweb.git] / root / js / stexaminer.js
CommitLineData
b8a92065 1var colors = ['#ffeeaa','#afc6e9','#d5fff6','#ffccaa','#ffaaaa','#e5ff80','#e5d5ff','#ffd5e5'];
2var row_triggered = false;
be8bf746 3var original_svg;
4
5function handle_row_click( row ) {
6 var ridx = row.parent().parent().index()
7 var rs = readingstats[ridx];
847e1ac6 8 var imghtml = '<img src="../../images/ajax-loader.gif" alt="Loading SVG..."/>'
be8bf746 9 $('#stemma_graph').empty();
10 $('#stemma_graph').append( imghtml );
11 if( rs.layerwits ) {
12 var stemma_form = { 'dot': graphdot, 'layerwits': rs.layerwits };
847e1ac6 13 $('#stemma_graph').load( '../graphsvg', stemma_form, function() {
be8bf746 14 color_row( row );
15 show_stats( rs );
16 });
17 } else {
18 $('#stemma_graph').empty();
19 $('#stemma_graph').append( original_svg );
20 color_row( row );
21 show_stats( rs );
22 }
23}
d5514865 24
25function color_row( row ) {
b8a92065 26 row_triggered = true;
f007ac1e 27 $('ellipse').attr( {stroke:'white', fill:'#fff'} );
b8a92065 28 $('.node').children('polygon').attr( {stroke:'#fff', fill:'#fff'} );
29 $('.node').children('text').attr( {stroke:'none', fill:'#000'} );
30 $('tr.active_variant_row').children('td').removeClass('cellb0 cellb1 cellb2 cellb3 cellb4 cellb5 cellb6 cellb7');
d5514865 31 row.parent().nextAll('.clickable').children('span').click();
b8a92065 32 $('td.active_variant_cell').removeClass('active_variant_cell');
33 row_triggered = false;
d5514865 34}
35
b8a92065 36function color_nodes( column_index, arr_node_ids, arr_greynode_ids ) {
37 if( !row_triggered ) {
38 $('tr.active_variant_row').children('td').removeClass('cellb0 cellb1 cellb2 cellb3 cellb4 cellb5 cellb6 cellb7');
39 $('td.active_variant_cell').removeClass('active_variant_cell');
f007ac1e 40 $('ellipse').attr( {stroke:'white', fill:'#fff'} );
b8a92065 41 $('.node').children('polygon').attr( {stroke:'#fff', fill:'#fff'} );
42 $('.node').children('text').attr( {stroke:'none', fill:'#000'} );
43 };
44 $('tr.active_variant_row').removeClass('active_variant_row')
45 jQuery.each( arr_greynode_ids, function(index,value) {
46 nodes = $('.node').children('title').filter( function(index) {
47 return $(this).text() == value;
48 })
49 nodes.siblings('ellipse, polygon, text').each( function( index ) {
50 $(this).attr( {stroke:'#ddd', fill:'#f8f8f8'} );
51 });
52 });
53 jQuery.each( arr_node_ids, function(index,value) {
54 $('.node').children('title').filter( function(index) {
55 return $(this).text() == value;
56 }).siblings('ellipse').each( function( index ) {
57 $(this).attr( {stroke:'black', fill:colors[column_index-1]} );
58 });
59 });
60}
ef3db56f 61
be8bf746 62function show_stats( rs ) {
ef3db56f 63 var rshtml = $('#stats_template').clone();
64 rshtml.find('#statrank').append( rs.id );
d35db27a 65 if( "unsolved" in rs ) {
ec0d9b5b 66 var nocalcmsg;
67 if( rs.unsolved == 'IDP error' ) {
68 nocalcmsg = $('<span>').attr('class', 'error').append(
69 "(Could not reach calculation server - are you offline?)" );
70 } else {
71 nocalcmsg = "(Not yet calculated for this location - please try later)";
72 }
73 rshtml.find('.solutionstatus').append( nocalcmsg );
d35db27a 74 } else {
75 $.each( rs.readings, function( idx, rdghash ) {
76 var rdgstats = $('#reading_template').clone();
77 rdgstats.find('.readinglabel').append( rdghash.text );
78 rdgstats.find('.reading_copied').append( rdghash.followed );
79 rdgstats.find('.reading_changed').append( rdghash.not_followed );
80 rdgstats.find('.reading_unclear').append( rdghash.follow_unknown );
81 rdgstats.find('.readingroots').append( rdghash.independent_occurrence );
82 if( rdghash.is_reverted ) {
83 rdgstats.find('.reversionroots').append( rdghash.reversions );
84 } else {
85 rdgstats.find('.readingreversions').empty();
86 }
87 var rdgsourcehtml = fill_parent_template( rdghash, 'source' );
88 var rdgreverthtml = fill_parent_template( rdghash, 'reversion' );
89 rdgstats.find('.reading_statistics').append( rdgsourcehtml );
90 rdgstats.find('.reading_statistics').append( rdgreverthtml );
91 // If neither, append a small spacer
92 if( !rdgsourcehtml && !rdgreverthtml ) {
93 rdgstats.find('.reading_statistics').append( '<br/>' );
94 }
95 rshtml.append( rdgstats.contents() );
96 });
97 }
ef3db56f 98 $('#row_statistics').empty();
99 $('#row_statistics').append( rshtml.contents() );
f7371955 100
ef3db56f 101};
be8bf746 102
f7371955 103function fill_parent_template( rdghash, type ) {
104 var objname = type + '_parents';
105 var template_id = '#reading_' + type + '_template';
106 var list_class = '.reading_' + type + '_list';
107 if( ! $.isEmptyObject( rdghash[objname] ) ) {
108 var parentstats = $( template_id ).clone();
109 $.each( rdghash[objname], function( parentid, pdata ) {
110 var parentdesc = pdata.label;
111 if( pdata.relation ) {
112 parentdesc += ' - variant type ' + pdata.relation.type;
113 if( pdata.relation.annotation ) {
114 parentdesc += ' [ ' + pdata.relation.annotation + ' ]';
115 }
116 } else {
117 parentdesc += ' - no syntactic relation';
118 }
119 var parentitem = $('<li>').append( parentdesc );
120 parentstats.find( list_class ).append( parentitem );
121 });
122 return( parentstats.contents() );
123 }
124}
125
be8bf746 126// Save the original unextended SVG for when we need it.
127$(document).ready(function () {
128 original_svg = $('#stemma_graph > svg').clone();
2fd8f80c 129
130 $('#aboutlink').popupWindow({
131 height:500,
132 width:800,
133 top:50,
134 left:50,
135 scrollbars:1
136 });
137 $('#options').dialog({
138 autoOpen: false,
139 height: 200,
140 width: 300,
141 modal: true,
142 buttons: {
143 Cancel: function() {
144 $(this).dialog( "close" );
145 },
146 Reanalyze: function() {
147 $('#use_variants_form').submit();
148 },
149 }
150 });
151
be8bf746 152});