From 20263390c4d67c257b09f9dd2997432fb0a51af9 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 25 Jul 2023 13:48:18 +0300 Subject: [PATCH] fix decision form for nominations fix htmx target errors on nomination rounds --- scipost_django/colleges/forms.py | 2 +- .../_hx_nomination_decision_form.html | 55 +++++++++++++------ .../templates/colleges/_hx_nomination_li.html | 3 +- .../colleges/_hx_nomination_li_contents.html | 6 +- .../colleges/_hx_nominations_invitations.html | 3 +- .../_hx_nominations_needing_specialties.html | 2 +- .../colleges/_hx_voting_round_results.html | 27 +-------- .../colleges/_hx_voting_rounds_tablist.html | 6 +- .../templates/colleges/nominations.html | 14 ++--- 9 files changed, 56 insertions(+), 62 deletions(-) diff --git a/scipost_django/colleges/forms.py b/scipost_django/colleges/forms.py index aefa515b3..467335b79 100644 --- a/scipost_django/colleges/forms.py +++ b/scipost_django/colleges/forms.py @@ -568,8 +568,8 @@ class FellowshipNominationDecisionForm(forms.ModelForm): css_class="row", ), ) - if voting_round: + self.fields["voting_round"].initial = voting_round self.fields["outcome"].initial = voting_round.vote_outcome diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html b/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html index 8944c9831..aa9e4d6fb 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_decision_form.html @@ -1,26 +1,47 @@ {% load crispy_forms_tags %} {% load automarkup %} -{% if voting_round.decision %} - {{ voting_round.decision }} - <p>Fixed on: {{ voting_round.decision.fixed_on }}</p> +<div id="nomination-{{ voting_round.id }}-decision"> - {% if voting_round.decision.comments %} - <p>Comments:</p> - {% automarkup voting_round.decision.comments %} - {% endif %} + {% if voting_round.decision %} + + {% if voting_round.decision.outcome == 'elected' %} + <div class="badge fs-4 mb-2 bg-success">{{ voting_round.decision.get_outcome_display }}</div> + {% elif voting_round.decision.outcome == 'notelected' %} + <div class="badge fs-4 mb-2 bg-danger">{{ voting_round.decision.get_outcome_display }}</div> + {% endif %} + + {% if voting_round.decision.comments %} + <h5>Decision comments</h5> + <p>{{ voting_round.decision.comments }}</p> + {% endif %} + + {% else %} -{% else %} - {% with blocks=voting_round.decision_blocks %} + {% if "edadmin" in user_roles %} + + {% if not voting_round.is_open %} + {% with blocks=voting_round.decision_blocks %} + + {% if blocks %} + <p>The decision cannot be fixed at this moment: {{ blocks }}</p> + {% else %} + <form hx-post="{% url 'colleges:_hx_nomination_decision_form' round_id=voting_round.id %}" + hx-target="#nomination-{{ voting_round.id }}-decision"> + {% crispy decision_form %} + </form> + {% endif %} + + + {% endwith %} + {% else %} + <p class="text-warning">The voting round is still open. You many not draft a decision yet.</p> + {% endif %} - {% if blocks %} - <p>The decision cannot be fixed at this moment: {{ blocks }}</p> {% else %} - <form hx-post="{% url 'colleges:_hx_nomination_decision_form' round_id=voting_round.id %}" - hx-target="#nomination-{{ voting_round.id }}-decision"> - {% crispy decision_form %} - </form> + <p class="text-warning">No decision has been formulated yet.</p> {% endif %} - {% endwith %} -{% endif %} + {% endif %} + +</div> diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_li.html b/scipost_django/colleges/templates/colleges/_hx_nomination_li.html index 20f026388..187f1f54e 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_li.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_li.html @@ -50,7 +50,6 @@ <div id="nomination-{{ nomination.id }}-li-contents" hx-get="{% url 'colleges:_hx_nomination_li_contents' nomination_id=nomination.id %}" - hx-trigger="toggle from:#nomination-{{ nomination.id }}-li-details" - hx-target="this"></div> + hx-trigger="intersect once"></div> </details> </div> diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_li_contents.html b/scipost_django/colleges/templates/colleges/_hx_nomination_li_contents.html index b5e521051..a7d11ee58 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_li_contents.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_li_contents.html @@ -118,8 +118,7 @@ <div id="nomination-{{ nomination.id }}-comments" hx-get="{% url 'colleges:_hx_nomination_comments' nomination_id=nomination.id %}" - hx-trigger="revealed" - hx-target="this"></div> + hx-trigger="intersect once"></div> </div> </details> </div> @@ -139,8 +138,7 @@ {% if round.is_open and session_fellowship in round.eligible_to_vote.all %} <div id="nomination-{{ round.nomination.id }}-vote" hx-get="{% url 'colleges:_hx_nomination_vote' voting_round_id=round.id %}" - hx-trigger="revealed" - hx-target="this"></div> + hx-trigger="intersect once"></div> {% else %} {% include "colleges/_hx_voting_round_results.html" with voting_round=round %} {% endif %} diff --git a/scipost_django/colleges/templates/colleges/_hx_nominations_invitations.html b/scipost_django/colleges/templates/colleges/_hx_nominations_invitations.html index dda5c98a5..7b4a51157 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nominations_invitations.html +++ b/scipost_django/colleges/templates/colleges/_hx_nominations_invitations.html @@ -49,8 +49,7 @@ <h4>Update the response to this invitation:</h4> <div id="invitation-{{ invitation.id }}-update-response" hx-get="{% url 'colleges:_hx_fellowship_invitation_update_response' invitation_id=invitation.id %}" - hx-trigger="toggle from:#invitation-{{ invitation.id }}-details" - hx-target="this"></div> + hx-trigger="toggle from:#invitation-{{ invitation.id }}-details"></div> </div> </details> {% empty %} diff --git a/scipost_django/colleges/templates/colleges/_hx_nominations_needing_specialties.html b/scipost_django/colleges/templates/colleges/_hx_nominations_needing_specialties.html index d12155d46..228dd433c 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nominations_needing_specialties.html +++ b/scipost_django/colleges/templates/colleges/_hx_nominations_needing_specialties.html @@ -6,7 +6,7 @@ class="p-2 mt-2" hx-get="{% url 'profiles:_hx_profile_specialties' profile_id=nomination.profile.id %}" hx-trigger="toggle from:#nomination-{{ nomination.id }}-specialties"></div> - <button class="btn btn-success text-white m-2" + <button class="btn btn-success text-white m-2 nomination-specialties-done-btn" hx-get="{% url 'colleges:_hx_nominations_needing_specialties' %}" hx-target="#nominations_needing_specialties">Done</button> </details> diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_round_results.html b/scipost_django/colleges/templates/colleges/_hx_voting_round_results.html index a6d5f3d3e..e82d9f903 100644 --- a/scipost_django/colleges/templates/colleges/_hx_voting_round_results.html +++ b/scipost_django/colleges/templates/colleges/_hx_voting_round_results.html @@ -5,36 +5,15 @@ <h3>Votes</h3> <div id="nomination-{{ nomination.id }}-round-{{ voting_round.id }}-votes" hx-get="{% url 'colleges:_hx_nomination_voter_table' round_id=voting_round.id %}" - hx-trigger="revealed" - hx-target="this"></div> + hx-trigger="intersect once"></div> {% endif %} <div class="row mb-0"> <div class="col-12 col-md mt-3"> <h3>Decision</h3> - {% if voting_round.decision.outcome == 'elected' %} - <div class="badge fs-4 ms-2 bg-success">{{ voting_round.decision.get_outcome_display }}</div> - {% elif voting_round.decision.outcome == 'notelected' %} - <div class="badge fs-4 ms-2 bg-danger">{{ voting_round.decision.get_outcome_display }}</div> - {% else %} - - {% if "edadmin" in user_roles %} - - {% if not voting_round.is_open %} - <div id="nomination-{{ nomination.id }}-decision_form" - hx-get="{% url 'colleges:_hx_nomination_decision_form' round_id=voting_round.id %}" - hx-trigger="revealed" - hx-target="this"></div> - {% else %} - <p class="text-warning">The voting round is still open. You many not draft a decision yet.</p> - {% endif %} - - {% else %} - <p class="text-warning">No decision has been formulated yet.</p> - {% endif %} - - {% endif %} + <div hx-get="{% url 'colleges:_hx_nomination_decision_form' round_id=voting_round.id %}" + hx-trigger="intersect once"></div> </div> <div class="col-12 col-md mt-3">{% include "colleges/_voting_results_box.html" with voting_round=voting_round %}</div> diff --git a/scipost_django/colleges/templates/colleges/_hx_voting_rounds_tablist.html b/scipost_django/colleges/templates/colleges/_hx_voting_rounds_tablist.html index 0758404ac..9e584c125 100644 --- a/scipost_django/colleges/templates/colleges/_hx_voting_rounds_tablist.html +++ b/scipost_django/colleges/templates/colleges/_hx_voting_rounds_tablist.html @@ -1,7 +1,9 @@ <div class="tablist"> + {% for tab_choice in tab_choices %} - <a hx-get="{% url 'colleges:_hx_voting_rounds' %}?tab={{ tab_choice.0 }}" - {% if selected == tab_choice.0 %}class="selected"{% endif %} + <a hx-get="{% url 'colleges:_hx_voting_rounds' %}?tab={{ tab_choice.0 }}" hx-target="#voting_tablist" + {% if selected == tab_choice.0 %}class="selected"{% endif %} >{{ tab_choice.1 }}</a> {% endfor %} + </div> diff --git a/scipost_django/colleges/templates/colleges/nominations.html b/scipost_django/colleges/templates/colleges/nominations.html index d8eb94154..4eaecfc68 100644 --- a/scipost_django/colleges/templates/colleges/nominations.html +++ b/scipost_django/colleges/templates/colleges/nominations.html @@ -113,12 +113,12 @@ <h3>Add specialties</h3> <div id="nominations_needing_specialties" hx-get="{% url 'colleges:_hx_nominations_needing_specialties' %}" - hx-trigger="toggle from:#ensure-specialties-details"></div> + hx-trigger="intersect once"></div> <h3 class="mt-4 ">Start round</h3> <div id="nominations_no_round_started" hx-get="{% url 'colleges:_hx_nominations_no_round_started' %}" - hx-trigger="toggle from:#ensure-specialties-details, click from:body target:.nomination-start-round-btn"> + hx-trigger="intersect once, click from:body target:.nomination-start-round-btn, click from:body target:.nomination-specialties-done-btn"> </div> </div> </details> @@ -138,10 +138,8 @@ </summary> <div class="p-2"> - <div id="voting_tablist" hx-get="{% url 'colleges:_hx_voting_rounds' %}?tab= - {% if 'edadmin' in user_roles %}ongoing{% else %}ongoing-vote_required{% endif %} - " hx-trigger="toggle from:#voting-details, click from:body target:.nomination-start-round-btn" hx-target="this" hx-swap="innerHTML"> - </div> + <div id="voting_tablist" hx-trigger="toggle from:#voting-details, click from:body target:.nomination-start-round-btn" + hx-get="{% url 'colleges:_hx_voting_rounds' %}?tab={% if 'edadmin' in user_roles %}ongoing{% else %}ongoing-vote_required{% endif %}" ></div> </div> </details> @@ -154,9 +152,7 @@ <div class="p-2 mt-2"> <div id="invitations_tablist" hx-get="{% url 'colleges:_hx_nominations_invitations' %}?response=notyetinvited" - hx-trigger="toggle from:#invitations-details" - hx-target="this" - hx-swap="innerHTML"></div> + hx-trigger="toggle from:#invitations-details"></div> </div> </details> {% endif %} -- GitLab