web/views/formrenderers.py
changeset 3369 7b88d12b4ee2
parent 3293 69c0ba095536
parent 3360 b02df886eb3e
child 3377 dd9d292b6a6d
child 3388 b8be8fc77c27
--- a/web/views/formrenderers.py	Thu Sep 17 15:52:46 2009 +0200
+++ b/web/views/formrenderers.py	Tue Sep 22 12:11:12 2009 +0200
@@ -475,6 +475,9 @@
         w(u'</table>')
         w(u'</fieldset>')
 
+    # NOTE: should_* and display_* method extracted and moved to the form to
+    # ease overriding
+
     def inline_entities_form(self, w, form):
         """create a form to edit entity's inlined relations"""
         if not hasattr(form, 'inlined_relations'):
@@ -494,12 +497,10 @@
     def inline_relation_form(self, w, form, rschema, targettype, role):
         entity = form.edited_entity
         __ = self.req.pgettext
+        i18nctx = 'inlined:%s.%s.%s' % (entity.e_schema, rschema, role)
         w(u'<div id="inline%sslot">' % rschema)
-        existant = entity.has_eid() and entity.related(rschema)
-        if existant:
-            # display inline-edition view for all existing related entities
-            w(form.view('inline-edition', existant, rtype=rschema, role=role,
-                        ptype=entity.e_schema, peid=entity.eid))
+        existant = form.display_inline_edition_form(w, rschema, targettype,
+                                                    role, i18nctx)
         if role == 'subject':
             card = rschema.rproperty(entity.e_schema, targettype, 'cardinality')[0]
         else:
@@ -507,9 +508,8 @@
         # there is no related entity and we need at least one: we need to
         # display one explicit inline-creation view
         if form.should_display_inline_creation_form(rschema, existant, card):
-            w(form.view('inline-creation', None, etype=targettype,
-                        peid=entity.eid, ptype=entity.e_schema,
-                        rtype=rschema, role=role))
+            form.display_inline_creation_form(w, rschema, targettype,
+                                              role, i18nctx)
             existant = True
         # we can create more than one related entity, we thus display a link
         # to add new related entities
@@ -517,13 +517,12 @@
             divid = "addNew%s%s%s:%s" % (targettype, rschema, role, entity.eid)
             w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">'
               % divid)
-            js = "addInlineCreationForm('%s', '%s', '%s', '%s')" % (
-                entity.eid, targettype, rschema, role)
-            if card in '1?':
+            js = "addInlineCreationForm('%s', '%s', '%s', '%s', '%s')" % (
+                entity.eid, targettype, rschema, role, i18nctx)
+            if form.should_hide_add_new_relation_link(rschema, card):
                 js = "toggleVisibility('%s'); %s" % (divid, js)
-            ctx = 'inlined:%s.%s.%s' % (entity.e_schema, rschema, role)
             w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
-              % (rschema, entity.eid, js, __(ctx, 'add a %s' % targettype)))
+              % (rschema, entity.eid, js, __(i18nctx, 'add a %s' % targettype)))
             w(u'</div>')
             w(u'<div class="trame_grise">&#160;</div>')
         w(u'</div>')
@@ -547,7 +546,9 @@
             w(u'<div id="notice-%s" class="notice">%s</div>' % (
                 values['divid'], self.req._('click on the box to cancel the deletion')))
         w(u'<div class="iformBody">')
-        values['removemsg'] = self.req.__('remove this %s' % form.edited_entity.e_schema)
+        eschema = form.edited_entity.e_schema
+        ctx = values.pop('i18nctx')
+        values['removemsg'] = self.req.pgettext(ctx, 'remove this %s' % eschema)
         w(u'<div class="iformTitle"><span>%(title)s</span> '
           '#<span class="icounter">%(counter)s</span> '
           '[<a href="javascript: %(removejs)s;noop();">%(removemsg)s</a>]</div>'