diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index d315237f1..8a155f5a2 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -8,18 +8,12 @@ class FavoritesController < ApplicationController
end
def create
- @favorite = Favorite.create(
- :user_id => CurrentUser.id,
- :post_id => params[:id]
- )
+ Post.find(params[:id]).add_favorite(CurrentUser.user)
render :nothing => true
end
def destroy
- Favorite.destroy(
- :user_id => CurrentUser.id,
- :post_id => params[:id]
- )
+ Post.find(params[:id]).remove_favorite(CurrentUser.user)
render :nothing => true
end
end
diff --git a/app/models/post.rb b/app/models/post.rb
index 2a61fe666..77a15b021 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -30,7 +30,7 @@ class Post < ActiveRecord::Base
scope :commented_before, lambda {|date| where("last_commented_at < ?", date).order("last_commented_at DESC")}
scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
- scope :before_id, lambda {|id| where(["posts.id < ?", id])}
+ scope :before_id, lambda {|id| id.present? ? where(["posts.id < ?", id]) : where("TRUE")}
scope :tag_match, lambda {|query| Post.tag_match_helper(query)}
module FileMethods
diff --git a/app/models/upload.rb b/app/models/upload.rb
index 4bf28a256..7b2ccce4e 100644
--- a/app/models/upload.rb
+++ b/app/models/upload.rb
@@ -96,11 +96,8 @@ class Upload < ActiveRecord::Base
def merge_tags(post)
post.tag_string += " #{tag_string}"
- post.updater_id = uploader_id
- post.updater_ip_addr = uploader_ip_addr
post.save
update_attribute(:status, "duplicate: #{post.id}")
- raise
end
end
@@ -259,8 +256,8 @@ class Upload < ActiveRecord::Base
self.file_path = temp_file_path
- if file.local_path
- FileUtils.cp(file.local_path, file_path)
+ if file.tempfile
+ FileUtils.cp(file.tempfile.path, file_path)
else
File.open(file_path, 'wb') do |out|
out.write(file.read)
diff --git a/app/views/comments/partials/new/_form.html.erb b/app/views/comments/partials/new/_form.html.erb
index 776b24c3b..8a1188a24 100644
--- a/app/views/comments/partials/new/_form.html.erb
+++ b/app/views/comments/partials/new/_form.html.erb
@@ -1,9 +1,10 @@
+
+<%= form_tag(comments_path) do %>
+ <%= hidden_field "comment", "post_id", :value => post.id %>
+ <%= text_area "comment", "body", :size => "60x7" %>
+
+ <%= submit_tag "Post" %>
+ <%= submit_tag "Preview" %>
+<% end %>
diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb
index d1ab79d21..5b3d94866 100644
--- a/app/views/layouts/default.html.erb
+++ b/app/views/layouts/default.html.erb
@@ -1,10 +1,12 @@
- <%= @page_title %>
+ <%= yield :page_title %>
<%= csrf_meta_tag %>
+
+
<% unless CurrentUser.user.blacklisted_tags.blank? %>
<% end %>
diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb
index 969d83622..0bfc23295 100644
--- a/app/views/posts/index.html.erb
+++ b/app/views/posts/index.html.erb
@@ -62,7 +62,7 @@
<% content_for(:page_title) do %>
- / <%= @post_set.tags %>
+ /<%= @post_set.tags %>
<% end %>
<%= render :partial => "posts/partials/common/secondary_links" %>
diff --git a/app/views/posts/partials/show/_options.html.erb b/app/views/posts/partials/show/_options.html.erb
index 8d3b3642d..aa304e004 100644
--- a/app/views/posts/partials/show/_options.html.erb
+++ b/app/views/posts/partials/show/_options.html.erb
@@ -1,7 +1,7 @@
<%= resize_image_links(post, CurrentUser.user) %>
- - <%= link_to "Favorite", "#" %>
- - <%= link_to "Unfavorite", "#" %>
+ - <%= link_to "Favorite", "#", :id => "add-to-favorites" %>

+ - <%= link_to "Unfavorite", "#", :id => "remove-from-favorites" %>

- <%= link_to "Translate", "#" %>
- <%= link_to "Unapprove", "#" %>
<% if CurrentUser.user.is_janitor? %>
diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb
index cc89a5cd8..b0bb669f4 100644
--- a/app/views/posts/show.html.erb
+++ b/app/views/posts/show.html.erb
@@ -55,13 +55,14 @@
<% content_for(:page_title) do %>
- / <%= @post.tag_string %>
+ /p/<%= @post.tag_string %>
<% end %>
<% content_for(:html_header) do %>
+
<% end %>
<%= render :partial => "posts/partials/common/secondary_links" %>
diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb
index 4299196b1..5e85716a6 100644
--- a/app/views/sessions/new.html.erb
+++ b/app/views/sessions/new.html.erb
@@ -1,7 +1,7 @@
- Login
+ Sign In
<%= form_tag(session_path) do %>
@@ -33,12 +33,12 @@
- <%= link_to "I don't have an account", new_user_path %>
- <%= link_to "I forgot my password", reset_password_path %>
- - <%= link_to "I forgot my login", login_reminder_path %>
+ - <%= link_to "I forgot my user name", login_reminder_path %>
<% content_for(:page_title) do %>
- / login
+ /sign in
<% end %>
diff --git a/app/views/uploads/update.js.erb b/app/views/uploads/update.js.erb
new file mode 100644
index 000000000..0dcd5d9e3
--- /dev/null
+++ b/app/views/uploads/update.js.erb
@@ -0,0 +1 @@
+location.reload()
\ No newline at end of file
diff --git a/app/views/uploads/update.js.rjs b/app/views/uploads/update.js.rjs
deleted file mode 100644
index 869438706..000000000
--- a/app/views/uploads/update.js.rjs
+++ /dev/null
@@ -1 +0,0 @@
-page.reload
diff --git a/public/images/wait.gif b/public/images/wait.gif
new file mode 100644
index 000000000..a0e37d53d
Binary files /dev/null and b/public/images/wait.gif differ
diff --git a/public/javascripts/compiled/default.js b/public/javascripts/compiled/default.js
index 18f6dffcb..e1e22dd2b 100644
--- a/public/javascripts/compiled/default.js
+++ b/public/javascripts/compiled/default.js
@@ -1071,7 +1071,6 @@ $(document).ready(function() {
body: $(e.target).closest("form").find("textarea").val()
},
success: function(data, text_status, xhr) {
- console.log($(this).closest("div.new-comment").find("div.comment-preview"));
$(this).closest("div.new-comment").find("div.comment-preview").show().html(data);
},
type: "post"
@@ -1110,3 +1109,72 @@ $(document).ready(function() {
$("#p2").hide();
}
});
+(function() {
+ Danbooru.Favorite = {};
+
+ Danbooru.Favorite.initialize_all = function() {
+ this.initialize_add_to_favorites();
+ this.initialize_remove_from_favorites();
+ this.hide_or_remove_add_to_favorites_link();
+ }
+
+ Danbooru.Favorite.hide_or_remove_add_to_favorites_link = function() {
+ var favorites = $("meta[name=favorites]").attr("content");
+ var current_user = $("meta[name=current-user-id]").attr("content");
+ var regexp = new RegExp("\\bfav:" + current_user + "\\b");
+ if (favorites.match(regexp)) {
+ $("a#add-to-favorites").hide();
+ } else {
+ $("a#remove-from-favorites").hide();
+ }
+ }
+
+ Danbooru.Favorite.initialize_add_to_favorites = function() {
+ $("a#add-to-favorites").click(function(e) {
+ e.stopPropagation();
+
+ $.ajax({
+ url: "/favorites",
+ data: {
+ id: $("meta[name=post-id]").attr("content")
+ },
+ beforeSend: function() {
+ $("img#add-to-favorites-wait").show();
+ },
+ success: function(data, text_status, xhr) {
+ $("a#add-to-favorites").hide();
+ $("a#remove-from-favorites").show();
+ $("img#add-to-favorites-wait").hide();
+ },
+ type: "post"
+ });
+
+ return false;
+ });
+ }
+
+ Danbooru.Favorite.initialize_remove_from_favorites = function() {
+ $("a#remove-from-favorites").click(function(e) {
+ e.stopPropagation();
+
+ $.ajax({
+ url: "/favorites/" + $("meta[name=post-id]").attr("content"),
+ beforeSend: function() {
+ $("img#remove-from-favorites-wait").show();
+ },
+ success: function(data, text_status, xhr) {
+ $("a#add-to-favorites").show();
+ $("a#remove-from-favorites").hide();
+ $("img#remove-from-favorites-wait").hide();
+ },
+ type: "delete"
+ });
+
+ return false;
+ });
+ }
+})();
+
+$(document).ready(function() {
+ Danbooru.Favorite.initialize_all();
+});
diff --git a/public/javascripts/src/app/comments.js b/public/javascripts/src/app/comments.js
index e0f35b9a9..fc2b1e0a4 100644
--- a/public/javascripts/src/app/comments.js
+++ b/public/javascripts/src/app/comments.js
@@ -27,7 +27,6 @@
body: $(e.target).closest("form").find("textarea").val()
},
success: function(data, text_status, xhr) {
- console.log($(this).closest("div.new-comment").find("div.comment-preview"));
$(this).closest("div.new-comment").find("div.comment-preview").show().html(data);
},
type: "post"
diff --git a/public/javascripts/src/app/favorites.js b/public/javascripts/src/app/favorites.js
new file mode 100644
index 000000000..06060d80f
--- /dev/null
+++ b/public/javascripts/src/app/favorites.js
@@ -0,0 +1,69 @@
+(function() {
+ Danbooru.Favorite = {};
+
+ Danbooru.Favorite.initialize_all = function() {
+ this.initialize_add_to_favorites();
+ this.initialize_remove_from_favorites();
+ this.hide_or_remove_add_to_favorites_link();
+ }
+
+ Danbooru.Favorite.hide_or_remove_add_to_favorites_link = function() {
+ var favorites = $("meta[name=favorites]").attr("content");
+ var current_user = $("meta[name=current-user-id]").attr("content");
+ var regexp = new RegExp("\\bfav:" + current_user + "\\b");
+ if (favorites.match(regexp)) {
+ $("a#add-to-favorites").hide();
+ } else {
+ $("a#remove-from-favorites").hide();
+ }
+ }
+
+ Danbooru.Favorite.initialize_add_to_favorites = function() {
+ $("a#add-to-favorites").click(function(e) {
+ e.stopPropagation();
+
+ $.ajax({
+ url: "/favorites",
+ data: {
+ id: $("meta[name=post-id]").attr("content")
+ },
+ beforeSend: function() {
+ $("img#add-to-favorites-wait").show();
+ },
+ success: function(data, text_status, xhr) {
+ $("a#add-to-favorites").hide();
+ $("a#remove-from-favorites").show();
+ $("img#add-to-favorites-wait").hide();
+ },
+ type: "post"
+ });
+
+ return false;
+ });
+ }
+
+ Danbooru.Favorite.initialize_remove_from_favorites = function() {
+ $("a#remove-from-favorites").click(function(e) {
+ e.stopPropagation();
+
+ $.ajax({
+ url: "/favorites/" + $("meta[name=post-id]").attr("content"),
+ beforeSend: function() {
+ $("img#remove-from-favorites-wait").show();
+ },
+ success: function(data, text_status, xhr) {
+ $("a#add-to-favorites").show();
+ $("a#remove-from-favorites").hide();
+ $("img#remove-from-favorites-wait").hide();
+ },
+ type: "delete"
+ });
+
+ return false;
+ });
+ }
+})();
+
+$(document).ready(function() {
+ Danbooru.Favorite.initialize_all();
+});
diff --git a/script/custom/compile_javascripts b/script/custom/compile_javascripts
index ea3be09b1..e66ffc628 100755
--- a/script/custom/compile_javascripts
+++ b/script/custom/compile_javascripts
@@ -12,3 +12,4 @@ cat public/javascripts/src/app/posts.js >> public/javascripts/compiled/default.j
cat public/javascripts/src/app/comments.js >> public/javascripts/compiled/default.js
cat public/javascripts/src/app/uploads.js >> public/javascripts/compiled/default.js
cat public/javascripts/src/app/users.js >> public/javascripts/compiled/default.js
+cat public/javascripts/src/app/favorites.js >> public/javascripts/compiled/default.js
- <%= submit_tag "Post" %> - <%= submit_tag "Preview" %> - <% end %>