OpenLayers OpenLayers

Changeset 7256

Show
Ignore:
Timestamp:
05/22/08 13:57:58 (6 months ago)
Author:
sbenthall
Message:

Save no longer sends unnecessary read() request; instead pulls fids for features right from the response from protocol.commit(). protocol.commit() now passes along more normalized information back to the callback passed to it. (Later this can be augmented to include full features).

Also, the WFS protocol now has its read request name parameterized out (in anticipation of WFSV protocol)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/vector-behavior/lib/OpenLayers/Protocol/WFS/v1_0_0.js

    r7218 r7256  
    9696     
    9797    /** 
     98     * Property: readRequestName 
     99     * {String} The tag name for read requests. 
     100     */ 
     101    readRequestName: "wfs:GetFeature", 
     102     
     103    /** 
    98104     * Constructor: OpenLayers.Protocol.WFS 
    99105     * A class for giving layers WFS protocol. 
     
    153159        OpenLayers.Util.applyDefaults(params, this.params); 
    154160         
    155         var root = this.createEnvelope("wfs:GetFeature", params); 
     161        var root = this.createEnvelope(this.readRequestName, params); 
    156162         
    157163        var query = this.format.createElementNSPlus("wfs:Query", { 
     
    298304        var data = this.format.write(root); 
    299305         
    300         var callback; 
    301306        if(options){ 
    302307            callback = options.callback || function(){}; 
    303308        } 
     309         
     310        var wfstCallback = function(request){ 
     311            //Insert results 
     312            var inserts = [];          
     313            var insertResult = request.responseXML.getElementsByTagName("InsertResult")[0]; 
     314            var featureIdNodes = insertResult.getElementsByTagName("FeatureId");    
     315             
     316            for (var index = 0; index < featureIdNodes.length; index++) { 
     317                 
     318                featureId = featureIdNodes[index]; 
     319                  
     320                if (featureId) { 
     321                    var fid = this.format.getAttributeNS(featureId, "", "fid"); 
     322                    inserts.push(fid); 
     323                } 
     324            } 
     325             
     326            //Transaction result 
     327            var transactionResult = request.responseXML.getElementsByTagName("TransactionResult")[0]; 
     328            var status = transactionResult.getElementsByTagName("Status")[0]; 
     329             
     330            if(status.getElementsByTagName("SUCCESS").length > 0){ 
     331                callback({inserts : inserts, success : true});     
     332            } else { 
     333                callback({success : false, request : request}); 
     334            } 
     335            
     336        } 
     337         
    304338         
    305339        return OpenLayers.Request.POST({ 
    306340            url: this.url, 
    307341            data: data, 
    308             callback: callback 
     342            callback: wfstCallback, 
     343            scope : this 
    309344        });       
    310345    }, 
  • sandbox/vector-behavior/lib/OpenLayers/Strategy/Save.js

    r7245 r7256  
    8888        var strategy = this; 
    8989         
    90         var saveCallback = function(request){ 
     90        var saveCallback = function(object){ 
    9191            var state; 
    9292             
    93             //Updates and deletes Deletes 
    94             for(var i = 0; i < features.length; i++){ 
    95                 state = features[i].state; 
    96                  
    97                 if(state == OpenLayers.State.UPDATE){ 
    98                     features[i].state = null; 
     93            if (object.success) { 
     94                //Updates and deletes Deletes 
     95                for (var i = 0; i < features.length; i++) { 
     96                    state = features[i].state; 
     97                     
     98                    if (state == OpenLayers.State.UPDATE) { 
     99                        features[i].state = null; 
     100                    } 
     101                     
     102                    if (state == OpenLayers.State.DELETE) { 
     103                        strategy.layer.destroyFeatures([features[i]]); 
     104                    } 
    99105                } 
    100106                 
    101                 if(state == OpenLayers.State.DELETE){ 
    102                     strategy.layer.destroyFeatures([features[i]]); 
    103                 }          
    104             } 
    105              
    106             //Inserts          
    107             var xml = new OpenLayers.Format.XML(); 
    108               
    109             var inserts = [];          
    110             var insertResult = request.responseXML.getElementsByTagName("InsertResult")[0]; 
    111             var featureIdNodes = insertResult.getElementsByTagName("FeatureId");    
    112              
    113             for (var index = 0; index < featureIdNodes.length; index++) { 
     107                var inserts = object.inserts; 
    114108                 
    115                 featureId = featureIdNodes[index]; 
    116                   
    117                 if (featureId) { 
    118                     var fid = xml.getAttributeNS(featureId, "", "fid"); 
    119                     inserts.push(fid); 
     109                if (inserts[0] != "none") { 
     110                    var j = 0; 
     111                     
     112                    for (var i = 0; i < features.length; i++) { 
     113                        if (features[i].state == OpenLayers.State.INSERT) { 
     114                            features[i].state = null; 
     115                            features[i].fid = inserts[j]; 
     116                            j++; 
     117                        } 
     118                    } 
    120119                } 
    121             } 
    122              
    123             if(inserts[0] != "none"){ 
    124                 var fidFilter = new OpenLayers.Filter.FeatureId({fids: inserts}); 
    125  
    126                 params = { 
    127                     filter: fidFilter,        
    128                     srsName: strategy.layer.projection.getCode() 
    129                 }; 
    130              
    131                 strategy.layer.protocol.read({ 
    132                     params: params, 
    133                     callback: function(resp) { 
    134                         strategy.remove(); 
    135                         strategy.merge(resp.features); 
    136                     }, 
    137                     scope: this 
    138                 });     
    139120            } 
    140121        };