diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index db177db7e8c..63f5b8316df 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -119,12 +119,10 @@ class mail_thread(osv.AbstractModel): return True return False - def _get_subscription_data(self, cr, uid, ids, name, args, context=None): + def _get_subscription_data(self, cr, uid, ids, user_id, name, args, context=None): """ Computes: - message_subtype_data: data about document subtypes: which are available, which are followed if any """ - if context is None: - context = {} res = dict((id, dict(message_subtype_data='')) for id in ids) user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] @@ -135,8 +133,8 @@ class mail_thread(osv.AbstractModel): for id in ids: res[id]['message_subtype_data'] = subtype_dict.copy() - if 'partner_id' in context: - user_pid = context.get('partner_id') + if user_id: + user_pid = user_id # find the document followers, update the data fol_obj = self.pool.get('mail.followers') fol_ids = fol_obj.search(cr, uid, [ @@ -301,17 +299,6 @@ class mail_thread(osv.AbstractModel): default['message_follower_ids'] = [] return super(mail_thread, self).copy(cr, uid, id, default=default, context=context) - def apply_edited_subtypes(self, cr, uid, ids, partner_id, check_list, context=None): - """ Apply the edited subtypes of the user.""" - fol_obj = self.pool.get('mail.followers') - fol_ids = fol_obj.search(cr, uid, [ - ('partner_id', '=', partner_id), - ('res_id', 'in', ids), - ('res_model', '=', self._name), - ], context=context) - fol_obj.write(cr, uid, fol_ids, {'subtype_ids': [(6,0, check_list)]}, context=context) - return True - #------------------------------------------------------ # Automatically log tracked fields #------------------------------------------------------ @@ -1102,21 +1089,23 @@ class mail_thread(osv.AbstractModel): # Followers API #------------------------------------------------------ - def message_get_subscription_data(self, cr, uid, ids, context=None): + def message_get_subscription_data(self, cr, uid, ids, user_id=None, context=None): """ Wrapper to get subtypes data. """ - return self._get_subscription_data(cr, uid, ids, None, None, context=context) + return self._get_subscription_data(cr, uid, ids, user_id, None, None, context=context) - def message_subscribe_users(self, cr, uid, ids, user_ids=None, subtype_ids=None, context=None): + def message_subscribe_users(self, cr, uid, ids, user_ids=None, partner_id=None, subtype_ids=None, context=None): """ Wrapper on message_subscribe, using users. If user_ids is not provided, subscribe uid instead. """ if user_ids is None: user_ids = [uid] 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) + return self.message_subscribe(cr, uid, ids, partner_ids, partner_id, subtype_ids=subtype_ids, context=context) - def message_subscribe(self, cr, uid, ids, partner_ids, subtype_ids=None, context=None): + def message_subscribe(self, cr, uid, ids, partner_ids, user_id, subtype_ids=None, context=None): """ Add partners to the records followers. """ user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] + if user_id: + partner_ids = [user_id] if set(partner_ids) == set([user_pid]): self.check_access_rights(cr, uid, 'read') else: diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 7e49a391bca..bc15eed3fd9 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -82,38 +82,20 @@ openerp_mail_followers = function(session, mail) { on_edit_subtype: function(event) { var self = this; var partner_id = $(event.target).data('id'); - var context = new session.web.CompoundContext(this.build_context(), {'partner_id': partner_id}); - self.$dialog = new session.web.dialog($('
'), { + self.$dialog = new session.web.dialog($('
'), { modal: true, width: 'auto', height: 'auto', - title: _t('Edit Subscriptions of ') + $(event.target).siblings('a').text(), + title: _t('Edit Subscription of ') + $(event.target).siblings('a').text(), buttons: [ { text: _t("Apply"), click: function() { - self.on_apply_subtype(partner_id); + self.do_update_subscription(event, partner_id); $(this).remove(); }}, { text: _t("Cancel"), click: function() { $(this).remove(); }} ], }); - return self.fetch_subtypes(context); - }, - - on_apply_subtype: function(partner_id) { - var check_list = new Array(); - var id = this.view.datarecord.id; - _($('.oe_edit_actions input[type="checkbox"]')).each(function (record) { - if ($(record).is(':checked')) { - check_list.push(parseInt($(record).data('id'))); - } - }); - - if (!check_list.length) { - this.do_unfollow(); - } else { - return this.ds_model.call('apply_edited_subtypes', [[id], partner_id, check_list, new session.web.CompoundContext(this.build_context(), {})]) - .then(this.proxy('read_value')); - } + return self.fetch_subtypes(partner_id); }, on_invite_follower: function (event) { @@ -251,17 +233,17 @@ openerp_mail_followers = function(session, mail) { }, /** Fetch subtypes, only if current user is follower */ - fetch_subtypes: function (context) { + fetch_subtypes: function (partner_id) { var self = this; var mode = ""; - if (context && context.eval('partner_id')) { + if (partner_id) { mode = "edit_follower"; } else { var subtype_list_ul = this.$('.oe_subtype_list').empty(); if (! this.message_is_follower) return; } var id = this.view.datarecord.id; - this.ds_model.call('message_get_subscription_data', [[id],context]) + this.ds_model.call('message_get_subscription_data', [[id], partner_id, new session.web.CompoundContext(this.build_context(), {})]) .then(function (data) {self.display_subtypes(data, id, mode);}); }, @@ -307,23 +289,30 @@ openerp_mail_followers = function(session, mail) { return false; }, - do_update_subscription: function (event) { + do_update_subscription: function (event, partner_id) { var self = this; var checklist = new Array(); - _(this.$('.oe_actions input[type="checkbox"]')).each(function (record) { - if ($(record).is(':checked')) { - checklist.push(parseInt($(record).data('id'))); - } - }); - + if (partner_id) { + _($('.oe_edit_actions input[type="checkbox"]')).each(function (record) { + if ($(record).is(':checked')) { + checklist.push(parseInt($(record).data('id'))); + } + }); + } else { + _(this.$('.oe_actions input[type="checkbox"]')).each(function (record) { + if ($(record).is(':checked')) { + checklist.push(parseInt($(record).data('id'))); + } + }); + } if (!checklist.length) { if (!this.do_unfollow()) { $(event.target).attr("checked", "checked"); } } else { var context = new session.web.CompoundContext(this.build_context(), {}); - return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], checklist, context]) + return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], partner_id, checklist, context]) .then(this.proxy('read_value')); } },