Skip to content

Commit

Permalink
fix the bug after add/deteling family for an attendee in attendee upd…
Browse files Browse the repository at this point in the history
…ate page
  • Loading branch information
xjlin0 committed May 20, 2024
1 parent f4124bf commit 2f9a6ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions attendees/static/js/persons/attendee_update_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ Attendees.datagridUpdate = {
}, {});
},

removeFamilyFromAttendeeDropDowns: (deletingFamilyId) => {
const newAttendeeDxDropDownButton = Attendees.datagridUpdate.attendeeMainDxForm.getEditor('add_new_attendee');
Attendees.utilities.removeElementFromArray(Attendees.datagridUpdate.families, 'id', deletingFamilyId);
document.querySelectorAll('div.dropdown-menu-right a').forEach(x=> { if (x.getAttribute('href').includes(deletingFamilyId)) {x.parentNode.removeChild(x)} });
newAttendeeDxDropDownButton.option('dataSource', Attendees.datagridUpdate.families);
if (Attendees.datagridUpdate.families.length < 1) {
newAttendeeDxDropDownButton.option('text', '+New family member');
newAttendeeDxDropDownButton.option('hint', 'Need at least one family to add family members');
newAttendeeDxDropDownButton.option('disabled', true);
}
},

patchNewAttendeeDropDownAndFamilyAddress: (newFamily) => {
const newAttendeeDxDropDownButton = Attendees.datagridUpdate.attendeeMainDxForm.getEditor('add_new_attendee');
const $newAttendeeLinkWithoutFamily = $('a.add-new-attendee').last(); // Non-devextreme button for creating attendee (to family)
Expand Down Expand Up @@ -256,6 +268,7 @@ Attendees.datagridUpdate = {
});
}
if (Attendees.datagridUpdate.families.length > 0) {
newAttendeeDxDropDownButton.option('disabled', false);
newAttendeeDxDropDownButton.option('dataSource', Attendees.datagridUpdate.families);
newAttendeeDxDropDownButton.option('hint', 'Select a family to add a new member');
}
Expand Down Expand Up @@ -3625,6 +3638,7 @@ Attendees.datagridUpdate = {
url: `${$('form#family-attr-update-popup-form').attr('action')}${Attendees.datagridUpdate.familyAttrPopupDxFormData.id}/`,
method: 'DELETE',
success: (response) => {
Attendees.datagridUpdate.removeFamilyFromAttendeeDropDowns(familyAttrButton.value);
Attendees.datagridUpdate.familyAttrPopup.hide();
DevExpress.ui.notify(
{
Expand Down
5 changes: 5 additions & 0 deletions attendees/static/js/shared/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ Attendees.utilities = {
window.sessionStorage.setItem(storageKey, JSON.stringify(state));
}, // to remove annoyed search text. Custom stateStoring interfered with column visibility

removeElementFromArray: (array, key, value) => {
const index = array.findIndex(obj => obj[key] === value);
return array.splice(index, 1);
},

genderEnums: () => {
return [
{name: 'MALE'},
Expand Down

0 comments on commit 2f9a6ac

Please sign in to comment.