[autoform] do not show remove link for inline form if card == 1 stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 17 Jun 2010 15:02:22 +0200
branchstable
changeset 5769 b3b48e0b8e3b
parent 5767 1d811df051c2
child 5770 9e4f8db66962
[autoform] do not show remove link for inline form if card == 1
web/views/autoform.py
web/views/formrenderers.py
--- a/web/views/autoform.py	Thu Jun 17 14:42:41 2010 +0200
+++ b/web/views/autoform.py	Thu Jun 17 15:02:22 2010 +0200
@@ -296,12 +296,13 @@
         # the 'add a new xxx' link disappears. If the user then cancel the addition,
         # we have to make this link appears back. This is done by giving add new link
         # id to removeInlineForm.
-        if card not in '?1':
+        if card == '?':
+            divid = "addNew%s%s%s:%s" % (self.etype, self.rtype, self.role, self.peid)
+            return "removeInlineForm('%%s', '%%s', '%s', '%%s', '%s')" % (
+                self.role, divid)
+        elif card in '+*':
             return "removeInlineForm('%%s', '%%s', '%s', '%%s')" % self.role
-        divid = "addNew%s%s%s:%s" % (
-            self.etype, self.rtype, self.role, self.peid)
-        return "removeInlineForm('%%s', '%%s', '%s', '%%s', '%s')" % (
-            self.role, divid)
+        # don't do anything for card == '1'
 
     @cached
     def _entity(self):
--- a/web/views/formrenderers.py	Thu Jun 17 14:42:41 2010 +0200
+++ b/web/views/formrenderers.py	Thu Jun 17 15:02:22 2010 +0200
@@ -444,14 +444,20 @@
                 values['divid'], self._cw._('click on the box to cancel the deletion')))
         w(u'<div class="iformBody">')
         eschema = form.edited_entity.e_schema
-        values['removemsg'] = self._cw._('remove-inlined-entity-form')
-        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>'
-          % values)
+        if values['removejs']:
+            values['removemsg'] = self._cw._('remove-inlined-entity-form')
+            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>'
+              % values)
+        else:
+            w(u'<div class="iformTitle"><span>%(title)s</span> '
+              '#<span class="icounter">%(counter)s</span></div>'
+              % values)
+        # XXX that stinks
         # cleanup values
         for key in ('title', 'removejs', 'removemsg'):
-            values.pop(key)
+            values.pop(key, None)
         self.render_fields(w, form, values)
         w(u'</div></div>')
         return '\n'.join(data)