web/views/formrenderers.py
branchstable
changeset 3327 44efba78afac
parent 3275 5247789df541
child 3330 2fa09be849e7
equal deleted inserted replaced
3326:e3089ceee1ea 3327:44efba78afac
   487                 self.inline_relation_form(w, form, rschema, targettype, role)
   487                 self.inline_relation_form(w, form, rschema, targettype, role)
   488 
   488 
   489     def inline_relation_form(self, w, form, rschema, targettype, role):
   489     def inline_relation_form(self, w, form, rschema, targettype, role):
   490         entity = form.edited_entity
   490         entity = form.edited_entity
   491         __ = self.req.pgettext
   491         __ = self.req.pgettext
       
   492         i18nctx = 'inlined:%s.%s.%s' % (entity.e_schema, rschema, role)
   492         w(u'<div id="inline%sslot">' % rschema)
   493         w(u'<div id="inline%sslot">' % rschema)
   493         existant = entity.has_eid() and entity.related(rschema)
   494         existant = entity.has_eid() and entity.related(rschema)
   494         if existant:
   495         if existant:
   495             # display inline-edition view for all existing related entities
   496             # display inline-edition view for all existing related entities
   496             w(form.view('inline-edition', existant, rtype=rschema, role=role,
   497             w(form.view('inline-edition', existant, rtype=rschema, role=role,
   502         # there is no related entity and we need at least one: we need to
   503         # there is no related entity and we need at least one: we need to
   503         # display one explicit inline-creation view
   504         # display one explicit inline-creation view
   504         if form.should_display_inline_creation_form(rschema, existant, card):
   505         if form.should_display_inline_creation_form(rschema, existant, card):
   505             w(form.view('inline-creation', None, etype=targettype,
   506             w(form.view('inline-creation', None, etype=targettype,
   506                         peid=entity.eid, ptype=entity.e_schema,
   507                         peid=entity.eid, ptype=entity.e_schema,
   507                         rtype=rschema, role=role))
   508                         rtype=rschema, role=role, i18nctx=i18nctx))
   508             existant = True
   509             existant = True
   509         # we can create more than one related entity, we thus display a link
   510         # we can create more than one related entity, we thus display a link
   510         # to add new related entities
   511         # to add new related entities
   511         if form.should_display_add_new_relation_link(rschema, existant, card):
   512         if form.should_display_add_new_relation_link(rschema, existant, card):
   512             divid = "addNew%s%s%s:%s" % (targettype, rschema, role, entity.eid)
   513             divid = "addNew%s%s%s:%s" % (targettype, rschema, role, entity.eid)
   513             w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">'
   514             w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">'
   514               % divid)
   515               % divid)
   515             js = "addInlineCreationForm('%s', '%s', '%s', '%s')" % (
   516             js = "addInlineCreationForm('%s', '%s', '%s', '%s', '%s')" % (
   516                 entity.eid, targettype, rschema, role)
   517                 entity.eid, targettype, rschema, role, i18nctx)
   517             if card in '1?':
   518             if form.should_hide_add_new_relation_link(rschema, card):
   518                 js = "toggleVisibility('%s'); %s" % (divid, js)
   519                 js = "toggleVisibility('%s'); %s" % (divid, js)
   519             ctx = 'inlined:%s.%s.%s' % (entity.e_schema, rschema, role)
       
   520             w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
   520             w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
   521               % (rschema, entity.eid, js, __(ctx, 'add a %s' % targettype)))
   521               % (rschema, entity.eid, js, __(i18nctx, 'add a %s' % targettype)))
   522             w(u'</div>')
   522             w(u'</div>')
   523             w(u'<div class="trame_grise">&#160;</div>')
   523             w(u'<div class="trame_grise">&#160;</div>')
   524         w(u'</div>')
   524         w(u'</div>')
   525 
   525 
   526 
   526 
   540             w(u'<div id="div-%(divid)s">' % values)
   540             w(u'<div id="div-%(divid)s">' % values)
   541         else:
   541         else:
   542             w(u'<div id="notice-%s" class="notice">%s</div>' % (
   542             w(u'<div id="notice-%s" class="notice">%s</div>' % (
   543                 values['divid'], self.req._('click on the box to cancel the deletion')))
   543                 values['divid'], self.req._('click on the box to cancel the deletion')))
   544         w(u'<div class="iformBody">')
   544         w(u'<div class="iformBody">')
   545         values['removemsg'] = self.req.__('remove this %s' % form.edited_entity.e_schema)
   545         eschema = form.edited_entity.e_schema
       
   546         ctx = values.pop('i18nctx')
       
   547         values['removemsg'] = self.req.pgettext(ctx, 'remove this %s' % eschema)
   546         w(u'<div class="iformTitle"><span>%(title)s</span> '
   548         w(u'<div class="iformTitle"><span>%(title)s</span> '
   547           '#<span class="icounter">%(counter)s</span> '
   549           '#<span class="icounter">%(counter)s</span> '
   548           '[<a href="javascript: %(removejs)s;noop();">%(removemsg)s</a>]</div>'
   550           '[<a href="javascript: %(removejs)s;noop();">%(removemsg)s</a>]</div>'
   549           % values)
   551           % values)
   550         # cleanup values
   552         # cleanup values