mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 10:29:23 +02:00
additional work on delete
This commit is contained in:
parent
2107016dd6
commit
8d8c31f37a
2 changed files with 27 additions and 17 deletions
|
@ -1229,7 +1229,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
let tableHeaders = document.querySelectorAll('.domain-requests__table th[data-sortable]');
|
||||
let tableAnnouncementRegion = document.querySelector('.domain-requests__table-wrapper .usa-table__announcement-region')
|
||||
|
||||
function deleteDomainRequest(domainRequestPk) {
|
||||
function deleteDomainRequest(domainRequestPk,pageToDisplay) {
|
||||
const csrfToken = getCsrfToken();
|
||||
|
||||
// Create FormData object and append the CSRF token
|
||||
|
@ -1247,12 +1247,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
console.log('response', data);
|
||||
// Perform any additional actions, e.g., updating the UI
|
||||
loadDomainRequests(pageToDisplay, currentSortBy, currentOrder, hasLoaded, currentSearchTerm);
|
||||
//return response.json();
|
||||
})
|
||||
// .then(data => {
|
||||
// console.log('response', data);
|
||||
// // Perform any additional actions, e.g., updating the UI
|
||||
// })
|
||||
.catch(error => console.error('Error fetching domain requests:', error));
|
||||
}
|
||||
|
||||
|
@ -1361,7 +1362,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
|
||||
const modalSubmit = `
|
||||
<button type="button"
|
||||
class="usa-button usa-button--secondary usa-moda__submit"
|
||||
class="usa-button usa-button--secondary usa-modal__submit"
|
||||
data-pk = ${request.id}
|
||||
name="delete-domain-request">Yes, delete request</button>
|
||||
`
|
||||
|
@ -1443,17 +1444,22 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
// initialize modals immediately after the DOM content is updated
|
||||
initializeModals();
|
||||
|
||||
let subbmitButtons = document.querySelectorAll('.usa-moda__submit');
|
||||
subbmitButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
pk = button.getAttribute('data-pk');
|
||||
console.log('pk ' + pk);
|
||||
deleteDomainRequest(pk);
|
||||
loadDomainRequests(1, 'id', 'asc');
|
||||
const modals = document.querySelectorAll('.usa-modal__content');
|
||||
|
||||
modals.forEach(modal => {
|
||||
const submitButton = modal.querySelector('.usa-modal__submit');
|
||||
const closeButton = modal.querySelector('.usa-modal__close');
|
||||
submitButton.addEventListener('click', function() {
|
||||
pk = submitButton.getAttribute('data-pk');
|
||||
closeButton.click();
|
||||
let pageToDisplay = data.page;
|
||||
if (data.total == 1 && data.unfiltered_total > 1) {
|
||||
pageToDisplay--;
|
||||
}
|
||||
deleteDomainRequest(pk, pageToDisplay);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
if (hasLoaded)
|
||||
ScrollToElement('id', 'domain-requests-header');
|
||||
|
||||
|
|
|
@ -798,8 +798,11 @@ class DomainRequestDeleteView(DomainRequestPermissionDeleteView):
|
|||
domain_request: DomainRequest = self.get_object()
|
||||
contacts_to_delete, duplicates = self._get_orphaned_contacts(domain_request)
|
||||
|
||||
self.object = self.get_object()
|
||||
self.object.delete()
|
||||
|
||||
# Delete the DomainRequest
|
||||
response = super().post(request, *args, **kwargs)
|
||||
# response = super().post(request, *args, **kwargs)
|
||||
|
||||
# Delete orphaned contacts - but only for if they are not associated with a user
|
||||
Contact.objects.filter(id__in=contacts_to_delete, user=None).delete()
|
||||
|
@ -811,7 +814,8 @@ class DomainRequestDeleteView(DomainRequestPermissionDeleteView):
|
|||
duplicates_to_delete, _ = self._get_orphaned_contacts(domain_request, check_db=True)
|
||||
Contact.objects.filter(id__in=duplicates_to_delete, user=None).delete()
|
||||
|
||||
return response
|
||||
# Return a 200 response with an empty body
|
||||
return HttpResponse(status=200)
|
||||
|
||||
def _get_orphaned_contacts(self, domain_request: DomainRequest, check_db=False):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue