Correction des erreurs dans l'édition des booléens

This commit is contained in:
leosw
2026-01-20 20:15:50 +01:00
parent 04ecae8211
commit 5f07c557f5
3 changed files with 43 additions and 32 deletions

View File

@@ -32,9 +32,11 @@ switch ($controller->splitted_url[1]) {
$value = $_POST[$key];
if (str_starts_with($key, 'b_')) {
// 3 états : 1 = oui, 0 = non, -1 = non renseigné
$params[$key] = ($value === "1" ? 1 :
($value === "0" ? 0 : -1));
if ($value === "0" || $value === "1" || $value === "2") {
$params[$key] = intval($value);
} else {
$params[$key] = -1; // non renseigné
}
}
elseif (str_starts_with($key, 'n_')) {
$params[$key] = is_numeric($value) ? (0 + $value) : null;
@@ -159,9 +161,11 @@ switch ($controller->splitted_url[1]) {
$value = $_POST[$key];
if (str_starts_with($key, 'b_')) {
// 3 états : 1 = oui, 0 = non, -1 = non renseigné
$params[$key] = ($value === "1" ? 1 :
($value === "0" ? 0 : -1));
if ($value === "0" || $value === "1" || $value === "2") {
$params[$key] = intval($value);
} else {
$params[$key] = -1;
}
}
elseif (str_starts_with($key, 'n_')) {
$params[$key] = is_numeric($value) ? (0 + $value) : null;

View File

@@ -62,19 +62,22 @@ var unsaved = false;
function update3State(id) {
var input = $("input[name="+id+"]");
var label = $("label[for="+id+"]");
switch (+input.val()) {
case 0:
input.val(1);
label.toggleClass('uncheck intermediate');
break;
case 1:
input.val(2);
label.toggleClass('intermediate check');
break;
default:
input.val(0);
label.toggleClass('check uncheck');
}
var v = parseInt(input.val(), 10);
// cycle propre : 0 → 1 → 2 → 0
if (v === 0) v = 1;
else if (v === 1) v = 2;
else v = 0;
input.val(v);
label.removeClass("uncheck intermediate check");
if (v === 0) label.addClass("uncheck");
if (v === 1) label.addClass("intermediate");
if (v === 2) label.addClass("check");
unsaved = true;
}
@@ -95,12 +98,16 @@ function updateForm(type) {
case 'b':
var cls = 'intermediate';
var val = 1;
if (existing == 0) {
cls = 'uncheck';
val = 0;
} else if (existing == 2) {
cls = 'check';
val = 2;
} else if (existing == -1 || existing === null) {
cls = 'intermediate';
val = 1;
}
html_form +=
'<label class="threecb ' + cls + '" for="' + index + '" onclick="update3State(\'' + index + '\')">' +
@@ -160,10 +167,7 @@ $(document).ready(function(){
if (current_poi_type) {
updateForm(current_poi_type);
}
if (poi_mode === "edit") {
unsaved = true;
}
unsaved = !is_new;
$('#type_selector label').click(function(){
@@ -219,10 +223,12 @@ $( "#name" ).change(function() {
</section>
<script>
<? if($poi->lat != null && $poi->lon != null) { ?>
var poi_lat = <?=$poi->lat?>;
var poi_lon = <?=$poi->lon?>;
<? } ?>
var poi_type = "<?=$poi->poi_type?>";
var poi_mode = "edit";
var is_new = <?= isset($new) && $new == 1 ? "true" : "false" ?>;
var root = "<?=$config['rel_root_folder']?>";
</script>

View File

@@ -145,11 +145,12 @@
<div class="bool-row values">
<?php foreach ($bool_fields as $key => $label): ?>
<?php
$value = $values[$key] ?? -1;
$value = $values[$key] ?? 2;
$icon = [
-1 => "<span class='boolean-pill boolean-yes'>✔️</span>",
0 => "<span class='boolean-pill boolean-no'>❌</span>",
1 => "<span class='boolean-pill boolean-unknown'>❓</span>"
1 => "<span class='boolean-pill boolean-maybe'>❓</span>",
2 => "<span class='boolean-pill boolean-yes'>✔️</span>",
-1 => "<span class='boolean-pill boolean-unknown'></span>"
][$value];
?>
<div class="bool-cell">