[CLEAN] mail: vote: cleaned frond-end. Improved XML of vote template; this template is now directly called when rendering the message. Re-binded the vote event, cleaned function called on voting and rendering system. Added a records var on thread, holding the message values. Cleaned CSS.
bzr revid: tde@openerp.com-20120918122315-t41hgufdz71qil1z
This commit is contained in:
parent
20eee8405a
commit
76d1e4dad5
|
@ -261,15 +261,10 @@
|
|||
}
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Mail Vote System (Like or Unlike Comment)
|
||||
/* mail.vote
|
||||
/*--------------------------------------------------------------*/
|
||||
|
||||
.oe_mail_vote_image{
|
||||
height='12px';
|
||||
width='16px';
|
||||
}
|
||||
|
||||
button.oe_mail_msg_vote_like{
|
||||
.openerp .oe_mail_msg_content button.oe_mail_msg_vote {
|
||||
height:21px;
|
||||
width: 30px;
|
||||
padding: 1px;
|
||||
|
@ -277,18 +272,19 @@ button.oe_mail_msg_vote_like{
|
|||
margin-top: -4px;
|
||||
}
|
||||
|
||||
button.oe_mail_msg_vote_like:hover{
|
||||
background: #8A89BA;
|
||||
.openerp .oe_mail_msg_content button.oe_mail_msg_vote_true {
|
||||
background:#DC5F59;
|
||||
}
|
||||
|
||||
button.oe_mail_msg_vote_like span {
|
||||
.openerp .oe_mail_msg_content button.oe_mail_msg_vote span {
|
||||
color: white;
|
||||
}
|
||||
|
||||
span.oe_mail_vote_string{
|
||||
.openerp .oe_mail_msg_content span.oe_mail_vote_count{
|
||||
color: #807FB4;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* mail.compose.message form view & OpenERP hacks
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -291,6 +291,7 @@ openerp.mail = function(session) {
|
|||
truncate_limit: options.truncate_limit || 250,
|
||||
}
|
||||
// datasets and internal vars
|
||||
this.records = {};
|
||||
this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model);
|
||||
this.ds_notification = new session.web.DataSetSearch(this, 'mail.notification');
|
||||
this.ds_message = new session.web.DataSetSearch(this, 'mail.message');
|
||||
|
@ -309,56 +310,6 @@ openerp.mail = function(session) {
|
|||
return display_done && compose_done;
|
||||
},
|
||||
|
||||
//Mail vote Functionality...
|
||||
add_vote_event: function(element){
|
||||
self = this;
|
||||
vote_button = element.find('.oe_mail_msg_vote_like');
|
||||
if (vote_button)
|
||||
vote_button.click(function(){
|
||||
self.subscribe_vote($(this).attr('data-id'));
|
||||
});
|
||||
return
|
||||
},
|
||||
|
||||
// Fetch Records using updated message_id
|
||||
|
||||
fetch_voters: function (message_id) {
|
||||
var self= this
|
||||
this.ds_message.call('message_read', [[parseInt(message_id)]]).then(function(results){
|
||||
_.each(results, function(result){
|
||||
self.render_vote(result);
|
||||
});
|
||||
});
|
||||
},
|
||||
// Like and unlike..
|
||||
subscribe_vote: function(message_id){
|
||||
var self = this;
|
||||
return this.ds_message.call('vote_toggle', [[parseInt(message_id)]]).then(function(result){
|
||||
self.fetch_voters(message_id);
|
||||
});
|
||||
},
|
||||
// Find parent element using current message id.
|
||||
|
||||
find_parent_element: function(elements, message_id){
|
||||
parent_element = false;
|
||||
_.each($(elements), function(element){
|
||||
if ($(element).attr("data-id") == message_id){
|
||||
parent_element = element;
|
||||
}
|
||||
});
|
||||
return parent_element;
|
||||
},
|
||||
|
||||
// Render vote Display template.
|
||||
render_vote: function(record){
|
||||
var self = this;
|
||||
vote_element = session.web.qweb.render('VoteDisplay', {});
|
||||
// Get all element from record..
|
||||
vote_element = session.web.qweb.render('VoteDisplay', {'message_id': record.id, 'vote_count': record.vote_user_ids.length, 'has_voted': record.has_voted});
|
||||
parent_element = self.find_parent_element(".oe_mail_msg_vote", record.id);
|
||||
$(parent_element).html(vote_element).appendTo(this.add_vote_event($(parent_element)));
|
||||
},
|
||||
|
||||
/** Customize the display
|
||||
* - show_header_compose: show the composition form in the header */
|
||||
do_customize_display: function() {
|
||||
|
@ -405,6 +356,8 @@ openerp.mail = function(session) {
|
|||
'default_parent_id': parseInt(msg_id),
|
||||
'default_content_subtype': 'html'} );
|
||||
});
|
||||
// event: click on 'Vote' button
|
||||
this.$el.on('click', 'button.oe_mail_msg_vote', this.on_vote);
|
||||
},
|
||||
|
||||
on_message_delete: function (event) {
|
||||
|
@ -423,6 +376,16 @@ openerp.mail = function(session) {
|
|||
return this.ds_notification.call('set_message_read', [parseInt(msg_id)]);
|
||||
},
|
||||
|
||||
on_vote: function (event) {
|
||||
event.stopPropagation();
|
||||
var self = this;
|
||||
var message_id = $(event.srcElement).parent().data().msg_id;
|
||||
var vote_node = $(event.srcElement).parents('li').eq(0);
|
||||
if (! message_id) { return false; }
|
||||
return this.ds_message.call('vote_toggle', [[parseInt(message_id)]]).pipe(
|
||||
self.toggle_vote(message_id, vote_node));
|
||||
},
|
||||
|
||||
/**
|
||||
* Override-hack of do_action: automatically reload the chatter.
|
||||
* Normally it should be called only when clicking on 'Post/Send'
|
||||
|
@ -542,6 +505,8 @@ openerp.mail = function(session) {
|
|||
attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach);
|
||||
}
|
||||
record.is_author = mail.ChatterUtils.is_author(this, record.author_user_id[0]);
|
||||
// add to internal storage
|
||||
this.records[record.id] = record;
|
||||
// render, add the expand feature
|
||||
var rendered = session.web.qweb.render('mail.thread.message', {'record': record, 'thread': this, 'options': this.options});
|
||||
$(rendered).appendTo(this.$el.children('div.oe_mail_thread_display:first'));
|
||||
|
@ -553,9 +518,23 @@ openerp.mail = function(session) {
|
|||
moreClass: 'oe_mail_expand',
|
||||
lessClass: 'oe_mail_reduce',
|
||||
});
|
||||
|
||||
//Render Votes.
|
||||
this.render_vote(record);
|
||||
},
|
||||
|
||||
// Render vote Display template.
|
||||
toggle_vote: function (message_id, vote_node) {
|
||||
var self = this;
|
||||
var record = this.records[message_id];
|
||||
if (record.has_voted) {
|
||||
var idx = _.map(record.vote_user_ids, function (x) { return x[0]; }).indexOf(message_id);
|
||||
record.vote_user_ids.splice(idx, 1);
|
||||
}
|
||||
else {
|
||||
record.vote_user_ids.push([this.session.uid, 'Current user']);
|
||||
}
|
||||
record.has_voted = ! record.has_voted;
|
||||
var vote_element = session.web.qweb.render('mail.thread.message.vote', {'record': record});
|
||||
vote_node.empty();
|
||||
vote_node.html(vote_element);
|
||||
},
|
||||
|
||||
/** Display 'show more' button */
|
||||
|
|
|
@ -106,25 +106,6 @@
|
|||
</div>
|
||||
</ul>
|
||||
|
||||
<!-- Vote system (Like or Unlike -->
|
||||
<t t-name="VoteDisplay">
|
||||
<t t-if='vote_count'>
|
||||
<span class="oe_left oe_mail_vote_string">Votes :<t t-esc="vote_count"/></span>
|
||||
</t>
|
||||
<li>
|
||||
<t t-if="!has_voted">
|
||||
<button class="oe_mail_msg_vote_like" t-att-data-id="message_id" title="Click to Vote.">
|
||||
<span>+1</span>
|
||||
</button>
|
||||
</t>
|
||||
<t t-if="has_voted">
|
||||
<button class="oe_mail_msg_vote_like" t-att-data-id="message_id" title="Click to Unvote." style="background:#DC5F59; padding:1px">
|
||||
<span>-1</span>
|
||||
</button>
|
||||
</t>
|
||||
</li>
|
||||
</t>
|
||||
|
||||
<!-- default layout -->
|
||||
<li t-name="mail.thread.message" class="oe_mail oe_mail_thread_msg">
|
||||
<div t-attf-class="oe_mail_msg_#{record.type} oe_semantic_html_override">
|
||||
|
@ -161,12 +142,10 @@
|
|||
</li>
|
||||
<li><a t-attf-href="#model=res.partner&id=#{record.author_id[0]}"><t t-raw="record.author_id[1]"/></a></li>
|
||||
<li><span t-att-title="record.date"><t t-raw="record.timerelative"/></span></li>
|
||||
<li> <span t-att-data-id="record.id" class="oe_mail_msg_vote"></span> </li>
|
||||
<t t-call="mail.thread.message.vote"/>
|
||||
<!-- <li><span t-att-data-id="record.id" class="oe_mail_msg_vote"></span></li> -->
|
||||
<li t-if="options.show_reply"><a class="oe_mail_msg_reply">Reply</a></li>
|
||||
<li t-if="options.show_reply_by_email"><a class="oe_mail_msg_reply_by_email" t-attf-data-msg_id="{record.id}">Reply</a></li>
|
||||
<!-- uncomment when merging vote
|
||||
<li><a href="#">Like</a></li>
|
||||
-->
|
||||
<li t-if="record.attachment_ids.length > 0">
|
||||
<a class="oe_mail_msg_view_attachments">
|
||||
<t t-if="record.attachment_ids.length == 1">1 Attachment</t>
|
||||
|
@ -200,4 +179,17 @@
|
|||
</ul>
|
||||
</t>
|
||||
|
||||
<!-- mail.thread.message.vote
|
||||
Template used to display Like/Unlike in a mail.message
|
||||
-->
|
||||
<li t-name="mail.thread.message.vote">
|
||||
<t t-if='record.vote_user_ids.length > 0'>
|
||||
<span class="oe_left oe_mail_vote_count"><t t-esc="record.vote_user_ids.length"/> votes</span>
|
||||
</t>
|
||||
<button t-attf-class="oe_mail_msg_vote oe_mail_msg_vote_#{record.has_voted}" t-attf-data-msg_id="{record.id}">
|
||||
<t t-if="! record.has_voted"><span>+1</span></t>
|
||||
<t t-if="record.has_voted"><span>-1</span></t>
|
||||
</button>
|
||||
</li>
|
||||
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue