From 57039657e49644e950881598c2a0c949d19cf26b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 23 Oct 2012 09:42:42 +0200 Subject: [PATCH 1/2] [IMP] mail: get message_ids list on the current model bzr revid: chm@openerp.com-20121023074242-u43ibl6bvfp31st6 --- addons/mail/static/src/js/mail.js | 34 +++++++++++++++-------------- addons/mail/static/src/xml/mail.xml | 1 + 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index bbf68f7711c..ff2c2f0b934 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -304,7 +304,7 @@ openerp.mail = function(session) { this.$render_expandable.on('blur', 'textarea', this.on_compose_expandable); /* stack for don't close the compose form if the user click on a button */ - this.$render_expandable.on('focus', 'textarea', function () { self.stay_open = false; }); + this.$render_expandable.on('focus, mouseup', 'textarea', function () { self.stay_open = false; }); this.$render_expandable.on('mousedown', function () { self.stay_open = true; }); } }, @@ -847,7 +847,6 @@ openerp.mail = function(session) { * add or remove a favorite (or starred) for a message and change class on the DOM */ on_star: function (event) { - console.log('on_star'); event.stopPropagation(); var self=this; var button = self.$('.oe_star:first'); @@ -1170,14 +1169,8 @@ openerp.mail = function(session) { // check if the message is already create for(var i in self.messages){ - if(self.messages[i].id == message.id){ + if(self.messages[i] && self.messages[i].id == message.id){ self.messages[i].destroy(); - if(message.id>0){ - self.messages[i] = message; - return true; - } else { - delete self.messages[i]; - } } } self.messages.push( message ); @@ -1288,6 +1281,10 @@ openerp.mail = function(session) { }); }, + /** + * this method is call when the widget of a message or an expandable message is destroy + * in this thread. The this.messages array is filter to remove this message + */ on_message_detroy: function (message) { this.messages = _.filter(this.messages, function (val) { return !val.isDestroyed(); }); @@ -1410,6 +1407,8 @@ openerp.mail = function(session) { *... @param {Boolean} [show_compose_message] allow to display the composer *... @param {Boolean} [show_compact_message] display the compact message on the thread * when the user clic on this compact mode, the composer is open + *... @param {Array} [message_ids] List of ids to fetch by the root thread. + * When you use this option, the domain is not used for the fetch root. */ init: function (parent, options) { this._super(parent); @@ -1425,7 +1424,8 @@ openerp.mail = function(session) { 'truncate_limit' : 250, 'show_record_name' : false, 'show_compose_message' : false, - 'show_compact_message' : false + 'show_compact_message' : false, + 'message_ids': [] }, options); if(this.display_indented_thread === false) { @@ -1462,9 +1462,9 @@ openerp.mail = function(session) { this.thread.appendTo( this.$el ); this.thread.no_message(); - this.thread.message_fetch(); + this.thread.message_fetch(null, null, this.options.message_ids); - if(this.options.show_compose_message && this.thread.ComposeMessage){ + if(this.options.show_compose_message){ this.thread.ComposeMessage.do_show_compact(); } }, @@ -1522,10 +1522,11 @@ openerp.mail = function(session) { // update domain var domain = this.options.domain.concat([['model', '=', this.view.model], ['res_id', '=', this.view.datarecord.id]]); - // TDE note: replace message_is_follower by a check in message_follower_ids, as message_is_follower is not used in views anymore var show_compose_message = this.view.is_action_enabled('edit') || (this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value()); + var message_ids = this.getParent().fields.message_ids && this.getParent().fields.message_ids.get_value(); + if(this.root){ this.root.destroy(); } @@ -1537,7 +1538,8 @@ openerp.mail = function(session) { 'display_indented_thread': -1, 'show_reply_button': 0, 'show_read_unread_button': -1, - 'show_compose_message': show_compose_message + 'show_compose_message': show_compose_message, + 'message_ids': message_ids } ); @@ -1631,11 +1633,11 @@ openerp.mail = function(session) { 'domain' : domain, 'context' : context, 'typeof_thread': context['typeof_thread'] || 'other', - 'display_indented_thread': 2, + 'display_indented_thread': 1, 'show_reply_button': 10, 'show_read_unread_button': 11, 'show_compose_message': true, - 'show_compact_message': true + 'show_compact_message': false } ); diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 1d5f3a9e239..a361daae154 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -145,6 +145,7 @@ + or From 7c789f5efa53fb82e4ee71c54b729e798b3bc5af Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 23 Oct 2012 10:47:36 +0200 Subject: [PATCH 2/2] [IMP] mail: add on js an option for the py: nb_indented_thread bzr revid: chm@openerp.com-20121023084736-314ul6edkplqxxb7 --- addons/mail/static/src/js/mail.js | 51 ++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index ff2c2f0b934..025e5d43b9a 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -145,6 +145,8 @@ openerp.mail = function(session) { this.context = options.context || {}; this.options = options.options; + this.show_compact_message = this.options.show_compact_message || false; + // data of this compose message this.attachment_ids = []; this.id = datasets.id; @@ -168,6 +170,12 @@ openerp.mail = function(session) { start: function(){ this.$render_compact = this.$el; + if( this.options.show_compact_message ) { + this.$render_compact.show(); + } else { + this.$render_compact.hide(); + } + this.bind_events(); }, @@ -395,13 +403,9 @@ openerp.mail = function(session) { } }, - /* convert the compact mode into the compose message + /* create the compose on expandable form */ - on_compose_expandable: function(event){ - if(event) event.stopPropagation(); - - var self = this; - + instantiate_expandable: function() { if(!this.$render_expandable) { this.$render_expandable = $(session.web.qweb.render('mail.compose_message', {'widget': this})); this.$render_expandable.hide(); @@ -411,6 +415,16 @@ openerp.mail = function(session) { this.bind_events(); } + }, + + /* convert the compact mode into the compose message + */ + on_compose_expandable: function(event){ + if(event) event.stopPropagation(); + + var self = this; + + this.instantiate_expandable(); if(this.$render_expandable.is(':hidden')){ @@ -423,7 +437,7 @@ openerp.mail = function(session) { // do not close the box if there are some text if(!this.$render_expandable.find('textarea').val().match(/\S+/)){ this.$render_expandable.hide(); - if(this.options.show_compact_message) { + if(this.options.show_compact_message && this.show_compact_message) { this.$render_compact.show(); } else { this.$render_compact.hide(); @@ -436,14 +450,14 @@ openerp.mail = function(session) { do_hide_compact: function() { this.$render_compact.hide(); - this.options.show_compact_message = false; + this.show_compact_message = false; }, do_show_compact: function() { - if(!this.$render_expandable || this.$render_expandable.is(':hidden')){ + if(this.options.show_compact_message && (!this.$render_expandable || this.$render_expandable.is(':hidden'))) { this.$render_compact.show(); } - this.options.show_compact_message = true; + this.show_compact_message = true; } }); @@ -1132,7 +1146,10 @@ openerp.mail = function(session) { fetch_context = replace_context ? replace_context : this.context; var message_loaded_ids = this.id ? [this.id].concat( self.get_child_ids() ) : self.get_child_ids(); - return this.ds_message.call('message_read', [ids, fetch_domain, message_loaded_ids, fetch_context, this.context.default_parent_id || undefined] + // CHM note : option for sending in flat mode by server + var nb_indented_thread = this.options.display_indented_thread > this.thread_level ? this.options.display_indented_thread - this.thread_level : 0; + + return this.ds_message.call('message_read', [ids, fetch_domain, message_loaded_ids, /*nb_indented_thread,*/ fetch_context, this.context.default_parent_id || undefined] ).then(this.proxy('switch_new_message')); }, @@ -1189,7 +1206,7 @@ openerp.mail = function(session) { var self=this; if(this.show_compose_message && - this.options.display_indented_thread > self.thread_level){ + this.options.display_indented_thread >= self.thread_level){ this.ComposeMessage.do_show_compact(); } @@ -1464,8 +1481,12 @@ openerp.mail = function(session) { this.thread.no_message(); this.thread.message_fetch(null, null, this.options.message_ids); - if(this.options.show_compose_message){ - this.thread.ComposeMessage.do_show_compact(); + if(this.options.show_compose_message) { + if(this.options.show_compact_message) { + this.thread.ComposeMessage.do_show_compact(); + } else { + this.thread.ComposeMessage.do_hide_compact(); + } } }, @@ -1637,7 +1658,7 @@ openerp.mail = function(session) { 'show_reply_button': 10, 'show_read_unread_button': 11, 'show_compose_message': true, - 'show_compact_message': false + 'show_compact_message': true } );