Pārlūkot izejas kodu

HUE-229. Request instances are not reusable

Aaron Newton 15 gadi atpakaļ
vecāks
revīzija
3842070d58
1 mainītis faili ar 18 papildinājumiem un 1 dzēšanām
  1. 18 1
      desktop/core/static/js/Source/CCS/CCS.JFrame.js

+ 18 - 1
desktop/core/static/js/Source/CCS/CCS.JFrame.js

@@ -705,6 +705,15 @@ CCS.JFrame = new Class({
 			see renderContent
 	*/
 	_setRequestOptions: function(request, options) {
+		/*
+			By default, there's only ever one request running per-jframe.
+			The linkers involved all create a new instance of request every time
+			they are invoked. However, Form.Request re-uses its instance. To prevent
+			that request instance from being "set up" twice, exit if there's already
+			a request and it's already been set up.
+		*/
+		if (this._request && this._request._jframeConfigured) return;
+		request._jframeConfigured = true;
 		request.setOptions($merge({
 			useSpinner: this.options.spinnerCondition.apply(this, [options]),
 			spinnerTarget: this.options.spinnerTarget || this.element,
@@ -712,7 +721,15 @@ CCS.JFrame = new Class({
 			onFailure: this.error.bind(this),
 			evalScripts: false,
 			onRequest: function(){
-				if (this._request) this._request.cancel();
+				/*
+					Here we cancel any running request if we kick off a new one.
+					The exception here is when we are re-using the running request.
+					FormRequest, for instance, reuses a Request instance. So we check
+					that the current request is not the one we're sending; if it is
+					the one we're sending, don't cancel it; only cancel if it's a different
+					one.
+				*/
+				if (this._request && this._request != request) this._request.cancel();
 				this._request = request;
 			}.bind(this),
 			onSuccess: function(requestTxt){