[IMP] mail: auto open and close the compose form on the threads

bzr revid: chm@openerp.com-20121019102117-rzpdmkrbi7xhynpf
This commit is contained in:
Christophe Matthieu 2012-10-19 12:21:17 +02:00
parent 97d11807aa
commit 7de23b01f5
3 changed files with 78 additions and 49 deletions

View File

@ -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 ?

View File

@ -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
},
});

View File

@ -190,9 +190,9 @@
<div class='oe_msg_right'>
<div class="oe_msg_icons">
<t t-call="mail.thread.message.star"/>
<a t-if="widget.datasets.show_read_unread" title="Read" class="oe_read oe_e">W</a>
<a t-if="widget.datasets.show_read_unread" title="Set back to unread" class="oe_unread oe_e">h</a>
<a t-if="widget.datasets.show_reply" title="Reply" class="oe_reply oe_e">)</a>
<a t-if="widget.datasets.show_read_unread_button" title="Read" class="oe_read oe_e">W</a>
<a t-if="widget.datasets.show_read_unread_button" title="Set back to unread" class="oe_unread oe_e">h</a>
<a t-if="widget.datasets.show_reply_button" title="Reply" class="oe_reply oe_e">)</a>
</div>
</div>
@ -258,11 +258,12 @@
<t t-if='widget.datasets.has_voted'>
You
</t>
<t t-if='(widget.datasets.vote_user_ids.length-(widget.datasets.has_voted?1:0)) > 0'>
<t t-if='(widget.datasets.vote_nb - (widget.datasets.has_voted ? 1 : 0)) > 0'>
<t t-if='widget.datasets.has_voted'> and </t>
<t t-esc="widget.datasets.vote_user_ids.length"/> people
<t t-esc="widget.datasets.vote_nb"/> people
</t>
<t t-if='widget.datasets.vote_user_ids.length > 0'>
<t t-if='(widget.datasets.vote_nb - (widget.datasets.has_voted ? 1 : 0)) > 0'>
<t t-raw="(widget.datasets.vote_nb - (widget.datasets.has_voted ? 1 : 0))"/>
concur
</t>
</span>