Explorar o código

HUE-353. Add livePathUpdate action to FormRequest

Marcus McLaughlin %!s(int64=15) %!d(string=hai) anos
pai
achega
78bc98996c

+ 3 - 0
desktop/core/static/js/Source/CCS/CCS.JFrame.js

@@ -153,6 +153,9 @@ CCS.JFrame = new Class({
 			}.bind(this)
 		});
 		this.addEvent('resize', this.behavior.resize.bind(this.behavior));
+		this.addEvent('livePathUpdate', function(uri) {
+			this.behavior.fireEvent('livePathUpdate', uri);
+		}.bind(this));
 		this.addBehaviors(this.options.behaviors);
 
 		this.element.addClass('jframe_wrapper').addClass('ccs-shared');

+ 15 - 2
desktop/core/static/js/Source/JFrameFilters/CCS.JFrame.FormRequest.js

@@ -30,7 +30,10 @@ CCS.JFrame.addGlobalFilters({
 		//get all forms in the response
 		container.getElements('form').each(function(form){
 			//set their action url and add the FormRequest filter
-			form.set('action', new URI(form.get('action'), {base: this.currentPath})).addDataFilter("FormRequest");
+			if(form.get('action')){
+				form.set('action', new URI(form.get('action'), {base: this.currentPath}));
+			}
+			form.addDataFilter("FormRequest");
 		}, this);
 	}
 
@@ -63,10 +66,20 @@ Behavior.addGlobalPlugin('FormRequest', 'JFrameFormRequest', function(element, m
 	});
 	//configure its request to use JFrame's response handler
 	methods.configureRequest(formRequest.request, options);
+	//if the element does not initially have an action, update its action to the new path, on livePathUpdate
+	var pathUpdate = function(uri) {
+		element.set('action', uri);
+	};
+	if (!element.get('action')){
+		methods.addEvent('livePathUpdate', pathUpdate);
+	}
 	formRequest.addEvent('send', function(form, query){
 		formRequest.request.setOptions({
 			formAction: form.get('action'),
 			formData: query
 		});
 	});
-});
+	this.markForCleanup(element, function() {
+		methods.removeEvent('livePathUpdate', pathUpdate);
+	});
+});

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

@@ -27,15 +27,15 @@ script: CCS.JFrame.LivePath.js
 	CCS.JFrame.addGlobalLinkers({
 
 		'[data-livepath-toggle]': function(event, link){
-			this.currentPath = updateLivePath(link, this.currentPath);
+			this.currentPath = updateLivePath.call(this, link, this.currentPath);
 		},
 		//these are a bit silly, but mootools 1.2 selector engine doesn't support
 		//complex selectors for element.match, so we have to do a bit of repetition here
 		'[data-livepath-add]': function(event, link){
-			this.currentPath = updateLivePath(link, this.currentPath);
+			this.currentPath = updateLivePath.call(this, link, this.currentPath);
 		},
 		'[data-livepath-remove]': function(event, link){
-			this.currentPath = updateLivePath(link, this.currentPath);
+			this.currentPath = updateLivePath.call(this, link, this.currentPath);
 		}
 
 	});
@@ -76,7 +76,8 @@ script: CCS.JFrame.LivePath.js
 			remove = remove.parseQueryString();
 			setData(uri, remove, 'toggle');
 		}
+		this.fireEvent('livePathUpdate', uri);
 		return uri.toString();
 	};
 
-})();
+})();