[IMP]mail: stared/unstared

bzr revid: chm@openerp.com-20121012152505-1rmms2k10vjr3yd4
This commit is contained in:
Christophe Matthieu
2012-10-12 17:25:05 +02:00
parent cdff3ac73c
commit a88378cd4c
7 changed files with 80 additions and 4 deletions
+1
View File
@@ -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
+28
View File
@@ -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
}
+7
View File
@@ -99,6 +99,13 @@
'context': {'default_model': 'res.partner', 'default_is_private': False} }""/>
</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>
+8 -2
View File
@@ -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>
+7
View File
@@ -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;
}
+19 -2
View File
@@ -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;
},
});
/**
+10
View File
@@ -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>