[reledit] relation edition : cleanup a bit #343123 tls-sprint
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 12 May 2009 19:17:54 +0200
branchtls-sprint
changeset 1760 6b97d286eb5a
parent 1759 61d026ced19f
child 1761 fef5d4b4f511
[reledit] relation edition : cleanup a bit #343123
web/data/cubicweb.edition.js
web/views/basecontrollers.py
web/views/baseviews.py
web/views/editforms.py
--- a/web/data/cubicweb.edition.js	Tue May 12 18:53:41 2009 +0200
+++ b/web/data/cubicweb.edition.js	Tue May 12 19:17:54 2009 +0200
@@ -488,38 +488,29 @@
     return false;
 }
 
-
-function inlineValidateRelationForm(formid, rtype, eid, divid, reload) {
+function inlineValidateRelationForm(formid, rtype, eid, divid, vid) {
     try {
 	var form = getNode(formid);
 	var zipped = formContents(form);
-	var d = asyncRemoteExec('edit_relation', 'apply', zipped[0], zipped[1], rtype, eid);
+	var d = asyncRemoteExec('edit_relation', 'apply', zipped[0], zipped[1], rtype, eid, vid);
     } catch (ex) {
 	log('got exception', ex);
 	return false;
     }
     d.addCallback(function (result, req) {
         handleFormValidationResponse(formid, noop, result);
-	if (reload) {
-             log(result[1]);
-	    //document.location.href = result[1];
-	} else {
-            log(result[2]);
-	    var fieldview = getNode(divid);
-	    // XXX using innerHTML is very fragile and won't work if
-	    // we mix XHTML and HTML
-	    fieldview.innerHTML = result[2];
-	    // switch inline form off only if no error
-	    if (result[0]) {
-		// hide global error messages
-		jQuery('div.errorMessage').remove();
-		jQuery('#appMsg').hide();
-		cancelInlineEdit(eid, rtype, divid);
-	    }
+	var fieldview = getNode(divid);
+        fieldview.innerHTML = result[2];
+	// switch inline form off only if no error
+	if (result[0]) {
+          // hide global error messages
+	  jQuery('div.errorMessage').remove();
+	  jQuery('#appMsg').hide();
+	  cancelInlineEdit(eid, rtype, divid);
 	}
-	return false;
+        return false;
     });
-    return false;
+  return false;
 }
 
 
--- a/web/views/basecontrollers.py	Tue May 12 18:53:41 2009 +0200
+++ b/web/views/basecontrollers.py	Tue May 12 19:17:54 2009 +0200
@@ -405,7 +405,7 @@
 
     @jsonize
     def js_edit_relation(self, action, names, values,
-                         rtype, eid, role='subject', vid='list'):
+                         rtype, eid, vid, role='subject'):
         success, args = self.validate_form(action, names, values)
         if success:
             entity = self.req.eid_rset(eid).get_entity(0, 0)
--- a/web/views/baseviews.py	Tue May 12 18:53:41 2009 +0200
+++ b/web/views/baseviews.py	Tue May 12 19:17:54 2009 +0200
@@ -68,7 +68,7 @@
     def cell_call(self, row, col, props=None, displaytime=False, format='text/html'):
         etype = self.rset.description[row][col]
         value = self.rset.rows[row][col]
-       
+
         if etype == 'String':
             entity, rtype = self.rset.related_entity(row, col)
             if entity is not None:
--- a/web/views/editforms.py	Tue May 12 18:53:41 2009 +0200
+++ b/web/views/editforms.py	Tue May 12 19:17:54 2009 +0200
@@ -94,7 +94,7 @@
     ondblclick = "showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')"
 
     def cell_call(self, row, col, rtype=None, role='subject', reload=False,
-                  vid='list'):
+                  vid='textoutofcontext'):
         """display field to edit entity's `rtype` relation on double-click"""
         rschema = self.schema.rschema(rtype)
         entity = self.entity(row, col)
@@ -105,43 +105,43 @@
                 value = entity.printable_value(rtype)
         else:
             rset = entity.related(rtype, role)
-            value = '&nbsp;%s&nbsp;' % self.view(vid, rset, 'null')
+            value = self.view(vid, rset, 'null')
         if not entity.has_perm('update'):
             self.w(value)
             return
         if rschema.is_final():
-            self._edit_attribute(entity, value, rtype, role, reload, row, col)
+            form = self._build_attribute_form(entity, value, rtype, role, reload, row, col)
         else:
-            self._edit_relation(entity, value, rtype, role, reload, row, col)
+            form = self._build_relation_form(entity, value, rtype, role, row, col, vid)
+        form.form_add_hidden(u'__maineid', entity.eid)
+        renderer = FormRenderer(display_label=False, display_help=False,
+                                display_fields=[(rtype, role)],
+                                table_class='', button_bar_class='buttonbar',
+                                display_progress_div=False)
+        self.w(form.form_render(renderer=renderer))
 
-    def _edit_relation(self, entity, value, rtype, role, reload, row, col):
+    def _build_relation_form(self, entity, value, rtype, role, row, col, vid):
         rtype = 'person_in_charge'
         entity = self.entity(row, col)
         divid = 'd%s' % make_uid('%s-%s' % (rtype, entity.eid))
-        event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype,
-                      'reload' : dumps(reload)}
+        event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'vid' : vid}
         form = EntityFieldsForm(self.req, None, entity=entity, action='#',
                                 domid='%s-form' % divid,
                                 cssstyle='display: none',
                                 onsubmit=("return inlineValidateRelationForm('%(divid)s-form', '%(rtype)s', "
-                                          "'%(eid)s', '%(divid)s', %(reload)s);" % event_data),
+                                          "'%(eid)s', '%(divid)s', '%(vid)s');" % event_data),
                                 form_buttons=[SubmitButton(),
                                               Button(stdmsgs.BUTTON_CANCEL,
                                                      onclick="cancelInlineEdit(%s,\'%s\',\'%s\')" %\
                                                          (entity.eid, rtype, divid))])
-        form.form_add_hidden(u'__maineid', entity.eid)
         form.append_field(RelationField(name=rtype, sort=True,
                                         widget=Select(dict(size=1)),
                                         label=u' '))
-        renderer = FormRenderer(display_label=False, display_help=False,
-                                display_fields=[(rtype, role)],
-                                table_class='', button_bar_class='buttonbar',
-                                display_progress_div=False)
         self.w(tags.div(value, klass='editableField', id=divid,
                         ondblclick=self.ondblclick % event_data))
-        self.w(form.form_render(renderer=renderer))
+        return form
 
-    def _edit_attribute(self, entity, value, rtype, role, reload, row, col):
+    def _build_attribute_form(self, entity, value, rtype, role, reload, row, col):
         eid = entity.eid
         divid = 'd%s' % make_uid('%s-%s' % (rtype, eid))
         event_data = {'divid' : divid, 'eid' : eid, 'rtype' : rtype,
@@ -155,14 +155,9 @@
                                        domid='%s-form' % divid, action='#',
                                        cssstyle='display: none',
                                        onsubmit=self.onsubmit % event_data)
-        form.form_add_hidden(u'__maineid', eid)
-        renderer = FormRenderer(display_label=False, display_help=False,
-                                display_fields=[(rtype, role)],
-                                table_class='', button_bar_class='buttonbar',
-                                display_progress_div=False)
         self.w(tags.div(value, klass='editableField', id=divid,
                         ondblclick=self.ondblclick % event_data))
-        self.w(form.form_render(renderer=renderer))
+        return form
 
 
 class EditionFormView(FormViewMixIn, EntityView):