Skip to content

Instantly share code, notes, and snippets.

@luizrobertofreitas
Created March 19, 2013 14:09
Show Gist options
  • Save luizrobertofreitas/5196392 to your computer and use it in GitHub Desktop.
Save luizrobertofreitas/5196392 to your computer and use it in GitHub Desktop.
JavaScript: Beautiful modal confirmation for RoR
/* Overriding custom rails on delete action to provide a more beautiful modal confirmation */
this.extendOnDeleteRailsAction = function() {
$.rails.allowAction = function(element) {
var $link, $modal_html, message, modal_html;
message = element.data('confirm');
if (!message) {
return true;
}
$link = element.clone().removeAttr('class')
.removeAttr('data-confirm').addClass('btn')
.addClass('btn-danger').html("<i class=\"icon-trash icon-white\"></i> Sim, eu quero excluir!");
modal_html = "<div class=\"modal hide fade modalDialogOnDelete\" id=\"deleteModal\" role=\"dialog\">\n " +
"<div class=\"modal-header\">\n " +
" <a class=\"close\" data-dismiss=\"modal\">×</a>\n " +
" <h3>" + "Confirmar exclusão" + "</h3>\n </div>\n <div class=\"modal-body\">\n " +
" <h4>" + message + "</h4>\n </div>\n <div class=\"modal-footer\">\n " +
" <a data-dismiss=\"modal\" class=\"btn\"><i class=\"icon-remove\"></i> Cancelar</a>\n </div>\n</div>";
$modal_html = $(modal_html);
$modal_html.find('.modal-footer').append($link);
$modal_html.modal();
return false;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment