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:
evazion
2019-09-27 20:26:39 -05:00
parent 9000bc5cc6
commit d29bbbbd71
11 changed files with 150 additions and 34 deletions

View 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;

View File

@@ -0,0 +1,9 @@
body.c-post-versions.a-index {
#subnav-undo-selected-link {
display: none;
}
.post-version-select-column {
min-width: 2em;
}
}