[IMP] mail: review and reduce of js

bzr revid: chm@openerp.com-20121030131136-e72mj13a408m2bwx
This commit is contained in:
Christophe Matthieu 2012-10-30 14:11:36 +01:00
parent 933a46893a
commit fbc46c5b2d
1 changed files with 42 additions and 38 deletions

View File

@ -745,12 +745,13 @@ openerp.mail = function (session) {
var self=this; var self=this;
// if this message is read, all childs message display is 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 () { this.ds_notification.call('set_message_read', [ [this.id].concat( this.get_child_ids() ) , this.to_read, this.context])
self.$el.removeClass(self.to_read ? 'oe_msg_unread':'oe_msg_read').addClass(self.to_read ? 'oe_msg_read':'oe_msg_unread'); .then(function () {
self.to_read = !self.to_read; self.$el.removeClass(self.to_read ? 'oe_msg_unread':'oe_msg_read').addClass(self.to_read ? 'oe_msg_read':'oe_msg_unread');
// check if the message must be display self.to_read = !self.to_read;
self.check_for_destroy(); // check if the message must be display
}); self.check_for_destroy();
});
return false; return false;
}, },
@ -803,12 +804,13 @@ openerp.mail = function (session) {
*/ */
on_vote: function (event) { on_vote: function (event) {
event.stopPropagation(); event.stopPropagation();
return this.ds_message.call('vote_toggle', [[this.id]]).pipe( return this.ds_message.call('vote_toggle', [[this.id]])
_.bind(function (vote) { .then(
this.has_voted = vote; _.bind(function (vote) {
this.vote_nb += this.has_voted ? 1 : -1; this.has_voted = vote;
this.display_vote(); this.vote_nb += this.has_voted ? 1 : -1;
}, this)); this.display_vote();
}, this));
return false; return false;
}, },
@ -828,16 +830,17 @@ openerp.mail = function (session) {
event.stopPropagation(); event.stopPropagation();
var self=this; var self=this;
var button = self.$('.oe_star:first'); 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]])
self.is_favorite=star; .then(function (star) {
if (self.is_favorite) { self.is_favorite=star;
button.addClass('oe_starred'); if (self.is_favorite) {
} else { button.addClass('oe_starred');
button.removeClass('oe_starred'); } else {
// check if the message must be display button.removeClass('oe_starred');
self.check_for_destroy(); // check if the message must be display
} self.check_for_destroy();
}); }
});
return false; return false;
}, },
@ -894,6 +897,7 @@ openerp.mail = function (session) {
this.options = options.options; this.options = options.options;
this.options.root_thread = (options.options.root_thread != undefined ? options.options.root_thread : this); this.options.root_thread = (options.options.root_thread != undefined ? options.options.root_thread : this);
this.options.show_compose_message = this.options.show_compose_message && (this.options.display_indented_thread >= this.thread_level || !this.thread_level);
// record options and data // record options and data
this.parent_message= parent.thread!= undefined ? parent : false ; this.parent_message= parent.thread!= undefined ? parent : false ;
@ -907,8 +911,7 @@ openerp.mail = function (session) {
this.thread_level = (datasets.thread_level+1) || 0, 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.messages = [];
this.show_compose_message = this.options.show_compose_message && (this.options.show_reply_button > this.thread_level || !this.thread_level);
// object compose message // object compose message
this.compose_message = false; this.compose_message = false;
@ -1096,18 +1099,20 @@ openerp.mail = function (session) {
* @param {Array} ids read (if the are some ids, the method don't use the domain) * @param {Array} ids read (if the are some ids, the method don't use the domain)
*/ */
message_fetch: function (replace_domain, replace_context, ids, callback) { message_fetch: function (replace_domain, replace_context, ids, callback) {
var self = this; return this.ds_message.call('message_read', [
// ids force to read
// domain and context: options + additional ids,
fetch_domain = replace_domain ? replace_domain : this.domain; // domain + additional
fetch_context = replace_context ? replace_context : this.context; (replace_domain ? replace_domain : this.domain),
var message_loaded_ids = this.id ? [this.id].concat( self.get_child_ids() ) : self.get_child_ids(); // ids allready loaded
(this.id ? [this.id].concat( this.get_child_ids() ) : this.get_child_ids()),
// CHM note : option for sending in flat mode by server // option for sending in flat mode by server
var thread_level = this.options.display_indented_thread > this.thread_level ? this.options.display_indented_thread - this.thread_level : 0; (this.options.display_indented_thread > this.thread_level ? this.options.display_indented_thread - this.thread_level : 0),
// context + additional
return this.ds_message.call('message_read', [ids, fetch_domain, message_loaded_ids, thread_level, fetch_context, this.context.default_parent_id || undefined]) (replace_context ? replace_context : this.context),
.then(callback ? _.bind(callback, this, arguments) : this.proxy('switch_new_message')); // parent_id
this.context.default_parent_id || undefined
]).done(callback ? _.bind(callback, this, arguments) : this.proxy('switch_new_message'));
}, },
/** /**
@ -1159,7 +1164,7 @@ openerp.mail = function (session) {
insert_message: function (message, dom_insert_after) { insert_message: function (message, dom_insert_after) {
var self=this; var self=this;
if (this.show_compose_message && this.options.show_compact_message) { if (this.options.show_compact_message) {
this.instantiate_compose_message(); this.instantiate_compose_message();
this.compose_message.do_show_compact(); this.compose_message.do_show_compact();
} }
@ -1526,7 +1531,6 @@ openerp.mail = function (session) {
*/ */
init: function (parent, options) { init: function (parent, options) {
this._super(parent); this._super(parent);
console.log(arguments);
this.options = options || {}; this.options = options || {};
this.options.domain = options.domain || []; this.options.domain = options.domain || [];
this.options.context = options.context || {}; this.options.context = options.context || {};