Update delete WI entry to new popup

c0039111ddb297195948b7d90643f5fe787636ad

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +17 -5Ignore whitespace
public/scripts/world-info.js+17 -5
@@ -2115,7 +2115,13 @@ export function setWIOriginalDataValue(data, uid, key, value) {
2115 }2115 }
2116}2116}
21172117
2118function deleteWIOriginalDataValue(data, uid) {2118/**
2119 * Deletes the original data entry corresponding to the given uid from the provided data object
2120 *
2121 * @param {object} data - The data object containing the original data entries
2122 * @param {string} uid - The unique identifier of the data entry to be deleted
2123 */
2124export function deleteWIOriginalDataValue(data, uid) {
2119 if (data.originalData && Array.isArray(data.originalData.entries)) {2125 if (data.originalData && Array.isArray(data.originalData.entries)) {
2120 const originalIndex = data.originalData.entries.findIndex(x => x.uid === uid);2126 const originalIndex = data.originalData.entries.findIndex(x => x.uid === uid);
21212127
@@ -3003,7 +3009,8 @@ function getWorldEntry(name, data, entry) {
3003 deleteButton.data('uid', entry.uid);3009 deleteButton.data('uid', entry.uid);
3004 deleteButton.on('click', async function () {3010 deleteButton.on('click', async function () {
3005 const uid = $(this).data('uid');3011 const uid = $(this).data('uid');
3006 deleteWorldInfoEntry(data, uid);3012 const deleted = await deleteWorldInfoEntry(data, uid);
3013 if (!deleted) return;
3007 deleteWIOriginalDataValue(data, uid);3014 deleteWIOriginalDataValue(data, uid);
3008 await saveWorldInfo(name, data);3015 await saveWorldInfo(name, data);
3009 updateEditor(navigation_option.previous);3016 updateEditor(navigation_option.previous);
@@ -3241,17 +3248,22 @@ export function duplicateWorldInfoEntry(data, uid) {
3241 * Deletes a WI entry, with a user confirmation dialog3248 * Deletes a WI entry, with a user confirmation dialog
3242 * @param {*[]} data - The data of the book3249 * @param {*[]} data - The data of the book
3243 * @param {number} uid - The uid of the entry to copy in this book3250 * @param {number} uid - The uid of the entry to copy in this book
3251 * @param {object} [options={}] - Optional arguments
3252 * @param {boolean} [options.silent=false] - Whether to prompt the user for deletion or just do it
3253 * @returns {Promise<boolean>} Whether the entry deletion was successful
3244 */3254 */
3245export function deleteWorldInfoEntry(data, uid) {3255export async function deleteWorldInfoEntry(data, uid, { silent = false } = {}) {
3246 if (!data || !('entries' in data)) {3256 if (!data || !('entries' in data)) {
3247 return;3257 return;
3248 }3258 }
32493259
3250 if (!confirm(`Delete the entry with UID: ${uid}? This action is irreversible!`)) {3260 const confirmation = silent || await Popup.show.confirm(`Delete the entry with UID: ${uid}?`, 'This action is irreversible!');
3251 throw new Error('User cancelled deletion');3261 if (!confirmation) {
3262 return false;
3252 }3263 }
32533264
3254 delete data.entries[uid];3265 delete data.entries[uid];
3266 return true;
3255}3267}
32563268
3257/**3269/**