From f47111449cebd813c0de6bca44fe8b8473bf8e5d Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 24 Sep 2012 11:56:16 +0200 Subject: [PATCH] [IMP] mail_follower: unique field widget, sub-types on click bzr revid: chm@openerp.com-20120924095616-keuji387bvy6pmcs --- addons/account/account_invoice_view.xml | 8 -- .../account_voucher/account_voucher_view.xml | 4 - .../voucher_payment_receipt_view.xml | 8 -- .../voucher_sales_purchase_view.xml | 8 -- addons/analytic/analytic_view.xml | 4 - addons/base_calendar/crm_meeting_view.xml | 4 - addons/crm/crm_lead_view.xml | 8 -- addons/crm/crm_phonecall_view.xml | 4 - addons/crm_claim/crm_claim_view.xml | 4 - addons/crm_helpdesk/crm_helpdesk_view.xml | 4 - addons/event/event_view.xml | 8 -- addons/hr_expense/hr_expense_view.xml | 4 - addons/hr_holidays/hr_holidays_view.xml | 8 -- addons/hr_recruitment/hr_recruitment_view.xml | 4 - addons/idea/idea_view.xml | 4 - addons/mail/mail_group_view.xml | 10 +- addons/mail/mail_thread.py | 6 + addons/mail/res_partner_view.xml | 4 - addons/mail/static/src/css/mail.css | 33 ++++-- addons/mail/static/src/js/mail_followers.js | 107 +++++++++++------- addons/mail/static/src/xml/mail_followers.xml | 10 +- addons/mrp/mrp_view.xml | 7 -- addons/mrp_operations/mrp_operations_view.xml | 4 - addons/mrp_repair/mrp_repair_view.xml | 4 - addons/note/note_view.xml | 4 - addons/procurement/procurement_view.xml | 4 - addons/product/product_view.xml | 4 - addons/project/project_view.xml | 8 -- addons/project_issue/project_issue_view.xml | 4 - addons/purchase/purchase_view.xml | 4 - .../purchase_requisition_view.xml | 3 - addons/sale/sale_view.xml | 4 - addons/stock/stock_view.xml | 8 -- 33 files changed, 101 insertions(+), 211 deletions(-) diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 7b3c41bba69..1c4d83106ca 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -278,11 +278,7 @@
- - - -
@@ -441,11 +437,7 @@
- - - -
diff --git a/addons/account_voucher/account_voucher_view.xml b/addons/account_voucher/account_voucher_view.xml index f06960ba7d2..5e26c366778 100644 --- a/addons/account_voucher/account_voucher_view.xml +++ b/addons/account_voucher/account_voucher_view.xml @@ -108,11 +108,7 @@
- - - -
diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index 03dc6b33fa2..c41ed6d5577 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -239,11 +239,7 @@
- - - -
@@ -412,11 +408,7 @@
- - - -
diff --git a/addons/account_voucher/voucher_sales_purchase_view.xml b/addons/account_voucher/voucher_sales_purchase_view.xml index 2affc51b667..5bcecfa268e 100644 --- a/addons/account_voucher/voucher_sales_purchase_view.xml +++ b/addons/account_voucher/voucher_sales_purchase_view.xml @@ -146,11 +146,7 @@
- - - -
@@ -305,11 +301,7 @@
- - - -
diff --git a/addons/analytic/analytic_view.xml b/addons/analytic/analytic_view.xml index 8f25d03ce30..51f5428002f 100644 --- a/addons/analytic/analytic_view.xml +++ b/addons/analytic/analytic_view.xml @@ -53,11 +53,7 @@
- - - -
diff --git a/addons/base_calendar/crm_meeting_view.xml b/addons/base_calendar/crm_meeting_view.xml index 5c0a3790fd6..b963de68130 100644 --- a/addons/base_calendar/crm_meeting_view.xml +++ b/addons/base_calendar/crm_meeting_view.xml @@ -229,11 +229,7 @@
- - - -
diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index 5f52f3e0d93..f91a8756598 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -223,11 +223,7 @@
- - - -
@@ -529,11 +525,7 @@
- - - -
diff --git a/addons/crm/crm_phonecall_view.xml b/addons/crm/crm_phonecall_view.xml index f3ce57f10a9..ea20624d738 100644 --- a/addons/crm/crm_phonecall_view.xml +++ b/addons/crm/crm_phonecall_view.xml @@ -149,11 +149,7 @@
- - - -
diff --git a/addons/crm_claim/crm_claim_view.xml b/addons/crm_claim/crm_claim_view.xml index 38b7e9891cf..820fb38e58a 100644 --- a/addons/crm_claim/crm_claim_view.xml +++ b/addons/crm_claim/crm_claim_view.xml @@ -181,11 +181,7 @@
- - - -
diff --git a/addons/crm_helpdesk/crm_helpdesk_view.xml b/addons/crm_helpdesk/crm_helpdesk_view.xml index d914cd601e8..5399c9880ca 100644 --- a/addons/crm_helpdesk/crm_helpdesk_view.xml +++ b/addons/crm_helpdesk/crm_helpdesk_view.xml @@ -99,11 +99,7 @@
- - - -
diff --git a/addons/event/event_view.xml b/addons/event/event_view.xml index 9f9130ced4d..e7c14aab18f 100644 --- a/addons/event/event_view.xml +++ b/addons/event/event_view.xml @@ -197,11 +197,7 @@
- - - -
@@ -483,11 +479,7 @@
- - - -
diff --git a/addons/hr_expense/hr_expense_view.xml b/addons/hr_expense/hr_expense_view.xml index 265c07328e6..8049255afbf 100644 --- a/addons/hr_expense/hr_expense_view.xml +++ b/addons/hr_expense/hr_expense_view.xml @@ -139,11 +139,7 @@
- - - -
diff --git a/addons/hr_holidays/hr_holidays_view.xml b/addons/hr_holidays/hr_holidays_view.xml index 84a48e46615..347e2b17ca5 100644 --- a/addons/hr_holidays/hr_holidays_view.xml +++ b/addons/hr_holidays/hr_holidays_view.xml @@ -121,11 +121,7 @@
- - - -
@@ -162,11 +158,7 @@
- - - -
diff --git a/addons/hr_recruitment/hr_recruitment_view.xml b/addons/hr_recruitment/hr_recruitment_view.xml index 9e3045d766e..08e5f31a2d2 100644 --- a/addons/hr_recruitment/hr_recruitment_view.xml +++ b/addons/hr_recruitment/hr_recruitment_view.xml @@ -183,11 +183,7 @@
- - - -
diff --git a/addons/idea/idea_view.xml b/addons/idea/idea_view.xml index 7f42eeb3751..eab3d03ceea 100644 --- a/addons/idea/idea_view.xml +++ b/addons/idea/idea_view.xml @@ -77,11 +77,7 @@
- - - -
diff --git a/addons/mail/mail_group_view.xml b/addons/mail/mail_group_view.xml index 869c76d2110..40f0a754e4f 100644 --- a/addons/mail/mail_group_view.xml +++ b/addons/mail/mail_group_view.xml @@ -15,12 +15,10 @@ - - - - + +
@@ -84,12 +82,8 @@
- - - -
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 97e78cfdd15..71d4bfd099b 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -169,6 +169,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_unread(self, cr, uid, obj=None, name=None, domain=None, context=None): @@ -679,6 +680,11 @@ class mail_thread(osv.AbstractModel): 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) + def get_message_subtypes(self, cr, uid, ids, context=None): + """ message_subtype_data: data about document subtypes: which are + available, which are followed if any """ + return self._get_subscription_data(cr, uid, ids, None, None, context=context) + def message_subscribe(self, cr, uid, ids, partner_ids, subtype_ids=None, context=None): """ Add partners to the records followers. """ self.write(cr, uid, ids, {'message_follower_ids': [(4, pid) for pid in partner_ids]}, context=context) diff --git a/addons/mail/res_partner_view.xml b/addons/mail/res_partner_view.xml index 3ef68ac8c59..2a8430926d5 100644 --- a/addons/mail/res_partner_view.xml +++ b/addons/mail/res_partner_view.xml @@ -9,12 +9,8 @@
- - - -
diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 895aa57bdc5..3fde4cbc67b 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -14,7 +14,6 @@ margin: 0; } - /* ------------------------------------------------------------ */ /* Wall /* ------------------------------------------------------------ */ @@ -37,6 +36,29 @@ list-style-type: none; } +/* ------------------------------------------------------------ */ +/* Followers +/* ------------------------------------------------------------ */ + +.openerp div.oe_mail_recthread_aside h4 { + display: inline-block; +} +.openerp div.oe_mail_recthread_aside button { + position: relative; +} +.openerp div.oe_mail_recthread_aside label, +.openerp div.oe_mail_recthread_aside input { + cursor:pointer; +} +.openerp div.oe_mail_recthread_subtypes { + display:none; +} +.openerp div.oe_mail_recthread_aside button span { + position: absolute; + top:-7px; + right:5px; +} + /* Specific display of threads in the wall */ /* ------------------------------------------------------------ */ @@ -113,15 +135,6 @@ margin-bottom: 8px; } - -/* ------------------------------------------------------------ */ -/* Followers -/* ------------------------------------------------------------ */ - -.openerp div.oe_mail_recthread_aside h4 { - display: inline-block; -} - /* ------------------------------------------------------------ */ /* Thread /* ------------------------------------------------------------ */ diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 0efbf9ca76e..a3ba6f91a04 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -27,9 +27,9 @@ openerp_mail_followers = function(session, mail) { this.options.image = this.node.attrs.image || 'image_small'; this.options.title = this.node.attrs.title || 'Followers'; this.ds_model = new session.web.DataSetSearch(this, this.view.model); - this.sub_model = new session.web.DataSetSearch(this,'mail.message.subtype') + this.sub_model = new session.web.DataSetSearch(this,'mail.message.subtype'); this.ds_follow = new session.web.DataSetSearch(this, this.field.relation); - this.follower_model = new session.web.DataSetSearch(this,'mail.followers') + this.follower_model = new session.web.DataSetSearch(this,'mail.followers'); }, start: function() { @@ -51,11 +51,12 @@ openerp_mail_followers = function(session, mail) { bind_events: function() { var self = this; - this.$el.find('button.oe_mail_button_unfollow').on('click', function () { self.do_unfollow(); }) - .mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); }) - .mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); }); - this.$el.on('click', 'button.oe_mail_button_follow', function () { self.do_follow(); }); - this.$el.on('click', 'ul.oe_mail_subtypes', function () {self.do_update_subscription(); }) + this.$el.find('button.oe_mail_button_unfollow').on('click', function () { self.do_unfollow(); self.clear_subtypes(); }) + .mouseover(function () { $(this).removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover').find('p').html('Unfollow');}) + .mouseleave(function () { $(this).removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout').find('p').html('Following'); }); + + this.$el.on('click', 'button.oe_mail_button_follow', function () { self.do_follow(); self.clear_subtypes(); }); + this.$el.on('click', 'ul.oe_mail_subtypes input', function () {self.do_update_subscription(); }) this.$el.on('click', 'button.oe_mail_button_invite', function(event) { action = { type: 'ir.actions.act_window', @@ -71,37 +72,34 @@ openerp_mail_followers = function(session, mail) { } self.do_action(action, function() { self.read_value(); }); }); + + this.$el.find('button span') + .click(function (e) { self.display_subtypes(); e.stopPropagation(); }) }, read_value: function() { var self = this; - return this.ds_model.read_ids([this.view.datarecord.id], ['message_follower_ids', 'message_is_follower', 'message_subtype_data']).pipe(function (results) { - self.set_value(results[0].message_follower_ids, results[0].message_is_follower, results[0].message_subtype_data); + return this.ds_model.read_ids([this.view.datarecord.id], ['message_follower_ids']).pipe(function (results) { + self.set_value(results[0].message_follower_ids); }); }, - get_or_set: function(field_name, value) { - if (this.view.fields[field_name]) { - if (value !== undefined) { - this.view.fields[field_name].set_value(value); - } - return this.view.fields[field_name].get_value(); - } - else { - return value; - } + set_value: function(value_) { + console.log("set_value", value_); + this.reinit(); + return this.fetch_followers(value_ || this.get_value()); }, - set_value: function(value_, message_is_follower_value_, message_subtype_data_value_) { - this.reinit(); - if (! this.view.datarecord.id || - session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) { - this.$el.find('div.oe_mail_recthread_aside').hide(); - return; + set_is_follower: function(value_) { + for(var i in value_){ + if(value_[i]['user_ids'][0]==this.session.uid) + this.message_is_follower=true; + this.display_buttons(); + return true; } - this.message_is_follower_value_ = this.get_or_set('message_is_follower', message_is_follower_value_) || false; - this.message_subtype_data_value_ = this.get_or_set('message_subtype_data', message_subtype_data_value_) || {}; - return this.fetch_followers(value_ || this.get_value()); + this.message_is_follower=false; + this.display_buttons(); + return false; }, fetch_followers: function (value_, message_is_follower) { @@ -136,12 +134,11 @@ openerp_mail_followers = function(session, mail) { record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); $(session.web.qweb.render('mail.followers.partner', {'record': record})).appendTo(node_user_list); }); - this.display_buttons(); - return this.display_subtypes(this.message_subtype_data_value_); + self.set_is_follower(records); }, display_buttons: function () { - if (this.message_is_follower_value_) { + if (this.message_is_follower) { this.$el.find('button.oe_mail_button_follow').hide(); this.$el.find('button.oe_mail_button_unfollow').show(); } @@ -156,24 +153,48 @@ openerp_mail_followers = function(session, mail) { this.$el.find('span.oe_mail_invite_wrapper').show(); }, - /** Display subtypes: {'name': default, followed} */ - display_subtypes: function (records) { - var subtype_list = this.$el.find('ul.oe_mail_subtypes').empty(); - if (! this.message_is_follower_value_) { - return; - } + set_subtypes:function(data){ + var self = this; + var records = data[this.view.datarecord.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.subtype', {'record': record})).appendTo(subtype_list); + $(session.web.qweb.render('mail.followers.subtype', {'record': record})).appendTo( self.$el.find('ul.oe_mail_subtypes') ); }); }, - + + /** Display subtypes: {'name': default, followed} */ + display_subtypes: function () { + var self = this; + var recthread_subtypes = self.$el.find('.oe_mail_recthread_subtypes'); + subtype_list_ul = self.$el.find('ul.oe_mail_subtypes'); + + if(recthread_subtypes.is(":visible")) { + self.hidden_subtypes(); + } else { + if(subtype_list_ul.is(":empty")) { + var context = new session.web.CompoundContext(this.build_context(), {}); + this.ds_model.call('get_message_subtypes',[[self.view.datarecord.id], context]).pipe(this.proxy('set_subtypes')); + } + + recthread_subtypes.show(); + } + }, + + clear_subtypes: function(){ + this.$el.find('ul.oe_mail_subtypes').empty(); + this.hidden_subtypes(); + }, + + hidden_subtypes: function (){ + this.$el.find('.oe_mail_recthread_subtypes').hide(); + }, + do_follow: function () { var context = new session.web.CompoundContext(this.build_context(), {}); return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, undefined, context]).pipe(this.proxy('read_value')); }, - + do_unfollow: function () { var context = new session.web.CompoundContext(this.build_context(), {}); return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('read_value')); @@ -182,13 +203,15 @@ openerp_mail_followers = function(session, mail) { do_update_subscription: function () { var context = new session.web.CompoundContext(this.build_context(), {}); var self = this; + var checklist = new Array(); _(this.$el.find('.oe_msg_subtype_check')).each(function(record){ if($(record).is(':checked')) { - checklist.push(parseInt($(record).attr('id')))} + checklist.push(parseInt($(record).data('id')))} }); + return this.ds_model.call('message_subscribe_users',[[self.view.datarecord.id], undefined, checklist, context]).pipe(this.proxy('read_value')); }, }); -}; +}; \ No newline at end of file diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 05eb349ea5d..9d0543bbdca 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -7,9 +7,9 @@ -->
- - - + + +

Message types to follow

    @@ -39,8 +39,8 @@
  • - - + +
  • diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index b49123b8a38..d05893cf778 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -410,9 +410,6 @@
    - - -
    @@ -790,11 +787,7 @@
    - - - -
    diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index 715f0a53531..834f3000472 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -107,11 +107,7 @@
    - - - -
    diff --git a/addons/mrp_repair/mrp_repair_view.xml b/addons/mrp_repair/mrp_repair_view.xml index 94a06e6b40d..55cbe49c75b 100644 --- a/addons/mrp_repair/mrp_repair_view.xml +++ b/addons/mrp_repair/mrp_repair_view.xml @@ -189,11 +189,7 @@
    - - - -
    diff --git a/addons/note/note_view.xml b/addons/note/note_view.xml index 789a112b868..19eff9bc250 100644 --- a/addons/note/note_view.xml +++ b/addons/note/note_view.xml @@ -50,7 +50,6 @@ - @@ -119,9 +118,6 @@
    - - -
    diff --git a/addons/procurement/procurement_view.xml b/addons/procurement/procurement_view.xml index 64b10bd2bbf..bf73b383216 100644 --- a/addons/procurement/procurement_view.xml +++ b/addons/procurement/procurement_view.xml @@ -103,11 +103,7 @@
    - - - -
    diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml index d175ea391d5..c08bbc412e3 100644 --- a/addons/product/product_view.xml +++ b/addons/product/product_view.xml @@ -203,11 +203,7 @@
    - - - -
    diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index fa639f46c6d..93d01a5619b 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -152,11 +152,7 @@
    - - - -
    @@ -482,11 +478,7 @@
    - - - -
    diff --git a/addons/project_issue/project_issue_view.xml b/addons/project_issue/project_issue_view.xml index f9e04e7420e..8d54520261f 100644 --- a/addons/project_issue/project_issue_view.xml +++ b/addons/project_issue/project_issue_view.xml @@ -161,11 +161,7 @@
    - - - -
    diff --git a/addons/purchase/purchase_view.xml b/addons/purchase/purchase_view.xml index 69042a2fa1a..759c0561631 100644 --- a/addons/purchase/purchase_view.xml +++ b/addons/purchase/purchase_view.xml @@ -285,11 +285,7 @@
    - - - -
    diff --git a/addons/purchase_requisition/purchase_requisition_view.xml b/addons/purchase_requisition/purchase_requisition_view.xml index cba22f384ca..80bdd9aa95b 100644 --- a/addons/purchase_requisition/purchase_requisition_view.xml +++ b/addons/purchase_requisition/purchase_requisition_view.xml @@ -103,9 +103,6 @@
    - - -
    diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 54fdcb8c140..5c2320a7d5c 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -351,11 +351,7 @@
    - - - -
    diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 2f2dc3a2d8a..83fed186f42 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -917,11 +917,7 @@
    - - - -
    @@ -1047,11 +1043,7 @@
    - - - -