Sha256: 841549a2a26b47f516ee7ca16db5cd91c85d7271efffa3ee1d60a0c9714f54f5

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

$.fn.handleDispatchForm = () ->
  $(this).each ->
    form = $(this)
    mailer_select = form.find("#item_mailer_name")
    list_select = form.find("#item_list")
    template_generic = form.find(".template-generic")
    template_mailer = form.find(".template-mailer")
    template_mailer = form.find(".template-mailer")
    mailing_from = form.find(".mailing-from")
    dispatch_start_at = form.find(".dispatch-start-at")

    update_form = () ->
      $.ajax(
        method: "post",
        url: form.data("update-form-path"),
        data: form.find("input[name^=item], textarea[name^=item], select[name^=item]").serialize(),
        dataType: "script"
      )

    update_from = () ->
      from_value = mailing_from.find("input[type=radio]:checked").val()
      from_field = mailing_from.find("input[type=text]")

      if from_value == "default"
        from_field.hide()
      else if from_value == "specify"
        from_field.show()

    update_start_at = () ->
      dispatch_start_at.find('[data-toggle="tooltip"]').tooltip()
      dispatch_start_at.find('button:first-child').focus ->
        dispatch_start_at.find("input.form-control").focus()
        true
      dispatch_start_at.find("input.form-control").datepicker(
        forceParse: false,
        format: "yyyy-mm-dd"
      )

    mailer_select.change ->
      update_form()

    list_select.change ->
      update_form()

    if mailer_select.val() == "generic"
      template_mailer.hide()
    else
      template_generic.hide()

    mailing_from.on "change", "input[type=radio]", ->
      update_from()

    update_from()
    update_start_at()

$ ->
  $(".dispatch-form").handleDispatchForm()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maily_herald-webui-0.8.0 app/assets/javascripts/maily_herald/webui/dispatches.coffee