Skip to content

Instantly share code, notes, and snippets.

@seanlinsley
Last active December 10, 2015 20:08
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 seanlinsley/4485846 to your computer and use it in GitHub Desktop.
Save seanlinsley/4485846 to your computer and use it in GitHub Desktop.
WIP for github.com/gregbell/active_admin/issues/1815
$ ->
confirmBox = (message, inputs, callback) ->
html = """<div id="dialog_confirm" title="Confirmation"><p>#{message}</p>""" +
inputs.map((a)-> """<label>#{a}</label><input name="#{a}"></input>""").join("\n") +
"</div>"
$(html).appendTo('body').dialog
modal: true
buttons:
OK: ->
callback $(@).find('input').serializeArray()
$(@).dialog('close')
Cancel: ->
$(@).dialog('close').remove()
$('#batch_actions_selector li a').click (event)->
if message = $(@).data 'confirm'
confirmBox message, $(@).data('inputs'), (inputs)=>
$(@).trigger 'confirm:complete', inputs
else
$(@).trigger 'confirm:complete'
event.stopPropagation() # prevent Rails UJS click event
$('#batch_actions_selector li a').on 'confirm:complete', (event, inputs)->
$('#batch_action_inputs').val JSON.stringify inputs
$('#batch_action').val $(@).data('action')
$("#collection_selection").submit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment