From 38a28e7ae555694901e3a17a9dc04fbf88da4b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Wed, 17 Oct 2012 11:43:22 +0200 Subject: [WIP] openchatter: css and dom refactor bzr revid: fva@openerp.com-20121017094322-h0z9jjuod5q9up1y --- addons/mail/static/src/js/mail.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index d2f2358af5f..f3bf7e9b9fa 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -503,7 +503,7 @@ openerp.mail = function(session) { // record parameters var param = options.parameters; - for(var i in param){ + for(var i in param){ //FIXME this[i] = param[i]; } this.id = param.id || -1; @@ -644,7 +644,7 @@ openerp.mail = function(session) { } ); /*insert thread in parent message*/ - self.thread.appendTo(self.$el.find('div.oe_thread_placeholder')); + self.thread.replace(self.$('.oe_thread_placeholder')); }, animated_destroy: function(options) { @@ -1052,7 +1052,7 @@ openerp.mail = function(session) { 'parameters': message }); } else { - var message = new mail.ThreadMessage(self, { + var message = new mail.ThreadMessage(self, { //FIXME 'domain': message.domain, 'context': { 'default_model': message.model, @@ -1227,7 +1227,7 @@ openerp.mail = function(session) { var thread_displayed = this.message_render(); this.options.domain = this.options.domain.concat(this.search_results['domain']); this.bind_events(); - return (searchview_ready && thread_displayed); + return (searchview_ready && thread_displayed); //FIXME }, /** @@ -1293,7 +1293,7 @@ openerp.mail = function(session) { bind_events: function(){ var self=this; - this.$("button.oe_write_full:first").click(function(){ self.thread.ComposeMessage.on_compose_fullmail(); }); + this.$("button.oe_write_full:first").click(function(){ self.thread.ComposeMessage.on_compose_fullmail(); }); //FIXME this.$("button.oe_write_onwall:first").click(function(){ self.thread.ComposeMessage.$el.toggle(); }); } }); -- cgit v1.2.3 From 09ee80ce68d5e9d48314bcbf1c1a1f18ae31515b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 17 Oct 2012 12:40:26 +0200 Subject: [IMP] mail: deferred bzr revid: chm@openerp.com-20121017104026-zamtldzb0k3s551s --- addons/mail/static/src/js/mail.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 5e4e4d7d689..7025dcb2bd1 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1307,7 +1307,7 @@ openerp.mail = function(session) { var thread_displayed = this.message_render(); this.options.domain = this.options.domain.concat(this.search_results['domain']); this.bind_events(); - return (searchview_ready && thread_displayed); + return $.when(searchview_ready, thread_displayed); }, /** @@ -1377,6 +1377,7 @@ openerp.mail = function(session) { bind_events: function(){ var self=this; this.$("button.oe_write_full:first").click(function(){ self.thread.ComposeMessage.on_compose_fullmail(); }); + this.$("button.oe_write_onwall:first").click(function(){ self.thread.ComposeMessage.$el.toggle(); }); } }); -- cgit v1.2.3 From fc47385ded8680996ecdcaaf622ec27e63514d50 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 17 Oct 2012 15:37:50 +0200 Subject: [IMP]mail: js/dom in progress bzr revid: chm@openerp.com-20121017133750-rqyyoprdkbg5fcom --- addons/mail/static/src/js/mail.js | 201 ++++++++++++++++++++++++-------------- 1 file changed, 125 insertions(+), 76 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index ef687139887..ee59d868746 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -408,7 +408,7 @@ openerp.mail = function(session) { * in the function. */ bind_events: function() { var self = this; - this.$el.on('click', 'a.oe_mail_fetch_more', self.on_expandable); + this.$el.on('click', 'a.oe_msg_fetch_more', self.on_expandable); }, animated_destroy: function(options) { @@ -639,7 +639,7 @@ openerp.mail = function(session) { } ); /*insert thread in parent message*/ - self.thread.replace(self.$('.oe_thread_placeholder')); + self.thread.insertAfter(self.$el); }, animated_destroy: function(options) { @@ -873,19 +873,11 @@ openerp.mail = function(session) { start: function() { this._super.apply(this, arguments); - this.list_ul = this.$('ul.oe_mail_thread_display:first'); this.more_msg = this.$(">.oe_msg_more_message:first"); this.display_user_avatar(); - var display_done = compose_done = false; this.bind_events(); - - if(this.options.thread._parents[0]==this){ - this.on_root_thread(); - } - - return display_done && compose_done; }, instantiate_ComposeMessage: function(){ @@ -896,31 +888,12 @@ openerp.mail = function(session) { 'options': this.options, 'show_attachment_delete': true, }); - this.ComposeMessage.appendTo(this.$(".oe_mail_thread_action:first")); - }, - - /* this method is runing for first parent thread - */ - on_root_thread: function(){ - var self=this; - // fetch and display message, using message_ids if set - this.message_fetch(); - - $(document).scroll( self.on_scroll ); - $(window).resize( self.on_scroll ); - window.setTimeout( self.on_scroll, 500 ); - - $(session.web.qweb.render('mail.wall_no_message', {})).appendTo(this.$('ul.oe_mail_thread_display')); - this.instantiate_ComposeMessage(); - this.ComposeMessage.datasets.is_private=true; - - if(this.options.thread.show_header_compose){ - this.ComposeMessage.$el.show(); - //this.ComposeMessage.set_free_attachments(); + if(this.datasets.thread_level){ + this.ComposeMessage.prependTo(this.$el); + } else { + this.ComposeMessage.appendTo(this.$el); } - - this.$el.addClass("oe_mail_root_thread"); }, /* When the expandable object is visible on screen (with scrolling) @@ -947,8 +920,16 @@ openerp.mail = function(session) { * in the function. */ bind_events: function() { var self = this; - self.$('.oe_mail_compose_textarea .oe_more').click(function () { var p=$(this).parent(); p.find('.oe_more_hidden, .oe_hidden').show(); p.find('.oe_more').hide(); }); - self.$('.oe_mail_compose_textarea .oe_more_hidden').click(function () { var p=$(this).parent(); p.find('.oe_more_hidden, .oe_hidden').hide(); p.find('.oe_more').show(); }); + self.$('.oe_mail_compose_textarea .oe_more').click(function () { + var p=$(this).parent(); + p.find('.oe_more_hidden, .oe_hidden').show(); + p.find('.oe_more').hide(); + }); + self.$('.oe_mail_compose_textarea .oe_more_hidden').click(function () { + var p=$(this).parent(); + p.find('.oe_more_hidden, .oe_hidden').hide(); + p.find('.oe_more').show(); + }); }, /* get all child message/thread id linked @@ -1027,11 +1008,20 @@ openerp.mail = function(session) { on_compose_message: function(){ if(!this.ComposeMessage){ this.instantiate_ComposeMessage(); + } else { + this.ComposeMessage.$el.toggle(); } - this.ComposeMessage.$el.toggle(); return false; }, + /* display the no message on the thread + */ + no_message: function(){ + + $(session.web.qweb.render('mail.wall_no_message', {})).appendTo(this.$el); + + }, + /** Fetch messages * @param {Bool} initial_mode: initial mode: try to use message_data or * message_ids, if nothing available perform a message_read; otherwise @@ -1087,9 +1077,9 @@ openerp.mail = function(session) { // check if the message is already create for(var i in self.messages){ - if(self.messages[i].datasets.id==message.datasets.id){ + if(self.messages[i].datasets.id == message.datasets.id){ self.messages[i].destroy(); - self.messages[i]=self.insert_message(message); + self.messages[i] = self.insert_message(message); return true; } } @@ -1100,7 +1090,7 @@ openerp.mail = function(session) { insert_message: function (message) { var self=this; - this.$("li.oe_wall_no_message").remove(); + this.$('.oe_wall_no_message').remove(); // insert on hierarchy display => insert in self child var thread_messages = self.messages; @@ -1161,19 +1151,19 @@ openerp.mail = function(session) { if(sort){ message.insertBefore(parent_older.$el); } else { - message.insertAfter(parent_older.$el); + message.insertAfter(parent_older.thread.$el); } } else if(parent_newer){ if(sort){ - message.insertAfter(parent_newer.$el); + message.insertAfter(parent_newer.thread.$el); } else { message.insertBefore(parent_newer.$el); } } else { if(sort && message.id > 0){ - message.prependTo(thread.list_ul); + message.prependTo(thread.$el); } else { - message.appendTo(thread.list_ul); + message.appendTo(thread.$el); } } @@ -1197,6 +1187,79 @@ openerp.mail = function(session) { }, }); + /** + * ------------------------------------------------------------ + * Wall Widget + * ------------------------------------------------------------ + * + * This widget handles the display of messages on a Wall. Its main + * use is to receive a context and a domain, and to delegate the message + * fetching and displaying to the Thread widget. + */ + session.web.client_actions.add('mail.Widget', 'session.mail.Widget'); + mail.Widget = session.web.Widget.extend({ + template: 'mail.Widget', + + /** + * @param {Object} parent parent + * @param {Object} [options] + * @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); + this.options = options || {}; + this.options.domain = options.domain || []; + this.options.context = options.context || {}; + this.search_results = {'domain': [], 'context': {}, 'groupby': {}}; + }, + + start: function (options) { + this._super.apply(this, arguments); + return this.message_render(); + }, + + /** + * Display the threads + */ + message_render: function (search) { + this.thread = new mail.Thread(this, { + 'domain' : this.options.domain, + 'context' : this.options.context, + 'options': { + 'thread' :{ + 'use_composer': this.options.use_composer || false, + 'show_header_compose': this.options.show_header_compose || false, + 'typeof_thread': this.options.context.typeof_thread || 'inbox', + 'display_on_thread': this.options.display_on_thread || [0,1] + }, + 'message': { + 'show_reply': this.options.show_reply || [0,0], + 'show_read_unread': this.options.show_read_unread || [0,-1], + 'show_dd_delete': this.options.show_dd_delete || false, + }, + }, + 'datasets': {}, + } + ); + + this.thread.appendTo( this.$el ); + this.thread.no_message(); + this.thread.message_fetch(); + + $(document).scroll( self.on_scroll ); + $(window).resize( self.on_scroll ); + window.setTimeout( self.on_scroll, 500 ); + }, + + bind_events: function(){ + var self=this; + } + }); + /** * ------------------------------------------------------------ @@ -1249,19 +1312,12 @@ openerp.mail = function(session) { this.thread = new mail.Thread(self, { 'domain': domain, 'context': this.options.context, - 'options':{ - 'thread':{ - 'show_header_compose': show_header_compose, - 'use_composer': show_header_compose, - 'display_on_thread':[-1,-1] - }, - 'message':{ - 'show_reply': [-1,-1], - 'show_read_unread': [-1,-1], - 'show_dd_delete': false - } - }, - 'datasets': {}, + 'show_header_compose': show_header_compose, + 'use_composer': show_header_compose, + 'display_on_thread':[-1,-1], + 'show_reply': [-1,-1], + 'show_read_unread': [-1,-1], + 'show_dd_delete': false } ); return this.thread.appendTo( this.$('.oe_mail_wall_threads:first') ); @@ -1350,33 +1406,26 @@ openerp.mail = function(session) { 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'] : {}); - this.thread = new mail.Thread(this, { - 'domain' : domain, - 'context' : context, - 'options': { - 'thread' :{ - 'use_composer': true, - 'show_header_compose': false, - 'typeof_thread': context.typeof_thread || 'inbox', - 'display_on_thread': [0,1] - }, - 'message': { - 'show_reply': [0,0], - 'show_read_unread': [0,-1], - 'show_dd_delete': false, - }, - }, - 'datasets': {}, + this.root = new mail.Widget(this, { + 'domain' : domain, + 'context' : context, + 'use_composer': true, + 'show_header_compose': false, + 'typeof_thread': context.typeof_thread || 'inbox', + 'display_on_thread': [0,1], + 'show_reply': [0,0], + 'show_read_unread': [0,-1], + 'show_dd_delete': false, } ); - return this.thread.appendTo( this.$('.oe_mail_wall_threads:first') ); + return this.root.appendTo( this.$('.oe_mail_wall_threads:first') ); }, bind_events: function(){ var self=this; - this.$("button.oe_write_full:first").click(function(){ self.thread.ComposeMessage.on_compose_fullmail(); }); - this.$("button.oe_write_onwall:first").click(function(){ self.thread.ComposeMessage.$el.toggle(); }); + this.$("button.oe_write_full:first").click(function(){ self.root.thread.ComposeMessage.on_compose_fullmail(); }); + this.$("button.oe_write_onwall:first").click(function(){ self.root.thread.on_compose_message(); }); } }); -- cgit v1.2.3 From 241c53ce3621eb05fee55004ed4c3910c2546bf7 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 17 Oct 2012 16:20:05 +0200 Subject: [IMP]mail: js/dom in progress bzr revid: chm@openerp.com-20121017142005-yoxn406gva3flz3o --- addons/mail/static/src/js/mail.js | 76 +++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 40 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index ee59d868746..6b39fae8dd8 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -134,7 +134,6 @@ 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_thread = options.options.thread.display_on_thread; this.options.thread.show_attachment_delete = true; this.options.thread.show_attachment_link = true; @@ -315,9 +314,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_thread[0]){ - this.$el.hide(); - } + this.$el.hide(); }, /*post a message and fetch the message*/ @@ -476,7 +473,6 @@ 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 {Boolean} [show_dd_delete] * @param {Array [A,B]} [show_reply] display the reply button on the * message for thread level between A and B. -1 for no begin or no end. * @param {Array [A,B]} [show_read_unread] display the read/unread button on the @@ -523,7 +519,6 @@ openerp.mail = function(session) { 'message_ids': options.options.message.message_ids || null, 'message_data': options.options.message.message_data || null, 'show_record_name': options.options.message.show_record_name != undefined ? options.options.message.show_record_name: true, - 'show_dd_delete': options.options.message.show_dd_delete || false, 'truncate_limit': options.options.message.truncate_limit || 250, 'show_reply': options.options.message.show_reply || [0,-1], 'show_read_unread': options.options.message.show_read_unread || [0,-1], @@ -735,7 +730,7 @@ openerp.mail = function(session) { if (!self.datasets.has_voted) { var votes=[]; for(var i in self.datasets.vote_user_ids){ - if(self.datasets.vote_user_ids[i][0]!=self.datasets.session.uid) + if(self.datasets.vote_user_ids[i][0]!=self.session.uid) vote.push(self.datasets.vote_user_ids[i]); } self.datasets.vote_user_ids=votes; @@ -803,8 +798,6 @@ openerp.mail = function(session) { * @param {Object} [options] * @param {Object} [message] read about mail.ThreadMessage object * @param {Object} [thread] - * @param {Boolean} [use_composer] use the advanced composer, or - * the default basic textarea if not set * @param {Number} [expandable_number=5] number message show * for each click on "show more message" * @param {Number} [expandable_default_number=5] number message show @@ -830,8 +823,6 @@ openerp.mail = function(session) { // options this.options={ 'thread' : { - 'show_header_compose': (options.options.thread.show_header_compose != undefined ? options.options.thread.show_header_compose: false), - 'use_composer': options.options.thread.use_composer || false, '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, @@ -1189,10 +1180,10 @@ openerp.mail = function(session) { /** * ------------------------------------------------------------ - * Wall Widget + * mail : root Widget * ------------------------------------------------------------ * - * This widget handles the display of messages on a Wall. Its main + * This widget handles the display of messages with thread options. Its main * use is to receive a context and a domain, and to delegate the message * fetching and displaying to the Thread widget. */ @@ -1202,12 +1193,25 @@ openerp.mail = function(session) { /** * @param {Object} parent parent + * @param {Array} [domain] + * @param {Object} [context] context of the thread. It should + * contain at least default_model, default_res_id. Please refer to + * the ComposeMessage 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 {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. + *... @param {Number} [truncate_limit=250] number of character to + * 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 {Array [A,B]} [show_reply] display the reply button on the + * message for thread level between A and B. -1 for no begin or no end. + *... @param {Array [A,B]} [show_read_unread] display the read/unread button on the + * message for thread level between A and B. -1 for no begin or no end. + *... @param {Array [A,B]} [display_on_thread] display the threads (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. */ init: function (parent, options) { this._super(parent); @@ -1219,7 +1223,8 @@ openerp.mail = function(session) { start: function (options) { this._super.apply(this, arguments); - return this.message_render(); + this.message_render(); + this.bind_events(); }, /** @@ -1231,15 +1236,14 @@ openerp.mail = function(session) { 'context' : this.options.context, 'options': { 'thread' :{ - 'use_composer': this.options.use_composer || false, - 'show_header_compose': this.options.show_header_compose || false, - 'typeof_thread': this.options.context.typeof_thread || 'inbox', + 'typeof_thread': this.options.typeof_thread || 'inbox', 'display_on_thread': this.options.display_on_thread || [0,1] }, 'message': { 'show_reply': this.options.show_reply || [0,0], 'show_read_unread': this.options.show_read_unread || [0,-1], - 'show_dd_delete': this.options.show_dd_delete || false, + 'truncate_limit': this.options.truncate_limit || 250, + 'show_record_name': this.options.show_record_name || false, }, }, 'datasets': {}, @@ -1249,14 +1253,14 @@ openerp.mail = function(session) { this.thread.appendTo( this.$el ); this.thread.no_message(); this.thread.message_fetch(); - - $(document).scroll( self.on_scroll ); - $(window).resize( self.on_scroll ); - window.setTimeout( self.on_scroll, 500 ); }, bind_events: function(){ - var self=this; + if(this.options.context.typeof_thread!='other'){ + $(document).scroll( this.thread.on_scroll ); + $(window).resize( this.thread.on_scroll ); + window.setTimeout( this.thread.on_scroll, 500 ); + } } }); @@ -1302,24 +1306,20 @@ openerp.mail = function(session) { default_is_private: false }); // update domain var domain = this.options.domain.concat([['model', '=', this.view.model], ['res_id', '=', this.view.datarecord.id]]); - // create and render Thread widget - var show_header_compose = this.view.is_action_enabled('edit') || - (this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value()); - + if(this.thread){ this.thread.destroy(); } this.thread = new mail.Thread(self, { 'domain': domain, 'context': this.options.context, - 'show_header_compose': show_header_compose, - 'use_composer': show_header_compose, + 'typeof_thread': this.options.context.typeof_thread || 'other', 'display_on_thread':[-1,-1], 'show_reply': [-1,-1], 'show_read_unread': [-1,-1], - 'show_dd_delete': false } ); + return this.thread.appendTo( this.$('.oe_mail_wall_threads:first') ); }, }); @@ -1409,17 +1409,13 @@ openerp.mail = function(session) { this.root = new mail.Widget(this, { 'domain' : domain, 'context' : context, - 'use_composer': true, - 'show_header_compose': false, - 'typeof_thread': context.typeof_thread || 'inbox', + 'typeof_thread': context.typeof_thread || 'other', 'display_on_thread': [0,1], 'show_reply': [0,0], 'show_read_unread': [0,-1], - 'show_dd_delete': false, } ); return this.root.appendTo( this.$('.oe_mail_wall_threads:first') ); - }, bind_events: function(){ -- cgit v1.2.3 From de47c4cb526af08382eda3ccb945256682b54337 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 17 Oct 2012 17:03:27 +0200 Subject: [IMP]mail: js/dom in progress bzr revid: chm@openerp.com-20121017150327-eo8z8kqaa2dnoc10 --- addons/mail/static/src/js/mail.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 6b39fae8dd8..02b8479b0fc 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -881,9 +881,9 @@ openerp.mail = function(session) { }); if(this.datasets.thread_level){ - this.ComposeMessage.prependTo(this.$el); - } else { this.ComposeMessage.appendTo(this.$el); + } else { + this.ComposeMessage.prependTo(this.$el); } }, @@ -1142,11 +1142,11 @@ openerp.mail = function(session) { if(sort){ message.insertBefore(parent_older.$el); } else { - message.insertAfter(parent_older.thread.$el); + message.insertAfter(parent_older.thread ? parent_older.thread.$el : parent_older.$el); } } else if(parent_newer){ if(sort){ - message.insertAfter(parent_newer.thread.$el); + message.insertAfter(parent_newer.thread ? parent_newer.thread.$el : parent_newer.$el); } else { message.insertBefore(parent_newer.$el); } -- cgit v1.2.3 From 81bc720be8c1915f8b8a9d172f06e5309adf0d47 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 17 Oct 2012 17:09:41 +0200 Subject: [IMP]mail: js/dom in progress bzr revid: chm@openerp.com-20121017150941-bqwwxndhiytcu3pu --- addons/mail/static/src/js/mail.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 02b8479b0fc..62de7bf3842 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -136,7 +136,6 @@ openerp.mail = function(session) { this.options.thread={}; this.options.thread.display_on_thread = options.options.thread.display_on_thread; this.options.thread.show_attachment_delete = true; - this.options.thread.show_attachment_link = true; this.parent_thread= parent.messages!= undefined ? parent : false; @@ -161,11 +160,11 @@ openerp.mail = function(session) { var self = this; var render = $(session.web.qweb.render('mail.thread.message.attachments', {'widget': self})); if(!this.list_attachment){ - this.$('.oe_mail_compose_attachment_list').replaceWith( render ); + this.$('.oe_msg_attachment_list').replaceWith( render ); } else { this.list_attachment.replaceWith( render ); } - this.list_attachment = this.$("ul.oe_msg_attachments"); + this.list_attachment = this.$(".oe_msg_attachments"); // event: delete an attachment this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete); @@ -602,7 +601,7 @@ openerp.mail = function(session) { }, expender: function(){ - this.$('div.oe_msg_body:first').expander({ + this.$('.oe_msg_body:first').expander({ slicePoint: this.options.truncate_limit, expandText: 'read more', userCollapseText: '[^]', -- cgit v1.2.3 From e33bcf5e0256198dd77aa385f8d8e98d8b7b7be9 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 17 Oct 2012 17:17:15 +0200 Subject: [IMP]mail: js/dom ok bzr revid: chm@openerp.com-20121017151715-hh08mpd57dcj6o2d --- addons/mail/static/src/js/mail.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 62de7bf3842..d58ac1cd8af 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -148,10 +148,7 @@ openerp.mail = function(session) { start: function(){ this.display_attachments(); this.bind_events(); - - //load avatar img - var user_avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid); - this.$('img.oe_mail_icon').attr('src', user_avatar); + this.display_user_avatar(); }, /* upload the file on the server, add in the attachments list and reload display @@ -353,6 +350,11 @@ openerp.mail = function(session) { return true; } }, + + display_user_avatar: function () { + var avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid); + return this.$('img.oe_msg_icon').attr('src', avatar); + }, }); /** @@ -862,11 +864,6 @@ openerp.mail = function(session) { start: function() { this._super.apply(this, arguments); - - this.more_msg = this.$(">.oe_msg_more_message:first"); - - this.display_user_avatar(); - this.bind_events(); }, @@ -1159,11 +1156,6 @@ openerp.mail = function(session) { return message }, - - display_user_avatar: function () { - var avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid); - return this.$('img.oe_mail_icon').attr('src', avatar); - }, /* Send the records to his parent thread */ switch_new_message: function(records) { -- cgit v1.2.3 From b1f8696c15f7c5c9172f3b70d815a7c8b9a67ed0 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 18 Oct 2012 10:04:11 +0200 Subject: [IMP] mail, openchatter: textarea compact/expandable bzr revid: chm@openerp.com-20121018080411-xggdwzkvrs7zeojn --- addons/mail/static/src/js/mail.js | 73 +++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 26 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index d58ac1cd8af..7f18f650dae 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -106,10 +106,14 @@ openerp.mail = function(session) { * * This widget handles the display of a form to compose a new message. * This form is a mail.compose.message form_view. - */ + * On first time : display a compact textarea but is not the compose form. + * When the user focus this box, the compose message is intantiate and + * with focus on the textarea. + */ mail.ThreadComposeMessage = session.web.Widget.extend({ - template: 'mail.compose_message', + template: 'mail.compose_message.compact', + // expandable view : 'mail.compose_message' /** * @param {Object} parent parent @@ -130,7 +134,8 @@ openerp.mail = function(session) { 'model': options.datasets.model, 'res_model': options.datasets.res_model, 'is_private': options.datasets.is_private || false, - 'partner_ids': options.datasets.partner_ids || [] + 'partner_ids': options.datasets.partner_ids || [], + 'avatar': mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid), }; this.options={}; this.options.thread={}; @@ -148,7 +153,6 @@ openerp.mail = function(session) { start: function(){ this.display_attachments(); this.bind_events(); - this.display_user_avatar(); }, /* upload the file on the server, add in the attachments list and reload display @@ -166,6 +170,9 @@ openerp.mail = function(session) { // event: delete an attachment this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete); }, + + /* when a user click on the upload button, send file read on_attachment_loaded + */ on_attachment_change: function (event) { event.stopPropagation(); var self = this; @@ -205,6 +212,8 @@ openerp.mail = function(session) { } }, + /* when the file is uploaded + */ on_attachment_loaded: function (event, result) { //session.web.unblockUI(); for(var i in this.datasets.attachment_ids){ @@ -223,6 +232,7 @@ openerp.mail = function(session) { $input.after($input.clone(true)).remove(); this.$(".oe_attachment_file").show(); }, + /* unlink the file on the server and reload display */ on_attachment_delete: function (event) { @@ -270,6 +280,7 @@ openerp.mail = function(session) { this.$el.on('click', 'a.oe_cancel', self.on_cancel ); this.$el.on('click', 'button.oe_post', function(){self.on_message_post()} ); this.$el.on('click', 'button.oe_full', function(){self.on_compose_fullmail()} ); + self.$el.on('focus', 'textarea.oe_compact', self.on_compose_expandable); }, on_compose_fullmail: function(){ @@ -351,9 +362,21 @@ openerp.mail = function(session) { } }, - display_user_avatar: function () { - var avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid); - return this.$('img.oe_msg_icon').attr('src', avatar); + /* convert the compact mode into the compose message + */ + on_compose_expandable: function(){ + var $render = $(session.web.qweb.render('mail.compose_message', {'widget': this})); + this.$el.replaceWith( $render ); + this.$el = $render; + this.$('textarea').focus(); + }, + + /* convert the compact mode into the compose message + */ + on_compose_compact: function(){ + var $render = $(session.web.qweb.render('mail.compose_message.compact', {'widget': this})); + this.$el.replaceWith( $render ); + this.$el = $render; }, }); @@ -864,11 +887,11 @@ openerp.mail = function(session) { start: function() { this._super.apply(this, arguments); + this.instantiate_ComposeMessage(); this.bind_events(); }, instantiate_ComposeMessage: function(){ - // add message composition form view this.ComposeMessage = new mail.ThreadComposeMessage(this,{ 'context': this.context, 'datasets': this.datasets, @@ -879,6 +902,7 @@ openerp.mail = function(session) { if(this.datasets.thread_level){ this.ComposeMessage.appendTo(this.$el); } else { + // root view this.ComposeMessage.prependTo(this.$el); } }, @@ -907,16 +931,20 @@ openerp.mail = function(session) { * in the function. */ bind_events: function() { var self = this; - self.$('.oe_mail_compose_textarea .oe_more').click(function () { - var p=$(this).parent(); - p.find('.oe_more_hidden, .oe_hidden').show(); - p.find('.oe_more').hide(); - }); - self.$('.oe_mail_compose_textarea .oe_more_hidden').click(function () { - var p=$(this).parent(); - p.find('.oe_more_hidden, .oe_hidden').hide(); - p.find('.oe_more').show(); - }); + self.$el.on('click', '.oe_mail_list_recipients .oe_more', self.on_show_recipients); + self.$el.on('click', '.oe_mail_compose_textarea .oe_more_hidden', self.on_hide_recipients); + }, + + on_show_recipients: function(){ + var p=$(this).parent(); + p.find('.oe_more_hidden, .oe_hidden').show(); + p.find('.oe_more').hide(); + }, + + on_hide_recipients: function(){ + var p=$(this).parent(); + p.find('.oe_more_hidden, .oe_hidden').hide(); + p.find('.oe_more').show(); }, /* get all child message/thread id linked @@ -993,20 +1021,13 @@ openerp.mail = function(session) { /* this function is launch when a user click on "Reply" button */ on_compose_message: function(){ - if(!this.ComposeMessage){ - this.instantiate_ComposeMessage(); - } else { - this.ComposeMessage.$el.toggle(); - } - return false; + this.ComposeMessage.on_compose_expandable(); }, /* display the no message on the thread */ no_message: function(){ - $(session.web.qweb.render('mail.wall_no_message', {})).appendTo(this.$el); - }, /** Fetch messages -- cgit v1.2.3 From aa472b8f9528874e6e6744060fa46680be54a5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Thu, 18 Oct 2012 14:02:53 +0200 Subject: [FIX] mail: composition button bindings + annoying button commented out bzr revid: fva@openerp.com-20121018120253-mc260x4ljfzrhrsh --- addons/mail/static/src/js/mail.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 7f18f650dae..8e1be70e459 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -369,6 +369,7 @@ openerp.mail = function(session) { this.$el.replaceWith( $render ); this.$el = $render; this.$('textarea').focus(); + this.bind_events(); }, /* convert the compact mode into the compose message @@ -377,6 +378,7 @@ openerp.mail = function(session) { var $render = $(session.web.qweb.render('mail.compose_message.compact', {'widget': this})); this.$el.replaceWith( $render ); this.$el = $render; + this.bind_events(); }, }); -- cgit v1.2.3 From 8bee0d228191f2985f9f240b6090c93271050776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Thu, 18 Oct 2012 15:50:50 +0200 Subject: [IMP] mail: the css doesn't makes your eyes bleed anymore bzr revid: fva@openerp.com-20121018135050-ihwzxb5f26d927oq --- addons/mail/static/src/js/mail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8e1be70e459..d2a4509ffc3 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -695,7 +695,7 @@ openerp.mail = function(session) { // if this message is read, all childs message display is read var ids = [this.datasets.id].concat( this.get_child_ids() ); var read = $(event.srcElement).hasClass("oe_read"); - this.$el.removeClass("oe_mail_" + (read?"un":"") + "read").addClass("oe_mail_" + (read?"":"un") + "read"); + this.$el.removeClass(read ? 'oe_msg_unread':'oe_msg_read').addClass(read ? 'oe_msg_read':'oe_msg_unread'); if( (read && this.options.thread.typeof_thread == 'inbox') || (!read && this.options.thread.typeof_thread == 'archives')) { -- cgit v1.2.3 From 0a210d1a353ec565badb81632110aa7507f5c170 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 18 Oct 2012 18:39:23 +0200 Subject: [IMP] mail: improve js for dom css bzr revid: chm@openerp.com-20121018163923-yk2splqzvnr02q9g --- addons/mail/static/src/js/mail.js | 306 ++++++++++++++++---------------------- 1 file changed, 127 insertions(+), 179 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8e1be70e459..f57f77ce34e 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -121,26 +121,24 @@ openerp.mail = function(session) { * @param {Object} [context] context passed to the * mail.compose.message DataSetSearch. Please refer to this model * for more details about fields and default values. - * @param {Boolean} [show_attachment_delete] */ - init: function (parent, options) { + init: function (parent, datasets, options) { var self = this; this._super(parent); this.context = options.context || {}; this.datasets = { 'attachment_ids' : [], - 'id': options.datasets.id, - 'model': options.datasets.model, - 'res_model': options.datasets.res_model, - 'is_private': options.datasets.is_private || false, - 'partner_ids': options.datasets.partner_ids || [], + 'id': datasets.id, + 'model': datasets.model, + 'res_model': datasets.res_model, + 'is_private': datasets.is_private || false, + 'partner_ids': datasets.partner_ids || [], 'avatar': mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid), }; this.options={}; - this.options.thread={}; - this.options.thread.display_on_thread = options.options.thread.display_on_thread; - this.options.thread.show_attachment_delete = true; + this.options.display_indented_thread = options.options.display_indented_thread || -1; + this.options.show_attachment_delete = true; this.parent_thread= parent.messages!= undefined ? parent : false; @@ -352,7 +350,7 @@ openerp.mail = function(session) { false, this.context.default_parent_id, attachments, - _.extend(this.parent_thread.context, {'message_loaded':[this.datasets.id||0].concat( self.parent_thread.options.thread._parents[0].get_child_ids() )})] + _.extend(this.parent_thread.context, {'message_loaded':[this.datasets.id||0].concat( self.parent_thread.options._parents[0].get_child_ids() )})] ).then(function(records){ self.parent_thread.switch_new_message(records); self.datasets.attachment_ids=[]; @@ -398,7 +396,7 @@ openerp.mail = function(session) { mail.ThreadExpandable = session.web.Widget.extend({ template: 'mail.thread.expandable', - init: function(parent, options) { + init: function(parent, datasets, options) { this._super(parent); this.domain = options.domain || []; this.context = _.extend({ @@ -407,17 +405,17 @@ openerp.mail = function(session) { default_parent_id: false }, options.context || {}); this.datasets = { - 'id' : options.datasets.id || -1, - 'model' : options.datasets.model || false, - 'parent_id' : options.datasets.parent_id || false, - 'nb_messages' : options.datasets.nb_messages || 0, + 'id' : datasets.id || -1, + 'model' : datasets.model || false, + 'parent_id' : datasets.parent_id || false, + 'nb_messages' : datasets.nb_messages || 0, 'type' : 'expandable', - 'max_limit' : options.datasets.max_limit || false, + 'max_limit' : datasets.max_limit || false, 'flag_used' : false, }; // record options and data - this.parent_thread= parent.messages!= undefined ? parent : options.options.thread._parents[0] ; + this.parent_thread= parent.messages!= undefined ? parent : options.options._parents[0] ; }, @@ -499,16 +497,13 @@ 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 {Array [A,B]} [show_reply] display the reply button on the - * message for thread level between A and B. -1 for no begin or no end. - * @param {Array [A,B]} [show_read_unread] display the read/unread button on the - * message for thread level between A and B. -1 for no begin or no end. + *... @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, options) { + init: function(parent, datasets, options) { this._super(parent); // record datasets - var param = options.datasets; this.datasets = _.extend({ 'id' : -1, 'model' : false, @@ -528,8 +523,8 @@ openerp.mail = function(session) { 'to_read' : true, 'author_id' : [], 'attachment_ids' : [], - }, param || {}); - this.datasets._date = param.date; + }, datasets || {}); + this.datasets._date = datasets.date; // record domain and context this.domain = options.domain || []; @@ -539,28 +534,20 @@ openerp.mail = function(session) { default_parent_id: false }, options.context || {}); // record options - this.options={ - 'thread' : options.options.thread, - 'message' : { - 'message_ids': options.options.message.message_ids || null, - 'message_data': options.options.message.message_data || null, - 'show_record_name': options.options.message.show_record_name != undefined ? options.options.message.show_record_name: true, - 'truncate_limit': options.options.message.truncate_limit || 250, - 'show_reply': options.options.message.show_reply || [0,-1], - 'show_read_unread': options.options.message.show_read_unread || [0,-1], - } - }; - - this.datasets.show_reply = this.options.message.show_reply[0]>=0 && - this.options.message.show_reply[0]<=this.datasets.thread_level && - (this.options.message.show_reply[1]<0 || this.options.message.show_reply[1]>=this.datasets.thread_level); + this.options = _.extend(options.options, { + 'message_ids': options.options.message_ids || null, + 'message_data': options.options.message_data || null, + 'show_record_name': options.options.show_record_name != undefined ? options.options.show_record_name: true, + 'truncate_limit': options.options.truncate_limit || 250, + 'show_reply_button': options.options.show_reply_button || -1, + 'show_read_unread_button': options.options.show_read_unread_button || -1 + }); - this.datasets.show_read_unread = this.options.message.show_read_unread[0]>=0 && - this.options.message.show_read_unread[0]<=this.datasets.thread_level && - (this.options.message.show_read_unread[1]<0 || this.options.message.show_read_unread[1]>=this.datasets.thread_level); + this.datasets.show_reply_button = this.options.show_reply_button>this.datasets.thread_level; + this.datasets.show_read_unread_button = this.options.show_read_unread_button>this.datasets.thread_level; // record options and data - this.parent_thread= parent.messages!= undefined ? parent : options.options.thread._parents[0]; + this.parent_thread= parent.messages!= undefined ? parent : options.options._parents[0]; this.thread = false; if( this.datasets.id > 0 ) { @@ -645,18 +632,14 @@ openerp.mail = function(session) { } /*create thread*/ - self.thread = new mail.Thread(self, { + self.thread = new mail.Thread(self, self.datasets, { 'domain': self.domain, 'context':{ 'default_model': self.datasets.model, 'default_res_id': self.datasets.res_id, 'default_parent_id': self.datasets.id }, - 'options': { - 'thread' : self.options.thread, - 'message' : self.options.message - }, - 'datasets': self.datasets + 'options': self.options } ); /*insert thread in parent message*/ @@ -697,8 +680,8 @@ openerp.mail = function(session) { 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')) { + if( (read && this.options.typeof_thread == 'inbox') || + (!read && this.options.typeof_thread == 'archives')) { this.animated_destroy({fadeTime:250}); } @@ -717,8 +700,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.thread._parents[0].messages){ - var res=this.options.thread._parents[0].messages[i].browse_message(options); + for(var i in this.options._parents[0].messages){ + var res=this.options._parents[0].messages[i].browse_message(options); if(res) return res; } } @@ -788,7 +771,7 @@ openerp.mail = function(session) { button.addClass('oe_stared'); } else { button.removeClass('oe_stared'); - if( self.options.thread.typeof_thread == 'stared' ) { + if( self.options.typeof_thread == 'stared' ) { self.animated_destroy({fadeTime:250}); } } @@ -828,17 +811,15 @@ 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 {Array [A,B]} [display_on_thread] display the threads (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 {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 */ - init: function(parent, options) { + init: function(parent, datasets, options) { this._super(parent); this.domain = options.domain || []; this.context = _.extend({ @@ -847,36 +828,35 @@ openerp.mail = function(session) { default_parent_id: false }, options.context || {}); // options - this.options={ - 'thread' : { - '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_thread': options.options.thread.display_on_thread || [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 - }; + this.options = _.extend(options.options, { + 'expandable_number': options.options.expandable_number || 5, + 'expandable_default_number': options.options.expandable_default_number || 5, + '_expandable_max': options.options.expandable_default_number || 5, + 'display_indented_thread': options.options.display_indented_thread || -1, + 'show_reply_button': options.options.show_reply_button || -1, + 'typeof_thread': options.options.typeof_thread || 'inbox', + '_parents': (options.options._parents != undefined ? options.options._parents : []).concat( [this] ) + }); // record options and data this.parent_message= parent.thread!= undefined ? parent : false ; - var param = options.datasets // datasets and internal vars this.datasets = { - 'id' : param.id || false, - 'model' : param.model || false, - 'parent_id' : param.parent_id || false, - 'is_private' : param.is_private || false, - 'author_id' : param.author_id || false, - 'thread_level' : (param.thread_level+1) || 0, + 'id' : datasets.id || false, + 'model' : datasets.model || false, + 'parent_id' : datasets.parent_id || false, + 'is_private' : datasets.is_private || false, + 'author_id' : datasets.author_id || false, + 'thread_level' : (datasets.thread_level+1) || 0, 'partner_ids' : [] }; - for(var i in param.partner_ids){ - if(param.partner_ids[i][0]!=(param.author_id ? param.author_id[0] : -1)){ - this.datasets.partner_ids.push(param.partner_ids[i]); + this.datasets.show_composeform = this.options.show_reply_button>this.datasets.thread_level; + + for(var i in datasets.partner_ids){ + if(datasets.partner_ids[i][0]!=(datasets.author_id ? datasets.author_id[0] : -1)){ + this.datasets.partner_ids.push(datasets.partner_ids[i]); } } @@ -889,16 +869,16 @@ openerp.mail = function(session) { start: function() { this._super.apply(this, arguments); - this.instantiate_ComposeMessage(); + if(this.datasets.show_composeform){ + this.instantiate_ComposeMessage(); + } this.bind_events(); }, instantiate_ComposeMessage: function(){ - this.ComposeMessage = new mail.ThreadComposeMessage(this,{ + this.ComposeMessage = new mail.ThreadComposeMessage(this, this.datasets, { 'context': this.context, - 'datasets': this.datasets, 'options': this.options, - 'show_attachment_delete': true, }); if(this.datasets.thread_level){ @@ -907,6 +887,7 @@ openerp.mail = function(session) { // root view this.ComposeMessage.prependTo(this.$el); } + this.ComposeMessage.$el.hide(); }, /* When the expandable object is visible on screen (with scrolling) @@ -985,7 +966,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.thread._parents[0].browse_thread(options); + return this.options._parents[0].browse_thread(options); } if(this.datasets.id==options.id){ @@ -1016,8 +997,8 @@ openerp.mail = function(session) { * @return thread object */ browse_message: function(options){ - if(this.options.thread._parents[0].messages[0]) - return this.options.thread._parents[0].messages[0].browse_message(options); + if(this.options._parents[0].messages[0]) + return this.options._parents[0].messages[0].browse_message(options); }, /* this function is launch when a user click on "Reply" button @@ -1043,13 +1024,13 @@ openerp.mail = function(session) { var self = this; // initial mode: try to use message_data or message_ids - if (initial_mode && this.options.thread.message_data) { + if (initial_mode && this.options.message_data) { return this.create_message_object(this.options.message_data); } // domain and context: options + additional fetch_domain = replace_domain ? replace_domain : this.domain; fetch_context = replace_context ? replace_context : this.context; - fetch_context.message_loaded= [this.datasets.id||0].concat( self.options.thread._parents[0].get_child_ids() ); + fetch_context.message_loaded= [this.datasets.id||0].concat( self.options._parents[0].get_child_ids() ); return this.ds_message.call('message_read', [ids, fetch_domain, 0, fetch_context, this.context.default_parent_id || undefined] ).then(function (records) { self.switch_new_message(records); }); @@ -1061,28 +1042,22 @@ openerp.mail = function(session) { var self = this; if(data.type=='expandable'){ - var message = new mail.ThreadExpandable(self, { + 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.datasets.id }, - 'datasets': data }); } else { - var message = new mail.ThreadMessage(self, { + var message = new mail.ThreadMessage(self, _.extend(data, {'thread_level': self.datasets.thread_level}), { 'domain': data.domain, 'context': { 'default_model': data.model, 'default_res_id': data.res_id, 'default_parent_id': data.id }, - 'options':{ - 'thread': self.options.thread, - 'message': self.options.message - }, - 'datasets': _.extend(data, {'thread_level': self.datasets.thread_level}) + 'options': self.options }); - var data = _.extend(data, {'thread_level': self.datasets.thread_level}); } // check if the message is already create @@ -1100,83 +1075,66 @@ openerp.mail = function(session) { insert_message: function (message) { var self=this; + this.ComposeMessage.$el.show(); + this.$('.oe_wall_no_message').remove(); // insert on hierarchy display => insert in self child var thread_messages = self.messages; var thread = self; - var flat = false; - var hierarchy = self.options.thread.display_on_thread; - if( hierarchy[0] < 0 || - hierarchy[0] > self.datasets.thread_level || - (hierarchy[1]>0 && hierarchy[1] < self.datasets.thread_level) ) { - - var flat = true; - - if(hierarchy[0]<0){ - - // all is in flat mode - thread = self.options.thread._parents[0]; - var nb_thread_level = null; - - } else if(hierarchy[0] > self.datasets.thread_level) { - - // list all childs messages for flat display before the hierarchy - thread = self.options.thread._parents[0]; - var nb_thread_level = hierarchy[0]; - - } else if(hierarchy[1] < self.datasets.thread_level) { - - // list all childs messages for flat display after the hierarchy - thread = self.options.thread._parents[hierarchy[1]]; - var nb_thread_level = hierarchy[1]>0 ? hierarchy[1]-hierarchy[0] : null; - } else { - - thread = self.options.thread._parents[0]; - var nb_thread_level = null; - } - + if( self.options.display_indented_thread < self.datasets.thread_level ) { + var thread = self.options._parents[self.options.display_indented_thread] || self.options._parents[0]; var thread_messages = []; - _(thread.get_childs( nb_thread_level )).each(function (val, key) { thread_messages.push(val.parent_message); }); + _(thread.get_childs()).each(function (val, key) { thread_messages.push(val.parent_message); }); } // check older and newer message for insert var parent_newer = false; var parent_older = false; - if ( message.datasets.id > 0 ){ - for(var i in thread_messages){ - if(thread_messages[i].datasets.id > message.datasets.id){ - if(!parent_newer || parent_newer.datasets.id>=thread_messages[i].datasets.id) - parent_newer = thread_messages[i]; - } else if(thread_messages[i].datasets.id>0 && thread_messages[i].datasets.id < message.datasets.id) { - if(!parent_older || parent_older.id message.datasets.id && message.datasets.id > 0) || + thread_messages[i].datasets.id < 0){ + if(!parent_newer || + thread_messages[i].datasets.id < 0 || + parent_newer.datasets.id >= thread_messages[i].datasets.id) { + parent_newer = thread_messages[i]; + } + } else if((thread_messages[i].datasets.id > 0 && thread_messages[i].datasets.id < message.datasets.id) || message.datasets.id < 0) { + if(!parent_older || + parent_older.datasets.id < thread_messages[i].datasets.id) { + parent_older = thread_messages[i]; } } } - var sort = self.datasets.thread_level==0 || (flat && self.datasets.thread_level>=1); + var sort = self.datasets.thread_level; if(parent_older){ if(sort){ - message.insertBefore(parent_older.$el); - } else { message.insertAfter(parent_older.thread ? parent_older.thread.$el : parent_older.$el); + } else { + message.insertBefore(parent_older.$el); } } else if(parent_newer){ - if(sort){ - message.insertAfter(parent_newer.thread ? parent_newer.thread.$el : parent_newer.$el); - } else { + if(sort || parent_newer.datasets.id<0){ message.insertBefore(parent_newer.$el); + } else { + message.insertAfter(parent_newer.thread ? parent_newer.thread.$el : parent_newer.$el); } } else { - if(sort && message.id > 0){ + if(sort) { message.prependTo(thread.$el); } else { message.appendTo(thread.$el); } } + // must be improve by CHM (temporary test for DOM) + self.options._parents[0].$('.oe_msg_comment:first, .oe_thread .oe_msg_comment:first').addClass("oe_msg_first"); + self.options._parents[0].$('.oe_thread:has(.oe_msg_comment:visible) + .oe_msg').addClass("oe_msg_group_first"); + self.options._parents[0].$('.oe_msg_comment:last, .oe_thread .oe_msg_comment:last').addClass("oe_msg_last"); + self.options._parents[0].$('.oe_thread:not(:has(.oe_msg:visible)) ~ .oe_thread:has(.oe_thread .oe_msg:visible)').addClass("oe_msg_group_last"); + return message }, @@ -1218,14 +1176,10 @@ 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 {Array [A,B]} [show_reply] display the reply button on the - * message for thread level between A and B. -1 for no begin or no end. - *... @param {Array [A,B]} [show_read_unread] display the read/unread button on the - * message for thread level between A and B. -1 for no begin or no end. - *... @param {Array [A,B]} [display_on_thread] display the threads (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 {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 {int} [display_indented_thread] number thread level to indented threads. + * other are on flat mode */ init: function (parent, options) { this._super(parent); @@ -1245,24 +1199,18 @@ openerp.mail = function(session) { * Display the threads */ message_render: function (search) { - this.thread = new mail.Thread(this, { - 'domain' : this.options.domain, - 'context' : this.options.context, - 'options': { - 'thread' :{ - 'typeof_thread': this.options.typeof_thread || 'inbox', - 'display_on_thread': this.options.display_on_thread || [0,1] - }, - 'message': { - 'show_reply': this.options.show_reply || [0,0], - 'show_read_unread': this.options.show_read_unread || [0,-1], - 'truncate_limit': this.options.truncate_limit || 250, - 'show_record_name': this.options.show_record_name || false, - }, - }, - 'datasets': {}, - } - ); + this.thread = new mail.Thread(this, {}, { + 'domain' : this.options.domain, + 'context' : this.options.context, + 'options': { + 'typeof_thread': this.options.typeof_thread || 'inbox', + 'display_indented_thread': this.options.display_indented_thread || 1, + 'show_reply_button': this.options.show_reply_button || 1, + 'show_read_unread_button': this.options.show_read_unread_button || 1, + 'truncate_limit': this.options.truncate_limit || 250, + 'show_record_name': this.options.show_record_name || false, + }, + }); this.thread.appendTo( this.$el ); this.thread.no_message(); @@ -1328,9 +1276,9 @@ openerp.mail = function(session) { 'domain': domain, 'context': this.options.context, 'typeof_thread': this.options.context.typeof_thread || 'other', - 'display_on_thread':[-1,-1], - 'show_reply': [-1,-1], - 'show_read_unread': [-1,-1], + 'display_indented_thread': false, + 'show_reply_button': false, + 'show_read_unread_button': false, } ); @@ -1424,9 +1372,9 @@ openerp.mail = function(session) { 'domain' : domain, 'context' : context, 'typeof_thread': context.typeof_thread || 'other', - 'display_on_thread': [0,1], - 'show_reply': [0,0], - 'show_read_unread': [0,-1], + 'display_indented_thread': 2, + 'show_reply_button': 2, + 'show_read_unread_button': 3, } ); return this.root.appendTo( this.$('.oe_mail_wall_threads:first') ); -- cgit v1.2.3 From a670da21e4097b31cb8f433af9b9bdf9b93e748e Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 09:44:49 +0200 Subject: [FIX] mail: search for the thread message widget bzr revid: chm@openerp.com-20121019074449-5n0vylf3zoqwb2hr --- addons/mail/static/src/js/mail.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index b5eb57a1056..37cfbfa75d1 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1130,9 +1130,12 @@ openerp.mail = function(session) { } // must be improve by CHM (temporary test for DOM) - self.options._parents[0].$('.oe_msg_comment:first, .oe_thread .oe_msg_comment:first').addClass("oe_msg_first"); + self.$('.oe_msg_first').removeClass("oe_msg_first"); + self.$('.oe_msg_comment:first, .oe_thread .oe_msg_comment:first').addClass("oe_msg_first"); + self.$('.oe_msg_last').removeClass("oe_msg_last"); + self.$('.oe_msg_comment:last, .oe_thread .oe_msg_comment:last').addClass("oe_msg_last"); + self.options._parents[0].$('.oe_thread:has(.oe_msg_comment:visible) + .oe_msg').addClass("oe_msg_group_first"); - self.options._parents[0].$('.oe_msg_comment:last, .oe_thread .oe_msg_comment:last').addClass("oe_msg_last"); self.options._parents[0].$('.oe_thread:not(:has(.oe_msg:visible)) ~ .oe_thread:has(.oe_thread .oe_msg:visible)').addClass("oe_msg_group_last"); return message @@ -1336,7 +1339,7 @@ openerp.mail = function(session) { 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.add(self.do_searchview_search); + self.searchview.on('search_data', self, self.do_searchview_search); }); }, @@ -1356,7 +1359,7 @@ openerp.mail = function(session) { }).then(function (results) { self.search_results['context'] = results.context; self.search_results['domain'] = results.domain; - self.thread.destroy(); + self.root.destroy(); return self.message_render(); }); }, -- cgit v1.2.3 From 7f9da8b853a2100eae1b9ec91a87abb5133f2267 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 10:19:26 +0200 Subject: [IMP] mail: js add class on dom for CSS bzr revid: chm@openerp.com-20121019081926-0gevpfwb75k3ye93 --- addons/mail/static/src/js/mail.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 37cfbfa75d1..f1844890402 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1129,15 +1129,11 @@ openerp.mail = function(session) { } } - // must be improve by CHM (temporary test for DOM) - self.$('.oe_msg_first').removeClass("oe_msg_first"); - self.$('.oe_msg_comment:first, .oe_thread .oe_msg_comment:first').addClass("oe_msg_first"); - self.$('.oe_msg_last').removeClass("oe_msg_last"); - self.$('.oe_msg_comment:last, .oe_thread .oe_msg_comment:last').addClass("oe_msg_last"); - - self.options._parents[0].$('.oe_thread:has(.oe_msg_comment:visible) + .oe_msg').addClass("oe_msg_group_first"); - self.options._parents[0].$('.oe_thread:not(:has(.oe_msg:visible)) ~ .oe_thread:has(.oe_thread .oe_msg:visible)').addClass("oe_msg_group_last"); - + self.$('.oe_msg_first:first').removeClass("oe_msg_first"); + self.$('.oe_msg_last:last').removeClass("oe_msg_last"); + self.$('.oe_msg_comment:first, .oe_msg_comment:first-child').addClass("oe_msg_first"); + self.$('.oe_msg_comment:last, .oe_msg_comment:last-child').addClass("oe_msg_last"); + return message }, -- cgit v1.2.3 From 62fad9c114a5c21ea7d564beca45c67e496993e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 19 Oct 2012 12:03:50 +0200 Subject: [IMP] mail: removed first/last message classes bzr revid: fva@openerp.com-20121019100350-6egth3faj7uoci6u --- addons/mail/static/src/js/mail.js | 5 ----- 1 file changed, 5 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 7603490ded5..6d8f31c9ac7 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1124,11 +1124,6 @@ openerp.mail = function(session) { } } - self.$('.oe_msg_first:first').removeClass("oe_msg_first"); - self.$('.oe_msg_last:last').removeClass("oe_msg_last"); - self.$('.oe_msg_comment:first, .oe_msg_comment:first-child').addClass("oe_msg_first"); - self.$('.oe_msg_comment:last, .oe_msg_comment:last-child').addClass("oe_msg_last"); - return message }, -- cgit v1.2.3 From 7de23b01f540d52811e9263fa453831219515605 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 12:21:17 +0200 Subject: [IMP] mail: auto open and close the compose form on the threads bzr revid: chm@openerp.com-20121019102117-rzpdmkrbi7xhynpf --- addons/mail/static/src/js/mail.js | 100 +++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 33 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 7603490ded5..9d90b592dc1 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -113,6 +113,7 @@ openerp.mail = function(session) { * mail.compose.message DataSetSearch. Please refer to this model * for more details about fields and default values. */ + init: function (parent, datasets, options) { var self = this; this._super(parent); @@ -122,6 +123,7 @@ openerp.mail = function(session) { 'attachment_ids' : [], 'id': datasets.id, 'model': datasets.model, + 'show_compact': true, 'res_model': datasets.res_model, 'is_private': datasets.is_private || false, 'partner_ids': datasets.partner_ids || [], @@ -137,10 +139,20 @@ openerp.mail = function(session) { this.fileupload_id = _.uniqueId('oe_fileupload_temp'); $(window).on(self.fileupload_id, self.on_attachment_loaded); + + this.$render_expandable = false; + this.$render_compact = false; }, start: function(){ - this.display_attachments(); + this.$render_compact = this.$el; + + if(this.datasets.show_compact) { + this.$render_compact.show(); + } else { + this.$render_compact.hide(); + } + this.bind_events(); }, @@ -270,7 +282,8 @@ openerp.mail = function(session) { this.$el.on('click', 'a.oe_cancel', self.on_cancel ); this.$el.on('click', 'button.oe_post', function(){self.on_message_post()} ); this.$el.on('click', 'button.oe_full', function(){self.on_compose_fullmail()} ); - self.$el.on('focus', 'textarea.oe_compact', self.on_compose_expandable); + + this.$('textarea.oe_compact').on('focus', self.on_compose_expandable); }, on_compose_fullmail: function(){ @@ -353,22 +366,52 @@ openerp.mail = function(session) { /* convert the compact mode into the compose message */ - on_compose_expandable: function(){ - var $render = $(session.web.qweb.render('mail.compose_message', {'widget': this})); - this.$el.replaceWith( $render ); - this.$el = $render; - this.$('textarea').focus(); - this.bind_events(); + on_compose_expandable: function(event){ + if(event) event.stopPropagation(); + + var self = this; + + if(!this.$render_expandable) { + this.$render_expandable = $(session.web.qweb.render('mail.compose_message', {'widget': this})); + this.$render_expandable.hide(); + + this.$render_expandable.insertAfter( this.$render_compact ); + this.display_attachments(); + + 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('mousedown', function () { self.stay_open = true; }); + } + if(this.$render_expandable.is(':hidden')){ + + this.$render_expandable.show(); + this.$render_compact.hide(); + this.$render_expandable.find('textarea').focus(); + + } else if(!this.stay_open){ + + this.$render_expandable.hide(); + if(this.datasets.show_compact) { + this.$render_compact.show(); + } else { + this.$render_compact.hide(); + } + + } + return true; }, - /* convert the compact mode into the compose message - */ - on_compose_compact: function(){ - var $render = $(session.web.qweb.render('mail.compose_message.compact', {'widget': this})); - this.$el.replaceWith( $render ); - this.$el = $render; - this.bind_events(); + do_hide_compact: function() { + this.$render_compact.hide(); + this.datasets.show_compact = false; }, + + do_show_compact: function() { + this.$render_compact.show(); + this.datasets.show_compact = true; + } }); /** @@ -507,7 +550,7 @@ openerp.mail = function(session) { 'name' : false, 'record_name' : false, 'body' : false, - 'vote_user_ids' :[], + 'vote_nb' :0, 'has_voted' : false, 'is_favorite' : false, 'thread_level' : 0, @@ -595,8 +638,8 @@ openerp.mail = function(session) { this.$el.on('click', 'a.oe_reply', this.on_message_reply); // event: click on 'Vote' button this.$el.on('click', 'button.oe_msg_vote', this.on_vote); - // event: click on 'Star' button - this.$el.on('click', 'button.oe_mail_starbox', this.on_star); + // event: click on 'starred/favorite' button + this.$el.on('click', 'a.oe_mail_starbox', this.on_star); }, on_message_reply:function(event){ @@ -727,17 +770,7 @@ openerp.mail = function(session) { return this.ds_message.call('vote_toggle', [[self.datasets.id]]).pipe(function(vote){ self.datasets.has_voted=vote; - if (!self.datasets.has_voted) { - var votes=[]; - for(var i in self.datasets.vote_user_ids){ - if(self.datasets.vote_user_ids[i][0]!=self.session.uid) - vote.push(self.datasets.vote_user_ids[i]); - } - self.datasets.vote_user_ids=votes; - } - else { - self.datasets.vote_user_ids.push([self.session.uid, 'You']); - } + self.datasets.vote_nb += self.datasets.has_voted ? 1 : -1; self.display_vote(); }); return false; @@ -747,8 +780,8 @@ openerp.mail = function(session) { display_vote: function () { var self = this; var vote_element = session.web.qweb.render('mail.thread.message.vote', {'widget': self}); - self.$(".placeholder-mail-vote:first").empty(); - self.$(".placeholder-mail-vote:first").html(vote_element); + self.$(".oe_msg_vote:first").remove(); + self.$(".oe_mail_vote_count:first").replaceWith(vote_element); }, // Stared/unstared + Render star. @@ -880,7 +913,7 @@ openerp.mail = function(session) { // root view this.ComposeMessage.prependTo(this.$el); } - this.ComposeMessage.$el.hide(); + this.ComposeMessage.do_hide_compact(); }, /* When the expandable object is visible on screen (with scrolling) @@ -1069,7 +1102,7 @@ openerp.mail = function(session) { var self=this; if(this.datasets.show_composeform){ - this.ComposeMessage.$el.show(); + this.ComposeMessage.do_show_compact(); } this.$('.oe_wall_no_message').remove(); @@ -1203,6 +1236,7 @@ openerp.mail = function(session) { 'show_read_unread_button': this.options.show_read_unread_button || 1, 'truncate_limit': this.options.truncate_limit || 250, 'show_record_name': this.options.show_record_name || false, + 'show_header_compose': this.options.show_header_compose || false }, }); -- cgit v1.2.3 From dfa34c02540cbb84ad6018ad62582574c4e959b9 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 13:39:51 +0200 Subject: [IMP] mail: auto open and close the compose form on the threads bzr revid: chm@openerp.com-20121019113951-pz44iipv45misvgk --- addons/mail/static/src/js/mail.js | 188 +++++++++++++++++++++++--------------- 1 file changed, 116 insertions(+), 72 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 7603490ded5..ac7e01b40e5 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -113,6 +113,7 @@ openerp.mail = function(session) { * mail.compose.message DataSetSearch. Please refer to this model * for more details about fields and default values. */ + init: function (parent, datasets, options) { var self = this; this._super(parent); @@ -122,6 +123,7 @@ openerp.mail = function(session) { 'attachment_ids' : [], 'id': datasets.id, 'model': datasets.model, + 'show_compact': true, 'res_model': datasets.res_model, 'is_private': datasets.is_private || false, 'partner_ids': datasets.partner_ids || [], @@ -137,10 +139,20 @@ openerp.mail = function(session) { this.fileupload_id = _.uniqueId('oe_fileupload_temp'); $(window).on(self.fileupload_id, self.on_attachment_loaded); + + this.$render_expandable = false; + this.$render_compact = false; }, start: function(){ - this.display_attachments(); + this.$render_compact = this.$el; + + if(this.datasets.show_compact) { + this.$render_compact.show(); + } else { + this.$render_compact.hide(); + } + this.bind_events(); }, @@ -150,14 +162,14 @@ openerp.mail = function(session) { var self = this; var render = $(session.web.qweb.render('mail.thread.message.attachments', {'widget': self})); if(!this.list_attachment){ - this.$('.oe_msg_attachment_list').replaceWith( render ); + this.$render_expandable.find('.oe_msg_attachment_list').replaceWith( render ); } else { this.list_attachment.replaceWith( render ); } - this.list_attachment = this.$(".oe_msg_attachments"); + this.list_attachment = this.$render_expandable.find(".oe_msg_attachments"); // event: delete an attachment - this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete); + this.$render_expandable.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete); }, /* when a user click on the upload button, send file read on_attachment_loaded @@ -185,10 +197,9 @@ openerp.mail = function(session) { this.datasets.attachment_ids = attachments; // submit file - //session.web.blockUI(); - self.$('form.oe_form_binary_form').submit(); + this.$render_expandable.find('form.oe_form_binary_form').submit(); - this.$(".oe_attachment_file").hide(); + this.$render_expandable.find(".oe_attachment_file").hide(); this.datasets.attachment_ids.push({ 'id': 0, @@ -204,7 +215,6 @@ openerp.mail = function(session) { /* when the file is uploaded */ on_attachment_loaded: function (event, result) { - //session.web.unblockUI(); for(var i in this.datasets.attachment_ids){ if(this.datasets.attachment_ids[i].filename == result.filename && this.datasets.attachment_ids[i].upload) { this.datasets.attachment_ids[i]={ @@ -217,9 +227,9 @@ openerp.mail = function(session) { } this.display_attachments(); - var $input = this.$('input.oe_form_binary_file'); + var $input = this.$render_expandable.find('input.oe_form_binary_file'); $input.after($input.clone(true)).remove(); - this.$(".oe_attachment_file").show(); + this.$render_expandable.find(".oe_attachment_file").show(); }, /* unlink the file on the server and reload display @@ -265,12 +275,24 @@ openerp.mail = function(session) { bind_events: function() { var self = this; - // set the function called when attachments are added - this.$el.on('change', 'input.oe_form_binary_file', self.on_attachment_change ); - this.$el.on('click', 'a.oe_cancel', self.on_cancel ); - this.$el.on('click', 'button.oe_post', function(){self.on_message_post()} ); - this.$el.on('click', 'button.oe_full', function(){self.on_compose_fullmail()} ); - self.$el.on('focus', 'textarea.oe_compact', self.on_compose_expandable); + this.$render_compact.find('textarea').unbind().on('focus', self.on_compose_expandable); + + if(this.$render_expandable){ + // set the function called when attachments are added + this.$render_expandable.on('change', 'input.oe_form_binary_file', self.on_attachment_change ); + + this.$render_expandable.on('click', 'a.oe_cancel', self.on_cancel ); + this.$render_expandable.on('click', 'button.oe_post', function(){self.on_message_post()} ); + this.$render_expandable.on('click', 'button.oe_full', function(){self.on_compose_fullmail()} ); + + // auto close + 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('mousedown', function () { self.stay_open = true; }); + } + }, on_compose_fullmail: function(){ @@ -292,11 +314,11 @@ openerp.mail = function(session) { views: [[false, 'form']], target: 'new', context: { - 'default_model': false, - 'default_res_id': 0, + 'default_model': this.context.default_model, + 'default_res_id': this.context.default_res_id, 'default_content_subtype': 'html', 'default_parent_id': this.datasets.id, - 'default_body': mail.ChatterUtils.get_text2html(this.$('textarea').val() || ''), + 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable.find('textarea').val() || ''), 'default_attachment_ids': attachments, 'default_partner_ids': partner_ids }, @@ -306,11 +328,13 @@ openerp.mail = function(session) { on_cancel: function(event){ if(event) event.stopPropagation(); - this.$('textarea').val(""); - this.$('input[data-id]').remove(); - //this.attachment_ids=[]; + this.$render_expandable.find('textarea').val(""); + this.$render_expandable.find('input[data-id]').remove(); + + this.datasets.attachment_ids=[]; this.display_attachments(); - this.$el.hide(); + + this.on_compose_expandable(); }, /*post a message and fetch the message*/ @@ -318,7 +342,7 @@ openerp.mail = function(session) { var self = this; if (! body) { - var comment_node = this.$('textarea'); + var comment_node = this.$render_expandable.find('textarea'); var body = comment_node.val(); comment_node.val(''); } @@ -333,6 +357,7 @@ openerp.mail = function(session) { } if(body.match(/\S+/)) { + session.web.blockUI(); this.parent_thread.ds_thread.call('message_post_api', [ this.context.default_res_id, mail.ChatterUtils.get_text2html(body), @@ -344,8 +369,8 @@ openerp.mail = function(session) { this.parent_thread.context ]).then(function(records){ self.parent_thread.switch_new_message(records); - self.datasets.attachment_ids=[]; self.on_cancel(); + session.web.unblockUI(); }); return true; } @@ -353,22 +378,48 @@ openerp.mail = function(session) { /* convert the compact mode into the compose message */ - on_compose_expandable: function(){ - var $render = $(session.web.qweb.render('mail.compose_message', {'widget': this})); - this.$el.replaceWith( $render ); - this.$el = $render; - this.$('textarea').focus(); - this.bind_events(); + on_compose_expandable: function(event){ + if(event) event.stopPropagation(); + + var self = this; + + if(!this.$render_expandable) { + this.$render_expandable = $(session.web.qweb.render('mail.compose_message', {'widget': this})); + this.$render_expandable.hide(); + + this.$render_expandable.insertAfter( this.$render_compact ); + this.display_attachments(); + + this.bind_events(); + } + if(this.$render_expandable.is(':hidden')){ + + this.$render_expandable.show(); + this.$render_compact.hide(); + this.$render_expandable.find('textarea').focus(); + + } else if(!this.stay_open){ + + this.$render_expandable.hide(); + if(this.datasets.show_compact) { + this.$render_compact.show(); + } else { + this.$render_compact.hide(); + } + + } + return true; }, - /* convert the compact mode into the compose message - */ - on_compose_compact: function(){ - var $render = $(session.web.qweb.render('mail.compose_message.compact', {'widget': this})); - this.$el.replaceWith( $render ); - this.$el = $render; - this.bind_events(); + do_hide_compact: function() { + this.$render_compact.hide(); + this.datasets.show_compact = false; }, + + do_show_compact: function() { + this.$render_compact.show(); + this.datasets.show_compact = true; + } }); /** @@ -507,7 +558,7 @@ openerp.mail = function(session) { 'name' : false, 'record_name' : false, 'body' : false, - 'vote_user_ids' :[], + 'vote_nb' :0, 'has_voted' : false, 'is_favorite' : false, 'thread_level' : 0, @@ -595,8 +646,8 @@ openerp.mail = function(session) { this.$el.on('click', 'a.oe_reply', this.on_message_reply); // event: click on 'Vote' button this.$el.on('click', 'button.oe_msg_vote', this.on_vote); - // event: click on 'Star' button - this.$el.on('click', 'button.oe_mail_starbox', this.on_star); + // event: click on 'starred/favorite' button + this.$el.on('click', 'a.oe_mail_starbox', this.on_star); }, on_message_reply:function(event){ @@ -617,24 +668,22 @@ openerp.mail = function(session) { }, create_thread: function(){ - var self=this; if(this.thread){ return false; } - /*create thread*/ - self.thread = new mail.Thread(self, self.datasets, { - 'domain': self.domain, + this.thread = new mail.Thread(this, this.datasets, { + 'domain': this.domain, 'context':{ - 'default_model': self.datasets.model, - 'default_res_id': self.datasets.res_id, - 'default_parent_id': self.datasets.id + 'default_model': this.datasets.model, + 'default_res_id': this.datasets.res_id, + 'default_parent_id': this.datasets.id }, - 'options': self.options + 'options': this.options } ); /*insert thread in parent message*/ - self.thread.insertAfter(self.$el); + this.thread.insertAfter(this.$el); }, animated_destroy: function(options) { @@ -727,17 +776,7 @@ openerp.mail = function(session) { return this.ds_message.call('vote_toggle', [[self.datasets.id]]).pipe(function(vote){ self.datasets.has_voted=vote; - if (!self.datasets.has_voted) { - var votes=[]; - for(var i in self.datasets.vote_user_ids){ - if(self.datasets.vote_user_ids[i][0]!=self.session.uid) - vote.push(self.datasets.vote_user_ids[i]); - } - self.datasets.vote_user_ids=votes; - } - else { - self.datasets.vote_user_ids.push([self.session.uid, 'You']); - } + self.datasets.vote_nb += self.datasets.has_voted ? 1 : -1; self.display_vote(); }); return false; @@ -747,8 +786,8 @@ openerp.mail = function(session) { display_vote: function () { var self = this; var vote_element = session.web.qweb.render('mail.thread.message.vote', {'widget': self}); - self.$(".placeholder-mail-vote:first").empty(); - self.$(".placeholder-mail-vote:first").html(vote_element); + self.$(".oe_msg_vote:first").remove(); + self.$(".oe_mail_vote_count:first").replaceWith(vote_element); }, // Stared/unstared + Render star. @@ -826,7 +865,7 @@ openerp.mail = function(session) { 'display_indented_thread': options.options.display_indented_thread || -1, 'show_reply_button': options.options.show_reply_button || -1, 'typeof_thread': options.options.typeof_thread || 'inbox', - 'show_header_compose': options.options.show_header_compose || false, + 'show_compose_message': options.options.show_compose_message || false, '_parents': (options.options._parents != undefined ? options.options._parents : []).concat( [this] ) }); @@ -844,7 +883,7 @@ openerp.mail = function(session) { 'partner_ids' : [] }; - this.datasets.show_composeform = this.options.show_header_compose && this.options.show_reply_button>this.datasets.thread_level; + this.datasets.show_composeform = this.options.show_compose_message && this.options.show_reply_button>this.datasets.thread_level; for(var i in datasets.partner_ids){ if(datasets.partner_ids[i][0]!=(datasets.author_id ? datasets.author_id[0] : -1)){ @@ -880,7 +919,7 @@ openerp.mail = function(session) { // root view this.ComposeMessage.prependTo(this.$el); } - this.ComposeMessage.$el.hide(); + this.ComposeMessage.do_hide_compact(); }, /* When the expandable object is visible on screen (with scrolling) @@ -1069,7 +1108,7 @@ openerp.mail = function(session) { var self=this; if(this.datasets.show_composeform){ - this.ComposeMessage.$el.show(); + this.ComposeMessage.do_show_compact(); } this.$('.oe_wall_no_message').remove(); @@ -1203,12 +1242,17 @@ openerp.mail = function(session) { 'show_read_unread_button': this.options.show_read_unread_button || 1, 'truncate_limit': this.options.truncate_limit || 250, 'show_record_name': this.options.show_record_name || false, + 'show_compose_message': this.options.show_compose_message || false }, }); this.thread.appendTo( this.$el ); this.thread.no_message(); this.thread.message_fetch(); + + if(this.options.show_compose_message){ + this.thread.ComposeMessage.do_show_compact(); + } }, bind_events: function(){ @@ -1264,7 +1308,7 @@ openerp.mail = function(session) { 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_header_compose = this.view.is_action_enabled('edit') || + var show_compose_message = this.view.is_action_enabled('edit') || (this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value()); if(this.root){ @@ -1275,10 +1319,10 @@ openerp.mail = function(session) { 'domain' : domain, 'context' : this.options.context, 'typeof_thread': this.options.context['typeof_thread'] || 'other', - 'display_indented_thread': false, - 'show_reply_button': false, + 'display_indented_thread': 0, + 'show_reply_button': 1, 'show_read_unread_button': false, - 'show_header_compose': show_header_compose + 'show_compose_message': show_compose_message } ); @@ -1375,7 +1419,7 @@ openerp.mail = function(session) { 'display_indented_thread': 2, 'show_reply_button': 2, 'show_read_unread_button': 3, - 'show_header_compose': true + 'show_compose_message': true } ); return this.root.appendTo( this.$('.oe_mail_wall_threads:first') ); -- cgit v1.2.3 From f1a444bfa8b52262d30976ad00832abbe0d88744 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 13:53:34 +0200 Subject: [FIX] mail: double box on compose bzr revid: chm@openerp.com-20121019115334-t7vmenp4isw9k1qi --- addons/mail/static/src/js/mail.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 4d8fdf8941c..69aeba6b9e0 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -292,7 +292,6 @@ openerp.mail = function(session) { this.$render_expandable.on('focus', 'textarea', function () { self.stay_open = false; }); this.$render_expandable.on('mousedown', function () { self.stay_open = true; }); } - }, on_compose_fullmail: function(){ @@ -334,6 +333,7 @@ openerp.mail = function(session) { this.datasets.attachment_ids=[]; this.display_attachments(); + this.stay_open = false; this.on_compose_expandable(); }, @@ -357,7 +357,7 @@ openerp.mail = function(session) { } if(body.match(/\S+/)) { - session.web.blockUI(); + //session.web.blockUI(); this.parent_thread.ds_thread.call('message_post_api', [ this.context.default_res_id, mail.ChatterUtils.get_text2html(body), @@ -370,7 +370,7 @@ openerp.mail = function(session) { ]).then(function(records){ self.parent_thread.switch_new_message(records); self.on_cancel(); - session.web.unblockUI(); + //session.web.unblockUI(); }); return true; } @@ -392,6 +392,7 @@ openerp.mail = function(session) { this.bind_events(); } + if(this.$render_expandable.is(':hidden')){ this.$render_expandable.show(); @@ -420,7 +421,9 @@ openerp.mail = function(session) { }, do_show_compact: function() { - this.$render_compact.show(); + if(!this.$render_expandable || this.$render_expandable.is(':hidden')){ + this.$render_compact.show(); + } this.datasets.show_compact = true; } }); -- cgit v1.2.3 From 35b6725f3f8b23d94bbe45c92ecfa669eea1f48d Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 14:38:16 +0200 Subject: [FIX] mail: sort of expandable message bzr revid: chm@openerp.com-20121019123816-dzortu46e3fofmxp --- addons/mail/static/src/js/mail.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 69aeba6b9e0..bc59bd3c35b 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -457,6 +457,7 @@ openerp.mail = function(session) { 'model' : datasets.model || false, 'parent_id' : datasets.parent_id || false, 'nb_messages' : datasets.nb_messages || 0, + 'thread_level' : datasets.thread_level || 0, 'type' : 'expandable', 'max_limit' : datasets.max_limit || false, 'flag_used' : false, @@ -933,13 +934,13 @@ openerp.mail = function(session) { */ on_scroll: function(event){ if(event)event.stopPropagation(); - var message = this.messages[0]; + var message = this.messages[this.messages.length-1]; if(message && message.datasets.type=="expandable" && message.datasets.max_limit){ var pos = message.$el.position(); if(pos.top){ /* bottom of the screen */ var bottom = $(window).scrollTop()+$(window).height()+200; - if(bottom - pos.top > 0){ + if(bottom > pos.top){ message.on_expandable(); } } @@ -1131,23 +1132,23 @@ openerp.mail = function(session) { // check older and newer message for insert var parent_newer = false; var parent_older = false; - for(var i in thread_messages){ - if((thread_messages[i].datasets.id > message.datasets.id && message.datasets.id > 0) || - thread_messages[i].datasets.id < 0){ - if(!parent_newer || - thread_messages[i].datasets.id < 0 || - parent_newer.datasets.id >= thread_messages[i].datasets.id) { - parent_newer = thread_messages[i]; - } - } else if((thread_messages[i].datasets.id > 0 && thread_messages[i].datasets.id < message.datasets.id) || message.datasets.id < 0) { - if(!parent_older || - parent_older.datasets.id < thread_messages[i].datasets.id) { - parent_older = thread_messages[i]; + if(message.datasets.id > 0){ + for(var i in thread_messages){ + if(thread_messages[i].datasets.id > message.datasets.id){ + if(!parent_newer || + parent_newer.datasets.id > thread_messages[i].datasets.id) { + parent_newer = thread_messages[i]; + } + } else if(thread_messages[i].datasets.id > 0 && thread_messages[i].datasets.id < message.datasets.id) { + if(!parent_older || + parent_older.datasets.id < thread_messages[i].datasets.id) { + parent_older = thread_messages[i]; + } } } } - var sort = self.datasets.thread_level; + var sort = (!!message.datasets.thread_level || message.datasets.id<0); if(parent_older){ if(sort){ @@ -1162,7 +1163,7 @@ openerp.mail = function(session) { message.insertAfter(parent_newer.thread ? parent_newer.thread.$el : parent_newer.$el); } } else { - if(sort) { + if(sort && message.datasets.id>0) { message.prependTo(thread.$el); } else { message.appendTo(thread.$el); -- cgit v1.2.3 From 491034ed0af1e6784a122f9cbf15e44696f675c7 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 15:13:58 +0200 Subject: [FIX] mail: to_read value of _message_get_dict bzr revid: chm@openerp.com-20121019131358-xn3b8yyepscsrad7 --- addons/mail/static/src/js/mail.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index bc59bd3c35b..8d5c1aabf87 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -934,6 +934,8 @@ 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.datasets.type=="expandable" && message.datasets.max_limit){ var pos = message.$el.position(); @@ -944,7 +946,6 @@ openerp.mail = function(session) { message.on_expandable(); } } - } }, @@ -1099,15 +1100,22 @@ openerp.mail = function(session) { }); } + // insert the message on dom + self.insert_message( message ); + // check if the message is already create for(var i in self.messages){ if(self.messages[i].datasets.id == message.datasets.id){ self.messages[i].destroy(); - self.messages[i] = self.insert_message(message); - return true; + if(message.datasets.id>0){ + self.messages[i] = message; + return true; + } else { + delete self.messages[i]; + } } } - self.messages.push( self.insert_message(message) ); + self.messages.push( message ); }, /** Displays a message or an expandable message */ -- cgit v1.2.3 From aefa8b2337ee1fd060c91faa487cd3f6501d15d3 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 15:16:22 +0200 Subject: [FIX] mail: full_message first open bzr revid: chm@openerp.com-20121019131622-o2ef1afapata7eda --- addons/mail/static/src/js/mail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8d5c1aabf87..823f57a271d 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -317,7 +317,7 @@ openerp.mail = function(session) { 'default_res_id': this.context.default_res_id, 'default_content_subtype': 'html', 'default_parent_id': this.datasets.id, - 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable.find('textarea').val() || ''), + 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''), 'default_attachment_ids': attachments, 'default_partner_ids': partner_ids }, -- cgit v1.2.3 From 591c0ff3486e8c26a6b16e016e9db84fccd660ea Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 15:23:07 +0200 Subject: [FIX] mail_followers: display_subtypes read first time bzr revid: chm@openerp.com-20121019132307-s7hvnjltjvc9kndo --- addons/mail/static/src/js/mail_followers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 735b3e00e0b..7deabf21846 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -188,7 +188,7 @@ openerp_mail_followers = function(session, mail) { display_subtypes:function (data) { var self = this; var subtype_list_ul = this.$('.oe_subtypes'); - var records = data[this.view.dataset.ids[0]].message_subtype_data; + var records = data[this.view.datarecord.id || this.view.dataset.ids[0]].message_subtype_data; _(records).each(function (record, record_name) { record.name = record_name; -- cgit v1.2.3 From 63d5acfa6b1a1a910d173e980edc7b2b66eae212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 19 Oct 2012 15:32:05 +0200 Subject: [IMP] mail: buttons are at the right place bzr revid: fva@openerp.com-20121019133205-06uavw1esxh5our5 --- addons/mail/static/src/js/mail.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 24946a6fd81..e49811ab38c 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -886,7 +886,7 @@ openerp.mail = function(session) { } this.messages = []; - this.ComposeMessage = false; + this.composeMessage = false; this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model || 'mail.thread'); this.ds_message = new session.web.DataSetSearch(this, 'mail.message'); @@ -902,18 +902,18 @@ openerp.mail = function(session) { instantiate_ComposeMessage: function(){ // add message composition form view - this.ComposeMessage = new mail.ThreadComposeMessage(this, this.datasets, { + this.composeMessage = new mail.ThreadComposeMessage(this, this.datasets, { 'context': this.context, 'options': this.options, }); if(this.datasets.thread_level){ - this.ComposeMessage.appendTo(this.$el); + this.composeMessage.appendTo(this.$el); } else { // root view - this.ComposeMessage.prependTo(this.$el); + this.composeMessage.prependTo(this.$el); } - this.ComposeMessage.do_hide_compact(); + this.composeMessage.do_hide_compact(); }, /* When the expandable object is visible on screen (with scrolling) @@ -1030,7 +1030,7 @@ openerp.mail = function(session) { /* this function is launch when a user click on "Reply" button */ on_compose_message: function(){ - this.ComposeMessage.on_compose_expandable(); + this.composeMessage.on_compose_expandable(); }, /* display the no message on the thread @@ -1102,7 +1102,7 @@ openerp.mail = function(session) { var self=this; if(this.datasets.show_composeform){ - this.ComposeMessage.do_show_compact(); + this.composeMessage.do_show_compact(); } this.$('.oe_wall_no_message').remove(); @@ -1412,7 +1412,7 @@ openerp.mail = function(session) { bind_events: function(){ var self=this; - this.$("button.oe_write_full:first").click(function(){ self.root.thread.ComposeMessage.on_compose_fullmail(); }); + this.$("button.oe_write_full:first").click(function(){ self.root.thread.composeMessage.on_compose_fullmail(); }); this.$("button.oe_write_onwall:first").click(function(){ self.root.thread.on_compose_message(); }); } }); -- cgit v1.2.3 From 8d31ef9c0ec4b2aa597addd33d56c15e92ae5bea Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 15:53:56 +0200 Subject: [IMP] mail: reduce options for js bzr revid: chm@openerp.com-20121019135356-kxtg99zmxdyesbcr --- addons/mail/static/src/js/mail.js | 85 +++++++++++++-------------------------- 1 file changed, 28 insertions(+), 57 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 823f57a271d..419005b4b74 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -129,8 +129,7 @@ openerp.mail = function(session) { 'partner_ids': datasets.partner_ids || [], 'avatar': mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid), }; - this.options={}; - this.options.display_indented_thread = options.options.display_indented_thread || -1; + this.options = options.options; this.options.show_attachment_delete = true; this.parent_thread= parent.messages!= undefined ? parent : false; @@ -539,9 +538,6 @@ openerp.mail = function(session) { * @param {Object} [options] * @param {Object} [thread] read obout mail.Thread object * @param {Object} [message] - * @param {Number} [message_ids=null] ids for message_fetch - * @param {Number} [message_data=null] already formatted message data, - * for subthreads getting data from their parent * @param {Number} [truncate_limit=250] number of character to * display before having a "show more" link; note that the text * will not be truncated if it does not have 110% of the parameter @@ -583,17 +579,10 @@ openerp.mail = function(session) { default_parent_id: false }, options.context || {}); // record options - this.options = _.extend(options.options, { - 'message_ids': options.options.message_ids || null, - 'message_data': options.options.message_data || null, - 'show_record_name': options.options.show_record_name != undefined ? options.options.show_record_name: true, - 'truncate_limit': options.options.truncate_limit || 250, - 'show_reply_button': options.options.show_reply_button || -1, - 'show_read_unread_button': options.options.show_read_unread_button || -1 - }); + this.options = options.options; - this.datasets.show_reply_button = this.options.show_reply_button>this.datasets.thread_level; - this.datasets.show_read_unread_button = this.options.show_read_unread_button>this.datasets.thread_level; + this.datasets.show_reply_button = this.options.show_compose_message && this.options.show_reply_button > this.datasets.thread_level; + this.datasets.show_read_unread_button = this.options.show_read_unread_button > this.datasets.thread_level; // record options and data this.parent_thread= parent.messages!= undefined ? parent : options.options._parents[0]; @@ -844,10 +833,6 @@ openerp.mail = function(session) { * @param {Object} [options] * @param {Object} [message] read about mail.ThreadMessage object * @param {Object} [thread] - * @param {Number} [expandable_number=5] number message show - * 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 {int} [display_indented_thread] number thread level to indented threads. * other are on flat mode * @param {Select} [typeof_thread] inbox/archives/stared/sent @@ -864,17 +849,8 @@ openerp.mail = function(session) { default_res_id: 0, default_parent_id: false }, options.context || {}); - // options - this.options = _.extend(options.options, { - 'expandable_number': options.options.expandable_number || 5, - 'expandable_default_number': options.options.expandable_default_number || 5, - '_expandable_max': options.options.expandable_default_number || 5, - 'display_indented_thread': options.options.display_indented_thread || -1, - 'show_reply_button': options.options.show_reply_button || -1, - 'typeof_thread': options.options.typeof_thread || 'inbox', - 'show_compose_message': options.options.show_compose_message || false, - '_parents': (options.options._parents != undefined ? options.options._parents : []).concat( [this] ) - }); + this.options = options.options; + this.options._parents = (options.options._parents != undefined ? options.options._parents : []).concat( [this] ); // record options and data this.parent_message= parent.thread!= undefined ? parent : false ; @@ -890,7 +866,7 @@ openerp.mail = function(session) { 'partner_ids' : [] }; - this.datasets.show_composeform = this.options.show_compose_message && this.options.show_reply_button>this.datasets.thread_level; + this.datasets.show_compose_message = this.options.show_compose_message && this.options.show_reply_button>this.datasets.thread_level; for(var i in datasets.partner_ids){ if(datasets.partner_ids[i][0]!=(datasets.author_id ? datasets.author_id[0] : -1)){ @@ -907,7 +883,7 @@ openerp.mail = function(session) { start: function() { this._super.apply(this, arguments); - if(this.datasets.show_composeform){ + if(this.datasets.show_compose_message){ this.instantiate_ComposeMessage(); } this.bind_events(); @@ -1054,19 +1030,12 @@ openerp.mail = function(session) { }, /** Fetch messages - * @param {Bool} initial_mode: initial mode: try to use message_data or - * message_ids, if nothing available perform a message_read; otherwise - * directly perform a message_read * @param {Array} replace_domain: added to this.domain * @param {Object} replace_context: added to this.context */ message_fetch: function (initial_mode, replace_domain, replace_context, ids, callback) { var self = this; - // initial mode: try to use message_data or message_ids - if (initial_mode && this.options.message_data) { - return this.create_message_object(this.options.message_data); - } // domain and context: options + additional fetch_domain = replace_domain ? replace_domain : this.domain; fetch_context = replace_context ? replace_context : this.context; @@ -1122,7 +1091,7 @@ openerp.mail = function(session) { insert_message: function (message) { var self=this; - if(this.datasets.show_composeform){ + if(this.datasets.show_compose_message && this.options.display_indented_thread > self.datasets.thread_level){ this.ComposeMessage.do_show_compact(); } @@ -1232,9 +1201,17 @@ openerp.mail = function(session) { init: function (parent, options) { this._super(parent); this.options = options || {}; - this.options.domain = options.domain || []; - this.options.context = options.context || {}; + this.domain = options.domain || []; + this.context = options.context || {}; this.search_results = {'domain': [], 'context': {}, 'groupby': {}}; + + this.options.typeof_thread = this.options.typeof_thread || 'inbox', + this.options.display_indented_thread = this.options.display_indented_thread !== false ? this.options.display_indented_thread : -1, + this.options.show_reply_button = this.options.show_reply_button !== false ? this.options.show_reply_button : -1, + this.options.show_read_unread_button = this.options.show_read_unread_button !== false ? this.options.show_read_unread_button : -1, + this.options.truncate_limit = this.options.truncate_limit || 250, + this.options.show_record_name = this.options.show_record_name || false, + this.options.show_compose_message = this.options.show_compose_message || false }, start: function (options) { @@ -1247,18 +1224,11 @@ openerp.mail = function(session) { * Display the threads */ message_render: function (search) { + this.thread = new mail.Thread(this, {}, { - 'domain' : this.options.domain, - 'context' : this.options.context, - 'options': { - 'typeof_thread': this.options.typeof_thread || 'inbox', - 'display_indented_thread': this.options.display_indented_thread || 1, - 'show_reply_button': this.options.show_reply_button || 1, - 'show_read_unread_button': this.options.show_read_unread_button || 1, - 'truncate_limit': this.options.truncate_limit || 250, - 'show_record_name': this.options.show_record_name || false, - 'show_compose_message': this.options.show_compose_message || false - }, + 'domain' : this.domain, + 'context' : this.context, + 'options': this.options, }); this.thread.appendTo( this.$el ); @@ -1271,7 +1241,7 @@ openerp.mail = function(session) { }, bind_events: function(){ - if(this.options.context['typeof_thread']!='other'){ + 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 ); @@ -1334,9 +1304,9 @@ openerp.mail = function(session) { 'domain' : domain, 'context' : this.options.context, 'typeof_thread': this.options.context['typeof_thread'] || 'other', - 'display_indented_thread': 0, - 'show_reply_button': 1, - 'show_read_unread_button': false, + 'display_indented_thread': -1, + 'show_reply_button': 10, + 'show_read_unread_button': -1, 'show_compose_message': show_compose_message } ); @@ -1437,6 +1407,7 @@ openerp.mail = function(session) { 'show_compose_message': true } ); + return this.root.appendTo( this.$('.oe_mail_wall_threads:first') ); }, -- cgit v1.2.3 From 9daba198cd5b79c093ef8a14c9c3d7797e9108c5 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 16:32:28 +0200 Subject: [IMP] mail: reduce code js bzr revid: chm@openerp.com-20121019143228-rzc4k2s7pxa0glk9 --- addons/mail/static/src/js/mail.js | 61 ++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 419005b4b74..6adc357023e 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -123,14 +123,12 @@ openerp.mail = function(session) { 'attachment_ids' : [], 'id': datasets.id, 'model': datasets.model, - 'show_compact': true, 'res_model': datasets.res_model, 'is_private': datasets.is_private || false, 'partner_ids': datasets.partner_ids || [], 'avatar': mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid), }; this.options = options.options; - this.options.show_attachment_delete = true; this.parent_thread= parent.messages!= undefined ? parent : false; @@ -146,7 +144,7 @@ openerp.mail = function(session) { start: function(){ this.$render_compact = this.$el; - if(this.datasets.show_compact) { + if(this.options.show_compact_message) { this.$render_compact.show(); } else { this.$render_compact.hide(); @@ -403,7 +401,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.datasets.show_compact) { + if(this.options.show_compact_message) { this.$render_compact.show(); } else { this.$render_compact.hide(); @@ -416,14 +414,14 @@ openerp.mail = function(session) { do_hide_compact: function() { this.$render_compact.hide(); - this.datasets.show_compact = false; + this.options.show_compact_message = false; }, do_show_compact: function() { if(!this.$render_expandable || this.$render_expandable.is(':hidden')){ this.$render_compact.show(); } - this.datasets.show_compact = true; + this.options.show_compact_message = true; } }); @@ -863,17 +861,11 @@ openerp.mail = function(session) { 'is_private' : datasets.is_private || false, 'author_id' : datasets.author_id || false, 'thread_level' : (datasets.thread_level+1) || 0, - 'partner_ids' : [] + 'partner_ids' : _.filter(datasets.partner_ids, function(partner){ return partner[0]!=datasets.author_id[0]; } ) }; this.datasets.show_compose_message = this.options.show_compose_message && this.options.show_reply_button>this.datasets.thread_level; - for(var i in datasets.partner_ids){ - if(datasets.partner_ids[i][0]!=(datasets.author_id ? datasets.author_id[0] : -1)){ - this.datasets.partner_ids.push(datasets.partner_ids[i]); - } - } - this.messages = []; this.ComposeMessage = false; @@ -1020,6 +1012,11 @@ openerp.mail = function(session) { /* this function is launch when a user click on "Reply" button */ on_compose_message: function(){ + if(!this.ComposeMessage){ + this.instantiate_ComposeMessage(); + this.ComposeMessage.do_hide_compact(); + } + this.ComposeMessage.on_compose_expandable(); }, @@ -1091,7 +1088,7 @@ openerp.mail = function(session) { insert_message: function (message) { var self=this; - if(this.datasets.show_compose_message && this.options.display_indented_thread > self.datasets.thread_level){ + if(this.datasets.show_compose_message && this.options.display_indented_thread > self.datasets.thread_level && this.options.show_compact_message){ this.ComposeMessage.do_show_compact(); } @@ -1197,21 +1194,37 @@ openerp.mail = function(session) { *... @param {int} [show_read_unread_button] number thread level to 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 + *... @param {Boolean} [show_compact_message] display the compact message on the thread + * when the user clic on this compact mode, the composer is open */ init: function (parent, options) { this._super(parent); - this.options = options || {}; this.domain = options.domain || []; this.context = options.context || {}; this.search_results = {'domain': [], 'context': {}, 'groupby': {}}; - this.options.typeof_thread = this.options.typeof_thread || 'inbox', - this.options.display_indented_thread = this.options.display_indented_thread !== false ? this.options.display_indented_thread : -1, - this.options.show_reply_button = this.options.show_reply_button !== false ? this.options.show_reply_button : -1, - this.options.show_read_unread_button = this.options.show_read_unread_button !== false ? this.options.show_read_unread_button : -1, - this.options.truncate_limit = this.options.truncate_limit || 250, - this.options.show_record_name = this.options.show_record_name || false, - this.options.show_compose_message = this.options.show_compose_message || false + this.options = _.extend({ + 'typeof_thread' : 'inbox', + 'display_indented_thread' : -1, + 'show_reply_button' : -1, + 'show_read_unread_button' : -1, + 'truncate_limit' : 250, + 'show_record_name' : false, + 'show_compose_message' : false, + 'show_compact_message' : false + }, options); + + 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; + } + }, start: function (options) { @@ -1402,8 +1415,8 @@ openerp.mail = function(session) { 'context' : context, 'typeof_thread': context['typeof_thread'] || 'other', 'display_indented_thread': 2, - 'show_reply_button': 2, - 'show_read_unread_button': 3, + 'show_reply_button': 10, + 'show_read_unread_button': 11, 'show_compose_message': true } ); -- cgit v1.2.3 From e81ee26f64530ccba748d8d0dd975d1db3fde350 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 22 Oct 2012 09:50:58 +0200 Subject: [FIX] mail: openchatter, sort for expandable message bzr revid: chm@openerp.com-20121022075058-5sm5hs6lr8tvw2pg --- addons/mail/static/src/js/mail.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 6adc357023e..46db23fc99a 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -144,12 +144,6 @@ 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(); }, @@ -687,6 +681,7 @@ openerp.mail = function(session) { self.$el.fadeOut(options.fadeTime, function(){ self.destroy(); }); + self.thread.$el.fadeOut(options.fadeTime); } else { self.destroy(); } @@ -700,7 +695,6 @@ openerp.mail = function(session) { // delete this message and his childs var ids = [this.datasets.id].concat( this.get_child_ids() ); this.ds_message.unlink(ids); - this.animated_destroy(); return false; }, @@ -864,7 +858,7 @@ openerp.mail = function(session) { 'partner_ids' : _.filter(datasets.partner_ids, function(partner){ return partner[0]!=datasets.author_id[0]; } ) }; - this.datasets.show_compose_message = this.options.show_compose_message && this.options.show_reply_button>this.datasets.thread_level; + this.datasets.show_compose_message = this.options.show_compose_message && this.options.show_reply_button > this.datasets.thread_level; this.messages = []; this.ComposeMessage = false; @@ -1088,7 +1082,8 @@ openerp.mail = function(session) { insert_message: function (message) { var self=this; - if(this.datasets.show_compose_message && this.options.display_indented_thread > self.datasets.thread_level && this.options.show_compact_message){ + if(this.datasets.show_compose_message && + this.options.display_indented_thread > self.datasets.thread_level){ this.ComposeMessage.do_show_compact(); } @@ -1103,7 +1098,7 @@ openerp.mail = function(session) { _(thread.get_childs()).each(function (val, key) { thread_messages.push(val.parent_message); }); } - // check older and newer message for insert + // check older and newer message for insertion var parent_newer = false; var parent_older = false; if(message.datasets.id > 0){ @@ -1122,7 +1117,7 @@ openerp.mail = function(session) { } } - var sort = (!!message.datasets.thread_level || message.datasets.id<0); + var sort = (!!self.datasets.thread_level || message.datasets.id<0); if(parent_older){ if(sort){ @@ -1417,7 +1412,8 @@ openerp.mail = function(session) { 'display_indented_thread': 2, 'show_reply_button': 10, 'show_read_unread_button': 11, - 'show_compose_message': true + 'show_compose_message': true, + 'show_compact_message': true } ); -- cgit v1.2.3 From 5bd53c249791473013bbcd53d03dd30f3736ac73 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 22 Oct 2012 10:10:48 +0200 Subject: [IMP] mail.js: delete datasets bzr revid: chm@openerp.com-20121022081048-5ohjli1c3io3iv1b --- addons/mail/static/src/js/mail.js | 247 ++++++++++++++++++-------------------- 1 file changed, 119 insertions(+), 128 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index e90ee5fc6e4..042a8cecf6a 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -118,18 +118,16 @@ openerp.mail = function(session) { var self = this; this._super(parent); this.context = options.context || {}; - - this.datasets = { - 'attachment_ids' : [], - 'id': datasets.id, - 'model': datasets.model, - 'res_model': datasets.res_model, - 'is_private': datasets.is_private || false, - 'partner_ids': datasets.partner_ids || [], - 'avatar': mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid), - }; this.options = options.options; + // 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.parent_thread= parent.messages!= undefined ? parent : false; this.ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment'); @@ -175,24 +173,24 @@ openerp.mail = function(session) { // if the files exits for this answer, delete the file before upload var attachments=[]; - for(var i in this.datasets.attachment_ids){ - if((this.datasets.attachment_ids[i].filename || this.datasets.attachment_ids[i].name) == filename){ - if(this.datasets.attachment_ids[i].upload){ + for(var i in this.attachment_ids){ + if((this.attachment_ids[i].filename || this.attachment_ids[i].name) == filename){ + if(this.attachment_ids[i].upload){ return false; } - this.ds_attachment.unlink([this.datasets.attachment_ids[i].id]); + this.ds_attachment.unlink([this.attachment_ids[i].id]); } else { - attachments.push(this.datasets.attachment_ids[i]); + attachments.push(this.attachment_ids[i]); } } - this.datasets.attachment_ids = attachments; + this.attachment_ids = attachments; // submit file this.$render_expandable.find('form.oe_form_binary_form').submit(); this.$render_expandable.find(".oe_attachment_file").hide(); - this.datasets.attachment_ids.push({ + this.attachment_ids.push({ 'id': 0, 'name': filename, 'filename': filename, @@ -206,9 +204,9 @@ openerp.mail = function(session) { /* when the file is uploaded */ on_attachment_loaded: function (event, result) { - for(var i in this.datasets.attachment_ids){ - if(this.datasets.attachment_ids[i].filename == result.filename && this.datasets.attachment_ids[i].upload) { - this.datasets.attachment_ids[i]={ + for(var i in this.attachment_ids){ + if(this.attachment_ids[i].filename == result.filename && this.attachment_ids[i].upload) { + this.attachment_ids[i]={ 'id': result.id, 'name': result.name, 'filename': result.filename, @@ -230,15 +228,15 @@ openerp.mail = function(session) { var attachment_id=$(event.target).data("id"); if (attachment_id) { var attachments=[]; - for(var i in this.datasets.attachment_ids){ - if(attachment_id!=this.datasets.attachment_ids[i].id){ - attachments.push(this.datasets.attachment_ids[i]); + for(var i in this.attachment_ids){ + if(attachment_id!=this.attachment_ids[i].id){ + attachments.push(this.attachment_ids[i]); } else { this.ds_attachment.unlink([attachment_id]); } } - this.datasets.attachment_ids = attachments; + this.attachment_ids = attachments; this.display_attachments(); } }, @@ -287,16 +285,16 @@ openerp.mail = function(session) { on_compose_fullmail: function(){ var attachments=[]; - for(var i in this.datasets.attachment_ids){ - attachments.push(this.datasets.attachment_ids[i].id); + for(var i in this.attachment_ids){ + attachments.push(this.attachment_ids[i].id); } /* TDE note: I think this is not necessary, because * 1/ post on a document: followers added server-side in _notify * 2/ reply to a message: mail.compose.message should add the previous partners */ var partner_ids=[]; - for(var i in this.datasets.partner_ids){ - partner_ids.push(this.datasets.partner_ids[i][0]); + for(var i in this.partner_ids){ + partner_ids.push(this.partner_ids[i][0]); } var action = { type: 'ir.actions.act_window', @@ -310,7 +308,7 @@ openerp.mail = function(session) { 'default_model': this.context.default_model, 'default_res_id': this.context.default_res_id, 'default_content_subtype': 'html', - 'default_parent_id': this.datasets.id, + 'default_parent_id': this.id, 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''), 'default_attachment_ids': attachments, 'default_partner_ids': partner_ids @@ -324,7 +322,7 @@ openerp.mail = function(session) { this.$render_expandable.find('textarea').val(""); this.$render_expandable.find('input[data-id]').remove(); - this.datasets.attachment_ids=[]; + this.attachment_ids=[]; this.display_attachments(); this.stay_open = false; @@ -342,12 +340,12 @@ openerp.mail = function(session) { } var attachments=[]; - for(var i in this.datasets.attachment_ids){ - if(this.datasets.attachment_ids[i].upload){ + for(var i in this.attachment_ids){ + if(this.attachment_ids[i].upload){ session.web.dialog($('
' + session.web.qweb.render('CrashManager.warning', {message: 'Please, wait while the file is uploading.'}) + '
')); return false; } - attachments.push(this.datasets.attachment_ids[i].id); + attachments.push(this.attachment_ids[i].id); } if(body.match(/\S+/)) { @@ -446,18 +444,15 @@ openerp.mail = function(session) { default_res_id: 0, default_parent_id: false }, options.context || {}); - this.datasets = { - 'id' : datasets.id || -1, - 'model' : datasets.model || false, - 'parent_id' : datasets.parent_id || false, - 'nb_messages' : datasets.nb_messages || 0, - 'thread_level' : datasets.thread_level || 0, - 'type' : 'expandable', - 'max_limit' : datasets.max_limit || false, - 'flag_used' : false, - }; - - // record options and data + // data of this expandable message + this.id = datasets.id || -1, + this.model = datasets.model || false, + this.parent_id = datasets.parent_id || false, + this.nb_messages = datasets.nb_messages || 0, + this.thread_level = datasets.thread_level || 0, + this.type = 'expandable', + this.max_limit = datasets.max_limit || false, + this.flag_used = false, this.parent_thread= parent.messages!= undefined ? parent : options.options._parents[0] ; }, @@ -492,10 +487,10 @@ openerp.mail = function(session) { */ on_expandable: function (event) { if(event)event.stopPropagation(); - if(this.datasets.flag_used) { + if(this.flag_used) { return false } - this.datasets.flag_used = true; + this.flag_used = true; this.animated_destroy({'fadeTime':300}); this.parent_thread.message_fetch(false, this.domain, this.context); @@ -543,28 +538,26 @@ openerp.mail = function(session) { init: function(parent, datasets, options) { this._super(parent); - // record datasets - this.datasets = _.extend({ - 'id' : -1, - 'model' : false, - 'parent_id': false, - 'res_id' : false, - 'type' : false, - 'is_author' : false, - 'is_private' : false, - 'subject' : false, - 'name' : false, - 'record_name' : false, - 'body' : false, - 'vote_nb' :0, - 'has_voted' : false, - 'is_favorite' : false, - 'thread_level' : 0, - 'to_read' : true, - 'author_id' : [], - 'attachment_ids' : [], - }, datasets || {}); - this.datasets._date = datasets.date; + // data of this message + this.id = datasets.id || -1, + this.model = datasets.model || false, + this.parent_id = datasets.parent_id || false, + this.res_id = datasets.res_id || false, + this.type = datasets.type || false, + this.is_author = datasets.is_author || false, + this.is_private = datasets.is_private || false, + this.subject = datasets.subject || false, + this.name = datasets.name || false, + this.record_name = datasets.record_name || false, + this.body = datasets.body || false, + this.vote_nb = datasets.vote_nb || 0, + this.has_voted = datasets.has_voted || false, + this.is_favorite = datasets.is_favorite || false, + this.thread_level = datasets.thread_level || 0, + this.to_read = datasets.to_read || true, + this.author_id = datasets.author_id || [], + this.attachment_ids = datasets.attachment_ids || [], + this._date = datasets.date; // record domain and context this.domain = options.domain || []; @@ -576,14 +569,14 @@ openerp.mail = function(session) { // record options this.options = options.options; - this.datasets.show_reply_button = this.options.show_compose_message && this.options.show_reply_button > this.datasets.thread_level; - this.datasets.show_read_unread_button = this.options.show_read_unread_button > this.datasets.thread_level; + 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.thread = false; - if( this.datasets.id > 0 ) { + if( this.id > 0 ) { this.formating_data(); } @@ -595,15 +588,15 @@ openerp.mail = function(session) { formating_data: function(){ //formating and add some fields for render - this.datasets.date = session.web.format_value(this.datasets._date, {type:"datetime"}); - this.datasets.timerelative = $.timeago(this.datasets.date); - if (this.datasets.type == 'email') { - this.datasets.avatar = ('/mail/static/src/img/email_icon.png'); + this.date = session.web.format_value(this._date, {type:"datetime"}); + this.timerelative = $.timeago(this.date); + if (this.type == 'email') { + this.avatar = ('/mail/static/src/img/email_icon.png'); } else { - this.datasets.avatar = mail.ChatterUtils.get_image(this.session, 'res.partner', 'image_small', this.datasets.author_id[0]); + this.avatar = mail.ChatterUtils.get_image(this.session, 'res.partner', 'image_small', this.author_id[0]); } - for (var l in this.datasets.attachment_ids) { - var attach = this.datasets.attachment_ids[l]; + for (var l in this.attachment_ids) { + var attach = this.attachment_ids[l]; attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach); } }, @@ -663,12 +656,12 @@ openerp.mail = function(session) { return false; } /*create thread*/ - this.thread = new mail.Thread(this, this.datasets, { + this.thread = new mail.Thread(this, this, { 'domain': this.domain, 'context':{ - 'default_model': this.datasets.model, - 'default_res_id': this.datasets.res_id, - 'default_parent_id': this.datasets.id + 'default_model': this.model, + 'default_res_id': this.res_id, + 'default_parent_id': this.id }, 'options': this.options } @@ -696,7 +689,7 @@ openerp.mail = function(session) { this.animated_destroy({fadeTime:250}); // delete this message and his childs - var ids = [this.datasets.id].concat( this.get_child_ids() ); + var ids = [this.id].concat( this.get_child_ids() ); this.ds_message.unlink(ids); return false; }, @@ -709,7 +702,7 @@ openerp.mail = function(session) { // and send its opposite to set_message_read event.stopPropagation(); // if this message is read, all childs message display is read - var ids = [this.datasets.id].concat( this.get_child_ids() ); + var ids = [this.id].concat( this.get_child_ids() ); var read = $(event.srcElement).hasClass("oe_read"); this.$el.removeClass(read ? 'oe_msg_unread':'oe_msg_read').addClass(read ? 'oe_msg_read':'oe_msg_unread'); @@ -739,7 +732,7 @@ openerp.mail = function(session) { } } - if(this.datasets.id==options.id) + if(this.id==options.id) return this; for(var i in this.thread.messages){ @@ -756,7 +749,7 @@ openerp.mail = function(session) { */ get_child_ids: function(){ var res=[] - if(arguments[0]) res.push(this.datasets.id); + if(arguments[0]) res.push(this.id); if(this.thread){ res = res.concat( this.thread.get_child_ids(true) ); } @@ -766,10 +759,10 @@ openerp.mail = function(session) { on_vote: function (event) { event.stopPropagation(); var self=this; - return this.ds_message.call('vote_toggle', [[self.datasets.id]]).pipe(function(vote){ + return this.ds_message.call('vote_toggle', [[self.id]]).pipe(function(vote){ // TDE note: to update, because vote_user_ids is about to disappear to be replaced by vote_nb (number of votes) - self.datasets.has_voted=vote; - self.datasets.vote_nb += self.datasets.has_voted ? 1 : -1; + self.has_voted=vote; + self.vote_nb += self.has_voted ? 1 : -1; self.display_vote(); }); return false; @@ -788,9 +781,9 @@ openerp.mail = function(session) { event.stopPropagation(); var self=this; var button = self.$('button.oe_mail_starbox:first'); - return this.ds_message.call('favorite_toggle', [[self.datasets.id]]).pipe(function(star){ - self.datasets.is_favorite=star; - if(self.datasets.is_favorite){ + return this.ds_message.call('favorite_toggle', [[self.id]]).pipe(function(star){ + self.is_favorite=star; + if(self.is_favorite){ button.addClass('oe_stared'); } else { button.removeClass('oe_stared'); @@ -852,20 +845,18 @@ openerp.mail = function(session) { // record options and data this.parent_message= parent.thread!= undefined ? parent : false ; - // datasets and internal vars - this.datasets = { - 'id' : datasets.id || false, - 'model' : datasets.model || false, - 'parent_id' : datasets.parent_id || false, - 'is_private' : datasets.is_private || false, - 'author_id' : datasets.author_id || false, - 'thread_level' : (datasets.thread_level+1) || 0, - 'partner_ids' : _.filter(datasets.partner_ids, function(partner){ return partner[0]!=datasets.author_id[0]; } ) - }; - - this.datasets.show_compose_message = this.options.show_compose_message && this.options.show_reply_button > this.datasets.thread_level; - + // data of this thread + this.id = datasets.id || false, + this.model = datasets.model || false, + this.parent_id = datasets.parent_id || false, + this.is_private = datasets.is_private || false, + this.author_id = datasets.author_id || false, + this.thread_level = (datasets.thread_level+1) || 0, + this.partner_ids = _.filter(datasets.partner_ids, function(partner){ return partner[0]!=datasets.author_id[0]; } ) this.messages = []; + this.show_compose_message = this.options.show_compose_message && this.options.show_reply_button > this.thread_level; + + // object compose message this.ComposeMessage = false; this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model || 'mail.thread'); @@ -874,7 +865,7 @@ openerp.mail = function(session) { start: function() { this._super.apply(this, arguments); - if(this.datasets.show_compose_message){ + if(this.show_compose_message){ this.instantiate_ComposeMessage(); } this.bind_events(); @@ -882,12 +873,12 @@ openerp.mail = function(session) { instantiate_ComposeMessage: function(){ // add message composition form view - this.ComposeMessage = new mail.ThreadComposeMessage(this, this.datasets, { + this.ComposeMessage = new mail.ThreadComposeMessage(this, this, { 'context': this.context, 'options': this.options, }); - if(this.datasets.thread_level){ + if(this.thread_level){ this.ComposeMessage.appendTo(this.$el); } else { // root view @@ -904,7 +895,7 @@ openerp.mail = function(session) { this.$('.oe_msg_expandable:last'); var message = this.messages[this.messages.length-1]; - if(message && message.datasets.type=="expandable" && message.datasets.max_limit){ + if(message && message.type=="expandable" && message.max_limit){ var pos = message.$el.position(); if(pos.top){ /* bottom of the screen */ @@ -941,7 +932,7 @@ openerp.mail = function(session) { */ get_child_ids: function(){ var res=[]; - _(this.get_childs()).each(function (val, key) { res.push(val.datasets.id); }); + _(this.get_childs()).each(function (val, key) { res.push(val.id); }); return res; }, @@ -976,7 +967,7 @@ openerp.mail = function(session) { return this.options._parents[0].browse_thread(options); } - if(this.datasets.id==options.id){ + if(this.id==options.id){ return this; } @@ -1035,7 +1026,7 @@ openerp.mail = function(session) { // domain and context: options + additional fetch_domain = replace_domain ? replace_domain : this.domain; fetch_context = replace_context ? replace_context : this.context; - var message_loaded = [this.datasets.id||0].concat( self.options._parents[0].get_child_ids() ); + var message_loaded = [this.id||0].concat( self.options._parents[0].get_child_ids() ); return this.ds_message.call('message_read', [ids, fetch_domain, message_loaded, fetch_context, this.context.default_parent_id || undefined] ).then(this.proxy('switch_new_message')); @@ -1052,10 +1043,10 @@ openerp.mail = function(session) { 'context': { 'default_model': data.model || self.context.default_model, 'default_res_id': data.res_id || self.context.default_res_id, - 'default_parent_id': self.datasets.id }, + 'default_parent_id': self.id }, }); } else { - var message = new mail.ThreadMessage(self, _.extend(data, {'thread_level': self.datasets.thread_level}), { + var message = new mail.ThreadMessage(self, _.extend(data, {'thread_level': self.thread_level}), { 'domain': data.domain, 'context': { 'default_model': data.model, @@ -1070,9 +1061,9 @@ openerp.mail = function(session) { // check if the message is already create for(var i in self.messages){ - if(self.messages[i].datasets.id == message.datasets.id){ + if(self.messages[i].id == message.id){ self.messages[i].destroy(); - if(message.datasets.id>0){ + if(message.id>0){ self.messages[i] = message; return true; } else { @@ -1087,8 +1078,8 @@ openerp.mail = function(session) { insert_message: function (message) { var self=this; - if(this.datasets.show_compose_message && - this.options.display_indented_thread > self.datasets.thread_level){ + if(this.show_compose_message && + this.options.display_indented_thread > self.thread_level){ this.ComposeMessage.do_show_compact(); } @@ -1097,7 +1088,7 @@ openerp.mail = function(session) { // insert on hierarchy display => insert in self child var thread_messages = self.messages; var thread = self; - if( self.options.display_indented_thread < self.datasets.thread_level ) { + if( self.options.display_indented_thread < self.thread_level ) { var thread = self.options._parents[self.options.display_indented_thread] || self.options._parents[0]; var thread_messages = []; _(thread.get_childs()).each(function (val, key) { thread_messages.push(val.parent_message); }); @@ -1106,23 +1097,23 @@ openerp.mail = function(session) { // check older and newer message for insertion var parent_newer = false; var parent_older = false; - if(message.datasets.id > 0){ + if(message.id > 0){ for(var i in thread_messages){ - if(thread_messages[i].datasets.id > message.datasets.id){ + if(thread_messages[i].id > message.id){ if(!parent_newer || - parent_newer.datasets.id > thread_messages[i].datasets.id) { + parent_newer.id > thread_messages[i].id) { parent_newer = thread_messages[i]; } - } else if(thread_messages[i].datasets.id > 0 && thread_messages[i].datasets.id < message.datasets.id) { + } else if(thread_messages[i].id > 0 && thread_messages[i].id < message.id) { if(!parent_older || - parent_older.datasets.id < thread_messages[i].datasets.id) { + parent_older.id < thread_messages[i].id) { parent_older = thread_messages[i]; } } } } - var sort = (!!self.datasets.thread_level || message.datasets.id<0); + var sort = (!!self.thread_level || message.id<0); if(parent_older){ if(sort){ @@ -1131,13 +1122,13 @@ openerp.mail = function(session) { message.insertBefore(parent_older.$el); } } else if(parent_newer){ - if(sort || parent_newer.datasets.id<0){ + if(sort || parent_newer.id<0){ message.insertBefore(parent_newer.$el); } else { message.insertAfter(parent_newer.thread ? parent_newer.thread.$el : parent_newer.$el); } } else { - if(sort && message.datasets.id>0) { + if(sort && message.id>0) { message.prependTo(thread.$el); } else { message.appendTo(thread.$el); -- cgit v1.2.3 From 87afad0a4df19a38787e452f685110766099fa2c Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 22 Oct 2012 10:59:02 +0200 Subject: [IMP] mail.js: more comment bzr revid: chm@openerp.com-20121022085902-kxb9jhdmknhmdg7x --- addons/mail/static/src/js/mail.js | 154 ++++++++++++++++++++++++++++---------- 1 file changed, 114 insertions(+), 40 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 042a8cecf6a..d70be673fd4 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -7,7 +7,7 @@ openerp.mail = function(session) { openerp_mail_followers(session, mail); // import mail_followers.js /** - * ------------------------------------------------------------ + * ------------------------------------------------------------ * FormView * ------------------------------------------------------------ * @@ -38,7 +38,7 @@ openerp.mail = function(session) { /** - * ------------------------------------------------------------ + * ------------------------------------------------------------ * ChatterUtils * ------------------------------------------------------------ * @@ -51,17 +51,20 @@ openerp.mail = function(session) { mail.ChatterUtils = { - /** Get an image in /web/binary/image?... */ + /** + *Get an image in /web/binary/image?... */ get_image: function(session, model, field, id) { return session.prefix + '/web/binary/image?session_id=' + session.session_id + '&model=' + model + '&field=' + field + '&id=' + (id || ''); }, - /** Get the url of an attachment {'id': id} */ + /** + *Get the url of an attachment {'id': id} */ get_attachment_url: function (session, attachment) { return session.origin + '/web/binary/saveas?session_id=' + session.session_id + '&model=ir.attachment&field=datas&filename_field=datas_fname&id=' + attachment['id']; }, - /** Replaces some expressions + /** + *Replaces some expressions * - :name - shortcut to an image */ do_replace_expressions: function (string) { @@ -91,7 +94,7 @@ openerp.mail = function(session) { /** - * ------------------------------------------------------------ + * ------------------------------------------------------------ * ComposeMessage widget * ------------------------------------------------------------ * @@ -420,8 +423,8 @@ openerp.mail = function(session) { } }); - /** - * ------------------------------------------------------------ + /** + * ------------------------------------------------------------ * Thread Message Expandable Widget * ------------------------------------------------------------ * @@ -493,13 +496,13 @@ openerp.mail = function(session) { this.flag_used = true; this.animated_destroy({'fadeTime':300}); - this.parent_thread.message_fetch(false, this.domain, this.context); + this.parent_thread.message_fetch(this.domain, this.context); return false; }, }); - /** - * ------------------------------------------------------------ + /** + * ------------------------------------------------------------ * Thread Message Widget * ------------------------------------------------------------ * This widget handles the display of a messages in a thread. @@ -554,7 +557,7 @@ openerp.mail = function(session) { this.has_voted = datasets.has_voted || false, this.is_favorite = datasets.is_favorite || false, this.thread_level = datasets.thread_level || 0, - this.to_read = datasets.to_read || true, + this.to_read = datasets.to_read || false, this.author_id = datasets.author_id || [], this.attachment_ids = datasets.attachment_ids || [], this._date = datasets.date; @@ -585,6 +588,9 @@ openerp.mail = function(session) { this.ds_follow = new session.web.DataSetSearch(this, 'mail.followers'); }, + /** + *Convert date, timerelative and avatar in displayable data. + */ formating_data: function(){ //formating and add some fields for render @@ -634,6 +640,9 @@ openerp.mail = function(session) { this.$el.on('click', 'a.oe_mail_starbox', this.on_star); }, + /** + * call the on_compose_message on the thread of this message. + */ on_message_reply:function(event){ event.stopPropagation(); this.thread.on_compose_message(); @@ -651,6 +660,10 @@ openerp.mail = function(session) { }); }, + /** + * instantiate the thread object of this message. + * Each message have only one thread. + */ create_thread: function(){ if(this.thread){ return false; @@ -670,6 +683,10 @@ openerp.mail = function(session) { this.thread.insertAfter(this.$el); }, + /** + * Fade out the message and his child thread. + * Then this object is destroyed. + */ animated_destroy: function(options) { var self=this; //graphic effects @@ -683,6 +700,10 @@ openerp.mail = function(session) { } }, + /** + * Wait a confirmation for delete the message on the DB. + * Make an animate destroy + */ on_message_delete: function (event) { event.stopPropagation(); if (! confirm(_t("Do you really want to delete this message?"))) { return false; } @@ -715,7 +736,9 @@ openerp.mail = function(session) { return false; }, - /** browse message + /** + * search a message in all thread and child thread. + * This method return an object message. * @param {object}{int} option.id * @param {object}{string} option.model * @param {object}{boolean} option._go_thread_wall @@ -745,7 +768,8 @@ openerp.mail = function(session) { return false; }, - /* get all child message/thread id linked + /* get all child message id linked. + * @return array of id */ get_child_ids: function(){ var res=[] @@ -756,6 +780,9 @@ openerp.mail = function(session) { return res; }, + /** + * add or remove a vote for a message and display the result + */ on_vote: function (event) { event.stopPropagation(); var self=this; @@ -768,7 +795,9 @@ openerp.mail = function(session) { return false; }, - // Render vote Display template. + /** + * 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}); @@ -776,7 +805,9 @@ openerp.mail = function(session) { self.$(".oe_mail_vote_count:first").replaceWith(vote_element); }, - // Stared/unstared + Render star. + /** + * add or remove a favorite (or starred) for a message and change class on the DOM + */ on_star: function (event) { event.stopPropagation(); var self=this; @@ -797,8 +828,8 @@ openerp.mail = function(session) { }); - /** - * ------------------------------------------------------------ + /** + * ------------------------------------------------------------ * Thread Widget * ------------------------------------------------------------ * @@ -871,6 +902,9 @@ openerp.mail = function(session) { this.bind_events(); }, + /* instantiate the compose message object and insert this on the DOM. + * The compose message is display in compact form. + */ instantiate_ComposeMessage: function(){ // add message composition form view this.ComposeMessage = new mail.ThreadComposeMessage(this, this, { @@ -916,19 +950,26 @@ openerp.mail = function(session) { self.$el.on('click', '.oe_mail_compose_textarea .oe_more_hidden', self.on_hide_recipients); }, + /** + *show all the partner list of this parent message + */ on_show_recipients: function(){ var p=$(this).parent(); p.find('.oe_more_hidden, .oe_hidden').show(); p.find('.oe_more').hide(); }, + /** + *hide a part of the partner list of this parent message + */ on_hide_recipients: function(){ var p=$(this).parent(); p.find('.oe_more_hidden, .oe_hidden').hide(); p.find('.oe_more').show(); }, - /* get all child message/thread id linked + /* get all child message/thread id linked. + * @return array of id */ get_child_ids: function(){ var res=[]; @@ -936,7 +977,9 @@ openerp.mail = function(session) { return res; }, - /* get all child message/thread linked + /* get all child message/thread linked. + * @param {int} nb_thread_level, number of traversed thread level for this search + * @return array of thread object */ get_childs: function(nb_thread_level){ var res=[]; @@ -951,7 +994,9 @@ openerp.mail = function(session) { return res; }, - /** browse thread + /** + *search a thread in all thread and child thread. + * This method return an object thread. * @param {object}{int} option.id * @param {object}{string} option.model * @param {object}{boolean} option._go_thread_wall @@ -987,19 +1032,24 @@ openerp.mail = function(session) { return false; }, - /** browse message + /** + *search a message in all thread and child thread. + * This method return an object message. * @param {object}{int} option.id * @param {object}{string} option.model * @param {object}{boolean} option._go_thread_wall * private for check the top thread - * @return thread object + * @return message object */ browse_message: function(options){ if(this.options._parents[0].messages[0]) return this.options._parents[0].messages[0].browse_message(options); }, - /* this function is launch when a user click on "Reply" button + /** + *If ComposeMessage doesn't exist, instantiate the compose message. + * Call the on_compose_expandable method to allow the user to write his message. + * (Is call when a user click on "Reply" button) */ on_compose_message: function(){ if(!this.ComposeMessage){ @@ -1010,17 +1060,22 @@ openerp.mail = function(session) { this.ComposeMessage.on_compose_expandable(); }, - /* display the no message on the thread + /** + *display the message "there are no message" on the thread */ no_message: function(){ $(session.web.qweb.render('mail.wall_no_message', {})).appendTo(this.$el); }, - /** Fetch messages + /** + *make a request to read the message (calling RPC to "message_read"). + * The result of this method is send to the switch message for sending ach message to + * his parented object thread. * @param {Array} replace_domain: added to this.domain * @param {Object} replace_context: added to this.context + * @param {Array} ids read (if the are some ids, the method don't use the domain) */ - message_fetch: function (initial_mode, replace_domain, replace_context, ids, callback) { + message_fetch: function (replace_domain, replace_context, ids) { var self = this; // domain and context: options + additional @@ -1032,7 +1087,11 @@ openerp.mail = function(session) { ).then(this.proxy('switch_new_message')); }, - /* create record object and linked him + /** + *create the message object and attached on this thread. + * When the message object is create, this method call insert_message for, + * displaying this message on the DOM. + * @param : {object} data from calling RPC to "message_read" */ create_message_object: function (data) { var self = this; @@ -1074,7 +1133,15 @@ openerp.mail = function(session) { self.messages.push( message ); }, - /** Displays a message or an expandable message */ + /** + *insert the message on the DOM. + * All message (and expandable message) are sorted. The method get the + * older and newer message to insert the message (before, after). + * If there are no older or newer, the message is prepend or append to + * the thread (parent object or on root thread for flat view). + * The sort is define by the thread_level (O for newer on top). + * @param : {object} ThreadMessage object + */ insert_message: function (message) { var self=this; @@ -1143,7 +1210,11 @@ openerp.mail = function(session) { return message }, - /* Send the records to his parent thread */ + /** + *get the parent thread of the messages. + * Each message is send to his parent object for creating the object message. + * @param : {Array} datas from calling RPC to "message_read" + */ switch_new_message: function(records) { var self=this; _(records).each(function(record){ @@ -1155,8 +1226,8 @@ openerp.mail = function(session) { }, }); - /** - * ------------------------------------------------------------ + /** + * ------------------------------------------------------------ * mail : root Widget * ------------------------------------------------------------ * @@ -1224,9 +1295,12 @@ openerp.mail = function(session) { this.bind_events(); }, + /** - * Display the threads - */ + *Create the root thread and display this object in the DOM. + * Call the no_message method then c all the message_fetch method + * of this root thread to display the messages. + */ message_render: function (search) { this.thread = new mail.Thread(this, {}, { @@ -1254,8 +1328,8 @@ openerp.mail = function(session) { }); - /** - * ------------------------------------------------------------ + /** + * ------------------------------------------------------------ * mail_thread Widget * ------------------------------------------------------------ * @@ -1321,8 +1395,8 @@ openerp.mail = function(session) { }); - /** - * ------------------------------------------------------------ + /** + * ------------------------------------------------------------ * Wall Widget * ------------------------------------------------------------ * @@ -1397,7 +1471,7 @@ openerp.mail = function(session) { /** - * Display the threads + *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']); @@ -1426,7 +1500,7 @@ openerp.mail = function(session) { /** - * ------------------------------------------------------------ + * ------------------------------------------------------------ * UserMenu * ------------------------------------------------------------ * -- cgit v1.2.3 From 739694db06c0f25277eab0404cd43f2e943af410 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 22 Oct 2012 15:32:47 +0200 Subject: [IMP] mail: concat expandable messages bzr revid: chm@openerp.com-20121022133247-oen01b8ozq2cozhk --- addons/mail/static/src/js/mail.js | 201 +++++++++++++++++++++++++++++++------- 1 file changed, 164 insertions(+), 37 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index d70be673fd4..f6b6c0e43bc 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -89,6 +89,28 @@ openerp.mail = function(session) { return text .replace(/[\n\r]/g,'
') .replace(/((?:https?|ftp):\/\/[\S]+)/g,'$1 ') + }, + + /** + * return the complete domain with "&" + */ + expend_domain: function (domain) { + var new_domain = []; + var nb_and = -1; + + for ( var k = domain.length-1; k >= 0 ; k-- ) { + if ( typeof domain[k] != 'array' ) { + nb_and -= 2; + continue; + } + nb_and += 1; + } + + for (var k = 0; k < nb_and ; k++){ + domain.unshift('&'); + } + + return domain; } }; @@ -134,6 +156,7 @@ openerp.mail = function(session) { this.parent_thread= parent.messages!= undefined ? parent : false; this.ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment'); + this.show_delete_attachment = true; this.fileupload_id = _.uniqueId('oe_fileupload_temp'); $(window).on(self.fileupload_id, self.on_attachment_loaded); @@ -365,6 +388,7 @@ openerp.mail = function(session) { ]).then(function(records){ self.parent_thread.switch_new_message(records); self.on_cancel(); + self.do_show_compact(); //session.web.unblockUI(); }); return true; @@ -454,7 +478,7 @@ openerp.mail = function(session) { this.nb_messages = datasets.nb_messages || 0, this.thread_level = datasets.thread_level || 0, this.type = 'expandable', - this.max_limit = datasets.max_limit || false, + this.max_limit = this.id < 0 || false, this.flag_used = false, this.parent_thread= parent.messages!= undefined ? parent : options.options._parents[0] ; }, @@ -465,12 +489,18 @@ openerp.mail = function(session) { this.bind_events(); }, + reinit: function () { + var $render = $(session.web.qweb.render('mail.thread.expandable', {'widget': this})); + this.$el.replaceWith( $render ); + this.$el = $render; + this.bind_events(); + }, + /** * Bind events in the widget. Each event is slightly described * in the function. */ bind_events: function() { - var self = this; - this.$el.on('click', 'a.oe_msg_fetch_more', self.on_expandable); + this.$el.on('click', 'a.oe_msg_fetch_more', this.on_expandable); }, animated_destroy: function(options) { @@ -692,11 +722,11 @@ openerp.mail = function(session) { //graphic effects if(options && options.fadeTime) { self.$el.fadeOut(options.fadeTime, function(){ - self.destroy(); + self.parent_thread.message_to_expandable(self); }); self.thread.$el.fadeOut(options.fadeTime); } else { - self.destroy(); + self.parent_thread.message_to_expandable(self); } }, @@ -719,20 +749,19 @@ openerp.mail = function(session) { * @param {object} mouse envent */ on_message_read_unread: function (event) { - // TDE note: code here seems complicated... just check that current message is read (value coming from server) - // and send its opposite to set_message_read event.stopPropagation(); - // if this message is read, all childs message display is read - var ids = [this.id].concat( this.get_child_ids() ); - var read = $(event.srcElement).hasClass("oe_read"); - this.$el.removeClass(read ? 'oe_msg_unread':'oe_msg_read').addClass(read ? 'oe_msg_read':'oe_msg_unread'); + var self=this; - if( (read && this.options.typeof_thread == 'inbox') || - (!read && this.options.typeof_thread == 'archives')) { + if( (this.to_read && this.options.typeof_thread == 'inbox') || + (!this.to_read && this.options.typeof_thread == 'archives')) { this.animated_destroy({fadeTime:250}); } - // TDE note: should have a context here - this.ds_notification.call('set_message_read', [ids, read]); + + // 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(this.to_read ? 'oe_msg_unread':'oe_msg_read').addClass(self.to_read ? 'oe_msg_read':'oe_msg_unread'); + self.to_read = !self.to_read; + }); return false; }, @@ -787,8 +816,7 @@ openerp.mail = function(session) { event.stopPropagation(); var self=this; return this.ds_message.call('vote_toggle', [[self.id]]).pipe(function(vote){ - // TDE note: to update, because vote_user_ids is about to disappear to be replaced by vote_nb (number of votes) - self.has_voted=vote; + self.has_voted = vote; self.vote_nb += self.has_voted ? 1 : -1; self.display_vote(); }); @@ -929,7 +957,7 @@ openerp.mail = function(session) { this.$('.oe_msg_expandable:last'); var message = this.messages[this.messages.length-1]; - if(message && message.type=="expandable" && message.max_limit){ + if(message && message.type=="expandable" && message.max_limit) { var pos = message.$el.position(); if(pos.top){ /* bottom of the screen */ @@ -1016,11 +1044,12 @@ openerp.mail = function(session) { return this; } - if(options.id) - for(var i in this.messages){ - if(this.messages[i].thread){ - var res=this.messages[i].thread.browse_thread({'id':options.id, '_go_thread_wall':true}); - if(res) return res; + if(options.id){ + for(var i in this.messages){ + if(this.messages[i].thread){ + var res=this.messages[i].thread.browse_thread({'id':options.id, '_go_thread_wall':true}); + if(res) return res; + } } } @@ -1167,13 +1196,11 @@ openerp.mail = function(session) { if(message.id > 0){ for(var i in thread_messages){ if(thread_messages[i].id > message.id){ - if(!parent_newer || - parent_newer.id > thread_messages[i].id) { + if(!parent_newer || parent_newer.id > thread_messages[i].id) { parent_newer = thread_messages[i]; } } else if(thread_messages[i].id > 0 && thread_messages[i].id < message.id) { - if(!parent_older || - parent_older.id < thread_messages[i].id) { + if(!parent_older || parent_older.id < thread_messages[i].id) { parent_older = thread_messages[i]; } } @@ -1182,23 +1209,41 @@ openerp.mail = function(session) { var sort = (!!self.thread_level || message.id<0); - if(parent_older){ - if(sort){ - message.insertAfter(parent_older.thread ? parent_older.thread.$el : parent_older.$el); - } else { - message.insertBefore(parent_older.$el); - } - } else if(parent_newer){ - if(sort || parent_newer.id<0){ + + if (sort) { + if (parent_older) { + + message.insertAfter(parent_older.$el); + + } else if(parent_newer) { + message.insertBefore(parent_newer.$el); + + } else if(message.id < 0) { + + message.appendTo(thread.$el); + } else { - message.insertAfter(parent_newer.thread ? parent_newer.thread.$el : parent_newer.$el); + + message.prependTo(thread.$el); } } else { - if(sort && message.id>0) { + if (parent_older) { + + message.insertBefore(parent_older.$el); + + } else if(parent_newer) { + + message.insertAfter(parent_newer.$el); + + } else if(message.id < 0) { + message.prependTo(thread.$el); + } else { + message.appendTo(thread.$el); + } } @@ -1224,6 +1269,88 @@ openerp.mail = function(session) { }).create_message_object( record ); }); }, + + /** + * Convert a destroyed message into a expandable message + */ + message_to_expandable: function (message) { + + if(!this.thread_level || message.isDestroyed()) { + message.destroy(); + return false; + } + + var messages = _.sortBy( _.filter(this.messages, function (val) { return !val.isDestroyed(); }), function (val) { return val.id; }); + var it = _.indexOf( messages, message ); + + var msg_up = messages[it-1]; + var msg_down = messages[it+1]; + + var message_dom = [ '&', ["id","in",[message.id]], ['parent_id', '=', message.parent_id] ]; + + if ( msg_up && msg_up.type == "expandable" && msg_down && msg_down.type == "expandable") { + // concat two expandable message and add this message to this dom + msg_up.domain = mail.ChatterUtils.expend_domain( msg_up.domain ); + msg_down.domain = mail.ChatterUtils.expend_domain( msg_down.domain ); + + msg_down.domain = ['|','|'].concat( msg_up.domain ).concat( message_dom ).concat( msg_down.domain ); + + if( !msg_down.max_limit ){ + msg_down.nb_messages += 1 + msg_up.nb_messages; + } + + msg_up.$el.remove(); + msg_up.destroy(); + + msg_down.reinit(); + + } else if ( msg_up && msg_up.type == "expandable") { + // concat preview expandable message and this message to this dom + msg_up.domain = mail.ChatterUtils.expend_domain( msg_up.domain ); + msg_up.domain = ['|'].concat( msg_up.domain ).concat( message_dom ); + + msg_up.nb_messages++; + + msg_up.reinit(); + + } else if ( msg_down && msg_down.type == "expandable") { + // concat next expandable message and this message to this dom + msg_down.domain = mail.ChatterUtils.expend_domain( msg_down.domain ); + msg_down.domain = ['|'].concat( msg_down.domain ).concat( message_dom ); + + // it's maybe a message expandable for the max limit read message + if( !msg_down.max_limit ){ + msg_down.nb_messages++; + } + + msg_down.reinit(); + + } else { + // create a expandable message + var expandable = new mail.ThreadExpandable(this, { + 'id': message.id, + 'model': message.model, + 'parent_id': message.parent_id, + 'nb_messages': 1, + 'thread_level': message.thread_level, + }, { + '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 }, + }); + + // add object on array and DOM + this.messages.push(expandable); + expandable.insertAfter(message.$el); + } + + // destroy message + message.destroy(); + + return true; + }, }); /** -- cgit v1.2.3 From eaa40d0c0cc8f6eaeeacca7aec3e7fae8382a1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Mon, 22 Oct 2012 16:19:32 +0200 Subject: [IMP] further work on the icons bzr revid: fva@openerp.com-20121022141932-xbdorr3287748zfw --- addons/mail/static/src/js/mail.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2c8ab4f5b98..77cb3a1938a 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -669,7 +669,7 @@ openerp.mail = function(session) { // event: click on 'Vote' button this.$el.on('click', '.oe_msg_vote', this.on_vote); // event: click on 'starred/favorite' button - this.$el.on('click', '.oe_mail_starbox', this.on_star); + this.$el.on('click', '.oe_star', this.on_star); }, /** @@ -839,15 +839,16 @@ 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.$('button.oe_mail_starbox:first'); + var button = self.$('.oe_star:first'); return this.ds_message.call('favorite_toggle', [[self.id]]).pipe(function(star){ self.is_favorite=star; if(self.is_favorite){ - button.addClass('oe_stared'); + button.addClass('oe_starred'); } else { - button.removeClass('oe_stared'); + button.removeClass('oe_starred'); if( self.options.typeof_thread == 'stared' ) { self.animated_destroy({fadeTime:250}); } -- cgit v1.2.3 From 317d446df0876ccfd73703028470c7a47472d276 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 22 Oct 2012 16:22:06 +0200 Subject: [IMP] mail: concat expandable messages + on_message_destroy bzr revid: chm@openerp.com-20121022142206-6jc28owq41rapqw6 --- addons/mail/static/src/js/mail.js | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2c8ab4f5b98..d5c07b882ad 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -99,7 +99,7 @@ openerp.mail = function(session) { var nb_and = -1; for ( var k = domain.length-1; k >= 0 ; k-- ) { - if ( typeof domain[k] != 'array' ) { + if ( typeof domain[k] != 'array' && typeof domain[k] != 'object' ) { nb_and -= 2; continue; } @@ -110,8 +110,6 @@ openerp.mail = function(session) { domain.unshift('&'); } - console.log( JSON.stringify(domain) ); - return domain; } }; @@ -531,6 +529,16 @@ openerp.mail = function(session) { this.parent_thread.message_fetch(this.domain, this.context); return false; }, + + /** + * call on_message_delete on his parent thread + */ + destroy: function() { + + this._super(); + this.parent_thread.on_message_detroy(this); + + } }); /** @@ -856,6 +864,16 @@ openerp.mail = function(session) { return false; }, + /** + * call on_message_delete on his parent thread + */ + destroy: function() { + + this._super(); + this.parent_thread.on_message_detroy(this); + + } + }); /** @@ -1112,9 +1130,9 @@ openerp.mail = function(session) { // domain and context: options + additional fetch_domain = replace_domain ? replace_domain : this.domain; fetch_context = replace_context ? replace_context : this.context; - var message_loaded = [this.id||0].concat( self.options._parents[0].get_child_ids() ); + 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, fetch_context, this.context.default_parent_id || undefined] + return this.ds_message.call('message_read', [ids, fetch_domain, message_loaded_ids, fetch_context, this.context.default_parent_id || undefined] ).then(this.proxy('switch_new_message')); }, @@ -1269,6 +1287,12 @@ openerp.mail = function(session) { }); }, + on_message_detroy: function (message) { + + this.messages = _.filter(this.messages, function (val) { return !val.isDestroyed(); }); + + }, + /** * Convert a destroyed message into a expandable message */ @@ -1279,7 +1303,7 @@ openerp.mail = function(session) { return false; } - var messages = _.sortBy( _.filter(this.messages, function (val) { return !val.isDestroyed(); }), function (val) { return val.id; }); + var messages = _.sortBy( this.messages, function (val) { return val.id; }); var it = _.indexOf( messages, message ); var msg_up = messages[it-1]; -- cgit v1.2.3 From fb1a0088572e4eef11653afae5d609066a48d7a8 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 22 Oct 2012 16:48:34 +0200 Subject: [IMP] mail: indented DOM class bzr revid: chm@openerp.com-20121022144834-qqnk9etnfuyr25fr --- addons/mail/static/src/js/mail.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 6e7310ac905..bbf68f7711c 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -769,7 +769,7 @@ openerp.mail = function(session) { // 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(this.to_read ? 'oe_msg_unread':'oe_msg_read').addClass(self.to_read ? 'oe_msg_read':'oe_msg_unread'); + 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; }); return false; @@ -934,7 +934,7 @@ openerp.mail = function(session) { this.thread_level = (datasets.thread_level+1) || 0, this.partner_ids = _.filter(datasets.partner_ids, function(partner){ return partner[0]!=datasets.author_id[0]; } ) this.messages = []; - this.show_compose_message = this.options.show_compose_message && this.options.show_reply_button > this.thread_level; + this.show_compose_message = this.options.show_compose_message && (this.options.show_reply_button > this.thread_level || !this.thread_level); // object compose message this.ComposeMessage = false; @@ -1464,7 +1464,7 @@ openerp.mail = function(session) { this.thread.no_message(); this.thread.message_fetch(); - if(this.options.show_compose_message){ + if(this.options.show_compose_message && this.thread.ComposeMessage){ this.thread.ComposeMessage.do_show_compact(); } }, @@ -1535,7 +1535,7 @@ openerp.mail = function(session) { 'context' : this.options.context, 'typeof_thread': this.options.context['typeof_thread'] || 'other', 'display_indented_thread': -1, - 'show_reply_button': 10, + 'show_reply_button': 0, 'show_read_unread_button': -1, 'show_compose_message': show_compose_message } -- cgit v1.2.3 From 57039657e49644e950881598c2a0c949d19cf26b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 23 Oct 2012 09:42:42 +0200 Subject: [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 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'addons/mail/static/src/js') 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 } ); -- cgit v1.2.3 From 7c789f5efa53fb82e4ee71c54b729e798b3bc5af Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 23 Oct 2012 10:47:36 +0200 Subject: [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(-) (limited to 'addons/mail/static/src/js') 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 } ); -- cgit v1.2.3 From 5e839a72de59497140a98e489acbd19cfc978233 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 23 Oct 2012 13:38:42 +0200 Subject: [IMP] mail: convert parent_id to ancestor_id in js side bzr revid: chm@openerp.com-20121023113842-0c9rh3dvr205p7uz --- addons/mail/static/src/js/mail.js | 105 ++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 50 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 025e5d43b9a..4cf17218a4c 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -342,7 +342,7 @@ openerp.mail = function(session) { 'default_model': this.context.default_model, 'default_res_id': this.context.default_res_id, 'default_content_subtype': 'html', - 'default_parent_id': this.id, + 'default_ancestor_id': this.id, 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''), 'default_attachment_ids': attachments, 'default_partner_ids': partner_ids @@ -390,13 +390,12 @@ openerp.mail = function(session) { false, 'comment', 'mail.mt_comment', - this.context.default_parent_id, + this.context.default_ancestor_id, attachments, this.parent_thread.context ]).then(function(records){ self.parent_thread.switch_new_message(records); self.on_cancel(); - self.do_show_compact(); //session.web.unblockUI(); }); return true; @@ -483,12 +482,12 @@ openerp.mail = function(session) { this.context = _.extend({ default_model: 'mail.thread', default_res_id: 0, - default_parent_id: false }, options.context || {}); + default_ancestor_id: false }, options.context || {}); // data of this expandable message this.id = datasets.id || -1, this.model = datasets.model || false, - this.parent_id = datasets.parent_id || false, + this.ancestor_id = datasets.ancestor_id || false, this.nb_messages = datasets.nb_messages || 0, this.thread_level = datasets.thread_level || 0, this.type = 'expandable', @@ -567,10 +566,10 @@ openerp.mail = function(session) { * - record.attachment_ids[].url: url of each attachmentThe * thread view : * - root thread - * - - sub message (parent_id = root message) + * - - sub message (ancestor_id = root message) * - - - sub thread * - - - - sub sub message (parent id = sub thread) - * - - sub message (parent_id = root message) + * - - sub message (ancestor_id = root message) * - - - sub thread */ mail.ThreadMessage = session.web.Widget.extend({ @@ -598,7 +597,7 @@ openerp.mail = function(session) { // data of this message this.id = datasets.id || -1, this.model = datasets.model || false, - this.parent_id = datasets.parent_id || false, + this.ancestor_id = datasets.ancestor_id || false, this.res_id = datasets.res_id || false, this.type = datasets.type || false, this.is_author = datasets.is_author || false, @@ -621,7 +620,7 @@ openerp.mail = function(session) { this.context = _.extend({ default_model: 'mail.thread', default_res_id: 0, - default_parent_id: false }, options.context || {}); + default_ancestor_id: false }, options.context || {}); // record options this.options = options.options; @@ -728,7 +727,7 @@ openerp.mail = function(session) { 'context':{ 'default_model': this.model, 'default_res_id': this.res_id, - 'default_parent_id': this.id + 'default_ancestor_id': this.id }, 'options': this.options } @@ -898,10 +897,10 @@ openerp.mail = function(session) { * This widget handles the display of a thread of messages. The * thread view: * - root thread - * - - sub message (parent_id = root message) + * - - sub message (ancestor_id = root message) * - - - sub thread * - - - - sub sub message (parent id = sub thread) - * - - sub message (parent_id = root message) + * - - sub message (ancestor_id = root message) * - - - sub thread */ mail.Thread = session.web.Widget.extend({ @@ -930,7 +929,7 @@ openerp.mail = function(session) { this.context = _.extend({ default_model: 'mail.thread', default_res_id: 0, - default_parent_id: false }, options.context || {}); + default_ancestor_id: false }, options.context || {}); this.options = options.options; this.options._parents = (options.options._parents != undefined ? options.options._parents : []).concat( [this] ); @@ -941,7 +940,7 @@ openerp.mail = function(session) { // data of this thread this.id = datasets.id || false, this.model = datasets.model || false, - this.parent_id = datasets.parent_id || false, + this.ancestor_id = datasets.ancestor_id || false, this.is_private = datasets.is_private || false, this.author_id = datasets.author_id || false, this.thread_level = (datasets.thread_level+1) || 0, @@ -1048,8 +1047,8 @@ openerp.mail = function(session) { if(arguments[1]) res.push(this); if(isNaN(nb_thread_level) || nb_thread_level>0){ _(this.messages).each(function (val, key) { - if(val.thread){ - res = res.concat( val.thread.get_childs((isNaN(nb_thread_level) ? null : nb_thread_level-1), true) ) + if(val.thread) { + res = res.concat( val.thread.get_childs((isNaN(nb_thread_level) ? undefined : nb_thread_level-1), true) ); } }); } @@ -1149,7 +1148,7 @@ openerp.mail = function(session) { // 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] + return this.ds_message.call('message_read', [ids, fetch_domain, message_loaded_ids, /*nb_indented_thread,*/ fetch_context, this.context.default_ancestor_id || undefined] ).then(this.proxy('switch_new_message')); }, @@ -1168,16 +1167,16 @@ openerp.mail = function(session) { '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_ancestor_id': self.id }, }); } else { - var message = new mail.ThreadMessage(self, _.extend(data, {'thread_level': self.thread_level}), { + 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': self.options + 'default_ancestor_id': data.id }, + 'options': _.extend(self.options, data.options) }); } @@ -1205,34 +1204,25 @@ openerp.mail = function(session) { insert_message: function (message) { var self=this; - if(this.show_compose_message && - this.options.display_indented_thread >= self.thread_level){ + if(this.show_compose_message /*&& + this.options.display_indented_thread >= self.thread_level*/){ this.ComposeMessage.do_show_compact(); } this.$('.oe_wall_no_message').remove(); - // insert on hierarchy display => insert in self child - var thread_messages = self.messages; - var thread = self; - if( self.options.display_indented_thread < self.thread_level ) { - var thread = self.options._parents[self.options.display_indented_thread] || self.options._parents[0]; - var thread_messages = []; - _(thread.get_childs()).each(function (val, key) { thread_messages.push(val.parent_message); }); - } - // check older and newer message for insertion var parent_newer = false; var parent_older = false; if(message.id > 0){ - for(var i in thread_messages){ - if(thread_messages[i].id > message.id){ - if(!parent_newer || parent_newer.id > thread_messages[i].id) { - parent_newer = thread_messages[i]; + for(var i in self.messages){ + if(self.messages[i].id > message.id){ + if(!parent_newer || parent_newer.id > self.messages[i].id) { + parent_newer = self.messages[i]; } - } else if(thread_messages[i].id > 0 && thread_messages[i].id < message.id) { - if(!parent_older || parent_older.id < thread_messages[i].id) { - parent_older = thread_messages[i]; + } else if(self.messages[i].id > 0 && self.messages[i].id < message.id) { + if(!parent_older || parent_older.id < self.messages[i].id) { + parent_older = self.messages[i]; } } } @@ -1253,11 +1243,11 @@ openerp.mail = function(session) { } else if(message.id < 0) { - message.appendTo(thread.$el); + message.appendTo(self.$el); } else { - message.prependTo(thread.$el); + message.prependTo(self.$el); } } else { if (parent_older) { @@ -1271,11 +1261,11 @@ openerp.mail = function(session) { } else if(message.id < 0) { - message.prependTo(thread.$el); + message.prependTo(self.$el); } else { - message.appendTo(thread.$el); + message.appendTo(self.$el); } } @@ -1285,16 +1275,31 @@ openerp.mail = function(session) { /** *get the parent thread of the messages. - * Each message is send to his parent object for creating the object message. + * Each message is send to his parent object (or parent thread flat mode) for creating the object message. * @param : {Array} datas from calling RPC to "message_read" */ switch_new_message: function(records) { var self=this; _(records).each(function(record){ - self.browse_thread({ - 'id': record.parent_id, + var thread = self.browse_thread({ + 'id': record.ancestor_id, 'default_return_top_thread':true - }).create_message_object( record ); + }); + + /* + record.thread_level = thread.thread_level; + record.options = {'_parents' : thread.options._parents }; + + // check for flat mode + var nb_level = thread.options.display_indented_thread - thread.thread_level; + + if(nb_level <= 0){ + var thread = thread.options._parents[ thread.options._parents.length - 1 + nb_level ]; + } + */ + + + thread.create_message_object( record ); }); }, @@ -1324,7 +1329,7 @@ openerp.mail = function(session) { var msg_up = messages[it-1]; var msg_down = messages[it+1]; - var message_dom = [ '&', ["id","in",[message.id]], ['parent_id', '=', message.parent_id] ]; + var message_dom = [ ["id", "=", message.id] ]; if ( msg_up && msg_up.type == "expandable" && msg_down && msg_down.type == "expandable") { // concat two expandable message and add this message to this dom @@ -1368,7 +1373,7 @@ openerp.mail = function(session) { var expandable = new mail.ThreadExpandable(this, { 'id': message.id, 'model': message.model, - 'parent_id': message.parent_id, + 'ancestor_id': message.ancestor_id, 'nb_messages': 1, 'thread_level': message.thread_level, }, { @@ -1376,7 +1381,7 @@ openerp.mail = function(session) { '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_ancestor_id': this.id }, }); // add object on array and DOM -- cgit v1.2.3 From 8c8c0dd75325ffae7b2fc70a12a69dd12008bee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 23 Oct 2012 13:41:24 +0200 Subject: [IMP] mail: message_read: improved flat / threaded domains (using child_of for thread, or only id for flat); improved ancestor fetching (not using parent_id anymore, because ancestor is the parent message to display the message thread). bzr revid: tde@openerp.com-20121023114124-co3ij97tz1c25qa8 --- addons/mail/static/src/js/mail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 7501eabe104..6d013c1d564 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1047,7 +1047,7 @@ openerp.mail = function(session) { fetch_context = replace_context ? replace_context : this.context; var message_loaded = [this.datasets.id||0].concat( self.options.thread._parents[0].get_child_ids() ); - return this.ds_message.call('message_read', [ids, fetch_domain, message_loaded, fetch_context, this.context.default_parent_id || undefined] + return this.ds_message.call('message_read', [ids, fetch_domain, message_loaded, 1, fetch_context, this.context.default_parent_id || undefined] ).then(this.proxy('switch_new_message')); }, -- cgit v1.2.3 From 4c99b037a6134a47f29eb64c1f501f4316e67f6b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 23 Oct 2012 14:16:47 +0200 Subject: [IMP] mail: ancestor_id bzr revid: chm@openerp.com-20121023121647-erx0p6416ufz6ni5 --- addons/mail/static/src/js/mail.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index d4aafa02733..0b8c39aca81 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1280,25 +1280,12 @@ openerp.mail = function(session) { */ switch_new_message: function(records) { var self=this; + console.log(records); _(records).each(function(record){ var thread = self.browse_thread({ 'id': record.ancestor_id, 'default_return_top_thread':true }); - - /* - record.thread_level = thread.thread_level; - record.options = {'_parents' : thread.options._parents }; - - // check for flat mode - var nb_level = thread.options.display_indented_thread - thread.thread_level; - - if(nb_level <= 0){ - var thread = thread.options._parents[ thread.options._parents.length - 1 + nb_level ]; - } - */ - - thread.create_message_object( record ); }); }, @@ -1376,6 +1363,7 @@ openerp.mail = function(session) { 'ancestor_id': message.ancestor_id, 'nb_messages': 1, 'thread_level': message.thread_level, + 'ancestor_id': message.ancestor_id }, { 'domain': message_dom, 'context': { -- cgit v1.2.3 From 5ca5acef4119b41650efb494b321fc9c2393882d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Tue, 23 Oct 2012 17:58:27 +0200 Subject: [IMP] mail: mail composer design bzr revid: fva@openerp.com-20121023155827-au8m4bzz3hlfie3v --- addons/mail/static/src/js/mail.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 025e5d43b9a..649444deedd 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -198,6 +198,7 @@ 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); @@ -304,9 +305,9 @@ openerp.mail = function(session) { // set the function called when attachments are added this.$render_expandable.on('change', 'input.oe_form_binary_file', self.on_attachment_change ); - this.$render_expandable.on('click', 'a.oe_cancel', self.on_cancel ); - this.$render_expandable.on('click', 'button.oe_post', function(){self.on_message_post()} ); - this.$render_expandable.on('click', 'button.oe_full', function(){self.on_compose_fullmail()} ); + this.$render_expandable.on('click', '.oe_cancel', self.on_cancel ); + this.$render_expandable.on('click', '.oe_post', function(){self.on_message_post()} ); + this.$render_expandable.on('click', '.oe_full', function(){self.on_compose_fullmail()} ); // auto close this.$render_expandable.on('blur', 'textarea', this.on_compose_expandable); @@ -365,6 +366,7 @@ openerp.mail = function(session) { /*post a message and fetch the message*/ on_message_post: function (body) { + console.log('post'); var self = this; if (! body) { -- cgit v1.2.3 From 7a507ea93e5ffddc0f1dc7cc65cbd807042fa112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Wed, 24 Oct 2012 12:05:18 +0200 Subject: [FIX] mail: show compose in form comments bzr revid: fva@openerp.com-20121024100518-ocqiyyo4wxzqaosc --- addons/mail/static/src/js/mail.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index ee80f5f7c89..2890e9eda6e 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1555,7 +1555,8 @@ openerp.mail = function(session) { 'show_reply_button': 0, 'show_read_unread_button': -1, 'show_compose_message': show_compose_message, - 'message_ids': message_ids + 'message_ids': message_ids, + 'show_compact_message': true, } ); @@ -1653,7 +1654,7 @@ openerp.mail = function(session) { 'show_reply_button': 10, 'show_read_unread_button': 11, 'show_compose_message': true, - 'show_compact_message': true + 'show_compact_message': true, } ); -- cgit v1.2.3 From 875b2ede23cdc52ac9a2c96bbd22f527c428e0aa Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 24 Oct 2012 14:28:03 +0200 Subject: [IMP] mail: use widget one2many_binary and value fix bzr revid: chm@openerp.com-20121024122803-ihr421qcvnsd3cjz --- addons/mail/static/src/js/mail.js | 58 ++++++++++++++------------------------- 1 file changed, 21 insertions(+), 37 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 0b8c39aca81..cda2a6fbd70 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -275,26 +275,6 @@ openerp.mail = function(session) { } }, - /* to avoid having unsorted file on the server. - we will show the users files of the first message post - TDE note: unnecessary call to server I think - */ - // set_free_attachments: function(){ - // var self=this; - // this.parent_thread.ds_message.call('user_free_attachment').then(function(attachments){ - // this.attachment_ids=[]; - // for(var i in attachments){ - // self.attachment_ids[i]={ - // 'id': attachments[i].id, - // 'name': attachments[i].name, - // 'filename': attachments[i].filename, - // 'url': mail.ChatterUtils.get_attachment_url(self.session, attachments[i]) - // }; - // } - // self.display_attachments(); - // }); - // }, - bind_events: function() { var self = this; @@ -318,10 +298,6 @@ openerp.mail = function(session) { }, on_compose_fullmail: function(){ - var attachments=[]; - for(var i in this.attachment_ids){ - attachments.push(this.attachment_ids[i].id); - } /* TDE note: I think this is not necessary, because * 1/ post on a document: followers added server-side in _notify * 2/ reply to a message: mail.compose.message should add the previous partners @@ -340,15 +316,20 @@ openerp.mail = function(session) { target: 'new', context: { 'default_model': this.context.default_model, + 'default_res_model': this.context.default_model, 'default_res_id': this.context.default_res_id, 'default_content_subtype': 'html', - 'default_ancestor_id': this.id, + 'default_parent_id': this.id, 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''), - 'default_attachment_ids': attachments, + 'default_attachment_ids': this.attachment_ids, 'default_partner_ids': partner_ids }, }; this.do_action(action); + + if(this.$render_expandable) { + this.on_cancel(); + } }, on_cancel: function(event){ @@ -390,7 +371,7 @@ openerp.mail = function(session) { false, 'comment', 'mail.mt_comment', - this.context.default_ancestor_id, + this.context.default_parent_id, attachments, this.parent_thread.context ]).then(function(records){ @@ -482,7 +463,7 @@ openerp.mail = function(session) { this.context = _.extend({ default_model: 'mail.thread', default_res_id: 0, - default_ancestor_id: false }, options.context || {}); + default_parent_id: false }, options.context || {}); // data of this expandable message this.id = datasets.id || -1, @@ -620,7 +601,7 @@ openerp.mail = function(session) { this.context = _.extend({ default_model: 'mail.thread', default_res_id: 0, - default_ancestor_id: false }, options.context || {}); + default_parent_id: false }, options.context || {}); // record options this.options = options.options; @@ -727,7 +708,7 @@ openerp.mail = function(session) { 'context':{ 'default_model': this.model, 'default_res_id': this.res_id, - 'default_ancestor_id': this.id + 'default_parent_id': this.id }, 'options': this.options } @@ -929,7 +910,7 @@ openerp.mail = function(session) { this.context = _.extend({ default_model: 'mail.thread', default_res_id: 0, - default_ancestor_id: false }, options.context || {}); + default_parent_id: false }, options.context || {}); this.options = options.options; this.options._parents = (options.options._parents != undefined ? options.options._parents : []).concat( [this] ); @@ -1148,7 +1129,7 @@ openerp.mail = function(session) { // 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_ancestor_id || undefined] + 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')); }, @@ -1167,7 +1148,7 @@ openerp.mail = function(session) { 'context': { 'default_model': data.model || self.context.default_model, 'default_res_id': data.res_id || self.context.default_res_id, - 'default_ancestor_id': self.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}), { @@ -1175,7 +1156,7 @@ openerp.mail = function(session) { 'context': { 'default_model': data.model, 'default_res_id': data.res_id, - 'default_ancestor_id': data.id }, + 'default_parent_id': data.id }, 'options': _.extend(self.options, data.options) }); } @@ -1280,7 +1261,6 @@ openerp.mail = function(session) { */ switch_new_message: function(records) { var self=this; - console.log(records); _(records).each(function(record){ var thread = self.browse_thread({ 'id': record.ancestor_id, @@ -1369,7 +1349,7 @@ openerp.mail = function(session) { 'context': { 'default_model': message.model || this.context.default_model, 'default_res_id': message.res_id || this.context.default_res_id, - 'default_ancestor_id': this.id }, + 'default_parent_id': this.id }, }); // add object on array and DOM @@ -1703,7 +1683,11 @@ openerp.mail = function(session) { action_from: 'mail.ThreadComposeMessage', views: [[false, 'form']], target: 'new', - context: this.options.context, + context: _.extend(this.options.context, { + 'default_model': this.context.default_model, + 'default_res_id': this.context.default_res_id, + 'default_content_subtype': 'html', + }), }; session.client.action_manager.do_action(action); }, -- cgit v1.2.3 From fc34572ee3bbdfd52f3c5cda21cbcc61729dd3be Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 24 Oct 2012 15:48:19 +0200 Subject: [IMP] mail: preview image on openchatter bzr revid: chm@openerp.com-20121024134819-5gf165nf6cc21601 --- addons/mail/static/src/js/mail.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'addons/mail/static/src/js') 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. */ -- cgit v1.2.3 From 4ce75bb9bdfe805d479ccc25060d8bcc6b0ace01 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 24 Oct 2012 16:09:10 +0200 Subject: [IMP] mail: preview documents (doc, pdf...) on openchatter bzr revid: chm@openerp.com-20121024140910-88gj3t5efhc7pzzi --- addons/mail/static/src/js/mail.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2fc2861c0d2..35fe012e054 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -636,11 +636,16 @@ openerp.mail = function(session) { } for (var l in this.attachment_ids) { var attach = this.attachment_ids[l]; + attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach); + 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); + 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 = escape(attach.url); + } } }, -- cgit v1.2.3 From 7b6cc50de71d7708881ff67620301b372c8b404d Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 24 Oct 2012 16:41:35 +0200 Subject: [IMP] mail: filter has attachment bzr revid: chm@openerp.com-20121024144135-frzyxty5iiksqtg4 --- addons/mail/static/src/js/mail.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 35fe012e054..a44941ece0b 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -637,14 +637,14 @@ openerp.mail = function(session) { for (var l in this.attachment_ids) { var attach = this.attachment_ids[l]; attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach); - + 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 = escape(attach.url); + attach.url_escape = escape(encodeURI(attach.url)); } } -- cgit v1.2.3 From 4f65723662fe8c80c081ad0e362895601a0a78ef Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 24 Oct 2012 16:43:50 +0200 Subject: [IMP] mail: try to fix encodeURI for document loader bzr revid: chm@openerp.com-20121024144350-yxf9ivj8rlmtx0eu --- addons/mail/static/src/js/mail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index a44941ece0b..db50b96560e 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -644,7 +644,7 @@ openerp.mail = function(session) { } 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 = escape(encodeURI(attach.url)); + attach.url_escape = encodeURIComponent(attach.url); } } -- cgit v1.2.3 From 8d9fdcc3526f1aaaf394f571e5fed8169f459cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Wed, 24 Oct 2012 17:20:43 +0200 Subject: [IMP] mail: followers css + widget integration in inbox and formview bzr revid: fva@openerp.com-20121024152043-q5j7hpa4rur39k03 --- addons/mail/static/src/js/mail.js | 4 ++-- addons/mail/static/src/js/mail_followers.js | 34 ++++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2890e9eda6e..888af67857a 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1560,7 +1560,7 @@ openerp.mail = function(session) { } ); - return this.root.appendTo( this.$('.oe_mail_wall_threads:first') ); + return this.root.replace(this.$('.oe_mail-placeholder')); }, }); @@ -1658,7 +1658,7 @@ openerp.mail = function(session) { } ); - return this.root.appendTo( this.$('.oe_mail_wall_threads:first') ); + return this.root.replace(this.$('.oe_mail-placeholder')); }, bind_events: function(){ diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index f08991be2cc..bf913df0b04 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -24,10 +24,10 @@ openerp_mail_followers = function(session, mail) { init: function() { this._super.apply(this, arguments); - this.options.image = this.node.attrs.image || 'image_small'; - this.options.title = this.node.attrs.title || 'Followers'; - this.options.comment = this.node.attrs.help || false; - this.options.displayed_nb = this.node.attrs.displayed_nb || 10; + this.image = this.node.attrs.image || 'image_small'; + this.title = this.node.attrs.title || 'Followers'; + this.comment = this.node.attrs.help || false; + this.displayed_nb = this.node.attrs.displayed_nb || 10; this.ds_model = new session.web.DataSetSearch(this, this.view.model); this.ds_follow = new session.web.DataSetSearch(this, this.field.relation); this.ds_users = new session.web.DataSetSearch(this, 'res.users'); @@ -61,7 +61,7 @@ openerp_mail_followers = function(session, mail) { self.do_unfollow(); }); // event: click on a subtype, that (un)subscribe for this subtype - this.$el.on('click', 'ul.oe_subtypes input', self.do_update_subscription); + this.$el.on('click', '.oe_subtype_list input', self.do_update_subscription); // event: click on 'invite' button, that opens the invite wizard this.$('.oe_invite').on('click', function (event) { action = { @@ -119,16 +119,16 @@ openerp_mail_followers = function(session, mail) { /* Display generic info about follower, for people not having access to res_partner */ display_generic: function () { var self = this; - var node_user_list = this.$('ul.oe_mail_followers_display').empty(); + var node_user_list = this.$('.oe_follower_list').empty(); // format content: Followers (You and 0 other) // Followers (3) - var content = this.options.title; + var content = this.title; if (this.message_is_follower) { content += ' (You and ' + (this.get('value').length-1) + ' other)'; } else { content += ' (' + this.get('value').length + ')' } - this.$('div.oe_mail_recthread_followers h4').html(content); + this.$('.oe_follower_title').html(content); }, /** Display the followers */ @@ -137,16 +137,16 @@ openerp_mail_followers = function(session, mail) { records = records || []; this.message_is_follower = this.set_is_follower(records); // clean and display title - var node_user_list = this.$('ul.oe_mail_followers_display').empty(); - this.$('div.oe_mail_recthread_followers h4').html(this.options.title + ' (' + records.length + ')'); + var node_user_list = this.$('.oe_follower_list').empty(); + this.$('.oe_follower_title').html(this.title + ' (' + records.length + ')'); // truncate number of displayed followers - truncated = records.splice(0, this.options.displayed_nb); + truncated = records.splice(0, this.displayed_nb); _(truncated).each(function (record) { record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); $(session.web.qweb.render('mail.followers.partner', {'record': record})).appendTo(node_user_list); }); - if (truncated.length < records.length) { - $('
  • And ' + (records.length - truncated.length) + ' more.
  • ').appendTo(node_user_list); + if (truncated.length < records.length) { //FIXME USE A TEMPLATE ! + $('
    And ' + (records.length - truncated.length) + ' more.
    ').appendTo(node_user_list); } }, @@ -172,7 +172,7 @@ openerp_mail_followers = function(session, mail) { /** Fetch subtypes, only if current user is follower */ fetch_subtypes: function () { - var subtype_list_ul = this.$('.oe_subtypes').empty(); + var subtype_list_ul = this.$('.oe_subtype_list').empty(); if (! this.message_is_follower) return; var context = new session.web.CompoundContext(this.build_context(), {}); this.ds_model.call('message_get_subscription_data', [[this.view.datarecord.id], context]).pipe(this.proxy('display_subtypes')); @@ -181,12 +181,12 @@ openerp_mail_followers = function(session, mail) { /** Display subtypes: {'name': default, followed} */ display_subtypes:function (data) { var self = this; - var subtype_list_ul = this.$('.oe_subtypes'); + var subtype_list_ul = this.$('.oe_subtype_list'); var records = data[this.view.datarecord.id || this.view.dataset.ids[0]].message_subtype_data; _(records).each(function (record, record_name) { record.name = record_name; record.followed = record.followed || undefined; - $(session.web.qweb.render('mail.followers.subtype', {'record': record})).appendTo( self.$('ul.oe_subtypes') ); + $(session.web.qweb.render('mail.followers.subtype', {'record': record})).appendTo( self.$('.oe_subtype_list') ); }); }, @@ -209,7 +209,7 @@ openerp_mail_followers = function(session, mail) { var self = this; var checklist = new Array(); - _(this.$('.oe_mail_recthread_actions input[type="checkbox"]')).each(function (record) { + _(this.$('.oe_actions input[type="checkbox"]')).each(function (record) { if ($(record).is(':checked')) { checklist.push(parseInt($(record).data('id'))); } -- cgit v1.2.3 From 4818ad676f37cac9e1a13c36f01de6d0752769b4 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 24 Oct 2012 17:27:11 +0200 Subject: [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(-) (limited to 'addons/mail/static/src/js') 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); + // } } }, -- cgit v1.2.3 From 3e4d6ad44066690bc01caab2ed9a893f54be8fb5 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 25 Oct 2012 10:05:29 +0200 Subject: [IMP] mail: oppenchatter hidden attachment bzr revid: chm@openerp.com-20121025080529-p2dw63h2u2ixyt26 --- addons/mail/static/src/js/mail.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'addons/mail/static/src/js') 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); -- cgit v1.2.3 From f503b4d5ff1262be3866ab7a7c73dca3ac3eed32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 25 Oct 2012 10:20:01 +0200 Subject: [IMP] mail_thread: message_post_api now returns the new message_id, not the result of a message_read. bzr revid: tde@openerp.com-20121025082001-4izbu2hg9rwc7jzb --- addons/mail/static/src/js/mail.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 6d013c1d564..b385e6bc9ec 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -344,9 +344,10 @@ openerp.mail = function(session) { attachments, this.parent_thread.context ]).then(function(records){ - self.parent_thread.switch_new_message(records); - self.datasets.attachment_ids=[]; - self.on_cancel(); + // TDE note: temp deactivation, because this will be fixed in DOM-CHM + // self.parent_thread.switch_new_message(records); + // self.datasets.attachment_ids=[]; + // self.on_cancel(); }); return true; } -- cgit v1.2.3 From a10c6c4dfdab8d7a8a1f722333d4a9c9b654f0c6 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 25 Oct 2012 10:36:31 +0200 Subject: [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/static/src/js/mail.js | 71 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'addons/mail/static/src/js') 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 -- cgit v1.2.3 From 31965cf97a090a8d47a893e4f6c53fb2ea96e410 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 25 Oct 2012 11:59:23 +0200 Subject: [IMP] mail: insert message post, and no quote for reply bzr revid: chm@openerp.com-20121025095923-7urqi5he10q3z1i6 --- addons/mail/static/src/js/mail.js | 381 ++++++++++++++++++++------------------ 1 file changed, 205 insertions(+), 176 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index f30255d209c..5339f92035b 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1,4 +1,4 @@ -openerp.mail = function(session) { +openerp.mail = function (session) { var _t = session.web._t, _lt = session.web._lt; @@ -16,7 +16,9 @@ openerp.mail = function(session) { */ session.web.FormView = session.web.FormView.extend({ - do_action: function(action) { + do_action: function (action) { + console.log(action); + if (action.res_model == 'mail.compose.message') { /* hack for stop context propagation of wrong value * delete this hack when a global method to clean context is create @@ -24,7 +26,7 @@ openerp.mail = function(session) { var context_keys = ['default_template_id', 'default_composition_mode', 'default_use_template', 'default_partner_ids', 'default_model', 'default_res_id', 'default_content_subtype', 'active_id', 'lang', - 'bin_raw', 'tz', 'active_model', 'edi_web_url_view', 'active_ids'] + 'bin_raw', 'tz', 'active_model', 'edi_web_url_view', 'active_ids', 'default_subject'] for (var key in action.context) { if (_.indexOf(context_keys, key) == -1) { action.context[key] = null; @@ -53,7 +55,7 @@ openerp.mail = function(session) { /** *Get an image in /web/binary/image?... */ - get_image: function(session, model, field, id) { + get_image: function (session, model, field, id) { return session.prefix + '/web/binary/image?session_id=' + session.session_id + '&model=' + model + '&field=' + field + '&id=' + (id || ''); }, @@ -85,7 +87,7 @@ openerp.mail = function(session) { * (add

    , ) * TDE note : should not be here, but server-side I think ... */ - get_text2html: function(text){ + get_text2html: function (text) { return text .replace(/[\n\r]/g,'
    ') .replace(/((?:https?|ftp):\/\/[\S]+)/g,'
    $1 ') @@ -106,7 +108,7 @@ openerp.mail = function(session) { nb_and += 1; } - for (var k = 0; k < nb_and ; k++){ + for (var k = 0; k < nb_and ; k++) { domain.unshift('&'); } @@ -168,10 +170,10 @@ openerp.mail = function(session) { this.$render_compact = false; }, - start: function(){ + start: function () { this.$render_compact = this.$el; - if( this.options.show_compact_message ) { + if ( this.options.show_compact_message ) { this.$render_compact.show(); } else { this.$render_compact.hide(); @@ -181,10 +183,10 @@ openerp.mail = function(session) { /* upload the file on the server, add in the attachments list and reload display */ - display_attachments: function(){ + display_attachments: function () { var self = this; var render = $(session.web.qweb.render('mail.thread.message.attachments', {'widget': self})); - if(!this.list_attachment){ + if (!this.list_attachment) { this.$render_expandable.find('.oe_msg_attachment_list').replaceWith( render ); } else { this.list_attachment.replaceWith( render ); @@ -207,9 +209,9 @@ openerp.mail = function(session) { // if the files exits for this answer, delete the file before upload var attachments=[]; - for(var i in this.attachment_ids){ - if((this.attachment_ids[i].filename || this.attachment_ids[i].name) == filename){ - if(this.attachment_ids[i].upload){ + for (var i in this.attachment_ids) { + if ((this.attachment_ids[i].filename || this.attachment_ids[i].name) == filename) { + if (this.attachment_ids[i].upload) { return false; } this.ds_attachment.unlink([this.attachment_ids[i].id]); @@ -238,8 +240,8 @@ openerp.mail = function(session) { /* when the file is uploaded */ on_attachment_loaded: function (event, result) { - for(var i in this.attachment_ids){ - if(this.attachment_ids[i].filename == result.filename && this.attachment_ids[i].upload) { + for (var i in this.attachment_ids) { + if (this.attachment_ids[i].filename == result.filename && this.attachment_ids[i].upload) { this.attachment_ids[i]={ 'id': result.id, 'name': result.name, @@ -262,8 +264,8 @@ openerp.mail = function(session) { var attachment_id=$(event.target).data("id"); if (attachment_id) { var attachments=[]; - for(var i in this.attachment_ids){ - if(attachment_id!=this.attachment_ids[i].id){ + for (var i in this.attachment_ids) { + if (attachment_id!=this.attachment_ids[i].id) { attachments.push(this.attachment_ids[i]); } else { @@ -275,18 +277,18 @@ openerp.mail = function(session) { } }, - bind_events: function() { + bind_events: function () { var self = this; this.$render_compact.find('textarea').unbind().on('focus', self.on_compose_expandable); - if(this.$render_expandable){ + if (this.$render_expandable) { // set the function called when attachments are added this.$render_expandable.on('change', 'input.oe_form_binary_file', self.on_attachment_change ); this.$render_expandable.on('click', '.oe_cancel', self.on_cancel ); - this.$render_expandable.on('click', '.oe_post', function(){self.on_message_post()} ); - this.$render_expandable.on('click', '.oe_full', function(){self.on_compose_fullmail()} ); + this.$render_expandable.on('click', '.oe_post', function () {self.on_message_post()} ); + this.$render_expandable.on('click', '.oe_full', function () {self.on_compose_fullmail('reply')} ); // auto close this.$render_expandable.on('blur', 'textarea', this.on_compose_expandable); @@ -297,15 +299,37 @@ openerp.mail = function(session) { } }, - on_compose_fullmail: function(){ + on_compose_fullmail: function (default_composition_mode) { /* TDE note: I think this is not necessary, because * 1/ post on a document: followers added server-side in _notify * 2/ reply to a message: mail.compose.message should add the previous partners */ - var partner_ids=[]; - for(var i in this.partner_ids){ + var partner_ids = []; + for (var i in this.partner_ids) { partner_ids.push(this.partner_ids[i][0]); } + + if (default_composition_mode == 'reply') { + var context = { + 'default_composition_mode': 'reply', + 'default_parent_id': this.id, + 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''), + 'default_attachment_ids': this.attachment_ids, + 'default_partner_ids': [], //partner_ids + }; + } else { + var context = { + 'default_model': this.context.default_model, + 'default_res_model': this.context.default_model, + 'default_res_id': this.context.default_res_id, + 'default_content_subtype': 'html', + 'default_composition_mode': 'comment', + 'default_parent_id': this.id, + 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''), + 'default_attachment_ids': this.attachment_ids, + 'default_partner_ids': [], //partner_ids + }; + } var action = { type: 'ir.actions.act_window', res_model: 'mail.compose.message', @@ -314,26 +338,18 @@ openerp.mail = function(session) { action_from: 'mail.ThreadComposeMessage', views: [[false, 'form']], target: 'new', - context: { - 'default_model': this.context.default_model, - 'default_res_model': this.context.default_model, - 'default_res_id': this.context.default_res_id, - 'default_content_subtype': 'html', - 'default_parent_id': this.id, - 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''), - 'default_attachment_ids': this.attachment_ids, - 'default_partner_ids': partner_ids - }, + context: context, }; + this.do_action(action); - if(this.$render_expandable) { + if (this.$render_expandable) { this.on_cancel(); } }, - on_cancel: function(event){ - if(event) event.stopPropagation(); + on_cancel: function (event) { + if (event) event.stopPropagation(); this.$render_expandable.find('textarea').val(""); this.$render_expandable.find('input[data-id]').remove(); @@ -355,15 +371,15 @@ openerp.mail = function(session) { } var attachments=[]; - for(var i in this.attachment_ids){ - if(this.attachment_ids[i].upload){ + for (var i in this.attachment_ids) { + if (this.attachment_ids[i].upload) { session.web.dialog($('

    ' + session.web.qweb.render('CrashManager.warning', {message: 'Please, wait while the file is uploading.'}) + '
    ')); return false; } attachments.push(this.attachment_ids[i].id); } - if(body.match(/\S+/)) { + if (body.match(/\S+/)) { //session.web.blockUI(); this.parent_thread.ds_thread.call('message_post_api', [ this.context.default_res_id, @@ -374,8 +390,13 @@ openerp.mail = function(session) { this.context.default_parent_id, attachments, this.parent_thread.context - ]).then(function(message_id) { - self.parent_thread.message_fetch([['id', '=', message_id]]); + ]).then(function (record) { + var thread = self.parent_thread; + // create object and attach to the thread object + var message = thread.create_message_object( record[0] ); + // insert the message on dom + thread.insert_message( message, self.thread_level > self.options.display_indented_thread ? self.parent_thread.$el : self.$el ); + // clean compose message self.on_cancel(); //session.web.unblockUI(); }); @@ -385,8 +406,8 @@ openerp.mail = function(session) { /* create the compose on expandable form */ - instantiate_expandable: function() { - if(!this.$render_expandable) { + instantiate_expandable: function () { + if (!this.$render_expandable) { this.$render_expandable = $(session.web.qweb.render('mail.compose_message', {'widget': this})); this.$render_expandable.hide(); @@ -399,25 +420,25 @@ openerp.mail = function(session) { /* convert the compact mode into the compose message */ - on_compose_expandable: function(event){ - if(event) event.stopPropagation(); + on_compose_expandable: function (event) { + if (event) event.stopPropagation(); var self = this; this.instantiate_expandable(); - if(this.$render_expandable.is(':hidden')){ + if (this.$render_expandable.is(':hidden')) { this.$render_expandable.css('display', ''); this.$render_compact.hide(); this.$render_expandable.find('textarea').focus(); - } else if(!this.stay_open){ + } else if (!this.stay_open) { // do not close the box if there are some text - if(!this.$render_expandable.find('textarea').val().match(/\S+/)){ + if (!this.$render_expandable.find('textarea').val().match(/\S+/)) { this.$render_expandable.hide(); - if(this.options.show_compact_message && this.show_compact_message) { + if (this.options.show_compact_message && this.show_compact_message) { this.$render_compact.css('display', ''); } else { this.$render_compact.hide(); @@ -428,13 +449,13 @@ openerp.mail = function(session) { return true; }, - do_hide_compact: function() { + do_hide_compact: function () { this.$render_compact.hide(); this.show_compact_message = false; }, - do_show_compact: function() { - if(this.options.show_compact_message && (!this.$render_expandable || this.$render_expandable.is(':hidden'))) { + do_show_compact: function () { + if (this.options.show_compact_message && (!this.$render_expandable || this.$render_expandable.is(':hidden'))) { this.$render_compact.css('display', ''); } this.show_compact_message = true; @@ -457,7 +478,7 @@ openerp.mail = function(session) { mail.ThreadExpandable = session.web.Widget.extend({ template: 'mail.thread.expandable', - init: function(parent, datasets, context) { + init: function (parent, datasets, context) { this._super(parent); this.domain = datasets.domain || []; this.options = datasets.options; @@ -479,7 +500,7 @@ openerp.mail = function(session) { }, - start: function() { + start: function () { this._super.apply(this, arguments); this.bind_events(); }, @@ -494,15 +515,15 @@ openerp.mail = function(session) { /** * Bind events in the widget. Each event is slightly described * in the function. */ - bind_events: function() { + bind_events: function () { this.$el.on('click', 'a.oe_msg_fetch_more', this.on_expandable); }, - animated_destroy: function(options) { + animated_destroy: function (options) { var self=this; //graphic effects - if(options && options.fadeTime) { - self.$el.fadeOut(options.fadeTime, function(){ + if (options && options.fadeTime) { + self.$el.fadeOut(options.fadeTime, function () { self.destroy(); }); } else { @@ -514,8 +535,8 @@ openerp.mail = function(session) { * @param {object} mouse envent */ on_expandable: function (event) { - if(event)event.stopPropagation(); - if(this.flag_used) { + if (event)event.stopPropagation(); + if (this.flag_used) { return false } this.flag_used = true; @@ -528,7 +549,7 @@ openerp.mail = function(session) { /** * call on_message_delete on his parent thread */ - destroy: function() { + destroy: function () { this._super(); this.parent_thread.on_message_detroy(this); @@ -573,7 +594,7 @@ 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, context) { + init: function (parent, datasets, context) { this._super(parent); // record domain and context @@ -585,7 +606,7 @@ openerp.mail = function(session) { // record options this.options = datasets.options; - + // data of this message this.id = datasets.id || -1, this.model = datasets.model || false, @@ -615,7 +636,7 @@ openerp.mail = function(session) { this.parent_thread= parent.messages!= undefined ? parent : this.options._parents[0]; this.thread = false; - if( this.id > 0 ) { + if ( this.id > 0 ) { this.formating_data(); } @@ -627,7 +648,7 @@ openerp.mail = function(session) { /** *Convert date, timerelative and avatar in displayable data. */ - formating_data: function(){ + formating_data: function () { //formating and add some fields for render this.date = session.web.format_value(this._date, {type:"datetime"}); @@ -641,28 +662,28 @@ openerp.mail = function(session) { var attach = this.attachment_ids[l]; attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach); - if((attach.filename || attach.name).match(/[.](jpg|jpg|gif|png|tif|svg)$/i)) { + if ((attach.filename || attach.name).match(/[.](jpg|jpg|gif|png|tif|svg)$/i)) { attach.is_image = true; attach['url'] = mail.ChatterUtils.get_image(this.session, 'ir.attachment', 'datas', attach.id); } } }, - start: function() { + start: function () { this._super.apply(this, arguments); this.expender(); - this.$el.hide().fadeIn(750, function() {$(this).css('display', '');}); + 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() { - var resize = function() { + resize_img: function () { + var resize = function () { var h = $(this).height(); var w = $(this).width(); - if( h > 100 || w >100 ) { + if ( h > 100 || w >100 ) { var ratio = 100 / (h > w ? h : w); $(this).attr("width", parseInt( w*ratio )).attr("height", parseInt( h*ratio )); } @@ -673,13 +694,13 @@ openerp.mail = function(session) { /** * Bind events in the widget. Each event is slightly described * in the function. */ - bind_events: function() { + bind_events: function () { var self = this; // event: click on 'Attachment(s)' in msg 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") ) { + if ( self.$('.oe_msg_attachments:first').hasClass("oe_hidden") ) { attach.removeClass("oe_hidden"); } else { attach.addClass("oe_hidden"); @@ -704,13 +725,13 @@ openerp.mail = function(session) { /** * call the on_compose_message on the thread of this message. */ - on_message_reply:function(event){ + on_message_reply:function (event) { event.stopPropagation(); this.thread.on_compose_message(); return false; }, - expender: function(){ + expender: function () { this.$('.oe_msg_body:first').expander({ slicePoint: this.options.truncate_limit, expandText: 'read more', @@ -725,8 +746,8 @@ openerp.mail = function(session) { * instantiate the thread object of this message. * Each message have only one thread. */ - create_thread: function(){ - if(this.thread){ + create_thread: function () { + if (this.thread) { return false; } /*create thread*/ @@ -748,11 +769,11 @@ openerp.mail = function(session) { * Fade out the message and his child thread. * Then this object is destroyed. */ - animated_destroy: function(options) { + animated_destroy: function (options) { var self=this; //graphic effects - if(options && options.fadeTime) { - self.$el.fadeOut(options.fadeTime, function(){ + if (options && options.fadeTime) { + self.$el.fadeOut(options.fadeTime, function () { self.parent_thread.message_to_expandable(self); }); self.thread.$el.fadeOut(options.fadeTime); @@ -783,13 +804,13 @@ openerp.mail = function(session) { event.stopPropagation(); var self=this; - if( (this.to_read && this.options.typeof_thread == 'inbox') || + if ( (this.to_read && this.options.typeof_thread == 'inbox') || (!this.to_read && this.options.typeof_thread == 'archives')) { this.animated_destroy({fadeTime:250}); } // 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(){ + 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; }); @@ -805,23 +826,23 @@ openerp.mail = function(session) { * private for check the top thread * @return thread object */ - browse_message: function(options){ + browse_message: function (options) { // goto the wall thread for launch browse - if(!options._go_thread_wall) { + if (!options._go_thread_wall) { options._go_thread_wall = true; - for(var i in this.options._parents[0].messages){ + for (var i in this.options._parents[0].messages) { var res=this.options._parents[0].messages[i].browse_message(options); - if(res) return res; + if (res) return res; } } - if(this.id==options.id) + if (this.id==options.id) return this; - for(var i in this.thread.messages){ - if(this.thread.messages[i].thread){ + for (var i in this.thread.messages) { + if (this.thread.messages[i].thread) { var res=this.thread.messages[i].browse_message(options); - if(res) return res; + if (res) return res; } } @@ -831,10 +852,10 @@ openerp.mail = function(session) { /* get all child message id linked. * @return array of id */ - get_child_ids: function(){ + get_child_ids: function () { var res=[] - if(arguments[0]) res.push(this.id); - if(this.thread){ + if (arguments[0]) res.push(this.id); + if (this.thread) { res = res.concat( this.thread.get_child_ids(true) ); } return res; @@ -846,7 +867,7 @@ 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){ + 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(); @@ -871,13 +892,13 @@ openerp.mail = function(session) { event.stopPropagation(); var self=this; var button = self.$('.oe_star:first'); - return this.ds_message.call('favorite_toggle', [[self.id]]).pipe(function(star){ + return this.ds_message.call('favorite_toggle', [[self.id]]).pipe(function (star) { self.is_favorite=star; - if(self.is_favorite){ + if (self.is_favorite) { button.addClass('oe_starred'); } else { button.removeClass('oe_starred'); - if( self.options.typeof_thread == 'stared' ) { + if ( self.options.typeof_thread == 'stared' ) { self.animated_destroy({fadeTime:250}); } } @@ -888,7 +909,7 @@ openerp.mail = function(session) { /** * call on_message_delete on his parent thread */ - destroy: function() { + destroy: function () { this._super(); this.parent_thread.on_message_detroy(this); @@ -931,7 +952,7 @@ openerp.mail = function(session) { * @param {Array} [parents] liked with the parents thread * use with browse, fetch... [O]= top parent */ - init: function(parent, datasets, options) { + init: function (parent, datasets, options) { this._super(parent); this.domain = options.domain || []; this.context = _.extend({ @@ -952,7 +973,7 @@ openerp.mail = function(session) { this.is_private = datasets.is_private || false, this.author_id = datasets.author_id || false, this.thread_level = (datasets.thread_level+1) || 0, - this.partner_ids = _.filter(datasets.partner_ids, function(partner){ return partner[0]!=datasets.author_id[0]; } ) + this.partner_ids = _.filter(datasets.partner_ids, function (partner) { return partner[0]!=datasets.author_id[0]; } ) this.messages = []; this.show_compose_message = this.options.show_compose_message && (this.options.show_reply_button > this.thread_level || !this.thread_level); @@ -963,9 +984,9 @@ openerp.mail = function(session) { this.ds_message = new session.web.DataSetSearch(this, 'mail.message'); }, - start: function() { + start: function () { this._super.apply(this, arguments); - if(this.show_compose_message){ + if (this.show_compose_message) { this.instantiate_ComposeMessage(); } this.bind_events(); @@ -974,14 +995,14 @@ openerp.mail = function(session) { /* instantiate the compose message object and insert this on the DOM. * The compose message is display in compact form. */ - instantiate_ComposeMessage: function(){ + instantiate_ComposeMessage: function () { // add message composition form view this.ComposeMessage = new mail.ThreadComposeMessage(this, this, { 'context': this.context, 'options': this.options, }); - if(this.thread_level){ + if (this.thread_level) { this.ComposeMessage.appendTo(this.$el); } else { // root view @@ -993,17 +1014,17 @@ openerp.mail = function(session) { /* When the expandable object is visible on screen (with scrolling) * then the on_expandable function is launch */ - on_scroll: function(event){ - if(event)event.stopPropagation(); + 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) { + if (message && message.type=="expandable" && message.max_limit) { var pos = message.$el.position(); - if(pos.top){ + if (pos.top) { /* bottom of the screen */ var bottom = $(window).scrollTop()+$(window).height()+200; - if(bottom > pos.top){ + if (bottom > pos.top) { message.on_expandable(); } } @@ -1013,7 +1034,7 @@ openerp.mail = function(session) { /** * Bind events in the widget. Each event is slightly described * in the function. */ - bind_events: function() { + bind_events: function () { var self = this; self.$el.on('click', '.oe_mail_list_recipients .oe_more', self.on_show_recipients); self.$el.on('click', '.oe_mail_compose_textarea .oe_more_hidden', self.on_hide_recipients); @@ -1022,7 +1043,7 @@ openerp.mail = function(session) { /** *show all the partner list of this parent message */ - on_show_recipients: function(){ + on_show_recipients: function () { var p=$(this).parent(); p.find('.oe_more_hidden, .oe_hidden').show(); p.find('.oe_more').hide(); @@ -1031,7 +1052,7 @@ openerp.mail = function(session) { /** *hide a part of the partner list of this parent message */ - on_hide_recipients: function(){ + on_hide_recipients: function () { var p=$(this).parent(); p.find('.oe_more_hidden, .oe_hidden').hide(); p.find('.oe_more').show(); @@ -1040,7 +1061,7 @@ openerp.mail = function(session) { /* get all child message/thread id linked. * @return array of id */ - get_child_ids: function(){ + get_child_ids: function () { var res=[]; _(this.get_childs()).each(function (val, key) { res.push(val.id); }); return res; @@ -1050,12 +1071,12 @@ openerp.mail = function(session) { * @param {int} nb_thread_level, number of traversed thread level for this search * @return array of thread object */ - get_childs: function(nb_thread_level){ + get_childs: function (nb_thread_level) { var res=[]; - if(arguments[1]) res.push(this); - if(isNaN(nb_thread_level) || nb_thread_level>0){ + if (arguments[1]) res.push(this); + if (isNaN(nb_thread_level) || nb_thread_level>0) { _(this.messages).each(function (val, key) { - if(val.thread) { + if (val.thread) { res = res.concat( val.thread.get_childs((isNaN(nb_thread_level) ? undefined : nb_thread_level-1), true) ); } }); @@ -1074,28 +1095,28 @@ openerp.mail = function(session) { * return the top thread (wall) if no thread found * @return thread object */ - browse_thread: function(options){ + browse_thread: function (options) { // goto the wall thread for launch browse - if(!options._go_thread_wall) { + if (!options._go_thread_wall) { options._go_thread_wall = true; return this.options._parents[0].browse_thread(options); } - if(this.id==options.id){ + if (this.id==options.id) { return this; } - if(options.id){ - for(var i in this.messages){ - if(this.messages[i].thread){ + if (options.id) { + for (var i in this.messages) { + if (this.messages[i].thread) { var res=this.messages[i].thread.browse_thread({'id':options.id, '_go_thread_wall':true}); - if(res) return res; + if (res) return res; } } } //if option default_return_top_thread, return the top if no found thread - if(options.default_return_top_thread){ + if (options.default_return_top_thread) { return this; } @@ -1111,8 +1132,8 @@ openerp.mail = function(session) { * private for check the top thread * @return message object */ - browse_message: function(options){ - if(this.options._parents[0].messages[0]) + browse_message: function (options) { + if (this.options._parents[0].messages[0]) return this.options._parents[0].messages[0].browse_message(options); }, @@ -1121,8 +1142,8 @@ openerp.mail = function(session) { * Call the on_compose_expandable method to allow the user to write his message. * (Is call when a user click on "Reply" button) */ - on_compose_message: function(){ - if(!this.ComposeMessage){ + on_compose_message: function () { + if (!this.ComposeMessage) { this.instantiate_ComposeMessage(); this.ComposeMessage.do_hide_compact(); } @@ -1133,7 +1154,7 @@ openerp.mail = function(session) { /** *display the message "there are no message" on the thread */ - no_message: function(){ + no_message: function () { $(session.web.qweb.render('mail.wall_no_message', {})).appendTo(this.$el); }, @@ -1172,7 +1193,7 @@ openerp.mail = function(session) { 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'){ + if (data.type=='expandable') { var message = new mail.ThreadExpandable(self, data, { 'default_model': data.model || self.context.default_model, 'default_res_id': data.res_id || self.context.default_res_id, @@ -1186,16 +1207,15 @@ openerp.mail = function(session) { }); } - // insert the message on dom - self.insert_message( message ); - // check if the message is already create - for(var i in self.messages){ - if(self.messages[i] && self.messages[i].id == message.id){ + for (var i in self.messages) { + if (self.messages[i] && self.messages[i].id == message.id) { self.messages[i].destroy(); } } self.messages.push( message ); + + return message; }, /** @@ -1207,27 +1227,32 @@ openerp.mail = function(session) { * The sort is define by the thread_level (O for newer on top). * @param : {object} ThreadMessage object */ - insert_message: function (message) { + insert_message: function (message, dom_insert_after) { var self=this; - if(this.show_compose_message /*&& - this.options.display_indented_thread >= self.thread_level*/){ + if (this.show_compose_message) { this.ComposeMessage.do_show_compact(); } this.$('.oe_wall_no_message').remove(); + + if (dom_insert_after) { + message.insertAfter(dom_insert_after); + return message + } + // check older and newer message for insertion var parent_newer = false; var parent_older = false; - if(message.id > 0){ - for(var i in self.messages){ - if(self.messages[i].id > message.id){ - if(!parent_newer || parent_newer.id > self.messages[i].id) { + if (message.id > 0) { + for (var i in self.messages) { + if (self.messages[i].id > message.id) { + if (!parent_newer || parent_newer.id > self.messages[i].id) { parent_newer = self.messages[i]; } - } else if(self.messages[i].id > 0 && self.messages[i].id < message.id) { - if(!parent_older || parent_older.id < self.messages[i].id) { + } else if (self.messages[i].id > 0 && self.messages[i].id < message.id) { + if (!parent_older || parent_older.id < self.messages[i].id) { parent_older = self.messages[i]; } } @@ -1243,11 +1268,11 @@ openerp.mail = function(session) { //warning : insert after the thread of the message ! message.insertAfter(parent_older.thread ? parent_older.thread.$el : parent_older.$el); - } else if(parent_newer) { + } else if (parent_newer) { message.insertBefore(parent_newer.$el); - } else if(message.id < 0) { + } else if (message.id < 0) { message.appendTo(self.$el); @@ -1260,12 +1285,12 @@ openerp.mail = function(session) { message.insertBefore(parent_older.$el); - } else if(parent_newer) { + } else if (parent_newer) { //warning : insert after the thread of the message ! message.insertAfter(parent_newer.thread ? parent_newer.thread.$el : parent_newer.$el); - } else if(message.id < 0) { + } else if (message.id < 0) { message.prependTo(self.$el); @@ -1284,14 +1309,17 @@ openerp.mail = function(session) { * Each message is send to his parent object (or parent thread flat mode) for creating the object message. * @param : {Array} datas from calling RPC to "message_read" */ - switch_new_message: function(records) { + switch_new_message: function (records) { var self=this; - _(records).each(function(record){ + _(records).each(function (record) { var thread = self.browse_thread({ 'id': record.ancestor_id, 'default_return_top_thread':true }); - thread.create_message_object( record ); + // create object and attach to the thread object + var message = thread.create_message_object( record ); + // insert the message on dom + thread.insert_message( message ); }); }, @@ -1310,7 +1338,7 @@ openerp.mail = function(session) { */ message_to_expandable: function (message) { - if(!this.thread_level || message.isDestroyed()) { + if (!this.thread_level || message.isDestroyed()) { message.destroy(); return false; } @@ -1330,7 +1358,7 @@ openerp.mail = function(session) { msg_down.domain = ['|','|'].concat( msg_up.domain ).concat( message_dom ).concat( msg_down.domain ); - if( !msg_down.max_limit ){ + if ( !msg_down.max_limit ) { msg_down.nb_messages += 1 + msg_up.nb_messages; } @@ -1354,7 +1382,7 @@ openerp.mail = function(session) { msg_down.domain = ['|'].concat( msg_down.domain ).concat( message_dom ); // it's maybe a message expandable for the max limit read message - if( !msg_down.max_limit ){ + if ( !msg_down.max_limit ) { msg_down.nb_messages++; } @@ -1370,6 +1398,7 @@ openerp.mail = function(session) { 'thread_level': message.thread_level, 'ancestor_id': message.ancestor_id, 'domain': message_dom, + 'options': message.options, }, { 'default_model': message.model || this.context.default_model, 'default_res_id': message.res_id || this.context.default_res_id, @@ -1442,13 +1471,13 @@ openerp.mail = function(session) { 'message_ids': [] }, options); - if(this.display_indented_thread === false) { + if (this.display_indented_thread === false) { this.display_indented_thread = -1; } - if(this.show_reply_button === false) { + if (this.show_reply_button === false) { this.show_reply_button = -1; } - if(this.show_read_unread_button === false) { + if (this.show_read_unread_button === false) { this.show_read_unread_button = -1; } @@ -1478,8 +1507,8 @@ openerp.mail = function(session) { this.thread.no_message(); this.thread.message_fetch(null, null, this.options.message_ids); - if(this.options.show_compose_message) { - if(this.options.show_compact_message) { + 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(); @@ -1487,8 +1516,8 @@ openerp.mail = function(session) { } }, - bind_events: function(){ - if(this.context['typeof_thread']!='other'){ + 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 ); @@ -1510,23 +1539,23 @@ openerp.mail = function(session) { mail.RecordThread = session.web.form.AbstractField.extend({ template: 'mail.record_thread', - init: function() { + init: function () { this._super.apply(this, arguments); this.options.domain = this.options.domain || []; this.options.context = {'default_model': 'mail.thread', 'default_res_id': false}; }, - start: function() { + start: function () { this._super.apply(this, arguments); // NB: check the actual_mode property on view to know if the view is in create mode anymore this.view.on("change:actual_mode", this, this._check_visibility); this._check_visibility(); }, - _check_visibility: function() { + _check_visibility: function () { this.$el.toggle(this.view.get("actual_mode") !== "create"); }, - render_value: function() { + render_value: function () { var self = this; if (! this.view.datarecord.id || session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) { this.$('oe_mail_thread').hide(); @@ -1545,7 +1574,7 @@ openerp.mail = function(session) { var message_ids = this.getParent().fields.message_ids && this.getParent().fields.message_ids.get_value(); - if(this.root){ + if (this.root) { this.root.destroy(); } // create and render Thread widget @@ -1625,7 +1654,7 @@ openerp.mail = function(session) { * @param {Array} contexts * @param {Array} groupbys */ - do_searchview_search: function(domains, contexts, groupbys) { + do_searchview_search: function (domains, contexts, groupbys) { var self = this; this.rpc('/web/session/eval_domain_and_context', { domains: domains || [], @@ -1654,17 +1683,17 @@ openerp.mail = function(session) { 'show_reply_button': 10, 'show_read_unread_button': 11, 'show_compose_message': true, - 'show_compact_message': true, + 'show_compact_message': false, } ); return this.root.appendTo( this.$('.oe_mail_wall_threads:first') ); }, - bind_events: function(){ + bind_events: function () { var self=this; - this.$("button.oe_write_full:first").click(function(){ self.root.thread.ComposeMessage.on_compose_fullmail(); }); - this.$("button.oe_write_onwall:first").click(function(){ self.root.thread.on_compose_message(); }); + this.$("button.oe_write_full:first").click(function () { self.root.thread.ComposeMessage.on_compose_fullmail(); }); + this.$("button.oe_write_onwall:first").click(function () { self.root.thread.on_compose_message(); }); } }); @@ -1690,13 +1719,13 @@ openerp.mail = function(session) { }; }, - start: function(parent, params) { + start: function (parent, params) { var self = this; this.$el.on('click', 'button', self.on_compose_message ); this._super(parent, params); }, - on_compose_message: function(event){ + on_compose_message: function (event) { event.stopPropagation(); var action = { type: 'ir.actions.act_window', @@ -1718,7 +1747,7 @@ openerp.mail = function(session) { }); session.web.UserMenu = session.web.UserMenu.extend({ - start: function(parent, params) { + start: function (parent, params) { var render = new session.web.ComposeMessageTopButton(); render.insertAfter(this.$el); this._super(parent, params); -- cgit v1.2.3 From 6966509c6eaec94965370f75780e0005a23bb1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 25 Oct 2012 13:30:48 +0200 Subject: [IMP] mail_message: partner_ids now holds only specific destination partners. Partners + followers is now stored into notified_partner_ids. Added a from field on mail_message, holding the email address of the sender, in case of an incoming email message that cannot be linked to a partner. bzr revid: tde@openerp.com-20121025113048-5f1ob8ligqzb52gu --- addons/mail/static/src/js/mail.js | 1 - 1 file changed, 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index b385e6bc9ec..0de1699ed5d 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -339,7 +339,6 @@ openerp.mail = function(session) { mail.ChatterUtils.get_text2html(body), false, 'comment', - 'mail.mt_comment', this.context.default_parent_id, attachments, this.parent_thread.context -- cgit v1.2.3 From 0805371fa9e1f17816a638b6878f7d6629d926ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Thu, 25 Oct 2012 14:43:20 +0200 Subject: [IMP] mail: compose textarea auto-resizes, various small fixes bzr revid: fva@openerp.com-20121025124320-ztzcdf4bkgjjs57h --- addons/mail/static/src/js/mail.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 1adcbc4ad4c..1779d1a6562 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -293,6 +293,7 @@ openerp.mail = function(session) { /* stack for don't close the compose form if the user click on a button */ this.$render_expandable.on('focus, mouseup', 'textarea', function () { self.stay_open = false; }); this.$render_expandable.on('mousedown', function () { self.stay_open = true; }); + this.$render_expandable.find('textarea').autosize(); } }, @@ -1662,8 +1663,8 @@ openerp.mail = function(session) { bind_events: function(){ var self=this; - this.$("button.oe_write_full:first").click(function(){ self.root.thread.ComposeMessage.on_compose_fullmail(); }); - this.$("button.oe_write_onwall:first").click(function(){ self.root.thread.on_compose_message(); }); + this.$(".oe_write_full").click(function(){ self.root.thread.ComposeMessage.on_compose_fullmail(); }); + this.$(".oe_write_onwall").click(function(){ self.root.thread.on_compose_message(); }); } }); -- cgit v1.2.3 From 7cdf99ade180b00af9caa6094d624007d47a3dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 26 Oct 2012 11:58:21 +0200 Subject: [IMP] mail: improved display of openchatter in form views bzr revid: fva@openerp.com-20121026095821-c3idarsd5yi9fzso --- addons/mail/static/src/js/mail_followers.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index bf913df0b04..7fed5371600 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -25,7 +25,6 @@ openerp_mail_followers = function(session, mail) { init: function() { this._super.apply(this, arguments); this.image = this.node.attrs.image || 'image_small'; - this.title = this.node.attrs.title || 'Followers'; this.comment = this.node.attrs.help || false; this.displayed_nb = this.node.attrs.displayed_nb || 10; this.ds_model = new session.web.DataSetSearch(this, this.view.model); @@ -115,20 +114,25 @@ openerp_mail_followers = function(session, mail) { self.message_is_follower = (_.indexOf(self.get('value'), pid) != -1); }).pipe(self.proxy('display_generic')); }, - + _format_followers: function(count){ + console.log('FORMAT FOLLWERS :',count); + function _t(str){return str;} + var str = ''; + if(count <= 0){ + str = _t('No followers'); + }else if(count === 1){ + str = _t('One follower'); + }else{ + str = ''+count+' '+_t('followers'); + } + console.log('URGH:',str); + return str; + }, /* Display generic info about follower, for people not having access to res_partner */ display_generic: function () { var self = this; var node_user_list = this.$('.oe_follower_list').empty(); - // format content: Followers (You and 0 other) // Followers (3) - var content = this.title; - if (this.message_is_follower) { - content += ' (You and ' + (this.get('value').length-1) + ' other)'; - } - else { - content += ' (' + this.get('value').length + ')' - } - this.$('.oe_follower_title').html(content); + this.$('.oe_follower_title').html(this._format_followers(this.get('value').length)); }, /** Display the followers */ @@ -138,7 +142,7 @@ openerp_mail_followers = function(session, mail) { this.message_is_follower = this.set_is_follower(records); // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); - this.$('.oe_follower_title').html(this.title + ' (' + records.length + ')'); + this.$('.oe_follower_title').html(this._format_followers(records.length)); // truncate number of displayed followers truncated = records.splice(0, this.displayed_nb); _(truncated).each(function (record) { -- cgit v1.2.3 From 0975d105e20f7572b4e7eadbb64719c3d4817d98 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 26 Oct 2012 12:58:35 +0200 Subject: [IMP] mail: one template for compose_message: compact & expend + replace by message bzr revid: chm@openerp.com-20121026105835-i3gca74hku1z6y2x --- addons/mail/static/src/js/mail.js | 258 +++++++++++++++++--------------------- 1 file changed, 116 insertions(+), 142 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 78aa3e8513d..f98e82481fa 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -130,8 +130,7 @@ openerp.mail = function (session) { */ mail.ThreadComposeMessage = session.web.Widget.extend({ - template: 'mail.compose_message.compact', - // expandable view : 'mail.compose_message' + template: 'mail.compose_message', /** * @param {Object} parent parent @@ -147,7 +146,7 @@ openerp.mail = function (session) { this.context = options.context || {}; this.options = options.options; - this.show_compact_message = this.options.show_compact_message || false; + this.show_compact_message = false; // data of this compose message this.attachment_ids = []; @@ -165,19 +164,10 @@ openerp.mail = function (session) { this.fileupload_id = _.uniqueId('oe_fileupload_temp'); $(window).on(self.fileupload_id, self.on_attachment_loaded); - - this.$render_expandable = false; - this.$render_compact = false; }, start: function () { - this.$render_compact = this.$el; - - if ( this.options.show_compact_message ) { - this.$render_compact.show(); - } else { - this.$render_compact.hide(); - } + this.display_attachments(); this.bind_events(); }, @@ -187,14 +177,14 @@ openerp.mail = function (session) { var self = this; var render = $(session.web.qweb.render('mail.thread.message.attachments', {'widget': self})); if (!this.list_attachment) { - this.$render_expandable.find('.oe_msg_attachment_list').replaceWith( render ); + this.$('.oe_msg_attachment_list').replaceWith( render ); } else { this.list_attachment.replaceWith( render ); } - this.list_attachment = this.$render_expandable.find(".oe_msg_attachments"); + this.list_attachment = this.$(".oe_msg_attachments"); // event: delete an attachment - this.$render_expandable.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete); + this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete); }, /* when a user click on the upload button, send file read on_attachment_loaded @@ -222,9 +212,9 @@ openerp.mail = function (session) { this.attachment_ids = attachments; // submit file - this.$render_expandable.find('form.oe_form_binary_form').submit(); + this.$('form.oe_form_binary_form').submit(); - this.$render_expandable.find(".oe_attachment_file").hide(); + this.$(".oe_attachment_file").hide(); this.attachment_ids.push({ 'id': 0, @@ -252,9 +242,9 @@ openerp.mail = function (session) { } this.display_attachments(); - var $input = this.$render_expandable.find('input.oe_form_binary_file'); + var $input = this.$('input.oe_form_binary_file'); $input.after($input.clone(true)).remove(); - this.$render_expandable.find(".oe_attachment_file").show(); + this.$(".oe_attachment_file").show(); }, /* unlink the file on the server and reload display @@ -280,24 +270,22 @@ openerp.mail = function (session) { bind_events: function () { var self = this; - this.$render_compact.find('textarea').unbind().on('focus', self.on_compose_expandable); + this.$('textarea.oe_compact').on('focus', self.on_compose_expandable); - if (this.$render_expandable) { - // set the function called when attachments are added - this.$render_expandable.on('change', 'input.oe_form_binary_file', self.on_attachment_change ); + // set the function called when attachments are added + this.$el.on('change', 'input.oe_form_binary_file', self.on_attachment_change ); - this.$render_expandable.on('click', '.oe_cancel', self.on_cancel ); - this.$render_expandable.on('click', '.oe_post', function () {self.on_message_post()} ); - this.$render_expandable.on('click', '.oe_full', function () {self.on_compose_fullmail('reply')} ); + this.$el.on('click', '.oe_cancel', self.on_cancel ); + this.$el.on('click', '.oe_post', function () {self.on_message_post()} ); + this.$el.on('click', '.oe_full', function () {self.on_compose_fullmail('reply')} ); - // auto close - 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.$el.on('mousedown', 'div', function () { self.stay_open = true; }); + this.$('textarea:not(.oe_compact):first').on('focus, mouseup, keydown', function () { self.stay_open = false; }); + this.$('textarea:not(.oe_compact):first').autosize(); - /* stack for don't close the compose form if the user click on a button */ - this.$render_expandable.on('focus, mouseup', 'textarea', function () { self.stay_open = false; }); - this.$render_expandable.on('mousedown', function () { self.stay_open = true; }); - this.$render_expandable.find('textarea').autosize(); - } + // auto close + this.$el.on('blur', 'textarea:not(.oe_compact):first', self.on_compose_expandable); }, on_compose_fullmail: function (default_composition_mode) { @@ -314,7 +302,7 @@ openerp.mail = function (session) { var context = { 'default_composition_mode': 'reply', 'default_parent_id': this.id, - 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''), + 'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''), 'default_attachment_ids': this.attachment_ids, 'default_partner_ids': [], //partner_ids }; @@ -326,7 +314,7 @@ openerp.mail = function (session) { 'default_content_subtype': 'html', 'default_composition_mode': 'comment', 'default_parent_id': this.id, - 'default_body': mail.ChatterUtils.get_text2html(this.$render_expandable ? (this.$render_expandable.find('textarea').val() || '') : ''), + 'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''), 'default_attachment_ids': this.attachment_ids, 'default_partner_ids': [], //partner_ids }; @@ -343,22 +331,26 @@ openerp.mail = function (session) { }; this.do_action(action); + this.on_cancel(); + }, - if (this.$render_expandable) { - this.on_cancel(); - } + reinit: function() { + var $render = $( session.web.qweb.render('mail.compose_message', {'widget': this}) ); + + $render.insertAfter(this.$el.last()); + this.$el.remove(); + this.$el = $render; + + this.display_attachments(); + this.bind_events(); }, on_cancel: function (event) { if (event) event.stopPropagation(); - this.$render_expandable.find('textarea').val(""); - this.$render_expandable.find('input[data-id]').remove(); - this.attachment_ids=[]; - this.display_attachments(); - this.stay_open = false; - this.on_compose_expandable(); + this.show_composer = false; + this.reinit(); }, /*post a message and fetch the message*/ @@ -366,7 +358,7 @@ openerp.mail = function (session) { var self = this; if (! body) { - var comment_node = this.$render_expandable.find('textarea'); + var comment_node = this.$('textarea:not(.oe_compact)'); var body = comment_node.val(); comment_node.val(''); } @@ -396,70 +388,44 @@ openerp.mail = function (session) { // create object and attach to the thread object var message = thread.create_message_object( record[0] ); // insert the message on dom - thread.insert_message( message, self.thread_level > self.options.display_indented_thread ? self.parent_thread.$el : self.$el ); - // clean compose message - self.on_cancel(); + thread.insert_message( message, self.$el ); + if (thread.parent_thread) { + self.$el.remove(); + self.parent_thread.compose_message = null; + } else { + self.on_cancel(); + } //session.web.unblockUI(); }); return true; } }, - /* create the compose on expandable form - */ - instantiate_expandable: function () { - if (!this.$render_expandable) { - this.$render_expandable = $(session.web.qweb.render('mail.compose_message', {'widget': this})); - this.$render_expandable.hide(); - - this.$render_expandable.insertAfter( this.$render_compact ); - this.display_attachments(); - - 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')) { - - this.$render_expandable.css('display', ''); - this.$render_compact.hide(); - this.$render_expandable.find('textarea').focus(); - - } else if (!this.stay_open) { - - // 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 && this.show_compact_message) { - this.$render_compact.css('display', ''); - } else { - this.$render_compact.hide(); - } - } - + if (!this.show_composer || !this.$('textarea:not(.oe_compact)').val().match(/\S+/)){ + this.show_composer = !this.show_composer || this.stay_open; + this.reinit(); } + this.$('textarea:not(.oe_compact):first').focus(); return true; }, do_hide_compact: function () { - this.$render_compact.hide(); this.show_compact_message = false; + if (!this.show_composer) { + this.reinit(); + } }, do_show_compact: function () { - if (this.options.show_compact_message && (!this.$render_expandable || this.$render_expandable.is(':hidden'))) { - this.$render_compact.css('display', ''); - } this.show_compact_message = true; + if (!this.show_composer) { + this.reinit(); + } } }); @@ -520,10 +486,10 @@ openerp.mail = function (session) { this.$el.on('click', 'a.oe_msg_fetch_more', this.on_expandable); }, - animated_destroy: function (options) { + animated_destroy: function (fadeTime) { var self=this; //graphic effects - if (options && options.fadeTime) { + if (fadeTime) { self.$el.fadeOut(options.fadeTime, function () { self.destroy(); }); @@ -542,7 +508,7 @@ openerp.mail = function (session) { } this.flag_used = true; - this.animated_destroy({'fadeTime':300}); + this.animated_destroy(300); this.parent_thread.message_fetch(this.domain, this.context); return false; }, @@ -770,10 +736,10 @@ openerp.mail = function (session) { * Fade out the message and his child thread. * Then this object is destroyed. */ - animated_destroy: function (options) { + animated_destroy: function (fadeTime) { var self=this; //graphic effects - if (options && options.fadeTime) { + if (fadeTime) { self.$el.fadeOut(options.fadeTime, function () { self.parent_thread.message_to_expandable(self); }); @@ -791,7 +757,7 @@ openerp.mail = function (session) { event.stopPropagation(); if (! confirm(_t("Do you really want to delete this message?"))) { return false; } - this.animated_destroy({fadeTime:250}); + this.animated_destroy(250); // delete this message and his childs var ids = [this.id].concat( this.get_child_ids() ); this.ds_message.unlink(ids); @@ -807,7 +773,7 @@ openerp.mail = function (session) { if ( (this.to_read && this.options.typeof_thread == 'inbox') || (!this.to_read && this.options.typeof_thread == 'archives')) { - this.animated_destroy({fadeTime:250}); + this.animated_destroy(250); } // if this message is read, all childs message display is read @@ -900,7 +866,7 @@ openerp.mail = function (session) { } else { button.removeClass('oe_starred'); if ( self.options.typeof_thread == 'stared' ) { - self.animated_destroy({fadeTime:250}); + self.animated_destroy(250); } } }); @@ -979,7 +945,7 @@ openerp.mail = function (session) { this.show_compose_message = this.options.show_compose_message && (this.options.show_reply_button > this.thread_level || !this.thread_level); // object compose message - this.ComposeMessage = false; + this.compose_message = false; this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model || 'mail.thread'); this.ds_message = new session.web.DataSetSearch(this, 'mail.message'); @@ -987,29 +953,33 @@ openerp.mail = function (session) { start: function () { this._super.apply(this, arguments); + if (this.show_compose_message) { - this.instantiate_ComposeMessage(); + this.instantiate_compose_message(); } + this.bind_events(); }, /* instantiate the compose message object and insert this on the DOM. * The compose message is display in compact form. */ - instantiate_ComposeMessage: function () { + instantiate_compose_message: function () { // add message composition form view - this.ComposeMessage = new mail.ThreadComposeMessage(this, this, { - 'context': this.context, - 'options': this.options, - }); - - if (this.thread_level) { - this.ComposeMessage.appendTo(this.$el); - } else { - // root view - this.ComposeMessage.prependTo(this.$el); + if (!this.compose_message) { + this.compose_message = new mail.ThreadComposeMessage(this, this, { + 'context': this.context, + 'options': this.options, + }); + if (!this.thread_level) { + // root view + this.compose_message.insertBefore(this.$el); + } else if (this.thread_level > this.options.display_indented_thread) { + this.compose_message.insertAfter(this.$el); + } else { + this.compose_message.appendTo(this.$el); + } } - this.ComposeMessage.do_hide_compact(); }, /* When the expandable object is visible on screen (with scrolling) @@ -1139,24 +1109,24 @@ openerp.mail = function (session) { }, /** - *If ComposeMessage doesn't exist, instantiate the compose message. + *If compose_message doesn't exist, instantiate the compose message. * Call the on_compose_expandable method to allow the user to write his message. * (Is call when a user click on "Reply" button) */ on_compose_message: function () { - if (!this.ComposeMessage) { - this.instantiate_ComposeMessage(); - this.ComposeMessage.do_hide_compact(); - } - - this.ComposeMessage.on_compose_expandable(); + this.instantiate_compose_message(); + this.compose_message.on_compose_expandable(); }, /** *display the message "there are no message" on the thread */ no_message: function () { - $(session.web.qweb.render('mail.wall_no_message', {})).appendTo(this.$el); + var no_message = $(session.web.qweb.render('mail.wall_no_message', {})); + if (this.options.no_message) { + no_message.html(this.options.no_message); + } + no_message.appendTo(this.$el); }, /** @@ -1231,8 +1201,9 @@ openerp.mail = function (session) { insert_message: function (message, dom_insert_after) { var self=this; - if (this.show_compose_message) { - this.ComposeMessage.do_show_compact(); + if (this.show_compose_message && this.options.show_compact_message) { + this.instantiate_compose_message(); + this.compose_message.do_show_compact(); } this.$('.oe_wall_no_message').remove(); @@ -1244,17 +1215,17 @@ openerp.mail = function (session) { } // check older and newer message for insertion - var parent_newer = false; - var parent_older = false; + var message_newer = false; + var message_older = false; if (message.id > 0) { for (var i in self.messages) { if (self.messages[i].id > message.id) { - if (!parent_newer || parent_newer.id > self.messages[i].id) { - parent_newer = self.messages[i]; + if (!message_newer || message_newer.id > self.messages[i].id) { + message_newer = self.messages[i]; } } else if (self.messages[i].id > 0 && self.messages[i].id < message.id) { - if (!parent_older || parent_older.id < self.messages[i].id) { - parent_older = self.messages[i]; + if (!message_older || message_older.id < self.messages[i].id) { + message_older = self.messages[i]; } } } @@ -1264,14 +1235,13 @@ openerp.mail = function (session) { if (sort) { - if (parent_older) { + if (message_older) { - //warning : insert after the thread of the message ! - message.insertAfter(parent_older.thread ? parent_older.thread.$el : parent_older.$el); + message.insertAfter(message_older.thread.compose_message ? message_older.thread.compose_message.$el : message_older.thread.$el); - } else if (parent_newer) { + } else if (message_newer) { - message.insertBefore(parent_newer.$el); + message.insertBefore(message_newer.$el); } else if (message.id < 0) { @@ -1282,14 +1252,13 @@ openerp.mail = function (session) { message.prependTo(self.$el); } } else { - if (parent_older) { + if (message_older) { - message.insertBefore(parent_older.$el); + message.insertBefore(message_older.$el); - } else if (parent_newer) { + } else if (message_newer) { - //warning : insert after the thread of the message ! - message.insertAfter(parent_newer.thread ? parent_newer.thread.$el : parent_newer.$el); + message.insertAfter(message_newer.thread.compose_message ? message_newer.thread.compose_message.$el : message_newer.thread.$el); } else if (message.id < 0) { @@ -1436,7 +1405,7 @@ openerp.mail = function (session) { * @param {Array} [domain] * @param {Object} [context] context of the thread. It should * contain at least default_model, default_res_id. Please refer to - * the ComposeMessage widget for more information about it. + * 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] @@ -1453,6 +1422,7 @@ openerp.mail = function (session) { * 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. + * @param {String} [no_message] Message to display when there are no message */ init: function (parent, options) { this._super(parent); @@ -1469,7 +1439,8 @@ openerp.mail = function (session) { 'show_record_name' : false, 'show_compose_message' : false, 'show_compact_message' : false, - 'message_ids': [] + 'message_ids': [], + 'no_message': false }, options); if (this.display_indented_thread === false) { @@ -1509,10 +1480,11 @@ openerp.mail = function (session) { this.thread.message_fetch(null, null, this.options.message_ids); if (this.options.show_compose_message) { + this.thread.instantiate_compose_message(); if (this.options.show_compact_message) { - this.thread.ComposeMessage.do_show_compact(); + this.thread.compose_message.do_show_compact(); } else { - this.thread.ComposeMessage.do_hide_compact(); + this.thread.compose_message.do_hide_compact(); } } }, @@ -1535,6 +1507,7 @@ openerp.mail = function (session) { * This widget handles the display of messages on a document. Its main * use is to receive a context and a domain, and to delegate the message * fetching and displaying to the Thread widget. + * Use Help on the field to display a custom "no message loaded" */ session.web.form.widgets.add('mail_thread', 'openerp.mail.RecordThread'); mail.RecordThread = session.web.form.AbstractField.extend({ @@ -1589,6 +1562,7 @@ openerp.mail = function (session) { 'show_compose_message': show_compose_message, 'message_ids': message_ids, 'show_compact_message': true, + 'no_message': this.node.attrs.help } ); @@ -1693,7 +1667,7 @@ openerp.mail = function (session) { bind_events: function () { var self=this; - this.$(".oe_write_full").click(function(){ self.root.thread.ComposeMessage.on_compose_fullmail(); }); + this.$(".oe_write_full").click(function(){ self.root.thread.compose_message.on_compose_fullmail(); }); this.$(".oe_write_onwall").click(function(){ self.root.thread.on_compose_message(); }); } }); -- cgit v1.2.3 From 60e7f19ec5abca5463b4ea65819f99900730d98b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 26 Oct 2012 16:17:43 +0200 Subject: [IMP] mail: bind event bzr revid: chm@openerp.com-20121026141743-m2kod12as9z2eale --- addons/mail/static/src/js/mail.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index f98e82481fa..5c41a38a91e 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -276,11 +276,11 @@ openerp.mail = function (session) { this.$el.on('change', 'input.oe_form_binary_file', self.on_attachment_change ); this.$el.on('click', '.oe_cancel', self.on_cancel ); - this.$el.on('click', '.oe_post', function () {self.on_message_post()} ); - this.$el.on('click', '.oe_full', function () {self.on_compose_fullmail('reply')} ); + this.$el.on('click', '.oe_post', _.bind( this.on_message_post, this) ); + this.$el.on('click', '.oe_full', _.bind( this.on_compose_fullmail, this, 'reply') ); /* stack for don't close the compose form if the user click on a button */ - this.$el.on('mousedown', 'div', function () { self.stay_open = true; }); + this.$el.on('mousedown', '.oe_msg_footer', function () { self.stay_open = true; }); this.$('textarea:not(.oe_compact):first').on('focus, mouseup, keydown', function () { self.stay_open = false; }); this.$('textarea:not(.oe_compact):first').autosize(); @@ -389,7 +389,7 @@ openerp.mail = function (session) { var message = thread.create_message_object( record[0] ); // insert the message on dom thread.insert_message( message, self.$el ); - if (thread.parent_thread) { + if (thread.parent_message) { self.$el.remove(); self.parent_thread.compose_message = null; } else { @@ -410,7 +410,9 @@ openerp.mail = function (session) { this.show_composer = !this.show_composer || this.stay_open; this.reinit(); } - this.$('textarea:not(.oe_compact):first').focus(); + if (!this.stay_open && this.show_composer) { + this.$('textarea:not(.oe_compact):first').focus(); + } return true; }, @@ -740,10 +742,10 @@ openerp.mail = function (session) { var self=this; //graphic effects if (fadeTime) { - self.$el.fadeOut(options.fadeTime, function () { + self.$el.fadeOut(fadeTime, function () { self.parent_thread.message_to_expandable(self); }); - self.thread.$el.fadeOut(options.fadeTime); + self.thread.$el.fadeOut(fadeTime); } else { self.parent_thread.message_to_expandable(self); } -- cgit v1.2.3 From 38f4a6137afe056ec7873570cc232a9450120a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 26 Oct 2012 16:57:58 +0200 Subject: [IMP] mail: improved followers widget layout bzr revid: fva@openerp.com-20121026145758-sfwxii65fizb3nqa --- addons/mail/static/src/js/mail.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 78aa3e8513d..67e66a6a11a 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -542,7 +542,7 @@ openerp.mail = function (session) { } this.flag_used = true; - this.animated_destroy({'fadeTime':300}); + this.animated_destroy({'fadeTime':200}); this.parent_thread.message_fetch(this.domain, this.context); return false; }, @@ -791,7 +791,7 @@ openerp.mail = function (session) { event.stopPropagation(); if (! confirm(_t("Do you really want to delete this message?"))) { return false; } - this.animated_destroy({fadeTime:250}); + this.animated_destroy({fadeTime:150}); // delete this message and his childs var ids = [this.id].concat( this.get_child_ids() ); this.ds_message.unlink(ids); @@ -807,7 +807,7 @@ openerp.mail = function (session) { if ( (this.to_read && this.options.typeof_thread == 'inbox') || (!this.to_read && this.options.typeof_thread == 'archives')) { - this.animated_destroy({fadeTime:250}); + this.animated_destroy({fadeTime:150}); } // if this message is read, all childs message display is read @@ -900,7 +900,7 @@ openerp.mail = function (session) { } else { button.removeClass('oe_starred'); if ( self.options.typeof_thread == 'stared' ) { - self.animated_destroy({fadeTime:250}); + self.animated_destroy({fadeTime:150}); } } }); -- cgit v1.2.3 From b2bc5614a9b89c235b52f0ffc8eb2c6cc6cb8a82 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 26 Oct 2012 18:39:29 +0200 Subject: [IMP] mail: code pre review bzr revid: chm@openerp.com-20121026163929-mx125ei97h01h42o --- addons/mail/static/src/js/mail.js | 49 +++++++++++---------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 5c41a38a91e..15f61a6309a 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -174,17 +174,10 @@ openerp.mail = function (session) { /* upload the file on the server, add in the attachments list and reload display */ display_attachments: function () { - var self = this; - var render = $(session.web.qweb.render('mail.thread.message.attachments', {'widget': self})); - if (!this.list_attachment) { - this.$('.oe_msg_attachment_list').replaceWith( render ); - } else { - this.list_attachment.replaceWith( render ); - } - this.list_attachment = this.$(".oe_msg_attachments"); - + this.$(".oe_msg_attachment_list").html( + session.web.qweb.render('mail.thread.message.attachments', {'widget': this}) ); // event: delete an attachment - this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete); + this.$(".oe_msg_attachment_list").on('click', '.oe_mail_attachment_delete', this.on_attachment_delete); }, /* when a user click on the upload button, send file read on_attachment_loaded @@ -270,41 +263,31 @@ openerp.mail = function (session) { bind_events: function () { var self = this; - this.$('textarea.oe_compact').on('focus', self.on_compose_expandable); + this.$('textarea.oe_compact').on('focus', _.bind( this.on_compose_expandable, this)); // set the function called when attachments are added - this.$el.on('change', 'input.oe_form_binary_file', self.on_attachment_change ); + this.$el.on('change', 'input.oe_form_binary_file', _.bind( this.on_attachment_change, this) ); - this.$el.on('click', '.oe_cancel', self.on_cancel ); + this.$el.on('click', '.oe_cancel', _.bind( this.on_cancel, this) ); this.$el.on('click', '.oe_post', _.bind( this.on_message_post, this) ); this.$el.on('click', '.oe_full', _.bind( this.on_compose_fullmail, this, 'reply') ); /* stack for don't close the compose form if the user click on a button */ - this.$el.on('mousedown', '.oe_msg_footer', function () { self.stay_open = true; }); - this.$('textarea:not(.oe_compact):first').on('focus, mouseup, keydown', function () { self.stay_open = false; }); + this.$el.on('mousedown', '.oe_msg_footer', _.bind( function () { this.stay_open = true; }, this)); + this.$('textarea:not(.oe_compact):first').on('focus, mouseup, keydown', _.bind( function () { this.stay_open = false; }, this)); this.$('textarea:not(.oe_compact):first').autosize(); // auto close - this.$el.on('blur', 'textarea:not(.oe_compact):first', self.on_compose_expandable); + this.$el.on('blur', 'textarea:not(.oe_compact):first', _.bind( this.on_compose_expandable, this)); }, on_compose_fullmail: function (default_composition_mode) { - /* TDE note: I think this is not necessary, because - * 1/ post on a document: followers added server-side in _notify - * 2/ reply to a message: mail.compose.message should add the previous partners - */ - var partner_ids = []; - for (var i in this.partner_ids) { - partner_ids.push(this.partner_ids[i][0]); - } - if (default_composition_mode == 'reply') { var context = { 'default_composition_mode': 'reply', 'default_parent_id': this.id, 'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''), 'default_attachment_ids': this.attachment_ids, - 'default_partner_ids': [], //partner_ids }; } else { var context = { @@ -316,7 +299,6 @@ openerp.mail = function (session) { 'default_parent_id': this.id, 'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''), 'default_attachment_ids': this.attachment_ids, - 'default_partner_ids': [], //partner_ids }; } var action = { @@ -354,14 +336,12 @@ openerp.mail = function (session) { }, /*post a message and fetch the message*/ - on_message_post: function (body) { + on_message_post: function (event) { var self = this; - if (! body) { - var comment_node = this.$('textarea:not(.oe_compact)'); - var body = comment_node.val(); - comment_node.val(''); - } + var comment_node = this.$('textarea'); + var body = comment_node.val(); + comment_node.val(''); var attachments=[]; for (var i in this.attachment_ids) { @@ -404,9 +384,8 @@ openerp.mail = function (session) { /* convert the compact mode into the compose message */ on_compose_expandable: function (event) { - if (event) event.stopPropagation(); - if (!this.show_composer || !this.$('textarea:not(.oe_compact)').val().match(/\S+/)){ + if (!this.stay_open && (!this.show_composer || !this.$('textarea:not(.oe_compact)').val().match(/\S+/))) { this.show_composer = !this.show_composer || this.stay_open; this.reinit(); } -- cgit v1.2.3 From 0d4fdc41f9bec83c20ac66be62d4da066ba601c2 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 29 Oct 2012 10:29:34 +0100 Subject: [FIX] mail: resolve error to read message after posting bzr revid: chm@openerp.com-20121029092934-gqfg7gq90xs8w3k1 --- addons/mail/static/src/js/mail.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 27ffdebfc5a..28ba0e66923 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -365,15 +365,17 @@ openerp.mail = function (session) { ]).then(function (record) { var thread = self.parent_thread; // create object and attach to the thread object - var message = thread.create_message_object( record[0] ); - // insert the message on dom - thread.insert_message( message, self.$el ); - if (thread.parent_message) { - self.$el.remove(); - self.parent_thread.compose_message = null; - } else { - self.on_cancel(); - } + thread.message_fetch(false, false, [record], function (arg, data) { + var message = thread.create_message_object( data[0] ); + // insert the message on dom + thread.insert_message( message, self.$el ); + if (thread.parent_message) { + self.$el.remove(); + self.parent_thread.compose_message = null; + } else { + self.on_cancel(); + } + }); //session.web.unblockUI(); }); return true; @@ -1107,7 +1109,7 @@ openerp.mail = function (session) { * @param {Object} replace_context: added to this.context * @param {Array} ids read (if the are some ids, the method don't use the domain) */ - message_fetch: function (replace_domain, replace_context, ids) { + message_fetch: function (replace_domain, replace_context, ids, callback) { var self = this; // domain and context: options + additional @@ -1119,7 +1121,7 @@ openerp.mail = function (session) { 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')); + .then(callback ? _.bind(callback, this, arguments) : this.proxy('switch_new_message')); }, /** -- cgit v1.2.3 From c4e6506f8532792fdc9b9ce188cdd9ec78c7d2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 29 Oct 2012 10:50:47 +0100 Subject: [FIX] mail.js: now giving an undefined (None) ids in message_read instead of a void list. bzr revid: tde@openerp.com-20121029095047-k8ahahmuq6z4b9tv --- addons/mail/static/src/js/mail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 27ffdebfc5a..2f38045b419 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1409,7 +1409,7 @@ openerp.mail = function (session) { 'show_record_name' : false, 'show_compose_message' : false, 'show_compact_message' : false, - 'message_ids': [], + 'message_ids': undefined, 'no_message': false }, options); -- cgit v1.2.3 From a2d3d1df80c044ed62a02e47d7dca242b385992d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 29 Oct 2012 11:12:30 +0100 Subject: [CLEAN] message_post_api: removed unnecessary type arg (posting is a comment). bzr revid: tde@openerp.com-20121029101230-x39pep9p5edd54ml --- addons/mail/static/src/js/mail.js | 1 - 1 file changed, 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 6a409782117..0b6a8ec86d2 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -358,7 +358,6 @@ openerp.mail = function (session) { this.context.default_res_id, mail.ChatterUtils.get_text2html(body), false, - 'comment', this.context.default_parent_id, attachments, this.parent_thread.context -- cgit v1.2.3 From d97ffd7b19249f3a9f72d3a91c9d23106bdf975b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 29 Oct 2012 12:21:17 +0100 Subject: [CLEAN] Misc cleaning of code: removed debug statements, added some notes. bzr revid: tde@openerp.com-20121029112117-kup1q99c2nbkgar7 --- addons/mail/static/src/js/mail.js | 71 +++++++++++++---------------- addons/mail/static/src/js/mail_followers.js | 8 ++-- 2 files changed, 35 insertions(+), 44 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 0b6a8ec86d2..766f5034fb0 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -7,7 +7,7 @@ openerp.mail = function (session) { openerp_mail_followers(session, mail); // import mail_followers.js /** - * ------------------------------------------------------------ + * ------------------------------------------------------------ * FormView * ------------------------------------------------------------ * @@ -17,16 +17,15 @@ openerp.mail = function (session) { session.web.FormView = session.web.FormView.extend({ do_action: function (action) { - console.log(action); - if (action.res_model == 'mail.compose.message') { /* hack for stop context propagation of wrong value * delete this hack when a global method to clean context is create */ var context_keys = ['default_template_id', 'default_composition_mode', 'default_use_template', 'default_partner_ids', 'default_model', - 'default_res_id', 'default_content_subtype', 'active_id', 'lang', - 'bin_raw', 'tz', 'active_model', 'edi_web_url_view', 'active_ids', 'default_subject'] + 'default_res_id', 'default_content_subtype', , 'default_subject', + 'default_body', 'active_id', 'lang', 'bin_raw', 'tz', + 'active_model', 'edi_web_url_view', 'active_ids'] for (var key in action.context) { if (_.indexOf(context_keys, key) == -1) { action.context[key] = null; @@ -40,7 +39,7 @@ openerp.mail = function (session) { /** - * ------------------------------------------------------------ + * ------------------------------------------------------------ * ChatterUtils * ------------------------------------------------------------ * @@ -53,20 +52,18 @@ openerp.mail = function (session) { mail.ChatterUtils = { - /** - *Get an image in /web/binary/image?... */ + /* Get an image in /web/binary/image?... */ get_image: function (session, model, field, id) { return session.prefix + '/web/binary/image?session_id=' + session.session_id + '&model=' + model + '&field=' + field + '&id=' + (id || ''); }, - /** - *Get the url of an attachment {'id': id} */ + /* Get the url of an attachment {'id': id} */ get_attachment_url: function (session, attachment) { return session.origin + '/web/binary/saveas?session_id=' + session.session_id + '&model=ir.attachment&field=datas&filename_field=datas_fname&id=' + attachment['id']; }, /** - *Replaces some expressions + * Replaces some expressions * - :name - shortcut to an image */ do_replace_expressions: function (string) { @@ -83,23 +80,23 @@ openerp.mail = function (session) { return string; }, - /* replace textarea text into html text - * (add

    , ) - * TDE note : should not be here, but server-side I think ... - */ + /** + * Replaces textarea text into html text (add

    , ) + * TDE note : should be done server-side, in Python -> use mail.compose.message ? + */ get_text2html: function (text) { return text .replace(/[\n\r]/g,'
    ') .replace(/((?:https?|ftp):\/\/[\S]+)/g,'
    $1 ') }, - /** - * return the complete domain with "&" + /* Returns the complete domain with "&" + * TDE note: please add some comments to explain how/why */ - expend_domain: function (domain) { + expand_domain: function (domain) { var new_domain = []; var nb_and = -1; - + // TDE note: smarted code maybe ? for ( var k = domain.length-1; k >= 0 ; k-- ) { if ( typeof domain[k] != 'array' && typeof domain[k] != 'object' ) { nb_and -= 2; @@ -118,16 +115,15 @@ openerp.mail = function (session) { /** - * ------------------------------------------------------------ + * ------------------------------------------------------------ * ComposeMessage widget * ------------------------------------------------------------ * * This widget handles the display of a form to compose a new message. * This form is a mail.compose.message form_view. - * On first time : display a compact textarea but is not the compose form. - * When the user focus this box, the compose message is intantiate and - * with focus on the textarea. - */ + * On first time : display a compact textarea that is not the compose form. + * When the user focuses the textarea, the compose message is instantiated. + */ mail.ThreadComposeMessage = session.web.Widget.extend({ template: 'mail.compose_message', @@ -284,7 +280,7 @@ openerp.mail = function (session) { on_compose_fullmail: function (default_composition_mode) { if (default_composition_mode == 'reply') { var context = { - 'default_composition_mode': 'reply', + 'default_composition_mode': default_composition_mode, 'default_parent_id': this.id, 'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''), 'default_attachment_ids': this.attachment_ids, @@ -292,10 +288,9 @@ openerp.mail = function (session) { } else { var context = { 'default_model': this.context.default_model, - 'default_res_model': this.context.default_model, 'default_res_id': this.context.default_res_id, 'default_content_subtype': 'html', - 'default_composition_mode': 'comment', + 'default_composition_mode': default_composition_mode, 'default_parent_id': this.id, 'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''), 'default_attachment_ids': this.attachment_ids, @@ -411,7 +406,7 @@ openerp.mail = function (session) { }); /** - * ------------------------------------------------------------ + * ------------------------------------------------------------ * Thread Message Expandable Widget * ------------------------------------------------------------ * @@ -501,7 +496,7 @@ openerp.mail = function (session) { }); /** - * ------------------------------------------------------------ + * ------------------------------------------------------------ * Thread Message Widget * ------------------------------------------------------------ * This widget handles the display of a messages in a thread. @@ -588,9 +583,7 @@ openerp.mail = function (session) { this.ds_follow = new session.web.DataSetSearch(this, 'mail.followers'); }, - /** - *Convert date, timerelative and avatar in displayable data. - */ + /* Convert date, timerelative and avatar in displayable data. */ formating_data: function () { //formating and add some fields for render @@ -665,9 +658,7 @@ openerp.mail = function (session) { this.$el.on('click', '.oe_star', this.on_star); }, - /** - * call the on_compose_message on the thread of this message. - */ + /* Call the on_compose_message on the thread of this message. */ on_message_reply:function (event) { event.stopPropagation(); this.thread.on_compose_message(); @@ -686,7 +677,7 @@ openerp.mail = function (session) { }, /** - * instantiate the thread object of this message. + * Instantiate the thread object of this message. * Each message have only one thread. */ create_thread: function () { @@ -1294,8 +1285,8 @@ openerp.mail = function (session) { if ( msg_up && msg_up.type == "expandable" && msg_down && msg_down.type == "expandable") { // concat two expandable message and add this message to this dom - msg_up.domain = mail.ChatterUtils.expend_domain( msg_up.domain ); - msg_down.domain = mail.ChatterUtils.expend_domain( msg_down.domain ); + msg_up.domain = mail.ChatterUtils.expand_domain( msg_up.domain ); + msg_down.domain = mail.ChatterUtils.expand_domain( msg_down.domain ); msg_down.domain = ['|','|'].concat( msg_up.domain ).concat( message_dom ).concat( msg_down.domain ); @@ -1310,7 +1301,7 @@ openerp.mail = function (session) { } else if ( msg_up && msg_up.type == "expandable") { // concat preview expandable message and this message to this dom - msg_up.domain = mail.ChatterUtils.expend_domain( msg_up.domain ); + msg_up.domain = mail.ChatterUtils.expand_domain( msg_up.domain ); msg_up.domain = ['|'].concat( msg_up.domain ).concat( message_dom ); msg_up.nb_messages++; @@ -1319,7 +1310,7 @@ openerp.mail = function (session) { } else if ( msg_down && msg_down.type == "expandable") { // concat next expandable message and this message to this dom - msg_down.domain = mail.ChatterUtils.expend_domain( msg_down.domain ); + msg_down.domain = mail.ChatterUtils.expand_domain( msg_down.domain ); msg_down.domain = ['|'].concat( msg_down.domain ).concat( message_dom ); // it's maybe a message expandable for the max limit read message diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 7fed5371600..a13d2048bf3 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -115,8 +115,8 @@ openerp_mail_followers = function(session, mail) { }).pipe(self.proxy('display_generic')); }, _format_followers: function(count){ - console.log('FORMAT FOLLWERS :',count); - function _t(str){return str;} + // TDE note: why redefining _t ? + function _t(str) { return str; } var str = ''; if(count <= 0){ str = _t('No followers'); @@ -125,7 +125,6 @@ openerp_mail_followers = function(session, mail) { }else{ str = ''+count+' '+_t('followers'); } - console.log('URGH:',str); return str; }, /* Display generic info about follower, for people not having access to res_partner */ @@ -149,7 +148,8 @@ openerp_mail_followers = function(session, mail) { record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); $(session.web.qweb.render('mail.followers.partner', {'record': record})).appendTo(node_user_list); }); - if (truncated.length < records.length) { //FIXME USE A TEMPLATE ! + // FVA note: be sure it is correctly translated + if (truncated.length < records.length) { $('

    And ' + (records.length - truncated.length) + ' more.
    ').appendTo(node_user_list); } }, -- cgit v1.2.3 From 81df392b715a4ebf299f52327f0dc740ce4be3ca Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 29 Oct 2012 12:22:54 +0100 Subject: [IMP] mail: openchatter, reduce DOM item bzr revid: chm@openerp.com-20121029112254-e0az3mi3vmmk83ca --- addons/mail/static/src/js/mail.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 766f5034fb0..8d439f59826 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -611,7 +611,9 @@ openerp.mail = function (session) { this.$el.hide().fadeIn(750, function () {$(this).css('display', '');}); this.resize_img(); this.bind_events(); - this.create_thread(); + if(this.thread_level < this.options.display_indented_thread) { + this.create_thread(); + } this.$('.oe_msg_attachments, .oe_msg_images').addClass("oe_hidden"); }, @@ -915,11 +917,6 @@ openerp.mail = function (session) { start: function () { this._super.apply(this, arguments); - - if (this.show_compose_message) { - this.instantiate_compose_message(); - } - this.bind_events(); }, @@ -1195,11 +1192,10 @@ openerp.mail = function (session) { var sort = (!!self.thread_level || message.id<0); - if (sort) { if (message_older) { - message.insertAfter(message_older.thread.compose_message ? message_older.thread.compose_message.$el : message_older.thread.$el); + message.insertAfter(message_older.thread ? (message_older.thread.compose_message ? message_older.thread.compose_message.$el : message_older.thread.$el) : message_older.$el); } else if (message_newer) { @@ -1220,7 +1216,7 @@ openerp.mail = function (session) { } else if (message_newer) { - message.insertAfter(message_newer.thread.compose_message ? message_newer.thread.compose_message.$el : message_newer.thread.$el); + message.insertAfter(message_newer.thread ? (message_newer.thread.compose_message ? message_newer.thread.compose_message.$el : message_newer.thread.$el) : message_newer.$el ); } else if (message.id < 0) { -- cgit v1.2.3 From 79669aaf9b3324b75397fb79e3c7f98302f65efa Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 29 Oct 2012 12:31:45 +0100 Subject: [FIX] mail: compose message with reduce DOM bzr revid: chm@openerp.com-20121029113145-50gx1qdu3co3jd0c --- addons/mail/static/src/js/mail.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8d439f59826..5b42620b260 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -663,6 +663,7 @@ openerp.mail = function (session) { /* Call the on_compose_message on the thread of this message. */ on_message_reply:function (event) { event.stopPropagation(); + this.create_thread(); this.thread.on_compose_message(); return false; }, @@ -1105,9 +1106,9 @@ openerp.mail = function (session) { var message_loaded_ids = this.id ? [this.id].concat( self.get_child_ids() ) : self.get_child_ids(); // 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; + 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, nb_indented_thread, fetch_context, this.context.default_parent_id || undefined]) + 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')); }, -- cgit v1.2.3 From 54a945f63c8329bb66d3db3015ec3f28d2c39715 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 29 Oct 2012 15:28:56 +0100 Subject: [IMP] mail: openchatter fadeout fix bzr revid: chm@openerp.com-20121029142856-kd2mnje5w4ee5x3t --- addons/mail/static/src/js/mail.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'addons/mail/static/src/js') diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 5b42620b260..9133e5de257 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -711,7 +711,9 @@ openerp.mail = function (session) { this.$el.fadeOut(fadeTime, function () { self.parent_thread.message_to_expandable(self); }); - this.thread.$el.fadeOut(fadeTime); + if (this.thread) { + this.thread.$el.fadeOut(fadeTime); + } }, /** -- cgit v1.2.3