Enhance modal/delete to fire a post ajax to the endpoint on confirmation, and optionally delete row of triggering element
This commit is contained in:
parent
4a4cf3c5bf
commit
628fbac8f9
@ -10,7 +10,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||||
<a type="button" class="btn btn-danger btn-ok">Delete</a>
|
<a type="button" class="btn btn-danger btn-ok" data-hide="{{ $hide }}">Delete</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -23,13 +23,37 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('.{{$trigger}}').click(function(e) {
|
$('.{{$trigger}}').click(function(e) {
|
||||||
confirm_delete.show();
|
confirm_delete.show();
|
||||||
console.log($('#confirm_delete')
|
|
||||||
.find('.btn-ok'));
|
|
||||||
$('#confirm_delete')
|
$('#confirm_delete')
|
||||||
.find('.btn-ok')
|
.find('.btn-ok')
|
||||||
.attr('href',e.currentTarget.href);
|
.attr('href',$(this).attr('href'))
|
||||||
|
.attr('data-id',$(this).data('id'));
|
||||||
|
|
||||||
return false;
|
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;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@append
|
@append
|
Loading…
Reference in New Issue
Block a user