Skip to content

Commit

Permalink
refs matomo-org#4253 as suggested by dalidev I specified a timeout fo…
Browse files Browse the repository at this point in the history
…r the autocomplete request (20seconds). If it is not loaded after 20 seconds
  • Loading branch information
tsteur committed May 8, 2014
1 parent 33a4852 commit e81d7e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/SegmentEditor/javascripts/Segmentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,15 @@ Segmentation = (function($) {
segmentName: segmentName
}, 'GET');
ajaxHandler.useRegularCallbackInCaseOfError = true;
ajaxHandler.setTimeout(20000);
ajaxHandler.setErrorCallback(function(response) {
loadingElement.hide();
inputElement.autocomplete({
source: [],
minLength: 0
});
$(inputElement).autocomplete('search', $(inputElement).val());
});
ajaxHandler.setCallback(function(response) {
loadingElement.hide();

Expand Down
20 changes: 20 additions & 0 deletions plugins/Zeitgeist/javascripts/ajaxHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ function ajaxHelper() {
*/
this.async = true;

/**
* A timeout for the request which will override any global timeout
* @type {Boolean}
*/
this.timeout = null;

/**
* Callback function to be executed on success
*/
Expand Down Expand Up @@ -181,6 +187,16 @@ function ajaxHelper() {
}, 'post');
};

/**
* Set a timeout (in milliseconds) for the request. This will override any global timeout.
*
* @param {integer} timeout Timeout in milliseconds
* @return {void}
*/
this.setTimeout = function (timeout) {
this.timeout = timeout;
};

/**
* Sets the callback called after the request finishes
*
Expand Down Expand Up @@ -381,6 +397,10 @@ function ajaxHelper() {
data: this._mixinDefaultPostParams(this.postParams)
};

if (this.timeout !== null) {
ajaxCall.timeout = this.timeout;
}

return $.ajax(ajaxCall);
};

Expand Down

0 comments on commit e81d7e1

Please sign in to comment.