From 73cf8d29f9209c8adfcbed97248f6bcaaa220f41 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Tue, 5 Mar 2013 18:24:42 +0530 Subject: [PATCH 01/38] [IMP] Added EDIT button in message_followers template for editing the subtypes of the users. bzr revid: psa@tinyerp.com-20130305125442-z8h470slga4d77ll --- addons/mail/mail_message_subtype.xml | 15 ++++++++++++++- addons/mail/static/src/css/mail.css | 6 ++++++ addons/mail/static/src/js/mail_followers.js | 19 +++++++++++++++++++ addons/mail/static/src/xml/mail_followers.xml | 1 + 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/addons/mail/mail_message_subtype.xml b/addons/mail/mail_message_subtype.xml index a79f5815bd1..156c366af30 100644 --- a/addons/mail/mail_message_subtype.xml +++ b/addons/mail/mail_message_subtype.xml @@ -5,7 +5,6 @@ mail.message.subtype.tree mail.message.subtype - 10 @@ -34,11 +33,25 @@ + + + edit.message.subtype.tree + mail.message.subtype + 9 + + + + + + + + Subtypes mail.message.subtype form tree,form + diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index e4e112cdfaf..3ed2482911c 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -617,6 +617,12 @@ right: 0px; line-height: 20px; } +.openerp .oe_followers .oe_edit_subtype{ + cursor: pointer; + line-height: 26px; + position: absolute; + right: 12px; +} .openerp .oe_followers .oe_show_more{ cursor: pointer; diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 41634fd2135..ba776995d5b 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -74,10 +74,29 @@ openerp_mail_followers = function(session, mail) { this.$el.on('click', '.oe_subtype_list input', self.do_update_subscription); // event: click on 'invite' button, that opens the invite wizard this.$('.oe_invite').on('click', self.on_invite_follower); + this.$el.on('click', '.oe_edit_subtype', self.on_edit_subtype); this.$el.on('click', '.oe_remove_follower', self.on_remove_follower); this.$el.on('click', '.oe_show_more', self.on_show_more_followers) }, + on_edit_subtype: function() { + var self = this; + var action = { + type: 'ir.actions.act_window', + res_model: 'mail.message.subtype', + domain: [['res_model','=', self.view.model]], + view_mode: 'list', + view_type: 'list', + views: [[false, 'list']], + target: 'new', + } + this.do_action(action, { + on_close: function() { + self.read_value(); + }, + }); + }, + on_invite_follower: function (event) { var self = this; var action = { diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 459f13155a0..c22d253b1f7 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -32,6 +32,7 @@
+ Edit X
From 7c5ddd2de0ead278c488fb380992a7a344b4c916 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Wed, 6 Mar 2013 16:48:54 +0530 Subject: [PATCH 02/38] [IMP]Placed edit image in place of edit link and improved css. bzr revid: psa@tinyerp.com-20130306111854-d95kiof2o4apc8ns --- addons/mail/mail_message_subtype.xml | 2 +- addons/mail/static/src/css/mail.css | 4 +++- addons/mail/static/src/img/icon-edit.gif | Bin 0 -> 129 bytes addons/mail/static/src/xml/mail_followers.xml | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 addons/mail/static/src/img/icon-edit.gif diff --git a/addons/mail/mail_message_subtype.xml b/addons/mail/mail_message_subtype.xml index 156c366af30..91317003e78 100644 --- a/addons/mail/mail_message_subtype.xml +++ b/addons/mail/mail_message_subtype.xml @@ -37,7 +37,7 @@ edit.message.subtype.tree mail.message.subtype - 9 + 10 diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 3ed2482911c..8056c95ecb3 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -619,9 +619,11 @@ } .openerp .oe_followers .oe_edit_subtype{ cursor: pointer; - line-height: 26px; position: absolute; right: 12px; + margin-top: 6px; + width: 10px !important; + height: 12px !important; } .openerp .oe_followers .oe_show_more{ diff --git a/addons/mail/static/src/img/icon-edit.gif b/addons/mail/static/src/img/icon-edit.gif new file mode 100644 index 0000000000000000000000000000000000000000..6e9aa5ef6599bb02e966d34994cc9f42a126ea5f GIT binary patch literal 129 zcmZ?wbhEHb - Edit + X From 14317130c38bb254de5398c40847d293b9f51b32 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 8 Mar 2013 12:50:39 +0530 Subject: [PATCH 03/38] [IMP] added method for checking the group technical features is added or not. bzr revid: psa@tinyerp.com-20130308072039-6iau8anuckonc6ps --- addons/mail/static/src/js/mail_followers.js | 16 +++++++++++++++- addons/mail/static/src/xml/mail_followers.xml | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index ba776995d5b..5c6d3bc3347 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -31,6 +31,7 @@ openerp_mail_followers = function(session, mail) { this.ds_model = new session.web.DataSetSearch(this, this.view.model); this.ds_follow = new session.web.DataSetSearch(this, this.field.relation); this.ds_users = new session.web.DataSetSearch(this, 'res.users'); + this.check_access = false; this.value = []; this.followers = []; @@ -149,7 +150,20 @@ openerp_mail_followers = function(session, mail) { return this.ds_follow.call('read', [this.value, ['name', 'user_ids']]) .then(this.proxy('display_followers'), this.proxy('fetch_generic')) .then(this.proxy('display_buttons')) - .then(this.proxy('fetch_subtypes')); + .then(this.proxy('fetch_subtypes')) + .then(this.proxy('check_group_tech_feature')); + }, + + check_group_tech_feature: function(){ + var self = this; + var edit_subtypes = new session.web.Model("res.groups"); + edit_subtypes.query(["name","users"]) + .filter([["name","=","Technical Features"], ["users","in",self.session.uid]]).first() + .then(function(res) { + if (res) { + self.check_access = true; + } + }); }, /** Read on res.partner failed: fall back on a generic case diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 1e88deb7960..18404c4ec05 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -32,7 +32,7 @@
- + X
From 0b62a6858f52a6d2e3edfaabdb64a71d2e0686fa Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 14 Mar 2013 15:59:49 +0530 Subject: [PATCH 04/38] [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
From f242c87c7e182dbe011bedb74b0fbfdecf89336a Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 14 Mar 2013 19:11:22 +0530 Subject: [PATCH 05/38] [IMP] Now partner name is displayed as per the record and added a new template. bzr revid: psa@tinyerp.com-20130314134122-gedt3b9eq5kolnlt --- addons/mail/static/src/js/mail_followers.js | 7 +++---- addons/mail/static/src/xml/mail_followers.xml | 9 +++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 031aeddb7d7..41f227b5881 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -84,12 +84,12 @@ openerp_mail_followers = function(session, mail) { 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; - console.log('thissssssssssssssss>>', this, id, partner_id); var $dialog = session.web.dialog($('
'), { modal: true, - title: partner_id, + title: _t('Edit Subtypes of ') + '"' + partner_name + '"', buttons: [ {text: _t("Apply"), click: function() { // self.apply_subtype(id, partner_id); @@ -109,8 +109,7 @@ openerp_mail_followers = function(session, mail) { _(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); + $(session.web.qweb.render("mail.followers.edit.subtype", {'record': record})).appendTo($dialog); }); }); diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 7721b1beb22..071205803bb 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -50,6 +50,15 @@ + + + + + + +
+
+
And more.
From 90868a808903c8f5812a4243092a448752f25100 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 15 Mar 2013 14:22:45 +0530 Subject: [PATCH 06/38] [IMP] Add method for the apply button when the user click on the apply button of the dialog box the data will be updated Removed unwanted code and clean the code. bzr revid: psa@tinyerp.com-20130315085245-uhefj63na5z62of5 --- addons/mail/mail_thread.py | 26 ++------ addons/mail/static/src/js/mail_followers.js | 64 ++++++------------- addons/mail/static/src/xml/mail_followers.xml | 5 +- 3 files changed, 29 insertions(+), 66 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 2cec1557a55..d85e91fa8ba 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -141,8 +141,8 @@ class mail_thread(osv.AbstractModel): 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)) @@ -155,38 +155,24 @@ class mail_thread(osv.AbstractModel): ('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=[] + 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) - 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 - + fol_obj.write(cr, uid, fol_ids, {'subtype_ids': [(6, 0, check_list)]}, context=context) + return True 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 41f227b5881..0eb864d02da 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -87,24 +87,21 @@ openerp_mail_followers = function(session, mail) { var partner_name = $(event.target).siblings('a').text(); var id = this.view.datarecord.id; var res_model = this.view.dataset.model; - var $dialog = session.web.dialog($('
'), { + var $dialog = session.web.dialog($('
'), { modal: true, title: _t('Edit Subtypes of ') + '"' + partner_name + '"', buttons: [ - {text: _t("Apply"), click: function() { - // self.apply_subtype(id, partner_id); - $(this).dialog("close"); - } - }, - {text: _t("Cancel"), click: function() { $(this).dialog("close"); }} + { text: _t("Apply"), click: function() { + self.on_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(), {})]) + 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; @@ -112,39 +109,21 @@ openerp_mail_followers = function(session, mail) { $(session.web.qweb.render("mail.followers.edit.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', //'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_apply_subtype: function(id, partner_id) { + var checklist = new Array(); + _($('.oe_edit_actions input[type="checkbox"]')).each(function (record) { + if ($(record).is(':checked')) { + checklist.push(parseInt($(record).data('id'))); + } + }); + if (!checklist.length) { + this.do_unfollow(); + } else { + this.ds_model.call('apply_edited_subtypes', [[id], partner_id, checklist, new session.web.CompoundContext(this.build_context(), {})]) + .then(this.proxy('read_value')); + } }, on_invite_follower: function (event) { @@ -325,7 +304,6 @@ 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 071205803bb..7a615044af1 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -32,8 +32,7 @@
- - + X
@@ -53,7 +52,7 @@ - +
From b5df63291a0de2cbcd42a348db5ffa925f8e4efc Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 15 Mar 2013 18:01:57 +0530 Subject: [PATCH 07/38] [IMP] Removed the dialog box on apply and close to open a new dialog box everytime. Removed unwanted code. bzr revid: psa@tinyerp.com-20130315123157-n0n3fdej014ysz7v --- addons/mail/mail_message_subtype.py | 1 + addons/mail/mail_thread.py | 6 ++-- addons/mail/static/src/js/mail_followers.js | 37 +++++++-------------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/addons/mail/mail_message_subtype.py b/addons/mail/mail_message_subtype.py index 253ec600c6c..bef6e427c3b 100644 --- a/addons/mail/mail_message_subtype.py +++ b/addons/mail/mail_message_subtype.py @@ -22,6 +22,7 @@ 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_thread.py b/addons/mail/mail_thread.py index d85e91fa8ba..ab4eead1a6e 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -162,7 +162,8 @@ class mail_thread(osv.AbstractModel): 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): + def apply_edited_subtypes(self, cr, uid, ids, partner_id, check_list, context=None): + print "\n\n uid, ids, partner_id, check_list,,>", uid, ids, partner_id, check_list, """ Apply the edited subtypes of the user.""" fol_obj = self.pool.get('mail.followers') @@ -171,7 +172,8 @@ class mail_thread(osv.AbstractModel): ('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) + print "\n fol _ids>", fol_ids, check_list + fol_obj.write(cr, uid, fol_ids, {'subtype_ids': [(6,0, check_list)]}, context=context) return True def _search_message_unread(self, cr, uid, obj=None, name=None, domain=None, context=None): diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 0eb864d02da..0bfcbfc29e9 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -31,7 +31,6 @@ openerp_mail_followers = function(session, mail) { this.ds_model = new session.web.DataSetSearch(this, this.view.model); this.ds_follow = new session.web.DataSetSearch(this, this.field.relation); this.ds_users = new session.web.DataSetSearch(this, 'res.users'); - this.check_access = false; this.value = []; this.followers = []; @@ -87,15 +86,15 @@ openerp_mail_followers = function(session, mail) { var partner_name = $(event.target).siblings('a').text(); var id = this.view.datarecord.id; var res_model = this.view.dataset.model; - var $dialog = session.web.dialog($('
'), { + var $dialog = new session.web.dialog($('
'), { modal: true, title: _t('Edit Subtypes of ') + '"' + partner_name + '"', buttons: [ { text: _t("Apply"), click: function() { self.on_apply_subtype(id, partner_id); - $(this).dialog("close"); + $dialog.remove(); }}, - { text: _t("Cancel"), click: function() { $(this).dialog("close"); }} + { text: _t("Cancel"), click: function() { $dialog.remove(); }} ], }); this.ds_model.call('edit_followers_subtype', [[id], partner_id, new session.web.CompoundContext(this.build_context(), {})]) @@ -112,16 +111,17 @@ openerp_mail_followers = function(session, mail) { }, on_apply_subtype: function(id, partner_id) { - var checklist = new Array(); - _($('.oe_edit_actions input[type="checkbox"]')).each(function (record) { - if ($(record).is(':checked')) { - checklist.push(parseInt($(record).data('id'))); - } + var check_list = new Array(); + _($('.oe_edit_actions input[type="checkbox"]')).each(function (records) { + if ($(records).is(':checked')) { + check_list.push(parseInt($(records).data('id'))); + } }); - if (!checklist.length) { + + if (!check_list.length) { this.do_unfollow(); } else { - this.ds_model.call('apply_edited_subtypes', [[id], partner_id, checklist, new session.web.CompoundContext(this.build_context(), {})]) + 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')); } }, @@ -178,20 +178,7 @@ openerp_mail_followers = function(session, mail) { return this.ds_follow.call('read', [this.value, ['name', 'user_ids']]) .then(this.proxy('display_followers'), this.proxy('fetch_generic')) .then(this.proxy('display_buttons')) - .then(this.proxy('fetch_subtypes')) - .then(this.proxy('check_group_tech_feature')); - }, - - check_group_tech_feature: function() { - var self = this; - var edit_subtypes = new session.web.Model("res.groups"); - edit_subtypes.query(["name","users"]) - .filter([["name","=","Technical Features"], ["users","in",self.session.uid]]).first() - .then(function(res) { - if (res) { - self.check_access = true; - } - }); + .then(this.proxy('fetch_subtypes')); }, /** Read on res.partner failed: fall back on a generic case From 0abe605544641bb0788f6b84f8df76603dd90b93 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 15 Mar 2013 18:18:43 +0530 Subject: [PATCH 08/38] [IMP] Oops sorry forgot to remove the prints and improved code. bzr revid: psa@tinyerp.com-20130315124843-xtp19rbm2cvyfb67 --- addons/mail/mail_thread.py | 2 -- addons/mail/static/src/js/mail_followers.js | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index ab4eead1a6e..720afd7fd8f 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -163,7 +163,6 @@ class mail_thread(osv.AbstractModel): return res def apply_edited_subtypes(self, cr, uid, ids, partner_id, check_list, context=None): - print "\n\n uid, ids, partner_id, check_list,,>", uid, ids, partner_id, check_list, """ Apply the edited subtypes of the user.""" fol_obj = self.pool.get('mail.followers') @@ -172,7 +171,6 @@ class mail_thread(osv.AbstractModel): ('res_id', 'in', ids), ('res_model', '=', self._name), ], context=context) - print "\n fol _ids>", fol_ids, check_list fol_obj.write(cr, uid, fol_ids, {'subtype_ids': [(6,0, check_list)]}, context=context) return True diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 0bfcbfc29e9..b778f3bb6b2 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -112,9 +112,9 @@ openerp_mail_followers = function(session, mail) { on_apply_subtype: function(id, partner_id) { var check_list = new Array(); - _($('.oe_edit_actions input[type="checkbox"]')).each(function (records) { - if ($(records).is(':checked')) { - check_list.push(parseInt($(records).data('id'))); + _($('.oe_edit_actions input[type="checkbox"]')).each(function (record) { + if ($(record).is(':checked')) { + check_list.push(parseInt($(record).data('id'))); } }); From cf3415f0877affc7f26ad16cd6a47ba671a9d601 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Tue, 19 Mar 2013 13:03:19 +0530 Subject: [PATCH 09/38] [IMP]Changed the position of methods and improved code. bzr revid: psa@tinyerp.com-20130319073319-8myj2hx5iaqmi5xj --- addons/mail/mail_thread.py | 71 ++++++++++--------- addons/mail/static/src/js/mail_followers.js | 4 +- addons/mail/static/src/xml/mail_followers.xml | 4 ++ 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 6ead2c9202b..ddbbf8a689b 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -140,40 +140,6 @@ class mail_thread(osv.AbstractModel): res[fol.res_id]['message_subtype_data'] = thread_subtype_dict return res - 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.""" - 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 - def _search_message_unread(self, cr, uid, obj=None, name=None, domain=None, context=None): return [('message_ids.to_read', '=', True)] @@ -323,6 +289,43 @@ 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.""" + 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 #------------------------------------------------------ diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 9a9f5f2ba54..1ca65087316 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -92,9 +92,9 @@ openerp_mail_followers = function(session, mail) { buttons: [ { text: _t("Apply"), click: function() { self.on_apply_subtype(id, partner_id); - $dialog.remove(); + $(this).remove(); }}, - { text: _t("Cancel"), click: function() { $dialog.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(), {})]) diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 4a492cee713..ea11c26570b 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -48,6 +48,10 @@ + From e9065f77273a544c99b546bf58201ee9c08b4b73 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 21 Mar 2013 18:10:36 +0530 Subject: [PATCH 10/38] [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 @@
- - - -
-
- - - - - - - + +
From e627fce6b8a3b9db56967a7b8d93b24a9bdc45f5 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 21 Mar 2013 18:18:59 +0530 Subject: [PATCH 11/38] [IMP] Little improvement with context(context is None:). bzr revid: psa@tinyerp.com-20130321124859-281pcjosai1xtvaj --- addons/mail/mail_thread.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 2268e66ce36..c8086a8db76 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -116,6 +116,8 @@ class mail_thread(osv.AbstractModel): """ 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] @@ -126,7 +128,7 @@ class mail_thread(osv.AbstractModel): for id in ids: res[id]['message_subtype_data'] = subtype_dict.copy() - if context and 'partner_id' in context: + if 'partner_id' in context: user_pid = context.get('partner_id') # find the document followers, update the data fol_obj = self.pool.get('mail.followers') From f1db1ed7783b664ac3b6cceb085edfdddb7b8ee2 Mon Sep 17 00:00:00 2001 From: "Vishmita Jadeja (openerp)" Date: Fri, 22 Mar 2013 13:52:06 +0530 Subject: [PATCH 12/38] [IMP]Add method for checking the group technical features. bzr revid: vja@tinyerp.com-20130322082206-x2490850o8qbkmk0 --- addons/mail/mail_thread.py | 7 +++++++ addons/mail/static/src/js/mail_followers.js | 9 +++++++-- addons/mail/static/src/xml/mail_followers.xml | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index c8086a8db76..f25d58c90e6 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -112,6 +112,13 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res + def check_access_right(self, cr, uid,ids , context=None ): + grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one') + user_pid = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users'] + if uid in user_pid: + return True + return False + def _get_subscription_data(self, cr, uid, ids, name, args, context=None): """ Computes: - message_subtype_data: data about document subtypes: which are diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 155cd74ebeb..c615ceb35e5 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -210,14 +210,19 @@ openerp_mail_followers = function(session, mail) { var self = this; this.followers = records || this.followers; this.message_is_follower = this.set_is_follower(this.followers); + this.check_access = false; + // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); _(truncated).each(function (record) { - record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); - $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); + self.ds_model.call('check_access_right', [self.session.uid]).then(function(r){ + self.check_access = r; + record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); + $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); + }) }); // FVA note: be sure it is correctly translated if (truncated.length < this.followers.length) { diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 6420046477c..bdcfd1e048c 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -31,7 +31,8 @@
- + console.log("dsfsdfd",d) + X
From bd6a436bbb04b8121e58ad8b547ba8d7c67c3584 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 22 Mar 2013 14:40:26 +0530 Subject: [PATCH 13/38] [IMP] Added css for the ' Close(X)' icon of the dialog box when the title size increases than overlap the title. bzr revid: psa@tinyerp.com-20130322091026-m0eqoqnt1t2p184v --- addons/mail/mail_thread.py | 2 +- addons/mail/static/src/css/mail.css | 4 +++- addons/mail/static/src/js/mail_followers.js | 4 ++-- addons/mail/static/src/xml/mail_followers.xml | 1 - 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index f25d58c90e6..14d13ab7094 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -112,7 +112,7 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res - def check_access_right(self, cr, uid,ids , context=None ): + def check_access_right(self, cr, uid, ids, context=None): grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one') user_pid = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users'] if uid in user_pid: diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 6d7d8875601..9805c9d3a61 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -646,7 +646,9 @@ width: 10px !important; height: 12px !important; } - +.openerp.ui-dialog .ui-dialog-titlebar .ui-dialog-title{ + padding-right: 20px; +} .openerp .oe_followers .oe_show_more{ cursor: pointer; } diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index c615ceb35e5..7e49a391bca 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -218,8 +218,8 @@ openerp_mail_followers = function(session, mail) { // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); _(truncated).each(function (record) { - self.ds_model.call('check_access_right', [self.session.uid]).then(function(r){ - self.check_access = r; + self.ds_model.call('check_access_right', [self.session.uid]).then(function(result){ + self.check_access = result; record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); }) diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index bdcfd1e048c..081111a9afd 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -31,7 +31,6 @@
- console.log("dsfsdfd",d) X
From b32cc3b4427c6d59581da13d039bde931ce82a5c Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 4 Apr 2013 12:37:23 +0530 Subject: [PATCH 14/38] [IMP] Improved code 1) Edit Subscriptions of -> Edit Subscription (without 's') of 2) Instead of defining a new 'apply_edited_subtype', you can use 'message_subscribe' that has an optional 'subtype_ids' parameter that already allows to manage subtypes of a subscription. 3) In _get_subscription_data: do not use context when it is not necessary. Please add a parameter user_id=None that will be used instead of uid to find user_pid. 4) Instead of defining a new 'on_apply_subtype', can't you reuse 'do_update_subscription' with maybe some update to handle the classic use / edit widget ? The above changes has been done. bzr revid: psa@tinyerp.com-20130404070723-5v1v35fte6vl2b2j --- addons/mail/mail_thread.py | 31 ++++-------- addons/mail/static/src/js/mail_followers.js | 55 +++++++++------------ 2 files changed, 32 insertions(+), 54 deletions(-) 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')); } }, From 9a2a45c768b77fb829582f060221a90340445da1 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 4 Apr 2013 14:17:24 +0530 Subject: [PATCH 15/38] [IMP] Improved code and removed unwanted code. As suggested by tde in his comment >> **What's the purpose of defining a new 'check_access_right' ? Limiting to 'group_no_one' does not seems a viable solution. Instead, access rights on mail.followers entries should be correctly written (please check it is the case). I think having an asynchronous call just to check access rights is not necessary. In debug mode, always display the button.** bzr revid: psa@tinyerp.com-20130404084724-meqsx35jdvk56z2c --- addons/mail/mail_thread.py | 7 ------- addons/mail/static/src/js/mail_followers.js | 9 ++------- addons/mail/static/src/xml/mail_followers.xml | 2 +- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 63f5b8316df..528fd412e46 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -112,13 +112,6 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res - def check_access_right(self, cr, uid, ids, context=None): - grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one') - user_pid = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users'] - if uid in user_pid: - return True - return False - def _get_subscription_data(self, cr, uid, ids, user_id, name, args, context=None): """ Computes: - message_subtype_data: data about document subtypes: which are diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index bc15eed3fd9..02cf01d9889 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -192,19 +192,14 @@ openerp_mail_followers = function(session, mail) { var self = this; this.followers = records || this.followers; this.message_is_follower = this.set_is_follower(this.followers); - this.check_access = false; - // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); _(truncated).each(function (record) { - self.ds_model.call('check_access_right', [self.session.uid]).then(function(result){ - self.check_access = result; - record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); - $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); - }) + record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); + $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); }); // FVA note: be sure it is correctly translated if (truncated.length < this.followers.length) { diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 081111a9afd..960c399ecce 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -31,7 +31,7 @@
- + X
From 7e2e37b7c9ab314c5a45f99547b1a22be58eede8 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 4 Apr 2013 15:25:28 +0530 Subject: [PATCH 16/38] [IMP] Added *None* where message_subscribe is used. bzr revid: psa@tinyerp.com-20130404095528-l58jnpxiw8l5nuqf --- addons/mail/mail_group.py | 2 +- addons/mail/mail_thread.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index 24aed942b1b..bb66c909ad6 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -111,7 +111,7 @@ class mail_group(osv.Model): partner_ids = [] for group in mail_group.group_ids: partner_ids += [user.partner_id.id for user in group.users] - self.message_subscribe(cr, uid, ids, partner_ids, context=context) + self.message_subscribe(cr, uid, ids, partner_ids, None, context=context) def create(self, cr, uid, vals, context=None): mail_alias = self.pool.get('mail.alias') diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 528fd412e46..aff451a9935 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -1206,7 +1206,7 @@ class mail_thread(osv.AbstractModel): for pid, subtypes in new_followers.items(): subtypes = list(subtypes) if subtypes is not None else None - self.message_subscribe(cr, uid, [record.id], [pid], subtypes, context=context) + self.message_subscribe(cr, uid, [record.id], [pid], None, subtypes, context=context) # find first email message, set it as unread for auto_subscribe fields for them to have a notification if user_id_partner_ids: From e61d6bae165444015ef37f71ae1e3c13f42ec253 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 5 Apr 2013 19:14:25 +0530 Subject: [PATCH 17/38] [IMP] Improved code and passed user_id=None as optional field. bzr revid: psa@tinyerp.com-20130405134425-3xfbbv3vapq1un68 --- addons/mail/mail_thread.py | 10 ++++----- addons/mail/static/src/js/mail_followers.js | 24 +++++++++------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 2527b4cf035..aa929083374 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -112,7 +112,7 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res - def _get_subscription_data(self, cr, uid, ids, user_id, name, args, context=None): + def _get_subscription_data(self, cr, uid, ids, name, args, user_id=None, context=None): """ Computes: - message_subtype_data: data about document subtypes: which are available, which are followed if any """ @@ -1105,17 +1105,17 @@ class mail_thread(osv.AbstractModel): 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, user_id, None, None, context=context) + return self._get_subscription_data(cr, uid, ids, None, None, user_id=user_id, context=context) - def message_subscribe_users(self, cr, uid, ids, user_ids=None, partner_id=None, subtype_ids=None, context=None): + def message_subscribe_users(self, cr, uid, ids, user_ids=None, subtype_ids=None, user_id=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, partner_id, subtype_ids=subtype_ids, context=context) + return self.message_subscribe(cr, uid, ids, partner_ids, subtype_ids=subtype_ids, user_id=user_id, context=context) - def message_subscribe(self, cr, uid, ids, partner_ids, user_id, subtype_ids=None, context=None): + def message_subscribe(self, cr, uid, ids, partner_ids, subtype_ids=None, user_id=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: diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 02cf01d9889..83b46f9f951 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -264,7 +264,7 @@ openerp_mail_followers = function(session, mail) { do_follow: function () { var context = new session.web.CompoundContext(this.build_context(), {}); - this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, context]) + this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, undefined, context]) .then(this.proxy('read_value')); _.each(this.$('.oe_subtype_list input'), function (record) { @@ -288,19 +288,15 @@ openerp_mail_followers = function(session, mail) { var self = this; var checklist = new Array(); - 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'))); - } - }); - } + var subtype_checkbox = _(this.$('.oe_actions input[type="checkbox"]')) + if (partner_id) { + subtype_checkbox = _($('.oe_edit_actions input[type="checkbox"]')) + } + subtype_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"); From 1769067ddd9b4b7b51ae4c0d430587e1287af22d Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Tue, 9 Apr 2013 10:09:32 +0530 Subject: [PATCH 18/38] [IMP] Improved code and removed unwanted 'None'. bzr revid: psa@tinyerp.com-20130409043932-z5c8hupbhrednwa0 --- addons/mail/mail_group.py | 2 +- addons/mail/mail_thread.py | 2 +- addons/mail/static/src/js/mail_followers.js | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index 93f363a740e..977608f487e 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -111,7 +111,7 @@ class mail_group(osv.Model): partner_ids = [] for group in mail_group.group_ids: partner_ids += [user.partner_id.id for user in group.users] - self.message_subscribe(cr, uid, ids, partner_ids, None, context=context) + self.message_subscribe(cr, uid, ids, partner_ids, context=context) def create(self, cr, uid, vals, context=None): mail_alias = self.pool.get('mail.alias') diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index aa929083374..01fb561ebf3 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -1227,7 +1227,7 @@ class mail_thread(osv.AbstractModel): for pid, subtypes in new_followers.items(): subtypes = list(subtypes) if subtypes is not None else None - self.message_subscribe(cr, uid, [record.id], [pid], None, subtypes, context=context) + self.message_subscribe(cr, uid, [record.id], [pid], subtypes, context=context) # find first email message, set it as unread for auto_subscribe fields for them to have a notification if user_id_partner_ids: diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 83b46f9f951..93f8f995ec7 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -297,13 +297,14 @@ openerp_mail_followers = function(session, mail) { 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], partner_id, checklist, context]) + return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], checklist, partner_id, context]) .then(this.proxy('read_value')); } }, From 5bbffbc39c899adb92d251a3c8ef7f06e39338a7 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 11 Apr 2013 18:05:37 +0530 Subject: [PATCH 19/38] [IMP] Improved code and made the EDIT followers visible when 'Technical Features' are given and it is in 'DEBUG mode'. bzr revid: psa@tinyerp.com-20130411123537-2wzb468o7o0dno8c --- addons/mail/mail_thread.py | 7 +++++++ addons/mail/static/src/js/mail_followers.js | 8 ++++++-- addons/mail/static/src/xml/mail_followers.xml | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 603c77f6ede..879f991ddb3 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -152,6 +152,13 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res + def check_access_right(self, cr, uid, ids, context=None): + grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one') + user_pid = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users'] + if uid in user_pid: + return True + return False + def _get_subscription_data(self, cr, uid, ids, name, args, user_id=None, context=None): """ Computes: - message_subtype_data: data about document subtypes: which are diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 93f8f995ec7..09f54f012ce 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -192,14 +192,18 @@ openerp_mail_followers = function(session, mail) { var self = this; this.followers = records || this.followers; this.message_is_follower = this.set_is_follower(this.followers); + this.check_access = false; // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); _(truncated).each(function (record) { - record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); - $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); + self.ds_model.call('check_access_right', [self.session.uid]).then(function(result){ + self.check_access = result; + record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); + $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); + }) }); // FVA note: be sure it is correctly translated if (truncated.length < this.followers.length) { diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 88f38146de3..ca0064cbc78 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -31,7 +31,7 @@
- + X
From 133ad0b97c0029e5902a836d821112b4928c465c Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 30 May 2013 10:10:37 +0530 Subject: [PATCH 20/38] [IMP] Improved code for removing the div of dialog everytime when the dialog box is created. bzr revid: psa@tinyerp.com-20130530044037-02cw9gap03qhz087 --- addons/mail/static/src/js/mail_followers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 7a4052e123b..d40f135d7db 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -82,6 +82,7 @@ openerp_mail_followers = function(session, mail) { on_edit_subtype: function(event) { var self = this; var partner_id = $(event.target).data('id'); + $('div.oe_edit_actions').remove(); self.$dialog = new session.web.dialog($('
'), { modal: true, width: 'auto', From dfb516fb5daadfe3a2a13c6b5c4f71ef2aea6593 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 31 May 2013 18:39:12 +0530 Subject: [PATCH 21/38] [IMP] created a new record rule for the technical features group. bzr revid: psa@tinyerp.com-20130531130912-ee0ptpjv27id4l32 --- addons/mail/security/mail_security.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/mail/security/mail_security.xml b/addons/mail/security/mail_security.xml index c369e96102b..92b0ca3fc0f 100644 --- a/addons/mail/security/mail_security.xml +++ b/addons/mail/security/mail_security.xml @@ -14,11 +14,21 @@ mail.followers: read and write its own entries + [('partner_id', '=', user.partner_id.id)] + + mail.followers: read and write its own entries + + + [] + + + + mail.notification: read and write its own entries From 872a688fbe4fba647f51169f2d3fe7d8715974fd Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Mon, 3 Jun 2013 18:02:27 +0530 Subject: [PATCH 22/38] [IMP] Added code for the access right on specific model. bzr revid: psa@tinyerp.com-20130603123227-76kykft5jl3u5egl --- addons/mail/static/src/js/mail_followers.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index d40f135d7db..c43b557e982 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -91,9 +91,9 @@ openerp_mail_followers = function(session, mail) { buttons: [ { text: _t("Apply"), click: function() { self.do_update_subscription(event, partner_id); - $(this).remove(); + $(this).dialog("close"); }}, - { text: _t("Cancel"), click: function() { $(this).remove(); }} + { text: _t("Cancel"), click: function() { $(this).dialog("close"); }} ], }); return self.fetch_subtypes(partner_id); @@ -291,6 +291,7 @@ openerp_mail_followers = function(session, mail) { var self = this; var checklist = new Array(); + this.ds_model.call('check_access_rights', ['write','read']) var subtype_checkbox = _(this.$('.oe_actions input[type="checkbox"]')) if (partner_id) { subtype_checkbox = _($('.oe_edit_actions input[type="checkbox"]')) From 388a3e14a15c9d18cc179cee0779a07e45424b82 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Tue, 4 Jun 2013 15:17:22 +0530 Subject: [PATCH 23/38] [ImP] method name change and removed the access call which is not needed bcz the system is calling it self. bzr revid: psa@tinyerp.com-20130604094722-2b8i6ba7blz1g2rc --- addons/mail/mail_thread.py | 2 +- addons/mail/static/src/js/mail_followers.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index b248247202b..cf8f5828650 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -152,7 +152,7 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res - def check_access_right(self, cr, uid, ids, context=None): + def check_technical_rights(self, cr, uid, ids, context=None): grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one') user_pid = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users'] if uid in user_pid: diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index c43b557e982..74a59d5abba 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -198,7 +198,7 @@ openerp_mail_followers = function(session, mail) { // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); _(truncated).each(function (record) { - self.ds_model.call('check_access_right', [self.session.uid]).then(function(result){ + self.ds_model.call('check_technical_rights', [self.session.uid]).then(function(result){ self.check_access = result; record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); @@ -291,7 +291,6 @@ openerp_mail_followers = function(session, mail) { var self = this; var checklist = new Array(); - this.ds_model.call('check_access_rights', ['write','read']) var subtype_checkbox = _(this.$('.oe_actions input[type="checkbox"]')) if (partner_id) { subtype_checkbox = _($('.oe_edit_actions input[type="checkbox"]')) From 52b02c879b0e2b23194f6c08fc30e38a22b42c4a Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Wed, 5 Jun 2013 18:40:31 +0530 Subject: [PATCH 24/38] [IMP] Improved code without disturbing the others methods and solved the issue of unfollowing the specific user by specific id. bzr revid: psa@tinyerp.com-20130605131031-bppkpzdwmi8sp4f7 --- addons/mail/mail_thread.py | 19 ++++----- addons/mail/static/src/js/mail_followers.js | 46 +++++++++++++-------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index cf8f5828650..778419968e2 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -159,12 +159,13 @@ class mail_thread(osv.AbstractModel): return True return False - def _get_subscription_data(self, cr, uid, ids, name, args, user_id=None, context=None): + def _get_subscription_data(self, cr, uid, ids, name, args, user_pid=None, context=None): """ Computes: - message_subtype_data: data about document subtypes: which are available, which are followed if any """ 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] + if user_pid is None: + user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] # find current model subtypes, add them to a dictionary subtype_obj = self.pool.get('mail.message.subtype') @@ -173,8 +174,6 @@ class mail_thread(osv.AbstractModel): for id in ids: res[id]['message_subtype_data'] = subtype_dict.copy() - 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, [ @@ -1257,23 +1256,21 @@ class mail_thread(osv.AbstractModel): # Followers API #------------------------------------------------------ - def message_get_subscription_data(self, cr, uid, ids, user_id=None, context=None): + def message_get_subscription_data(self, cr, uid, ids, user_pid=None, context=None): """ Wrapper to get subtypes data. """ - return self._get_subscription_data(cr, uid, ids, None, None, user_id=user_id, context=context) + return self._get_subscription_data(cr, uid, ids, None, None, user_pid=user_pid, context=context) - def message_subscribe_users(self, cr, uid, ids, user_ids=None, subtype_ids=None, user_id=None, context=None): + def message_subscribe_users(self, cr, uid, ids, user_ids=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, user_id=user_id, context=context) + return self.message_subscribe(cr, uid, ids, partner_ids, subtype_ids=subtype_ids, context=context) - def message_subscribe(self, cr, uid, ids, partner_ids, subtype_ids=None, user_id=None, context=None): + def message_subscribe(self, cr, uid, ids, partner_ids, 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]): try: self.check_access_rights(cr, uid, 'read') diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 74a59d5abba..8b4f044740d 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -81,7 +81,7 @@ openerp_mail_followers = function(session, mail) { on_edit_subtype: function(event) { var self = this; - var partner_id = $(event.target).data('id'); + var user_pid = $(event.target).data('id'); $('div.oe_edit_actions').remove(); self.$dialog = new session.web.dialog($('
'), { modal: true, @@ -90,13 +90,13 @@ openerp_mail_followers = function(session, mail) { title: _t('Edit Subscription of ') + $(event.target).siblings('a').text(), buttons: [ { text: _t("Apply"), click: function() { - self.do_update_subscription(event, partner_id); + self.do_update_subscription(event, user_pid); $(this).dialog("close"); }}, { text: _t("Cancel"), click: function() { $(this).dialog("close"); }} ], }); - return self.fetch_subtypes(partner_id); + return self.fetch_subtypes(user_pid); }, on_invite_follower: function (event) { @@ -231,17 +231,17 @@ openerp_mail_followers = function(session, mail) { }, /** Fetch subtypes, only if current user is follower */ - fetch_subtypes: function (partner_id) { + fetch_subtypes: function (user_pid) { var self = this; var mode = ""; - if (partner_id) { + if (user_pid) { 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], partner_id, new session.web.CompoundContext(this.build_context(), {})]) + this.ds_model.call('message_get_subscription_data', [[id], user_pid, new session.web.CompoundContext(this.build_context(), {})]) .then(function (data) {self.display_subtypes(data, id, mode);}); }, @@ -267,7 +267,7 @@ openerp_mail_followers = function(session, mail) { do_follow: function () { var context = new session.web.CompoundContext(this.build_context(), {}); - this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, undefined, context]) + this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, context]) .then(this.proxy('read_value')); _.each(this.$('.oe_subtype_list input'), function (record) { @@ -275,39 +275,49 @@ openerp_mail_followers = function(session, mail) { }); }, - do_unfollow: function () { + do_unfollow: function (user_pid) { if (confirm(_t("Warning! \nYou won't be notified of any email or discussion on this document. Do you really want to unfollow this document ?"))) { _(this.$('.oe_msg_subtype_check')).each(function (record) { $(record).attr('checked',false); }); + var unsubscribe = 'message_unsubscribe_users'; + var follower_ids = [this.session.uid]; + if (user_pid) { + unsubscribe = 'message_unsubscribe'; + follower_ids = [user_pid]; + } var context = new session.web.CompoundContext(this.build_context(), {}); - return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], [this.session.uid], context]) - .then(this.proxy('read_value')); + return this.ds_model.call(unsubscribe, [[this.view.datarecord.id], follower_ids, context]) + .then(this.proxy('read_value')); } return false; }, - do_update_subscription: function (event, partner_id) { + do_update_subscription: function (event, user_pid) { var self = this; + var subscribe = 'message_subscribe_users'; + var follower_ids = [this.session.uid]; + var oe_action = this.$('.oe_actions input[type="checkbox"]'); + if (user_pid) { + subscribe = 'message_subscribe'; + follower_ids = [user_pid]; + oe_action = $('.oe_edit_actions input[type="checkbox"]'); + } var checklist = new Array(); - var subtype_checkbox = _(this.$('.oe_actions input[type="checkbox"]')) - if (partner_id) { - subtype_checkbox = _($('.oe_edit_actions input[type="checkbox"]')) - } - subtype_checkbox.each(function (record) { + _(oe_action).each(function (record) { if ($(record).is(':checked')) { checklist.push(parseInt($(record).data('id'))); } }); if (!checklist.length) { - if (!this.do_unfollow()) { + if (!this.do_unfollow(user_pid)) { $(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, partner_id, context]) + return this.ds_model.call(subscribe, [[this.view.datarecord.id], follower_ids, checklist, context]) .then(this.proxy('read_value')); } }, From da775672ea6742a40d5827a30e49761e05868f94 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 6 Jun 2013 11:18:17 +0530 Subject: [PATCH 25/38] [IMP] Improved code. bzr revid: psa@tinyerp.com-20130606054817-k3bbkb4j1u9rolpi --- addons/mail/static/src/js/mail_followers.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 8b4f044740d..6394ccf27c8 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -249,16 +249,13 @@ openerp_mail_followers = function(session, mail) { display_subtypes:function (data, id, mode) { var self = this; var $list = this.$('.oe_subtype_list'); - if (mode.length == 0){ $list.empty().hide();} + if (mode.length != 0){ $list = self.$dialog; } + $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; - 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); - } + $(session.web.qweb.render('mail.followers.subtype', {'record': record,'mode': mode})).appendTo( $list ); }); if (_.size(records) > 1) { $list.show(); From 1e26218dd3d20df4d193794912ee49bf778d94c5 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 6 Jun 2013 16:42:06 +0530 Subject: [PATCH 26/38] [IMP] Added description of record and name. bzr revid: psa@tinyerp.com-20130606111206-01ykdwfohp73uhy2 --- addons/mail/security/mail_security.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/mail/security/mail_security.xml b/addons/mail/security/mail_security.xml index 92b0ca3fc0f..5384e2aba95 100644 --- a/addons/mail/security/mail_security.xml +++ b/addons/mail/security/mail_security.xml @@ -20,8 +20,9 @@ + - mail.followers: read and write its own entries + mail.followers: read and write others entries [] From b2ce2ae9bc4724a2bf5dba414d6e86c7042768d3 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Wed, 12 Jun 2013 10:56:45 +0530 Subject: [PATCH 27/38] [IMP] variable name improvements added action_ ahead of subscribe and unsubscribe to clearly understad the work of it. bzr revid: psa@tinyerp.com-20130612052645-x1wv4e1t2zyig4t2 --- addons/mail/static/src/js/mail_followers.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 2f010d6812b..faab16947d5 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -280,14 +280,14 @@ openerp_mail_followers = function(session, mail) { _(this.$('.oe_msg_subtype_check')).each(function (record) { $(record).attr('checked',false); }); - var unsubscribe = 'message_unsubscribe_users'; + var action_unsubscribe = 'message_unsubscribe_users'; var follower_ids = [this.session.uid]; if (user_pid) { - unsubscribe = 'message_unsubscribe'; + action_unsubscribe = 'message_unsubscribe'; follower_ids = [user_pid]; } var context = new session.web.CompoundContext(this.build_context(), {}); - return this.ds_model.call(unsubscribe, [[this.view.datarecord.id], follower_ids, context]) + return this.ds_model.call(action_unsubscribe, [[this.view.datarecord.id], follower_ids, context]) .then(this.proxy('read_value')); } return false; @@ -296,11 +296,11 @@ openerp_mail_followers = function(session, mail) { do_update_subscription: function (event, user_pid) { var self = this; - var subscribe = 'message_subscribe_users'; + var action_subscribe = 'message_subscribe_users'; var follower_ids = [this.session.uid]; var oe_action = this.$('.oe_actions input[type="checkbox"]'); if (user_pid) { - subscribe = 'message_subscribe'; + action_subscribe = 'message_subscribe'; follower_ids = [user_pid]; oe_action = $('.oe_edit_actions input[type="checkbox"]'); } @@ -317,7 +317,7 @@ openerp_mail_followers = function(session, mail) { } } else { var context = new session.web.CompoundContext(this.build_context(), {}); - return this.ds_model.call(subscribe, [[this.view.datarecord.id], follower_ids, checklist, context]) + return this.ds_model.call(action_subscribe, [[this.view.datarecord.id], follower_ids, checklist, context]) .then(this.proxy('read_value')); } }, From 14f157e395304c288e116e1759fdaf74128d8877 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Wed, 12 Jun 2013 17:15:38 +0530 Subject: [PATCH 28/38] [IMP] When the subtypes are not displayed in subtype list below the follow button than the edit subtype pencil will also not displayed. bzr revid: psa@tinyerp.com-20130612114538-21ohwb0l50or62fe --- addons/mail/static/src/js/mail_followers.js | 2 ++ addons/mail/static/src/xml/mail_followers.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index faab16947d5..6bcc0bb2a4e 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -252,6 +252,8 @@ openerp_mail_followers = function(session, mail) { if (mode.length != 0){ $list = self.$dialog; } $list.empty().hide(); var records = data[this.view.datarecord.id || this.view.dataset.ids[0]].message_subtype_data; + this.records_length = $.map(records, function(value, index) { return index; }).length; + if (this.records_length > 1) { self.display_followers(); } _(records).each(function (record, record_name) { record.name = record_name; record.followed = record.followed || undefined; diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 876cead3b50..0693b7c9532 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -31,7 +31,7 @@
- + X
From ae8302a3d6108d305c38190214b348a5e6715b7f Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Wed, 19 Jun 2013 19:18:17 +0530 Subject: [PATCH 29/38] [IMP] Now the edit_subtype pencil will be visible when the cursor goes on to the follower_list. And made the edit_subtype icon visible without debug mode. bzr revid: psa@tinyerp.com-20130619134817-n390r4dsgmpo33nb --- addons/mail/static/src/css/mail.css | 6 ++++++ addons/mail/static/src/js/mail_followers.js | 9 +++++++++ addons/mail/static/src/xml/mail_followers.xml | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index d976ce05f38..d5c1ffeedc7 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -628,6 +628,9 @@ text-overflow: ellipsis; margin-right: 10px; } +.openerp .oe_followers .oe_partner_name { + margin-right: 26px; +} .openerp .oe_followers .oe_partner img{ width: 32px; margin-right:4px; @@ -647,6 +650,9 @@ width: 10px !important; height: 12px !important; } +img.hidden { + display: none; +} .openerp.ui-dialog .ui-dialog-titlebar .ui-dialog-title{ padding-right: 20px; } diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 6bcc0bb2a4e..24dadec25ab 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -195,6 +195,15 @@ openerp_mail_followers = function(session, mail) { // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); + // On mouseenter it will show the edit_subtype penil + this.$el.on('mouseenter', 'div.oe_follower_list', function() { + $("img.oe_edit_subtype").removeClass("hidden"); + $('div.oe_follower_list').find('.oe_partner').addClass('oe_partner_name'); + }).on('mouseleave', 'div.oe_follower_list', function(){ + $("img.oe_edit_subtype").addClass("hidden"); + $('div.oe_follower_list').find('.oe_partner').removeClass('oe_partner_name'); + }); + // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); _(truncated).each(function (record) { diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 0693b7c9532..db58abb1441 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -31,7 +31,7 @@
- + X
From 4180da8a406acc8a55c329e6d90e4df377aba170 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Thu, 20 Jun 2013 10:30:26 +0530 Subject: [PATCH 30/38] [IMP] Improved code and removed unwanted code. bzr revid: psa@tinyerp.com-20130620050026-3kwfmowqfa9f4quz --- addons/mail/static/src/css/mail.css | 2 +- addons/mail/static/src/js/mail_followers.js | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index d5c1ffeedc7..4d46319a490 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -650,7 +650,7 @@ width: 10px !important; height: 12px !important; } -img.hidden { +.openerp .oe_followers .oe_partner img.hidden{ display: none; } .openerp.ui-dialog .ui-dialog-titlebar .ui-dialog-title{ diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 24dadec25ab..351031b9711 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -195,14 +195,6 @@ openerp_mail_followers = function(session, mail) { // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); - // On mouseenter it will show the edit_subtype penil - this.$el.on('mouseenter', 'div.oe_follower_list', function() { - $("img.oe_edit_subtype").removeClass("hidden"); - $('div.oe_follower_list').find('.oe_partner').addClass('oe_partner_name'); - }).on('mouseleave', 'div.oe_follower_list', function(){ - $("img.oe_edit_subtype").addClass("hidden"); - $('div.oe_follower_list').find('.oe_partner').removeClass('oe_partner_name'); - }); // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); @@ -211,6 +203,16 @@ openerp_mail_followers = function(session, mail) { self.check_access = result; record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); + // On mouseenter it will show the edit_subtype penil + if (self.check_access == true) { + self.$el.on('mouseenter', 'div.oe_follower_list', function() { + $("img.oe_edit_subtype").removeClass("hidden"); + $('div.oe_follower_list').find('.oe_partner').addClass('oe_partner_name'); + }).on('mouseleave', 'div.oe_follower_list', function(){ + $("img.oe_edit_subtype").addClass("hidden"); + $('div.oe_follower_list').find('.oe_partner').removeClass('oe_partner_name'); + }); + } }) }); // FVA note: be sure it is correctly translated @@ -271,9 +273,6 @@ openerp_mail_followers = function(session, mail) { if (_.size(records) > 1) { $list.show(); } - if (this.check_access && this.session.debug) { - $('div.oe_follower_list').find('.oe_partner').css('margin-right', '28px'); - } }, do_follow: function () { From cc05ab11dfd7e2070d2af9642808de34ec031add Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Wed, 26 Jun 2013 16:17:22 +0530 Subject: [PATCH 31/38] [IMP] Little Improvement. bzr revid: psa@tinyerp.com-20130626104722-jpzcu0gnbbggitv8 --- addons/mail/static/src/js/mail_followers.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index eafbb3ac4e1..b7862564732 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -74,6 +74,7 @@ openerp_mail_followers = function(session, mail) { this.$el.on('click', '.oe_subtype_list input', self.do_update_subscription); // event: click on 'invite' button, that opens the invite wizard this.$('.oe_invite').on('click', self.on_invite_follower); + // event: click on 'edit_subtype(pencil)' button to edit subscription this.$el.on('click', '.oe_edit_subtype', self.on_edit_subtype); this.$el.on('click', '.oe_remove_follower', self.on_remove_follower); this.$el.on('click', '.oe_show_more', self.on_show_more_followers) @@ -81,13 +82,14 @@ openerp_mail_followers = function(session, mail) { on_edit_subtype: function(event) { var self = this; - var user_pid = $(event.target).data('id'); + var $currentTarget = $(event.currentTarget); + var user_pid = $currentTarget.data('id'); $('div.oe_edit_actions').remove(); self.$dialog = new session.web.dialog($('
'), { modal: true, width: 'auto', height: 'auto', - title: _t('Edit Subscription of ') + $(event.target).siblings('a').text(), + title: _t('Edit Subscription of ') + $currentTarget.siblings('a').text(), buttons: [ { text: _t("Apply"), click: function() { self.do_update_subscription(event, user_pid); @@ -96,7 +98,7 @@ openerp_mail_followers = function(session, mail) { { text: _t("Cancel"), click: function() { $(this).dialog("close"); }} ], }); - return self.fetch_subtypes(user_pid); + return self.fetch_subtypes(user_pid); }, on_invite_follower: function (event) { From 39151ca2af306adb202394c54fffba26d2e53d40 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 28 Jun 2013 19:07:12 +0530 Subject: [PATCH 32/38] [IMP] Improved code for the followers which are visually duplicated when you click on a follower's name and get back to the sales order form. bzr revid: psa@tinyerp.com-20130628133712-tcfoaisr3o9wdv7x --- addons/mail/static/src/js/mail_followers.js | 27 ++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index b7862564732..260ff6092ea 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -36,6 +36,7 @@ openerp_mail_followers = function(session, mail) { this.followers = []; this.view_is_editable = this.__parentedParent.is_action_enabled('edit'); + this.check_access = false; }, start: function() { @@ -45,6 +46,7 @@ openerp_mail_followers = function(session, mail) { this.reinit(); this.bind_events(); this._super(); + this.check_group_tech_feature(); }, on_check_visibility_mode: function () { @@ -188,33 +190,36 @@ openerp_mail_followers = function(session, mail) { this.$('.oe_follower_title').html(this._format_followers(this.value.length)); }, + check_group_tech_feature: function(){ + var self = this; + self.ds_model.call('check_technical_rights', [self.session.uid]).then(function(result){ + self.check_access = result; + }); + }, + /** Display the followers */ display_followers: function (records) { var self = this; this.followers = records || this.followers; this.message_is_follower = this.set_is_follower(this.followers); - this.check_access = false; // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); _(truncated).each(function (record) { - self.ds_model.call('check_technical_rights', [self.session.uid]).then(function(result){ - self.check_access = result; - record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); - $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); - // On mouseenter it will show the edit_subtype penil - if (self.check_access == true) { - self.$el.on('mouseenter', 'div.oe_follower_list', function() { - $("img.oe_edit_subtype").removeClass("hidden"); - $('div.oe_follower_list').find('.oe_partner').addClass('oe_partner_name'); + record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); + $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); + // On mouseenter it will show the edit_subtype penil + if (self.check_access == true) { + self.$el.on('mouseenter', 'div.oe_follower_list', function() { + $("img.oe_edit_subtype").removeClass("hidden"); + $('div.oe_follower_list').find('.oe_partner').addClass('oe_partner_name'); }).on('mouseleave', 'div.oe_follower_list', function(){ $("img.oe_edit_subtype").addClass("hidden"); $('div.oe_follower_list').find('.oe_partner').removeClass('oe_partner_name'); }); } - }) }); // FVA note: be sure it is correctly translated if (truncated.length < this.followers.length) { From 6694183dcb7b95947eea4931bc76cc3e2e1dcee8 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 12 Jul 2013 19:09:20 +0530 Subject: [PATCH 33/38] [IMP] Improved code and added {'is_editable': True/False, 'is_uid': True/False} -- where is_editable will be True if uid is in technical group -- where is_uid will be True if uid is in partner.user_ids. bzr revid: psa@tinyerp.com-20130712133920-96l6axns7yynyz9e --- addons/mail/mail_thread.py | 21 ++++++++++----- addons/mail/static/src/js/mail_followers.js | 30 ++++++++++----------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 59f2817d016..ebd143e1be8 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -156,12 +156,21 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res - def check_technical_rights(self, cr, uid, ids, context=None): - grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one') - user_pid = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users'] - if uid in user_pid: - return True - return False + def read_followers_data(self, cr, uid, ids, context=None): + data = self.pool.get('res.partner').read(cr, uid, ids, ['name', 'user_ids'], context=context) + + grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one') + tech_user = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users'] + user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] + + if uid in tech_user: + for dict in data: + if dict['id'] in [user_pid]: + dict.update({'is_editable': True}) + if uid in dict['user_ids']: + dict.update({'is_uid': True}) + + return data def _get_subscription_data(self, cr, uid, ids, name, args, user_pid=None, context=None): """ Computes: diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 260ff6092ea..99c2a629f5d 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -29,7 +29,6 @@ openerp_mail_followers = function(session, mail) { this.displayed_limit = this.node.attrs.displayed_nb || 10; this.displayed_nb = this.displayed_limit; this.ds_model = new session.web.DataSetSearch(this, this.view.model); - this.ds_follow = new session.web.DataSetSearch(this, this.field.relation); this.ds_users = new session.web.DataSetSearch(this, 'res.users'); this.value = []; @@ -37,6 +36,7 @@ openerp_mail_followers = function(session, mail) { this.view_is_editable = this.__parentedParent.is_action_enabled('edit'); this.check_access = false; + this.is_follower = false; }, start: function() { @@ -46,7 +46,6 @@ openerp_mail_followers = function(session, mail) { this.reinit(); this.bind_events(); this._super(); - this.check_group_tech_feature(); }, on_check_visibility_mode: function () { @@ -154,11 +153,14 @@ openerp_mail_followers = function(session, mail) { }, fetch_followers: function (value_) { + var self = this; this.value = value_ || {}; - return this.ds_follow.call('read', [this.value, ['name', 'user_ids']]) - .then(this.proxy('display_followers'), this.proxy('fetch_generic')) - .then(this.proxy('display_buttons')) - .then(this.proxy('fetch_subtypes')); + return this.ds_model.call('read_followers_data', [this.value]).then(function(result) { + self.result = result; + self.display_followers(result), self.proxy('fetch_generic'); + self.display_buttons(); + self.fetch_subtypes(); + }); }, /** Read on res.partner failed: fall back on a generic case @@ -190,18 +192,16 @@ openerp_mail_followers = function(session, mail) { this.$('.oe_follower_title').html(this._format_followers(this.value.length)); }, - check_group_tech_feature: function(){ - var self = this; - self.ds_model.call('check_technical_rights', [self.session.uid]).then(function(result){ - self.check_access = result; - }); - }, - /** Display the followers */ display_followers: function (records) { var self = this; this.followers = records || this.followers; - this.message_is_follower = this.set_is_follower(this.followers); + _.each(this.result, function (record) { + if (self.session.uid == record.user_ids[0]) { + if (record.is_editable == true) { self.check_access = true; } + } + }); + this.message_is_follower = this.set_is_follower(this.followers); // self.is_follower // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); @@ -210,7 +210,7 @@ openerp_mail_followers = function(session, mail) { _(truncated).each(function (record) { record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); - // On mouseenter it will show the edit_subtype penil + // On mouse-enter it will show the edit_subtype pencil. if (self.check_access == true) { self.$el.on('mouseenter', 'div.oe_follower_list', function() { $("img.oe_edit_subtype").removeClass("hidden"); From 670710b88eb596ab9f6e8587de3d43ac133c0e18 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Mon, 15 Jul 2013 13:31:06 +0530 Subject: [PATCH 34/38] [IMP] Improved code and passed the data according to the format as suggest (partner_id, partner_name, {'is_editable': True/False, 'is_uid': True/False}) and done changes according this changes. bzr revid: psa@tinyerp.com-20130715080106-63dbeh3mhgiqppzv --- addons/mail/mail_thread.py | 29 +++++++++---------- addons/mail/static/src/js/mail_followers.js | 19 ++---------- addons/mail/static/src/xml/mail_followers.xml | 8 ++--- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index ebd143e1be8..949ed60ba82 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -156,21 +156,20 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res - def read_followers_data(self, cr, uid, ids, context=None): - data = self.pool.get('res.partner').read(cr, uid, ids, ['name', 'user_ids'], context=context) - - grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one') - tech_user = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users'] - user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] - - if uid in tech_user: - for dict in data: - if dict['id'] in [user_pid]: - dict.update({'is_editable': True}) - if uid in dict['user_ids']: - dict.update({'is_uid': True}) - - return data + def read_followers_data(self, cr, uid, follower_ids, context=None): + datas = [] + partner_pool = self.pool.get('res.partner') + technical_group = self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'group_no_one') + for follower in partner_pool.browse(cr, uid, follower_ids, context=context): + is_editable = uid in map(lambda x:x.id, technical_group.users) + is_uid = uid in map(lambda x:x.id, follower.user_ids) + data = ( + follower.id, + follower.name, + {'is_editable': is_editable, 'is_uid': is_uid}, + ) + datas.append(data) + return datas def _get_subscription_data(self, cr, uid, ids, name, args, user_pid=None, context=None): """ Computes: diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 99c2a629f5d..4fec4ff3fd3 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -35,8 +35,6 @@ openerp_mail_followers = function(session, mail) { this.followers = []; this.view_is_editable = this.__parentedParent.is_action_enabled('edit'); - this.check_access = false; - this.is_follower = false; }, start: function() { @@ -196,22 +194,17 @@ openerp_mail_followers = function(session, mail) { display_followers: function (records) { var self = this; this.followers = records || this.followers; - _.each(this.result, function (record) { - if (self.session.uid == record.user_ids[0]) { - if (record.is_editable == true) { self.check_access = true; } - } - }); - this.message_is_follower = this.set_is_follower(this.followers); // self.is_follower // clean and display title var node_user_list = this.$('.oe_follower_list').empty(); this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); // truncate number of displayed followers var truncated = this.followers.slice(0, this.displayed_nb); _(truncated).each(function (record) { - record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); + self.message_is_follower = record[2].is_uid; + record[2].avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record[0]); $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list); // On mouse-enter it will show the edit_subtype pencil. - if (self.check_access == true) { + if (record[2].is_editable == true) { self.$el.on('mouseenter', 'div.oe_follower_list', function() { $("img.oe_edit_subtype").removeClass("hidden"); $('div.oe_follower_list').find('.oe_partner').addClass('oe_partner_name'); @@ -227,12 +220,6 @@ openerp_mail_followers = function(session, mail) { } }, - /** Computes whether the current user is in the followers */ - set_is_follower: function (records) { - var user_ids = _.pluck(_.pluck(records, 'user_ids'), 0); - return _.indexOf(user_ids, this.session.uid) != -1; - }, - display_buttons: function () { if (this.message_is_follower) { this.$('button.oe_follower').removeClass('oe_notfollow').addClass('oe_following'); diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index db58abb1441..d23154096a6 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -29,10 +29,10 @@ Template used to display a partner following the record -->
- - - - X + + + + X
- - - - X + + + & + X