[OpenLayers-Commits] r7078 - in sandbox/vector-behavior/lib/OpenLayers: . Protocol Protocol/WFS Strategy
commits at openlayers.org
commits at openlayers.org
Wed May 7 04:46:48 EDT 2008
Author: elemoine
Date: 2008-05-07 04:46:48 -0400 (Wed, 07 May 2008)
New Revision: 7078
Modified:
sandbox/vector-behavior/lib/OpenLayers/Protocol.js
sandbox/vector-behavior/lib/OpenLayers/Protocol/HTTP.js
sandbox/vector-behavior/lib/OpenLayers/Protocol/WFS/v1_0_0.js
sandbox/vector-behavior/lib/OpenLayers/Strategy/BBOX.js
sandbox/vector-behavior/lib/OpenLayers/Strategy/Fixed.js
Log:
create a Protocol.Response class hierarchy. Protocol.Response objects are passed to protocol users.
Modified: sandbox/vector-behavior/lib/OpenLayers/Protocol/HTTP.js
===================================================================
--- sandbox/vector-behavior/lib/OpenLayers/Protocol/HTTP.js 2008-05-07 07:08:01 UTC (rev 7077)
+++ sandbox/vector-behavior/lib/OpenLayers/Protocol/HTTP.js 2008-05-07 08:46:48 UTC (rev 7078)
@@ -109,13 +109,21 @@
var callback = function(request) {
if(mergedOptions.callback) {
- var features = null;
+ var resp = new OpenLayers.Protocol.HTTP.Response({
+ 'priv': request,
+ 'features': null
+ });
if(request.status >= 200 && request.status < 300) {
- features = this.readResponse(request);
+ // success
+ resp.features = this.readResponse(request);
+ resp.code = OpenLayers.Protocol.Response.SUCCESS;
+ } else {
+ // failure
+ resp.code = OpenLayers.Protocol.Response.FAILURE;
}
- var context = {'request': request};
- mergedOptions.callback.apply(
- mergedOptions.scope, [features, context]
+
+ mergedOptions.callback.call(
+ mergedOptions.scope, resp
);
}
};
@@ -144,14 +152,22 @@
var callback = function(request) {
if(mergedOptions.callback) {
- var createdFeatures = null;
- // really '201 CREATED' is expected
+ var resp = new OpenLayers.Protocol.HTTP.Response({
+ 'priv': request,
+ 'features': null,
+ 'reqFeatures': features
+ });
if(request.status >= 200 && request.status < 300) {
- createdFeatures = this.readResponse(request);
+ // success
+ resp.features = this.readResponse(request);
+ resp.code = OpenLayers.Protocol.Response.SUCCESS;
+ } else {
+ // failure
+ resp.code = OpenLayers.Protocol.Response.FAILURE;
}
- var context = {'features': features, 'request': request};
- mergedOptions.callback.apply(
- mergedOptions.scope, [createdFeatures, context]
+
+ mergedOptions.callback.call(
+ mergedOptions.scope, resp
);
}
};
@@ -181,14 +197,21 @@
var callback = function(request) {
if(mergedOptions.callback) {
- var updatedFeatures = null;
- // really '201 CREATED' is expected
+ var resp = new OpenLayers.Protocol.HTTP.Response({
+ 'priv': request,
+ 'features': null,
+ 'reqFeatures': features
+ });
if(request.status >= 200 && request.status < 300) {
- updatedFeatures = this.readResponse(request);
+ // success
+ resp.features = this.readResponse(request);
+ resp.code = OpenLayers.Protocol.Response.SUCCESS;
+ } else {
+ // failure
+ resp.code = OpenLayers.Protocol.Response.FAILURE;
}
- var context = {'features': features, 'request': request};
- mergedOptions.callback.apply(
- mergedOptions.scope, [updatedFeatures, context]
+ mergedOptions.callback.call(
+ mergedOptions.scope, resp
);
}
};
@@ -217,10 +240,20 @@
var callback = function(request) {
if(mergedOptions.callback) {
- // really '204 No Content' expected
- var context = {'features': feature, 'request': request};
- mergedOptions.callback.apply(
- mergedOptions.scope, [context]
+ var resp = new OpenLayers.Protocol.HTTP.Response({
+ 'priv': request,
+ 'features': null,
+ 'reqFeatures': feature
+ });
+ if(request.status >= 200 && request.status < 300) {
+ // success
+ resp.code = OpenLayers.Protocol.Response.SUCCESS;
+ } else {
+ // failure
+ resp.code = OpenLayers.Protocol.Response.FAILURE;
+ }
+ mergedOptions.callback.call(
+ mergedOptions.scope, resp
);
}
};
@@ -267,3 +300,30 @@
CLASS_NAME: "OpenLayers.Protocol.HTTP"
});
+
+/**
+ * Class: OpenLayers.Protocol.Response
+ * Protocols return Response objects to their users.
+ */
+OpenLayers.Protocol.HTTP.Response = new OpenLayers.Class(
+ OpenLayers.Protocol.Response, {
+ /**
+ * Property: priv
+ * {Object} the XHR request object
+ */
+ priv: null,
+
+ /**
+ * Constructor: OpenLayers.Protocol.Response
+ *
+ * Parameters:
+ * options - {Object} Optional object whose properties will be set on the
+ * instance.
+ */
+ initialize: function(options) {
+ OpenLayers.Protocol.Response.prototype.initialize.apply(this, arguments);
+ },
+
+ CLASS_NAME: "OpenLayers.Protocol.HTTP.Response"
+});
+
Modified: sandbox/vector-behavior/lib/OpenLayers/Protocol/WFS/v1_0_0.js
===================================================================
--- sandbox/vector-behavior/lib/OpenLayers/Protocol/WFS/v1_0_0.js 2008-05-07 07:08:01 UTC (rev 7077)
+++ sandbox/vector-behavior/lib/OpenLayers/Protocol/WFS/v1_0_0.js 2008-05-07 08:46:48 UTC (rev 7078)
@@ -128,12 +128,19 @@
OpenLayers.Util.applyDefaults(params, this.params);
var callback = function(request) {
- var features = null;
+ var resp = new OpenLayers.Protocol.Response({
+ 'features': null
+ });
if(request.status >= 200 && request.status < 300) {
- features = this.readResponse(request);
+ // success
+ resp.features = this.readResponse(request);
+ resp.code = OpenLayers.Protocol.Response.SUCCESS;
+ } else {
+ // failure
+ resp.code = OpenLayers.Protocol.Response.FAILURE;
}
- mergedOptions.callback.apply(
- mergedOptions.scope, [features, request]
+ mergedOptions.callback.call(
+ mergedOptions.scope, resp
);
};
Modified: sandbox/vector-behavior/lib/OpenLayers/Protocol.js
===================================================================
--- sandbox/vector-behavior/lib/OpenLayers/Protocol.js 2008-05-07 07:08:01 UTC (rev 7077)
+++ sandbox/vector-behavior/lib/OpenLayers/Protocol.js 2008-05-07 08:46:48 UTC (rev 7078)
@@ -107,3 +107,65 @@
CLASS_NAME: "OpenLayers.Protocol"
});
+
+/**
+ * Class: OpenLayers.Protocol.Response
+ * Protocols return Response objects to their users.
+ */
+OpenLayers.Protocol.Response = new OpenLayers.Class({
+ /**
+ * Property: code
+ * {Integer} - OpenLayers.Protocol.Response.SUCCESS or
+ * OpenLayers.Protocol.Response.FAILURE
+ */
+ code: null,
+
+ /**
+ * Property: features
+ * {Array({<OpenLayers.Feature.Vector>})} or {<OpenLayers.Feature.Vector>}
+ * The features returned in the response by the server.
+ */
+ features: null,
+
+ /**
+ * Property: reqFeatures
+ * {Array({<OpenLayers.Feature.Vector>})} or {<OpenLayers.Feature.Vector>}
+ * The features provided by the user and placed in the request by the
+ * protocol.
+ */
+ reqFeatures: null,
+
+ /**
+ * Property: priv
+ */
+ priv: null,
+
+ /**
+ * Constructor: OpenLayers.Protocol.Response
+ *
+ * Parameters:
+ * options - {Object} Optional object whose properties will be set on the
+ * instance.
+ */
+ initialize: function(options) {
+ OpenLayers.Util.extend(this, options);
+ },
+
+ /**
+ * Method: success
+ *
+ * Returns:
+ * {Boolean} - true on success, false otherwise
+ */
+ success: function() {
+ return !!(this.code & OpenLayers.Protocol.Response.SUCCESS_MASK);
+ },
+
+ CLASS_NAME: "OpenLayers.Protocol.Response"
+});
+
+OpenLayers.Protocol.Response.SUCCESS_MASK = 0x000000ff;
+OpenLayers.Protocol.Response.SUCCESS = 0x00000001;
+
+OpenLayers.Protocol.Response.FAILURE_MASK = 0x0000ff00;
+OpenLayers.Protocol.Response.FAILURE = 0x00000100;
Modified: sandbox/vector-behavior/lib/OpenLayers/Strategy/BBOX.js
===================================================================
--- sandbox/vector-behavior/lib/OpenLayers/Strategy/BBOX.js 2008-05-07 07:08:01 UTC (rev 7077)
+++ sandbox/vector-behavior/lib/OpenLayers/Strategy/BBOX.js 2008-05-07 08:46:48 UTC (rev 7078)
@@ -90,9 +90,9 @@
});
return this.layer.protocol.read({
params: params,
- callback: function(features) {
+ callback: function(resp) {
this.remove();
- this.merge(features);
+ this.merge(resp.features);
},
scope: this
});
Modified: sandbox/vector-behavior/lib/OpenLayers/Strategy/Fixed.js
===================================================================
--- sandbox/vector-behavior/lib/OpenLayers/Strategy/Fixed.js 2008-05-07 07:08:01 UTC (rev 7077)
+++ sandbox/vector-behavior/lib/OpenLayers/Strategy/Fixed.js 2008-05-07 08:46:48 UTC (rev 7078)
@@ -46,11 +46,12 @@
* Method: merge
* Given a list of features, determine which ones to add to the layer.
*/
- merge: function(features) {
+ merge: function(resp) {
+ var features = resp.features;
if(features && features.length > 0) {
this.layer.addFeatures(features);
}
},
CLASS_NAME: "OpenLayers.Strategy.Fixed"
-});
\ No newline at end of file
+});
More information about the Commits
mailing list