From e9065f77273a544c99b546bf58201ee9c08b4b73 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 21 Mar 2013 18:10:36 +0530 Subject: [PATCH] [IMP] Reduced code, deleted redundant code, deleted the edit template and used it in the existing by using 'mode' and improved code using the existing code and removed unwanted code. bzr revid: psa@tinyerp.com-20130321124036-0s4pv3oivzesmjh5 --- addons/mail/mail_thread.py | 31 ++--------- addons/mail/static/src/js/mail_followers.js | 53 +++++++++---------- addons/mail/static/src/xml/mail_followers.xml | 17 +----- 3 files changed, 32 insertions(+), 69 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index c901f6e64c2..2268e66ce36 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -126,6 +126,8 @@ class mail_thread(osv.AbstractModel): for id in ids: res[id]['message_subtype_data'] = subtype_dict.copy() + if context and 'partner_id' in context: + user_pid = context.get('partner_id') # find the document followers, update the data fol_obj = self.pool.get('mail.followers') fol_ids = fol_obj.search(cr, uid, [ @@ -138,6 +140,7 @@ class mail_thread(osv.AbstractModel): for subtype in fol.subtype_ids: thread_subtype_dict[subtype.name]['followed'] = True res[fol.res_id]['message_subtype_data'] = thread_subtype_dict + return res def _search_message_unread(self, cr, uid, obj=None, name=None, domain=None, context=None): @@ -289,34 +292,8 @@ class mail_thread(osv.AbstractModel): default['message_follower_ids'] = [] return super(mail_thread, self).copy(cr, uid, id, default=default, context=context) - #------------------------------------------------------ - # Edit and apply followers subtypes. - #------------------------------------------------------ - def edit_followers_subtype(self, cr, uid, ids, partner_id, context=None): - res = dict((id, dict(message_subtype_data='')) for id in ids) - - subtype_obj = self.pool.get('mail.message.subtype') - subtype_ids = subtype_obj.search(cr, uid, ['|', ('res_model', '=', self._name), ('res_model', '=', False)], context=context) - subtype_dict = dict((subtype.name, dict(default=subtype.default, followed=False, id=subtype.id)) for subtype in subtype_obj.browse(cr, uid, subtype_ids, context=context)) - for id in ids: - res[id]['message_subtype_data'] = subtype_dict.copy() - - 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) - for fol in fol_obj.browse(cr, uid, fol_ids, context=context): - thread_subtype_dict = res[fol.res_id]['message_subtype_data'] - for subtype in fol.subtype_ids: - thread_subtype_dict[subtype.name]['followed'] = True - res[fol.res_id]['message_subtype_data'] = thread_subtype_dict - return res - def apply_edited_subtypes(self, cr, uid, ids, partner_id, check_list, context=None): - """ Apply the edited subtypes - of the user.""" + """ 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), diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 1ca65087316..155cd74ebeb 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -81,37 +81,27 @@ openerp_mail_followers = function(session, mail) { on_edit_subtype: function(event) { var self = this; - var records = []; var partner_id = $(event.target).data('id'); - var partner_name = $(event.target).siblings('a').text(); - var id = this.view.datarecord.id; - var res_model = this.view.dataset.model; - var $dialog = new session.web.dialog($('
'), { + var context = new session.web.CompoundContext(this.build_context(), {'partner_id': partner_id}); + self.$dialog = new session.web.dialog($('
'), { modal: true, - title: _t('Edit Subtypes of ') + '"' + partner_name + '"', + width: 'auto', + height: 'auto', + title: _t('Edit Subscriptions of ') + $(event.target).siblings('a').text(), buttons: [ { text: _t("Apply"), click: function() { - self.on_apply_subtype(id, partner_id); + self.on_apply_subtype(partner_id); $(this).remove(); }}, { text: _t("Cancel"), click: function() { $(this).remove(); }} ], }); - this.ds_model.call('edit_followers_subtype', [[id], partner_id, new session.web.CompoundContext(this.build_context(), {})]) - .then(function (data) { - if (data[id]) { - records = data[id].message_subtype_data; - } - _(records).each(function (record, record_name) { - record.name = record_name; - record.followed = record.followed || undefined; - $(session.web.qweb.render("mail.followers.edit.subtype", {'record': record})).appendTo($dialog); - }); - }); + return self.fetch_subtypes(context); }, - on_apply_subtype: function(id, partner_id) { + 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'))); @@ -256,25 +246,34 @@ openerp_mail_followers = function(session, mail) { }, /** Fetch subtypes, only if current user is follower */ - fetch_subtypes: function () { + fetch_subtypes: function (context) { var self = this; - var subtype_list_ul = this.$('.oe_subtype_list').empty(); - if (! this.message_is_follower) return; + var mode = ""; + if (context && context.eval('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], new session.web.CompoundContext(this.build_context(), {})]) - .then(function (data) {self.display_subtypes(data, id);}); + this.ds_model.call('message_get_subscription_data', [[id],context]) + .then(function (data) {self.display_subtypes(data, id, mode);}); }, /** Display subtypes: {'name': default, followed} */ - display_subtypes:function (data, id) { + display_subtypes:function (data, id, mode) { var self = this; var $list = this.$('.oe_subtype_list'); - $list.empty().hide(); + if (mode.length == 0){ $list.empty().hide();} var records = data[this.view.datarecord.id || this.view.dataset.ids[0]].message_subtype_data; _(records).each(function (record, record_name) { record.name = record_name; record.followed = record.followed || undefined; - $(session.web.qweb.render('mail.followers.subtype', {'record': record})).appendTo( self.$('.oe_subtype_list') ); + if (mode.length == 0) { + $(session.web.qweb.render('mail.followers.subtype', {'record': record,'mode': mode})).appendTo( self.$('.oe_subtype_list') ); + } else { + $(session.web.qweb.render('mail.followers.subtype', {'record': record,'mode': mode})).appendTo(self.$dialog); + } }); if (_.size(records) > 1) { $list.show(); diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index ea11c26570b..6420046477c 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -42,21 +42,8 @@ - - - -
-
- - - - - - - + +