summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@openerp.com>2012-10-12 17:25:05 +0200
committerChristophe Matthieu <chm@openerp.com>2012-10-12 17:25:05 +0200
commita88378cd4c46b16e33e2dae335f678a84581383d (patch)
tree8ddd95f59a6a43b6d89cce6ceac2d1f56795c4d2
parentcdff3ac73cb1d0f6b87269c3667d9040904e5290 (diff)
[IMP]mail: stared/unstared
bzr revid: chm@openerp.com-20121012152505-1rmms2k10vjr3yd4
-rw-r--r--addons/mail/__init__.py1
-rw-r--r--addons/mail/mail_message.py28
-rw-r--r--addons/mail/mail_message_view.xml7
-rw-r--r--addons/mail/mail_thread_view.xml10
-rw-r--r--addons/mail/static/src/css/mail.css7
-rw-r--r--addons/mail/static/src/js/mail.js21
-rw-r--r--addons/mail/static/src/xml/mail.xml10
7 files changed, 80 insertions, 4 deletions
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'),
}
@@ -173,6 +175,24 @@ class mail_message(osv.Model):
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} }&quot;"/>
</record>
+ <record id="action_mail_star_feeds" model="ir.actions.client">
+ <field name="name">Stared</field>
+ <field name="tag">mail.wall</field>
+ <field name="params" eval="&quot;{'domain': [('star_user_ids.user_ids', 'in', [uid])],
+ 'context': {'default_model': 'res.partner', 'default_is_private': False} }&quot;"/>
+ </record>
+
<record id="action_mail_archives_feeds" model="ir.actions.client">
<field name="name">Archives</field>
<field name="tag">mail.wall</field>
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 @@
<field name="action" ref="action_mail_to_me_feeds"/>
<field name="parent_id" ref="mail_feeds"/>
</record>
+ <record id="mail_starfeeds" model="ir.ui.menu">
+ <field name="name">Stared</field>
+ <field name="sequence" eval="14"/>
+ <field name="action" ref="action_mail_star_feeds"/>
+ <field name="parent_id" ref="mail_feeds"/>
+ </record>
<record id="mail_archivesfeeds" model="ir.ui.menu">
<field name="name">Archives</field>
- <field name="sequence" eval="12"/>
+ <field name="sequence" eval="16"/>
<field name="action" ref="action_mail_archives_feeds"/>
<field name="parent_id" ref="mail_feeds"/>
</record>
<record id="mail_sentfeeds" model="ir.ui.menu">
<field name="name">Sent</field>
- <field name="sequence" eval="13"/>
+ <field name="sequence" eval="18"/>
<field name="action" ref="action_mail_sent_feeds"/>
<field name="parent_id" ref="mail_feeds"/>
</record>
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 @@
<!-- message actions (read/unread, reply, delete...) -->
<ul class="oe_header">
<li class="placeholder-mail-vote"><t t-call="mail.thread.message.vote"/></li>
+ <li class="placeholder-mail-star"><t t-call="mail.thread.message.star"/></li>
<li t-if="!widget.options.thread.display_on_flat" title="Read" class="oe_read"><a class="oe_read oe_e">W</a></li>
<li t-if="!widget.options.thread.display_on_flat" title="Set back to unread" class="oe_unread"><a class="oe_unread oe_e">h</a></li>
<li title="Quick reply"><a class="oe_reply oe_e">)</a></li>
@@ -285,4 +286,13 @@
</button>
</span>
+ <!-- mail.thread.message.star
+ Template used to display stared/unstared message in a mail.message
+ -->
+ <span t-name="mail.thread.message.star">
+ <span class="oe_left">
+ <button t-attf-class="oe_mail_starbox oe_tag #{widget.has_stared?'oe_stared':''}">*</button>
+ </span>
+ </span>
+
</template>