You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ry...@apache.org on 2012/04/16 19:29:24 UTC

svn commit: r1326690 - /lucene/dev/trunk/solr/webapp/web/js/scripts/analysis.js

Author: ryan
Date: Mon Apr 16 17:29:23 2012
New Revision: 1326690

URL: http://svn.apache.org/viewvc?rev=1326690&view=rev
Log:
SOLR-3324: change URL when analysis form is submitted

Modified:
    lucene/dev/trunk/solr/webapp/web/js/scripts/analysis.js

Modified: lucene/dev/trunk/solr/webapp/web/js/scripts/analysis.js
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/webapp/web/js/scripts/analysis.js?rev=1326690&r1=1326689&r2=1326690&view=diff
==============================================================================
--- lucene/dev/trunk/solr/webapp/web/js/scripts/analysis.js (original)
+++ lucene/dev/trunk/solr/webapp/web/js/scripts/analysis.js Mon Apr 16 17:29:23 2012
@@ -86,11 +86,36 @@ sammy.get
               this
                 .html( content );
 
-              $( 'option[value="fieldname\=' + response.schema.defaultSearchField + '"]', this )
+              var defaultSearchField = 'fieldname\=' + ( context.params['analysis.fieldname'] || response.schema.defaultSearchField );
+
+              if( context.params['analysis.fieldtype'] )
+              {
+                defaultSearchField = 'fieldtype\=' + context.params['analysis.fieldtype'];
+              }
+
+              $( 'option[value="' + defaultSearchField + '"]', this )
                 .attr( 'selected', 'selected' );
 
               this
-                .chosen();
+                .chosen()
+                .trigger( 'change' );
+
+              var fields = 0;
+              for( var key in context.params )
+              {
+                if( 'string' === typeof context.params[key] )
+                {
+                  fields++;
+                  $( '[name="' + key + '"]', analysis_form )
+                    .val( context.params[key] );
+                }
+              }
+
+              if( 0 !== fields )
+              {
+                analysis_form
+                  .trigger( 'execute' );
+              }
             },
             error : function( xhr, text_status, error_thrown)
             {
@@ -164,79 +189,104 @@ sammy.get
         }
 
         var button = $( 'button', analysis_form )
+
+        var compute_analysis_params = function()
+        {
+          var params = analysis_form.formToArray();
+                          
+          var type_or_name = $( '#type_or_name', analysis_form ).val().split( '=' );
+          params.push( { name: 'analysis.' + type_or_name[0], value: type_or_name[1] } );
+
+          return params;
+        }
                 
         analysis_form
-          .ajaxForm
+          .die( 'submit' )
+          .live
           (
+            'submit',
+            function( event )
             {
-              url : core_basepath + '/analysis/field?wt=json',
-              dataType : 'json',
-              beforeSubmit : function( array, form, options )
-              {
-                loader.show( button );
-                button.attr( 'disabled', true );
-                                
-                array.push( { name: 'analysis.showmatch', value: 'true' } );
-                                
-                var type_or_name = $( '#type_or_name', form ).val().split( '=' );
-                array.push( { name: 'analysis.' + type_or_name[0], value: type_or_name[1] } );
-              },
-              success : function( response, status_text, xhr, form )
-              {
-                $( '.analysis-error', analysis_element )
-                  .hide();
-                                
-                analysis_result
-                  .empty()
-                  .show();
-                                
-                for( var name in response.analysis.field_names )
-                {
-                  build_analysis_table( 'name', name, response.analysis.field_names[name] );
-                }
-                                
-                for( var name in response.analysis.field_types )
-                {
-                  build_analysis_table( 'type', name, response.analysis.field_types[name] );
-                }
-
-                check_empty_spacer();
-              },
-              error : function( xhr, text_status, error_thrown )
-              {
-                analysis_result
-                  .empty()
-                  .hide();
+              var params = compute_analysis_params();
 
-                if( 404 === xhr.status )
-                {
-                  $( '#analysis-handler-missing', analysis_element )
-                    .show();
-                }
-                else
+              context.redirect( context.path.split( '?' ).shift() + '?' + $.param( params ) );
+              return false;
+            }
+          )
+          .die( 'execute' )
+          .live
+          (
+            'execute',
+            function( event )
+            {
+              $.ajax
+              (
                 {
-                  $( '#analysis-error', analysis_element )
-                    .show();
+                  url : core_basepath + '/analysis/field?wt=json&analysis.showmatch=true&' + context.path.split( '?' ).pop(),
+                  dataType : 'json',
+                  beforeSend : function( xhr, settings )
+                  {
+                    loader.show( button );
+                    button.attr( 'disabled', true );
+                  },
+                  success : function( response, status_text, xhr, form )
+                  {
+                    $( '.analysis-error', analysis_element )
+                      .hide();
+                                    
+                    analysis_result
+                      .empty()
+                      .show();
+                                    
+                    for( var name in response.analysis.field_names )
+                    {
+                      build_analysis_table( 'name', name, response.analysis.field_names[name] );
+                    }
+                                    
+                    for( var name in response.analysis.field_types )
+                    {
+                      build_analysis_table( 'type', name, response.analysis.field_types[name] );
+                    }
 
-                  var response = null;
-                  try
+                    check_empty_spacer();
+                  },
+                  error : function( xhr, text_status, error_thrown )
                   {
-                    eval( 'response = ' + xhr.responseText + ';' );
-                  }
-                  catch( e )
+                    analysis_result
+                      .empty()
+                      .hide();
+
+                    if( 404 === xhr.status )
+                    {
+                      $( '#analysis-handler-missing', analysis_element )
+                        .show();
+                    }
+                    else
+                    {
+                      $( '#analysis-error', analysis_element )
+                        .show();
+
+                      var response = null;
+                      try
+                      {
+                        eval( 'response = ' + xhr.responseText + ';' );
+                      }
+                      catch( e )
+                      {
+                        console.error( e );
+                      }
+
+                      $( '#analysis-error .body', analysis_element )
+                        .text( response ? response.error.msg : xhr.responseText );
+                    }
+                  },
+                  complete : function()
                   {
-                    console.error( e );
+                    loader.hide( $( 'button', analysis_form ) );
+                    button.removeAttr( 'disabled' );
                   }
-
-                  $( '#analysis-error .body', analysis_element )
-                    .text( response ? response.error.msg : xhr.responseText );
                 }
-              },
-              complete : function()
-              {
-                loader.hide( $( 'button', analysis_form ) );
-                button.removeAttr( 'disabled' );
-              }
+              );
             }
           );