Created
September 6, 2016 15:42
-
-
Save wdog/885ee8473cf96cd1bd7fbd336e6fec45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script language="javascript"> | |
var deleter = { | |
linkSelector: "a[data-delete]", | |
modalTitle: "Confermi Eliminazione?", | |
modalMessage: "Questo dato non potra' essere recuperato?", | |
modalCancelButtonText:'Annulla', | |
modalConfirmButtonText: "Si Elimina!", | |
laravelToken: null, | |
url: "/", | |
init: function () { | |
$(this.linkSelector).on('click', {self: this}, this.handleClick); | |
}, | |
handleClick: function (event) { | |
event.preventDefault(); | |
var self = event.data.self; | |
var link = $(this); | |
self.modalTitle = link.data('title') || self.modalTitle; | |
self.modalMessage = link.data('message') || self.modalMessage; | |
self.modalConfirmButtonText = link.data('button-text') || self.modalConfirmButtonText; | |
self.url = link.attr('href'); | |
self.laravelToken = $("meta[name=token]").attr('content'); | |
self.confirmDelete(); | |
}, | |
confirmDelete: function () { | |
swal({ | |
title: this.modalTitle, | |
text: this.modalMessage, | |
type: "warning", | |
showCancelButton: true, | |
confirmButtonColor: "#DD6B55", | |
confirmButtonText: this.modalConfirmButtonText, | |
cancelButtonText: this.modalCancelButtonText, | |
closeOnConfirm: true | |
}, | |
function () { | |
this.makeDeleteRequest() | |
}.bind(this) | |
); | |
}, | |
makeDeleteRequest: function () { | |
var form = | |
$('<form>', { | |
'method': 'POST', | |
'action': this.url | |
}); | |
var token = | |
$('<input>', { | |
'type': 'hidden', | |
'name': '_token', | |
'value': "{!! csrf_token(); !!}" | |
}); | |
var hiddenInput = | |
$('<input>', { | |
'name': '_method', | |
'type': 'hidden', | |
'value': 'DELETE' | |
}); | |
return form.append(token, hiddenInput).appendTo('body').submit(); | |
} | |
}; | |
deleter.init(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment