mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-13 02:20:14 +01:00
Fix bulk edit
This commit is contained in:
parent
84283bc2b4
commit
cd8a24a712
@ -7032,13 +7032,13 @@ function doCloseChat() {
|
|||||||
*
|
*
|
||||||
* @param {string} popup_type - The type of popup currently active.
|
* @param {string} popup_type - The type of popup currently active.
|
||||||
* @param {string} this_chid - The character ID to be deleted.
|
* @param {string} this_chid - The character ID to be deleted.
|
||||||
|
* @param {boolean} delete_chats - Whether to delete chats or not.
|
||||||
*/
|
*/
|
||||||
export async function handleDeleteCharacter(popup_type, this_chid) {
|
export async function handleDeleteCharacter(popup_type, this_chid, delete_chats) {
|
||||||
if (popup_type !== "del_ch") {
|
if (popup_type !== "del_ch") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const delete_chats = !!$("#del_char_checkbox").prop("checked");
|
|
||||||
const avatar = characters[this_chid].avatar;
|
const avatar = characters[this_chid].avatar;
|
||||||
const name = characters[this_chid].name;
|
const name = characters[this_chid].name;
|
||||||
|
|
||||||
@ -7476,7 +7476,8 @@ $(document).ready(function () {
|
|||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
if (popup_type == "del_ch") {
|
if (popup_type == "del_ch") {
|
||||||
handleDeleteCharacter(popup_type, this_chid, characters);
|
const deleteChats = !!$("#del_char_checkbox").prop("checked");
|
||||||
|
await handleDeleteCharacter(popup_type, this_chid, deleteChats);
|
||||||
}
|
}
|
||||||
if (popup_type == "alternate_greeting" && menu_type !== "create") {
|
if (popup_type == "alternate_greeting" && menu_type !== "create") {
|
||||||
createOrEditCharacter();
|
createOrEditCharacter();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { characters, getCharacters, saveSettingsDebounced, handleDeleteCharacter } from "../../../script.js";
|
import { characters, getCharacters, handleDeleteCharacter, callPopup } from "../../../script.js";
|
||||||
|
|
||||||
let is_bulk_edit = false;
|
let is_bulk_edit = false;
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ function onEditButtonClick() {
|
|||||||
* @param {string} this_chid - The chid of the character to delete.
|
* @param {string} this_chid - The chid of the character to delete.
|
||||||
*/
|
*/
|
||||||
async function deleteCharacter(this_chid) {
|
async function deleteCharacter(this_chid) {
|
||||||
await handleDeleteCharacter("del_ch", this_chid);
|
await handleDeleteCharacter("del_ch", this_chid, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,6 +45,13 @@ async function onDeleteButtonClick() {
|
|||||||
toDelete.push(avatar);
|
toDelete.push(avatar);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const confirm = await callPopup('<h3>Are you sure you want to delete these characters?</h3>You would need to delete the chat files manually.<br>', 'confirm');
|
||||||
|
|
||||||
|
if (!confirm) {
|
||||||
|
console.log('User cancelled delete');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Delete the characters
|
// Delete the characters
|
||||||
for (const avatar of toDelete) {
|
for (const avatar of toDelete) {
|
||||||
console.log(`Deleting character with avatar ${avatar}`);
|
console.log(`Deleting character with avatar ${avatar}`);
|
||||||
@ -78,7 +85,7 @@ function addButtons() {
|
|||||||
* Enables bulk selection by adding a checkbox next to each character.
|
* Enables bulk selection by adding a checkbox next to each character.
|
||||||
*/
|
*/
|
||||||
function enableBulkSelect() {
|
function enableBulkSelect() {
|
||||||
$(".character_select").each((i, el) => {
|
$("#rm_print_characters_block .character_select").each((i, el) => {
|
||||||
const character = $(el).text();
|
const character = $(el).text();
|
||||||
const checkbox = $("<input type='checkbox' class='bulk_select_checkbox'>");
|
const checkbox = $("<input type='checkbox' class='bulk_select_checkbox'>");
|
||||||
checkbox.on("change", () => {
|
checkbox.on("change", () => {
|
||||||
@ -86,6 +93,7 @@ function enableBulkSelect() {
|
|||||||
});
|
});
|
||||||
$(el).prepend(checkbox);
|
$(el).prepend(checkbox);
|
||||||
});
|
});
|
||||||
|
$("#rm_print_characters_block").addClass("bulk_select");
|
||||||
// We also need to disable the default click event for the character_select divs
|
// We also need to disable the default click event for the character_select divs
|
||||||
$(document).on("click", ".bulk_select_checkbox", function (event) {
|
$(document).on("click", ".bulk_select_checkbox", function (event) {
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
@ -97,6 +105,7 @@ function enableBulkSelect() {
|
|||||||
*/
|
*/
|
||||||
function disableBulkSelect() {
|
function disableBulkSelect() {
|
||||||
$(".bulk_select_checkbox").remove();
|
$(".bulk_select_checkbox").remove();
|
||||||
|
$("#rm_print_characters_block").removeClass("bulk_select");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"requires": [],
|
"requires": [],
|
||||||
"optional": [],
|
"optional": [],
|
||||||
"js": "index.js",
|
"js": "index.js",
|
||||||
"css": "",
|
"css": "style.css",
|
||||||
"author": "city-unit",
|
"author": "city-unit",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"homePage": "https://github.com/city-unit"
|
"homePage": "https://github.com/city-unit"
|
||||||
|
7
public/scripts/extensions/bulk-edit/style.css
Normal file
7
public/scripts/extensions/bulk-edit/style.css
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.bulk_select_checkbox {
|
||||||
|
align-self: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#rm_print_characters_block .wide100pLess70px {
|
||||||
|
width: calc(100% - 85px);
|
||||||
|
}
|
@ -1169,7 +1169,7 @@ app.post("/deletecharacter", jsonParser, async function (request, response) {
|
|||||||
return response.sendStatus(403);
|
return response.sendStatus(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.body.delete_chats == 'true') {
|
if (request.body.delete_chats == true) {
|
||||||
try {
|
try {
|
||||||
await fs.promises.rm(path.join(chatsPath, sanitize(dir_name)), { recursive: true, force: true })
|
await fs.promises.rm(path.join(chatsPath, sanitize(dir_name)), { recursive: true, force: true })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user