Преглед изворни кода

HUE-304. Cannot submit form from outside. Allow submitting any form from any link not only a child of the form itself.

* added the data-form attribute. This is a CSS selector that is used to search for the form.

* Safer request handling with specific warning when things go wrong
Thomas Aylott пре 15 година
родитељ
комит
9c22456c97

+ 6 - 1
apps/jframegallery/src/jframegallery/templates/submit.link.html

@@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 {% endcomment %}
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<!DOCTYPE html>
 <html>
 	<head>
 		<title>Submit Links</title>
@@ -31,6 +31,11 @@ limitations under the License.
 			<a class="ccs-submit_form" data-extra-data="{'link':'fetch html (link 2)'}">fetch html (link 2)</a>
 		</form>
 
+		<p>
+			Outside of the form:
+			<a data-form="form" class="ccs-submit_form" data-extra-data="{'link':'fetch html (link 3)'}">fetch html (link 3)</a>
+		</p>
+
 		<div style="position: relative; margin-top: 10px">
 			<div id="update" style="padding: 10px; width: 200px; border: 1px solid black; height: 100px; overflow:hidden;">
 				{% if post_vars %}

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

@@ -24,12 +24,31 @@ script: CCS.JFrame.SubmitLink.js
 ...
 */
 
+;(function(){
+
+function getFormForElement(el){
+	var formSelector = el.get('data-form') || 'form';
+	var form = el.getParent(formSelector) || this.getWindowElement().getElement(formSelector);
+	if (!form){
+		if (formSelector) dbug.error('Cannot find data-form="' +formSelector+ '" for ccs-submit_form');
+		else dbug.error('Cannot find FORM parent of ccs-submit_form');
+	}
+	return form;
+}
+
+
 CCS.JFrame.addGlobalLinkers({
 	/*
-		submit the form that the element is in.
+		submit the form that the element is in
+		or the form that it specifies
 	*/
-	'.ccs-submit_form': function(event, el) {
-		el.getParent('form').retrieve('form.request').setOptions({extraData: el.getJSONData('extra-data')}).send();
+	'.ccs-submit_form': function(event, el){
+		var rq = getFormForElement.call(this, el).retrieve('form.request');
+		if (rq) rq.setOptions({extraData:el.getJSONData('extra-data')}).send();
+		else dbug.error('Form Request not found');
 	}
 
-});
+});
+
+
+}());