diff --git a/addons/mail/__init__.py b/addons/mail/__init__.py index abf714ad534..da002d13d9d 100644 --- a/addons/mail/__init__.py +++ b/addons/mail/__init__.py @@ -27,6 +27,7 @@ import mail_mail import mail_thread import mail_group import mail_vote +import mail_star import res_partner import res_users import report diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 0d5344d5095..5e9b32d93f2 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -134,6 +134,8 @@ class mail_message(osv.Model): 'subtype_id': fields.many2one('mail.message.subtype', 'Subtype'), 'vote_user_ids': fields.many2many('res.users', 'mail_vote', 'message_id', 'user_id', string='Votes', help='Users that voted for this message'), + 'star_user_ids': fields.many2many('res.users', 'mail_star', 'message_id', 'user_id', string='Stared', + help='Users that stared this message'), 'is_private': fields.boolean('Private message'), } @@ -172,6 +174,24 @@ class mail_message(osv.Model): self.write(cr, SUPERUSER_ID, message.get('id'), {'vote_user_ids': [(3, user_id)]}, context=context) return not(has_voted) or False + #------------------------------------------------------ + # Stared/unstared + #------------------------------------------------------ + + def star_toggle(self, cr, uid, ids, user_ids=None, context=None): + ''' Toggles voting. Done as SUPERUSER_ID because of write access on + mail.message not always granted. ''' + if not user_ids: + user_ids = [uid] + for message in self.read(cr, SUPERUSER_ID, ids, ['star_user_ids'], context=context): + for user_id in user_ids: + has_stared = user_id in message.get('star_user_ids') + if not has_stared: + self.write(cr, SUPERUSER_ID, message.get('id'), {'star_user_ids': [(4, user_id)]}, context=context) + else: + self.write(cr, SUPERUSER_ID, message.get('id'), {'star_user_ids': [(3, user_id)]}, context=context) + return not(has_stared) or False + #------------------------------------------------------ # Message loading for web interface #------------------------------------------------------ @@ -189,6 +209,13 @@ class mail_message(osv.Model): if vote[0] == uid: has_voted = True break + + has_stared = False + star_ids = self.pool.get('res.users').name_get(cr, SUPERUSER_ID, [user.id for user in msg.star_user_ids], context=context) + for star in star_ids: + if star[0] == uid: + has_stared = True + break try: attachment_ids = [{'id': attach[0], 'name': attach[1]} for attach in self.pool.get('ir.attachment').name_get(cr, SUPERUSER_ID, [x.id for x in msg.attachment_ids], context=context)] except (orm.except_orm, osv.except_osv): @@ -228,6 +255,7 @@ class mail_message(osv.Model): 'parent_id': msg.parent_id and msg.parent_id.id or False, 'vote_user_ids': vote_ids, 'has_voted': has_voted, + 'has_stared': has_stared, 'unread': msg.unread and msg.unread['unread'] or False } diff --git a/addons/mail/mail_message_view.xml b/addons/mail/mail_message_view.xml index 0444803893e..f5400ad731d 100644 --- a/addons/mail/mail_message_view.xml +++ b/addons/mail/mail_message_view.xml @@ -99,6 +99,13 @@ 'context': {'default_model': 'res.partner', 'default_is_private': False} }""/> + + Stared + mail.wall + + + Archives mail.wall diff --git a/addons/mail/mail_thread_view.xml b/addons/mail/mail_thread_view.xml index 65ad477042c..f179dea9122 100644 --- a/addons/mail/mail_thread_view.xml +++ b/addons/mail/mail_thread_view.xml @@ -24,15 +24,21 @@ + + Stared + + + + Archives - + Sent - + diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 0dcb3b8bcd0..bf24cd2219d 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -195,6 +195,13 @@ vertical-align: bottom; } +.openerp button.oe_mail_starbox{ + background: #ff0000; +} +.openerp button.oe_mail_starbox.oe_stared{ + background: #00FF00; +} + .openerp div.oe_mail_thread_display { white-space: normal; } diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 39035dfb402..1a994afc9da 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -403,7 +403,6 @@ openerp.mail = function(session) { * in the function. */ bind_events: function() { var self = this; - // event: click on 'Vote' button this.$el.on('click', 'a.oe_mail_fetch_more', self.on_expandable); }, @@ -483,6 +482,7 @@ openerp.mail = function(session) { this.body = param.body || false; this.vote_user_ids =param.vote_user_ids || []; this.has_voted = param.has_voted || false; + this.has_stared = param.has_stared || false; this.vote_user_ids = param.vote_user_ids || []; @@ -568,6 +568,8 @@ openerp.mail = function(session) { this.$el.on('click', 'a.oe_reply', this.on_message_reply); // event: click on 'Vote' button this.$el.on('click', 'button.oe_mail_msg_vote', this.on_vote); + // event: click on 'Star' button + this.$el.on('click', 'button.oe_mail_starbox', this.on_star); }, on_message_reply:function(event){ @@ -696,7 +698,6 @@ openerp.mail = function(session) { return res; }, - on_vote: function (event) { event.stopPropagation(); var self=this; @@ -726,6 +727,22 @@ openerp.mail = function(session) { self.$(".placeholder-mail-vote:first").empty(); self.$(".placeholder-mail-vote:first").html(vote_element); }, + + // Stared/unstared + Render star. + on_star: function (event) { + event.stopPropagation(); + var self=this; + return this.ds_message.call('star_toggle', [[self.id]]).pipe(function(star){ + self.has_stared=star; + if(self.has_stared){ + self.$('button.oe_mail_starbox').addClass('oe_stared'); + } else { + self.$('button.oe_mail_starbox').removeClass('oe_stared'); + } + }); + return false; + }, + }); /** diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index a9c32649026..f2eebe67f4e 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -185,6 +185,7 @@