[IMP] mail: refactored a bit the code in message_post_user_api, as well as overrides in res_partner and res_users, to use kwargs. Updated mail.js to use kwargs. Updated mail.xml and css to tweak the display.

bzr revid: tde@openerp.com-20121221144014-otg03akq4c9grjmz
This commit is contained in:
Thibault Delavallée 2012-12-21 15:40:14 +01:00
parent 63d993e45d
commit f922d9ea1f
6 changed files with 60 additions and 75 deletions

View File

@ -886,8 +886,8 @@ class mail_thread(osv.AbstractModel):
return mail_message.create(cr, uid, values, context=context)
def message_post_user_api(self, cr, uid, thread_id, body='', subject=False, parent_id=False,
attachment_ids=None, extra_email=[],
def message_post_user_api(self, cr, uid, thread_id, body='', subject=False,
parent_id=False, attachment_ids=None, extra_emails=None,
context=None, content_subtype='plaintext', **kwargs):
""" Wrapper on message_post, used for user input :
- mail gateway
@ -902,40 +902,41 @@ class mail_thread(osv.AbstractModel):
to the related document. Should only be set by Chatter.
- extra_email: [ 'Fabien <fpi@openerp.com>', 'al@openerp.com' ]
"""
partner_obj = self.pool.get('res.partner')
mail_message_obj = self.pool.get('mail.message')
ir_attachment = self.pool.get('ir.attachment')
extra_emails = extra_emails or []
# 1. Pre-processing: body, partner_ids, type and subtype
if content_subtype == 'plaintext':
body = tools.plaintext2html(body)
new_partner_ids = set([])
for partner in extra_email:
part_ids = self.pool.get('res.partner').search(cr, uid, [('email', '=', partner)], context=context)
# create a new partner if not exists
if not part_ids:
part_ids = [self.pool.get('res.partner').name_create(cr, uid, partner, context=dict())[0]]
# 1.A.1: pre-process partners and incoming extra_emails
partner_ids = set([])
for email in extra_emails:
partner_id = partner_obj.find_or_create(cr, uid, email, context=context)
# link mail with this from mail to the new partner id
message_ids = mail_message.search(cr, uid, [('email_from', '=', partner)], context=context)
if part_ids and message_ids:
mail_message.write(cr, uid, message_ids, {'email_from': None, 'author_id': part_ids[0]}, context=context)
new_partner_ids |= set(part_ids)
if new_partner_ids:
self.message_subscribe(cr, uid, [thread_id], list(new_partner_ids), context=context)
partner_ids = set(kwargs.pop('partner_ids', [])) | set(new_partner_ids)
partner_msg_ids = mail_message_obj.search(cr, SUPERUSER_ID, [('email_from', '=', email), ('author_id', '=', False)], context=context)
if partner_id and partner_msg_ids:
mail_message_obj.write(cr, SUPERUSER_ID, partner_msg_ids, {'email_from': None, 'author_id': partner_id}, context=context)
partner_ids.add((4, partner_id))
if partner_ids:
self.message_subscribe(cr, uid, [thread_id], list(partner_ids), context=context)
# 1.A.2: add recipients of parent message
if parent_id:
parent_message = self.pool.get('mail.message').browse(cr, uid, parent_id, context=context)
parent_message = mail_message_obj.browse(cr, uid, parent_id, context=context)
partner_ids |= set([(4, partner.id) for partner in parent_message.partner_ids])
# TDE FIXME HACK: mail.thread -> private message
if self._name == 'mail.thread' and parent_message.author_id.id:
partner_ids.add((4, parent_message.author_id.id))
# 1.A.3: add specified recipients
partner_ids |= set(kwargs.pop('partner_ids', []))
# 1.B: handle body, message_type and message_subtype
if content_subtype == 'plaintext':
body = tools.plaintext2html(body)
message_type = kwargs.pop('type', 'comment')
message_subtype = kwargs.pop('subtype', 'mail.mt_comment')
# 2. Pre-processing: free attachments linked to the model
# 2. Pre-processing: attachments
# HACK TDE FIXME: Chatter: attachments linked to the document (not done JS-side), load the message
if attachment_ids:
# TDE FIXME (?): when posting a private message, we use mail.thread as a model
@ -955,10 +956,10 @@ class mail_thread(osv.AbstractModel):
attachment_ids = []
# 3. Post message
new_message_id = self.message_post(cr, uid, thread_id=thread_id, body=body, subject=subject, type=message_type,
subtype=message_subtype, parent_id=parent_id, attachment_ids=[(4, id) for id in attachment_ids],
context=context, partner_ids=partner_ids, **kwargs)
new_message_id = self.message_post(cr, uid, thread_id=thread_id, body=body, subject=subject,
type=message_type, subtype=message_subtype, parent_id=parent_id,
attachment_ids=[(4, id) for id in attachment_ids], partner_ids=partner_ids,
context=context, **kwargs)
return new_message_id
#------------------------------------------------------

View File

@ -42,8 +42,7 @@ class res_partner_mail(osv.Model):
'notification_email_send': lambda *args: 'comment'
}
def message_post(self, cr, uid, thread_id, body='', subject=None, type='notification',
subtype=None, parent_id=False, attachments=None, context=None, **kwargs):
def message_post(self, cr, uid, thread_id, **kwargs):
""" Override related to res.partner. In case of email message, set it as
private:
- add the target partner in the message partner_ids
@ -58,7 +57,6 @@ class res_partner_mail(osv.Model):
partner_ids.append((4, thread_id))
kwargs['partner_ids'] = partner_ids
thread_id = False
return super(res_partner_mail, self).message_post(cr, uid, thread_id, body=body, subject=subject,
type=type, subtype=subtype, parent_id=parent_id, attachments=attachments, context=context, **kwargs)
return super(res_partner_mail, self).message_post(cr, uid, thread_id, **kwargs)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -116,36 +116,28 @@ class res_users(osv.Model):
alias_pool.unlink(cr, uid, alias_ids, context=context)
return res
def message_post_user_api(self, cr, uid, thread_id, body='', subject=False, parent_id=False,
attachment_ids=None, extra_email=[],
context=None, content_subtype='plaintext', **kwargs):
""" Redirect the posting of message on res.users to the related partner.
This is done because when giving the context of Chatter on the
various mailboxes, we do not have access to the current partner_id.
We therefore post on the user and redirect on its partner. """
def _message_post_get_pid(self, cr, uid, thread_id, context=None):
assert thread_id, "res.users does not support posting global messages"
if context and 'thread_model' in context:
context['thread_model'] = 'res.partner'
if isinstance(thread_id, (list, tuple)):
thread_id = thread_id[0]
partner_id = self.browse(cr, uid, thread_id).partner_id.id
return self.pool.get('res.partner').message_post_user_api(cr, uid,
partner_id, body=body, subject=subject, parent_id=parent_id,
attachment_ids=attachment_ids, extra_email=extra_email,
context=context, content_subtype=content_subtype, **kwargs)
return self.browse(cr, uid, thread_id).partner_id.id
def message_post_user_api(self, cr, uid, thread_id, body='', context=None, **kwargs):
""" Redirect the posting of message on res.users to the related partner.
This is done because when giving the context of Chatter on the
various mailboxes, we do not have access to the current partner_id.
We therefore post on the user and redirect on its partner. """
partner_id = self._message_post_get_pid(cr, uid, thread_id, context=context)
return self.pool.get('res.partner').message_post_user_api(cr, uid, partner_id, **kwargs)
def message_post(self, cr, uid, thread_id, context=None, **kwargs):
""" Redirect the posting of message on res.users to the related partner.
This is done because when giving the context of Chatter on the
various mailboxes, we do not have access to the current partner_id.
We therefore post on the user and redirect on its partner. """
assert thread_id, "res.users does not support posting global messages"
if context and 'thread_model' in context:
context['thread_model'] = 'res.partner'
if isinstance(thread_id, (list, tuple)):
thread_id = thread_id[0]
partner_id = self.browse(cr, uid, thread_id).partner_id.id
partner_id = self._message_post_get_pid(cr, uid, thread_id, context=context)
return self.pool.get('res.partner').message_post(cr, uid, partner_id, context=context, **kwargs)
def message_update(self, cr, uid, ids, msg_dict, update_vals=None, context=None):

View File

@ -256,6 +256,7 @@
.openerp .oe_mail .oe_msg_composer .oe_emails_from{
font-size: 12px;
margin-left: 20px;
margin-bottom: 2px;
}
.openerp .oe_mail .oe_msg_composer .oe_emails_from label{
vertical-align: middle;

View File

@ -609,17 +609,14 @@ openerp.mail = function (session) {
/*do post a message and fetch the message*/
do_send_message_post: function () {
var self = this;
//session.web.blockUI();
var values = [
this.context.default_res_id, //thread_id
this.$('textarea').val(), //body
false, //subject
this.context.default_parent_id, //parent_id
_.map(this.attachment_ids, function (file) {return file.id;}), //attachment_ids
_.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), //extra_email
this.parent_thread.context, // context
];
this.parent_thread.ds_thread.call('message_post_user_api', values).done(function (message_id) {
this.parent_thread.ds_thread._model.call('message_post_user_api', [this.context.default_res_id], {
'body': this.$('textarea').val(),
'subject': false,
'parent_id': this.context.default_parent_id,
'attachment_ids': _.map(this.attachment_ids, function (file) {return file.id;}),
'extra_emails': _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}),
'context': this.parent_thread.context,
}).done(function (message_id) {
var thread = self.parent_thread;
var root = thread == self.options.root_thread;
if (self.options.display_indented_thread < self.thread_level && thread.parent_message) {
@ -632,7 +629,6 @@ openerp.mail = function (session) {
thread.insert_message( message, root ? undefined : self.$el, root );
});
self.on_cancel();
//session.web.unblockUI();
});
},
@ -1060,7 +1056,7 @@ openerp.mail = function (session) {
this.author_id = datasets.author_id || false;
this.thread_level = (datasets.thread_level+1) || 0;
this.partner_ids = datasets.partner_ids || [];
if (datasets.author_id)
if (datasets.author_id && datasets.author_id[0])
this.partner_ids.push(datasets.author_id);
this.messages = [];

View File

@ -114,26 +114,23 @@
</span>
</t>
<t t-if="!widget.is_private and (widget.partner_ids.length or (widget.author_id and widget.author_id[0]))"> and </t>
<t t-if="widget.author_id and widget.author_id[0]">
<a t-if="widget.options.show_link and widget.author_id[0]" t-attf-href="#model=res.partner&amp;id=#{widget.author_id[0]}"><t t-raw="widget.author_id[1]"/></a>
<span t-if="(!widget.options.show_link or !widget.author_id[0])"><t t-raw="widget.author_id[1]"/></span>
<t t-if="widget.partner_ids.length" t-raw="', '"/>
</t>
<t t-set="inc" t-value="0"/>
<t t-if="widget.partner_ids.length" t-foreach="widget.partner_ids" t-as="partner">
<t t-foreach="widget.partner_ids" t-as="partner">
<span t-attf-class="oe_partner_follower #{inc>=3?'oe_hidden':''}"><t t-if="inc" t-raw="', '"/>
<a t-if="widget.options.show_link" t-attf-href="#model=res.partner&amp;id=#{partner[0]}"><t t-raw="partner[1]"/></a>
<t t-if="!widget.options.show_link" t-raw="partner[1]"/>
</span><t t-set="inc" t-value="inc+1"/>
</span><t t-set="inc" t-value="(inc or 0)+1"/>
</t>
<t t-if="widget.partner_ids.length>=3">
<span class="oe_more">, <a><t t-raw="widget.partner_ids.length-3"/> others...</a></span>
<t t-if="widget.partner_ids.length > 3">
<span class="oe_more">, <a><t t-raw="widget.partner_ids.length - 3"/> others...</a></span>
<a class="oe_more_hidden">&lt;&lt;&lt;</a>
</t>
</div>
<div class="oe_emails_from" t-if="widget.emails_from.length">
<div class="oe_emails_from">
<t t-foreach='widget.emails_from' t-as='email_from'>
<label title="Add them into recipients and followers"><input type="checkbox" t-att-checked="email_from[1] ? 'checked' : undefind" t-att-data="email_from[0]"/> <t t-raw="email_from[0]"/></label>
<label title="Add them into recipients and followers">
<input type="checkbox" t-att-checked="email_from[1] ? 'checked' : undefind" t-att-data="email_from[0]"/>
<t t-raw="email_from[0]"/>
</label>
</t>
</div>
</t>