Skip to content

Commit

Permalink
Extract delete logic to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
psrpinto committed Feb 16, 2024
1 parent 3d269c7 commit 9e1cb64
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions assets/js/translation-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,13 @@
}
);

$('.delete-event').on('click', function(e) {
e.preventDefault();
if ( ! confirm( 'Are you sure you want to delete this event?' ) ) {
return;
$('.delete-event').on(
'click',
function ( e ) {
e.preventDefault();
handleDelete()
}
const $form = $('.translation-event-form');
$('#form-name').val('delete_event');
$('#event-form-action').val('delete');
$.ajax({
type: 'POST',
url: $translation_event.url,
data:$form.serialize(),
success: function(response) {
window.location = response.data.eventDeleteUrl;
},
error: function(error) {
$gp.notices.error(response.data.message);
},
});
});
);
}
);

Expand Down Expand Up @@ -89,6 +76,26 @@
);
}

function handleDelete() {
if ( ! confirm( 'Are you sure you want to delete this event?' ) ) {
return;
}
const $form = $('.translation-event-form');
$('#form-name').val('delete_event');
$('#event-form-action').val('delete');
$.ajax({
type: 'POST',
url: $translation_event.url,
data:$form.serialize(),
success: function(response) {
window.location = response.data.eventDeleteUrl;
},
error: function(error) {
$gp.notices.error(response.data.message);
},
});
}

function validateEventDates() {
const startDateTimeInput = $('#event-start');
const endDateTimeInput = $('#event-end');
Expand Down

0 comments on commit 9e1cb64

Please sign in to comment.