diff --git a/app/controllers/post_appeals_controller.rb b/app/controllers/post_appeals_controller.rb index 18a14494b..116c94030 100644 --- a/app/controllers/post_appeals_controller.rb +++ b/app/controllers/post_appeals_controller.rb @@ -3,7 +3,7 @@ class PostAppealsController < ApplicationController respond_to :html, :xml, :json, :js def new - @post_appeal = PostAppeal.new + @post_appeal = PostAppeal.new(post_appeal_params) respond_with(@post_appeal) end diff --git a/app/controllers/post_flags_controller.rb b/app/controllers/post_flags_controller.rb index b80bad83b..b64a729e5 100644 --- a/app/controllers/post_flags_controller.rb +++ b/app/controllers/post_flags_controller.rb @@ -3,7 +3,7 @@ class PostFlagsController < ApplicationController respond_to :html, :xml, :json, :js def new - @post_flag = PostFlag.new + @post_flag = PostFlag.new(post_flag_params) respond_with(@post_flag) end diff --git a/app/controllers/post_replacements_controller.rb b/app/controllers/post_replacements_controller.rb index c83fd7c8b..8327b2a5e 100644 --- a/app/controllers/post_replacements_controller.rb +++ b/app/controllers/post_replacements_controller.rb @@ -1,9 +1,10 @@ class PostReplacementsController < ApplicationController - respond_to :html, :xml, :json + respond_to :html, :xml, :json, :js before_action :moderator_only, except: [:index] def new - @post = Post.find(params[:post_id]) + @post_replacement = Post.find(params[:post_id]).replacements.new + respond_with(@post_replacement) end def create diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 01ef84c76..3e9fd8e62 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -23,9 +23,7 @@ class PostsController < ApplicationController def show @post = Post.find(params[:id]) - @post_flag = PostFlag.new(:post_id => @post.id) - @post_appeal = PostAppeal.new(:post_id => @post.id) - + include_deleted = @post.is_deleted? || (@post.parent_id.present? && @post.parent.is_deleted?) || CurrentUser.user.show_deleted_children? @parent_post_set = PostSets::PostRelationship.new(@post.parent_id, :include_deleted => include_deleted) @children_post_set = PostSets::PostRelationship.new(@post.id, :include_deleted => include_deleted) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1632d9766..49082424c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -181,10 +181,8 @@ module ApplicationHelper render "dtext/form", options end - def dtext_preview_button(object, name, options = {}) - options[:input_id] ||= "#{object}_#{name}" - options[:preview_id] ||= "dtext-preview" - submit_tag("Preview", "data-input-id" => options[:input_id], "data-preview-id" => options[:preview_id]) + def dtext_preview_button(object, name, input_id: "#{object}_#{name}", preview_id: "dtext-preview") + tag.input value: "Preview", type: "button", class: "dtext-preview-button", "data-input-id": input_id, "data-preview-id": preview_id end def search_field(method, label: method.titleize, hint: nil, value: nil, **attributes) diff --git a/app/javascript/src/javascripts/comments.js b/app/javascript/src/javascripts/comments.js index 7038cbf0b..9d67427b7 100644 --- a/app/javascript/src/javascripts/comments.js +++ b/app/javascript/src/javascripts/comments.js @@ -11,7 +11,6 @@ Comment.initialize_all = function() { $(window).on("danbooru:index_for_post", (_event, post_id, current_comment_section) => { $("#threshold-comments-notice-for-" + post_id).hide(); - Dtext.initialize_expandables(current_comment_section); }); } diff --git a/app/javascript/src/javascripts/dtext.js b/app/javascript/src/javascripts/dtext.js index e9a633f42..59121e65b 100644 --- a/app/javascript/src/javascripts/dtext.js +++ b/app/javascript/src/javascripts/dtext.js @@ -6,12 +6,11 @@ Dtext.initialize_all = function() { } Dtext.initialize_links = function() { - $(".simple_form input[value=Preview]").on("click.danbooru", Dtext.click_button); + $(document).on("click.danbooru", ".dtext-preview-button", Dtext.click_button); } -Dtext.initialize_expandables = function($parent) { - $parent = $parent || $(document); - $parent.find(".expandable-button").on("click.danbooru", function(e) { +Dtext.initialize_expandables = function() { + $(document).on("click.danbooru", ".expandable-button", function(e) { var button = $(this); button.parent().next().fadeToggle("fast"); if (button.val() === "Show") { @@ -34,7 +33,6 @@ Dtext.call_preview = function(e, $button, $input, $preview) { }, success: function(data) { $preview.html(data).fadeIn("fast"); - Dtext.initialize_expandables($preview); } }); } diff --git a/app/javascript/src/javascripts/post_appeals.js b/app/javascript/src/javascripts/post_appeals.js deleted file mode 100644 index 814c18343..000000000 --- a/app/javascript/src/javascripts/post_appeals.js +++ /dev/null @@ -1,35 +0,0 @@ -let PostAppeal = {}; - -PostAppeal.initialize_all = function() { - if ($("#c-posts").length && $("#a-show").length) { - this.initialize_appeal(); - } -} - -PostAppeal.initialize_appeal = function() { - $("#appeal-dialog").dialog({ - autoOpen: false, - width: 700, - modal: true, - buttons: { - "Submit": function() { - $("#appeal-dialog form").submit(); - $(this).dialog("close"); - }, - "Cancel": function() { - $(this).dialog("close"); - } - } - }); - - $("#appeal").on("click.danbooru", function(e) { - e.preventDefault(); - $("#appeal-dialog").dialog("open"); - }); -} - -$(document).ready(function() { - PostAppeal.initialize_all(); -}); - -export default PostAppeal diff --git a/app/javascript/src/javascripts/post_flags.js b/app/javascript/src/javascripts/post_flags.js deleted file mode 100644 index 27f4d56d3..000000000 --- a/app/javascript/src/javascripts/post_flags.js +++ /dev/null @@ -1,39 +0,0 @@ -let PostFlag = {}; - -PostFlag.initialize_all = function() { - if ($("#c-posts").length && $("#a-show").length) { - this.initialize_flag(); - } -} - -PostFlag.initialize_flag = function() { - $("#flag-dialog").dialog({ - autoOpen: false, - width: 700, - modal: true, - buttons: { - "Submit": function() { - $("#flag-dialog form").submit(); - $(this).dialog("close"); - }, - "Cancel": function() { - $(this).dialog("close"); - } - } - }); - - $('#flag-dialog form').submit(function() { - $('#flag-dialog').dialog('close'); - }); - - $("#flag").on("click.danbooru", function(e) { - e.preventDefault(); - $("#flag-dialog").dialog("open"); - }); -} - -$(function() { - PostFlag.initialize_all(); -}); - -export default PostFlag diff --git a/app/javascript/src/javascripts/posts.js.erb b/app/javascript/src/javascripts/posts.js.erb index 9a1eb4b96..795c23e87 100644 --- a/app/javascript/src/javascripts/posts.js.erb +++ b/app/javascript/src/javascripts/posts.js.erb @@ -31,7 +31,6 @@ Post.initialize_all = function() { this.initialize_post_image_resize_links(); this.initialize_post_image_resize_to_window_link(); this.initialize_similar(); - this.initialize_replace_image_dialog(); this.initialize_gestures(); if ((Utility.meta("always-resize-images") === "true") || (Utility.meta("viewport") && (window.screen.width <= 660))) { @@ -616,32 +615,6 @@ Post.initialize_saved_searches = function() { }); } -Post.initialize_replace_image_dialog = function() { - $("#replace-image-dialog").dialog({ - autoOpen: false, - width: 700, - modal: true, - buttons: { - "Submit": function() { - $("#replace-image-dialog form").submit(); - $(this).dialog("close"); - }, - "Cancel": function() { - $(this).dialog("close"); - } - } - }); - - $('#replace-image-dialog form').submit(function() { - $('#replace-image-dialog').dialog('close'); - }); - - $("#replace-image").on("click.danbooru", function(e) { - e.preventDefault(); - $("#replace-image-dialog").dialog("open"); - }); -}; - $(document).ready(function() { Post.initialize_all(); }); diff --git a/app/javascript/src/javascripts/utility.js b/app/javascript/src/javascripts/utility.js index 35ade85ec..802855e17 100644 --- a/app/javascript/src/javascripts/utility.js +++ b/app/javascript/src/javascripts/utility.js @@ -36,6 +36,31 @@ Utility.error = function(msg) { } } +Utility.dialog = function(title, html) { + const $dialog = $(html).dialog({ + title: title, + width: 700, + modal: true, + close: function() { + // Defer removing the dialog to avoid detaching the
diff --git a/app/views/post_appeals/_new.html.erb b/app/views/post_appeals/_new.html.erb index c06e3705f..b652c1d08 100644 --- a/app/views/post_appeals/_new.html.erb +++ b/app/views/post_appeals/_new.html.erb @@ -1,9 +1,13 @@ -<%= format_text(WikiPage.titled(Danbooru.config.appeal_notice_wiki_page).first.try(&:body)) %> +