410 |
410 |
411 def inline_entities_form(self, w, form): |
411 def inline_entities_form(self, w, form): |
412 """create a form to edit entity's inlined relations""" |
412 """create a form to edit entity's inlined relations""" |
413 if not hasattr(form, 'inlined_relations'): |
413 if not hasattr(form, 'inlined_relations'): |
414 return |
414 return |
415 entity = form.edited_entity |
|
416 __ = self.req.__ |
|
417 for rschema, targettypes, role in form.inlined_relations(): |
415 for rschema, targettypes, role in form.inlined_relations(): |
418 # show inline forms only if there's one possible target type |
416 # show inline forms only if there's one possible target type |
419 # for rschema |
417 # for rschema |
420 if len(targettypes) != 1: |
418 if len(targettypes) != 1: |
421 self.warning('entity related by the %s relation should have ' |
419 self.warning('entity related by the %s relation should have ' |
422 'inlined form but there is multiple target types, ' |
420 'inlined form but there is multiple target types, ' |
423 'dunno what to do', rschema) |
421 'dunno what to do', rschema) |
424 continue |
422 continue |
425 targettype = targettypes[0].type |
423 targettype = targettypes[0].type |
426 if form.should_inline_relation_form(rschema, targettype, role): |
424 if form.should_inline_relation_form(rschema, targettype, role): |
427 w(u'<div id="inline%sslot">' % rschema) |
425 self.inline_relation_form(w, form, rschema, targettype, role) |
428 existant = entity.has_eid() and entity.related(rschema) |
426 |
429 if existant: |
427 def inline_relation_form(self, w, form, rschema, targettype, role): |
430 # display inline-edition view for all existing related entities |
428 entity = form.edited_entity |
431 w(form.view('inline-edition', existant, rtype=rschema, role=role, |
429 __ = self.req.__ |
432 ptype=entity.e_schema, peid=entity.eid)) |
430 w(u'<div id="inline%sslot">' % rschema) |
433 if role == 'subject': |
431 existant = entity.has_eid() and entity.related(rschema) |
434 card = rschema.rproperty(entity.e_schema, targettype, 'cardinality')[0] |
432 if existant: |
435 else: |
433 # display inline-edition view for all existing related entities |
436 card = rschema.rproperty(targettype, entity.e_schema, 'cardinality')[1] |
434 w(form.view('inline-edition', existant, rtype=rschema, role=role, |
437 # there is no related entity and we need at least one: we need to |
435 ptype=entity.e_schema, peid=entity.eid)) |
438 # display one explicit inline-creation view |
436 if role == 'subject': |
439 if form.should_display_inline_creation_form(rschema, existant, card): |
437 card = rschema.rproperty(entity.e_schema, targettype, 'cardinality')[0] |
440 w(form.view('inline-creation', None, etype=targettype, |
438 else: |
441 peid=entity.eid, ptype=entity.e_schema, |
439 card = rschema.rproperty(targettype, entity.e_schema, 'cardinality')[1] |
442 rtype=rschema, role=role)) |
440 # there is no related entity and we need at least one: we need to |
443 # we can create more than one related entity, we thus display a link |
441 # display one explicit inline-creation view |
444 # to add new related entities |
442 if form.should_display_inline_creation_form(rschema, existant, card): |
445 if form.should_display_add_new_relation_link(rschema, existant, card): |
443 w(form.view('inline-creation', None, etype=targettype, |
446 divid = "addNew%s%s%s:%s" % (targettype, rschema, role, entity.eid) |
444 peid=entity.eid, ptype=entity.e_schema, |
447 w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">' |
445 rtype=rschema, role=role)) |
448 % divid) |
446 # we can create more than one related entity, we thus display a link |
449 js = "addInlineCreationForm('%s', '%s', '%s', '%s')" % ( |
447 # to add new related entities |
450 entity.eid, targettype, rschema, role) |
448 if form.should_display_add_new_relation_link(rschema, existant, card): |
451 if card in '1?': |
449 divid = "addNew%s%s%s:%s" % (targettype, rschema, role, entity.eid) |
452 js = "toggleVisibility('%s'); %s" % (divid, js) |
450 w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">' |
453 w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>' |
451 % divid) |
454 % (rschema, entity.eid, js, __('add a %s' % targettype))) |
452 js = "addInlineCreationForm('%s', '%s', '%s', '%s')" % ( |
455 w(u'</div>') |
453 entity.eid, targettype, rschema, role) |
456 w(u'<div class="trame_grise"> </div>') |
454 if card in '1?': |
457 w(u'</div>') |
455 js = "toggleVisibility('%s'); %s" % (divid, js) |
|
456 w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>' |
|
457 % (rschema, entity.eid, js, __('add a %s' % targettype))) |
|
458 w(u'</div>') |
|
459 w(u'<div class="trame_grise"> </div>') |
|
460 w(u'</div>') |
458 |
461 |
459 |
462 |
460 class EntityInlinedFormRenderer(EntityFormRenderer): |
463 class EntityInlinedFormRenderer(EntityFormRenderer): |
461 """specific renderer for entity inlined edition form |
464 """specific renderer for entity inlined edition form |
462 (inline-[creation|edition]) |
465 (inline-[creation|edition]) |