Changeset 7036


Ignore:
Timestamp:
Apr 30, 2008 2:14:08 AM (8 years ago)
Author:
elemoine
Message:
  • don't clobber user options
  • add commit method
Location:
sandbox/vector-behavior/lib/OpenLayers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sandbox/vector-behavior/lib/OpenLayers/Protocol.js

    r6954 r7036  
    6262    "delete": function() {
    6363    },
     64
     65    /**
     66     * Method: commit
     67     * Go over the features in the layer and for each take action
     68     * based on the feature state.
     69     */
     70    commit: function() {
     71    },
    6472   
    6573    CLASS_NAME: "OpenLayers.Protocol"
  • sandbox/vector-behavior/lib/OpenLayers/Protocol/HTTP.js

    r7028 r7036  
    105105     */
    106106    'read': function(options) {
    107         var mergedOptions = OpenLayers.Util.applyDefaults(
    108             options || {}, this.options
    109         );
     107        var mergedOptions = OpenLayers.Util.extend({}, options);
     108        OpenLayers.Util.applyDefaults(mergedOptions, this.options);
    110109
    111110        var callback = function(request) {
     
    140139     */
    141140    'create': function(features, options) {
    142         var mergedOptions = OpenLayers.Util.applyDefaults(
    143             options || {}, this.options
    144         );
     141        var mergedOptions = OpenLayers.Util.extend({}, options);
     142        OpenLayers.Util.applyDefaults(mergedOptions, this.options);
    145143
    146144        var callback = function(request) {
     
    177175    'update': function(features, options) {
    178176        var url = options.url || features.url || this.options.url;
    179         var mergedOptions = OpenLayers.Util.applyDefaults(
    180             options || {}, this.options
    181         );
     177        var mergedOptions = OpenLayers.Util.extend({}, options);
     178        OpenLayers.Util.applyDefaults(mergedOptions, this.options);
    182179
    183180        var callback = function(request) {
     
    213210    'delete': function(feature, options) {
    214211        var url = options.url || feature.url;
    215         var mergedOptions = OpenLayers.Util.applyDefaults(
    216             options || {}, this.options
    217         );
     212        var mergedOptions = OpenLayers.Util.extend({}, options);
     213        OpenLayers.Util.applyDefaults(mergedOptions, this.options);
    218214
    219215        var callback = function(request) {
     
    233229        });
    234230    },
     231
     232    /**
     233     * Method: commit
     234     * Go over the features in the layer and for each take action
     235     * based on the feature state. Possible actions are create,
     236     * update and delete.
     237     *
     238     * Parameters:
     239     * layer - {<OpenLayers.Layer.Vector>}
     240     * options - {Object} Map of options, the keys of the map are
     241     *           'create', 'update', and 'delete'
     242     */
     243    commit: function(layer, options) {
     244        var toCreate = [];
     245        for (var i = layer.features.length - 1; i >= 0; i--) {
     246            var feature = layer.features[i];
     247            switch (feature.state) {
     248                case OpenLayers.State.INSERT:
     249                    toCreate.push(feature);
     250                    break;
     251                case OpenLayers.State.UPDATE:
     252                    this.update(feature, options.update);
     253                    break;
     254                case OpenLayers.State.DELETE:
     255                    this.delete(feature, options.delete);
     256                    break;
     257            }
     258        }
     259        if (toCreate.length > 0) {
     260            this.create(toCreate, options.create);
     261        }
     262    },
    235263   
    236264    CLASS_NAME: "OpenLayers.Protocol.HTTP"
Note: See TracChangeset for help on using the changeset viewer.