summaryrefslogtreecommitdiff
path: root/addons/mail/static/src
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@openerp.com>2012-10-24 15:48:19 +0200
committerChristophe Matthieu <chm@openerp.com>2012-10-24 15:48:19 +0200
commitfc34572ee3bbdfd52f3c5cda21cbcc61729dd3be (patch)
tree153ea54b18f9750be06b334d6d24d965978786fe /addons/mail/static/src
parent69a2a3180ae592d7aabd64f00bd14a40437ba378 (diff)
[IMP] mail: preview image on openchatter
bzr revid: chm@openerp.com-20121024134819-5gf165nf6cc21601
Diffstat (limited to 'addons/mail/static/src')
-rw-r--r--addons/mail/static/src/js/mail.js20
-rw-r--r--addons/mail/static/src/xml/mail.xml21
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
-->
<t t-name="mail.thread.message.attachments">
- <div t-attf-class="oe_msg_attachments #{widget.attachment_ids[0]?'':'oe_hidden'}">
- <t t-foreach="widget.attachment_ids" t-as="attachment">
+ <span t-attf-class="oe_msg_attachments">
+ <t t-foreach="widget.attachment_ids" t-as="attachment" t-if="!attachment.is_image">
<div class="oe_attachment">
<span t-if="(attachment.upload or attachment.percent_loaded&lt;100)" t-attf-title="{(attachment.name || attachment.filename) + (attachment.date?' \n('+attachment.date+')':'' )}" t-attf-name="{attachment.name || attachment.filename}">
<div class="oe_upload_in_process">
@@ -79,15 +79,24 @@
</div>
<t t-raw="attachment.name || attachment.filename"/>
</span>
- <a t-if="(!attachment.upload or attachment.percent_loaded&gt;=100)" t-att-href="attachment.url" t-attf-title="{(attachment.name || attachment.filename) + (attachment.date?' \n('+attachment.date+')':'' )}">
- <t t-raw="attachment.name || attachment.filename"/>
- </a>
+ <t t-if="(!attachment.upload or attachment.percent_loaded&gt;=100)">
+ <a t-att-href="attachment.url" t-attf-title="{(attachment.name || attachment.filename) + (attachment.date?' \n('+attachment.date+')':'' )}">
+ <t t-raw="attachment.name || attachment.filename"/>
+ </a>
+ </t>
<t t-if="(widget.show_delete_attachment and (!attachment.upload or attachment.percent_loaded&gt;=100))">
<a class="oe_right oe_mail_attachment_delete oe_e" title="Delete this attachment" t-attf-data-id="{attachment.id}">[</a>
</t>
</div>
</t>
- </div>
+ </span>
+ <span t-attf-class="oe_msg_images">
+ <t t-foreach="widget.attachment_ids" t-as="attachment" t-if="attachment.is_image">
+ <a t-att-href="attachment.url" t-attf-title="{(attachment.name || attachment.filename) + (attachment.date?' \n('+attachment.date+')':'' )}">
+ <img t-if="attachment.is_image" t-attf-title="{(attachment.name || attachment.filename) + (attachment.date?' \n('+attachment.date+')':'' )}" t-att-src="attachment.url"/>
+ </a>
+ </t>
+ </span>
</t>
<t t-name="mail.thread.message.private">