diff --git a/plugins/Transitions/templates/transitions.js b/plugins/Transitions/templates/transitions.js index 72d96e795d3..3f2d63db99b 100644 --- a/plugins/Transitions/templates/transitions.js +++ b/plugins/Transitions/templates/transitions.js @@ -1408,6 +1408,7 @@ Piwik_Transitions_Ajax.prototype.callApi = function(method, params, callback) { var ajaxRequest = new ajaxHelper(); ajaxRequest.addParams(params, 'get'); + ajaxRequest.useCallbackInCaseOfError(); ajaxRequest.setCallback( function (result) { if (typeof result.result != 'undefined' && result.result == 'error') { diff --git a/themes/default/ajaxHelper.js b/themes/default/ajaxHelper.js index d33f7bd8416..accc3501c06 100644 --- a/themes/default/ajaxHelper.js +++ b/themes/default/ajaxHelper.js @@ -66,6 +66,12 @@ function ajaxHelper() { */ this.callback = function () {}; + /** + * Use this.callback if an error is returned + * @type {Boolean} + */ + this.useRegularCallbackInCaseOfError = false; + /** * Callback function to be executed on error */ @@ -156,6 +162,16 @@ function ajaxHelper() { this.callback = callback; }; + /** + * Set that the callback passed to setCallback() should be used if an application error (i.e. an + * Exception in PHP) is returned. + * + * @param {void} + */ + this.useCallbackInCaseOfError = function () { + this.useRegularCallbackInCaseOfError = true; + }; + /** * Set callback to redirect on success handler * &update=1(+x) will be appended to the current url @@ -301,7 +317,7 @@ function ajaxHelper() { $(that.loadingElement).hide(); } - if (response && response.result == 'error') { + if (response && response.result == 'error' && !that.useRegularCallbackInCaseOfError) { if ($(that.errorElement).length && response.message) { $(that.errorElement).html(response.message).fadeIn(); piwikHelper.lazyScrollTo(that.errorElement, 250);