fix: edit event possible when checkbox is disabled

refs #2
This commit is contained in:
Max Hohlfeld 2025-05-12 20:28:05 +02:00
parent 3a093b95f5
commit 544ba8d0ce
6 changed files with 28 additions and 13 deletions

View File

@ -45,8 +45,8 @@ pub struct NewOrEditEventForm {
#[serde(with = "short_date_time_format")] #[serde(with = "short_date_time_format")]
end: NaiveDateTime, end: NaiveDateTime,
location: i32, location: i32,
voluntarywachhabender: Option<bool>, voluntarywachhabender: bool,
voluntaryfuehrungsassistent: Option<bool>, voluntaryfuehrungsassistent: bool,
amount: i16, amount: i16,
clothing: String, clothing: String,
note: Option<String>, note: Option<String>,

View File

@ -53,8 +53,8 @@ pub async fn post(
.note .note
.clone() .clone()
.and_then(|n| if !n.is_empty() { Some(n) } else { None }), .and_then(|n| if !n.is_empty() { Some(n) } else { None }),
voluntary_wachhabender: form.voluntarywachhabender.unwrap_or(false), voluntary_wachhabender: form.voluntarywachhabender,
voluntary_fuehrungsassistent: form.voluntaryfuehrungsassistent.unwrap_or(false), voluntary_fuehrungsassistent: form.voluntaryfuehrungsassistent,
}; };
let assignments_for_event = Assignment::read_all_by_event(pool.get_ref(), event.id).await?; let assignments_for_event = Assignment::read_all_by_event(pool.get_ref(), event.id).await?;

View File

@ -36,8 +36,8 @@ pub async fn post(
.note .note
.clone() .clone()
.and_then(|n| if !n.is_empty() { Some(n) } else { None }), .and_then(|n| if !n.is_empty() { Some(n) } else { None }),
voluntary_wachhabender: form.voluntarywachhabender.unwrap_or(false), voluntary_wachhabender: form.voluntarywachhabender,
voluntary_fuehrungsassistent: form.voluntaryfuehrungsassistent.unwrap_or(false), voluntary_fuehrungsassistent: form.voluntaryfuehrungsassistent,
}; };
if let Err(e) = changeset.validate_with(&None) { if let Err(e) = changeset.validate_with(&None) {

View File

@ -96,3 +96,15 @@ htmx.on("showToast", (e) => {
toastProgress.classList.remove(`has-background-${e.detail.type}-90`) toastProgress.classList.remove(`has-background-${e.detail.type}-90`)
}, 3000); }, 3000);
}) })
const convertBool = (val) => {
if (val === "true" || val === true) return true;
if (val === "false" || val === false) return false;
return null;
}
_hyperscript.config.conversions["bool"] = convertBool;
_hyperscript.config.conversions["inverseBool"] = function(val) {
return !convertBool(val);
};

View File

@ -11,6 +11,9 @@
{% endif %} {% endif %}
<input type="hidden" name="date" value="{{ date }}"> <input type="hidden" name="date" value="{{ date }}">
<input type="hidden" name="voluntarywachhabender" id="voluntarywachhabender" value="{{ voluntary_wachhabender }}">
<input type="hidden" name="voluntaryfuehrungsassistent" id="voluntaryfuehrungsassistent"
value="{{ voluntary_fuehrungsassistent }}">
{% if let Some(id) = id %} {% if let Some(id) = id %}
<div class="field is-horizontal"> <div class="field is-horizontal">
@ -114,9 +117,9 @@
{% let wh_disabled = id.is_some() && is_wachhabender_planned %} {% let wh_disabled = id.is_some() && is_wachhabender_planned %}
<div class="control"> <div class="control">
<label class="checkbox"> <label class="checkbox">
<input class="checkbox" type="checkbox" name="voluntarywachhabender" value="true" <input class="checkbox" type="checkbox" {{ (wh_disabled || canceled)|cond_show("disabled")}}
{{ (wh_disabled || canceled)|cond_show("disabled")}} {{ voluntary_wachhabender|cond_show("checked") }}
{{ voluntary_wachhabender|cond_show("checked") }}> _="on click put (the value of #voluntarywachhabender) as inverseBool into the value of #voluntarywachhabender">
</label> </label>
</div> </div>
{% if wh_disabled %} {% if wh_disabled %}
@ -137,9 +140,9 @@
{% let fa_disabled = id.is_some() && is_fuehrungsassistent_planned %} {% let fa_disabled = id.is_some() && is_fuehrungsassistent_planned %}
<div class="control"> <div class="control">
<label class="checkbox"> <label class="checkbox">
<input class="checkbox" type="checkbox" name="voluntaryfuehrungsassistent" value="true" <input class="checkbox" type="checkbox" {{ (fa_disabled || canceled)|cond_show("disabled") }}
{{ (fa_disabled || canceled)|cond_show("disabled") }} {{ voluntary_fuehrungsassistent|cond_show("checked") }}
{{ voluntary_fuehrungsassistent|cond_show("checked") }}> _="on click put (the value of #voluntaryfuehrungsassistent) as inverseBool into the value of #voluntaryfuehrungsassistent">
</label> </label>
</div> </div>
{% if fa_disabled %} {% if fa_disabled %}

View File

@ -50,7 +50,7 @@
{% when AvailabillityAssignmentState::AssignedWachhabender(_) %} {% when AvailabillityAssignmentState::AssignedWachhabender(_) %}
<span>als Wachhabender geplant</span> <span>als Wachhabender geplant</span>
<svg class="icon"> <svg class="icon">
<use href="/static/feather-sprite.svg#edit" /> <use href="/static/feather-sprite.svg#edit-2" />
</svg> </svg>
{% when _ %} {% when _ %}
<span>Planen</span> <span>Planen</span>