Merge pull request #3923 from evazion/fix-3922

#3922: Render flag/appeal/replacement dialogs via ajax.
This commit is contained in:
Albert Yi
2018-09-27 12:55:02 -07:00
committed by GitHub
22 changed files with 91 additions and 169 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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);
});
}

View File

@@ -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);
}
});
}

View File

@@ -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

View File

@@ -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

View File

@@ -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();
});

View File

@@ -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 <form> tag before the
// form is submitted (which would prevent the submission from going through).
$(() => $dialog.dialog("destroy"));
},
buttons: {
"Submit": function() {
$dialog.find("form").submit();
},
"Cancel": function() {
$dialog.dialog("close");
}
}
});
$dialog.find("form").on("submit.danbooru", function() {
$dialog.dialog("close");
});
}
Utility.keydown = function(keys, namespace, handler) {
if (Utility.meta("enable-js-navigation") === "true") {
$(document).on("keydown.danbooru." + namespace, null, keys, handler);

View File

@@ -5,7 +5,7 @@
<label>Copy from</label>
<%= select_tag :commentary_source_type, options_for_select(%w[Source Post]) %>
<%= text_field_tag :commentary_source, post.source %>
<%= text_field_tag :commentary_post_id, (post.parent.try(&:id) || post.children.first.try(&:id)), :style => "display: none;" %>
<%= text_field_tag :commentary_post_id, post.parent_id, :style => "display: none;" %>
<%= button_tag "Fetch" %>
</div>
</form>

View File

@@ -1,9 +1,13 @@
<%= format_text(WikiPage.titled(Danbooru.config.appeal_notice_wiki_page).first.try(&:body)) %>
<div class="appeal-dialog-body">
<div class="prose">
<%= format_text(WikiPage.titled(Danbooru.config.appeal_notice_wiki_page).first.try(&:body)) %>
</div>
<%# XXX dtext_field expects there to be a `post_appeal` instance variable. %>
<% @post_appeal = post_appeal %>
<%= simple_form_for(@post_appeal, format: :js, remote: true) do |f| %>
<%= f.hidden_field :post_id %>
<%= dtext_field "post_appeal", "reason", preview_id: "dtext-preview-for-post-appeal" %>
<%= dtext_preview_button "post_appeal", "reason", preview_id: "dtext-preview-for-post-appeal" %>
<% end %>
<%# XXX dtext_field expects there to be a `post_appeal` instance variable. %>
<% @post_appeal = post_appeal %>
<%= simple_form_for(@post_appeal, format: :js, remote: true) do |f| %>
<%= f.hidden_field :post_id %>
<%= dtext_field "post_appeal", "reason", preview_id: "dtext-preview-for-post-appeal", type: "string" %>
<%= dtext_preview_button "post_appeal", "reason", preview_id: "dtext-preview-for-post-appeal" %>
<% end %>
</div>

View File

@@ -0,0 +1 @@
Danbooru.Utility.dialog("Appeal post", "<%= j render "post_appeals/new", post_appeal: @post_appeal %>");

View File

@@ -1,9 +1,13 @@
<%= format_text(WikiPage.titled(Danbooru.config.flag_notice_wiki_page).first.try(&:body)) %>
<div class="flag-dialog-body">
<div class="prose">
<%= format_text(WikiPage.titled(Danbooru.config.flag_notice_wiki_page).first.try(&:body)) %>
</div>
<%# XXX dtext_field expects there to be a `post_flag` instance variable. %>
<% @post_flag = post_flag %>
<%= simple_form_for(@post_flag, format: :js, remote: true) do |f| %>
<%= f.hidden_field :post_id %>
<%= dtext_field "post_flag", "reason", preview_id: "dtext-preview-for-post-flag", type: "string" %>
<%= dtext_preview_button "post_flag", "reason", preview_id: "dtext-preview-for-post-flag" %>
<% end %>
<%# XXX dtext_field expects there to be a `post_flag` instance variable. %>
<% @post_flag = post_flag %>
<%= simple_form_for(@post_flag, format: :js, remote: true) do |f| %>
<%= f.hidden_field :post_id %>
<%= dtext_field "post_flag", "reason", preview_id: "dtext-preview-for-post-flag", type: "string" %>
<%= dtext_preview_button "post_flag", "reason", preview_id: "dtext-preview-for-post-flag" %>
<% end %>
</div>

View File

@@ -0,0 +1 @@
Danbooru.Utility.dialog("Flag post", "<%= j render "post_flags/new", post_flag: @post_flag %>");

View File

@@ -1,8 +1,12 @@
<%= format_text(WikiPage.titled(Danbooru.config.replacement_notice_wiki_page).first.try(&:body)) %>
<div class="replace-image-dialog-body">
<div class="prose">
<%= format_text(WikiPage.titled(Danbooru.config.replacement_notice_wiki_page).first.try(&:body)) %>
</div>
<%= simple_form_for(post_replacement, url: post_replacements_path(post_id: post_replacement.post_id), method: :post) do |f| %>
<%= f.input :replacement_file, label: "File", as: :file %>
<%= f.input :replacement_url, label: "Replacement URL", hint: "The source URL to download the replacement from.", as: :string, input_html: { value: post_replacement.post.normalized_source } %>
<%= f.input :final_source, label: "Final Source", hint: "If present, the source field will be changed to this after replacement.", as: :string, input_html: { value: post_replacement.post.source } %>
<%= f.input :tags, label: "Tags", as: :text, input_html: { value: post_replacement.suggested_tags_for_removal, data: { autocomplete: "tag-edit" } } %>
<% end %>
<%= simple_form_for(post_replacement, url: post_replacements_path(post_id: post_replacement.post_id), method: :post) do |f| %>
<%= f.input :replacement_file, label: "File", as: :file %>
<%= f.input :replacement_url, label: "Replacement URL", hint: "The source URL to download the replacement from.", as: :string, input_html: { value: post_replacement.post.normalized_source } %>
<%= f.input :final_source, label: "Final Source", hint: "If present, the source field will be changed to this after replacement.", as: :string, input_html: { value: post_replacement.post.source } %>
<%= f.input :tags, label: "Tags", as: :string, input_html: { value: post_replacement.suggested_tags_for_removal, data: { autocomplete: "tag-edit" } } %>
<% end %>
</div>

View File

@@ -1,5 +1,5 @@
<div id="c-post-replacements">
<div id="a-new">
<%= render "new", post_replacement: @post.replacements.new %>
<%= render "new", post_replacement: @post_replacement %>
</div>
</div>

View File

@@ -0,0 +1 @@
Danbooru.Utility.dialog("Replace image", "<%= j render "post_replacements/new", post_replacement: @post_replacement %>");

View File

@@ -42,6 +42,7 @@
<% if CurrentUser.can_approve_posts? && !post.disapproved_by?(CurrentUser.user) %>
<%= render "moderator/post/queues/quick_mod", post: post %>
<%= render "post_disapprovals/detailed_rejection_dialog" %>
<% end %>
</div>
<% end %>
@@ -73,5 +74,3 @@
<span style="display: none;">Loading...</span>
</div>
<% end %>
<%= render "post_disapprovals/detailed_rejection_dialog" %>

View File

@@ -22,9 +22,9 @@
<li><span id="status-locked-notice">Status locked</span></li>
<% else %>
<% if !post.is_deleted? && !post.is_pending? && !post.is_flagged? %>
<li><%= link_to "Flag", new_post_flag_path(:post_id => post.id), :id => "flag" %></li>
<li><%= link_to "Flag", new_post_flag_path(post_flag: { post_id: post.id }), id: "flag", remote: true %></li>
<% elsif post.is_flagged? || post.is_deleted? %>
<li><%= link_to "Appeal", new_post_appeal_path(:post_id => post.id), :id => "appeal" %></li>
<li><%= link_to "Appeal", new_post_appeal_path(post_appeal: { post_id: post.id }), id: "appeal", remote: true %></li>
<% end %>
<% if CurrentUser.can_approve_posts? %>
@@ -53,7 +53,7 @@
<% end %>
<% if CurrentUser.is_moderator? %>
<li><%= link_to "Replace Image", new_post_replacement_path(:post_id => post.id), :id => "replace-image" %></li>
<li><%= link_to "Replace Image", new_post_replacement_path(post_id: post.id), id: "replace-image", remote: true %></li>
<li><%= link_to "Down vote report", reports_down_voting_post_path(post_id: post.id) %></li>
<% end %>
<% end %>

View File

@@ -135,29 +135,19 @@
</section>
</div>
<div id="flag-dialog" class="prose" title="Flag post" style="display: none;">
<%= render "post_flags/new", post_flag: @post.flags.new %>
</div>
<% if CurrentUser.is_member? %>
<div id="add-to-pool-dialog" title="Add to pool" style="display: none;">
<%= render "pool_elements/new" %>
</div>
<div id="appeal-dialog" class="prose" title="Appeal post" style="display: none;">
<%= render "post_appeals/new", post_appeal: @post.appeals.new %>
</div>
<div id="add-commentary-dialog" title="Add artist commentary" style="display: none;">
<%= render "artist_commentaries/form", :post => @post %>
</div>
<div id="replace-image-dialog" class="prose" title="Replace image" style="display: none;">
<%= render "post_replacements/new", post_replacement: @post.replacements.new %>
</div>
<div id="add-to-pool-dialog" title="Add to pool" style="display: none;">
<%= render "pool_elements/new" %>
</div>
<div id="add-commentary-dialog" title="Add artist commentary" style="display: none;">
<%= render "artist_commentaries/form", :post => @post %>
</div>
<div id="add-to-favgroup-dialog" title="Add to favorite group" style="display: none;">
<%= render "favorite_groups/add_to_favgroup_dialog", :post => @post %>
</div>
<div id="add-to-favgroup-dialog" title="Add to favorite group" style="display: none;">
<%= render "favorite_groups/add_to_favgroup_dialog", :post => @post %>
</div>
<% end %>
</div>
<%= post_view_count_js %>