import { characters, getCharacters, handleDeleteCharacter, callPopup } from "../script.js"; import {BulkEditOverlay, BulkEditOverlayState} from "./BulkEditOverlay.js"; let is_bulk_edit = false; const enableBulkEdit = () => { enableBulkSelect(); (new BulkEditOverlay()).selectState(); // show the delete button $("#bulkDeleteButton").show(); is_bulk_edit = true; } const disableBulkEdit = () => { disableBulkSelect(); (new BulkEditOverlay()).browseState(); // hide the delete button $("#bulkDeleteButton").hide(); is_bulk_edit = false; } const toggleBulkEditMode = (isBulkEdit) => { if (isBulkEdit) { disableBulkEdit(); } else { enableBulkEdit(); } } (new BulkEditOverlay()).addStateChangeCallback((state) => { if (state === BulkEditOverlayState.select) enableBulkEdit(); if (state === BulkEditOverlayState.browse) disableBulkEdit(); }); /** * Toggles bulk edit mode on/off when the edit button is clicked. */ function onEditButtonClick() { console.log("Edit button clicked"); toggleBulkEditMode(is_bulk_edit); } /** * Deletes the character with the given chid. * * @param {string} this_chid - The chid of the character to delete. */ async function deleteCharacter(this_chid) { await handleDeleteCharacter("del_ch", this_chid, false); } /** * Deletes all characters that have been selected via the bulk checkboxes. */ async function onDeleteButtonClick() { console.log("Delete button clicked"); // Create a mapping of chid to avatar let toDelete = []; $(".bulk_select_checkbox:checked").each((i, el) => { const chid = $(el).parent().attr("chid"); const avatar = characters[chid].avatar; // Add the avatar to the list of avatars to delete toDelete.push(avatar); }); const confirm = await callPopup('