Browse Source

HUE-323. Make it possible for forms to specify an ajax target

Aaron Newton 15 years ago
parent
commit
486b0913b2

+ 11 - 0
apps/jframegallery/src/jframegallery/templates/gallery/ajax-target.html

@@ -57,6 +57,17 @@ limitations under the License.
 			</div>
 			<hr/>
 			<a href="/jframegallery/gallery/partial_refresh.mako" data-ajax-target=".nothing_here">This is also an ajax link, but it's target is not found, so it falls back to being a regular link.</a>
+
+			<p>This form submits to the box below it:</p>
+			<form action="/jframegallery/gallery/post-load.prompt.popup.html" method="post" style="margin: 6px 0px 0px;" data-ajax-target=".ajax_form_target">
+				enter a value: <input type="text" name="prompt_value"/>
+				<input type="submit" class="jframe-hidden" name="submit"/>
+			</form>
+			<div style="border: 1px solid #000; padding: 10px; margin: 10px 0px; max-height: 100px; overflow:auto;">
+				<div class="ajax_form_target">
+				</div>
+			</div>
+
 		</div>
 	</body>
 </html>

+ 4 - 4
desktop/core/static/js/Source/CCS/CCS.JFrame.js

@@ -169,12 +169,12 @@ CCS.JFrame = new Class({
 		configureRequest - configures a passed in request to be have its response rendered within JFrame..
 		request - (* request object *) request object to be configured
 	*/
-	configureRequest: function(request){
-		this._setRequestOptions(request, {
+	configureRequest: function(request, options){
+		this._setRequestOptions(request, $merge({
 			onSuccess: function(nodes, elements, text){
-				this._requestSuccessHandler(request, text);
+				this._requestSuccessHandler(request, text, options);
 			}.bind(this)
-		});
+		}, options));
 	},
 
 

+ 26 - 1
desktop/core/static/js/Source/JFrameFilters/CCS.JFrame.FormRequest.js

@@ -42,6 +42,31 @@ Behavior.addGlobalPlugin('FormRequest', 'JFrameFormRequest', function(element, m
 	var formRequest = element.get('formRequest');
 	//tell it not to update anything
 	formRequest.request.options.update = null;
+	var options = {};
+	['append', 'replace', 'target', 'after', 'before'].each(function(action){
+		var selector = element.get('data', 'ajax-' + action);
+		if (selector) {
+			var target = methods.getContentElement().getElement(selector);
+			if (target) {
+				$extend(options, {
+					target: target,
+					spinnerTarget: target,
+					noScroll: true,
+					onlyProcessPartials: true,
+					ignoreAutoRefresh: true,
+					suppressLoadComplete: true,
+					fullFrameLoad: false,
+					retainPath: true
+				});
+			}
+		}
+	});
 	//configure its request to use JFrame's response handler
-	methods.configureRequest(formRequest.request);
+	methods.configureRequest(formRequest.request, options);
+	formRequest.addEvent('send', function(form, query){
+		formRequest.request.setOptions({
+			formAction: form.get('action'),
+			formData: query
+		});
+	});
 });