221 def title(self): |
221 def title(self): |
222 return self.req.__('add a %s' % self.rsettype) # generated msgid |
222 return self.req.__('add a %s' % self.rsettype) # generated msgid |
223 |
223 |
224 def url(self): |
224 def url(self): |
225 return self.build_url('add/%s' % self.rsettype) |
225 return self.build_url('add/%s' % self.rsettype) |
|
226 |
|
227 |
|
228 class AddRelatedActions(Action): |
|
229 """fill 'addrelated' sub-menu of the actions box""" |
|
230 id = 'addrelated' |
|
231 __select__ = Action.__select__ & one_line_rset() & non_final_entity() |
|
232 |
|
233 submenu = _('addrelated') |
|
234 order = 20 |
|
235 |
|
236 def fill_menu(self, box, menu): |
|
237 # when there is only one item in the sub-menu, replace the sub-menu by |
|
238 # item's title prefixed by 'add' |
|
239 menu.label_prefix = self.req._('add') |
|
240 super(AddRelatedActions, self).fill_menu(box, menu) |
|
241 |
|
242 def actual_actions(self): |
|
243 entity = self.rset.get_entity(self.row or 0, self.col or 0) |
|
244 eschema = entity.e_schema |
|
245 for rschema, teschema, x in self.add_related_schemas(entity): |
|
246 if x == 'subject': |
|
247 label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) |
|
248 url = self.linkto_url(entity, rschema, teschema, 'object') |
|
249 else: |
|
250 label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) |
|
251 url = self.linkto_url(entity, rschema, teschema, 'subject') |
|
252 yield self.build_action(self.req._(label), url) |
|
253 |
|
254 def add_related_schemas(self, entity): |
|
255 """this is actually used ui method to generate 'addrelated' actions from |
|
256 the schema. |
|
257 |
|
258 If you don't want any auto-generated actions, you should overrides this |
|
259 method to return an empty list. If you only want some, you can configure |
|
260 them by using uicfg.actionbox_appearsin_addmenu |
|
261 """ |
|
262 appearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
|
263 req = self.req |
|
264 eschema = entity.e_schema |
|
265 for role, rschemas in (('subject', eschema.subject_relations()), |
|
266 ('object', eschema.object_relations())): |
|
267 for rschema in rschemas: |
|
268 if rschema.is_final(): |
|
269 continue |
|
270 # check the relation can be added as well |
|
271 # XXX consider autoform_permissions_overrides? |
|
272 if role == 'subject'and not rschema.has_perm(req, 'add', |
|
273 fromeid=entity.eid): |
|
274 continue |
|
275 if role == 'object'and not rschema.has_perm(req, 'add', |
|
276 toeid=entity.eid): |
|
277 continue |
|
278 # check the target types can be added as well |
|
279 for teschema in rschema.targets(eschema, role): |
|
280 if not appearsin_addmenu.etype_get(eschema, rschema, |
|
281 role, teschema): |
|
282 continue |
|
283 if teschema.has_local_role('add') or teschema.has_perm(req, 'add'): |
|
284 yield rschema, teschema, role |
|
285 |
|
286 def linkto_url(self, entity, rtype, etype, target): |
|
287 return self.build_url(vid='creation', etype=etype, |
|
288 __linkto='%s:%s:%s' % (rtype, entity.eid, target), |
|
289 __redirectpath=entity.rest_path(), # should not be url quoted! |
|
290 __redirectvid=self.req.form.get('vid', '')) |
226 |
291 |
227 |
292 |
228 # logged user actions ######################################################### |
293 # logged user actions ######################################################### |
229 |
294 |
230 class UserPreferencesAction(Action): |
295 class UserPreferencesAction(Action): |