Merge pull request #4170 from imesha10/staging
Regex bulkedit select all toggle button add
This commit is contained in:
@@ -28,6 +28,9 @@
|
||||
</label>
|
||||
</div>
|
||||
<div class="regex_bulk_operations flex-container justifyCenter">
|
||||
<div id="bulk_select_all_toggle" class="menu_button menu_button_icon" title="Toggle Select All">
|
||||
<i class="fa-solid fa-check-double"></i>
|
||||
</div>
|
||||
<div id="bulk_enable_regex" class="menu_button menu_button_icon">
|
||||
<i class="fa-solid fa-toggle-on"></i>
|
||||
<small data-i18n="Enable">Enable</small>
|
||||
|
||||
@@ -27,6 +27,18 @@ export function getRegexScripts() {
|
||||
return [...(extension_settings.regex ?? []), ...(characters[this_chid]?.data?.extensions?.regex_scripts ?? [])];
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the icon for the "select all" checkbox in the regex settings.
|
||||
* - Use `fa-check-double` when the checkbox is unchecked (indicating all scripts are not selected).
|
||||
* - Use `fa-minus` when the checkbox is checked (indicating all scripts are selected).
|
||||
* @param {boolean} allAreChecked Should the "select all" icon be in the checked state?
|
||||
*/
|
||||
function setToggleAllIcon(allAreChecked) {
|
||||
const selectAllIcon = $('#bulk_select_all_toggle').find('i');
|
||||
selectAllIcon.toggleClass('fa-check-double', !allAreChecked);
|
||||
selectAllIcon.toggleClass('fa-minus', allAreChecked);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a regex script to the extension settings or character data.
|
||||
* @param {import('../../char-data.js').RegexScriptData} regexScript
|
||||
@@ -103,6 +115,7 @@ async function deleteRegexScript({ id, isScoped }) {
|
||||
async function loadRegexScripts() {
|
||||
$('#saved_regex_scripts').empty();
|
||||
$('#saved_scoped_scripts').empty();
|
||||
setToggleAllIcon(false);
|
||||
|
||||
const scriptTemplate = $(await renderExtensionTemplateAsync('regex', 'scriptTemplate'));
|
||||
|
||||
@@ -183,6 +196,11 @@ async function loadRegexScripts() {
|
||||
await deleteRegexScript({ id: script.id, isScoped });
|
||||
await reloadCurrentChat();
|
||||
});
|
||||
scriptHtml.find('.regex_bulk_checkbox').on('change', function () {
|
||||
const checkboxes = $('#regex_container .regex_bulk_checkbox');
|
||||
const allAreChecked = checkboxes.length === checkboxes.filter(':checked').length;
|
||||
setToggleAllIcon(allAreChecked);
|
||||
});
|
||||
|
||||
$(container).append(scriptHtml);
|
||||
}
|
||||
@@ -614,6 +632,19 @@ jQuery(async () => {
|
||||
return scripts.filter(script => selectedIds.includes(script.id));
|
||||
}
|
||||
|
||||
$('#bulk_select_all_toggle').on('click', async function () {
|
||||
const checkboxes = $('#regex_container .regex_bulk_checkbox');
|
||||
if (checkboxes.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const allAreChecked = checkboxes.length === checkboxes.filter(':checked').length;
|
||||
const newState = !allAreChecked; // true if we just checked all, false if we just unchecked all
|
||||
|
||||
checkboxes.prop('checked', newState);
|
||||
setToggleAllIcon(newState);
|
||||
});
|
||||
|
||||
$('#bulk_enable_regex').on('click', async function () {
|
||||
const scripts = getSelectedScripts().filter(script => script.disabled);
|
||||
if (scripts.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user