[imp]:improve own_post or annonymous user vote alert

bzr revid: sunilsharma.sharma07@gmail.com-20140326121424-a1oompnmu2f0132t
This commit is contained in:
Sunil Sharma (OpenERP) 2014-03-26 17:44:24 +05:30
parent 7435424cc4
commit 556d7dfa2a
3 changed files with 15 additions and 5 deletions

View File

@ -411,8 +411,10 @@ class website_forum(http.Controller):
return request.website.render("website_forum.users", values)
@http.route('/forum/post_vote/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
@http.route('/forum/post_vote/', type='json', auth="public", multilang=True, methods=['POST'], website=True)
def post_vote(self, **post):
if not request.session.uid:
return {'error': 'anonymous_user'}
cr, uid, context, post_id = request.cr, request.uid, request.context, int(post.get('post_id'))
Vote = request.registry['website.forum.post.vote']
return Vote.vote(cr, uid, post_id, post.get('vote'), context)

View File

@ -338,7 +338,7 @@ class Vote(osv.Model):
#user can not vote on own post.
post = self.pool['website.forum.post'].browse(cr, uid, post_id, context=context)
if post.user_id.id == uid:
return False
return {'error': 'own_post'}
vote_ids = self.search(cr, uid, [('post_id', '=', post_id), ('user_id','=',uid)], context=context)
if vote_ids:
#when user will click again on vote it should set it 0.

View File

@ -4,17 +4,25 @@ $(document).ready(function () {
ev.preventDefault();
var $link = $(ev.currentTarget);
var value = $link.attr("value")
openerp.jsonRpc("/forum/post_vote/", 'call', {
'post_id': $link.attr("id"),
'vote': value})
.then(function (data) {
if (data == false){
vote_alert = $link.parent().find("#vote_alert");
if (vote_alert.length == 0) {
if (data['error']){
if (data['error'] == 'own_post'){
var $warning = $('<div class="alert alert-danger alert-dismissable" id="vote_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">&times;</button>'+
'Sorry, you cannot vote for your own posts'+
'</div>');
} else if (data['error'] == 'anonymous_user'){
var $warning = $('<div class="alert alert-danger alert-dismissable" id="vote_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">&times;</button>'+
'Sorry, anonymous users cannot vote'+
'</div>');
}
vote_alert = $link.parent().find("#vote_alert");
if (vote_alert.length == 0) {
$link.parent().append($warning);
}
} else {