Skip to content

Commit b71c725

Browse files
Bugfixes for modal cleanup
1 parent 2869082 commit b71c725

12 files changed

Lines changed: 164 additions & 19 deletions

File tree

routers/core/invitation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ async def create_invitation(
139139
"organization/partials/invitations_list.html",
140140
{"active_invitations": active_invitations},
141141
)
142+
response.headers["HX-Trigger"] = "modalDismiss"
142143
return append_toast(response, request, templates, "Invitation sent successfully.")
143144
return RedirectResponse(url=f"/organizations/{organization_id}", status_code=303)
144145

routers/core/role.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def create_role(
9696
"ValidPermissions": ValidPermissions,
9797
},
9898
)
99+
response.headers["HX-Trigger"] = "modalDismiss"
99100
return append_toast(response, request, templates, "Role created successfully.")
100101
return RedirectResponse(
101102
url=organization_router.url_path_for("read_organization", org_id=organization_id),
@@ -185,6 +186,7 @@ def update_role(
185186
"ValidPermissions": ValidPermissions,
186187
},
187188
)
189+
response.headers["HX-Trigger"] = "modalDismiss"
188190
return append_toast(response, request, templates, "Role updated successfully.")
189191
return RedirectResponse(
190192
url=organization_router.url_path_for("read_organization", org_id=organization_id),

routers/core/user.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ async def update_profile(
109109
"allowed_formats": list(ALLOWED_CONTENT_TYPES.keys()),
110110
},
111111
)
112+
response.headers["HX-Trigger"] = "profileUpdated"
112113
return append_toast(response, request, templates, "Profile updated successfully.")
113114
return RedirectResponse(url=router.url_path_for("read_profile"), status_code=303)
114115

@@ -193,6 +194,7 @@ def update_user_role(
193194
"ValidPermissions": ValidPermissions,
194195
},
195196
)
197+
response.headers["HX-Trigger"] = "modalDismiss"
196198
return append_toast(response, request, templates, "User role updated successfully.")
197199
return RedirectResponse(
198200
url=organization_router.url_path_for("read_organization", org_id=organization_id),

templates/base.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@
9393
if (flash && flash.message) showToast(flash.message, flash.level);
9494
} catch(e) {}
9595
})();
96+
// Global handler: when a server response includes HX-Trigger: modalDismiss,
97+
// clean up any Bootstrap modal backdrop left behind by OOB swaps that
98+
// replaced the modal element before afterRequest could call .hide().
99+
document.body.addEventListener('modalDismiss', function() {
100+
document.querySelectorAll('.modal-backdrop').forEach(function(el) { el.remove(); });
101+
document.body.classList.remove('modal-open');
102+
document.body.style.removeProperty('overflow');
103+
document.body.style.removeProperty('padding-right');
104+
});
96105
</script>
97106
{% block extra_scripts %}{% endblock %}
98107
</body>

templates/organization/modals/edit_organization_modal.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<div class="modal-dialog">
55
<div class="modal-content">
66
<form method="POST" action="{{ url_for('update_organization', org_id=organization.id) }}"
7-
hx-post="{{ url_for('update_organization', org_id=organization.id) }}"
8-
hx-on::after-request="if(event.detail.successful) { bootstrap.Modal.getInstance(document.getElementById('editOrganizationModal'))?.hide(); }">
7+
hx-post="{{ url_for('update_organization', org_id=organization.id) }}">
98
<div class="modal-header">
109
<h5 class="modal-title" id="editOrganizationModalLabel">Edit Organization</h5>
1110
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

templates/organization/modals/members_card.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ <h4>Pending Invitations</h4>
104104
<form method="POST" action="{{ url_for('create_invitation') }}"
105105
hx-post="{{ url_for('create_invitation') }}"
106106
hx-target="#members-card-content"
107-
hx-swap="innerHTML"
108-
hx-on::after-request="if(event.detail.successful) { bootstrap.Modal.getInstance(document.getElementById('inviteMemberModal'))?.hide(); }">
107+
hx-swap="innerHTML">
109108
<div class="modal-header">
110109
<h5 class="modal-title" id="inviteMemberModalLabel">Invite New Member</h5>
111110
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
@@ -146,8 +145,7 @@ <h5 class="modal-title" id="inviteMemberModalLabel">Invite New Member</h5>
146145
<form method="POST" action="{{ url_for('update_user_role') }}"
147146
hx-post="{{ url_for('update_user_role') }}"
148147
hx-target="#members-card-content"
149-
hx-swap="innerHTML"
150-
hx-on::after-request="if(event.detail.successful) { bootstrap.Modal.getInstance(document.getElementById('editUserRoleModal{{ member.id }}'))?.hide(); }">
148+
hx-swap="innerHTML">
151149
<div class="modal-header">
152150
<h5 class="modal-title" id="editUserRoleModalLabel{{ member.id }}">Edit Roles for {{ member.name }}</h5>
153151
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

templates/organization/modals/roles_card.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@
8383
<form method="POST" action="{{ url_for('create_role') }}"
8484
hx-post="{{ url_for('create_role') }}"
8585
hx-target="#roles-card-content"
86-
hx-swap="innerHTML"
87-
hx-on::after-request="if(event.detail.successful) { bootstrap.Modal.getInstance(document.getElementById('createRoleModal'))?.hide(); }">
86+
hx-swap="innerHTML">
8887
<div class="modal-header">
8988
<h5 class="modal-title" id="createRoleModalLabel">Create New Role</h5>
9089
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
@@ -131,8 +130,7 @@ <h5 class="modal-title" id="createRoleModalLabel">Create New Role</h5>
131130
<form method="POST" action="{{ url_for('update_role') }}"
132131
hx-post="{{ url_for('update_role') }}"
133132
hx-target="#roles-card-content"
134-
hx-swap="innerHTML"
135-
hx-on::after-request="if(event.detail.successful) { bootstrap.Modal.getInstance(document.getElementById('editRoleModal{{ role.id }}'))?.hide(); }">
133+
hx-swap="innerHTML">
136134
<div class="modal-header">
137135
<h5 class="modal-title" id="editRoleModalLabel{{ role.id }}">Edit Role: {{ role.name }}</h5>
138136
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

templates/organization/partials/members_table.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ <h4>Pending Invitations</h4>
9090
<form method="POST" action="{{ url_for('update_user_role') }}"
9191
hx-post="{{ url_for('update_user_role') }}"
9292
hx-target="#members-card-content"
93-
hx-swap="innerHTML"
94-
hx-on::after-request="if(event.detail.successful) { bootstrap.Modal.getInstance(document.getElementById('editUserRoleModal{{ member.id }}'))?.hide(); }">
93+
hx-swap="innerHTML">
9594
<div class="modal-header">
9695
<h5 class="modal-title" id="editUserRoleModalLabel{{ member.id }}">Edit Roles for {{ member.name }}</h5>
9796
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

templates/organization/partials/roles_table.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666
<form method="POST" action="{{ url_for('update_role') }}"
6767
hx-post="{{ url_for('update_role') }}"
6868
hx-target="#roles-card-content"
69-
hx-swap="innerHTML"
70-
hx-on::after-request="if(event.detail.successful) { bootstrap.Modal.getInstance(document.getElementById('editRoleModal{{ role.id }}'))?.hide(); }">
69+
hx-swap="innerHTML">
7170
<div class="modal-header">
7271
<h5 class="modal-title" id="editRoleModalLabel{{ role.id }}">Edit Role: {{ role.name }}</h5>
7372
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

templates/users/partials/profile_form.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
hx-post="{{ url_for('update_profile') }}"
44
hx-target="#profile-display"
55
hx-swap="innerHTML"
6-
hx-encoding="multipart/form-data"
7-
hx-on::after-request="if(event.detail.successful) { document.getElementById('edit-profile').style.display='none'; document.getElementById('basic-info').style.display='block'; }">
6+
hx-encoding="multipart/form-data">
87
<div class="mb-3">
98
<label for="name" class="form-label">Name</label>
109
<input type="text" class="form-control" id="name" name="name" value="{{ user.name }}">

0 commit comments

Comments
 (0)