Created
December 5, 2011 21:20
-
-
Save matiaskorhonen/1435401 to your computer and use it in GitHub Desktop.
Prettier Rails confirmation dialogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
link_to("Destroy", "http://www.example.com", :method => :delete, :confirm => "Are you sure?") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
customConfirmBox = (message, callback) -> | |
template = ''' | |
<div id="dialog-confirm" title="Confirmation" class="hidden"> | |
<p> | |
{{message}} | |
</p> | |
</div> | |
''' | |
view = | |
message: message | |
html = Mustache.to_html(template, view) | |
$(html).appendTo("body").dialog | |
resizable: false | |
modal: true | |
buttons: | |
"Yes, I'm sure": -> | |
callback() | |
$(@).dialog("close").remove() | |
"Cancel": -> | |
$(@).dialog("close").remove() | |
$.rails.allowAction = (element) -> | |
message = element.data("confirm") | |
answer = false | |
return true unless message? | |
if $.rails.fire(element, "confirm") | |
customConfirmBox message, -> | |
callback = $.rails.fire(element, "confirm:complete", [answer]) | |
if callback? | |
oldAllowAction = $.rails.allowAction | |
$.rails.allowAction = -> | |
true | |
element.trigger("click") | |
$.rails.allowAction = oldAllowAction | |
return false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment