13 one_line_rset, two_lines_rset, one_etype_rset, relation_possible, |
13 one_line_rset, two_lines_rset, one_etype_rset, relation_possible, |
14 nonempty_rset, non_final_entity, |
14 nonempty_rset, non_final_entity, |
15 authenticated_user, match_user_groups, match_search_state, |
15 authenticated_user, match_user_groups, match_search_state, |
16 has_permission, has_add_permission, |
16 has_permission, has_add_permission, |
17 ) |
17 ) |
18 from cubicweb.web import uicfg, controller |
18 from cubicweb.web import uicfg, controller, action |
19 from cubicweb.web.action import Action |
|
20 from cubicweb.web.views import linksearch_select_url, vid_from_rset |
19 from cubicweb.web.views import linksearch_select_url, vid_from_rset |
21 |
20 |
22 |
21 |
23 class has_editable_relation(EntitySelector): |
22 class has_editable_relation(EntitySelector): |
24 """accept if some relations for an entity found in the result set is |
23 """accept if some relations for an entity found in the result set is |
72 return 1 |
71 return 1 |
73 return 0 |
72 return 0 |
74 |
73 |
75 # generic 'main' actions ####################################################### |
74 # generic 'main' actions ####################################################### |
76 |
75 |
77 class SelectAction(Action): |
76 class SelectAction(action.Action): |
78 """base class for link search actions. By default apply on |
77 """base class for link search actions. By default apply on |
79 any size entity result search it the current state is 'linksearch' |
78 any size entity result search it the current state is 'linksearch' |
80 if accept match. |
79 if accept match. |
81 """ |
80 """ |
82 __regid__ = 'select' |
81 __regid__ = 'select' |
83 __select__ = match_search_state('linksearch') & nonempty_rset() & match_searched_etype() |
82 __select__ = (match_search_state('linksearch') & nonempty_rset() |
|
83 & match_searched_etype()) |
84 |
84 |
85 title = _('select') |
85 title = _('select') |
86 category = 'mainactions' |
86 category = 'mainactions' |
87 order = 0 |
87 order = 0 |
88 |
88 |
89 def url(self): |
89 def url(self): |
90 return linksearch_select_url(self._cw, self.cw_rset) |
90 return linksearch_select_url(self._cw, self.cw_rset) |
91 |
91 |
92 |
92 |
93 class CancelSelectAction(Action): |
93 class CancelSelectAction(action.Action): |
94 __regid__ = 'cancel' |
94 __regid__ = 'cancel' |
95 __select__ = match_search_state('linksearch') |
95 __select__ = match_search_state('linksearch') |
96 |
96 |
97 title = _('cancel select') |
97 title = _('cancel select') |
98 category = 'mainactions' |
98 category = 'mainactions' |
102 target, eid, r_type, searched_type = self._cw.search_state[1] |
102 target, eid, r_type, searched_type = self._cw.search_state[1] |
103 return self._cw.build_url(str(eid), |
103 return self._cw.build_url(str(eid), |
104 vid='edition', __mode='normal') |
104 vid='edition', __mode='normal') |
105 |
105 |
106 |
106 |
107 class ViewAction(Action): |
107 class ViewAction(action.Action): |
108 __regid__ = 'view' |
108 __regid__ = 'view' |
109 __select__ = (match_search_state('normal') & |
109 __select__ = (action.Action.__select__ & |
110 match_user_groups('users', 'managers') & |
110 match_user_groups('users', 'managers') & |
111 view_is_not_default_view() & |
111 view_is_not_default_view() & |
112 non_final_entity()) |
112 non_final_entity()) |
113 |
113 |
114 title = _('view') |
114 title = _('view') |
121 params.pop(param, None) |
121 params.pop(param, None) |
122 return self._cw.build_url(self._cw.relative_path(includeparams=False), |
122 return self._cw.build_url(self._cw.relative_path(includeparams=False), |
123 **params) |
123 **params) |
124 |
124 |
125 |
125 |
126 class ModifyAction(Action): |
126 class ModifyAction(action.Action): |
127 __regid__ = 'edit' |
127 __regid__ = 'edit' |
128 __select__ = (match_search_state('normal') & |
128 __select__ = (action.Action.__select__ & one_line_rset() & |
129 one_line_rset() & |
|
130 (has_permission('update') | has_editable_relation('add'))) |
129 (has_permission('update') | has_editable_relation('add'))) |
131 |
130 |
132 title = _('modify') |
131 title = _('modify') |
133 category = 'mainactions' |
132 category = 'mainactions' |
134 order = 10 |
133 order = 10 |
136 def url(self): |
135 def url(self): |
137 entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
136 entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
138 return entity.absolute_url(vid='edition') |
137 return entity.absolute_url(vid='edition') |
139 |
138 |
140 |
139 |
141 class MultipleEditAction(Action): |
140 class MultipleEditAction(action.Action): |
142 __regid__ = 'muledit' # XXX get strange conflicts if id='edit' |
141 __regid__ = 'muledit' # XXX get strange conflicts if id='edit' |
143 __select__ = (match_search_state('normal') & |
142 __select__ = (action.Action.__select__ & two_lines_rset() & |
144 two_lines_rset() & one_etype_rset() & |
143 one_etype_rset() & has_permission('update')) |
145 has_permission('update')) |
|
146 |
144 |
147 title = _('modify') |
145 title = _('modify') |
148 category = 'mainactions' |
146 category = 'mainactions' |
149 order = 10 |
147 order = 10 |
150 |
148 |
152 return self._cw.build_url('view', rql=self.cw_rset.rql, vid='muledit') |
150 return self._cw.build_url('view', rql=self.cw_rset.rql, vid='muledit') |
153 |
151 |
154 |
152 |
155 # generic "more" actions ####################################################### |
153 # generic "more" actions ####################################################### |
156 |
154 |
157 class ManagePermissionsAction(Action): |
155 class ManagePermissionsAction(action.Action): |
158 __regid__ = 'managepermission' |
156 __regid__ = 'managepermission' |
159 __select__ = one_line_rset() & non_final_entity() & match_user_groups('managers') |
157 __select__ = (action.Action.__select__ & one_line_rset() & |
|
158 non_final_entity() & match_user_groups('managers')) |
160 |
159 |
161 title = _('manage permissions') |
160 title = _('manage permissions') |
162 category = 'moreactions' |
161 category = 'moreactions' |
163 order = 15 |
162 order = 15 |
164 |
163 |
188 entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
187 entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
189 return self._cw.build_url(entity.rest_path(), vid='deleteconf') |
188 return self._cw.build_url(entity.rest_path(), vid='deleteconf') |
190 return self._cw.build_url(rql=self.cw_rset.printable_rql(), vid='deleteconf') |
189 return self._cw.build_url(rql=self.cw_rset.printable_rql(), vid='deleteconf') |
191 |
190 |
192 |
191 |
193 class CopyAction(Action): |
192 class CopyAction(action.Action): |
194 __regid__ = 'copy' |
193 __regid__ = 'copy' |
195 __select__ = one_line_rset() & has_permission('add') |
194 __select__ = (action.Action.__select__ & one_line_rset() |
|
195 & has_permission('add')) |
196 |
196 |
197 title = _('copy') |
197 title = _('copy') |
198 category = 'moreactions' |
198 category = 'moreactions' |
199 order = 30 |
199 order = 30 |
200 |
200 |
206 class AddNewAction(MultipleEditAction): |
206 class AddNewAction(MultipleEditAction): |
207 """when we're seeing more than one entity with the same type, propose to |
207 """when we're seeing more than one entity with the same type, propose to |
208 add a new one |
208 add a new one |
209 """ |
209 """ |
210 __regid__ = 'addentity' |
210 __regid__ = 'addentity' |
211 __select__ = (match_search_state('normal') & |
211 __select__ = (action.Action.__select__ & |
212 (addable_etype_empty_rset() |
212 (addable_etype_empty_rset() |
213 | (two_lines_rset() & one_etype_rset & has_add_permission())) |
213 | (two_lines_rset() & one_etype_rset & has_add_permission())) |
214 ) |
214 ) |
215 |
215 |
216 category = 'moreactions' |
216 category = 'moreactions' |
228 |
228 |
229 def url(self): |
229 def url(self): |
230 return self._cw.build_url('add/%s' % self.rsettype) |
230 return self._cw.build_url('add/%s' % self.rsettype) |
231 |
231 |
232 |
232 |
233 class AddRelatedActions(Action): |
233 class AddRelatedActions(action.Action): |
234 """fill 'addrelated' sub-menu of the actions box""" |
234 """fill 'addrelated' sub-menu of the actions box""" |
235 __regid__ = 'addrelated' |
235 __regid__ = 'addrelated' |
236 __select__ = Action.__select__ & one_line_rset() & non_final_entity() |
236 __select__ = Action.__select__ & one_line_rset() & non_final_entity() |
237 |
237 |
238 submenu = _('addrelated') |
238 submenu = _('addrelated') |