[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.
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -44,7 +44,9 @@
|
||||
t-att-data-id="record.id"><t t-esc="record.name"/></a>
|
||||
<i t-if="record.is_editable and (widget.records_length > 1)"
|
||||
class="fa fa-pencil o_edit_subtype hide" title="Edit subscription"
|
||||
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"/>
|
||||
<i t-if="widget.view_is_editable" class="fa fa-remove o_remove_follower"
|
||||
title="Remove this follower"/>
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user