--- a/web/data/cubicweb.edition.js Mon Sep 21 18:02:59 2009 +0200
+++ b/web/data/cubicweb.edition.js Mon Sep 21 18:03:10 2009 +0200
@@ -254,7 +254,7 @@
form.insertBefore(insertBefore).slideDown('fast');
updateInlinedEntitiesCounters(rtype);
reorderTabindex();
- form.trigger('inlinedform-added');
+ jQuery(CubicWeb).trigger('inlinedform-added', form);
// if the inlined form contains a file input, we must force
// the form enctype to multipart/form-data
if (form.find('input:file').length) {
@@ -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/autoform.py Mon Sep 21 18:02:59 2009 +0200
+++ b/web/views/autoform.py Mon Sep 21 18:03:10 2009 +0200
@@ -319,6 +319,33 @@
"""
return card in '1?'
+ @property
+ def form_needs_multipart(self):
+ """true if the form needs enctype=multipart/form-data"""
+ if super(AutomaticEntityForm, self).form_needs_multipart:
+ return True
+ # take a look at inlined forms to check (recursively) if they
+ # need multipart handling.
+ # XXX: this is very suboptimal because inlined forms will be
+ # selected / instantiated twice : here and during form rendering.
+ # Potential solutions:
+ # -> use subforms for inlined forms to get easiser access
+ # -> use a simple onload js function to check if there is
+ # a input type=file in the form
+ # -> generate the <form> node when the content is rendered
+ # and we know the correct enctype (formrenderer's w attribute
+ # is not a StringIO)
+ for rschema, targettypes, role in self.inlined_relations():
+ # inlined forms don't handle multiple target types
+ if len(targettypes) != 1:
+ continue
+ targettype = targettypes[0]
+ if self.should_inline_relation_form(rschema, targettype, role):
+ entity = self.vreg['etypes'].etype_class(targettype)(self.req)
+ subform = self.vreg['forms'].select('edition', self.req, entity=entity)
+ if subform.form_needs_multipart:
+ return True
+ return False
def etype_relation_field(etype, rtype, role='subject'):
eschema = AutomaticEntityForm.schema.eschema(etype)
--- a/web/views/basecontrollers.py Mon Sep 21 18:02:59 2009 +0200
+++ b/web/views/basecontrollers.py Mon Sep 21 18:03:10 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