From dfa34c02540cbb84ad6018ad62582574c4e959b9 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 19 Oct 2012 13:39:51 +0200 Subject: [PATCH] [IMP] mail: auto open and close the compose form on the threads bzr revid: chm@openerp.com-20121019113951-pz44iipv45misvgk --- addons/mail/mail_message.py | 14 +-- addons/mail/static/src/css/mail.css | 14 +-- addons/mail/static/src/js/mail.js | 188 +++++++++++++++++----------- addons/mail/static/src/xml/mail.xml | 17 +-- 4 files changed, 132 insertions(+), 101 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 4fac2db1061..989b63afee5 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -350,8 +350,6 @@ class mail_message(osv.Model): read_messages = {} message_list = [] - print message_loaded_ids - # specific IDs given: fetch those ids and return directly the message list if ids: for message in self.read(cr, uid, ids, self._message_read_fields, context=context): @@ -377,15 +375,11 @@ class mail_message(osv.Model): message_list.append(self._message_get_dict(cr, uid, parent, context=context)) parent = self._get_parent(cr, uid, parent, context=context) - # print read_messages - # print message_list + # get the child expandable messages for the tree + message_list = sorted(message_list, key=lambda k: k['id']) + message_list = self._message_read_expandable(cr, uid, message_list, read_messages, + message_loaded_ids=message_loaded_ids, domain=domain, context=context, parent_id=parent_id, limit=limit) - # get the child expandable messages for the tree - message_list = sorted(message_list, key=lambda k: k['id']) - # message_list = self._message_read_expandable(cr, uid, message_list, read_messages, - # message_loaded_ids=message_loaded_ids, domain=domain, context=context, parent_id=parent_id, limit=limit) - - # message_list = sorted(message_list, key=lambda k: k['id']) return message_list # TDE Note: do we need this ? diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 8261478319a..f8bbe99dbef 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -51,6 +51,9 @@ padding-left: 4px; overflow: hidden; } +.openerp .oe_mail .oe_msg.oe_msg_composer .oe_msg_footer{ + height: auto; +} .openerp .oe_mail .oe_msg .oe_msg_content{ display: block; overflow: hidden; @@ -83,14 +86,3 @@ .openerp .oe_mail .oe_msg.oe_msg_read .oe_read{ display:none; } - -.openerp .oe_mail .oe_msg_last { - border-bottom: 5px solid black; - border-left: 2px solid black; - border-right: 2px solid black; -} -.openerp .oe_mail .oe_msg_first { - border-top: 5px solid black; - border-left: 2px solid black; - border-right: 2px solid black; -} \ No newline at end of file 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') ); diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 651f0588868..db3fb5050c9 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -174,9 +174,9 @@ -->
- +
@@ -190,9 +190,9 @@
- W - h - ) + W + h + )
@@ -258,11 +258,12 @@ You - + and - people + people - + + concur