http://www.mediawiki.org/wiki/Special:Code/MediaWiki/61743

Revision: 61743
Author:   shmichael
Date:     2010-01-31 13:43:26 +0000 (Sun, 31 Jan 2010)

Log Message:
-----------
* Addressed issues in r61513 and follow up to r61518 .
* Spinner appears when changing filters
* Performing multiple filter changes before results are returned will wait for 
the most recent results to return.

Modified Paths:
--------------
    
branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
    branches/js2-work/phase3/js/mwEmbed/skins/common/common.css

Modified: 
branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
===================================================================
--- 
branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js   
    2010-01-31 10:56:41 UTC (rev 61742)
+++ 
branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js   
    2010-01-31 13:43:26 UTC (rev 61743)
@@ -1230,16 +1230,48 @@
                }
        },
        
+       /**
+        * Callback for performing a search, given to providers for 
provider-activated
+        * searches e.g. filter state changes. This is probably also the future 
way to 
+        * implement "pushing" results.
+        * 
+        * The returned callback accepts two arguements. 
+        * 
+        * The first, mandatory, is the
+        * provider object. This should be curried with the current provider 
object 
+        * before handing over. (i.e. this.curry(this.getProviderCallback(), 
provider).
+        * 
+        * The second, optional, is the current results list to be replaced by 
a spinner.
+        */
        getProviderCallback: function() {
                
                var _this = this;
-               return function ( provider ) {
+
+               return function ( provider, $location ) {
                        
                        var d = new Date();
                        var searchTime = d.getMilliseconds();
        
+                       // If we are given a result location, we hide them.
+                       if ($location) {
+                               $location.html( mw.loading_spinner("float: 
left") );
+                       }
+                       
+                       var d = new Date();
+                       var context = _this.storeContext( d.getTime() );
+                       _this.currentRequest = context();
+                       mw.log( "ProviderCallBack Generated " + context() )
                        provider.sObj.getSearchResults( $j( '#rsd_q' ).val() , 
                                        function( resultStatus ) {
+                                               
+                                               mw.log( "ProviderCallBack 
Received  " + context() );
+                                               if( _this.currentRequest != 
context() ) {
+                                               // do not update the results 
this.currentRequest 
+                                                       // does not match the 
interface request state.
+                                               return false;
+                                           }
+                                           
+                                               //else update search results    
        
                                                _this.showResults();
                                        });
                        
@@ -1250,6 +1282,22 @@
        },
        
        /**
+        * Persists an object via closure to enable later context checking.
+        * This can be used e.g. when sending multiple getJSON requests and
+        * wanting to act only on the last request sent.
+        * 
+        * @param {Object} Object to store in context.
+        * 
+        * @return {function} A callback to retrieve the context.
+        */
+       storeContext: function( contextObject ) {
+               var context = contextObject;
+               return function() { 
+                       return context;
+               }
+       },
+       
+       /**
        * Loads a providers search library
        * 
        * @param {Object} provider content provider to be loaded
@@ -1327,8 +1375,22 @@
                var _this = this;
                var o = '';
                var provider = this.content_providers[ this.current_provider ];
-                       
                
+               // Result page structure:
+               //
+               // resultContainer
+               //   header
+               //   resultBody
+               //     filter form
+               //       filters...
+               //     resultList
+               //       results...
+               //   footer
+               
+               var $resultsContainer;
+               var $resultsBody = $j( '<div />' ).addClass( 'rsd_results_body' 
);
+               var $resultsList = $j( '<div />' ).addClass( 'rsd_results_list' 
);
+               
                // The "upload" tab has special results output target rather 
than top level
                // resutls container.
                if ( this.current_provider == 'upload' ) {
@@ -1344,16 +1406,13 @@
                        // Enable search filters, if the provider supports them.
                        if ( provider.sObj.filters && 
!(provider.disable_filters) ) {
                                provider.sObj.filters.filterChangeCallBack = 
-                                       this.curry( this.getProviderCallback(), 
provider );
-                               $resultsContainer.append( 
provider.sObj.filters.getHTML().attr ({
+                                       this.curry( this.getProviderCallback(), 
provider, $resultsList );
+                               $resultsBody.append( 
provider.sObj.filters.getHTML().attr ({
                                        id: 'rsd_filters_container'
                                }));
                        }
                }
                
-               // Empty the existing results:
-               // $j( tabSelector ).empty();
-               
                var numResults = 0;
 
                // Output all the results for the current current_provider
@@ -1363,8 +1422,12 @@
                                numResults++;
                        } );
                        // Put in the tab output (plus clear the output)
-                       $resultsContainer.append( o + '<div 
style="clear:both"/>' );
+                       $resultsList.append( o + '<div style="clear: both" />' 
);
                }
+               
+               $resultsBody.append( $resultsList );
+               $resultsContainer.append( $resultsBody );
+               
                // @@TODO should abstract footer and header ~outside~ of search 
results 
                // to have less leakgege with upload tab
                if ( this.current_provider != 'upload' ) {

Modified: branches/js2-work/phase3/js/mwEmbed/skins/common/common.css
===================================================================
--- branches/js2-work/phase3/js/mwEmbed/skins/common/common.css 2010-01-31 
10:56:41 UTC (rev 61742)
+++ branches/js2-work/phase3/js/mwEmbed/skins/common/common.css 2010-01-31 
13:43:26 UTC (rev 61743)
@@ -95,8 +95,9 @@
        z-index:3;
 }
 #rsd_filters_container {
-       float:left;
-       width:150px;
+       float: left;
+       width: 150px;
+       overflow: auto;
 }
 
 .ui-filter-title {
@@ -194,6 +195,10 @@
 .rsd_result_enumeration {
        margin: 0 1em;
 }
+.rsd_results_body {
+       height: 100%;
+       width: 100%;
+}
 #rsd_results_header {
        margin: 4px;
        background: #DEF;



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to