Sha256: 6fe775cc0762402b8e397a8248b91dc4d61aee4c5e7bc7d87a7a45c570c66596

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

# Fake file input (bootstrap style)
window.setupUploadInputs = (scope = document) ->
  $(scope).find(".form-control.upload").map ->
    container = $(this)
    form      = container.parents("form")
    input     = container.find("[type=file]")
    label     = container.find("label")
    submit    = form.find("[type=submit]")
    progress  = form.find(".progress")

    progress.hide() if not xhr2_available()

    label.map ->
      this.dataset.defaultValue = $(this).html()

    input.change ->
      if this.value == ""
        submit.prop(disabled: true) if input.hasClass("required")
        label_value = label.data("defaultValue")
      else
        submit.prop(disabled: false)
        label_value = this.value.split("/").pop().split("\\").pop()

      label.html(label_value)
    input.change()

$(document).on "turbolinks:load", ->
  $("button.reset").click ->
    form = $(this).parents("form")
    form.find("input, textarea, select").map ->
      return if String(this.type).match(/submit|hidden|button/)
      $(this).val String($(this).data("default-value") || "")

  # Referer with anchor
  $("form").submit ->
    return if this.method.toUpperCase() == "GET"
    return if $(this).find("[name=form_url]").length > 0

    input       = document.createElement("input")
    input.type  = "hidden"
    input.name  = "form_url"
    input.value = location.href
    $(this).append(input)

  $("select").map ->
    select = $(this)
    form   = select.parents("form")

    return if select.find("[value=custom_date]").length == 0

    select.change ->
      if select.val() == "custom_date"
        form.find(".form-group[class*=date_begin], .form-group[class*=date_end]").show()
      else
        form.find("input[id*=date_begin], input[id*=date_end]").val("")
        form.find(".form-group[class*=date_begin], .form-group[class*=date_end]").hide()

    select.change()

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dorsale-3.4.0 app/assets/javascripts/dorsale/common/forms.coffee
dorsale-3.3.0 app/assets/javascripts/dorsale/common/forms.coffee