[FIX] mail: avatar, record_name, rerender with childs propagation

bzr revid: chm@openerp.com-20121109142101-izotiix03uvx29mm
This commit is contained in:
Christophe Matthieu 2012-11-09 15:21:01 +01:00
parent e093a55501
commit 3dbf5a1611
2 changed files with 66 additions and 57 deletions

View File

@ -276,7 +276,7 @@ openerp.mail = function (session) {
}
if (this.type == 'email' && !this.author_id) {
this.avatar = ('/mail/static/src/img/email_icon.png');
} else if (this.author_id) {
} else if (this.author_id && this.template != 'mail.compose_message') {
this.avatar = mail.ChatterUtils.get_image(this.session, 'res.partner', 'image_small', this.author_id[0]);
} else {
this.avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid);
@ -327,6 +327,38 @@ openerp.mail = function (session) {
return res;
},
/**
* search a message in all thread and child thread.
* This method return an object message.
* @param {object}{int} option.id
* @param {object}{string} option.model
* @param {object}{boolean} option._go_thread_wall
* private for check the top thread
* @return thread object
*/
browse_message: function (options) {
// goto the wall thread for launch browse
if (!options._go_thread_wall) {
options._go_thread_wall = true;
for (var i in this.options.root_thread.messages) {
var res=this.options.root_thread.messages[i].browse_message(options);
if (res) return res;
}
}
if (this.id==options.id)
return this;
for (var i in this.thread.messages) {
if (this.thread.messages[i].thread) {
var res=this.thread.messages[i].browse_message(options);
if (res) return res;
}
}
return false;
},
/**
* call on_message_delete on his parent thread
*/
@ -442,7 +474,6 @@ openerp.mail = function (session) {
*/
on_attachment_delete: function (event) {
event.stopPropagation();
console.log(event);
var attachment_id=$(event.target).data("id");
if (attachment_id) {
var attachments=[];
@ -814,21 +845,26 @@ openerp.mail = function (session) {
* @param {callback} apply function
*/
check_for_rerender: function () {
var domain = mail.ChatterUtils.expand_domain( this.options.root_thread.domain ).concat([["id", "in", [this.id].concat(this.get_child_ids()) ]]);
return this.parent_thread.ds_message.call('message_read', [undefined, domain, [], 0, this.context, this.parent_thread.id])
.then( _.bind(function (record) {
if (!record || !record.length) {
var self = this;
this.animated_destroy(150);
var messages = [this].concat(this.get_childs());
var message_ids = _.map(messages, function (msg) { return msg.id;});
var domain = mail.ChatterUtils.expand_domain( this.options.root_thread.domain )
.concat([["id", "in", message_ids ]]);
} else if (this.options.rerender) {
return this.parent_thread.ds_message.call('message_read', [undefined, domain, [], this.parent_thread.options.display_indented_thread, this.context, this.parent_thread.id])
.then( function (records) {
// remove message not loaded
_.map(messages, function (msg) {
if(!_.find(records, function (record) { return record.id == msg.id; })) {
msg.animated_destroy(150);
} else {
msg.renderElement();
msg.start()
}
});
this.renderElement();
this.start();
}
}, this) );
});
},
on_message_read: function (event) {
@ -861,49 +897,20 @@ openerp.mail = function (session) {
this.ds_notification.call('set_message_read', [message_ids, read_value, this.context])
.then(function () {
self.to_read = !read_value;
if (self.options.toggle_read) {
self.options.show_read = self.to_read;
self.options.show_unread = !self.to_read;
}
// apply modification
_.each(messages, function (msg) {
msg.to_read = !read_value;
if (msg.options.toggle_read) {
msg.options.show_read = msg.to_read;
msg.options.show_unread = !msg.to_read;
}
});
// check if the message must be display, destroy or rerender
self.check_for_rerender();
});
return false;
},
/**
* search a message in all thread and child thread.
* This method return an object message.
* @param {object}{int} option.id
* @param {object}{string} option.model
* @param {object}{boolean} option._go_thread_wall
* private for check the top thread
* @return thread object
*/
browse_message: function (options) {
// goto the wall thread for launch browse
if (!options._go_thread_wall) {
options._go_thread_wall = true;
for (var i in this.options.root_thread.messages) {
var res=this.options.root_thread.messages[i].browse_message(options);
if (res) return res;
}
}
if (this.id==options.id)
return this;
for (var i in this.thread.messages) {
if (this.thread.messages[i].thread) {
var res=this.thread.messages[i].browse_message(options);
if (res) return res;
}
}
return false;
},
/**
* add or remove a vote for a message and display the result
*/
@ -999,7 +1006,7 @@ openerp.mail = function (session) {
this.options = options.options;
this.options.root_thread = (options.options.root_thread != undefined ? options.options.root_thread : this);
this.options.show_compose_message = this.options.show_compose_message && (this.options.display_indented_thread >= this.thread_level || !this.thread_level);
// record options and data
this.parent_message= parent.thread!= undefined ? parent : false ;
@ -1013,7 +1020,9 @@ openerp.mail = function (session) {
this.thread_level = (datasets.thread_level+1) || 0,
this.partner_ids = _.filter(datasets.partner_ids, function (partner) { return partner[0]!=datasets.author_id[0]; } )
this.messages = [];
this.options.flat_mode = (this.options.display_indented_thread > this.thread_level ? this.options.display_indented_thread - this.thread_level : 0);
// object compose message
this.compose_message = false;
@ -1208,7 +1217,7 @@ openerp.mail = function (session) {
// ids allready loaded
(this.id ? [this.id].concat( this.get_child_ids() ) : this.get_child_ids()),
// option for sending in flat mode by server
(this.options.display_indented_thread > this.thread_level ? this.options.display_indented_thread - this.thread_level : 0),
this.options.flat_mode,
// context + additional
(replace_context ? replace_context : this.context),
// parent_id

View File

@ -73,7 +73,7 @@
<t t-name="mail.thread.message.attachments">
<t t-foreach='widget.attachment_ids' t-as='attachment'>
<t t-if="attachment.filetype !== 'webimage'">
<div class='oe_attachment'>
<div t-attf-class="oe_attachment #{attachment.upload ? 'oe_uploading' : ''}">
<a t-att-href='attachment.url'><img t-att-src="'/mail/static/src/img/mimetypes/' + attachment.filetype + '.png'"></img></a>
<div class='oe_delete oe_e' title="Delete this attachment" t-attf-data-id="{attachment.id}">[</div>
<div class='oe_name'><t t-raw='attachment.name' /></div>
@ -83,7 +83,7 @@
</div>
</t>
<t t-if="attachment.filetype === 'webimage'">
<div class='oe_attachment oe_preview'>
<div t-attf-class="oe_attachment oe_preview #{attachment.upload ? 'oe_uploading' : ''}">
<a t-att-href='attachment.url'><img t-att-src="widget.attachments_resize_image(attachment.id, [100,100])"></img></a>
<div class='oe_delete oe_e'>[</div>
<div class='oe_name'><t t-raw='attachment.name' /></div>
@ -109,7 +109,7 @@
<t t-name="mail.thread.list_recipients">
<div class="oe_mail_list_recipients">
To:
<span t-if="!widget.is_private" class="oe_all_follower">Followers <t t-if="widget.parent_thread.parent_message.show_record_name" t-raw="' of &quot;' + widget.parent_thread.parent_message.record_name + '&quot;' "/></span>
<span t-if="!widget.is_private" class="oe_all_follower">Followers <t t-raw="' of &quot;' + widget.parent_thread.parent_message.record_name + '&quot;' "/></span>
<t t-if="!widget.is_private and widget.partner_ids.length"> and </t>
<t t-set="inc" t-value="0"/>
<t t-if="widget.partner_ids.length" 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-attf-href="#model=res.partner&amp;id=#{partner[0]}"><t t-raw="partner[1]"/></a></span><t t-set="inc" t-value="inc+1"/>