wagn.slotReady (slot) ->
slot.find('[data-toggle=\'modal\']').off("click").on 'click', (e) ->
e.preventDefault()
e.stopPropagation()
$_this = $(this)
href = $_this.attr('href')
modal_selector = $_this.data('target')
$(modal_selector).modal 'show'
$.ajax
url: href
type: 'GET'
success: (html) ->
$(modal_selector + ' .modal-content').html html
$(modal_selector).trigger('loaded.bs.modal')
error: (jqXHR, textStatus) ->
$(modal_selector + ' .modal-content').html jqXHR.responseText
$(modal_selector).trigger('loaded.bs.modal')
return false
slot.find(".submit-button.submit-modal:first").off("click").click (event) ->
$_this = $(this)
$_this.attr('disabled','disabled');
$_this.html($_this.data("disable-with"))
$_this.closest(".modal").find("form:first").submit()
slot.find('.modal.fade').find("form:first").off("ajax:complete").on 'ajax:complete', (event, data, c, d) ->
$submit_botton = $(this).closest(".modal.fade").find(".submit-button.submit-modal:first")
$submit_botton.removeAttr('disabled');
$submit_botton.html("Add")
slot.find('.modal.fade').find("form:first").off("ajax:success").on 'ajax:success', (event, data, c, d) ->
$_this = $(this)
if $_this.attr('action').indexOf("+add_value") > -1
#hide the modal again
$_this.closest(".modal.fade").modal('toggle')
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();