From 0d274b5cd11ffe9f90c9feec81c4659a98258b64 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 5 Sep 2023 17:13:12 +0200 Subject: [PATCH] convert creation of nominations into a button --- .../colleges/_hx_nomination_form.html | 19 ++-- .../colleges/_hx_nominations_new.html | 73 ++++++++++++++++ .../templates/colleges/nominations.html | 87 +++---------------- scipost_django/colleges/urls.py | 5 ++ scipost_django/colleges/views.py | 28 +++--- 5 files changed, 117 insertions(+), 95 deletions(-) create mode 100644 scipost_django/colleges/templates/colleges/_hx_nominations_new.html diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_form.html b/scipost_django/colleges/templates/colleges/_hx_nomination_form.html index 5543d1846..3b12c708b 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_form.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_form.html @@ -1,11 +1,10 @@ {% load crispy_forms_tags %} -<div class="m-2 p-4 border border-warning"> - <h3>Nomination to Fellowship: <span class="bg-success bg-opacity-25 p-2"><em>{{ profile }}</em></span></h3> - <form - hx-post="{% url 'colleges:_hx_nomination_form' profile_id=profile.pk %}" - hx-target="#nomination_form_response" - hx-indicator="#nomination_form_response-indicator" - > - {% crispy nomination_form %} - </form> -</div> + +<h3> + Nomination to Fellowship: <span class="bg-success bg-opacity-25 p-2"><em>{{ profile }}</em></span> +</h3> +<form hx-post="{% url 'colleges:_hx_nomination_form' profile_id=profile.pk %}" + hx-target="#new-nomination-container" + hx-indicator="#nomination_form_response-indicator"> + {% crispy nomination_form %} +</form> diff --git a/scipost_django/colleges/templates/colleges/_hx_nominations_new.html b/scipost_django/colleges/templates/colleges/_hx_nominations_new.html new file mode 100644 index 000000000..439a4585f --- /dev/null +++ b/scipost_django/colleges/templates/colleges/_hx_nominations_new.html @@ -0,0 +1,73 @@ +{% load crispy_forms_tags %} + +<div class="p-3 border border-success rounded rounded-lg"> + <h2 class="mb-4">Nominate a new potential Fellow</h2> + <div class="row"> + + <div class="col-lg-6"> + <h3>Procedure</h3> + <ul> + <li>Type your search query in the search form</li> + <li> + When the name you're looking for appears in the + <em>Matching profiles</em> list, double-click on it + </li> + <li>The nomination form will appear below</li> + <li>Non-eligibility flags (if any) will appear</li> + <li>If eligible, fill the form in (comments are optional)</li> + <li>Submit! (the vote will be arranged by EdAdmin)</li> + </ul> + <div class="row mb-0"> + + <div class="col-12"> + <form hx-post="{% url 'profiles:_hx_profile_dynsel_list' %}" + hx-trigger="keyup delay:200ms, change" + hx-target="#profile_dynsel_results" + hx-indicator="#profile_dynsel_results-indicator"> + <div id="profile_dynsel_form">{% crispy profile_dynsel_form %}</div> + </form> + </div> + + </div> + <div class="row mb-0"> + + <div class="col-auto"> + <div id="nomination_form_response-indicator" class="htmx-indicator"> + <button class="btn btn-sm btn-warning" type="button" disabled> + <strong>Loading form...</strong> + <div class="spinner-grow spinner-grow-sm ms-2" + role="status" + aria-hidden="true"></div> + </button> + </div> + </div> + + <div class="col-auto"> + <div id="profile_dynsel_results-indicator" class="htmx-indicator"> + <button class="btn btn-sm btn-warning" type="button" disabled> + <strong>Loading results...</strong> + <div class="spinner-grow spinner-grow-sm ms-2" + role="status" + aria-hidden="true"></div> + </button> + </div> + </div> + + </div> + </div> + + <div class="col-lg-6"> + <h3>Matching profiles</h3> + <div id="profile_dynsel_results" class="border border-light m-2 p-1"></div> + </div> + + </div> + + <div id="nomination_form_response"> + <h3 class="mb-2">Not found?</h3> + <p> + Then add to our database by <a href="{% url 'profiles:profile_create' %}" target="_blank">creating a new Profile</a> (opens in new window). + </p> + </div> + +</div> diff --git a/scipost_django/colleges/templates/colleges/nominations.html b/scipost_django/colleges/templates/colleges/nominations.html index 9b876352b..736184c12 100644 --- a/scipost_django/colleges/templates/colleges/nominations.html +++ b/scipost_django/colleges/templates/colleges/nominations.html @@ -28,6 +28,8 @@ <strong>Help out by nominating candidates!</strong> </p> + <div id="new-nomination-container"></div> + <details id="voting_rounds-filter-details" class="card my-4"> <summary class="card-header d-flex flex-row align-items-center justify-content-between list-triangle"> <div class="fs-3">Search / Filter</div> @@ -50,7 +52,16 @@ hx-get="{% url 'colleges:_hx_voting_round_search_form' filter_set="empty" %}" hx-target="#voting_round-search-form-container">Clear Filters</button> - <a id="refresh-button" class="m-2 btn btn-primary"> + <button class="btn btn-success me-2 text-white" + type="button" + hx-get="{% url 'colleges:_hx_nominations_new' %}" + hx-trigger="click" + hx-target="#new-nomination-container"> + {% include "bi/plus-square.html" %} + Add New + </button> + + <a id="refresh-button" class="me-2 btn btn-primary"> {% include "bi/arrow-clockwise.html" %} Refresh</a> </div> @@ -65,80 +76,6 @@ <div id="search-voting_rounds-results" class="mt-2"></div> - <details class="border border-warning border-2 mt-4"> - <summary class="bg-warning bg-opacity-10 p-2 d-block list-triangle"> - <div class="fs-5">Nominate</div> - </summary> - - <div class="p-2"> - <div class="row"> - - <div class="col-lg-6"> - <h3>Procedure</h3> - <ul> - <li>Type your search query in the search form</li> - <li> - When the name you're looking for appears in the - <em>Matching profiles</em> list, double-click on it - </li> - <li>The nomination form will appear below</li> - <li>Non-eligibility flags (if any) will appear</li> - <li>If eligible, fill the form in (comments are optional)</li> - <li>Submit! (the vote will be arranged by EdAdmin)</li> - </ul> - <div class="row"> - - <div class="col-8"> - <form hx-post="{% url 'profiles:_hx_profile_dynsel_list' %}" - hx-trigger="keyup delay:200ms, change" - hx-target="#profile_dynsel_results" - hx-indicator="#profile_dynsel_results-indicator"> - <div id="profile_dynsel_form">{% crispy profile_dynsel_form %}</div> - </form> - </div> - - <div class="col-2"> - <div id="nomination_form_response-indicator" class="htmx-indicator"> - <button class="btn btn-sm btn-warning" type="button" disabled> - <strong>Loading form...</strong> - <div class="spinner-grow spinner-grow-sm ms-2" - role="status" - aria-hidden="true"></div> - </button> - </div> - </div> - - <div class="col-2"> - <div id="profile_dynsel_results-indicator" class="htmx-indicator"> - <button class="btn btn-sm btn-warning" type="button" disabled> - <strong>Loading results...</strong> - <div class="spinner-grow spinner-grow-sm ms-2" - role="status" - aria-hidden="true"></div> - </button> - </div> - </div> - - </div> - - <h3 class="mb-2">Not found?</h3> - <p> - Then add to our database by <a href="{% url 'profiles:profile_create' %}" target="_blank">creating a new Profile</a> (opens in new window). - </p> - </div> - - <div class="col-lg-6"> - <h3>Matching profiles</h3> - <div id="profile_dynsel_results" class="border border-light m-2 p-1"></div> - </div> - - </div> - - <div id="nomination_form_response"></div> - - </div> - </details> - {% if "edadmin" in user_roles or "active_senior_fellow" in user_roles %} <details id="ensure-specialties-details" class="border border-danger border-2 mt-4"> diff --git a/scipost_django/colleges/urls.py b/scipost_django/colleges/urls.py index c60f2c168..ee62e72ca 100644 --- a/scipost_django/colleges/urls.py +++ b/scipost_django/colleges/urls.py @@ -273,6 +273,11 @@ urlpatterns = [ views._hx_nominations_invitations, name="_hx_nominations_invitations", ), + path( + "_hx_nominations_new", + views._hx_nominations_new, + name="_hx_nominations_new", + ), path( "fellowship_invitation/<int:pk>/email_initial", views.FellowshipInvitationEmailInitialView.as_view(), diff --git a/scipost_django/colleges/views.py b/scipost_django/colleges/views.py index 479b87167..27ea43479 100644 --- a/scipost_django/colleges/views.py +++ b/scipost_django/colleges/views.py @@ -697,18 +697,8 @@ def nominations(request): """ List Nominations. """ - profile_dynsel_form = ProfileDynSelForm( - initial={ - "action_url_name": "colleges:_hx_nomination_form", - "action_url_base_kwargs": {}, - "action_target_element_id": "nomination_form_response", - "action_target_swap": "innerHTML", - } - ) context = { - "profile_dynsel_form": profile_dynsel_form, "search_nominations_form": FellowshipNominationSearchForm(), - "rounds": FellowshipNominationVotingRound.objects.all()[:10], } return render(request, "colleges/nominations.html", context) @@ -1050,6 +1040,24 @@ def _hx_nomination_decision_form(request, round_id): return render(request, "colleges/_hx_nomination_decision_form.html", context) +# Check permission to create a new nomination +def _hx_nominations_new(request): + """Render the contents of the new nomination form.""" + profile_dynsel_form = ProfileDynSelForm( + initial={ + "action_url_name": "colleges:_hx_nomination_form", + "action_url_base_kwargs": {}, + "action_target_element_id": "nomination_form_response", + "action_target_swap": "innerHTML", + } + ) + context = { + "profile_dynsel_form": profile_dynsel_form, + } + + return render(request, "colleges/_hx_nominations_new.html", context) + + @login_required @user_passes_test(is_edadmin) def _hx_nominations_invitations(request): -- GitLab