390 # XXX both (add, delete) |
390 # XXX both (add, delete) |
391 return [(rschema, x) for rschema, _, x in entity.relations_by_category(('primary', 'secondary'), 'add') |
391 return [(rschema, x) for rschema, _, x in entity.relations_by_category(('primary', 'secondary'), 'add') |
392 if rschema != 'eid'] |
392 if rschema != 'eid'] |
393 |
393 |
394 def relations_form(self, entity, kwargs): |
394 def relations_form(self, entity, kwargs): |
|
395 pendings = list(self.restore_pending_inserts(entity)) |
|
396 relations_table = list(self.relations_table(entity)) |
|
397 srels_by_cat = entity.srelations_by_category(('generic', 'metadata'), 'add') |
|
398 if not pendings and not relations_table and not srels_by_cat: |
|
399 return u'' |
395 req = self.req |
400 req = self.req |
396 _ = self.req._ |
401 _ = self.req._ |
397 label = u'%s :' % _('This %s' % entity.e_schema).capitalize() |
402 label = u'%s :' % _('This %s' % entity.e_schema).capitalize() |
398 eid = entity.eid |
403 eid = entity.eid |
399 html = [] |
404 html = [] |
400 pendings = list(self.restore_pending_inserts(entity)) |
|
401 w = html.append |
405 w = html.append |
402 w(u'<fieldset class="subentity">') |
406 w(u'<fieldset class="subentity">') |
403 w(u'<legend class="iformTitle">%s</legend>' % label) |
407 w(u'<legend class="iformTitle">%s</legend>' % label) |
404 w(u'<table id="relatedEntities">') |
408 w(u'<table id="relatedEntities">') |
405 for row in self.relations_table(entity): |
409 for row in relations_table: |
|
410 # already linked entities |
406 if row[2]: |
411 if row[2]: |
407 w(u'<tr><th class="labelCol">%s</th>' % row[0].display_name(req, row[1])) |
412 w(u'<tr><th class="labelCol">%s</th>' % row[0].display_name(req, row[1])) |
408 w(u'<td>') |
413 w(u'<td>') |
409 w(u'<ul>') |
414 w(u'<ul>') |
410 for viewparams in row[2]: |
415 for viewparams in row[2]: |
417 w(u'</tr>') |
422 w(u'</tr>') |
418 if not pendings: |
423 if not pendings: |
419 w(u'<tr><th> </th><td> </td></tr>') |
424 w(u'<tr><th> </th><td> </td></tr>') |
420 else: |
425 else: |
421 for row in pendings: |
426 for row in pendings: |
|
427 # soon to be linked to entities |
422 w(u'<tr id="tr%s">' % row[1]) |
428 w(u'<tr id="tr%s">' % row[1]) |
423 w(u'<th>%s</th>' % row[3]) |
429 w(u'<th>%s</th>' % row[3]) |
424 w(u'<td>') |
430 w(u'<td>') |
425 w(u'<a class="handle" title="%s" href="%s">[x]</a>' % |
431 w(u'<a class="handle" title="%s" href="%s">[x]</a>' % |
426 (_('cancel this insert'), row[2])) |
432 (_('cancel this insert'), row[2])) |
432 w(u'<th class="labelCol">') |
438 w(u'<th class="labelCol">') |
433 w(u'<span>%s</span>' % _('add relation')) |
439 w(u'<span>%s</span>' % _('add relation')) |
434 w(u'<select id="relationSelector_%s" tabindex="%s" onchange="javascript:showMatchingSelect(this.options[this.selectedIndex].value,%s);">' |
440 w(u'<select id="relationSelector_%s" tabindex="%s" onchange="javascript:showMatchingSelect(this.options[this.selectedIndex].value,%s);">' |
435 % (eid, req.next_tabindex(), html_escape(dumps(eid)))) |
441 % (eid, req.next_tabindex(), html_escape(dumps(eid)))) |
436 w(u'<option value="">%s</option>' % _('select a relation')) |
442 w(u'<option value="">%s</option>' % _('select a relation')) |
437 for i18nrtype, rschema, target in entity.srelations_by_category(('generic', 'metadata'), 'add'): |
443 for i18nrtype, rschema, target in srels_by_cat: |
|
444 # more entities to link to |
438 w(u'<option value="%s_%s">%s</option>' % (rschema, target, i18nrtype)) |
445 w(u'<option value="%s_%s">%s</option>' % (rschema, target, i18nrtype)) |
439 w(u'</select>') |
446 w(u'</select>') |
440 w(u'</th>') |
447 w(u'</th>') |
441 w(u'<td id="unrelatedDivs_%s"></td>' % eid) |
448 w(u'<td id="unrelatedDivs_%s"></td>' % eid) |
442 w(u'</tr>') |
449 w(u'</tr>') |