Bug 36521: Checkbox preferences should be allowed to be submitted empty

Visit:
http://localhost:8081/cgi-bin/koha/admin/preferences.pl?tab=i18n_l10n

Uncheck English on both 'language' and 'OPACLanguages'. Save.
Notice "Nothing to save" shows.
Apply patch. Repeat. Notice you can now save with all options empty.

To my knowledge, these 2 language preferences are the only checkbox preferences of this kind (correct me
if I'm wrong please).

I need to add a new system preference for bug 35604 listing all installed ILL backends so the user
may enable or disable each of the backends.
I want that particular system preference to be disabled as a whole if all backends are unchecked, but I was unable
to uncheck all before this patch.

I understand that for languages checkboxes specifically not allowing everything to be empty may make sense (at least
one language should be enabled, after all). But these languages checkbox preferences should be the exception, not the rule,
for this behaviour.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Pedro Amorim 2024-04-04 12:35:56 +00:00 committed by Katrin Fischer
parent 335b5b7ad5
commit d9aef9163f
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834

View file

@ -10,10 +10,24 @@ KOHA.Preferences = {
let sysprefs = $(form).find('.modified').not('.preference-checkbox').toArray().reduce((map, e) => ({ ...map, [$(e).attr('name')]: [$(e).val()].flat()}), {});
// language prefs
$(form).find('.modified.preference-checkbox:checked').toArray().forEach((elt) => {
(sysprefs[$(elt).attr('name')] = sysprefs[$(elt).attr('name')] || []).push($(elt).val());
});
// checkbox prefs
let modified_boxes = $(form).find(".modified.preference-checkbox");
let all_boxes_unchecked = true;
if (modified_boxes.length > 0) {
modified_boxes
.toArray()
.filter(elt => $(elt).prop("checked"))
.forEach(elt => {
all_boxes_unchecked = false;
(sysprefs[$(elt).attr("name")] =
sysprefs[$(elt).attr("name")] || []).push($(elt).val());
});
if (all_boxes_unchecked) {
modified_boxes.toArray().forEach(elt => {
sysprefs[$(elt).attr("name")] = [];
});
}
}
if ( !Object.keys(sysprefs).length ) {
humanMsg.displayAlert( __("Nothing to save") );