Rationalize button disabling/enabling throughout UI
[scpubgit/stemmaweb.git] / root / js / relationship.js
index cf40f3e..8cb73d4 100644 (file)
@@ -600,6 +600,14 @@ function relation_factory() {
        $('#delete_relation_type').text( relation.data('type') );
        $('#delete_relation_scope').text( relation.data('scope') );
        $('#delete_relation_attributes').empty();
+       var significance = ' is not ';
+       if( relation.data( 'is_significant' ) === 'yes') {
+               significance = ' is ';
+       } else if ( relation.data( 'is_significant' ) === 'maybe' ) {
+               significance = ' might be ';
+       }
+               $('#delete_relation_attributes').append( 
+                       "This relationship" + significance + "stemmatically significant<br/>");
        if( relation.data( 'a_derivable_from_b' ) ) {
                $('#delete_relation_attributes').append( 
                        "'" + relation.data('source_text') + "' derivable from '" + relation.data('target_text') + "'<br/>");
@@ -1050,23 +1058,25 @@ $(document).ready(function () {
   if( editable ) {
        $( '#dialog-form' ).dialog( {
        autoOpen: false,
-       height: 270,
+       height: 350,
        width: 330,
        modal: true,
        buttons: {
          'Merge readings': function( evt ) {
-                 $( evt.target ).button( 'disable' );
+                 var mybuttons = $(evt.target).closest('button').parent().find('button');
+                 mybuttons.button( 'disable' );
                  $( '#status' ).empty();
                  form_values = $( '#collapse_node_form' ).serialize();
                  ncpath = getTextURL( 'merge' );
                  var jqjson = $.post( ncpath, form_values, function( data ) {
                          merge_nodes( $( '#source_node_id' ).val(), $( '#target_node_id' ).val(), data );
-                         $(evt.target).button( 'enable' );
+                         mybuttons.button( 'enable' );
               $( '#dialog-form' ).dialog( 'close' );
                  } );
          },
          OK: function( evt ) {
-               $( evt.target ).button( 'disable' );
+               var mybuttons = $(evt.target).closest('button').parent().find('button');
+               mybuttons.button( 'disable' );
                $( '#status' ).empty();
                form_values = $( '#collapse_node_form' ).serialize();
                ncpath = getTextURL( 'relationships' );
@@ -1082,7 +1092,7 @@ $(document).ready(function () {
                                                relation.data( k.name, k.value );
                                        });
                                }
-                               $(evt.target).button( 'enable' );
+                               mybuttons.button( 'enable' );
                   });
                        $( '#dialog-form' ).dialog( 'close' );
                }, 'json' );
@@ -1100,11 +1110,15 @@ $(document).ready(function () {
                $.each( relationship_scopes, function(index, value) {   
                         $('#scope').append( $('<option />').attr( "value", value ).text(value) ); 
                });
-               // Handler to clear the annotation field, the first time the relationship is
-               // changed after opening the form.
+               $.each( ternary_values, function( index, value ) {
+                       $('#is_significant').append( $('<option />').attr( "value", value ).text(value) );
+               });
+               // Handler to reset fields to default, the first time the relationship 
+               // is changed after opening the form.
                $('#rel_type').change( function () {
                        if( !$(this).data( 'changed_after_open' ) ) {
                                $('#note').val('');
+                               $(this).find(':checked').removeAttr('checked');
                        }
                        $(this).data( 'changed_after_open', true );
                });
@@ -1132,7 +1146,8 @@ $(document).ready(function () {
                $("#dialog_overlay").hide();
        }
        }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
-               if( ajaxSettings.url == getTextURL('relationships') 
+               if( ( ajaxSettings.url == getTextURL('relationships')
+                         || ajaxSettings.url == getTextURL('merge') )
                        && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
                        var error;
                        if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
@@ -1208,12 +1223,13 @@ $(document).ready(function () {
         Cancel: function() { $( this ).dialog( "close" ); },
         Detach: function ( evt ) { 
             var self = $(this);
-            $( evt.target ).button( "disable" );
+                       var mybuttons = $(evt.target).closest('button').parent().find('button');
+                       mybuttons.button( 'disable' );
             var form_values = $('#detach_collated_form').serialize();
             ncpath = getTextURL( 'duplicate' );
             var jqjson = $.post( ncpath, form_values, function(data) {
                 detach_node( data );
-                $(evt.target).button("enable");
+                mybuttons.button("enable");
                 self.dialog( "close" );
             } );
         }
@@ -1295,7 +1311,8 @@ $(document).ready(function () {
                        },
                        Update: function( evt ) {
                                // Disable the button
-                               $(evt.target).button("disable");
+                               var mybuttons = $(evt.target).closest('button').parent().find('button');
+                               mybuttons.button( 'disable' );
                                $('#reading_status').empty();
                                var reading_id = $('#reading_id').val()
                                form_values = {
@@ -1322,7 +1339,7 @@ $(document).ready(function () {
                                        if( $('#update_workspace_button').data('locked') == false ) {
                                                color_inactive( get_ellipse( reading_id ) );
                                        }
-                                       $(evt.target).button("enable");
+                                       mybuttons.button("enable");
                                        $( "#reading-form" ).dialog( "close" );
                                });
                                // Re-color the node if necessary