correct error handling at session timeout: issue #3
[scpubgit/stemmaweb.git] / root / js / relationship.js
index 4cb62f1..873945b 100644 (file)
@@ -41,6 +41,14 @@ function node_dblclick_listener( evt ) {
        }
        $('#reading_normal_form').attr( 'size', nfboxsize )
        $('#reading_normal_form').val( normal_form );
+       if( editable ) {
+               // Fill in the witnesses for the de-collation box.
+               $('#reading_decollate_witnesses').empty();
+               $.each( reading_info['witnesses'], function( idx, wit ) {
+                       $('#reading_decollate_witnesses').append( $('<option/>').attr(
+                               'value', wit ).text( wit ) );
+               });
+       }
        // Now do the morphological properties.
        morphology_form( reading_info['lexemes'] );
        // and then open the dialog.
@@ -695,12 +703,22 @@ $(document).ready(function () {
                $("#dialog_overlay").hide();
        }
        }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
-         if( ajaxSettings.url == getTextURL('relationships') 
-               && 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");
+               if( ajaxSettings.url == getTextURL('relationships') 
+                       && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
+                       var error;
+                       if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
+                               error = 'You are not authorized to modify this tradition. (Try logging in again?)';
+                       } else {
+                               try {
+                                       var errobj = jQuery.parseJSON( jqXHR.responseText );
+                                       error = errobj.error + '</br>The relationship cannot be made.</p>';
+                               } catch(e) {
+                                       error = jqXHR.responseText;
+                               }
+                       }
+                       $('#status').append( '<p class="error">Error: ' + error );
+               }
+               $(event.target).parent().find('.ui-button').button("enable");
        } );
   }
 
@@ -752,6 +770,11 @@ $(document).ready(function () {
   // function for reading form dialog should go here; 
   // just hide the element for now if we don't have morphology
   if( can_morphologize ) {
+         if( editable ) {
+                 $('#reading_decollate_witnesses').multiselect();
+         } else {
+                 $('#decollation').hide();
+         }
          $('#reading-form').dialog({
                autoOpen: false,
                // height: 400,
@@ -807,6 +830,8 @@ $(document).ready(function () {
                },
                open: function() {
                        $(".ui-widget-overlay").css("background", "none");
+                       $('#reading_decollate_witnesses').multiselect("refresh");
+                       $('#reading_decollate_witnesses').multiselect("uncheckAll");
                        $("#dialog_overlay").show();
                        $('#reading_status').empty();
                        $("#dialog_overlay").height( $("#enlargement_container").height() );
@@ -818,12 +843,22 @@ $(document).ready(function () {
                        $("#dialog_overlay").hide();
                }
          }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
-                 if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1
+               if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1
                        && 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");
+                       var error;
+                       if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
+                               error = 'You are not authorized to modify this tradition. (Try logging in again?)';
+                       } else {
+                               try {
+                                       var errobj = jQuery.parseJSON( jqXHR.responseText );
+                                       error = errobj.error + '</br>The relationship cannot be made.</p>';
+                               } catch(e) {
+                                       error = jqXHR.responseText;
+                               }
+                       }
+                       $('#status').append( '<p class="error">Error: ' + error );
+               }
+               $(event.target).parent().find('.ui-button').button("enable");
          });
        } else {
                $('#reading-form').hide();