From 3fca767624f4211ce742d97d4ffb53eb55029fb6 Mon Sep 17 00:00:00 2001 From: Davide Bellini Date: Thu, 1 Oct 2015 23:28:01 +0200 Subject: [PATCH] Use SweetAlert for confirmation dialog --- resources/assets/js/app.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 660ed880..126348d0 100755 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -48,7 +48,17 @@ $(function() { return methodForm; }) .removeAttr('href') - .attr('onclick', ' if ($(this).hasClass(\'confirm-action\')) { if(confirm("Are you sure you want to do this?")) { $(this).find("form").submit(); } } else { $(this).find("form").submit(); }'); + .on('click', function() { + var button = $(this); + + if (button.hasClass('confirm-action')) { + askConfirmation(function() { + button.find("form").submit(); + }); + } else { + button.find("form").submit(); + } + }); // Messenger config Messenger.options = { @@ -351,3 +361,16 @@ $(function() { .addClass("active"); } }); + +function askConfirmation(callback) { + swal({ + type: "warning", + title: "Confirm your action", + text: "Are you sure you want to do this ?", + confirmButtonText: "Yes", + confirmButtonColor: "#FF6F6F", + showCancelButton: true + }, function() { + callback(); + }); +}