Fix #4178: add ability to mass undo tag edits.
Adds checkboxes to the /post_versions index allowing you to select and undo multiple versions at once.
This commit is contained in:
@@ -36,6 +36,7 @@ export { default as Note } from '../src/javascripts/notes.js';
|
||||
export { default as Post } from '../src/javascripts/posts.js.erb';
|
||||
export { default as PostModeMenu } from '../src/javascripts/post_mode_menu.js';
|
||||
export { default as PostTooltip } from '../src/javascripts/post_tooltips.js';
|
||||
export { default as PostVersion } from '../src/javascripts/post_version.js';
|
||||
export { default as RelatedTag } from '../src/javascripts/related_tag.js';
|
||||
export { default as Shortcuts } from '../src/javascripts/shortcuts.js';
|
||||
export { default as Upload } from '../src/javascripts/uploads.js.erb';
|
||||
|
||||
45
app/javascript/src/javascripts/post_version.js
Normal file
45
app/javascript/src/javascripts/post_version.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import Utility from './utility';
|
||||
|
||||
let PostVersion = {};
|
||||
|
||||
PostVersion.initialize_all = function() {
|
||||
if ($("#c-post-versions #a-index").length) {
|
||||
PostVersion.initialize_undo();
|
||||
}
|
||||
};
|
||||
|
||||
PostVersion.initialize_undo = function() {
|
||||
/* Expand the clickable area of the checkbox to the entire table cell. */
|
||||
$(".post-version-select-column").on("click.danbooru", function(event) {
|
||||
$(event.target).find(".post-version-select-checkbox:not(:disabled)").prop("checked", (_, checked) => !checked).change();
|
||||
});
|
||||
|
||||
$("#post-version-select-all-checkbox").on("change.danbooru", function(event) {
|
||||
$("td .post-version-select-checkbox:not(:disabled)").prop("checked", $("#post-version-select-all-checkbox").prop("checked")).change();
|
||||
});
|
||||
|
||||
$(".post-version-select-checkbox").on("change.danbooru", function(event) {
|
||||
let checked = $("td .post-version-select-checkbox:checked");
|
||||
$("#subnav-undo-selected-link").text(`Undo selected (${checked.length})`).toggle(checked.length > 0);
|
||||
});
|
||||
|
||||
$("#subnav-undo-selected-link").on("click.danbooru", PostVersion.undo_selected);
|
||||
};
|
||||
|
||||
PostVersion.undo_selected = async function () {
|
||||
event.preventDefault();
|
||||
|
||||
let updated = 0;
|
||||
let selected_rows = $("td .post-version-select-checkbox:checked").parents("tr");
|
||||
|
||||
for (let row of selected_rows) {
|
||||
let id = $(row).data("post-version-id");
|
||||
await $.ajax(`/post_versions/${id}/undo.json`, { method: "PUT" });
|
||||
|
||||
updated++;
|
||||
Utility.notice(`${updated}/${selected_rows.length} changes undone.`);
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(PostVersion.initialize_all);
|
||||
export default PostVersion;
|
||||
9
app/javascript/src/styles/specific/post_versions.scss
Normal file
9
app/javascript/src/styles/specific/post_versions.scss
Normal file
@@ -0,0 +1,9 @@
|
||||
body.c-post-versions.a-index {
|
||||
#subnav-undo-selected-link {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.post-version-select-column {
|
||||
min-width: 2em;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user