Changeset 1264

Show
Ignore:
Timestamp:
10/31/08 11:10:37 (2 months ago)
Author:
elemoine
Message:

bring improvements to widgets.data.Proxy, and add tests for it

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/tests/list-tests.html

    r1263 r1264  
    1616    <li>widgets/data/test_LayerStoreMediator.html</li> 
    1717    <li>widgets/data/test_GridRowFeatureMediator.html</li> 
     18    <li>widgets/data/Proxy.html</li> 
    1819    <li>widgets/toolbar/Toolbar.html</li> 
    1920</ul> 
  • sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/widgets/data/Proxy.js

    r1149 r1264  
    3636 
    3737Ext.extend(mapfish.widgets.data.Proxy, Ext.data.DataProxy, { 
     38    /** 
     39     * APIProperty: protocol 
     40     * {<OpenLayers.Protocol>} The protocol used to fetch features. 
     41     */ 
     42    protocol: null, 
    3843 
    3944    /** 
    40      * Property: loadArgs 
    41      * {Object} Arguments passed to the load method 
     45     * APIProperty: abortPrevious 
     46     * {Boolean} Whether to abort the previous request or not, defaults 
     47     * to true. 
    4248     */ 
    43     loadArgs: null
     49    abortPrevious: true
    4450 
    4551    /** 
    46      * APIMethod: load 
     52     * Property: response 
     53     * {<OpenLayers.Protocol.Response>} The response returned by 
     54     * the read call on the protocol. 
     55     */ 
     56    response: null, 
     57 
     58    /** 
     59     * Method: load 
    4760     * 
    4861     * Parameters: 
    49      * params - {Object} An object containing properties which are to be used as HTTP parameters 
    50      *     for the request to the remote server. 
     62     * params - {Object} An object containing properties which are to be used 
     63     *     as HTTP parameters for the request to the remote server. 
    5164     * reader - {Ext.data.DataReader} The Reader object which converts the data 
    5265     *     object into a block of Ext.data.Records. 
    53      * callback - {Function} The function into which to pass the block of Ext.data.Records. 
    54      *     The function must be passed: 
    55      *       - The Record block object 
    56      *       - The "arg" argument from the load function 
    57      *       - A boolean success indicator 
     66     * callback - {Function} The function into which to pass the block of 
     67     *     Ext.data.Records. The function is passed the Record block object, 
     68     *     the "args" argument passed to the load function, and a boolean 
     69     *     success indicator 
    5870     * scope - {Object} The scope in which to call the callback 
    59      * arg - {Object} An optional argument which is passed to the callback as its second parameter. 
     71     * arg - {Object} An optional argument which is passed to the callback 
     72     *     as its second parameter. 
    6073     */ 
    6174    load: function(params, reader, callback, scope, arg) { 
    6275        if (this.fireEvent("beforeload", this, params) !== false) { 
    63  
    64             this.loadArgs = { 
     76            var o = { 
    6577                params: params || {}, 
    6678                request: { 
     
    7183                reader: reader 
    7284            }; 
    73  
    74             this.protocol.read({ 
    75                 filter: params, 
    76                 callback: this.loadResponse, 
     85            var cb = OpenLayers.Function.bind(this.loadResponse, this, o); 
     86            if (this.abortPrevious) { 
     87                this.abortRequest(); 
     88            } 
     89            this.response = this.protocol.read({ 
     90                params: params, 
     91                filter: arg.filter, 
     92                callback: cb, 
    7793                scope: this 
    7894            }); 
     
    8399 
    84100    /** 
     101     * Method: abortRequest 
     102     * Called to abort any ongoing request. 
     103     */ 
     104    abortRequest: function() { 
     105        // FIXME really we should rely on the protocol itself to 
     106        // cancel the request, the Protocol class in OpenLayers 
     107        // 2.7 does not expose a cancel() method 
     108        if (this.response) { 
     109            var response = this.response; 
     110            if (response.priv && 
     111                typeof response.priv.abort == "function") { 
     112                response.priv.abort(); 
     113                this.response = null; 
     114            } 
     115        } 
     116    }, 
     117 
     118    /** 
    85119     * Method: loadResponse 
    86120     * Handle response from the protocol 
    87121     * 
    88122     * Parameters: 
     123     * o - {Object}  
    89124     * response - {<OpenLayers.Protocol.Response>}  
    90125     */ 
    91     loadResponse: function(response) { 
     126    loadResponse: function(o, response) { 
    92127        if (response.success()) { 
    93             var result = this.loadArgs.reader.read(response); 
    94             this.fireEvent("load", this, this.loadArgs, this.loadArgs.request.arg); 
    95  
    96             this.loadArgs.request.callback.call(this.loadArgs.request.scope, result, 
    97                                                this.loadArgs.request.arg, true); 
     128            var result = o.reader.read(response); 
     129            this.fireEvent("load", this, o, o.request.arg); 
     130            o.request.callback.call( 
     131               o.request.scope, result, o.request.arg, true); 
    98132        } else { 
    99             this.fireEvent("loadexception", this, this.loadArgs, response); 
    100             this.loadArgs.request.callback.call(this.loadArgs.request.scope, null,  
    101                                                 this.loadArgs.request.arg, false); 
     133            this.fireEvent("loadexception", this, o, response); 
     134            o.request.callback.call( 
     135                o.request.scope, null, o.request.arg, false); 
    102136        } 
    103137    }