partial fix for #1263 (posts)
This commit is contained in:
@@ -143,6 +143,8 @@
|
|||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".unvote-post-link").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Post.initialize_post_relationship_previews = function() {
|
Danbooru.Post.initialize_post_relationship_previews = function() {
|
||||||
|
|||||||
@@ -82,6 +82,13 @@ class PostsController < ApplicationController
|
|||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unvote
|
||||||
|
@post = Post.find(params[:id])
|
||||||
|
@post.unvote!
|
||||||
|
rescue PostVote::Error => x
|
||||||
|
@error = x
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def tag_query
|
def tag_query
|
||||||
params[:tags] || (params[:post] && params[:post][:tags])
|
params[:tags] || (params[:post] && params[:post][:tags])
|
||||||
|
|||||||
@@ -650,6 +650,24 @@ class Post < ActiveRecord::Base
|
|||||||
raise PostVote::Error.new("You have already voted for this post")
|
raise PostVote::Error.new("You have already voted for this post")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unvote!
|
||||||
|
if can_be_voted_by?(CurrentUser.user)
|
||||||
|
raise PostVote::Error.new("You have not voted for this post")
|
||||||
|
else
|
||||||
|
vote = votes.where("user_id = ?", CurrentUser.user.id).first
|
||||||
|
|
||||||
|
if vote.score == 1
|
||||||
|
Post.update_all("score = score - 1, up_score = up_score - 1", {:id => id})
|
||||||
|
self.score -= 1
|
||||||
|
else
|
||||||
|
Post.update_all("score = score + 1, down_score = down_score + 1", {:id => id})
|
||||||
|
self.score += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
vote.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module CountMethods
|
module CountMethods
|
||||||
|
|||||||
@@ -4,3 +4,5 @@
|
|||||||
Danbooru.notice("Vote saved");
|
Danbooru.notice("Vote saved");
|
||||||
$("#score-for-post-<%= @post.id %>").html(<%= @post.score %>);
|
$("#score-for-post-<%= @post.id %>").html(<%= @post.score %>);
|
||||||
<% end %>
|
<% end %>
|
||||||
|
$("#vote-links-for-post-<%= @post.id %>").hide();
|
||||||
|
$("#unvote-link-for-post-<%= @post.id %>").show();
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li>Source: <%= post_source_tag(post) %></li>
|
<li>Source: <%= post_source_tag(post) %></li>
|
||||||
<li>Rating: <%= post.pretty_rating %></li>
|
<li>Rating: <%= post.pretty_rating %></li>
|
||||||
<li>Score: <span id="score-for-post-<%= post.id %>"><%= post.score %></span> <% if CurrentUser.is_gold? %>(vote <%= link_to "up", post_votes_path(:post_id => post.id, :score => "up"), :remote => true, :method => :post %>/<%= link_to "down", post_votes_path(:post_id => post.id, :score => "down"), :remote => true, :method => :post %>)<% end %></li>
|
<li>Score: <span id="score-for-post-<%= post.id %>"><%= post.score %></span> <% if CurrentUser.is_gold? %>(<span id="vote-links-for-post-<%= post.id %>">vote <%= link_to "up", post_votes_path(:post_id => post.id, :score => "up"), :remote => true, :method => :post %>/<%= link_to "down", post_votes_path(:post_id => post.id, :score => "down"), :remote => true, :method => :post %></span><%= link_to "unvote", unvote_post_path(post), :remote => true, :method => :put, :id => "unvote-link-for-post-#{post.id}", :class => "unvote-post-link" %>)<% end %></li>
|
||||||
<li>Favorites: <span id="favcount-for-post-<%= post.id %>"><%= post.fav_count %></span>
|
<li>Favorites: <span id="favcount-for-post-<%= post.id %>"><%= post.fav_count %></span>
|
||||||
<% if CurrentUser.is_gold? %>
|
<% if CurrentUser.is_gold? %>
|
||||||
<%= link_to "»".html_safe, "#", :id => "show-favlist-link" %>
|
<%= link_to "»".html_safe, "#", :id => "show-favlist-link" %>
|
||||||
|
|||||||
8
app/views/posts/unvote.js.erb
Normal file
8
app/views/posts/unvote.js.erb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<% if @error %>
|
||||||
|
Danbooru.notice("<%= j @error.to_s %>");
|
||||||
|
<% else %>
|
||||||
|
Danbooru.notice("Unvoted successfully");
|
||||||
|
$("#score-for-post-<%= @post.id %>").html(<%= @post.score %>);
|
||||||
|
<% end %>
|
||||||
|
$("#vote-links-for-post-<%= @post.id %>").show();
|
||||||
|
$("#unvote-link-for-post-<%= @post.id %>").hide();
|
||||||
@@ -154,6 +154,7 @@ Danbooru::Application.routes.draw do
|
|||||||
put :revert
|
put :revert
|
||||||
put :copy_notes
|
put :copy_notes
|
||||||
get :show_seq
|
get :show_seq
|
||||||
|
put :unvote
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :post_appeals
|
resources :post_appeals
|
||||||
|
|||||||
Reference in New Issue
Block a user