From 2447ed07a75bde52ec644c8236242ac6cb15ea8f Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 29 Oct 2012 16:13:27 +0100 Subject: [PATCH 1/4] [FIX] mail: display vote bzr revid: chm@openerp.com-20121029151327-cptuukjtkrh06bij --- addons/mail/static/src/js/mail.js | 19 +++++++++---------- addons/mail/static/src/xml/mail.xml | 3 +-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 9133e5de257..86211c589bb 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -800,12 +800,12 @@ openerp.mail = function (session) { */ on_vote: function (event) { event.stopPropagation(); - var self=this; - return this.ds_message.call('vote_toggle', [[self.id]]).pipe(function (vote) { - self.has_voted = vote; - self.vote_nb += self.has_voted ? 1 : -1; - self.display_vote(); - }); + return this.ds_message.call('vote_toggle', [[this.id]]).pipe( + _.bind(function (vote) { + this.has_voted = vote; + this.vote_nb += this.has_voted ? 1 : -1; + this.display_vote(); + }, this)); return false; }, @@ -813,10 +813,9 @@ openerp.mail = function (session) { * Display the render of this message's vote */ display_vote: function () { - var self = this; - var vote_element = session.web.qweb.render('mail.thread.message.vote', {'widget': self}); - self.$(".oe_msg_vote:first").remove(); - self.$(".oe_mail_vote_count:first").replaceWith(vote_element); + var vote_element = session.web.qweb.render('mail.thread.message.vote', {'widget': this}); + this.$(".oe_msg_footer:first .oe_mail_vote_count").remove(); + this.$(".oe_msg_footer:first .oe_msg_vote").replaceWith(vote_element); }, /** diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index caa85cd3deb..1a40fbc61ac 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -257,12 +257,11 @@ Template used to display Like/Unlike in a mail.message --> - 8 - + like unlike From 566d7dd3afc38efb2171e829b9aadaf7cd064852 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 30 Oct 2012 11:03:18 +0100 Subject: [PATCH 2/4] [IMP] mail: activate default value for the search view bzr revid: chm@openerp.com-20121030100318-pnvgcm2id034na93 --- addons/mail/mail_message_view.xml | 10 +-- addons/mail/static/src/js/mail.js | 94 +++++++++++++---------------- addons/mail/static/src/xml/mail.xml | 13 ++-- 3 files changed, 55 insertions(+), 62 deletions(-) diff --git a/addons/mail/mail_message_view.xml b/addons/mail/mail_message_view.xml index 93b35797fd5..e265fc76afe 100644 --- a/addons/mail/mail_message_view.xml +++ b/addons/mail/mail_message_view.xml @@ -59,21 +59,24 @@ + - + @@ -84,7 +87,6 @@ form tree,form - {'search_default_to_read_message':True} diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 86211c589bb..2062c2ce615 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -948,16 +948,14 @@ openerp.mail = function (session) { */ on_scroll: function (event) { if (event)event.stopPropagation(); - this.$('.oe_msg_expandable:last'); - - var message = this.messages[this.messages.length-1]; - if (message && message.type=="expandable" && message.max_limit) { - var pos = message.$el.position(); + $last = this.$('> .oe_msg_expandable:last'); + if ($last.hasClass('oe_max_limit')) { + var pos = $last.position(); if (pos.top) { /* bottom of the screen */ var bottom = $(window).scrollTop()+$(window).height()+200; if (bottom > pos.top) { - message.on_expandable(); + $last.find('.oe_msg_fetch_more').click(); } } } @@ -1451,9 +1449,10 @@ openerp.mail = function (session) { bind_events: function () { if (this.context['typeof_thread']!='other') { - $(document).scroll( this.thread.on_scroll ); - $(window).resize( this.thread.on_scroll ); - window.setTimeout( this.thread.on_scroll, 500 ); + $(document).scroll( _.bind(this.thread.on_scroll, this.thread) ); + $(window).resize( _.bind(this.thread.on_scroll, this.thread) ); + this.$el.resize( _.bind(this.thread.on_scroll, this.thread) ); + window.setTimeout( _.bind(this.thread.on_scroll, this.thread), 500 ); } } }); @@ -1556,17 +1555,23 @@ openerp.mail = function (session) { this.options = options || {}; this.options.domain = options.domain || []; this.options.context = options.context || {}; - this.search_results = {'domain': [], 'context': {}, 'groupby': {}} - this.ds_msg = new session.web.DataSetSearch(this, 'mail.message'); + + this.options.defaults = {}; + for (var key in options.context) { + if(key.match(/^search_default_/)) { + this.options.defaults[key.replace(/^search_default_/, '')] = options.context[key]; + } + } }, start: function () { this._super.apply(this, arguments); - var searchview_ready = this.load_searchview({}, false); - var thread_displayed = this.message_render(); - this.options.domain = this.options.domain.concat(this.search_results['domain']); + this.load_searchview(this.options.defaults, false); this.bind_events(); - return $.when(searchview_ready, thread_displayed); + + if(!this.searchview.has_defaults) { + this.message_render(); + } }, /** @@ -1576,10 +1581,14 @@ openerp.mail = function (session) { */ load_searchview: function (defaults, hidden) { var self = this; - this.searchview = new session.web.SearchView(this, this.ds_msg, false, defaults || {}, hidden || false); - return this.searchview.appendTo(this.$('.oe_view_manager_view_search')).then(function () { - self.searchview.on('search_data', self, self.do_searchview_search); - }); + var ds_msg = new session.web.DataSetSearch(self, 'mail.message'); + self.searchview = new session.web.SearchView(self, ds_msg, false, defaults || {}, hidden || false); + self.searchview.appendTo(self.$('.oe_view_manager_view_search')) + .then(function () { self.searchview.on('search_data', self, self.do_searchview_search); }); + if (this.searchview.has_defaults) { + this.searchview.ready.then(this.searchview.do_search); + } + return self.searchview }, /** @@ -1596,10 +1605,11 @@ openerp.mail = function (session) { contexts: contexts || [], group_by_seq: groupbys || [] }).then(function (results) { - self.search_results['context'] = results.context; - self.search_results['domain'] = results.domain; - self.root.destroy(); - return self.message_render(); + if(self.root) { + $('').insertAfter(self.root.$el); + self.root.destroy(); + } + return self.message_render(results); }); }, @@ -1607,13 +1617,12 @@ openerp.mail = function (session) { /** *Create the root thread widget and display this object in the DOM */ - message_render: function (search) { - var domain = this.options.domain.concat(this.search_results['domain']); - var context = _.extend(this.options.context, search&&search.search_results['context'] ? search.search_results['context'] : {}); + message_render: function ( search ) { + var domain = this.options.domain.concat(search && search['domain'] ? search['domain'] : []); + var context = _.extend(this.options.context, search && search['context'] ? search['context'] : {}); this.root = new mail.Widget(this, { 'domain' : domain, 'context' : context, - 'typeof_thread': context['typeof_thread'] || 'other', 'display_indented_thread': 1, 'show_reply_button': 10, 'show_read_unread_button': 11, @@ -1641,23 +1650,11 @@ openerp.mail = function (session) { * Add a link on the top user bar for write a full mail */ session.web.ComposeMessageTopButton = session.web.Widget.extend({ - template:'mail.compose_message.button_top_bar', + template:'mail.ComposeMessageTopButton', - init: function (parent, options) { - this._super.apply(this, options); - this.options = this.options || {}; - this.options.domain = this.options.domain || []; - this.options.context = { - 'default_model': false, - 'default_res_id': 0, - 'default_content_subtype': 'html', - }; - }, - - start: function (parent, params) { - var self = this; - this.$el.on('click', 'button', self.on_compose_message ); - this._super(parent, params); + start: function () { + this.$el.on('click', 'button', this.on_compose_message ); + this._super(); }, on_compose_message: function (event) { @@ -1667,14 +1664,9 @@ openerp.mail = function (session) { res_model: 'mail.compose.message', view_mode: 'form', view_type: 'form', - action_from: 'mail.ThreadComposeMessage', views: [[false, 'form']], target: 'new', - context: _.extend(this.options.context, { - 'default_model': this.context.default_model, - 'default_res_id': this.context.default_res_id, - 'default_content_subtype': 'html', - }), + context: { 'default_content_subtype': 'html' }, }; session.client.action_manager.do_action(action); }, @@ -1682,10 +1674,10 @@ openerp.mail = function (session) { }); session.web.UserMenu = session.web.UserMenu.extend({ - start: function (parent, params) { + start: function () { var render = new session.web.ComposeMessageTopButton(); render.insertAfter(this.$el); - this._super(parent, params); + this._super(); } }); diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 1a40fbc61ac..179d6aae421 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -140,9 +140,7 @@

- News Feed - / - + Email box

@@ -234,11 +232,12 @@ -
+ @@ -247,9 +246,9 @@ mail.compose_message.button_top_bar render of the button on the user bar for open wizard compose message --> - +
- +
From b8a9b420e837cd37aa31fae4fb03ba32cba5bab8 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 30 Oct 2012 11:56:58 +0100 Subject: [PATCH 3/4] [IMP] mail: -typof_thread option, +check_for_destroy method bzr revid: chm@openerp.com-20121030105658-j5k6zctwmx7wwyfu --- addons/mail/mail_thread_view.xml | 10 ++++---- addons/mail/static/src/js/mail.js | 40 ++++++++++++++----------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/addons/mail/mail_thread_view.xml b/addons/mail/mail_thread_view.xml index 07b24725b05..70a0d7a96aa 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.users', 'default_res_id': uid} }""/> To: me mail.wall + 'context': {'default_model': 'res.users', 'default_res_id': uid} }""/> Favorites mail.wall + 'context': {'default_model': 'res.users', 'default_res_id': uid} }""/> Archives mail.wall + 'context': {'default_model': 'res.users', 'default_res_id': uid} }""/> Sent mail.wall + 'context': {'default_model': 'res.users', 'default_res_id': uid} }""/> diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2062c2ce615..0ee6d155ca0 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -731,6 +731,15 @@ openerp.mail = function (session) { return false; }, + /* Check if the message must be destroy and detroy it + * @param {callback} apply function + */ + check_for_destroy: function () { + var domain = mail.ChatterUtils.expand_domain( this.parent_thread.domain ).concat([["id", "=", this.id]]); + this.parent_thread.ds_message.call('message_read', [undefined, domain, [], 0, this.context, this.parent_thread.id]) + .then( _.bind(function (record) { if (!record || !record.length) this.animated_destroy(150); }, this) ); + }, + /*The selected thread and all childs (messages/thread) became read * @param {object} mouse envent */ @@ -738,15 +747,12 @@ openerp.mail = function (session) { event.stopPropagation(); var self=this; - if ( (this.to_read && this.options.typeof_thread == 'inbox') || - (!this.to_read && this.options.typeof_thread == 'archives')) { - this.animated_destroy(150); - } - // if this message is read, all childs message display is read this.ds_notification.call('set_message_read', [ [this.id].concat( this.get_child_ids() ) , this.to_read, this.context]).pipe(function () { self.$el.removeClass(self.to_read ? 'oe_msg_unread':'oe_msg_read').addClass(self.to_read ? 'oe_msg_read':'oe_msg_unread'); self.to_read = !self.to_read; + // check if the message must be display + self.check_for_destroy(); }); return false; }, @@ -831,9 +837,8 @@ openerp.mail = function (session) { button.addClass('oe_starred'); } else { button.removeClass('oe_starred'); - if ( self.options.typeof_thread == 'stared' ) { - self.animated_destroy(150); - } + // check if the message must be display + self.check_for_destroy(); } }); return false; @@ -879,9 +884,6 @@ openerp.mail = function (session) { * @param {Object} [thread] * @param {int} [display_indented_thread] number thread level to indented threads. * other are on flat mode - * @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 */ @@ -1108,7 +1110,7 @@ openerp.mail = function (session) { var thread_level = 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, thread_level, fetch_context, this.context.default_parent_id || undefined]) - .then(callback ? _.bind(callback, this, arguments) : this.proxy('switch_new_message')); + .then(callback ? _.bind(callback, this) : this.proxy('switch_new_message')); }, /** @@ -1364,8 +1366,6 @@ openerp.mail = function (session) { * @param {Object} [context] context of the thread. It should * contain at least default_model, default_res_id. Please refer to * the compose_message widget for more information about it. - * ... @param {Select} [typeof_thread=(mail|stared|archives|send|other)] - * options for destroy message when the user click on a button * @param {Object} [options] *... @param {Number} [truncate_limit=250] number of character to * display before having a "show more" link; note that the text @@ -1389,7 +1389,6 @@ openerp.mail = function (session) { this.search_results = {'domain': [], 'context': {}, 'groupby': {}}; this.options = _.extend({ - 'typeof_thread' : 'inbox', 'display_indented_thread' : -1, 'show_reply_button' : -1, 'show_read_unread_button' : -1, @@ -1448,12 +1447,10 @@ openerp.mail = function (session) { }, bind_events: function () { - if (this.context['typeof_thread']!='other') { - $(document).scroll( _.bind(this.thread.on_scroll, this.thread) ); - $(window).resize( _.bind(this.thread.on_scroll, this.thread) ); - this.$el.resize( _.bind(this.thread.on_scroll, this.thread) ); - window.setTimeout( _.bind(this.thread.on_scroll, this.thread), 500 ); - } + $(document).scroll( _.bind(this.thread.on_scroll, this.thread) ); + $(window).resize( _.bind(this.thread.on_scroll, this.thread) ); + this.$el.resize( _.bind(this.thread.on_scroll, this.thread) ); + window.setTimeout( _.bind(this.thread.on_scroll, this.thread), 500 ); } }); @@ -1514,7 +1511,6 @@ openerp.mail = function (session) { this.root = new mail.Widget(this, { 'domain' : domain, 'context' : this.options.context, - 'typeof_thread': this.options.context['typeof_thread'] || 'other', 'display_indented_thread': -1, 'show_reply_button': 0, 'show_read_unread_button': -1, From 49325c24d2730147c18541a7cca1968445b9f863 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 30 Oct 2012 12:33:56 +0100 Subject: [PATCH 4/4] [IMP] mail: reduce options on js bzr revid: chm@openerp.com-20121030113356-374gjb6zanw4xtsw --- addons/mail/static/src/js/mail.js | 57 ++++++++++++----------------- addons/mail/static/src/xml/mail.xml | 6 +-- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 0ee6d155ca0..d11e610064e 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -145,15 +145,16 @@ openerp.mail = function (session) { this.show_compact_message = false; // data of this compose message - this.attachment_ids = []; this.id = datasets.id; this.model = datasets.model; this.res_model = datasets.res_model; 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.attachment_ids = []; this.parent_thread= parent.messages!= undefined ? parent : false; + this.avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid); this.ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment'); this.show_delete_attachment = true; @@ -439,7 +440,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 : this.options._parents[0]; + this.parent_thread= parent.messages!= undefined ? parent : this.options.root_thread; }, @@ -529,8 +530,8 @@ openerp.mail = function (session) { * display before having a "show more" link; note that the text * will not be truncated if it does not have 110% of the parameter * @param {Boolean} [show_record_name] - *... @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 + *... @param {boolean} [show_reply_button] display the reply button + *... @param {boolean} [show_read_unread_button] display the read/unread button */ init: function (parent, datasets, context) { this._super(parent); @@ -543,7 +544,7 @@ openerp.mail = function (session) { default_parent_id: false }, context || {}); // record options - this.options = datasets.options; + this.options = datasets.options || {}; // data of this message this.id = datasets.id || -1, @@ -566,12 +567,8 @@ openerp.mail = function (session) { this.attachment_ids = datasets.attachment_ids || [], this._date = datasets.date; - - 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 : this.options._parents[0]; + this.parent_thread= parent.messages!= undefined ? parent : this.options.root_thread; this.thread = false; if ( this.id > 0 ) { @@ -735,7 +732,7 @@ openerp.mail = function (session) { * @param {callback} apply function */ check_for_destroy: function () { - var domain = mail.ChatterUtils.expand_domain( this.parent_thread.domain ).concat([["id", "=", this.id]]); + var domain = mail.ChatterUtils.expand_domain( this.options.root_thread.domain ).concat([["id", "=", this.id]]); this.parent_thread.ds_message.call('message_read', [undefined, domain, [], 0, this.context, this.parent_thread.id]) .then( _.bind(function (record) { if (!record || !record.length) this.animated_destroy(150); }, this) ); }, @@ -770,8 +767,8 @@ openerp.mail = function (session) { // goto the wall thread for launch browse if (!options._go_thread_wall) { options._go_thread_wall = true; - for (var i in this.options._parents[0].messages) { - var res=this.options._parents[0].messages[i].browse_message(options); + for (var i in this.options.root_thread.messages) { + var res=this.options.root_thread.messages[i].browse_message(options); if (res) return res; } } @@ -896,7 +893,7 @@ openerp.mail = function (session) { default_parent_id: false }, options.context || {}); this.options = options.options; - this.options._parents = (options.options._parents != undefined ? options.options._parents : []).concat( [this] ); + this.options.root_thread = (options.options.root_thread != undefined ? options.options.root_thread : this); // record options and data this.parent_message= parent.thread!= undefined ? parent : false ; @@ -1031,7 +1028,7 @@ openerp.mail = function (session) { // goto the wall thread for launch browse if (!options._go_thread_wall) { options._go_thread_wall = true; - return this.options._parents[0].browse_thread(options); + return this.options.root_thread.browse_thread(options); } if (this.id==options.id) { @@ -1065,8 +1062,8 @@ openerp.mail = function (session) { * @return message object */ browse_message: function (options) { - if (this.options._parents[0].messages[0]) - return this.options._parents[0].messages[0].browse_message(options); + if (this.options.root_thread.messages[0]) + return this.options.root_thread.messages[0].browse_message(options); }, /** @@ -1110,7 +1107,7 @@ openerp.mail = function (session) { var thread_level = 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, thread_level, fetch_context, this.context.default_parent_id || undefined]) - .then(callback ? _.bind(callback, this) : this.proxy('switch_new_message')); + .then(callback ? _.bind(callback, this, arguments) : this.proxy('switch_new_message')); }, /** @@ -1371,8 +1368,8 @@ openerp.mail = function (session) { * display before having a "show more" link; note that the text * will not be truncated if it does not have 110% of the parameter *... @param {Boolean} [show_record_name] display the name and link for do action - *... @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 + *... @param {boolean} [show_reply_button] display the reply button + *... @param {boolean} [show_read_unread_button] display the read/unread button *... @param {int} [display_indented_thread] number thread level to indented threads. * other are on flat mode *... @param {Boolean} [show_compose_message] allow to display the composer @@ -1390,8 +1387,8 @@ openerp.mail = function (session) { this.options = _.extend({ 'display_indented_thread' : -1, - 'show_reply_button' : -1, - 'show_read_unread_button' : -1, + 'show_reply_button' : false, + 'show_read_unread_button' : false, 'truncate_limit' : 250, 'show_record_name' : false, 'show_compose_message' : false, @@ -1403,12 +1400,6 @@ openerp.mail = function (session) { if (this.display_indented_thread === false) { this.display_indented_thread = -1; } - if (this.show_reply_button === false) { - this.show_reply_button = -1; - } - if (this.show_read_unread_button === false) { - this.show_read_unread_button = -1; - } }, @@ -1512,8 +1503,8 @@ openerp.mail = function (session) { 'domain' : domain, 'context' : this.options.context, 'display_indented_thread': -1, - 'show_reply_button': 0, - 'show_read_unread_button': -1, + 'show_reply_button': false, + 'show_read_unread_button': false, 'show_compose_message': show_compose_message, 'message_ids': message_ids, 'show_compact_message': true, @@ -1620,8 +1611,8 @@ openerp.mail = function (session) { 'domain' : domain, 'context' : context, 'display_indented_thread': 1, - 'show_reply_button': 10, - 'show_read_unread_button': 11, + 'show_reply_button': true, + 'show_read_unread_button': true, 'show_compose_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 179d6aae421..c22a71dde30 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -195,9 +195,9 @@
- X - v - ( + X + v + ( 7