From 4818ad676f37cac9e1a13c36f01de6d0752769b4 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 24 Oct 2012 17:27:11 +0200 Subject: [PATCH 1/4] [IMP] mail: for security, document loader is in comment bzr revid: chm@openerp.com-20121024152711-igcz0seor2if6ist --- addons/mail/static/src/js/mail.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index db50b96560e..03c0b21da20 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -640,12 +640,13 @@ openerp.mail = function(session) { if((attach.filename || attach.name).match(/[.](jpg|jpg|gif|png|tif|svg)$/i)) { attach.is_image = true; - - } - if((attach.filename || attach.name).match(/[.](pdf|doc|docx|xls|xlsx|ppt|pptx|psd|tiff|dxf|svg)$/i)) { - attach.is_document = true; - attach.url_escape = encodeURIComponent(attach.url); + attach['url'] = mail.ChatterUtils.get_image(this.session, 'ir.attachment', 'datas', attach.id); } + //To do + // if((attach.filename || attach.name).match(/[.](pdf|doc|docx|xls|xlsx|ppt|pptx|psd|tiff|dxf|svg)$/i)) { + // attach.is_document = true; + // attach.url_escape = encodeURIComponent(attach.url); + // } } }, From 3e4d6ad44066690bc01caab2ed9a893f54be8fb5 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 25 Oct 2012 10:05:29 +0200 Subject: [PATCH 2/4] [IMP] mail: oppenchatter hidden attachment bzr revid: chm@openerp.com-20121025080529-p2dw63h2u2ixyt26 --- addons/mail/static/src/css/mail.css | 4 +++- addons/mail/static/src/js/mail.js | 35 +++++++++++++++-------------- addons/mail/static/src/xml/mail.xml | 14 +++--------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 4b412000a54..0221c36824c 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -158,9 +158,11 @@ padding-top: 2px; padding-bottom:6px; } -.openerp .oe_mail .oe_msg_attachments.oe_hidden{ +.openerp .oe_mail .oe_msg_attachments.oe_hidden, +.openerp .oe_mail .oe_msg_images.oe_hidden{ margin:0px; border: none; + display: none; } .openerp .oe_mail .oe_msg_attachments{ margin-bottom: 4px; diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 03c0b21da20..6ba893339fc 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -372,8 +372,9 @@ openerp.mail = function(session) { 'mail.mt_comment', this.context.default_parent_id, attachments, + // (this.options.display_indented_thread - this.thread_level), this.parent_thread.context - ]).then(function(records){ + ]).then(function(records) { self.parent_thread.switch_new_message(records); self.on_cancel(); //session.web.unblockUI(); @@ -407,7 +408,7 @@ openerp.mail = function(session) { if(this.$render_expandable.is(':hidden')){ - this.$render_expandable.show(); + this.$render_expandable.css('display', ''); this.$render_compact.hide(); this.$render_expandable.find('textarea').focus(); @@ -417,7 +418,7 @@ openerp.mail = function(session) { if(!this.$render_expandable.find('textarea').val().match(/\S+/)){ this.$render_expandable.hide(); if(this.options.show_compact_message && this.show_compact_message) { - this.$render_compact.show(); + this.$render_compact.css('display', ''); } else { this.$render_compact.hide(); } @@ -434,7 +435,7 @@ openerp.mail = function(session) { do_show_compact: function() { if(this.options.show_compact_message && (!this.$render_expandable || this.$render_expandable.is(':hidden'))) { - this.$render_compact.show(); + this.$render_compact.css('display', ''); } this.show_compact_message = true; } @@ -642,33 +643,29 @@ openerp.mail = function(session) { attach.is_image = true; attach['url'] = mail.ChatterUtils.get_image(this.session, 'ir.attachment', 'datas', attach.id); } - //To do - // if((attach.filename || attach.name).match(/[.](pdf|doc|docx|xls|xlsx|ppt|pptx|psd|tiff|dxf|svg)$/i)) { - // attach.is_document = true; - // attach.url_escape = encodeURIComponent(attach.url); - // } } - }, start: function() { this._super.apply(this, arguments); this.expender(); - this.$el.hide().fadeIn(750); + this.$el.hide().fadeIn(750, function() {$(this).css('display', '');}); this.resize_img(); this.bind_events(); this.create_thread(); + this.$('.oe_msg_attachments, .oe_msg_images').addClass("oe_hidden"); }, resize_img: function() { - this.$("img").load(function() { + var resize = 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 )); } - }); + }; + this.$("img").load(resize).each(resize); }, /** @@ -678,8 +675,14 @@ openerp.mail = function(session) { var self = this; // event: click on 'Attachment(s)' in msg - this.$('a.oe_msg_view_attachments:first').on('click', function (event) { - self.$('.oe_msg_attachments:first').toggle(); + this.$('.oe_mail_msg_view_attachments').on('click', function (event) { + var attach = self.$('.oe_msg_attachments:first, .oe_msg_images:first'); + if( self.$('.oe_msg_attachments:first').hasClass("oe_hidden") ) { + attach.removeClass("oe_hidden"); + } else { + attach.addClass("oe_hidden"); + } + self.resize_img(); }); // event: click on icone 'Read' in header this.$el.on('click', '.oe_read', this.on_message_read_unread); @@ -1584,8 +1587,6 @@ openerp.mail = function(session) { * @param {Array} [options.domain] domain on the Wall * @param {Object} [options.context] context, is an object. It should * contain default_model, default_res_id, to give it to the threads. - * @param {Number} [options.thread_level] number of thread levels to display - * 0 being flat. */ init: function (parent, options) { this._super(parent); diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 59ffc93bdf4..e806cf93a22 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 --> - - + +
@@ -90,21 +90,13 @@
- + - - - - - - - - From a10c6c4dfdab8d7a8a1f722333d4a9c9b654f0c6 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 25 Oct 2012 10:36:31 +0200 Subject: [PATCH 3/4] [IMP] mail: change message_post_api (method py return id); class indented in DOM for expandable & compose bzr revid: chm@openerp.com-20121025083631-ze0x0rmnj7catsmu --- addons/mail/mail_thread.py | 3 +- addons/mail/static/src/js/mail.js | 71 ++++++++++++++--------------- addons/mail/static/src/xml/mail.xml | 6 +-- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index af4818bcbcd..7d3f48b0f3d 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -708,8 +708,7 @@ class mail_thread(osv.AbstractModel): ir_attachment.write(cr, SUPERUSER_ID, attachment_ids, {'res_model': self._name, 'res_id': thread_id}, context=context) mail_message.write(cr, SUPERUSER_ID, [new_message_id], {'attachment_ids': [(6, 0, [pid for pid in attachment_ids])]}, context=context) - new_message = self.pool.get('mail.message').message_read(cr, uid, [new_message_id], context=context) - return new_message + return new_message_id #------------------------------------------------------ # Followers API diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 6ba893339fc..f30255d209c 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -155,6 +155,7 @@ openerp.mail = function(session) { this.is_private = datasets.is_private || false; this.partner_ids = datasets.partner_ids || []; this.avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid); + this.thread_level = datasets.thread_level; this.parent_thread= parent.messages!= undefined ? parent : false; this.ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment'); @@ -372,10 +373,9 @@ openerp.mail = function(session) { 'mail.mt_comment', this.context.default_parent_id, attachments, - // (this.options.display_indented_thread - this.thread_level), this.parent_thread.context - ]).then(function(records) { - self.parent_thread.switch_new_message(records); + ]).then(function(message_id) { + self.parent_thread.message_fetch([['id', '=', message_id]]); self.on_cancel(); //session.web.unblockUI(); }); @@ -457,13 +457,14 @@ openerp.mail = function(session) { mail.ThreadExpandable = session.web.Widget.extend({ template: 'mail.thread.expandable', - init: function(parent, datasets, options) { + init: function(parent, datasets, context) { this._super(parent); - this.domain = options.domain || []; + this.domain = datasets.domain || []; + this.options = datasets.options; this.context = _.extend({ default_model: 'mail.thread', default_res_id: 0, - default_parent_id: false }, options.context || {}); + default_parent_id: false }, context || {}); // data of this expandable message this.id = datasets.id || -1, @@ -474,7 +475,7 @@ openerp.mail = function(session) { this.type = 'expandable', this.max_limit = this.id < 0 || false, this.flag_used = false, - this.parent_thread= parent.messages!= undefined ? parent : options.options._parents[0]; + this.parent_thread= parent.messages!= undefined ? parent : this.options._parents[0]; }, @@ -572,9 +573,19 @@ openerp.mail = function(session) { *... @param {int} [show_reply_button] number thread level to display the reply button *... @param {int} [show_read_unread_button] number thread level to display the read/unread button */ - init: function(parent, datasets, options) { + init: function(parent, datasets, context) { this._super(parent); + // record domain and context + this.domain = datasets.domain || []; + this.context = _.extend({ + default_model: 'mail.thread', + default_res_id: 0, + default_parent_id: false }, context || {}); + + // record options + this.options = datasets.options; + // data of this message this.id = datasets.id || -1, this.model = datasets.model || false, @@ -596,21 +607,12 @@ openerp.mail = function(session) { this.attachment_ids = datasets.attachment_ids || [], this._date = datasets.date; - // record domain and context - this.domain = options.domain || []; - this.context = _.extend({ - default_model: 'mail.thread', - default_res_id: 0, - default_parent_id: false }, options.context || {}); - - // record options - this.options = options.options; this.show_reply_button = this.options.show_compose_message && this.options.show_reply_button > this.thread_level; this.show_read_unread_button = this.options.show_read_unread_button > this.thread_level; // record options and data - this.parent_thread= parent.messages!= undefined ? parent : options.options._parents[0]; + this.parent_thread= parent.messages!= undefined ? parent : this.options._parents[0]; this.thread = false; if( this.id > 0 ) { @@ -1167,22 +1169,20 @@ openerp.mail = function(session) { create_message_object: function (data) { var self = this; + var data = _.extend(data, {'thread_level': data.thread_level ? data.thread_level : self.thread_level}); + data.options = _.extend(self.options, data.options); + if(data.type=='expandable'){ var message = new mail.ThreadExpandable(self, data, { - 'domain': data.domain, - 'context': { - 'default_model': data.model || self.context.default_model, - 'default_res_id': data.res_id || self.context.default_res_id, - 'default_parent_id': self.id }, + 'default_model': data.model || self.context.default_model, + 'default_res_id': data.res_id || self.context.default_res_id, + 'default_parent_id': self.id, }); } else { - var message = new mail.ThreadMessage(self, _.extend(data, {'thread_level': data.thread_level ? data.thread_level : self.thread_level}), { - 'domain': data.domain, - 'context': { - 'default_model': data.model, - 'default_res_id': data.res_id, - 'default_parent_id': data.id }, - 'options': _.extend(self.options, data.options) + var message = new mail.ThreadMessage(self, data, { + 'default_model': data.model, + 'default_res_id': data.res_id, + 'default_parent_id': data.id, }); } @@ -1368,13 +1368,12 @@ openerp.mail = function(session) { 'ancestor_id': message.ancestor_id, 'nb_messages': 1, 'thread_level': message.thread_level, - 'ancestor_id': message.ancestor_id - }, { + 'ancestor_id': message.ancestor_id, 'domain': message_dom, - 'context': { - 'default_model': message.model || this.context.default_model, - 'default_res_id': message.res_id || this.context.default_res_id, - 'default_parent_id': this.id }, + }, { + 'default_model': message.model || this.context.default_model, + 'default_res_id': message.res_id || this.context.default_res_id, + 'default_parent_id': this.id, }); // add object on array and DOM diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index e806cf93a22..0f0362e84ce 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -15,7 +15,7 @@ for main thread composition form in document form view. --> -
+
User img
@@ -40,7 +40,7 @@ mail.compose_message when focus on textarea --> -
+