diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index d945c93a815..df813ae4f6a 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -260,6 +260,8 @@ class mail_message(osv.Model): create the expandable message for all parent message read this function is used by message_read """ + # sort for group items + tree = sorted(tree, key=lambda k: k['id']) tree_not = [] # expandable for not show message @@ -323,9 +325,6 @@ class mail_message(osv.Model): 'id': -1 }); - - result = sorted(result, key=lambda k: k['id']) - return result def message_read(self, cr, uid, ids=False, domain=[], level=0, context=None, parent_id=False, limit=None): @@ -352,54 +351,58 @@ class mail_message(osv.Model): tree = [] message_ids = [] record = None + result = [] # select ids if ids and ids!=[None]: for msg in self.browse(cr, uid, ids, context=context): - message_ids.append(msg.id) - - result = [] - for msg in self.browse(cr, uid, message_ids, context=context): - record = self._message_dict_get(cr, uid, msg, context=context) - result.append( record ) + if msg.id not in message_ids: + message_ids.append(msg.id) + record = self._message_dict_get(cr, uid, msg, context=context) + result.append( record ) # key: ID, value: tree if not ids: ids = self.search(cr, uid, domain, context=context, limit=limit) for msg in self.browse(cr, uid, ids, context=context): # if not in tree and not in message_loded list - if msg not in tree and msg.id not in message_loaded_ids : + if msg.id not in message_ids and msg.id not in message_loaded_ids : message_ids.append(msg.id) tree.append(msg) + #try to get parent message try: parent = msg.parent_id parent = parent.parent_id except (orm.except_orm, osv.except_osv): parent = False + # get all parented message if the user have the access while parent and parent.id != parent_id: parent_id = msg.parent_id.id - if msg.parent_id.id not in tree: + if msg.parent_id not in tree and parent_id not in message_loaded_ids: tree.append(parent) # if not in tree and not in message_loded list - if parent.id not in message_loaded_ids : + if parent.id not in message_ids and parent.id not in message_loaded_ids : message_ids.append(parent.id) + #try to get parent message try: parent = msg.parent_id except (orm.except_orm, osv.except_osv): parent = False + else: + parent = False - result = [] + # record the dic of message for msg in self.browse(cr, uid, message_ids, context=context): record = self._message_dict_get(cr, uid, msg, context=context) result.append( record ) + # get the child expandable messages for the tree result = self._message_read_expandable(cr, uid, tree, result, message_loaded_ids, domain, context, parent_id, limit) result = sorted(result, key=lambda k: k['id']) - return result def user_free_attachment(self, cr, uid, context=None): diff --git a/addons/mail/mail_thread_view.xml b/addons/mail/mail_thread_view.xml index d5b46fb3575..2d7cf2ecf58 100644 --- a/addons/mail/mail_thread_view.xml +++ b/addons/mail/mail_thread_view.xml @@ -5,35 +5,35 @@ Inbox mail.wall + 'context': {'default_model': 'res.partner', 'default_is_private': False, 'typeof_thread': 'inbox'} }""/> To: me mail.wall + 'context': {'default_model': 'res.partner', 'default_is_private': False, 'typeof_thread': 'inbox'} }""/> Stared mail.wall + 'context': {'default_model': 'res.partner', 'default_is_private': False, 'typeof_thread': 'stared'} }""/> Archives mail.wall + 'context': {'default_model': 'res.partner', 'default_is_private': False, 'typeof_thread': 'archives'} }""/> Sent mail.wall + 'context': {'default_model': 'res.partner', 'default_is_private': False, 'typeof_thread': 'send'} }""/> diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 295ab4a91a3..8dd42cd2763 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -137,7 +137,7 @@ openerp.mail = function(session) { this.options={}; this.options.thread={}; this.options.thread.show_header_compose = options.options.thread.show_header_compose; - this.options.thread.display_on_flat = options.options.thread.display_on_flat; + this.options.thread.display_on_hierarchy = options.options.thread.display_on_hierarchy; this.options.thread.show_attachment_delete = true; this.options.thread.show_attachment_link = true; @@ -317,7 +317,7 @@ openerp.mail = function(session) { this.$('input[data-id]').remove(); //this.attachment_ids=[]; this.display_attachments(); - if(!this.options.thread.show_header_compose || !this.options.thread.display_on_flat){ + if(!this.options.thread.show_header_compose || !this.options.thread.display_on_hierarchy[0]){ this.$el.hide(); } }, @@ -649,17 +649,15 @@ openerp.mail = function(session) { */ on_message_read_unread: function (event) { event.stopPropagation(); - if($(event.srcElement).hasClass("oe_read")) this.animated_destroy({fadeTime:250}); // if this message is read, all childs message display is read var ids = [this.datasets.id].concat( this.get_child_ids() ); - - if($(event.srcElement).hasClass("oe_read")) { - this.ds_notification.call('set_message_read', [ids,true]); - this.$el.removeClass("oe_mail_unread").addClass("oe_mail_read"); - } else { - this.ds_notification.call('set_message_read', [ids,false]); - this.$el.removeClass("oe_mail_read").addClass("oe_mail_unread"); + var read = $(event.srcElement).hasClass("oe_read"); + this.$el.removeClass("oe_mail_"+(read?"un":"")+"read").addClass("oe_mail_"+(read?"":"un")+"read"); + if( (read && this.options.thread.typeof_thread=='inbox') || + (!read && this.options.thread.typeof_thread=='archives')) { + this.animated_destroy({fadeTime:250}); } + this.ds_notification.call('set_message_read', [ids,read]); return false; }, @@ -783,8 +781,13 @@ openerp.mail = function(session) { * for each click on "show more message" * @param {Number} [expandable_default_number=5] number message show * on begin before the first click on "show more message" - * @param {Boolean} [display_on_flat] display all thread - * on the wall thread level (no hierarchy) + * @param {Array [A,B]} [display_on_hierarchy] display the threads on hierarchy + * for the thread level between A and B. -1 for no begin or no end. + * All thread before A are insert in the root thread. + * All thread after B are insert in parent thread on B level. + * @param {Select} [typeof_thread] inbox/archives/stared/sent + * type of thread and option for user application like animate + * destroy for read/unread * @param {Array} [parents] liked with the parents thread * use with browse, fetch... [O]= top parent */ @@ -804,14 +807,15 @@ openerp.mail = function(session) { 'expandable_number': options.options.thread.expandable_number || 5, 'expandable_default_number': options.options.thread.expandable_default_number || 5, '_expandable_max': options.options.thread.expandable_default_number || 5, - 'display_on_flat': options.options.thread.display_on_flat || false, + 'display_on_hierarchy': options.options.thread.display_on_hierarchy || [0,-1], + 'typeof_thread': options.options.thread.typeof_thread || 'inbox', '_parents': (options.options.thread._parents != undefined ? options.options.thread._parents : []).concat( [this] ) }, 'message' : options.options.message }; // record options and data - this.parent_linked_message= parent.thread!= undefined ? parent : false ; + this.parent_message= parent.thread!= undefined ? parent : false ; var param = options.parameters this.datasets = {}; @@ -821,7 +825,7 @@ openerp.mail = function(session) { this.datasets.parent_id= param.parent_id || false; this.datasets.is_private = param.is_private || false; this.datasets.author_id = param.author_id || false; - this.datasets.thread_level = param.thread_level-1 || 0 + this.datasets.thread_level = param.thread_level+1 || 0 this.datasets.partner_ids = []; for(var i in param.partner_ids){ @@ -850,7 +854,7 @@ openerp.mail = function(session) { this.bind_events(); if(this.options.thread._parents[0]==this){ - this.on_first_thread(); + this.on_root_thread(); } return display_done && compose_done; @@ -869,7 +873,7 @@ openerp.mail = function(session) { /* this method is runing for first parent thread */ - on_first_thread: function(){ + on_root_thread: function(){ var self=this; // fetch and display message, using message_ids if set this.message_fetch(); @@ -883,7 +887,7 @@ openerp.mail = function(session) { this.ComposeMessage.$el.show(); //this.ComposeMessage.set_free_attachments(); } - this.ComposeMessage.is_private=true; + this.ComposeMessage.datasets.is_private=true; var button_fetch = $('