[IMP] mail-Chatter: composition form: improved behavior of 'email_mode' and 'formatting'. They now calls onchange methods, that gives default values for dest_partner_ids, subject and so on. Partners are created when toggling into email mode, if not present in the database, based on the email_from of the document.
bzr revid: tde@openerp.com-20120713142333-y7krivwnybxkjl5b
This commit is contained in:
parent
bbf4b854d6
commit
f806af0240
|
@ -21,7 +21,6 @@
|
|||
|
||||
from osv import osv
|
||||
from osv import fields
|
||||
import re
|
||||
|
||||
class res_partner(osv.osv):
|
||||
""" Inherits partner and adds CRM information in the partner form """
|
||||
|
|
|
@ -352,7 +352,14 @@ openerp.mail = function(session) {
|
|||
/**
|
||||
* Toggle the formatting mode. */
|
||||
toggle_formatting_mode: function() {
|
||||
var self = this;
|
||||
this.formatting = ! this.formatting;
|
||||
// calls onchange
|
||||
var call_defer = this.ds_compose.call('onchange_formatting', [[], this.formatting, this.params.res_model, this.params.res_id]).then(
|
||||
function (result) {
|
||||
console.log(result);
|
||||
self.form_view.on_processed_onchange(result, []);
|
||||
});
|
||||
// update context of datasetsearch
|
||||
this.ds_compose.context.formatting = this.formatting;
|
||||
// toggle display
|
||||
|
@ -364,7 +371,14 @@ openerp.mail = function(session) {
|
|||
/**
|
||||
* Toggle the email mode. */
|
||||
toggle_email_mode: function() {
|
||||
var self = this;
|
||||
this.email_mode = ! this.email_mode;
|
||||
// calls onchange
|
||||
var call_defer = this.ds_compose.call('onchange_email_mode', [[], this.email_mode, this.params.res_model, this.params.res_id]).then(
|
||||
function (result) {
|
||||
console.log(result);
|
||||
self.form_view.on_processed_onchange(result, []);
|
||||
});
|
||||
// update context of datasetsearch
|
||||
this.ds_compose.context.email_mode = this.email_mode;
|
||||
// update 'Post' button -> 'Send'
|
||||
|
|
|
@ -141,6 +141,35 @@ class mail_compose_message(osv.TransientModel):
|
|||
})
|
||||
return result
|
||||
|
||||
def onchange_email_mode(self, cr, uid, ids, value, model, res_id, context=None):
|
||||
""" email_mode (values: True or False). This onchange on the email mode
|
||||
allows to have some specific behavior when going in email mode, or
|
||||
when going out of email mode.
|
||||
Basically, dest_partner_ids is reset when going out of email
|
||||
mode.
|
||||
This method can be overridden for models that want to have their
|
||||
specific behavior.
|
||||
Note that currently, this onchange is used in mail.js and called
|
||||
manually on the form instantiated in the Chatter.
|
||||
"""
|
||||
if not value:
|
||||
return {'value': {'dest_partner_ids': []}}
|
||||
return {'value': {}}
|
||||
|
||||
def onchange_formatting(self, cr, uid, ids, value, model, res_id, context=None):
|
||||
""" onchange_formatting (values: True or False). This onchange on the
|
||||
formatting allows to have some specific behavior when going in
|
||||
formatting mode, or when going out of formatting.
|
||||
Basically, subject is reset when going out of formatting mode.
|
||||
This method can be overridden for models that want to have their
|
||||
specific behavior.
|
||||
Note that currently, this onchange is used in mail.js and called
|
||||
manually on the form instantiated in the Chatter.
|
||||
"""
|
||||
if not value:
|
||||
return {'value': {'subject': False}}
|
||||
return {'value': {}}
|
||||
|
||||
def get_message_data(self, cr, uid, message_id, context=None):
|
||||
""" Returns a defaults-like dict with initial values for the composition
|
||||
wizard when replying to the given message (e.g. including the quote
|
||||
|
@ -343,7 +372,7 @@ class mail_compose_message_extended(osv.TransientModel):
|
|||
""" Overrides the default implementation to provide more default field values
|
||||
related to the corresponding CRM case.
|
||||
"""
|
||||
result = super(mail_compose_message_extended, self).get_value(cr, uid, model, res_id, context=context)
|
||||
result = super(mail_compose_message_extended, self).get_value(cr, uid, model, res_id, context=context)
|
||||
model_obj = self.pool.get(model)
|
||||
if getattr(model_obj, '_mail_compose_message', False) and res_id:
|
||||
data = model_obj.browse(cr, uid , res_id, context)
|
||||
|
@ -356,4 +385,48 @@ class mail_compose_message_extended(osv.TransientModel):
|
|||
result['reply_to'] = data.section_id and data.section_id.reply_to or False
|
||||
return result
|
||||
|
||||
def onchange_email_mode(self, cr, uid, ids, value, model, res_id, context=None):
|
||||
""" Overrides the default implementation to provide default values for
|
||||
dest_partner_ids. This method checks that a partner maching the
|
||||
``email_from`` of the record exists. It it does not exist, it
|
||||
creates a new partner. The found or created partner is then added
|
||||
in dest_partner_ids.
|
||||
Partner check/creation valid inly if the value is True, and if
|
||||
the model has the ``_mail_compose_message`` attribute.
|
||||
"""
|
||||
result = super(mail_compose_message_extended, self).onchange_email_mode(cr, uid, ids, value, model, res_id, context=context)
|
||||
model_obj = self.pool.get(model)
|
||||
if not value or not (getattr(model_obj, '_mail_compose_message', False) and res_id):
|
||||
return result
|
||||
data = model_obj.browse(cr, uid , res_id, context=context)
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
partner_ids = partner_obj.search(cr, uid, [('email', '=', data.email_from)], context=context)
|
||||
if partner_ids:
|
||||
partner_id = partner_ids[0]
|
||||
else:
|
||||
partner_id = partner_obj.name_create(cr, uid, data.email_from, context=context)[0]
|
||||
result['value'].update({
|
||||
'dest_partner_ids': [partner_id],
|
||||
'email_cc': tools.ustr(data.email_cc or ''),
|
||||
})
|
||||
if hasattr(data, 'section_id'):
|
||||
result['value']['reply_to'] = data.section_id and data.section_id.reply_to or False
|
||||
return result
|
||||
|
||||
def onchange_formatting(self, cr, uid, ids, value, model, res_id, context=None):
|
||||
""" Overrides the default implementation to provide default values for
|
||||
the subject.
|
||||
Subject re-creation valid only if the value is True, and if the
|
||||
model has the ``_mail_compose_message`` attribute.
|
||||
"""
|
||||
result = super(mail_compose_message_extended, self).onchange_formatting(cr, uid, ids, value, model, res_id, context=context)
|
||||
model_obj = self.pool.get(model)
|
||||
if not value or not (getattr(model_obj, '_mail_compose_message', False) and res_id):
|
||||
return result
|
||||
data = model_obj.browse(cr, uid , res_id, context=context)
|
||||
result['value'].update({
|
||||
'subject': data.name or False,
|
||||
})
|
||||
return result
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue