favorites: unify create.js.erb & destory.js.erb code paths.
This commit is contained in:
@@ -26,6 +26,7 @@ class FavoritesController < ApplicationController
|
||||
def create
|
||||
@post = Post.find(params[:post_id])
|
||||
@post.add_favorite!(CurrentUser.user)
|
||||
flash[:notice] = "You have favorited this post"
|
||||
|
||||
respond_with(@post)
|
||||
end
|
||||
@@ -39,6 +40,7 @@ class FavoritesController < ApplicationController
|
||||
Favorite.remove(post_id: params[:id], user: CurrentUser.user)
|
||||
end
|
||||
|
||||
flash[:notice] = "You have unfavorited this post"
|
||||
respond_with(@post)
|
||||
end
|
||||
end
|
||||
|
||||
16
app/views/favorites/_update.js.erb
Normal file
16
app/views/favorites/_update.js.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
$("#add-to-favorites, #add-fav-button, #remove-from-favorites, #remove-fav-button").toggle();
|
||||
$("#score-for-post-<%= @post.id %>").text(<%= @post.score %>);
|
||||
$("#favcount-for-post-<%= @post.id %>").text(<%= @post.fav_count %>);
|
||||
|
||||
<% if CurrentUser.is_gold? %>
|
||||
var fav_count = <%= @post.fav_count %>;
|
||||
$("#favlist").html("<%= j post_favlist(@post) %>");
|
||||
|
||||
if (fav_count === 0) {
|
||||
$("#show-favlist-link, #hide-favlist-link, #favlist").hide();
|
||||
} else if (!$("#favlist").is(":visible")) {
|
||||
$("#show-favlist-link").show();
|
||||
}
|
||||
<% end %>
|
||||
|
||||
Danbooru.Utility.notice("<%= j flash[:notice] %>");
|
||||
@@ -1,13 +0,0 @@
|
||||
$("#add-to-favorites").hide();
|
||||
$("#add-fav-button").hide();
|
||||
$("#remove-from-favorites").show();
|
||||
$("#remove-fav-button").show();
|
||||
$("#score-for-post-<%= @post.id %>").html(<%= @post.score %>);
|
||||
$("#favcount-for-post-<%= @post.id %>").html(<%= @post.fav_count %>);
|
||||
<% if CurrentUser.is_gold? %>
|
||||
$("#favlist").html("<%= escape_javascript(post_favlist(@post)) %>");
|
||||
if (!$("#favlist").is(":visible")) {
|
||||
$("#show-favlist-link").show();
|
||||
}
|
||||
<% end %>
|
||||
$(window).trigger("danbooru:notice", "You have favorited this post");
|
||||
1
app/views/favorites/create.js.erb
Symbolic link
1
app/views/favorites/create.js.erb
Symbolic link
@@ -0,0 +1 @@
|
||||
_update.js.erb
|
||||
@@ -1,13 +0,0 @@
|
||||
$("#add-to-favorites").show();
|
||||
$("#add-fav-button").show();
|
||||
$("#remove-from-favorites").hide();
|
||||
$("#remove-fav-button").hide();
|
||||
$("#score-for-post-<%= @post.id %>").html(<%= @post.score %>);
|
||||
$("#favcount-for-post-<%= @post.id %>").html(<%= @post.fav_count %>);
|
||||
<% if CurrentUser.is_gold? %>
|
||||
$("#favlist").html("<%= escape_javascript(post_favlist(@post)) %>");
|
||||
<% if @post.fav_count == 0 %>
|
||||
$("#show-favlist-link, #hide-favlist-link, #favlist").hide();
|
||||
<% end %>
|
||||
<% end %>
|
||||
$(window).trigger("danbooru:notice", "You have unfavorited this post");
|
||||
1
app/views/favorites/destroy.js.erb
Symbolic link
1
app/views/favorites/destroy.js.erb
Symbolic link
@@ -0,0 +1 @@
|
||||
_update.js.erb
|
||||
Reference in New Issue
Block a user