[IMP] mail: insert message post, and no quote for reply

bzr revid: chm@openerp.com-20121025095923-7urqi5he10q3z1i6
This commit is contained in:
Christophe Matthieu 2012-10-25 11:59:23 +02:00
parent a10c6c4dfd
commit 31965cf97a
5 changed files with 225 additions and 185 deletions

View File

@ -694,7 +694,13 @@ class mail_thread(osv.AbstractModel):
# TDE FIXME: body is plaintext: convert it into html
# when writing on res.partner, without specific thread_id -> redirect to the user's partner
if self._name == 'res.partner' and not thread_id:
thread_id = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
thread_id = self.pool.get('res.users').read(cr, uid, uid, ['partner_id', 'subject'], context=context)['partner_id'][0]
mail_message = self.pool.get('mail.message')
if not subject and parent_id:
parent = mail_message.read(cr, uid, parent_id, ['subject'], context=context)
subject = 'Re: ' + parent['subject']
new_message_id = self.message_post(cr, uid, thread_id=thread_id, body=body, subject=subject, type=type,
subtype=subtype, parent_id=parent_id, context=context)
@ -702,13 +708,13 @@ class mail_thread(osv.AbstractModel):
# Chatter: attachments linked to the document (not done JS-side), load the message
if attachments:
ir_attachment = self.pool.get('ir.attachment')
mail_message = self.pool.get('mail.message')
attachment_ids = ir_attachment.search(cr, SUPERUSER_ID, [('res_model', '=', 'mail.compose.message'), ('res_id', '=', 0), ('create_uid', '=', uid), ('id', 'in', attachments)], context=context)
if attachment_ids:
ir_attachment.write(cr, SUPERUSER_ID, attachment_ids, {'res_model': self._name, 'res_id': thread_id}, context=context)
mail_message.write(cr, SUPERUSER_ID, [new_message_id], {'attachment_ids': [(6, 0, [pid for pid in attachment_ids])]}, context=context)
return new_message_id
new_message = self.pool.get('mail.message').message_read(cr, uid, [new_message_id], context=context)
return new_message
#------------------------------------------------------
# Followers API

View File

@ -253,3 +253,12 @@
opacity: 1;
-webkit-transition: opacity 0.2s linear;
}
/* ---------------- MESSAGES BODY ------------------ */
.openerp .oe_mail .oe_msg_content .oe_blockquote,
.openerp .oe_mail .oe_msg_content blockquote {
padding: 4px;
border-radius: 2px;
border: solid 1px rgba(124,123,173,0.14);
}

View File

@ -17,6 +17,8 @@ openerp.mail = function(session) {
session.web.FormView = session.web.FormView.extend({
do_action: function (action) {
console.log(action);
if (action.res_model == 'mail.compose.message') {
/* hack for stop context propagation of wrong value
* delete this hack when a global method to clean context is create
@ -24,7 +26,7 @@ openerp.mail = function(session) {
var context_keys = ['default_template_id', 'default_composition_mode',
'default_use_template', 'default_partner_ids', 'default_model',
'default_res_id', 'default_content_subtype', 'active_id', 'lang',
'bin_raw', 'tz', 'active_model', 'edi_web_url_view', 'active_ids']
'bin_raw', 'tz', 'active_model', 'edi_web_url_view', 'active_ids', 'default_subject']
for (var key in action.context) {
if (_.indexOf(context_keys, key) == -1) {
action.context[key] = null;
@ -286,7 +288,7 @@ openerp.mail = function(session) {
this.$render_expandable.on('click', '.oe_cancel', self.on_cancel );
this.$render_expandable.on('click', '.oe_post', function () {self.on_message_post()} );
this.$render_expandable.on('click', '.oe_full', function(){self.on_compose_fullmail()} );
this.$render_expandable.on('click', '.oe_full', function () {self.on_compose_fullmail('reply')} );
// auto close
this.$render_expandable.on('blur', 'textarea', this.on_compose_expandable);
@ -297,7 +299,7 @@ openerp.mail = function(session) {
}
},
on_compose_fullmail: function(){
on_compose_fullmail: function (default_composition_mode) {
/* TDE note: I think this is not necessary, because
* 1/ post on a document: followers added server-side in _notify
* 2/ reply to a message: mail.compose.message should add the previous partners
@ -306,6 +308,28 @@ openerp.mail = function(session) {
for (var i in this.partner_ids) {
partner_ids.push(this.partner_ids[i][0]);
}
if (default_composition_mode == 'reply') {
var context = {
'default_composition_mode': 'reply',
'default_parent_id': this.id,
'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''),
'default_attachment_ids': this.attachment_ids,
'default_partner_ids': [], //partner_ids
};
} else {
var context = {
'default_model': this.context.default_model,
'default_res_model': this.context.default_model,
'default_res_id': this.context.default_res_id,
'default_content_subtype': 'html',
'default_composition_mode': 'comment',
'default_parent_id': this.id,
'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''),
'default_attachment_ids': this.attachment_ids,
'default_partner_ids': [], //partner_ids
};
}
var action = {
type: 'ir.actions.act_window',
res_model: 'mail.compose.message',
@ -314,17 +338,9 @@ openerp.mail = function(session) {
action_from: 'mail.ThreadComposeMessage',
views: [[false, 'form']],
target: 'new',
context: {
'default_model': this.context.default_model,
'default_res_model': this.context.default_model,
'default_res_id': this.context.default_res_id,
'default_content_subtype': 'html',
'default_parent_id': this.id,
'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''),
'default_attachment_ids': this.attachment_ids,
'default_partner_ids': partner_ids
},
context: context,
};
this.do_action(action);
if (this.$render_expandable) {
@ -374,8 +390,13 @@ openerp.mail = function(session) {
this.context.default_parent_id,
attachments,
this.parent_thread.context
]).then(function(message_id) {
self.parent_thread.message_fetch([['id', '=', message_id]]);
]).then(function (record) {
var thread = self.parent_thread;
// create object and attach to the thread object
var message = thread.create_message_object( record[0] );
// insert the message on dom
thread.insert_message( message, self.thread_level > self.options.display_indented_thread ? self.parent_thread.$el : self.$el );
// clean compose message
self.on_cancel();
//session.web.unblockUI();
});
@ -1186,9 +1207,6 @@ openerp.mail = function(session) {
});
}
// insert the message on dom
self.insert_message( message );
// check if the message is already create
for (var i in self.messages) {
if (self.messages[i] && self.messages[i].id == message.id) {
@ -1196,6 +1214,8 @@ openerp.mail = function(session) {
}
}
self.messages.push( message );
return message;
},
/**
@ -1207,16 +1227,21 @@ openerp.mail = function(session) {
* The sort is define by the thread_level (O for newer on top).
* @param : {object} ThreadMessage object
*/
insert_message: function (message) {
insert_message: function (message, dom_insert_after) {
var self=this;
if(this.show_compose_message /*&&
this.options.display_indented_thread >= self.thread_level*/){
if (this.show_compose_message) {
this.ComposeMessage.do_show_compact();
}
this.$('.oe_wall_no_message').remove();
if (dom_insert_after) {
message.insertAfter(dom_insert_after);
return message
}
// check older and newer message for insertion
var parent_newer = false;
var parent_older = false;
@ -1291,7 +1316,10 @@ openerp.mail = function(session) {
'id': record.ancestor_id,
'default_return_top_thread':true
});
thread.create_message_object( record );
// create object and attach to the thread object
var message = thread.create_message_object( record );
// insert the message on dom
thread.insert_message( message );
});
},
@ -1370,6 +1398,7 @@ openerp.mail = function(session) {
'thread_level': message.thread_level,
'ancestor_id': message.ancestor_id,
'domain': message_dom,
'options': message.options,
}, {
'default_model': message.model || this.context.default_model,
'default_res_id': message.res_id || this.context.default_res_id,
@ -1654,7 +1683,7 @@ openerp.mail = function(session) {
'show_reply_button': 10,
'show_read_unread_button': 11,
'show_compose_message': true,
'show_compact_message': true,
'show_compact_message': false,
}
);

View File

@ -211,7 +211,7 @@
</div>
<!-- message itself -->
<div class="oe_msg_content">
<h1 t-if="widget.subject" class="oe_msg_title">
<h1 t-if="widget.subject and !widget.thread_level" class="oe_msg_title">
<t t-raw="widget.subject"/>
</h1>
<div class="oe_msg_body">

View File

@ -157,11 +157,7 @@ class mail_compose_message(osv.TransientModel):
if not (reply_subject.startswith('Re:') or reply_subject.startswith(re_prefix)) and message_data.subject:
reply_subject = "%s %s" % (re_prefix, reply_subject)
# create the reply in the body
reply_body = _('<div>On %(date)s, %(sender_name)s wrote:<blockquote>%(body)s</blockquote></div>') % {
'date': message_data.date if message_data.date else '',
'sender_name': message_data.author_id.name,
'body': message_data.body,
}
reply_body = (context and context.get('default_body') or '')
# get partner_ids from original message
partner_ids = [partner.id for partner in message_data.partner_ids] if message_data.partner_ids else []