From 628fbac8f9ce60c5124ee83b288733ae24e48b63 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 26 Jul 2024 12:26:31 +1000 Subject: [PATCH] Enhance modal/delete to fire a post ajax to the endpoint on confirmation, and optionally delete row of triggering element --- resources/components/modal/delete.blade.php | 32 ++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/resources/components/modal/delete.blade.php b/resources/components/modal/delete.blade.php index 1278140..3d9ed6c 100644 --- a/resources/components/modal/delete.blade.php +++ b/resources/components/modal/delete.blade.php @@ -10,7 +10,7 @@ @@ -23,13 +23,37 @@ $(document).ready(function() { $('.{{$trigger}}').click(function(e) { confirm_delete.show(); - console.log($('#confirm_delete') - .find('.btn-ok')); + $('#confirm_delete') .find('.btn-ok') - .attr('href',e.currentTarget.href); + .attr('href',$(this).attr('href')) + .attr('data-id',$(this).data('id')); + return false; }); + + $('.btn-ok').click(function(item) { + var that = $(this); + + // Delete + $.ajax({ + url: that.attr('href'), + method: 'POST', + dataType: 'json', + + }).done(function(data) { + if (that.data('hide') == 'row') + $('a[data-id="'+that.data('id')+'"].{{$trigger}}').closest('tr').hide(); + + }).fail(function() { + alert('Hmm, that didnt work?'); + }); + + // Clear the data cache + that.removeData(); + confirm_delete.hide(); + return false; + }) }); @append \ No newline at end of file