Fix post mode menu delete/undelete

This commit is contained in:
Kira 2020-01-18 14:40:51 -08:00
parent 26b14a16d7
commit f47cb7b7e8
5 changed files with 40 additions and 9 deletions

View File

@ -24,6 +24,7 @@ module Moderator
def undelete
@post = ::Post.find(params[:id])
@post.undelete!
respond_with(@post)
end
def confirm_move_favorites

View File

@ -32,7 +32,7 @@ $(function() {
const reason = $(e.target).data('reason');
if (confirm(`Delete post for being ${prompt}?`))
Post.delete_with_reason(post_id, reason);
Post.delete_with_reason(post_id, reason, true);
});
});

View File

@ -145,9 +145,11 @@ PostModeMenu.change = function() {
$body.removeClass((i, classNames) => classNames.split(/ /).filter(name => /^mode-/.test(name)).join(" "));
$body.addClass("mode-" + s);
LS.put("mode", s, 1);
$("#set-id").hide();
$("#tag-script-field").hide();
$("#quick-mode-reason").hide();
if (s === "tag-script") {
$("#set-id").hide();
let current_script_id = LS.get("current_tag_script_id");
if (!current_script_id) {
current_script_id = "1";
@ -160,9 +162,8 @@ PostModeMenu.change = function() {
} else if (s === 'add-to-set' || s === 'remove-from-set') {
PostModeMenu.update_sets_menu();
$("#set-id").show();
} else {
$("#set-id").hide();
$("#tag-script-field").hide();
} else if (s === 'delete') {
$("#quick-mode-reason").show();
}
}
@ -208,6 +209,10 @@ PostModeMenu.click = function(e) {
Post.update(post_id, {"post[is_rating_locked]": "1"});
} else if (s === 'lock-note') {
Post.update(post_id, {"post[is_note_locked]": "1"});
} else if (s === 'delete') {
Post.delete_with_reason(post_id, $("#quick-mode-reason").val(), false);
} else if (s === 'undelete') {
Post.undelete(post_id);
} else if (s === 'approve') {
Post.approve(post_id);
} else if (s === "tag-script") {

View File

@ -586,7 +586,7 @@ Post.update = function(post_id, params) {
});
}
Post.delete_with_reason = function(post_id, reason) {
Post.delete_with_reason = function(post_id, reason, reload_after_delete) {
Post.notice_update("inc");
SendQueue.add(function() {
$.ajax({
@ -598,7 +598,30 @@ Post.delete_with_reason = function(post_id, reason) {
$(window).trigger('danbooru:error', "Error: " + message);
}).done(function(data) {
$(window).trigger("danbooru:notice", "Deleted post.");
location.reload();
if(reload_after_delete) {
location.reload();
} else {
$(`article#post_${post_id}`).attr('data-flags', 'deleted');
}
}).always(function() {
Post.notice_update("dec");
});
});
}
Post.undelete = function(post_id) {
Post.notice_update("inc");
SendQueue.add(function() {
$.ajax({
type: "POST",
url: `/moderator/post/posts/${post_id}/undelete.json`
}).fail(function(data) {
// var message = $.map(data.responseJSON.errors, function(msg, attr) { return msg; }).join('; ');
const message = data.responseJSON.message;
$(window).trigger('danbooru:error', "Error: " + message);
}).done(function(data) {
$(window).trigger("danbooru:notice", "Deleted post.");
$(`article#post_${post_id}`).attr('data-flags', 'active');
}).always(function() {
Post.notice_update("dec");
});
@ -614,7 +637,8 @@ Post.unflag = function(post_id, approval) {
url: `/posts/${post_id}/flag.json`,
data: {approval: modApproval}
}).fail(function(data) {
var message = $.map(data.responseJSON.errors, function(msg, attr) { return msg; }).join('; ');
// var message = $.map(data.responseJSON.errors, function(msg, attr) { return msg; }).join('; ');
const message = data.responseJSON.message;
$(window).trigger('danbooru:error', "Error: " + message);
}).done(function(data) {
$(window).trigger("danbooru:notice", "Unflagged post");

View File

@ -29,6 +29,7 @@
</form>
<select id="set-id"></select>
<% if CurrentUser.is_privileged? %>
<input id="tag-script-field" data-autocomplete="tag-edit" placeholder="Enter tag script" style="display: none; margin-top: 0.5em;">
<input id="tag-script-field" data-autocomplete="tag-edit" placeholder="Enter tag script" style="display: none; margin-top: 0.5em;"/>
<input id="quick-mode-reason" placeholder="Reason" style="display: none; margin-top: 0.5em;"/>
<% end %>
</section>