29 title = _('send email') |
29 title = _('send email') |
30 category = 'mainactions' |
30 category = 'mainactions' |
31 |
31 |
32 def url(self): |
32 def url(self): |
33 params = {'vid': 'massmailing', '__force_display': 1} |
33 params = {'vid': 'massmailing', '__force_display': 1} |
34 if self.req.form.has_key('rql'): |
34 if self._cw.form.has_key('rql'): |
35 params['rql'] = self.req.form['rql'] |
35 params['rql'] = self._cw.form['rql'] |
36 return self.build_url(self.req.relative_path(includeparams=False), |
36 return self.build_url(self._cw.relative_path(includeparams=False), |
37 **params) |
37 **params) |
38 |
38 |
39 |
39 |
40 class MassMailingForm(forms.FieldsForm): |
40 class MassMailingForm(forms.FieldsForm): |
41 __regid__ = 'massmailing' |
41 __regid__ = 'massmailing' |
52 stdmsgs.BUTTON_CANCEL, 'CANCEL_EMAIL_ICON')] |
52 stdmsgs.BUTTON_CANCEL, 'CANCEL_EMAIL_ICON')] |
53 form_renderer_id = id |
53 form_renderer_id = id |
54 |
54 |
55 def form_field_vocabulary(self, field): |
55 def form_field_vocabulary(self, field): |
56 if field.name == 'recipient': |
56 if field.name == 'recipient': |
57 vocab = [(entity.get_email(), entity.eid) for entity in self.rset.entities()] |
57 vocab = [(entity.get_email(), entity.eid) for entity in self.cw_rset.entities()] |
58 return [(label, value) for label, value in vocab if label] |
58 return [(label, value) for label, value in vocab if label] |
59 return super(MassMailingForm, self).form_field_vocabulary(field) |
59 return super(MassMailingForm, self).form_field_vocabulary(field) |
60 |
60 |
61 def form_field_value(self, field, values): |
61 def form_field_value(self, field, values): |
62 if field.name == 'recipient': |
62 if field.name == 'recipient': |
63 return [entity.eid for entity in self.rset.entities() if entity.get_email()] |
63 return [entity.eid for entity in self.cw_rset.entities() if entity.get_email()] |
64 elif field.name == 'mailbody': |
64 elif field.name == 'mailbody': |
65 field.widget.attrs['cubicweb:variables'] = ','.join(self.get_allowed_substitutions()) |
65 field.widget.attrs['cubicweb:variables'] = ','.join(self.get_allowed_substitutions()) |
66 return super(MassMailingForm, self).form_field_value(field, values) |
66 return super(MassMailingForm, self).form_field_value(field, values) |
67 |
67 |
68 def get_allowed_substitutions(self): |
68 def get_allowed_substitutions(self): |
69 attrs = [] |
69 attrs = [] |
70 for coltype in self.rset.column_types(0): |
70 for coltype in self.cw_rset.column_types(0): |
71 eclass = self.vreg['etypes'].etype_class(coltype) |
71 eclass = self._cw.vreg['etypes'].etype_class(coltype) |
72 attrs.append(eclass.allowed_massmail_keys()) |
72 attrs.append(eclass.allowed_massmail_keys()) |
73 return sorted(reduce(operator.and_, attrs)) |
73 return sorted(reduce(operator.and_, attrs)) |
74 |
74 |
75 def build_substitutions_help(self): |
75 def build_substitutions_help(self): |
76 insertLink = u'<a href="javascript: insertText(\'%%(%s)s\', \'emailarea\');">%%(%s)s</a>' |
76 insertLink = u'<a href="javascript: insertText(\'%%(%s)s\', \'emailarea\');">%%(%s)s</a>' |
77 substs = (u'<div class="substitution">%s</div>' % (insertLink % (subst, subst)) |
77 substs = (u'<div class="substitution">%s</div>' % (insertLink % (subst, subst)) |
78 for subst in self.get_allowed_substitutions()) |
78 for subst in self.get_allowed_substitutions()) |
79 helpmsg = self.req._('You can use any of the following substitutions in your text') |
79 helpmsg = self._cw._('You can use any of the following substitutions in your text') |
80 return u'<div id="substitutions"><span>%s</span>%s</div>' % ( |
80 return u'<div id="substitutions"><span>%s</span>%s</div>' % ( |
81 helpmsg, u'\n'.join(substs)) |
81 helpmsg, u'\n'.join(substs)) |
82 |
82 |
83 |
83 |
84 class MassMailingFormRenderer(formrenderers.FormRenderer): |
84 class MassMailingFormRenderer(formrenderers.FormRenderer): |
120 class MassMailingFormView(FormViewMixIn, EntityView): |
120 class MassMailingFormView(FormViewMixIn, EntityView): |
121 __regid__ = 'massmailing' |
121 __regid__ = 'massmailing' |
122 __select__ = implements(IEmailable) & match_user_groups('managers', 'users') |
122 __select__ = implements(IEmailable) & match_user_groups('managers', 'users') |
123 |
123 |
124 def call(self): |
124 def call(self): |
125 req = self.req |
125 req = self._cw |
126 req.add_js('cubicweb.widgets.js', 'cubicweb.massmailing.js') |
126 req.add_js('cubicweb.widgets.js', 'cubicweb.massmailing.js') |
127 req.add_css('cubicweb.mailform.css') |
127 req.add_css('cubicweb.mailform.css') |
128 from_addr = '%s <%s>' % (req.user.dc_title(), req.user.get_email()) |
128 from_addr = '%s <%s>' % (req.user.dc_title(), req.user.get_email()) |
129 form = self.vreg['forms'].select('massmailing', self.req, rset=self.rset, |
129 form = self._cw.vreg['forms'].select('massmailing', self._cw, rset=self.cw_rset, |
130 action='sendmail', domid='sendmail') |
130 action='sendmail', domid='sendmail') |
131 self.w(form.form_render(sender=from_addr)) |
131 self.w(form.form_render(sender=from_addr)) |