46 |
46 |
47 @objectify_selector |
47 @objectify_selector |
48 def view_is_not_default_view(cls, req, rset=None, **kwargs): |
48 def view_is_not_default_view(cls, req, rset=None, **kwargs): |
49 # interesting if it propose another view than the current one |
49 # interesting if it propose another view than the current one |
50 vid = req.form.get('vid') |
50 vid = req.form.get('vid') |
51 if vid and vid != vid_from_rset(req, rset, cls.schema): |
51 if vid and vid != vid_from_rset(req, rset, req.vreg.schema): |
52 return 1 |
52 return 1 |
53 return 0 |
53 return 0 |
54 |
54 |
55 @objectify_selector |
55 @objectify_selector |
56 def addable_etype_empty_rset(cls, req, rset=None, **kwargs): |
56 def addable_etype_empty_rset(cls, req, rset=None, **kwargs): |
59 if len(rqlst.children) > 1: |
59 if len(rqlst.children) > 1: |
60 return 0 |
60 return 0 |
61 select = rqlst.children[0] |
61 select = rqlst.children[0] |
62 if len(select.defined_vars) == 1 and len(select.solutions) == 1: |
62 if len(select.defined_vars) == 1 and len(select.solutions) == 1: |
63 rset._searched_etype = select.solutions[0].itervalues().next() |
63 rset._searched_etype = select.solutions[0].itervalues().next() |
64 eschema = cls.schema.eschema(rset._searched_etype) |
64 eschema = req.schema.eschema(rset._searched_etype) |
65 if not (eschema.is_final() or eschema.is_subobject(strict=True)) \ |
65 if not (eschema.is_final() or eschema.is_subobject(strict=True)) \ |
66 and eschema.has_perm(req, 'add'): |
66 and eschema.has_perm(req, 'add'): |
67 return 1 |
67 return 1 |
68 return 0 |
68 return 0 |
69 |
69 |
92 title = _('cancel select') |
92 title = _('cancel select') |
93 category = 'mainactions' |
93 category = 'mainactions' |
94 order = 10 |
94 order = 10 |
95 |
95 |
96 def url(self): |
96 def url(self): |
97 target, eid, r_type, searched_type = self.req.search_state[1] |
97 target, eid, r_type, searched_type = self._cw.search_state[1] |
98 return self.build_url(str(eid), |
98 return self._cw.build_url(str(eid), |
99 vid='edition', __mode='normal') |
99 vid='edition', __mode='normal') |
100 |
100 |
101 |
101 |
102 class ViewAction(Action): |
102 class ViewAction(Action): |
103 __regid__ = 'view' |
103 __regid__ = 'view' |
104 __select__ = (match_search_state('normal') & |
104 __select__ = (match_search_state('normal') & |
109 title = _('view') |
109 title = _('view') |
110 category = 'mainactions' |
110 category = 'mainactions' |
111 order = 0 |
111 order = 0 |
112 |
112 |
113 def url(self): |
113 def url(self): |
114 params = self.req.form.copy() |
114 params = self._cw.form.copy() |
115 for param in ('vid', '__message') + controller.NAV_FORM_PARAMETERS: |
115 for param in ('vid', '__message') + controller.NAV_FORM_PARAMETERS: |
116 params.pop(param, None) |
116 params.pop(param, None) |
117 return self.build_url(self.req.relative_path(includeparams=False), |
117 return self._cw.build_url(self._cw.relative_path(includeparams=False), |
118 **params) |
118 **params) |
119 |
119 |
120 |
120 |
121 class ModifyAction(Action): |
121 class ModifyAction(Action): |
122 __regid__ = 'edit' |
122 __regid__ = 'edit' |
123 __select__ = (match_search_state('normal') & |
123 __select__ = (match_search_state('normal') & |
177 title = _('delete') |
177 title = _('delete') |
178 category = 'moreactions' |
178 category = 'moreactions' |
179 order = 20 |
179 order = 20 |
180 |
180 |
181 def url(self): |
181 def url(self): |
182 if len(self.rset) == 1: |
182 if len(self.cw_rset) == 1: |
183 entity = self.rset.get_entity(self.row or 0, self.col or 0) |
183 entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
184 return self.build_url(entity.rest_path(), vid='deleteconf') |
184 return self._cw.build_url(entity.rest_path(), vid='deleteconf') |
185 return self.build_url(rql=self.rset.printable_rql(), vid='deleteconf') |
185 return self._cw.build_url(rql=self.cw_rset.printable_rql(), vid='deleteconf') |
186 |
186 |
187 |
187 |
188 class CopyAction(Action): |
188 class CopyAction(Action): |
189 __regid__ = 'copy' |
189 __regid__ = 'copy' |
190 __select__ = one_line_rset() & has_permission('add') |
190 __select__ = one_line_rset() & has_permission('add') |
211 category = 'moreactions' |
211 category = 'moreactions' |
212 order = 40 |
212 order = 40 |
213 |
213 |
214 @property |
214 @property |
215 def rsettype(self): |
215 def rsettype(self): |
216 if self.rset: |
216 if self.cw_rset: |
217 return self.rset.description[0][0] |
217 return self.cw_rset.description[0][0] |
218 return self.rset._searched_etype |
218 return self.cw_rset._searched_etype |
219 |
219 |
220 @property |
220 @property |
221 def title(self): |
221 def title(self): |
222 return self.req.__('add a %s' % self.rsettype) # generated msgid |
222 return self._cw.__('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._cw.build_url('add/%s' % self.rsettype) |
226 |
226 |
227 |
227 |
228 class AddRelatedActions(Action): |
228 class AddRelatedActions(Action): |
229 """fill 'addrelated' sub-menu of the actions box""" |
229 """fill 'addrelated' sub-menu of the actions box""" |
230 __regid__ = 'addrelated' |
230 __regid__ = 'addrelated' |
234 order = 20 |
234 order = 20 |
235 |
235 |
236 def fill_menu(self, box, menu): |
236 def fill_menu(self, box, menu): |
237 # when there is only one item in the sub-menu, replace the sub-menu by |
237 # when there is only one item in the sub-menu, replace the sub-menu by |
238 # item's title prefixed by 'add' |
238 # item's title prefixed by 'add' |
239 menu.label_prefix = self.req._('add') |
239 menu.label_prefix = self._cw._('add') |
240 super(AddRelatedActions, self).fill_menu(box, menu) |
240 super(AddRelatedActions, self).fill_menu(box, menu) |
241 |
241 |
242 def actual_actions(self): |
242 def actual_actions(self): |
243 entity = self.rset.get_entity(self.row or 0, self.col or 0) |
243 entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
244 eschema = entity.e_schema |
244 eschema = entity.e_schema |
245 for rschema, teschema, x in self.add_related_schemas(entity): |
245 for rschema, teschema, x in self.add_related_schemas(entity): |
246 if x == 'subject': |
246 if x == 'subject': |
247 label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) |
247 label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) |
248 url = self.linkto_url(entity, rschema, teschema, 'object') |
248 url = self.linkto_url(entity, rschema, teschema, 'object') |
249 else: |
249 else: |
250 label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) |
250 label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) |
251 url = self.linkto_url(entity, rschema, teschema, 'subject') |
251 url = self.linkto_url(entity, rschema, teschema, 'subject') |
252 yield self.build_action(self.req._(label), url) |
252 yield self.build_action(self._cw._(label), url) |
253 |
253 |
254 def add_related_schemas(self, entity): |
254 def add_related_schemas(self, entity): |
255 """this is actually used ui method to generate 'addrelated' actions from |
255 """this is actually used ui method to generate 'addrelated' actions from |
256 the schema. |
256 the schema. |
257 |
257 |
258 If you don't want any auto-generated actions, you should overrides this |
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 |
259 method to return an empty list. If you only want some, you can configure |
260 them by using uicfg.actionbox_appearsin_addmenu |
260 them by using uicfg.actionbox_appearsin_addmenu |
261 """ |
261 """ |
262 appearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
262 appearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
263 req = self.req |
263 req = self._cw |
264 eschema = entity.e_schema |
264 eschema = entity.e_schema |
265 for role, rschemas in (('subject', eschema.subject_relations()), |
265 for role, rschemas in (('subject', eschema.subject_relations()), |
266 ('object', eschema.object_relations())): |
266 ('object', eschema.object_relations())): |
267 for rschema in rschemas: |
267 for rschema in rschemas: |
268 if rschema.is_final(): |
268 if rschema.is_final(): |
282 continue |
282 continue |
283 if teschema.has_local_role('add') or teschema.has_perm(req, 'add'): |
283 if teschema.has_local_role('add') or teschema.has_perm(req, 'add'): |
284 yield rschema, teschema, role |
284 yield rschema, teschema, role |
285 |
285 |
286 def linkto_url(self, entity, rtype, etype, target): |
286 def linkto_url(self, entity, rtype, etype, target): |
287 return self.build_url('add/%s' % etype, |
287 return self._cw.build_url('add/%s' % etype, |
288 __linkto='%s:%s:%s' % (rtype, entity.eid, target), |
288 __linkto='%s:%s:%s' % (rtype, entity.eid, target), |
289 __redirectpath=entity.rest_path(), # should not be url quoted! |
289 __redirectpath=entity.rest_path(), # should not be url quoted! |
290 __redirectvid=self.req.form.get('vid', '')) |
290 __redirectvid=self._cw.form.get('vid', '')) |
291 |
291 |
292 |
292 |
293 # logged user actions ######################################################### |
293 # logged user actions ######################################################### |
294 |
294 |
295 class UserPreferencesAction(Action): |
295 class UserPreferencesAction(Action): |