453 'removemsg' : self.req.__('remove this %s' % entity.e_schema), |
453 'removemsg' : self.req.__('remove this %s' % entity.e_schema), |
454 'notice' : self.req._('click on the box to cancel the deletion'), |
454 'notice' : self.req._('click on the box to cancel the deletion'), |
455 } |
455 } |
456 ctx.update(local_ctx) |
456 ctx.update(local_ctx) |
457 return ctx |
457 return ctx |
458 |
|
459 |
|
460 class InlineEntityCreationForm(InlineFormMixIn, CreationForm): |
|
461 id = 'inline-creation' |
|
462 __select__ = (match_kwargs('ptype', 'peid', 'rtype') |
|
463 & specified_etype_implements('Any')) |
|
464 |
|
465 EDITION_BODY = u'''\ |
|
466 <div id="div-%(parenteid)s-%(rtype)s-%(eid)s" class="inlinedform"> |
|
467 <div class="iformBody"> |
|
468 <div class="iformTitle"><span>%(title)s</span> #<span class="icounter">1</span> [<a href="javascript: removeInlineForm('%(parenteid)s', '%(rtype)s', '%(eid)s'); noop();">%(removemsg)s</a>]</div> |
|
469 <fieldset class="subentity"> |
|
470 %(attrform)s |
|
471 %(relattrform)s |
|
472 </fieldset> |
|
473 </div> |
|
474 <fieldset class="hidden" id="fs-%(parenteid)s-%(rtype)s-%(eid)s"> |
|
475 %(base)s |
|
476 <input type="hidden" value="%(novalue)s" name="edit%(so)s-%(rtype)s:%(parenteid)s" /> |
|
477 <input id="rel-%(parenteid)s-%(rtype)s-%(eid)s" type="hidden" value="%(eid)s" name="%(rtype)s:%(parenteid)s" /> |
|
478 </fieldset> |
|
479 </div>''' # do not insert trailing space or \n here ! |
|
480 |
|
481 def call(self, etype, ptype, peid, rtype, role='subject', **kwargs): |
|
482 """ |
|
483 :param etype: the entity type being created in the inline form |
|
484 :param parent: the parent entity hosting the inline form |
|
485 :param rtype: the relation bridging `etype` and `parent` |
|
486 :param role: the role played by the `parent` in the relation |
|
487 """ |
|
488 try: |
|
489 entity = self.vreg.etype_class(etype)(self.req, None, None) |
|
490 except: |
|
491 self.w(self.req._('no such entity type %s') % etype) |
|
492 return |
|
493 self.edit_form(entity, ptype, peid, rtype, role, **kwargs) |
|
494 |
|
495 |
|
496 class InlineEntityEditionForm(InlineFormMixIn, EditionForm): |
|
497 id = 'inline-edition' |
|
498 __select__ = non_final_entity() & match_kwargs('ptype', 'peid', 'rtype') |
|
499 |
|
500 EDITION_BODY = u'''\ |
|
501 <div onclick="restoreInlinedEntity('%(parenteid)s', '%(rtype)s', '%(eid)s')" id="div-%(parenteid)s-%(rtype)s-%(eid)s" class="inlinedform"> |
|
502 <div id="notice-%(parenteid)s-%(rtype)s-%(eid)s" class="notice">%(notice)s</div> |
|
503 <div class="iformTitle"><span>%(title)s</span> #<span class="icounter">%(count)s</span> [<a href="javascript: removeInlinedEntity('%(parenteid)s', '%(rtype)s', '%(eid)s'); noop();">%(removemsg)s</a>]</div> |
|
504 <div class="iformBody"> |
|
505 <fieldset class="subentity"> |
|
506 %(attrform)s |
|
507 </fieldset> |
|
508 %(relattrform)s |
|
509 </div> |
|
510 <fieldset id="fs-%(parenteid)s-%(rtype)s-%(eid)s"> |
|
511 %(base)s |
|
512 <input type="hidden" value="%(eid)s" name="edit%(so)s-%(rtype)s:%(parenteid)s" /> |
|
513 %(rinput)s |
|
514 </fieldset> |
|
515 </div>''' # do not insert trailing space or \n here ! |
|
516 |
|
517 rel_input = u'''<input id="rel-%(parenteid)s-%(rtype)s-%(eid)s" type="hidden" value="%(eid)s" name="%(rtype)s:%(parenteid)s" />''' |
|
518 |
|
519 def call(self, **kwargs): |
|
520 """redefine default View.call() method to avoid automatic |
|
521 insertions of <div class="section"> between each row of |
|
522 the resultset |
|
523 """ |
|
524 rset = self.rset |
|
525 for i in xrange(len(rset)): |
|
526 self.wview(self.id, rset, row=i, **kwargs) |
|
527 |
|
528 def cell_call(self, row, col, ptype, peid, rtype, role='subject', **kwargs): |
|
529 """ |
|
530 :param parent: the parent entity hosting the inline form |
|
531 :param rtype: the relation bridging `etype` and `parent` |
|
532 :param role: the role played by the `parent` in the relation |
|
533 """ |
|
534 entity = self.entity(row, col) |
|
535 self.edit_form(entity, ptype, peid, rtype, role, **kwargs) |
|
536 |
|
537 |
|
538 def form_context(self, entity, kwargs): |
|
539 ctx = super(InlineEntityEditionForm, self).form_context(entity, kwargs) |
|
540 if self.keep_entity(entity): |
|
541 ctx['rinput'] = self.rel_input % ctx |
|
542 ctx['todelete'] = u'' |
|
543 else: |
|
544 ctx['rinput'] = u'' |
|
545 ctx['todelete'] = u'checked="checked"' |
|
546 ctx['count'] = entity.row + 1 |
|
547 return ctx |
|
548 |
458 |
549 |
459 |
550 class CopyEditionForm(EditionForm): |
460 class CopyEditionForm(EditionForm): |
551 id = 'copy' |
461 id = 'copy' |
552 title = _('copy edition') |
462 title = _('copy edition') |