From 2a73f8bdd18a56b26b5e9ffbad4104efa1e716f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 6 Feb 2012 16:10:09 +0100 Subject: [PATCH] [IMP] Improved ThradView widget: follow/unfollow mechanism, draft of comment post mechanism bzr revid: tde@openerp.com-20120206151009-qvfutg9n6ytffxei --- addons/mail/mail_thread.py | 15 ++++++++-- addons/mail/static/src/js/mail.js | 43 +++++++++++++++++++++++++++-- addons/mail/static/src/xml/mail.xml | 34 ++++++++++------------- 3 files changed, 68 insertions(+), 24 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 132653ba3b0..209a0d2ab23 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -66,7 +66,8 @@ class mail_thread(osv.osv): 'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', readonly=True), 'message_ids_social': fields.function(_get_message_ids, method=True, type='one2many', obj='mail.message', string='Temp messages', - widget='mail.ThreadView'), + ), + #widget='mail.ThreadView'), } #------------------------------------------------------ @@ -523,7 +524,17 @@ class mail_thread(osv.osv): sub_ids = subscription_obj.search(cr, uid, ['&', ('res_model', '=', self._name), ('res_id', '=', id)], context=context) subs = subscription_obj.browse(cr, uid, sub_ids, context=context) return subs - + + def message_is_subscriber(self, cr, uid, ids, context=None): + print uid + print ids + subs = self.message_get_subscribers(cr, uid, ids, context=context) + for sub in subs: + print sub + print sub.user_id + if sub.user_id == uid: return True + return False + def message_subscribe(self, cr, uid, ids, context=None): subscription_obj = self.pool.get('mail.subscription') subscriber_id = uid # TODO diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 22584e442b0..e50eec4e6d8 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -8,31 +8,64 @@ openerp.mail = function(session) { /* ThreadView Widget: thread of comments */ mail.ThreadView = session.web.form.Field.extend({ // QWeb template to use when rendering the object - template: 'MailTest', + template: 'ThreadView', init: function() { + console.log('Entering init'); // this.timeout; + this.follow_state = 0; this._super.apply(this, arguments); this.ds = new session.web.DataSet(this, this.view.model); this.ds_sub = new session.web.DataSet(this, 'mail.subscription'); + console.log('Leaving init'); }, start: function() { + console.log('Entering start'); var self = this; this._super.apply(this, arguments); + /* bind follow and unfollow buttons */ self.$element.find('button.oe_mail_action_follow').bind('click', function () { self.do_follow(); }); + self.$element.find('button.oe_mail_action_follow').hide(); self.$element.find('button.oe_mail_action_unfollow').bind('click', function () { self.do_unfollow(); }); + self.$element.find('button.oe_mail_action_unfollow').hide(); + /* find wich (un)follow buttons to show */ + var call_res = this.ds.call('message_is_subscriber', [[this.session.uid]]).then(function (records) { + console.log('Pouet'); + console.log(records); + console.log('Pouet2'); + if (records == true) { self.follow_state = 1; console.log('brout!'); self.$element.find('button.oe_mail_action_unfollow').show(); } + else { self.follow_state = 0; console.log('proutch!'); self.$element.find('button.oe_mail_action_follow').show(); } + }); + console.log(call_res); + console.log('Leaving start'); + }, + + render: function() { + console.log('Entering render'); +// this._super.apply(this, arguments); + var template = this.template; + var render_res = session.web.qweb.render(template, { + 'tmp': 'comment', + }); + console.log('Leaving render'); + return render_res; }, stop: function () { // clearTimeout(this.timeout); + console.log('Entering stop'); this._super(); + console.log('Leaving stop'); }, set_value: function() { + console.log('Entering set_value'); this._super.apply(this, arguments); if (! this.view.datarecord.id) { return; } - return this.fetch_messages(); + var fetch_res = this.fetch_messages(); + console.log('Leaving set_value'); + return fetch_res }, fetch_messages: function () { @@ -57,12 +90,16 @@ openerp.mail = function(session) { do_follow: function () { console.log('Follow'); console.log(this); - this.ds_sub.create({'res_model': this.view.model, 'user_id': this.session.uid, 'res_id': this.view.datarecord.id}).then( + this.$element.find('button.oe_mail_action_unfollow').show(); + this.$element.find('button.oe_mail_action_follow').hide(); + return this.ds_sub.create({'res_model': this.view.model, 'user_id': this.session.uid, 'res_id': this.view.datarecord.id}).then( console.log('Subscription done')); }, do_unfollow: function () { console.log('Unfollow'); + this.$element.find('button.oe_mail_action_follow').show(); + this.$element.find('button.oe_mail_action_unfollow').hide(); return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).then( console.log('Unfollowing')); } diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index ad9c886fab3..b8bd0b1fe20 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -1,25 +1,21 @@ \ No newline at end of file