diff --git a/plugins/vote/lib/ext/vote.rb b/plugins/vote/lib/ext/vote.rb new file mode 100644 index 0000000..0b5729e --- /dev/null +++ b/plugins/vote/lib/ext/vote.rb @@ -0,0 +1,18 @@ +require_dependency 'models/vote' + +class Vote + + validate :verify_target_archived + + def verify_target_archived + + if voteable.kind_of?(Article) || voteable.kind_of?(Comment) + if voteable.archived? + errors.add(:base, _("The target is achived and can't accept votes")) + false + end + end + + end + +end diff --git a/plugins/vote/lib/vote_plugin_helper.rb b/plugins/vote/lib/vote_plugin_helper.rb index 78099bb..63e59a9 100644 --- a/plugins/vote/lib/vote_plugin_helper.rb +++ b/plugins/vote/lib/vote_plugin_helper.rb @@ -2,8 +2,10 @@ module VotePluginHelper def vote_partial(target, like = true, load_voters=false) vote = like ? 1 : -1 + like_action = like ? 'like' : 'dislike' type = target.kind_of?(Article) ? 'article' : target.kind_of?(Comment) ? 'comment' : nil + disable_vote = target.archived? ? true : false proc do settings = Noosfero::Plugin::Settings.new(environment, VotePlugin) @@ -14,7 +16,7 @@ module VotePluginHelper active = user ? (like ? user.voted_for?(target) : user.voted_against?(target)) : false count = like ? target.votes_for : target.votes_against - render(:partial => 'vote/vote', :locals => {:target => target, :active => active, :action => like_action, :count => count, :voters => voters, :vote => vote, :model => type }) + render(:partial => 'vote/vote', :locals => {:target => target, :active => active, :action => like_action, :count => count, :voters => voters, :vote => vote, :model => type, :disable_vote => disable_vote }) else "" end diff --git a/plugins/vote/public/style.css b/plugins/vote/public/style.css index d128764..7d0cd06 100644 --- a/plugins/vote/public/style.css +++ b/plugins/vote/public/style.css @@ -73,3 +73,12 @@ #article .action .vote-detail img { vertical-align: bottom; } + +.comments-action-bar span.disabled a, +.comments-action-bar span.disabled a:hover, +.vote-actions span.disabled a, +.vote-actions span.disabled a:hover { + opacity: 0.5; + pointer-events: none; + cursor: default; +} diff --git a/plugins/vote/public/vote_actions.js b/plugins/vote/public/vote_actions.js index 86268af..3ccbd45 100644 --- a/plugins/vote/public/vote_actions.js +++ b/plugins/vote/public/vote_actions.js @@ -16,7 +16,9 @@ function openVotersDialog(div) { clearTimeout(openEvent); var url = $(div).data('reload_url'); hideAllVoteDetail(); - $.post(url); + if(url && url != '#'){ + $.post(url); + } } jQuery('body').live('click', function() { hideAllVoteDetail(); }); diff --git a/plugins/vote/test/functional/vote_plugin_profile_controller_test.rb b/plugins/vote/test/functional/vote_plugin_profile_controller_test.rb index a81fe85..db30150 100644 --- a/plugins/vote/test/functional/vote_plugin_profile_controller_test.rb +++ b/plugins/vote/test/functional/vote_plugin_profile_controller_test.rb @@ -35,6 +35,16 @@ class VotePluginProfileControllerTest < ActionController::TestCase assert profile.votes.empty? end + should 'not vote if a target is archived' do + article = Article.create!(:profile => profile, :name => 'Archived article', :archived => true) + comment = Comment.create!(:body => 'Comment test', :source => article, :author => profile) + xhr :post, :vote, :profile => profile.identifier, :id => article.id, :model => 'article', :vote => 1 + assert profile.votes.empty? + + xhr :post, :vote, :profile => profile.identifier, :id => comment.id, :model => 'comment', :vote => 1 + assert !profile.voted_for?(comment) + end + should 'like comment' do xhr :post, :vote, :profile => profile.identifier, :id => comment.id, :model => 'comment', :vote => 1 assert profile.voted_for?(comment) diff --git a/plugins/vote/views/vote/_vote.html.erb b/plugins/vote/views/vote/_vote.html.erb index 0c2bc14..bbb5de3 100644 --- a/plugins/vote/views/vote/_vote.html.erb +++ b/plugins/vote/views/vote/_vote.html.erb @@ -1,9 +1,14 @@ <% -url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :vote, :id => target.id, :model => model, :vote => vote) -reload_url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :reload_vote, :id => target.id, :model => model, :vote => vote) +if disable_vote + url = reload_url = '#' + class_action = 'disabled' +else + url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :vote, :id => target.id, :model => model, :vote => vote) + reload_url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :reload_vote, :id => target.id, :model => model, :vote => vote) +end %> - class="vote-action action <%= action %>-action"> + class="vote-action action <%= action %>-action <%= class_action %>"> <%= link_to content_tag(:span, count, :class=>'like-action-counter') + content_tag(:span, '', :class=>"action-icon #{action}"), url, :class => "#{active ? 'like-action-active':''} #{user ? '':'disabled'} require-login-popup" %> -- libgit2 0.21.2