mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 18:39:21 +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 tableHeaders = document.querySelectorAll('.domain-requests__table th[data-sortable]');
|
||||||
let tableAnnouncementRegion = document.querySelector('.domain-requests__table-wrapper .usa-table__announcement-region')
|
let tableAnnouncementRegion = document.querySelector('.domain-requests__table-wrapper .usa-table__announcement-region')
|
||||||
|
|
||||||
function deleteDomainRequest(domainRequestPk) {
|
function deleteDomainRequest(domainRequestPk,pageToDisplay) {
|
||||||
const csrfToken = getCsrfToken();
|
const csrfToken = getCsrfToken();
|
||||||
|
|
||||||
// Create FormData object and append the CSRF token
|
// Create FormData object and append the CSRF token
|
||||||
|
@ -1247,12 +1247,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
return response.json();
|
loadDomainRequests(pageToDisplay, currentSortBy, currentOrder, hasLoaded, currentSearchTerm);
|
||||||
})
|
//return response.json();
|
||||||
.then(data => {
|
|
||||||
console.log('response', data);
|
|
||||||
// Perform any additional actions, e.g., updating the UI
|
|
||||||
})
|
})
|
||||||
|
// .then(data => {
|
||||||
|
// console.log('response', data);
|
||||||
|
// // Perform any additional actions, e.g., updating the UI
|
||||||
|
// })
|
||||||
.catch(error => console.error('Error fetching domain requests:', error));
|
.catch(error => console.error('Error fetching domain requests:', error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1361,7 +1362,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
||||||
const modalSubmit = `
|
const modalSubmit = `
|
||||||
<button type="button"
|
<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}
|
data-pk = ${request.id}
|
||||||
name="delete-domain-request">Yes, delete request</button>
|
name="delete-domain-request">Yes, delete request</button>
|
||||||
`
|
`
|
||||||
|
@ -1443,16 +1444,21 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
// initialize modals immediately after the DOM content is updated
|
// initialize modals immediately after the DOM content is updated
|
||||||
initializeModals();
|
initializeModals();
|
||||||
|
|
||||||
let subbmitButtons = document.querySelectorAll('.usa-moda__submit');
|
const modals = document.querySelectorAll('.usa-modal__content');
|
||||||
subbmitButtons.forEach(button => {
|
|
||||||
button.addEventListener('click', function() {
|
|
||||||
pk = button.getAttribute('data-pk');
|
|
||||||
console.log('pk ' + pk);
|
|
||||||
deleteDomainRequest(pk);
|
|
||||||
loadDomainRequests(1, 'id', 'asc');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
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)
|
if (hasLoaded)
|
||||||
ScrollToElement('id', 'domain-requests-header');
|
ScrollToElement('id', 'domain-requests-header');
|
||||||
|
|
|
@ -798,8 +798,11 @@ class DomainRequestDeleteView(DomainRequestPermissionDeleteView):
|
||||||
domain_request: DomainRequest = self.get_object()
|
domain_request: DomainRequest = self.get_object()
|
||||||
contacts_to_delete, duplicates = self._get_orphaned_contacts(domain_request)
|
contacts_to_delete, duplicates = self._get_orphaned_contacts(domain_request)
|
||||||
|
|
||||||
|
self.object = self.get_object()
|
||||||
|
self.object.delete()
|
||||||
|
|
||||||
# Delete the DomainRequest
|
# 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
|
# 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()
|
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)
|
duplicates_to_delete, _ = self._get_orphaned_contacts(domain_request, check_db=True)
|
||||||
Contact.objects.filter(id__in=duplicates_to_delete, user=None).delete()
|
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):
|
def _get_orphaned_contacts(self, domain_request: DomainRequest, check_db=False):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue