From fc34572ee3bbdfd52f3c5cda21cbcc61729dd3be Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 24 Oct 2012 15:48:19 +0200 Subject: [PATCH] [IMP] mail: preview image on openchatter bzr revid: chm@openerp.com-20121024134819-5gf165nf6cc21601 --- addons/mail/static/src/js/mail.js | 20 +++++++++++++++++--- addons/mail/static/src/xml/mail.xml | 21 +++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8044128cbe7..2fc2861c0d2 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -175,7 +175,6 @@ openerp.mail = function(session) { } else { this.$render_compact.hide(); } - this.bind_events(); }, @@ -198,7 +197,6 @@ openerp.mail = function(session) { /* when a user click on the upload button, send file read on_attachment_loaded */ on_attachment_change: function (event) { - console.log('attach'); event.stopPropagation(); var self = this; var $target = $(event.target); @@ -347,7 +345,6 @@ openerp.mail = function(session) { /*post a message and fetch the message*/ on_message_post: function (body) { - console.log('post'); var self = this; if (! body) { @@ -639,18 +636,35 @@ openerp.mail = function(session) { } for (var l in this.attachment_ids) { var attach = this.attachment_ids[l]; + if((attach.filename || attach.name).match(/[.](jpg|jpg|gif|png|tif|svg)$/i)) { + attach.is_image = true; + + } attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach); } + }, start: function() { this._super.apply(this, arguments); this.expender(); this.$el.hide().fadeIn(750); + this.resize_img(); this.bind_events(); this.create_thread(); }, + resize_img: function() { + this.$("img").load(function() { + var h = $(this).height(); + var w = $(this).width(); + if( h > 100 || w >100 ) { + var ratio = 100 / (h > w ? h : w); + $(this).attr("width", parseInt( w*ratio )).attr("height", parseInt( h*ratio )); + } + }); + }, + /** * Bind events in the widget. Each event is slightly described * in the function. */ diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 3cd43996569..1e3c699e39a 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -70,8 +70,8 @@ Template used to display attachments in a mail.message --> -
- + +
@@ -79,15 +79,24 @@
- - - + + + + + [
-
+ + + + + + + +