Patch from funky_c to move all alert()s in the library to a single

OpenLayers.Console.userError function. This allows for easy overriding of this
function for people who need to report errors at an application level (or
hiding these errors entirely), with the same default behavior as previous
releases. Patch from funky_c, r=me, (Closes #1651)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@7675 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2008-08-01 22:21:50 +00:00
parent ba561a9fb5
commit 64fc4fcb1b
10 changed files with 30 additions and 15 deletions

View File

@@ -38,7 +38,7 @@ OpenLayers.ProxyHost = "";
* @param {} request
*/
OpenLayers.nullHandler = function(request) {
alert(OpenLayers.i18n("unhandledRequest", {'statusText':request.statusText}));
OpenLayers.Console.userError(OpenLayers.i18n("unhandledRequest", {'statusText':request.statusText}));
};
/**
@@ -55,13 +55,13 @@ OpenLayers.nullHandler = function(request) {
* onComplete - {Function} Optional callback for success. The callback
* will be called with this set to caller and will receive the request
* object as an argument. Note that if you do not specify an onComplete
* function, <OpenLayers.nullHandler> will be called (which pops up an
* alert dialog).
* function, <OpenLayers.nullHandler> will be called (which pops up a
* user friendly error message dialog).
* onFailure - {Function} Optional callback for failure. In the event of
* a failure, the callback will be called with this set to caller and will
* receive the request object as an argument. Note that if you do not
* specify an onComplete function, <OpenLayers.nullHandler> will be called
* (which pops up an alert dialog).
* (which pops up a user friendly error message dialog).
*
* Returns:
* {<OpenLayers.Request.XMLHttpRequest>} The request object. To abort loading,

View File

@@ -86,6 +86,21 @@ OpenLayers.Console = {
* object - {Object}
*/
error: function() {},
/**
* APIFunction: userError
* A single interface for showing error messages to the user. The default
* behavior is a Javascript alert, though this can be overridden by
* reassigning OpenLayers.Console.userError to a different function.
*
* Expects a single error message
*
* Parameters:
* object - {Object}
*/
userError: function(error) {
alert(error);
},
/**
* APIFunction: assert

View File

@@ -43,7 +43,7 @@
* > },
* >
* > notice: function (bounds) {
* > alert(bounds);
* > OpenLayers.Console.userError(bounds);
* > }
* > });
* > map.addControl(control);

View File

@@ -497,7 +497,7 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
// as the base layer for the main map. This should be made more robust.
if(this.map.getUnits() != 'degrees') {
if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) {
alert(OpenLayers.i18n("sameProjection"));
OpenLayers.Console.userError(OpenLayers.i18n("sameProjection"));
}
}
var pxBounds = this.getRectBoundsFromMapBounds(this.map.getExtent());

View File

@@ -68,7 +68,7 @@ OpenLayers.Format = OpenLayers.Class({
* Depends on the subclass
*/
read: function(data) {
alert(OpenLayers.i18n("readNotImplemented"));
OpenLayers.Console.userError(OpenLayers.i18n("readNotImplemented"));
},
/**
@@ -82,7 +82,7 @@ OpenLayers.Format = OpenLayers.Class({
* {String} A string representation of the object.
*/
write: function(object) {
alert(OpenLayers.i18n("writeNotImplemented"));
OpenLayers.Console.userError(OpenLayers.i18n("writeNotImplemented"));
},
CLASS_NAME: "OpenLayers.Format"

View File

@@ -129,7 +129,7 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
* feature - {<OpenLayers.Feature.Vector>}
*/
update: function(feature) {
if (!feature.fid) { alert(OpenLayers.i18n("noFID")); }
if (!feature.fid) { OpenLayers.Console.userError(OpenLayers.i18n("noFID")); }
var updateNode = this.createElementNS(this.wfsns, 'wfs:Update');
updateNode.setAttribute("typeName", this.layerName);
@@ -186,7 +186,7 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
*/
remove: function(feature) {
if (!feature.fid) {
alert(OpenLayers.i18n("noFID"));
OpenLayers.Console.userError(OpenLayers.i18n("noFID"));
return false;
}
var deleteNode = this.createElementNS(this.wfsns, 'wfs:Delete');

View File

@@ -162,7 +162,7 @@ OpenLayers.Layer.GML = OpenLayers.Class(OpenLayers.Layer.Vector, {
* request - {String}
*/
requestFailure: function(request) {
alert(OpenLayers.i18n("errorLoadingGML", {'url':this.url}));
OpenLayers.Console.userError(OpenLayers.i18n("errorLoadingGML", {'url':this.url}));
this.events.triggerEvent("loadend");
},

View File

@@ -109,7 +109,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
/**
* APIProperty: reportError
* {Boolean} report error message via alert() when loading of renderers
* {Boolean} report friendly error message when loading of renderer
* fails.
*/
reportError: true,
@@ -271,7 +271,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
*/
displayError: function() {
if (this.reportError) {
alert(OpenLayers.i18n("browserNotSupported",
OpenLayers.Console.userError(OpenLayers.i18n("browserNotSupported",
{'renderers':this.renderers.join("\n")}));
}
},

View File

@@ -511,7 +511,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class(
* response - {String} full XML response
*/
commitReport: function(string, response) {
alert(string);
OpenLayers.Console.userError(string);
},

View File

@@ -1141,7 +1141,7 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) {
//compare all keys (host, port, etc)
for(var key in urlObj1) {
if (options.test) {
alert(key + "\n1:" + urlObj1[key] + "\n2:" + urlObj2[key]);
OpenLayers.Console.userError(key + "\n1:" + urlObj1[key] + "\n2:" + urlObj2[key]);
}
var val1 = urlObj1[key];
var val2 = urlObj2[key];