Skip to content

Commit

Permalink
only reload contact-tab content when submiting form
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalfox committed Oct 19, 2024
1 parent f0517a3 commit 5d852a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion staffing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,6 @@ def mission_contacts(request, mission_id):
form = MissionContactsForm(request.POST, instance=mission)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse("staffing:mission_home", args=[mission.id, ]))

# Unbound form
form = MissionContactsForm(instance=mission)
Expand Down
14 changes: 11 additions & 3 deletions templates/staffing/mission_contacts.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
{# of a page loaded in ajax #}
{% load i18n %}

<div hx-on::after-settle="$('#contact_edit').hide();"
hx-target="this"
hx-swap="outerHTML">

<div id="contact_display">
{% for mission_contact in mission_contacts %}
{% ifchanged mission_contact.company %}
Expand All @@ -28,15 +32,17 @@ <h3 class="mt-2"><a href="{% url 'crm:company_detail' mission_contact.company.id
{% if pydici_feature.contacts_write %}
<br/>
<a class="btn btn-primary" href="javascript:;"
onClick="$('#contact_display').hide();$('#contact_edit').show();">
onClick="$('#contact_display').hide();$('#contact_edit').show();$('.django-select2').djangoSelect2({ 'theme': 'bootstrap-5', 'width': 'auto'});">
{% trans "Add or edit" %}</a>
</div>

<div id="contact_edit">
<form action="{% url 'staffing:mission_contacts' mission.id %}#tab-contacts" method="POST">
<form>
{{ mission_contact_form.non_field_errors }}
{{ mission_contact_form }}
<input class="btn btn-primary" type="submit" value="{% trans 'Save' %}"/>
<input class="btn btn-primary" type="submit" value="{% trans 'Save' %}"
hx-post="{% url 'staffing:mission_contacts' mission.id %}#tab-contacts"
/>
</form>
<br/>
<a href="{% url 'crm:linked_mission_contact_create' mission.id %}?return_to={% url 'staffing:mission_home' mission.id %}#goto_tab-contacts" class="btn btn-primary">{% trans "New mission contact" %}</a>
Expand All @@ -51,5 +57,7 @@ <h3 class="mt-2"><a href="{% url 'crm:company_detail' mission_contact.company.id
<script type="text/javascript">
$(document).ready(function() {
$('#contact_edit').hide();
htmx.process(document.body);
});
</script>
</div>

0 comments on commit 5d852a0

Please sign in to comment.