Skip to content

Commit

Permalink
refs #3332 fixing regression related to using ajaxHelper in transitio…
Browse files Browse the repository at this point in the history
…ns: use regular transitions callback when PHP throws an exception (e.g. NoDataForAction) to let transitions handle the error and show a message in the popover.
  • Loading branch information
timo-bes committed Mar 21, 2013
1 parent 485f537 commit 725ef87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/Transitions/templates/transitions.js
Expand Up @@ -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') {
Expand Down
18 changes: 17 additions & 1 deletion themes/default/ajaxHelper.js
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 725ef87

Please sign in to comment.