mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Bulk enable/disable databank attachments
This commit is contained in:
@ -1056,7 +1056,8 @@ async function openAttachmentManager() {
|
|||||||
localStorage.setItem('DataBank_sortOrder', sortOrder);
|
localStorage.setItem('DataBank_sortOrder', sortOrder);
|
||||||
renderAttachments();
|
renderAttachments();
|
||||||
});
|
});
|
||||||
template.find('.bulkActionDelete').on('click', async () => {
|
function handleBulkAction(action) {
|
||||||
|
return async () => {
|
||||||
const selectedAttachments = document.querySelectorAll('.attachmentListItemCheckboxContainer .attachmentListItemCheckbox:checked');
|
const selectedAttachments = document.querySelectorAll('.attachmentListItemCheckboxContainer .attachmentListItemCheckbox:checked');
|
||||||
|
|
||||||
if (selectedAttachments.length === 0) {
|
if (selectedAttachments.length === 0) {
|
||||||
@ -1064,13 +1065,15 @@ async function openAttachmentManager() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const confirm = await callGenericPopup('Are you sure you want to delete the selected attachments?', POPUP_TYPE.CONFIRM);
|
if (action.confirmMessage) {
|
||||||
|
const confirm = await callGenericPopup(action.confirmMessage, POPUP_TYPE.CONFIRM);
|
||||||
if (confirm !== POPUP_RESULT.AFFIRMATIVE) {
|
if (confirm !== POPUP_RESULT.AFFIRMATIVE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const attachments = getDataBankAttachments();
|
const includeDisabled = true;
|
||||||
|
const attachments = getDataBankAttachments(includeDisabled);
|
||||||
selectedAttachments.forEach(async (checkbox) => {
|
selectedAttachments.forEach(async (checkbox) => {
|
||||||
const listItem = checkbox.closest('.attachmentListItem');
|
const listItem = checkbox.closest('.attachmentListItem');
|
||||||
if (!(listItem instanceof HTMLElement)) {
|
if (!(listItem instanceof HTMLElement)) {
|
||||||
@ -1082,7 +1085,7 @@ async function openAttachmentManager() {
|
|||||||
if (!attachment) {
|
if (!attachment) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await deleteAttachment(attachment, source, () => {}, false);
|
await action.perform(attachment, source);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelectorAll('.attachmentListItemCheckbox, .attachmentsBulkEditCheckbox').forEach(checkbox => {
|
document.querySelectorAll('.attachmentListItemCheckbox, .attachmentsBulkEditCheckbox').forEach(checkbox => {
|
||||||
@ -1092,7 +1095,22 @@ async function openAttachmentManager() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await renderAttachments();
|
await renderAttachments();
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template.find('.bulkActionDisable').on('click', handleBulkAction({
|
||||||
|
perform: (attachment) => disableAttachment(attachment, () => { }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
template.find('.bulkActionEnable').on('click', handleBulkAction({
|
||||||
|
perform: (attachment) => enableAttachment(attachment, () => { }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
template.find('.bulkActionDelete').on('click', handleBulkAction({
|
||||||
|
confirmMessage: 'Are you sure you want to delete the selected attachments?',
|
||||||
|
perform: async (attachment, source) => await deleteAttachment(attachment, source, () => { }, false),
|
||||||
|
}));
|
||||||
|
|
||||||
template.find('.bulkActionSelectAll').on('click', () => {
|
template.find('.bulkActionSelectAll').on('click', () => {
|
||||||
$('.attachmentListItemCheckbox:visible').each((_, checkbox) => {
|
$('.attachmentListItemCheckbox:visible').each((_, checkbox) => {
|
||||||
if (checkbox instanceof HTMLInputElement) {
|
if (checkbox instanceof HTMLInputElement) {
|
||||||
|
@ -53,6 +53,14 @@
|
|||||||
<i class="fa-solid fa-square"></i>
|
<i class="fa-solid fa-square"></i>
|
||||||
<span data-i18n="Select None">Select None</span>
|
<span data-i18n="Select None">Select None</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="menu_button menu_button_icon bulkActionDisable" title="Disable selected attachments">
|
||||||
|
<i class="fa-solid fa-comment-slash"></i>
|
||||||
|
<span data-i18n="Disable">Disable</span>
|
||||||
|
</div>
|
||||||
|
<div class="menu_button menu_button_icon bulkActionEnable" title="Enable selected attachments">
|
||||||
|
<i class="fa-solid fa-comment"></i>
|
||||||
|
<span data-i18n="Enable">Enable</span>
|
||||||
|
</div>
|
||||||
<div class="menu_button menu_button_icon bulkActionDelete" title="Delete selected attachments">
|
<div class="menu_button menu_button_icon bulkActionDelete" title="Delete selected attachments">
|
||||||
<i class="fa-solid fa-trash"></i>
|
<i class="fa-solid fa-trash"></i>
|
||||||
<span data-i18n="Delete">Delete</span>
|
<span data-i18n="Delete">Delete</span>
|
||||||
|
Reference in New Issue
Block a user