implemented favorites on post/show page
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<div class="comment-preview dtext">
|
||||
<%= form_tag(comments_path, :remote => true) do %>
|
||||
<%= hidden_field "comment", "post_id", :value => post.id %>
|
||||
<%= text_area "comment", "body", :size => "60x7" %>
|
||||
<br>
|
||||
<%= submit_tag "Post" %>
|
||||
<%= submit_tag "Preview" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= form_tag(comments_path) do %>
|
||||
<%= hidden_field "comment", "post_id", :value => post.id %>
|
||||
<%= text_area "comment", "body", :size => "60x7" %>
|
||||
<br>
|
||||
<%= submit_tag "Post" %>
|
||||
<%= submit_tag "Preview" %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%= @page_title %></title>
|
||||
<title><%= yield :page_title %></title>
|
||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||
<link rel="top" title="<%= Danbooru.config.app_name %>" href="/">
|
||||
<%= csrf_meta_tag %>
|
||||
<meta name="current-user-name" content="<%= CurrentUser.name %>">
|
||||
<meta name="current-user-id" content="<%= CurrentUser.id %>">
|
||||
<% unless CurrentUser.user.blacklisted_tags.blank? %>
|
||||
<meta name="blacklisted-tags" content="<%= CurrentUser.user.blacklisted_tags %>">
|
||||
<% end %>
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
</section>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
/ <%= @post_set.tags %>
|
||||
/<%= @post_set.tags %>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "posts/partials/common/secondary_links" %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<ul>
|
||||
<%= resize_image_links(post, CurrentUser.user) %>
|
||||
<li><%= link_to "Favorite", "#" %></li>
|
||||
<li><%= link_to "Unfavorite", "#" %></li>
|
||||
<li><%= link_to "Favorite", "#", :id => "add-to-favorites" %> <img src="/images/wait.gif" style="display: none;" id="add-to-favorites-wait"></li>
|
||||
<li><%= link_to "Unfavorite", "#", :id => "remove-from-favorites" %> <img src="/images/wait.gif" style="display: none;" id="remove-from-favorites-wait"></li>
|
||||
<li><%= link_to "Translate", "#" %></li>
|
||||
<li><%= link_to "Unapprove", "#" %></li>
|
||||
<% if CurrentUser.user.is_janitor? %>
|
||||
|
||||
@@ -55,13 +55,14 @@
|
||||
</div>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
/ <%= @post.tag_string %>
|
||||
/p/<%= @post.tag_string %>
|
||||
<% end %>
|
||||
|
||||
<% content_for(:html_header) do %>
|
||||
<meta name="tags" content="<%= @post.tag_string %>">
|
||||
<meta name="favorites" content="<%= @post.fav_string %>">
|
||||
<meta name="pools" content="<%= @post.pool_string %>">
|
||||
<meta name="post-id" content="<%= @post.id %>">
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "posts/partials/common/secondary_links" %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div id="sessions">
|
||||
<div id="new">
|
||||
<section>
|
||||
<h2>Login</h2>
|
||||
<h2>Sign In</h2>
|
||||
<%= form_tag(session_path) do %>
|
||||
<table width="100%">
|
||||
<tfoot>
|
||||
@@ -33,12 +33,12 @@
|
||||
<ul>
|
||||
<li><%= link_to "I don't have an account", new_user_path %></li>
|
||||
<li><%= link_to "I forgot my password", reset_password_path %></li>
|
||||
<li><%= link_to "I forgot my login", login_reminder_path %></li>
|
||||
<li><%= link_to "I forgot my user name", login_reminder_path %></li>
|
||||
</ul>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
/ login
|
||||
/sign in
|
||||
<% end %>
|
||||
|
||||
1
app/views/uploads/update.js.erb
Normal file
1
app/views/uploads/update.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
location.reload()
|
||||
@@ -1 +0,0 @@
|
||||
page.reload
|
||||
BIN
public/images/wait.gif
Normal file
BIN
public/images/wait.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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"
|
||||
|
||||
69
public/javascripts/src/app/favorites.js
Normal file
69
public/javascripts/src/app/favorites.js
Normal file
@@ -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();
|
||||
});
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user