Bharat Devnani (Open ERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-vote-system-bde
into lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
Requested reviews:
OpenERP R&D Team (openerp-dev)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-vote-system-bde/+merge/104506
Hello Sir,
I have added the functionality of Like, Unlike (Vote) in openchatter.
Which allows logged in user to like particular document, and even provides
facility to unlike the liked document.
Thanks & Regards,
Devnani Bharat R.
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-vote-system-bde/+merge/104506
Your team OpenERP R&D Team is requested to review the proposed merge of
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-vote-system-bde
into lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
=== modified file 'mail/mail_message.py'
--- mail/mail_message.py 2012-04-06 12:37:32 +0000
+++ mail/mail_message.py 2012-05-03 09:30:28 +0000
@@ -599,5 +599,5 @@
def cancel(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state':'cancel'}, context=context)
return True
-
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'mail/mail_thread.py'
--- mail/mail_thread.py 2012-04-06 12:37:32 +0000
+++ mail/mail_thread.py 2012-05-03 09:30:28 +0000
@@ -788,5 +788,18 @@
notif_msg_ids = msg_ids
to_del_notif_ids = notif_obj.search(cr, uid, ['&', ('user_id', '=', uid), ('message_id', 'in', notif_msg_ids)], context=context)
return notif_obj.unlink(cr, uid, to_del_notif_ids, context=context)
+
+
+class mail_vote(osv.osv):
+ _name = 'mail.vote'
+ _description = 'Mail Vote'
+
+ _columns = {
+ 'res_model_id': fields.char('Related Document Model', size=64),
+ 'res_id': fields.char('Related Document ID', size=32),
+ 'user_id': fields.many2one('res.users', 'User'),
+ }
+
+mail_vote()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'mail/static/src/js/mail.js'
--- mail/static/src/js/mail.js 2012-04-19 08:58:38 +0000
+++ mail/static/src/js/mail.js 2012-05-03 09:30:28 +0000
@@ -160,6 +160,7 @@
}
return false;
});
+
// event: click on 'hide' in msg
this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_hide', 'click', function (event) {
//console.log('hiding');
@@ -253,7 +254,6 @@
self.display_comment(record);
self.thread = new mail.Thread(self, {'res_model': self.params.res_model, 'res_id': self.params.res_id, 'uid': self.params.uid,
'records': sub_msgs, 'thread_level': (self.params.thread_level-1), 'parent_id': record.id});
- self.$element.find('li.oe_mail_thread_msg:last').append('<div class="oe_mail_thread_subthread"/>');
self.thread.appendTo(self.$element.find('div.oe_mail_thread_subthread:last'));
}
else if (self.params.thread_level == 0) {
@@ -480,14 +480,17 @@
this._super.apply(this, arguments);
this.see_subscribers = true;
this.thread = null;
+
// datasets
this.ds = new session.web.DataSet(this, this.view.model);
this.ds_users = new session.web.DataSet(this, 'res.users');
+ this.mail_vote = new session.web.DataSetSearch(this, 'mail.vote', null, null);
},
start: function() {
this._super.apply(this, arguments);
var self = this;
+
// bind buttons
this.$element.find('button.oe_mail_button_followers').click(function () { self.do_toggle_followers(); }).hide();
this.$element.find('button.oe_mail_button_follow').click(function () { self.do_follow(); })
@@ -496,18 +499,111 @@
this.$element.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); })
.mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
.mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
+ this.$element.find('button.oe_mail_button_like').click(function () { self.create_entry(); }).hide();
+ this.$element.find('button.oe_mail_button_unlike').click(function () { self.delete_entry(); }).hide();
+
+ this.$element.find('div.oe_votes').show();
+
+ if (self.view.datarecord.id){
+ this.mail_vote.call('search', [[['res_model_id', '=', self.ds.model],['res_id','=', self.view.datarecord.id]]]).then(function (records){
+ records = records.length;
+ self.display_votes(records);
+ });
+ }
+
this.reinit();
},
-
+
+ create_entry: function () {
+ var self = this;
+ this.mail_vote.call('search', [[['res_model_id', '=', this.ds.model],['res_id','=', this.view.datarecord.id],['user_id','=', this.ds_users.session.uid]]]).then(function (search_records) {
+ var rec_length = search_records.length;
+ if (rec_length == 0){
+ self.mail_vote.create({'res_model_id': self.ds.model, 'res_id': self.view.datarecord.id, 'user_id': self.ds_users.session.uid})
+ }
+ self.$element.find('button.oe_mail_button_like').hide();
+ self.$element.find('button.oe_mail_button_unlike').show();
+ self.get_votes(self.ds.model, self.view.datarecord.id);
+ });
+ },
+
+ get_votes: function (model, active_id) {
+ active_id = active_id.toString();
+ var self = this;
+ this.mail_vote.read_slice([]).then(function(records) {
+ self.mail_vote.call('search', [[['res_model_id', '=', model],['res_id','=',active_id]]]).done(function (i_records){
+ records = i_records.length;
+ self.display_votes(records);
+ });
+ });
+ },
+
+ delete_entry: function(){
+ var self = this;
+ this.mail_vote.call('search', [[['res_model_id', '=', self.ds.model],['res_id','=', self.view.datarecord.id],['user_id','=', self.ds_users.session.uid]]]).done(function (search_val) {
+ self.mail_vote.unlink(search_val).done(function(){
+ self.get_votes_unlike(self.ds.model, self.view.datarecord.id)
+ });
+ });
+ this.$element.find('button.oe_mail_button_like').show();
+ this.$element.find('button.oe_mail_button_unlike').hide();
+ },
+
+ get_votes_unlike: function (model, active_id) {
+ active_id = active_id.toString();
+ var self = this;
+ this.mail_vote.call('search', [[['res_model_id', '=', model],['res_id','=', active_id]]]).then(function (i_records){
+ i_records = i_records.length;
+ tot_records = i_records;
+ self.display_votes(tot_records);
+ });
+ },
+
+ display_votes: function(i_records){
+ var sub_node = this.$element.find('div.oe_votes')
+ sub_node.empty();
+ this.$element.find('div.oe_votes').show();
+
+ if (! i_records){
+ $('<h4/>').html('Likes (' + (0) + ')').appendTo(sub_node);
+ }
+ else
+ {
+ $('<h4/>').html('Likes (' + (i_records) + ')').appendTo(sub_node);
+ }
+ },
+
destroy: function () {
this._super.apply(this, arguments);
},
reinit: function() {
+ var self = this;
this.see_subscribers = true;
this.$element.find('button.oe_mail_button_followers').html('Hide followers')
this.$element.find('button.oe_mail_button_follow').hide();
this.$element.find('button.oe_mail_button_unfollow').hide();
+
+ this.$element.find('div.oe_votes').show();
+
+ if (this.view.datarecord.id){
+ this.mail_vote.call('search', [[['res_model_id', '=', self.ds.model],['res_id','=', self.view.datarecord.id]]]).then(function (records){
+ records = records.length;
+ self.display_votes(records);
+ });
+
+ self.mail_vote.call('search', [[['res_model_id', '=', self.ds.model],['res_id','=', self.view.datarecord.id],['user_id','=', self.ds_users.session.uid]]]).then(function (records){
+ rec_length = records.length;
+ if (rec_length == 0){
+ self.$element.find('button.oe_mail_button_like').show();
+ }
+ else
+ {
+ self.$element.find('button.oe_mail_button_like').hide();
+ self.$element.find('button.oe_mail_button_unlike').show();
+ }
+ });
+ }
},
set_value: function() {
@@ -553,6 +649,7 @@
self.$element.find('button.oe_mail_button_unfollow').hide(); }
},
+
do_follow: function () {
return this.ds.call('message_subscribe', [[this.view.datarecord.id]]).pipe(this.proxy('fetch_subscribers'));
},
=== modified file 'mail/static/src/xml/mail.xml'
--- mail/static/src/xml/mail.xml 2012-04-18 11:32:17 +0000
+++ mail/static/src/xml/mail.xml 2012-05-03 09:30:28 +0000
@@ -33,13 +33,22 @@
<div class="oe_mail_recthread_actions">
<button type="button" class="oe_mail_button_follow oe_mail_button_mouseout">Not following</button>
<button type="button" class="oe_mail_button_unfollow oe_mail_button_mouseout">Following</button>
+ <button type="button" class="oe_mail_button_like oe_mail_button_mouseout">Like</button>
+ <button type="button" class="oe_mail_button_unlike oe_mail_button_mouseout">Unlike</button>
+ <br/>
<button type="button" class="oe_mail_button_followers">Display followers</button>
</div>
+
+ <div class="oe_votes">
+ <h4>Likes</h4>
+ </div>
+
<div class="oe_mail_recthread_followers">
<h4>Followers</h4>
<div class="oe_mail_followers_display">
</div>
</div>
+
</div>
</div>
@@ -81,6 +90,7 @@
</span>
<t t-if="display['show_reply']"><a href="#" class="oe_mail_oe_space oe_mail_msg_reply oe_mail_oe_intlink"> Reply</a> </t>
<t t-if="display['show_delete']">
+ <t t-if="thread._is_author(record.user_id[0])"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_oe_space oe_mail_msg_like oe_mail_oe_intlink"> Like </a></t>
<t t-if="thread._is_author(record.user_id[0])"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_oe_space oe_mail_msg_delete oe_mail_oe_intlink"> Delete </a></t>
</t>
<t t-if="display['show_hide']">
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp