Skip to content

Instantly share code, notes, and snippets.

@nicogaldamez
Last active March 14, 2017 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicogaldamez/d4a363f60dc881b50fd382d20b659ff9 to your computer and use it in GitHub Desktop.
Save nicogaldamez/d4a363f60dc881b50fd382d20b659ff9 to your computer and use it in GitHub Desktop.
ConfirmationBox
App.ConfirmationBox =
defaults:
title: 'Warning'
message: 'Are you sure?'
cancel_btn: 'Cancel'
confirm_btn: 'Confirm'
confirmDialog: (element) ->
title = element.data('title') || @defaults['title']
message = element.data('confirm') || @defaults['message']
cancel_btn = element.data('cancel-btn') || @defaults['cancel_btn']
confirm_btn = element.data('confirm-btn') || @defaults['confirm_btn']
element.data('confirm', null)
bootbox.confirm
title: title
message: message
buttons:
cancel:
label: cancel_btn
className: 'btn-default'
confirm:
label: confirm_btn
className: 'btn-danger'
callback: (result) ->
element.trigger 'click.rails' if result
element.data('confirm', message)
return
$(document).on 'confirm', (event) ->
element = $(event.target)
App.ConfirmationBox.confirmDialog(element)
false
<div class="btn-group">
<%= link_to 'Eliminar', product, class: 'btn btn-danger', method: :delete,
data: { confirm: 'Se eliminará el producto junto a todos sus modelos de forma permanente',
'disable-with' => 'Eliminando...', title: '¿Eliminar Producto?',
'confirm-btn' => 'Si, eliminar producto', 'cancel-btn' => 'No, no eliminar'} %>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment