From 0b62a6858f52a6d2e3edfaabdb64a71d2e0686fa Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 14 Mar 2013 15:59:49 +0530 Subject: [PATCH] [IMP] 1) Added code for opening the dialog box of edit followers, 2) Added an image in the mail.message.subtype template which is visible when the Technical Features menu is selected true . 3) On clicking on the edit pencil which is with the followers name gives the subtypes of the specific followers on which the user had clicked rather than the current form. bzr revid: psa@tinyerp.com-20130314102949-4v9l6xpz5u1jeq10 --- addons/mail/mail_message_subtype.py | 1 - addons/mail/mail_message_subtype.xml | 15 +---- addons/mail/mail_thread.py | 49 ++++++++++++++- addons/mail/static/src/js/mail_followers.js | 59 +++++++++++++++++-- addons/mail/static/src/xml/mail_followers.xml | 3 +- 5 files changed, 106 insertions(+), 21 deletions(-) diff --git a/addons/mail/mail_message_subtype.py b/addons/mail/mail_message_subtype.py index bef6e427c3b..253ec600c6c 100644 --- a/addons/mail/mail_message_subtype.py +++ b/addons/mail/mail_message_subtype.py @@ -22,7 +22,6 @@ from openerp.osv import osv from openerp.osv import fields - class mail_message_subtype(osv.osv): """ Class holding subtype definition for messages. Subtypes allow to tune the follower subscription, allowing only some subtypes to be pushed diff --git a/addons/mail/mail_message_subtype.xml b/addons/mail/mail_message_subtype.xml index 91317003e78..a79f5815bd1 100644 --- a/addons/mail/mail_message_subtype.xml +++ b/addons/mail/mail_message_subtype.xml @@ -5,6 +5,7 @@ mail.message.subtype.tree mail.message.subtype + 10 @@ -33,25 +34,11 @@ - - - edit.message.subtype.tree - mail.message.subtype - 10 - - - - - - - - Subtypes mail.message.subtype form tree,form - diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 64b1410508d..2cec1557a55 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -138,9 +138,56 @@ 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 edit_followers_subtype(self, cr, uid, ids, partner_id, context=None): + print "cr, uid, ids, partner_id, co",cr, uid, ids, partner_id + 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) + print "\n\n fol _ids>>>>>>>>>>", fol_ids + 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 + print "\n<<<>>>",res + return res + + def apply_subtype(self, cr, uid, ids, partner_id, context=None): + print "\n\n uid, ids, subtype_id,", uid, ids, partner_id + res=[] + 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) + print "\n\n fol _ids>>>>>>>>>>", fol_ids + for fol in fol_obj.browse(cr, uid, fol_ids, context=context): + print "\fol.subtype::::>:>:>:>:>", fol.subtype_ids + for subtype in fol.subtype_ids: + res.append(subtype.id) + print "\nres::::>:>:>:>:>", res + if partner_id==True: + res.append(ids[0]) + else: + res.remove(ids[0]) + fol_obj.write(cr, uid, fol_ids, {'subtype_ids': [(6,0,res)]}, context=context) + print "\nsubtype_id......>>>", partner_id, res + return partner_id + + def _search_message_unread(self, cr, uid, obj=None, name=None, domain=None, context=None): return [('message_ids.to_read', '=', True)] diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 5c6d3bc3347..031aeddb7d7 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -80,22 +80,72 @@ openerp_mail_followers = function(session, mail) { this.$el.on('click', '.oe_show_more', self.on_show_more_followers) }, - on_edit_subtype: function() { + on_edit_subtype: function(event) { var self = this; + var records = []; + var partner_id = $(event.target).data('id'); + var id = this.view.datarecord.id; + var res_model = this.view.dataset.model; + console.log('thissssssssssssssss>>', this, id, partner_id); + var $dialog = session.web.dialog($('
'), { + modal: true, + title: partner_id, + buttons: [ + {text: _t("Apply"), click: function() { + // self.apply_subtype(id, partner_id); + $(this).dialog("close"); + } + }, + {text: _t("Cancel"), click: function() { $(this).dialog("close"); }} + ], + }); + this.ds_model.call('edit_followers_subtype', [[id], [partner_id], new session.web.CompoundContext(this.build_context(), {})]) + .then(function (data) { + // console.log('then>>>>>', data, id, partner_id); + if (data[id]) { + records = data[id].message_subtype_data; + // console.log('records........', records); + } + _(records).each(function (record, record_name) { + record.name = record_name; + record.followed = record.followed || undefined; + console.log('record??????????????', record); + $(session.web.qweb.render("mail.followers.subtype", {'record': record})).appendTo($dialog); + }); + }); + + /* var partner_id = $(event.target).data('id'); + var context = new session.web.CompoundContext(this.build_context(), {}); + var action = { type: 'ir.actions.act_window', - res_model: 'mail.message.subtype', + res_model: 'mail.message.subtype', //'subtype.edit.wizard', domain: [['res_model','=', self.view.model]], view_mode: 'list', view_type: 'list', views: [[false, 'list']], target: 'new', + context: { + 'res_model': this.view.dataset.model, + 'res_id': this.view.datarecord.id, + 'partner_id': partner_id, + }, } + this.do_action(action, { on_close: function() { self.read_value(); }, - }); + });*/ + + }, + + apply_subtype: function(id, partner_id) { + console.log('id>>>partner_id>>> ', id, partner_id); + this.ds_model.call('apply_subtype', [[id], [partner_id], new session.web.CompoundContext(this.build_context(), {})]) + .then(function (data) { + console.log('dataaaaaaaaaaaaa', data); + }); }, on_invite_follower: function (event) { @@ -154,7 +204,7 @@ openerp_mail_followers = function(session, mail) { .then(this.proxy('check_group_tech_feature')); }, - check_group_tech_feature: function(){ + check_group_tech_feature: function() { var self = this; var edit_subtypes = new session.web.Model("res.groups"); edit_subtypes.query(["name","users"]) @@ -276,6 +326,7 @@ openerp_mail_followers = function(session, mail) { .then(this.proxy('read_value')); _.each(this.$('.oe_subtype_list input'), function (record) { + console.log('do follow>', record); $(record).attr('checked', 'checked'); }); }, diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 18404c4ec05..7721b1beb22 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -32,7 +32,8 @@
- + + X