Skip to content

Instantly share code, notes, and snippets.

@rubencp
Forked from cedricdekimpe/application.js
Last active August 29, 2015 14:06
Show Gist options
  • Save rubencp/f87b827707d9440d3941 to your computer and use it in GitHub Desktop.
Save rubencp/f87b827707d9440d3941 to your computer and use it in GitHub Desktop.
//= require bootbox.min
$(document).ready(function() {
$.rails.allowAction = function(element) {
var message = element.data('confirm'),
answer = false, callback;
if (!message) { return true; }
if ($.rails.fire(element, 'confirm')) {
myCustomConfirmBox(message, function() {
callback = $.rails.fire(element,
'confirm:complete', [answer]);
if(callback) {
var oldAllowAction = $.rails.allowAction;
$.rails.allowAction = function() { return true; };
element.trigger('click');
$.rails.allowAction = oldAllowAction;
}
});
}
return false;
}
function myCustomConfirmBox(message, callback) {
bootbox.confirm(message, "Cancel", "Yes", function(confirmed) {
if(confirmed){
callback();
}
});
}
});
@rubencp
Copy link
Author

rubencp commented Sep 6, 2014

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"
}
}
});
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment