#= require ./behavior

class window.AjaxModal extends window.Behavior
  init: ->
    @url = @data('ajax-modal-url')
    @form = @data('ajax-modal-form-serialize')

    @$dom.click =>
      @showModal()
      false

  requestData: ->
    if @form? then $(@form).serialize() else null

  modalTarget: ->
    @domData('ajax-modal-target')

  showOverlay: ->
    #$("body").modalmanager "loading"

  showModal: ->
    @showOverlay()
    $target = @modalTarget()
    $target.load @url, @requestData(), ->
      $target.modal()
