lib/ymdp/javascripts/ajax.js in ymdp-0.5.1 vs lib/ymdp/javascripts/ajax.js in ymdp-0.6.0
- old
+ new
@@ -31,11 +31,10 @@
response = YAHOO.lang.JSON.parse(response.data);
if (response.error) {
if (error_function) {
error_function(response);
} else {
- Debug.error("No error_function", response);
YAHOO.oib.showError(
{
"method": "OIB.call",
"description": "error callback"
}
@@ -43,11 +42,10 @@
}
} else {
if (success_function) {
success_function(response);
} else {
- Debug.error("no success function", response);
YAHOO.oib.showError(
{
"method": "OIB.call",
"description": "success callback error"
}
@@ -59,46 +57,57 @@
},
ajax_response: false,
ajax: function(url, method, params, success_function, error_function) {
+ var debug;
+
params = params || {};
params["application"] = View.application;
- Debug.log("OIB.ajax: About to call openmail.Application.callWebService: ", {
- "method": method,
- "url": url + "?" + Object.toQueryString(params)
- });
+ debug = !params["_hide_debug"];
+
+ if (debug) {
+ Debug.log("OIB.ajax: About to call openmail.Application.callWebService: ", {
+ "method": method,
+ "url": url + "?" + Object.toQueryString(params)
+ });
+ }
openmail.Application.callWebService(
{
url: url,
method: method,
parameters: params
},
function(response) {
// response from Ajax call was a 200 response
//
- Debug.log("inside response from openMail.Application.callWebService", response);
+ if (debug) {
+ Debug.log("inside response from openMail.Application.callWebService", response);
+ }
if (response.error) {
// response has a parameter called "error"
//
if (error_function) {
error_function(response);
} else {
- OIB.error(url, params, response);
+ if (debug) {
+ OIB.error(url, params, response);
+ }
}
} else {
// SUCCESSFUL RESPONSE
//
// response doesn't have a parameter called "error"
//
- Debug.log("success response inside openMail.Application.callWebService", response);
try {
success_function(response);
} catch(e) {
- Debug.log("Error in OIB.request success function", e);
+ if (debug) {
+ Debug.log("Error in OIB.request success function", e);
+ }
YAHOO.oib.showError({
"method": "OIB.request",
"description": "exception caught in OIB.request success callback",
"error": e
});
@@ -106,15 +115,20 @@
}
});
},
request: function(oib_path, params, success_function, error_function, base_url) {
- Debug.log("inside OIB.request: ", {
- "oib_path": oib_path,
- "params": Object.toJSON(params)
- });
- var oib_url, method;
+ var oib_url, method, debug;
+
+ debug = !params["_hide_debug"];
+
+ if (debug) {
+ Debug.log("inside OIB.request: ", {
+ "oib_path": oib_path,
+ "params": Object.toJSON(params)
+ });
+ }
oib_url = base_url ? base_url : YAHOO.constants.base_url;
if (!(oib_path && typeof(oib_path) === "string")) {
throw("OIB.request must define oib_path");
@@ -132,20 +146,26 @@
method = params.method;
delete params.method;
}
params.version = params.version || <%= @version %>;
- Debug.log("about to call OIB.ajax");
+ if (debug) {
+ Debug.log("about to call OIB.ajax");
+ }
OIB.ajax(oib_url, method, params, success_function, error_function);
},
// overwrite this function locally if you need to
error: function(url, params, response) {
- var message;
+ var message, debug;
- message = "OIB.error: " + Object.toJSON(response) + " calling url: " + url + "?" + Object.toQueryString(params);
- Debug.error(message);
+ debug = !params["_hide_debug"];
+
+ if (debug) {
+ message = "OIB.error: " + Object.toJSON(response) + " calling url: " + url + "?" + Object.toQueryString(params);
+ Debug.error(message);
+ }
},
// advance the user to the next state in the signup process
//
advance: function(success_function, error_function) {