[IMP] email_template: relooked a bit the mail.compose.message wizard, use_template by default, on bottom-right choose the template; rendre only when use_template and template_id set.

bzr revid: tde@openerp.com-20121113113625-fg3jp3047gnrx2wr
This commit is contained in:
Thibault Delavallée 2012-11-13 12:36:25 +01:00
parent ea4eb01ac1
commit a370d1c059
2 changed files with 23 additions and 18 deletions

View File

@ -52,8 +52,9 @@ class mail_compose_message(osv.TransientModel):
context = {}
result = super(mail_compose_message, self).default_get(cr, uid, fields, context=context)
result['template_id'] = context.get('default_template_id', context.get('mail.compose.template_id', False))
# pre-render the template if any
if result.get('use_template'):
if result.get('use_template') and result.get('template_id'):
onchange_res = self.onchange_use_template(cr, uid, [], result.get('use_template'), result.get('template_id'),
result.get('composition_mode'), result.get('model'), result.get('res_id'), context=context)
result.update(onchange_res['value'])
@ -65,6 +66,10 @@ class mail_compose_message(osv.TransientModel):
'template_id': fields.selection(_get_templates, 'Template', size=-1),
}
_defaults = {
'use_template': True,
}
def onchange_template_id(self, cr, uid, ids, use_template, template_id, composition_mode, model, res_id, context=None):
""" - use_template not set: return default_get
- use_template set in mass_mailing: we cannot render, so return the template values
@ -154,7 +159,7 @@ class mail_compose_message(osv.TransientModel):
# transform email_to, email_cc into partner_ids
values['partner_ids'] = []
mails = tools.email_split( values.pop('email_to', '') + ' ' + values.pop('email_cc', '') )
mails = tools.email_split(values.pop('email_to', '') + ' ' + values.pop('email_cc', ''))
for mail in mails:
partner_id = self.pool.get('res.partner').find_or_create(cr, uid, mail, context=context)
values['partner_ids'].append(partner_id)

View File

@ -8,23 +8,23 @@
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//form/group" position="after">
<group attrs="{'invisible':[('use_template','=',False)]}">
<field name="use_template" invisible="1"
on_change="onchange_use_template(use_template, template_id, composition_mode, model, res_id, context)"/>
<field name="template_id"
on_change="onchange_template_id(use_template, template_id, composition_mode, model, res_id, context)"/>
</group>
<xpath expr="//field[@name='content_subtype']" position="after">
<field name="use_template" invisible="1"
on_change="onchange_use_template(use_template, template_id, composition_mode, model, res_id, context)"/>
</xpath>
<xpath expr="//form/footer/button" position="after">
<button icon="/email_template/static/src/img/email_template.png"
type="object" name="toggle_template" string=""
help="Use a message template"
attrs="{'invisible':[('content_subtype','!=','html')]}"/>
<button icon="/email_template/static/src/img/email_template_save.png"
type="object" name="save_as_template" string=""
help="Save as a new template"
attrs="{'invisible':[('content_subtype','!=','html')]}"/>
<xpath expr="//footer" position="inside">
<group class="oe_right" col="1">
<div>Use template
<field name="template_id" attrs="{'invisible':[('use_template','=',False)]}"
nolabel="1"
on_change="onchange_template_id(use_template, template_id, composition_mode, model, res_id, context)"/>
</div>
or
<button icon="/email_template/static/src/img/email_template_save.png"
type="object" name="save_as_template" string="Save as new template" class="oe_link"
help="Save as a new template"
attrs="{'invisible':[('content_subtype','!=','html')]}"/>
</group>
</xpath>
</data>
</field>