better handling for errors, don't send filler text to server
[scpubgit/stemmatology.git] / stemmaweb / root / js / relationship.js
index 807b5d4..cd3d867 100644 (file)
@@ -136,11 +136,13 @@ function color_inactive ( el ) {
        // If the reading info has any non-disambiguated lexemes, color it yellow;
        // otherwise color it green.
        $(el).attr( {stroke:'green', fill:'#b3f36d'} );
-       $.each( reading_info['lexemes'], function ( idx, lex ) {
-               if( !lex['is_disambiguated'] || lex['is_disambiguated'] == 0 ) {
-                       $(el).attr( {stroke:'orange', fill:'#fee233'} );
-               }
-       });
+       if( reading_info ) {
+               $.each( reading_info['lexemes'], function ( idx, lex ) {
+                       if( !lex['is_disambiguated'] || lex['is_disambiguated'] == 0 ) {
+                               $(el).attr( {stroke:'orange', fill:'#fee233'} );
+                       }
+               });
+       }
 }
 
 function relemmatize () {
@@ -706,8 +708,8 @@ $(document).ready(function () {
        && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
          var errobj = jQuery.parseJSON( jqXHR.responseText );
           $('#status').append( '<p class="error">Error: ' + errobj.error + '</br>The relationship cannot be made.</p>' );
-                 $(event.target).parent().find('.ui-button').button("enable");
       }
+         $(event.target).parent().find('.ui-button').button("enable");
   } );
 
   $( "#delete-form" ).dialog({
@@ -770,9 +772,11 @@ $(document).ready(function () {
                                'normal_form': $('#reading_normal_form').val() };
                        // Add the morphology values
                        $('.reading_morphology').each( function() {
-                               var rmid = $(this).attr('id');
-                               rmid = rmid.substring(8);
-                               form_values[rmid] = $(this).val();
+                               if( $(this).val() != '(Click to select)' ) {
+                                       var rmid = $(this).attr('id');
+                                       rmid = rmid.substring(8);
+                                       form_values[rmid] = $(this).val();
+                               }
                        });
                        // Make the JSON call
                        ncpath = getReadingURL( reading_id );
@@ -801,6 +805,7 @@ $(document).ready(function () {
         $("#dialog_overlay").height( $("#enlargement_container").height() );
         $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
         $("#dialog_overlay").offset( $("#enlargement_container").offset() );
+        $("#reading-form").parent().find('.ui-button').button("enable");
        },
        close: function() {
                $("#dialog_overlay").hide();
@@ -810,8 +815,8 @@ $(document).ready(function () {
        && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
          var errobj = jQuery.parseJSON( jqXHR.responseText );
           $('#reading_status').append( '<p class="error">Error: ' + errobj.error + '</p>' );
-                 $(event.target).parent().find('.ui-button').button("enable");
       }
+         $(event.target).parent().find('.ui-button').button("enable");
   });