diff --git a/controllers/d.poi.php b/controllers/d.poi.php index 63d188e..8a63783 100755 --- a/controllers/d.poi.php +++ b/controllers/d.poi.php @@ -31,11 +31,13 @@ switch ($controller->splitted_url[1]) { if (isset($_POST[$key])) { $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 (str_starts_with($key, 'b_')) { + 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; } @@ -158,11 +160,13 @@ switch ($controller->splitted_url[1]) { if (isset($_POST[$key])) { $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 (str_starts_with($key, 'b_')) { + 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; } diff --git a/views/d.poi.edit.html b/views/d.poi.edit.html index f535e58..05ecf75 100755 --- a/views/d.poi.edit.html +++ b/views/d.poi.edit.html @@ -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 += '