Fix posts not being processed by blacklist after post updates

- Blacklisting individual posts was moved into its own function
- Fixed Javascript variables being leaked into the user environment
- Fixed post qTips being orphaned by replacements by destroying them first
- Moved edit form check into post success to avoid repeating post check
This commit is contained in:
BrokenEagle
2020-03-06 21:56:04 +00:00
parent 1a2c082b86
commit d84150b232
2 changed files with 28 additions and 22 deletions

View File

@@ -1,14 +1,16 @@
var post_id = <%= @post.id %>;
var $post = $(`#post_${post_id}`);
<% if @post.valid? %>
$post.replaceWith("<%= j PostPresenter.preview(@post, show_deleted: true) %>");
var $post = $("#post_<%= @post.id %>");
<% if !CurrentUser.disable_post_tooltips %>
$post.find("img").qtip("destroy", true);
<% end %>
var $new_post = $("<%= j PostPresenter.preview(@post, show_deleted: true) %>");
Danbooru.Blacklist.apply_post($new_post.get(0));
$("#post_<%= @post.id %>").replaceWith($new_post);
<% if params[:mode] == "quick-edit" %>
Danbooru.PostModeMenu.close_edit_form();
<% end %>
<% else %>
Danbooru.error(`Post #${post_id}: <%= j @post.errors.full_messages.join("; ") %>`);
<% end %>
<% if @post.valid? && params[:mode] == "quick-edit" %>
Danbooru.PostModeMenu.close_edit_form();
Danbooru.error(`Post #<%= @post.id %>: <%= j @post.errors.full_messages.join("; ") %>`);
<% end %>
$(document).trigger("danbooru:post-preview-updated", <%= raw @post.to_json %>);