Skip to content

Instantly share code, notes, and snippets.

@carloswherbet
Forked from rubencp/Gemfile
Created May 23, 2017 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carloswherbet/0d8ea53c3d406b4abb550e736ec5d2e5 to your computer and use it in GitHub Desktop.
Save carloswherbet/0d8ea53c3d406b4abb550e736ec5d2e5 to your computer and use it in GitHub Desktop.
Override Confirm dialog Rails 4 and Bootbox.js
//= require bootbox
gem 'bootbox-rails', '~>0.3'
<a href="#" id="link">Click me to verify that it bootbox is working</a>
<script>
$(function() {
$('#link').click(function() {
bootbox.alert("Hello world!");
})
})
</script>
<%= link_to 'Deleta', admin_path(user), :method => :delete, data: { confirm: "Are you 1000% Sure?" }, :class => "btn pull-right btn-danger btn-xs" %>
var ready;
ready = function() {
window.myCustomConfirmBox = function(message, callback) {
return bootbox.dialog({
message: message,
"class": 'class-confirm-box',
className: "my-modal",
buttons: {
success: {
label: "More than Sure, Thankyou!",
className: "btn-danger",
callback: function() {
return callback();
}
},
chickenout: {
label: "No, I'll chicken out!",
className: "btn-success pull-left"
}
}
});
};
return $.rails.allowAction = function(element) {
var answer, callback, message;
message = element.data("confirm");
if (!message) {
return true;
}
answer = false;
callback = void 0;
if ($.rails.fire(element, "confirm")) {
myCustomConfirmBox(message, function() {
var oldAllowAction;
callback = $.rails.fire(element, "confirm:complete", [answer]);
if (callback) {
oldAllowAction = $.rails.allowAction;
$.rails.allowAction = function() {
return true;
};
element.trigger("click");
return $.rails.allowAction = oldAllowAction;
}
});
}
return false;
};
};
$(document).ready(ready);
$(document).on('page:load', ready);
ready = ->
window.myCustomConfirmBox = (message,callback) ->
bootbox.dialog
message: message
class: 'class-confirm-box'
className: "my-modal"
buttons:
success:
label: "More than Sure, Thankyou!"
className: "btn-danger"
callback: -> callback()
chickenout:
label: "No, I'll chicken out!"
className: "btn-success pull-left"
$.rails.allowAction = (element) ->
message = element.data("confirm")
return true unless message
answer = false
callback = undefined
if $.rails.fire(element, "confirm")
myCustomConfirmBox message, ->
callback = $.rails.fire(element, "confirm:complete", [answer])
if callback
oldAllowAction = $.rails.allowAction
$.rails.allowAction = ->
true
element.trigger "click"
$.rails.allowAction = oldAllowAction
false
$(document).ready(ready)
$(document).on('page:load', ready)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment