From 76d1e4dad506ebf09b1deaf0b144dc31a943b47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 18 Sep 2012 14:23:15 +0200 Subject: [PATCH] [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 --- addons/mail/static/src/css/mail.css | 18 +++--- addons/mail/static/src/js/mail.js | 85 +++++++++++------------------ addons/mail/static/src/xml/mail.xml | 38 +++++-------- 3 files changed, 54 insertions(+), 87 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index d0e706191f7..2f9b35f1c95 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -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 /* ------------------------------------------------------------ */ diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 9cb107ca338..2f5f95fbb62 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -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 */ diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 088edee0f64..a09641e1992 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -106,25 +106,6 @@ - - - - Votes : - -
  • - - - - - - -
  • -
    -
  • @@ -161,12 +142,10 @@
  • -
  • + +
  • Reply
  • Reply
  • -
  • 1 Attachment @@ -200,4 +179,17 @@ + +
  • + + votes + + +
  • +