[IMP]mail: read_more with expandable, debug
bzr revid: chm@openerp.com-20121002151245-yhltbv3r9fo16qek
This commit is contained in:
parent
1ab943d7f0
commit
09763017a5
|
@ -193,7 +193,7 @@ class mail_message(osv.Model):
|
||||||
attachment_ids = []
|
attachment_ids = []
|
||||||
try:
|
try:
|
||||||
author_id = self.pool.get('res.partner').name_get(cr, uid, [msg.author_id.id], context=context)[0]
|
author_id = self.pool.get('res.partner').name_get(cr, uid, [msg.author_id.id], context=context)[0]
|
||||||
is_author = uid in msg.author_id.user_ids
|
is_author = uid == msg.author_id.user_ids[0].id
|
||||||
except (orm.except_orm, osv.except_osv):
|
except (orm.except_orm, osv.except_osv):
|
||||||
author_id = False
|
author_id = False
|
||||||
is_author = False
|
is_author = False
|
||||||
|
@ -215,8 +215,6 @@ class mail_message(osv.Model):
|
||||||
'author_id': author_id,
|
'author_id': author_id,
|
||||||
'is_author': is_author,
|
'is_author': is_author,
|
||||||
'partner_ids': partner_ids,
|
'partner_ids': partner_ids,
|
||||||
'child_ids': [],
|
|
||||||
'child_nbr': child_nbr,
|
|
||||||
'parent_id': msg.parent_id and msg.parent_id.id or False,
|
'parent_id': msg.parent_id and msg.parent_id.id or False,
|
||||||
'vote_user_ids': vote_ids,
|
'vote_user_ids': vote_ids,
|
||||||
'has_voted': has_voted,
|
'has_voted': has_voted,
|
||||||
|
@ -311,18 +309,20 @@ class mail_message(osv.Model):
|
||||||
|
|
||||||
limit = limit or self._message_read_limit
|
limit = limit or self._message_read_limit
|
||||||
context = context or {}
|
context = context or {}
|
||||||
if not ids:
|
|
||||||
ids = self.search(cr, SUPERUSER_ID, domain, context=context, limit=limit)
|
|
||||||
# if the user can read a message, he can read all the thread
|
|
||||||
|
|
||||||
messages = self.browse(cr, uid, ids, context=context)
|
|
||||||
|
|
||||||
|
|
||||||
# key: ID, value: record
|
|
||||||
tree = []
|
tree = []
|
||||||
result = []
|
result = []
|
||||||
record = None
|
record = None
|
||||||
for msg in messages:
|
|
||||||
|
# select ids
|
||||||
|
if ids:
|
||||||
|
for msg in self.browse(cr, uid, ids, context=context):
|
||||||
|
result.append(self._message_dict_get(cr, uid, msg, context=context))
|
||||||
|
return result
|
||||||
|
|
||||||
|
# key: ID, value: record
|
||||||
|
ids = self.search(cr, SUPERUSER_ID, domain, context=context, limit=limit)
|
||||||
|
for msg in self.browse(cr, uid, ids, context=context):
|
||||||
# if not in record and not in message_loded list
|
# if not in record and not in message_loded list
|
||||||
if msg.id not in tree and msg.id not in message_loaded :
|
if msg.id not in tree and msg.id not in message_loaded :
|
||||||
record = self._message_dict_get(cr, uid, msg, context=context)
|
record = self._message_dict_get(cr, uid, msg, context=context)
|
||||||
|
@ -341,10 +341,12 @@ class mail_message(osv.Model):
|
||||||
|
|
||||||
result = sorted(result, key=lambda k: k['id'])
|
result = sorted(result, key=lambda k: k['id'])
|
||||||
|
|
||||||
|
|
||||||
|
tree_not = []
|
||||||
# expandable for not show message
|
# expandable for not show message
|
||||||
for id_msg in tree:
|
for id_msg in tree:
|
||||||
# get all childs
|
# get all childs
|
||||||
not_loaded_ids = self.search(cr, SUPERUSER_ID, [['parent_id','=',id_msg],['id','not in',message_loaded]], None, limit=limit)
|
not_loaded_ids = self.search(cr, SUPERUSER_ID, [['parent_id','=',id_msg],['id','not in',message_loaded]], None, limit=1000)
|
||||||
# group childs not read
|
# group childs not read
|
||||||
id_min=None
|
id_min=None
|
||||||
id_max=None
|
id_max=None
|
||||||
|
@ -356,6 +358,7 @@ class mail_message(osv.Model):
|
||||||
id_min=not_loaded_id
|
id_min=not_loaded_id
|
||||||
if id_max==None or id_max<not_loaded_id:
|
if id_max==None or id_max<not_loaded_id:
|
||||||
id_max=not_loaded_id
|
id_max=not_loaded_id
|
||||||
|
tree_not.append(not_loaded_id)
|
||||||
else:
|
else:
|
||||||
if nb>0:
|
if nb>0:
|
||||||
result.append({
|
result.append({
|
||||||
|
@ -375,8 +378,9 @@ class mail_message(osv.Model):
|
||||||
'id': id_min
|
'id': id_min
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
# expandable for limit max
|
# expandable for limit max
|
||||||
ids = self.search(cr, SUPERUSER_ID, domain+[['id','not in',message_loaded]], context=context, limit=1)
|
ids = self.search(cr, SUPERUSER_ID, domain+[['id','not in',message_loaded+tree+tree_not]], context=context, limit=1)
|
||||||
if len(ids) > 0:
|
if len(ids) > 0:
|
||||||
result.append(
|
result.append(
|
||||||
{
|
{
|
||||||
|
|
|
@ -277,7 +277,6 @@ openerp.mail = function(session) {
|
||||||
* in the function. */
|
* in the function. */
|
||||||
bind_events: function() {
|
bind_events: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$('*').unbind();
|
|
||||||
// event: click on 'Vote' button
|
// event: click on 'Vote' button
|
||||||
this.$el.on('click', 'a.oe_mail_fetch_more', self.on_expandable);
|
this.$el.on('click', 'a.oe_mail_fetch_more', self.on_expandable);
|
||||||
},
|
},
|
||||||
|
@ -421,7 +420,6 @@ openerp.mail = function(session) {
|
||||||
* in the function. */
|
* in the function. */
|
||||||
bind_events: function() {
|
bind_events: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$('*').unbind();
|
|
||||||
// event: click on 'Attachment(s)' in msg
|
// event: click on 'Attachment(s)' in msg
|
||||||
this.$el.on('click', 'a.oe_mail_msg_view_attachments', function (event) {
|
this.$el.on('click', 'a.oe_mail_msg_view_attachments', function (event) {
|
||||||
var act_dom = $(this).parent().parent().parent().find('.oe_mail_msg_attachments');
|
var act_dom = $(this).parent().parent().parent().find('.oe_mail_msg_attachments');
|
||||||
|
@ -450,7 +448,7 @@ openerp.mail = function(session) {
|
||||||
|
|
||||||
on_message_reply_by_mail:function(event){
|
on_message_reply_by_mail:function(event){
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
this.thread.on_compose_message($(event.srcElement).hasClass("oe_full_reply"), true);
|
this.thread.on_compose_message(true, true);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -496,7 +494,7 @@ openerp.mail = function(session) {
|
||||||
animated_destroy: function(options) {
|
animated_destroy: function(options) {
|
||||||
var self=this;
|
var self=this;
|
||||||
//graphic effects
|
//graphic effects
|
||||||
if(options.fadeTime) {
|
if(options && options.fadeTime) {
|
||||||
self.$el.fadeOut(options.fadeTime, function(){
|
self.$el.fadeOut(options.fadeTime, function(){
|
||||||
self.destroy();
|
self.destroy();
|
||||||
});
|
});
|
||||||
|
@ -688,16 +686,16 @@ openerp.mail = function(session) {
|
||||||
|
|
||||||
this.display_user_avatar();
|
this.display_user_avatar();
|
||||||
var display_done = compose_done = false;
|
var display_done = compose_done = false;
|
||||||
|
|
||||||
if(this.options.thread._parents[0]==this){
|
|
||||||
this.on_first_thread();
|
|
||||||
}
|
|
||||||
|
|
||||||
// add message composition form view
|
// add message composition form view
|
||||||
compose_done = this.instantiate_composition_form();
|
compose_done = this.instantiate_composition_form();
|
||||||
|
|
||||||
this.bind_events();
|
this.bind_events();
|
||||||
|
|
||||||
|
if(this.options.thread._parents[0]==this){
|
||||||
|
this.on_first_thread();
|
||||||
|
}
|
||||||
|
|
||||||
return display_done && compose_done;
|
return display_done && compose_done;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -707,7 +705,7 @@ openerp.mail = function(session) {
|
||||||
* in the composition form. */
|
* in the composition form. */
|
||||||
do_action: function(action, on_close) {
|
do_action: function(action, on_close) {
|
||||||
this.instantiate_composition_form();
|
this.instantiate_composition_form();
|
||||||
this.message_fletch();
|
this.message_fletch(false, false, false, [action.id]);
|
||||||
return this._super(action, on_close);
|
return this._super(action, on_close);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -832,7 +830,7 @@ openerp.mail = function(session) {
|
||||||
if (!this.compose_message_widget) return true;
|
if (!this.compose_message_widget) return true;
|
||||||
this.compose_message_widget.refresh({
|
this.compose_message_widget.refresh({
|
||||||
'default_composition_mode': 'reply',
|
'default_composition_mode': 'reply',
|
||||||
'default_parent_id': message.id,
|
'default_parent_id': this.id,
|
||||||
'default_content_subtype': 'html'} );
|
'default_content_subtype': 'html'} );
|
||||||
}
|
}
|
||||||
this.$('div.oe_mail_thread_action:first').toggle();
|
this.$('div.oe_mail_thread_action:first').toggle();
|
||||||
|
@ -854,8 +852,7 @@ openerp.mail = function(session) {
|
||||||
comment_node.val('');
|
comment_node.val('');
|
||||||
}
|
}
|
||||||
if(body.match(/\S+/)) {
|
if(body.match(/\S+/)) {
|
||||||
//this.$("textarea:first").blur();
|
this.ds_thread.call('message_post_api', [
|
||||||
return this.ds_thread.call('message_post_api', [
|
|
||||||
[this.context.default_res_id], body, false, 'comment', false, this.context.default_parent_id, undefined])
|
[this.context.default_res_id], body, false, 'comment', false, this.context.default_parent_id, undefined])
|
||||||
.then(this.proxy('switch_new_message'));
|
.then(this.proxy('switch_new_message'));
|
||||||
}
|
}
|
||||||
|
@ -871,7 +868,7 @@ openerp.mail = function(session) {
|
||||||
* @param {Array} replace_domain: added to this.domain
|
* @param {Array} replace_domain: added to this.domain
|
||||||
* @param {Object} replace_context: added to this.context
|
* @param {Object} replace_context: added to this.context
|
||||||
*/
|
*/
|
||||||
message_fletch: function (initial_mode, replace_domain, replace_context) {
|
message_fletch: function (initial_mode, replace_domain, replace_context, ids) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// initial mode: try to use message_data or message_ids
|
// initial mode: try to use message_data or message_ids
|
||||||
|
@ -883,7 +880,7 @@ openerp.mail = function(session) {
|
||||||
fetch_context = replace_context ? replace_context : this.context;
|
fetch_context = replace_context ? replace_context : this.context;
|
||||||
fetch_context.message_loaded= [this.id||0].concat( self.options.thread._parents[0].get_child_ids() );
|
fetch_context.message_loaded= [this.id||0].concat( self.options.thread._parents[0].get_child_ids() );
|
||||||
|
|
||||||
return this.ds_message.call('message_read', [false, fetch_domain, (this.options.thread.thread_level+1), fetch_context, this.context.default_parent_id || undefined]
|
return this.ds_message.call('message_read', [ids, fetch_domain, (this.options.thread.thread_level+1), fetch_context, this.context.default_parent_id || undefined]
|
||||||
).then(this.proxy('switch_new_message'));
|
).then(this.proxy('switch_new_message'));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -933,16 +930,18 @@ openerp.mail = function(session) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var thread = self.options.thread.display_on_flat ? self.options.thread._parents[0] : this;
|
||||||
|
|
||||||
// check older and newer message for insert
|
// check older and newer message for insert
|
||||||
var parent_newer = false;
|
var parent_newer = false;
|
||||||
var parent_older = false;
|
var parent_older = false;
|
||||||
for(var i in this.messages){
|
for(var i in thread.messages){
|
||||||
if(this.messages[i].id > message.id){
|
if(thread.messages[i].id > message.id){
|
||||||
if(!parent_newer || parent_newer.id>this.messages[i].id)
|
if(!parent_newer || parent_newer.id>thread.messages[i].id)
|
||||||
parent_newer = this.messages[i];
|
parent_newer = thread.messages[i];
|
||||||
} else if(this.messages[i].id>0 && this.messages[i].id < message.id) {
|
} else if(thread.messages[i].id>0 && thread.messages[i].id < message.id) {
|
||||||
if(!parent_older || parent_older.id<this.messages[i].id)
|
if(!parent_older || parent_older.id<thread.messages[i].id)
|
||||||
parent_older = this.messages[i];
|
parent_older = thread.messages[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -951,7 +950,7 @@ openerp.mail = function(session) {
|
||||||
else if(parent_older)
|
else if(parent_older)
|
||||||
message.insertBefore(parent_older.$el);
|
message.insertBefore(parent_older.$el);
|
||||||
else
|
else
|
||||||
message.prependTo(this.list_ul);
|
message.prependTo(thread.list_ul);
|
||||||
|
|
||||||
return message
|
return message
|
||||||
},
|
},
|
||||||
|
@ -979,7 +978,7 @@ openerp.mail = function(session) {
|
||||||
var self=this;
|
var self=this;
|
||||||
_(records).each(function(record){
|
_(records).each(function(record){
|
||||||
self.browse_thread({
|
self.browse_thread({
|
||||||
'id': (self.options.thread.display_on_flat ? false : record.parent_id),
|
'id': record.parent_id,
|
||||||
'default_return_top_thread':true
|
'default_return_top_thread':true
|
||||||
}).create_message_object( record );
|
}).create_message_object( record );
|
||||||
});
|
});
|
||||||
|
|
|
@ -109,12 +109,10 @@
|
||||||
<!-- message actions (read/unread, reply, delete...) -->
|
<!-- message actions (read/unread, reply, delete...) -->
|
||||||
<ul class="oe_header">
|
<ul class="oe_header">
|
||||||
<li class="placeholder-mail-vote"><t t-call="mail.thread.message.vote"/></li>
|
<li class="placeholder-mail-vote"><t t-call="mail.thread.message.vote"/></li>
|
||||||
<t t-if="!widget.options.thread.display_on_flat">
|
<li t-if="!widget.options.thread.display_on_flat and widget.unread" title="Read"><a class="oe_read oe_e">W</a></li>
|
||||||
<li t-if="widget.unread" title="Read"><a class="oe_read oe_e">W</a></li>
|
<li t-if="!widget.options.thread.display_on_flat and !widget.unread" title="Set back to unread"><a class="oe_unread oe_e">h</a></li>
|
||||||
<li t-if="!widget.unread" title="Set back to unread"><a class="oe_unread oe_e">h</a></li>
|
<li t-if="!widget.options.message.show_reply_by_email" title="Reply"><a class="oe_reply oe_e">)</a></li>
|
||||||
<li t-if="widget.options.message.show_reply" title="Reply"><a class="oe_reply oe_e">)</a></li>
|
<li t-if="widget.options.message.show_reply_by_email"><a class="oe_reply_by_email oe_e" title="Reply by mail">)</a></li>
|
||||||
<li t-if="widget.options.message.show_reply_by_email"><a class="oe_reply_by_email oe_e" title="Reply by mail">)</a></li>
|
|
||||||
</t>
|
|
||||||
<t t-if="(widget.options.message.show_reply || widget.options.message.show_reply_by_email || (widget.is_author and widget.options.message.show_dd_delete) || widget.type == 'email')">
|
<t t-if="(widget.options.message.show_reply || widget.options.message.show_reply_by_email || (widget.is_author and widget.options.message.show_dd_delete) || widget.type == 'email')">
|
||||||
<li>
|
<li>
|
||||||
<span class="oe_dropdown_toggle">
|
<span class="oe_dropdown_toggle">
|
||||||
|
@ -176,7 +174,7 @@
|
||||||
<li t-name="mail.thread.expandable" t-attf-class="oe_mail oe_mail_thread_msg oe_mail_unread" t-attf-data-thread_id="{widget.id}">
|
<li t-name="mail.thread.expandable" t-attf-class="oe_mail oe_mail_thread_msg oe_mail_unread" t-attf-data-thread_id="{widget.id}">
|
||||||
<div t-attf-class="oe_mail_msg_#{widget.type} oe_semantic_html_override">
|
<div t-attf-class="oe_mail_msg_#{widget.type} oe_semantic_html_override">
|
||||||
<div class="oe_mail_msg_content oe_mail_msg_more_message">
|
<div class="oe_mail_msg_content oe_mail_msg_more_message">
|
||||||
<a class="oe_mail_fetch_more">Load more messages <span t-if="widget.nb_messages>0">(<t t-raw="widget.nb_messages"/> not display)</span>...</a>
|
<a class="oe_mail_fetch_more">Load more messages <span t-if="widget.nb_messages>0">(<t t-raw="widget.nb_messages"/> messages not display)</span>...</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -255,13 +255,13 @@ class mail_compose_message(osv.TransientModel):
|
||||||
post_values['attachments'] += new_attachments
|
post_values['attachments'] += new_attachments
|
||||||
post_values.update(email_dict)
|
post_values.update(email_dict)
|
||||||
# post the message
|
# post the message
|
||||||
active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype='mt_comment', context=context, **post_values)
|
id=active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype='mt_comment', context=context, **post_values)
|
||||||
|
|
||||||
# post process: update attachments, because id is not necessarily known when adding attachments in Chatter
|
# post process: update attachments, because id is not necessarily known when adding attachments in Chatter
|
||||||
# self.pool.get('ir.attachment').write(cr, uid, [attach.id for attach in wizard.attachment_ids], {
|
# self.pool.get('ir.attachment').write(cr, uid, [attach.id for attach in wizard.attachment_ids], {
|
||||||
# 'res_id': wizard.id, 'res_model': wizard.model or False}, context=context)
|
# 'res_id': wizard.id, 'res_model': wizard.model or False}, context=context)
|
||||||
|
|
||||||
return {'type': 'ir.actions.act_window_close', 'res_model':'mail.compose.message'}
|
return {'type': 'ir.actions.act_window_close', 'res_model':'mail.compose.message', 'id': id}
|
||||||
|
|
||||||
def render_message(self, cr, uid, wizard, res_id, context=None):
|
def render_message(self, cr, uid, wizard, res_id, context=None):
|
||||||
""" Generate an email from the template for given (wizard.model, res_id)
|
""" Generate an email from the template for given (wizard.model, res_id)
|
||||||
|
|
Loading…
Reference in New Issue