Advertisement
Guest User

Untitled

a guest
May 27th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. var deleter = {
  2.  
  3. linkSelector : "a[data-delete]",
  4. modalTitle : "Are you sure?",
  5. modalMessage : "You will not be able to recover this entry?",
  6. modalConfirmButtonText: "Yes, delete it!",
  7. laravelToken : null,
  8. url : "/",
  9.  
  10. init: function() {
  11. $(this.linkSelector).on('click', {self:this}, this.handleClick);
  12. },
  13.  
  14. handleClick: function(event) {
  15. event.preventDefault();
  16.  
  17. var self = event.data.self;
  18. var link = $(this);
  19.  
  20. self.modalTitle = link.data('title') || self.modalTitle;
  21. self.modalMessage = link.data('message') || self.modalMessage;
  22. self.modalConfirmButtonText = link.data('button-text') || self.modalConfirmButtonText;
  23. self.url = link.attr('href');
  24. self.laravelToken = $("meta[name=token]").attr('content');
  25.  
  26. self.confirmDelete();
  27.  
  28. },
  29.  
  30. confirmDelete: function() {
  31. swal({
  32. title : this.modalTitle,
  33. text : this.modalMessage,
  34. type : "warning",
  35. showCancelButton : true,
  36. confirmButtonColor: "#DD6B55",
  37. confirmButtonText : this.modalConfirmButtonText,
  38. closeOnConfirm : true
  39. }).then(function(isConfirm) {
  40. if (isConfirm) {
  41. this.makeDeleteRequest();
  42. }
  43. }.bind(this));
  44. },
  45.  
  46. makeDeleteRequest: function() {
  47.  
  48. var form =
  49. $('<form>', {
  50. 'method': 'POST',
  51. 'action': this.url
  52. });
  53.  
  54. var token =
  55. $('<input>', {
  56. 'type': 'hidden',
  57. 'name': '_token',
  58. 'value': this.laravelToken
  59. });
  60.  
  61. var hiddenInput =
  62. $('<input>', {
  63. 'name': '_method',
  64. 'type': 'hidden',
  65. 'value': 'DELETE'
  66. });
  67.  
  68. return form.append(token, hiddenInput).appendTo('body').submit();
  69. }
  70. };
  71.  
  72. deleter.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement