refactor: scope checkbox selection to dialog and extract reusable function
- Scope checkbox selector to .column-selector-list to prevent selecting checkboxes outside the dialog - Refactor Select All and Unselect All into reusable toggle_all_checkboxes function - Reduce code duplication and improve maintainability
This commit is contained in:
parent
b3b85b9090
commit
65dbc16948
1 changed files with 22 additions and 17 deletions
|
|
@ -704,31 +704,36 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder {
|
|||
update_column_count_message();
|
||||
});
|
||||
|
||||
// Select All functionality
|
||||
$body.on("click", ".select-all-btn", function () {
|
||||
$body.find("input[type='checkbox']").each(function () {
|
||||
if (!$(this).prop("checked")) {
|
||||
$(this).prop("checked", true);
|
||||
const fieldname = $(this).attr("data-fieldname");
|
||||
// Toggle all checkboxes in column selector
|
||||
const toggle_all_checkboxes = function (should_check, should_clear_value) {
|
||||
// Scope to column selector list checkboxes only
|
||||
$body.find(".column-selector-list input[type='checkbox'][data-fieldname]").each(function () {
|
||||
const $checkbox = $(this);
|
||||
const is_checked = $checkbox.prop("checked");
|
||||
|
||||
// Only process checkboxes that need to be changed
|
||||
if ((should_check && !is_checked) || (!should_check && is_checked)) {
|
||||
$checkbox.prop("checked", should_check);
|
||||
const fieldname = $checkbox.attr("data-fieldname");
|
||||
const input = get_width_input(fieldname);
|
||||
input.prop("disabled", false);
|
||||
input.prop("disabled", !should_check);
|
||||
|
||||
if (should_clear_value) {
|
||||
input.val("");
|
||||
}
|
||||
}
|
||||
});
|
||||
update_column_count_message();
|
||||
};
|
||||
|
||||
// Select All functionality
|
||||
$body.on("click", ".select-all-btn", function () {
|
||||
toggle_all_checkboxes(true, false);
|
||||
});
|
||||
|
||||
// Unselect All functionality
|
||||
$body.on("click", ".unselect-all-btn", function () {
|
||||
$body.find("input[type='checkbox']").each(function () {
|
||||
if ($(this).prop("checked")) {
|
||||
$(this).prop("checked", false);
|
||||
const fieldname = $(this).attr("data-fieldname");
|
||||
const input = get_width_input(fieldname);
|
||||
input.prop("disabled", true);
|
||||
input.val("");
|
||||
}
|
||||
});
|
||||
update_column_count_message();
|
||||
toggle_all_checkboxes(false, true);
|
||||
});
|
||||
|
||||
d.show();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue