From: Tara L Andrews Date: Wed, 30 May 2012 02:00:47 +0000 (+0200) Subject: make relemmatize button work X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmatology.git;a=commitdiff_plain;h=4aed7cc51a1239fd06e7e85481f0545749dfe75b make relemmatize button work --- diff --git a/stemmaweb/lib/stemmaweb/Controller/Relation.pm b/stemmaweb/lib/stemmaweb/Controller/Relation.pm index c980f80..38cae7e 100644 --- a/stemmaweb/lib/stemmaweb/Controller/Relation.pm +++ b/stemmaweb/lib/stemmaweb/Controller/Relation.pm @@ -287,6 +287,7 @@ sub reading :Chained('text') :PathPart :Args(1) { my $nf = $c->request->param('normal_form'); # TODO throw error unless $nf $rdg->normal_form( $nf ); + # TODO throw error if lemmatization fails $rdg->lemmatize(); } else { # Set all the values that we have for the reading. @@ -307,7 +308,8 @@ sub reading :Chained('text') :PathPart :Args(1) { } $lx->disambiguate( $idx ); } elsif( $read_write_keys{$p} ) { - $rdg->$p( $c->request->param( $p ) ); + my $val = _clean_booleans( $rdg, $p, $c->request->param( $p ) ); + $rdg->$p( $val ); } } } @@ -319,6 +321,15 @@ sub reading :Chained('text') :PathPart :Args(1) { } +sub _clean_booleans { + my( $rdg, $param, $val ) = @_; + if( $rdg->meta->get_attribute( $param )->type_constraint->name eq 'Bool' ) { + $val = 1 if $val eq 'true'; + $val = undef if $val eq 'false'; + } + return $val; +} + =head2 end Attempt to render a view, if needed. diff --git a/stemmaweb/root/js/relationship.js b/stemmaweb/root/js/relationship.js index 8f308db..a731474 100644 --- a/stemmaweb/root/js/relationship.js +++ b/stemmaweb/root/js/relationship.js @@ -52,8 +52,8 @@ function node_dblclick_listener( evt ) { // 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'] ); + $('#reading_is_nonsense').attr( 'checked', reading_info['is_nonsense'] ); + $('#reading_grammar_invalid').attr( 'checked', reading_info['grammar_invalid'] ); // Use .text as a backup for .normal_form var normal_form = reading_info['normal_form']; if( !normal_form ) { @@ -80,7 +80,6 @@ function morphology_form ( lexlist ) { morphoptions.push( tagstr ); }); var formtag = 'morphology_' + idx; - //forminput.autocomplete('search', ''); var formstr = ''; if( lex['form'] ) { formstr = stringify_wordform( lex['form'] ); @@ -132,6 +131,26 @@ function color_inactive ( el ) { }); } +function relemmatize () { + // Send the reading for a new lemmatization and reopen the form. + var reading_id = $('#reading_id').val() + ncpath = getReadingURL( reading_id ); + form_values = { + 'normal_form': $('#reading_normal_form').val(), + 'relemmatize': 1 }; + var jqjson = $.post( ncpath, form_values, function( data ) { + // Update the form with the return + if( 'id' in data ) { + // We got back a good answer. Stash it + readingdata[reading_id] = data; + // and regenerate the morphology form. + morphology_form( data['lexemes'] ); + } else { + alert("Could not relemmatize as requested: " + data['error']); + } + }); +} + // Initialize the SVG once it exists function svgEnlargementLoaded() { //Give some visual evidence that we are working @@ -726,8 +745,8 @@ $(document).ready(function () { var reading_id = $('#reading_id').val() form_values = { 'id' : reading_id, - 'is_nonsense': $('#reading_is_nonsense').val(), - 'grammar_invalid': $('#reading_grammar_invalid').val(), + 'is_nonsense': $('#reading_is_nonsense').is(':checked'), + 'grammar_invalid': $('#reading_grammar_invalid').is(':checked'), 'normal_form': $('#reading_normal_form').val() }; // Add the morphology values $('.reading_morphology').each( function() { @@ -753,27 +772,6 @@ $(document).ready(function () { } }, create: function() { - // $('#reading_relemmatize').button(); - $('#reading_relemmatize').click( function () { - // Send the reading for a new lemmatization and reopen the form. - alert( "Got a click function for relemmatize button" ); - var reading_id = $('#reading_id').val() - ncpath = getReadingURL( reading_id ); - form_values = { - 'normal_form': $('#reading_normal_form').val(), - 'relemmatize': 1 }; - var jqjson = $.post( ncpath, form_values, function( data ) { - // Update the form with the return - if( 'reading_id' in data ) { - // We got back a good answer. Stash it - readingdata[reading_id] = data; - // and regenerate the morphology form. - morphology_form( data['lexemes'] ); - } // else throw an error with what is in ['error'] - }); - // Prevent submit - return false; - }); }, open: function() { $(".ui-widget-overlay").css("background", "none"); diff --git a/stemmaweb/root/src/relate.tt b/stemmaweb/root/src/relate.tt index 8c9e9a8..2aa7d3a 100644 --- a/stemmaweb/root/src/relate.tt +++ b/stemmaweb/root/src/relate.tt @@ -87,7 +87,7 @@ $(document).ready(function () { - +