From 36bbda3d45b33fbd00073173c095bbd5c503c0f8 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 18 Apr 2013 00:04:51 -0700 Subject: [PATCH] fixes #1085 --- app/assets/javascripts/posts.js | 31 ++++++++++-------------------- app/assets/javascripts/utility.js | 2 +- app/models/post.rb | 11 ++++++----- app/views/post_votes/create.js.erb | 3 ++- db/structure.sql | 7 +++++-- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index 1cb1197c7..897605fc0 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -281,17 +281,19 @@ $("#edit").hide(); } - Danbooru.Post.notice_update = function(x) { + Danbooru.Post.notice_update = function(x, hide_msg) { if (x === "inc") { Danbooru.Post.pending_update_count += 1; Danbooru.notice("Updating posts (" + Danbooru.Post.pending_update_count + " pending)..."); } else { Danbooru.Post.pending_update_count -= 1; - if (Danbooru.Post.pending_update_count < 1) { - Danbooru.notice("Posts updated"); - } else { - Danbooru.notice("Updating posts (" + Post.pending_update_count + " pending)..."); + if (!!hide_msg) { + if (Danbooru.Post.pending_update_count < 1) { + Danbooru.notice("Posts updated"); + } else { + Danbooru.notice("Updating posts (" + Post.pending_update_count + " pending)..."); + } } } } @@ -304,23 +306,10 @@ } Danbooru.Post.vote = function(score, id) { - Danbooru.Post.notice_update("inc"); + Danbooru.notice("Voting..."); - $.ajax({ - type: "POST", - url: "/posts/" + id + "/votes", - data: { - score: score - }, - complete: function() { - Danbooru.Post.notice_update("dec"); - }, - success: function(data, status, xhr) { - $("post-score-" + data.post_id).html(data.score); - }, - error: function(data, status, xhr) { - Danbooru.notice("Error: " + data.reason); - } + $.post("/posts/" + id + "/votes.js", { + score: score }); } diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index e56b905d3..4058cfeab 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -18,7 +18,7 @@ } else { top = element.offset().top - 10; } - $('html, body').animate({scrollTop: top}, 200, "linear", function() {Danbooru.scrolling = false;}); + $('html, body').animate({scrollTop: top}, 300, "linear", function() {Danbooru.scrolling = false;}); } Danbooru.notice = function(msg) { diff --git a/app/models/post.rb b/app/models/post.rb index 70a9d8e18..790ad1fbf 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -527,8 +527,8 @@ class Post < ActiveRecord::Base def add_favorite!(user) return if favorited_by?(user.id) append_user_to_fav_string(user.id) - increment!(:fav_count) - increment!(:score) if CurrentUser.is_privileged? + Post.connection.execute_sql("update posts set fav_count = fav_count + 1 where id = #{id}") + Post.connection.execute_sql("update posts set score = score + 1 where id = #{id}") if CurrentUser.is_privileged? user.add_favorite!(self) end @@ -538,8 +538,8 @@ class Post < ActiveRecord::Base def remove_favorite!(user) return unless favorited_by?(user.id) - decrement!(:fav_count) - decrement!(:score) if CurrentUser.is_privileged? + Post.connection.execute_sql("update posts set fav_count = fav_count - 1 where id = #{id}") + Post.connection.execute_sql("update posts set score = score - 1 where id = #{id}") if CurrentUser.is_privileged? delete_user_from_fav_string(user.id) user.remove_favorite!(self) end @@ -597,7 +597,7 @@ class Post < ActiveRecord::Base module VoteMethods def can_be_voted_by?(user) - !votes.exists?(["user_id = ?", user.id]) + !PostVote.exists?(:user_id => user.id, :post_id => id) end def vote!(score) @@ -612,6 +612,7 @@ class Post < ActiveRecord::Base votes.create(:score => score) else + puts "raising" raise PostVote::Error.new("You have already voted for this post") end end diff --git a/app/views/post_votes/create.js.erb b/app/views/post_votes/create.js.erb index 49f7f9768..0483156a4 100644 --- a/app/views/post_votes/create.js.erb +++ b/app/views/post_votes/create.js.erb @@ -1,5 +1,6 @@ <% if @error %> - Danbooru.error("<%= j @error.to_s %>"); + Danbooru.notice("<%= j @error.to_s %>"); <% else %> + Danbooru.notice("Vote saved"); $("#score-for-post-<%= @post.id %>").html(<%= @post.score %>); <% end %> diff --git a/db/structure.sql b/db/structure.sql index 71a55762a..fce0cfba7 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2691,7 +2691,8 @@ CREATE TABLE users ( enable_privacy_mode boolean DEFAULT false NOT NULL, enable_sequential_post_navigation boolean DEFAULT true NOT NULL, per_page integer DEFAULT 20 NOT NULL, - hide_deleted_posts boolean DEFAULT false NOT NULL + hide_deleted_posts boolean DEFAULT false NOT NULL, + style_usernames boolean DEFAULT false NOT NULL ); @@ -6406,4 +6407,6 @@ INSERT INTO schema_migrations (version) VALUES ('20130331182719'); INSERT INTO schema_migrations (version) VALUES ('20130401013601'); -INSERT INTO schema_migrations (version) VALUES ('20130409191950'); \ No newline at end of file +INSERT INTO schema_migrations (version) VALUES ('20130409191950'); + +INSERT INTO schema_migrations (version) VALUES ('20130417221643'); \ No newline at end of file