posts/show: load flag/appeal/replacement dialogs via ajax (#3922).
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
1
app/views/post_appeals/new.js.erb
Normal file
1
app/views/post_appeals/new.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
Danbooru.Utility.dialog("Appeal post", "<%= j render "post_appeals/new", post_appeal: @post_appeal %>");
|
||||
@@ -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>
|
||||
|
||||
1
app/views/post_flags/new.js.erb
Normal file
1
app/views/post_flags/new.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
Danbooru.Utility.dialog("Flag post", "<%= j render "post_flags/new", post_flag: @post_flag %>");
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
1
app/views/post_replacements/new.js.erb
Normal file
1
app/views/post_replacements/new.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
Danbooru.Utility.dialog("Replace image", "<%= j render "post_replacements/new", post_replacement: @post_replacement %>");
|
||||
@@ -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 %>
|
||||
|
||||
@@ -135,18 +135,6 @@
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div id="flag-dialog" class="prose" title="Flag post" style="display: none;">
|
||||
<%= render "post_flags/new", post_flag: @post.flags.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="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>
|
||||
|
||||
Reference in New Issue
Block a user