[REV] mail: remove the python read attachment and update the controleur for image resizing

bzr revid: chm@openerp.com-20121108100544-u4t3k3c43jzwqobh
This commit is contained in:
Christophe Matthieu 2012-11-08 11:05:44 +01:00
parent da2bc197c4
commit d28124c40c
2 changed files with 28 additions and 17 deletions

View File

@ -53,8 +53,8 @@ openerp.mail = function (session) {
mail.ChatterUtils = {
/* Get an image in /web/binary/image?... */
get_image: function (session, model, field, id) {
return session.prefix + '/web/binary/image?session_id=' + session.session_id + '&model=' + model + '&field=' + field + '&id=' + (id || '');
get_image: function (session, model, field, id, resize) {
return session.prefix + '/web/binary/image?session_id=' + session.session_id + '&model=' + model + '&field=' + field + '&id=' + (id || '') + '&resize=' + (resize ? encodeURIComponent(resize) : '');
},
/* Get the url of an attachment {'id': id} */
@ -285,6 +285,18 @@ openerp.mail = function (session) {
return 'unknown';
},
/* upload the file on the server, add in the attachments list and reload display
*/
display_attachments: function () {
this.$(".oe_msg_attachment_list").html( session.web.qweb.render('mail.thread.message.attachments', {'widget': this}) );
},
/* return the link to resized image
*/
attachments_resize_image: function (id, resize) {
return mail.ChatterUtils.get_image(this.session, 'ir.attachment', 'datas', id, resize);
},
/* get all child message id linked.
* @return array of id
*/
@ -357,13 +369,6 @@ openerp.mail = function (session) {
this.bind_events();
},
/* upload the file on the server, add in the attachments list and reload display
*/
display_attachments: function () {
//this.$(".oe_msg_attachment_list").off('click', '.oe_mail_attachment_delete')
this.$(".oe_msg_attachment_list").html( session.web.qweb.render('mail.thread.message.attachments', {'widget': this}) );
},
/* when a user click on the upload button, send file read on_attachment_loaded
*/
on_attachment_change: function (event) {
@ -705,12 +710,9 @@ openerp.mail = function (session) {
this.$('.oe_msg_delete').on('click', this.on_message_delete);
this.$('.oe_reply').on('click', this.on_message_reply);
this.$('.oe_star').on('click', this.on_star);
this.$('.oe_msg_vote').on('click', this.on_vote);
this.$('.oe_view_attachments').on('click', this.on_view_attachments);
this.$('.oe_view_attachments').on('click', function(){
self.$('.oe_msg_attachment_list').toggle(200);
});
},
/* Call the on_compose_message on the thread of this message. */
@ -769,6 +771,17 @@ openerp.mail = function (session) {
}
},
/* Call the on_compose_message on the thread of this message. */
on_view_attachments:function (event) {
event.stopPropagation();
var self = this;
if (!this.toggle_attachment) {
self.display_attachments();
this.toggle_attachment = true;
}
this.$('.oe_msg_attachment_list').toggle(200);
},
/**
* Wait a confirmation for delete the message on the DB.
* Make an animate destroy

View File

@ -83,7 +83,7 @@
</t>
<t t-if="widget.filetype(attachment) === 'webimage'">
<div class='oe_attachment oe_preview'>
<a t-att-href='attachment.url'><img t-att-src="attachment.url"></img></a>
<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='widget.breakword(attachment.name || attachment.filename)' /></div>
<div class='oe_progress_bar'>
@ -211,9 +211,7 @@
</div>
<div class="oe_msg_footer">
<t t-if="widget.attachment_ids.length > 0">
<div class="oe_msg_attachment_list">
<t t-call="mail.thread.message.attachments"/>
</div>
<div class="oe_msg_attachment_list"></div>
</t>
<a t-if="widget.author_id" t-attf-href="#model=res.partner&amp;id=#{widget.author_id[0]}"><t t-raw="widget.author_id[1]"/></a>
<span class='oe_subtle'></span>