[validatecontroller] allow additional args to be passed to the js callback stable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 21 Sep 2009 17:04:19 +0200
branchstable
changeset 3343 383b42263bb1
parent 3342 8b30ae9c4e67
child 3349 cb610a404001
[validatecontroller] allow additional args to be passed to the js callback
web/data/cubicweb.edition.js
web/views/basecontrollers.py
--- a/web/data/cubicweb.edition.js	Mon Sep 21 15:55:40 2009 +0200
+++ b/web/data/cubicweb.edition.js	Mon Sep 21 17:04:19 2009 +0200
@@ -350,11 +350,11 @@
 }
 
 
-function handleFormValidationResponse(formid, onsuccess, onfailure, result) {
+function handleFormValidationResponse(formid, onsuccess, onfailure, result, cbargs) {
     // Success
     if (result[0]) {
 	if (onsuccess) {
-             onsuccess(result, formid);
+             onsuccess(result, formid, cbargs);
 	} else {
 	    document.location.href = result[1];
 	}
@@ -374,7 +374,7 @@
     updateMessage(_('please correct errors below'));
     document.location.hash = '#header';
     if (onfailure) {
-	onfailure(formid);
+	onfailure(formid, cbargs);
     }
     return false;
 }
--- a/web/views/basecontrollers.py	Mon Sep 21 15:55:40 2009 +0200
+++ b/web/views/basecontrollers.py	Mon Sep 21 17:04:19 2009 +0200
@@ -213,12 +213,13 @@
     def response(self, domid, status, args, entity):
         callback = str(self.req.form.get('__onsuccess', 'null'))
         errback = str(self.req.form.get('__onfailure', 'null'))
+        cbargs = str(self.req.form.get('__cbargs', 'null'))
         self.req.set_content_type('text/html')
         jsargs = simplejson.dumps((status, args, entity), cls=CubicWebJsonEncoder)
         return """<script type="text/javascript">
  wp = window.parent;
- window.parent.handleFormValidationResponse('%s', %s, %s, %s);
-</script>""" %  (domid, callback, errback, jsargs)
+ window.parent.handleFormValidationResponse('%s', %s, %s, %s, %s);
+</script>""" %  (domid, callback, errback, jsargs, cbargs)
 
     def publish(self, rset=None):
         self.req.json_request = True