[IMP] mail: auto display subtypes on subscription (web)

bzr revid: chm@openerp.com-20120925085809-u8f7tvtbdxnftbu4
This commit is contained in:
Christophe Matthieu
2012-09-25 10:58:09 +02:00
parent ac7adf29d2
commit 4525190e72
2 changed files with 47 additions and 19 deletions
+29 -7
View File
@@ -625,10 +625,17 @@ class mail_thread(osv.AbstractModel):
``(name,content)``, where content is NOT base64 encoded
:return: ID of newly created mail.message
"""
# message_post
# [26] False notification mt_crm_stage False
# message_post
# [26] False notification mt_crm_won False
context = context or {}
attachments = attachments or []
assert (not thread_id) or isinstance(thread_id, (int, long)) or \
(isinstance(thread_id, (list, tuple)) and len(thread_id) == 1), "Invalid thread_id"
if isinstance(thread_id, (list, tuple)):
thread_id = thread_id and thread_id[0]
@@ -652,9 +659,19 @@ class mail_thread(osv.AbstractModel):
else:
subtype_id = False
#auto link messages for same id and object
messages = self.pool.get('mail.message')
model = context.get('thread_model', self._name) if thread_id else False
if model != 'res.partner':
message_ids = messages.search(cr, uid, ['&',('res_id', '=', thread_id),('model','=',model)], context=context)
if len(message_ids):
parent_id = min(message_ids)
values = kwargs
values.update({
'model': context.get('thread_model', self._name) if thread_id else False,
'model': model,
'res_id': thread_id or False,
'body': body,
'subject': subject,
@@ -666,12 +683,22 @@ class mail_thread(osv.AbstractModel):
# Avoid warnings about non-existing fields
for x in ('from', 'to', 'cc'):
values.pop(x, None)
return self.pool.get('mail.message').create(cr, uid, values, context=context)
print "------------------------------------------"
print values, "mail_thread 688"
print "--------≃============----------------------------------"
return messages.create(cr, uid, values, context=context)
#------------------------------------------------------
# Followers API
#------------------------------------------------------
def get_message_subtypes(self, cr, uid, ids, context=None):
""" message_subtype_data: data about document subtypes: which are
available, which are followed if any """
return self._get_subscription_data(cr, uid, ids, None, None, context=context)
def message_subscribe_users(self, cr, uid, ids, user_ids=None, subtype_ids=None, context=None):
""" Wrapper on message_subscribe, using users. If user_ids is not
provided, subscribe uid instead. """
@@ -680,11 +707,6 @@ class mail_thread(osv.AbstractModel):
partner_ids = [user.partner_id.id for user in self.pool.get('res.users').browse(cr, uid, user_ids, context=context)]
return self.message_subscribe(cr, uid, ids, partner_ids, subtype_ids=subtype_ids, context=context)
def get_message_subtypes(self, cr, uid, ids, context=None):
""" message_subtype_data: data about document subtypes: which are
available, which are followed if any """
return self._get_subscription_data(cr, uid, ids, None, None, context=context)
def message_subscribe(self, cr, uid, ids, partner_ids, subtype_ids=None, context=None):
""" Add partners to the records followers. """
self.write(cr, uid, ids, {'message_follower_ids': [(4, pid) for pid in partner_ids]}, context=context)
+18 -12
View File
@@ -51,11 +51,11 @@ openerp_mail_followers = function(session, mail) {
bind_events: function() {
var self = this;
this.$el.find('button.oe_mail_button_unfollow').on('click', function () { self.do_unfollow(); self.clear_subtypes(); })
this.$el.find('button.oe_mail_button_unfollow').on('click', function () { self.do_unfollow(); })
.mouseover(function () { $(this).removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover').find('p').html('Unfollow');})
.mouseleave(function () { $(this).removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout').find('p').html('Following'); });
this.$el.on('click', 'button.oe_mail_button_follow', function () { self.do_follow(); self.clear_subtypes(); });
this.$el.on('click', 'button.oe_mail_button_follow', function () { self.do_follow(); });
this.$el.on('click', 'ul.oe_mail_subtypes input', function () {self.do_update_subscription(); })
this.$el.on('click', 'button.oe_mail_button_invite', function(event) {
action = {
@@ -101,9 +101,9 @@ openerp_mail_followers = function(session, mail) {
return false;
},
fetch_followers: function (value_, message_is_follower) {
this.value = value_;
this.message_is_follower = message_is_follower || (this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value());
fetch_followers: function (value_) {
this.value = value_ || {};
this.message_is_follower = (this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value());
return this.ds_follow.call('read', [value_, ['name', 'user_ids']]).pipe(this.proxy('display_followers'), this.proxy('display_generic'));
},
@@ -163,7 +163,7 @@ openerp_mail_followers = function(session, mail) {
},
/** Display subtypes: {'name': default, followed} */
display_subtypes: function () {
display_subtypes: function (visible) {
var self = this;
var recthread_subtypes = self.$el.find('.oe_mail_recthread_subtypes');
subtype_list_ul = self.$el.find('ul.oe_mail_subtypes');
@@ -180,21 +180,27 @@ openerp_mail_followers = function(session, mail) {
}
},
clear_subtypes: function(){
this.$el.find('ul.oe_mail_subtypes').empty();
this.hidden_subtypes();
},
hidden_subtypes: function (){
this.$el.find('.oe_mail_recthread_subtypes').hide();
},
do_follow: function () {
var self =this;
_(this.$el.find('.oe_msg_subtype_check')).each(function(record){
$(record).attr('checked','checked');
});
var context = new session.web.CompoundContext(this.build_context(), {});
return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, undefined, context]).pipe(this.proxy('read_value'));
return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, undefined, context]).pipe(function(value_){
self.read_value(value_);
if(!self.$el.find('.oe_mail_recthread_subtypes').is(":visible"))
self.display_subtypes(true);
});
},
do_unfollow: function () {
_(this.$el.find('.oe_msg_subtype_check')).each(function(record){
$(record).attr('checked',false);
});
var context = new session.web.CompoundContext(this.build_context(), {});
return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('read_value'));
},