From 762cc2dbfa02c1a4afe7c6a200917cc41054aa79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Wed, 9 Sep 2015 15:35:37 +0200 Subject: [PATCH] [FIX] mail : make follower subtype edition works On follower list of a document, the user can (if access rights granted) edit the subtype subscription of other follower. This open a modal with checkboxes. This is commit make this feature works and adapt it to channel follower. --- addons/mail/controllers/main.py | 17 ++++++----- addons/mail/static/src/js/mail_followers.js | 28 +++++++++++-------- addons/mail/static/src/xml/mail_followers.xml | 4 ++- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/addons/mail/controllers/main.py b/addons/mail/controllers/main.py index edde14ffb6e..781ada93edc 100644 --- a/addons/mail/controllers/main.py +++ b/addons/mail/controllers/main.py @@ -49,16 +49,20 @@ class MailController(http.Controller): return result @http.route('/mail/read_subscription_data', type='json', auth='user') - def read_subscription_data(self, res_model, res_id): + def read_subscription_data(self, res_model, res_id, follower_id=None): """ Computes: - message_subtype_data: data about document subtypes: which are available, which are followed if any """ # find the document followers, update the data - followers = request.env['mail.followers'].search([ - ('partner_id', '=', request.env.user.partner_id.id), - ('res_id', '=', res_id), - ('res_model', '=', res_model), - ]) + followers = request.env['mail.followers'] + if not follower_id: + followers = followers.search([ + ('partner_id', '=', request.env.user.partner_id.id), + ('res_id', '=', res_id), + ('res_model', '=', res_model), + ]) + else: + followers = followers.browse(follower_id) # find current model subtypes, add them to a dictionary subtypes = request.env['mail.message.subtype'].search(['&', ('hidden', '=', False), '|', ('res_model', '=', res_model), ('res_model', '=', False)]) @@ -73,7 +77,6 @@ class MailController(http.Controller): 'id': subtype.id } for subtype in subtypes] subtypes_list = sorted(subtypes_list, key=itemgetter('parent_model', 'res_model', 'internal', 'sequence')) - return subtypes_list @http.route('/mail/view', type='http', auth='none') diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 3e83831b478..8e09d1116c4 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -112,7 +112,8 @@ var Followers = form_common.AbstractField.extend({ on_edit_subtype: function(event) { var self = this; var $currentTarget = $(event.currentTarget); - var user_pid = $currentTarget.data('id'); + var user_pid = $currentTarget.data('res-id'); + var follower_id = $currentTarget.data('id'); self.dialog = new Dialog(this, { size: 'small', title: _t('Edit Subscription of ') + $currentTarget.siblings('a').text(), @@ -130,7 +131,7 @@ var Followers = form_common.AbstractField.extend({ }, ], }).open(); - return self.fetch_subtypes(user_pid); + return self.fetch_subtypes(follower_id); }, on_invite_follower: function (channel_only) { @@ -277,11 +278,11 @@ var Followers = form_common.AbstractField.extend({ }, /** Fetch subtypes, only if current user is follower */ - fetch_subtypes: function (user_pid) { + fetch_subtypes: function (follower_id) { var self = this; var dialog = false; - if (user_pid) { + if (follower_id) { dialog = true; } else { @@ -295,7 +296,7 @@ var Followers = form_common.AbstractField.extend({ } } if (this.follower_id) { - return ajax.jsonRpc('/mail/read_subscription_data', 'call', {'res_model': this.view.model, 'res_id': this.view.datarecord.id}) + return ajax.jsonRpc('/mail/read_subscription_data', 'call', {'res_model': this.view.model, 'res_id': this.view.datarecord.id, 'follower_id': follower_id}) .then(function (data) { self.display_subtypes(data, dialog); }); } else { return $.Deferred().resolve(); @@ -381,35 +382,38 @@ var Followers = form_common.AbstractField.extend({ var self = this; this.data_subtype = {}; + var kwargs = {}; var action_subscribe = 'message_subscribe_users'; - var follower_ids = [session.uid]; var subtypes = this.$('.o_followers_actions input[type="checkbox"]'); // Subtypes edited from the modal if (user_pid) { action_subscribe = 'message_subscribe'; - follower_ids = [user_pid]; subtypes = this.dialog.$('input[type="checkbox"]'); + kwargs['partner_ids'] = [user_pid]; + }else{ + kwargs['user_ids'] = [session.uid]; } + // Get the subtype ids var checklist = []; _(subtypes).each(function (record) { if ($(record).is(':checked')) { checklist.push(parseInt($(record).data('id'))); } }); + kwargs['subtype_ids'] = checklist; + // If no more subtype followed, unsubscribe the partner. if (!checklist.length) { if (!this.do_unfollow(undefined, [user_pid], undefined)) { $(event.target).attr("checked", "checked"); } else { self.$('.o_subtypes_list ul').empty(); } - } - else { - var context = new data.CompoundContext(this.build_context(), {}); - return this.ds_model.call(action_subscribe, [[this.view.datarecord.id], follower_ids, undefined, checklist, context]) - .then(this.proxy('read_value')); + } else { + kwargs['context'] = new data.CompoundContext(this.build_context(), {}); + return this.ds_model._model.call(action_subscribe, [[this.view.datarecord.id]], kwargs).then(this.proxy('read_value')); } }, }); diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 6370715695a..c25d3954bb1 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -44,7 +44,9 @@ t-att-data-id="record.id"> + t-att-data-id="record.id" + t-att-data-res-model="record.res_model" + t-att-data-res-id="record.res_id"/>