Skip to content

Instantly share code, notes, and snippets.

@matiaskorhonen
Created December 5, 2011 21:20
Show Gist options
  • Save matiaskorhonen/1435401 to your computer and use it in GitHub Desktop.
Save matiaskorhonen/1435401 to your computer and use it in GitHub Desktop.
Prettier Rails confirmation dialogs
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