481 |
481 |
482 @property |
482 @property |
483 @cached |
483 @cached |
484 def form(self): |
484 def form(self): |
485 entity = self._entity() |
485 entity = self._entity() |
486 form = self.vreg['forms'].select('edition', self._cw, |
486 form = self._cw.vreg['forms'].select('edition', self._cw, |
487 entity=entity, |
487 entity=entity, |
488 form_renderer_id='inline', |
488 form_renderer_id='inline', |
489 copy_nav_params=False, |
489 copy_nav_params=False, |
490 mainform=False, |
490 mainform=False, |
491 parent_form=self.pform, |
491 parent_form=self.pform, |
492 **self.extra_kwargs) |
492 **self.cw_extra_kwargs) |
493 if self.pform is None: |
493 if self.pform is None: |
494 form.restore_previous_post(form.session_key()) |
494 form.restore_previous_post(form.session_key()) |
495 #assert form.parent_form |
495 #assert form.parent_form |
496 self.add_hiddens(form, entity) |
496 self.add_hiddens(form, entity) |
497 return form |
497 return form |
517 countkey = '%s_count' % self.rtype |
517 countkey = '%s_count' % self.rtype |
518 try: |
518 try: |
519 self._cw.data[countkey] += 1 |
519 self._cw.data[countkey] += 1 |
520 except KeyError: |
520 except KeyError: |
521 self._cw.data[countkey] = 1 |
521 self._cw.data[countkey] = 1 |
522 self.w(self.form.form.render( |
|
523 divid=divid, title=title, removejs=removejs, i18nctx=i18nctx, |
|
524 counter=self.req.data[countkey], **kwargs)) |
|
525 self.w(self.form.render( |
522 self.w(self.form.render( |
526 rendervalues=dict(divid=divid, title=title, removejs=removejs, |
523 rendervalues=dict(divid=divid, title=title, removejs=removejs, |
527 i18nctx=i18nctx, counter=self._cw.data[countkey]), |
524 i18nctx=i18nctx, counter=self._cw.data[countkey]), |
528 formvalues=kwargs)) |
525 formvalues=kwargs)) |
529 |
526 |
530 def form_title(self, entity, i18nctx): |
527 def form_title(self, entity, i18nctx): |
531 return self.req.pgettext(i18nctx, 'This %s' % entity.e_schema) |
528 return self._cw.pgettext(i18nctx, 'This %s' % entity.e_schema) |
532 |
529 |
533 def add_hiddens(self, form, entity): |
530 def add_hiddens(self, form, entity): |
534 """to ease overriding (see cubes.vcsfile.views.forms for instance)""" |
531 """to ease overriding (see cubes.vcsfile.views.forms for instance)""" |
535 iid = 'rel-%s-%s-%s' % (self.peid, self.rtype, entity.eid) |
532 iid = 'rel-%s-%s-%s' % (self.peid, self.rtype, entity.eid) |
536 # * str(self.rtype) in case it's a schema object |
533 # * str(self.rtype) in case it's a schema object |
579 try: |
576 try: |
580 cls = self._cw.vreg['etypes'].etype_class(self.etype) |
577 cls = self._cw.vreg['etypes'].etype_class(self.etype) |
581 except: |
578 except: |
582 self.w(self._cw._('no such entity type %s') % etype) |
579 self.w(self._cw._('no such entity type %s') % etype) |
583 return |
580 return |
584 self.initialize_varmaker() |
581 entity = cls(self._cw) |
585 entity = cls(self.req) |
582 entity.eid = self._cw.varmaker.next() |
586 entity.eid = self.varmaker.next() |
|
587 return entity |
583 return entity |
588 |
584 |
589 def call(self, i18nctx, **kwargs): |
585 def call(self, i18nctx, **kwargs): |
590 self.render_form(i18nctx, **kwargs) |
586 self.render_form(i18nctx, **kwargs) |
591 |
587 |
607 % divid) |
603 % divid) |
608 js = "addInlineCreationForm('%s', '%s', '%s', '%s', '%s')" % ( |
604 js = "addInlineCreationForm('%s', '%s', '%s', '%s', '%s')" % ( |
609 self.peid, self.etype, self.rtype, self.role, i18nctx) |
605 self.peid, self.etype, self.rtype, self.role, i18nctx) |
610 if self.pform.should_hide_add_new_relation_link(self.rtype, self.card): |
606 if self.pform.should_hide_add_new_relation_link(self.rtype, self.card): |
611 js = "toggleVisibility('%s'); %s" % (divid, js) |
607 js = "toggleVisibility('%s'); %s" % (divid, js) |
612 __ = self.req.pgettext |
608 __ = self._cw.pgettext |
613 self.w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>' |
609 self.w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>' |
614 % (self.rtype, self.peid, js, __(i18nctx, 'add a %s' % self.etype))) |
610 % (self.rtype, self.peid, js, __(i18nctx, 'add a %s' % self.etype))) |
615 self.w(u'</div>') |
611 self.w(u'</div>') |