Sha256: c59f57b90f9cb8eb1d43bd64a70150020b3b5b81272a7523b27b5006c5d9511b

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

class @SpinningForm

  constructor: (element) ->
    @element = $(element)
    @submitBtn = @element.find("[type='submit']")
    @setBindings()

  setBindings: () =>
    @element.on('ajax:beforeSend', (event, xhr, settings) =>
      @disableBtn()
      @submitBtn.html("<i class='fa fa-spinner fa-spin'>&nbsp;</i> Saving...")
    )
    @element.on('ajax:success', (event, xhr, status) =>
      @submitBtn
        .addClass('btn-info')
        .html("<i class='fa fa-check'>&nbsp;</i> Saved")
    )
    @element.on('ajax:error', (event, xhr, status) =>
      @submitBtn
        .addClass('btn-danger')
        .html("<i class='fa fa-exclamation-triangle'>&nbsp;</i> Oups!")
    )
    @element.on('ajax:complete', (event, xhr, status) =>
      setTimeout(
        () =>
          @clearBtnClasses()
          @enableBtn()
          @submitBtn.html("<i class='fa fa-check'>&nbsp;</i> Save")
        , 2000
      )
    )

  disableBtn: () =>
    @submitBtn.prop('disabled', true)

  enableBtn: () =>
    @submitBtn.prop('disabled', false)

  clearBtnClasses: () =>
    @submitBtn
      .removeClass('btn-info')
      .removeClass('btn-danger')


$.fn.spinningForm = () ->
  @each ->
    new SpinningForm($(this))

jQuery ->
  $("form[data-remote='true']").each () ->
    $(this).spinningForm()

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
georgia-0.8.0 app/assets/javascripts/georgia/components/forms/spinning.js.coffee
georgia-0.7.8 app/assets/javascripts/georgia/components/forms/spinning.js.coffee
georgia-0.7.7 app/assets/javascripts/georgia/components/forms/spinning.js.coffee
georgia-0.7.6 app/assets/javascripts/georgia/components/forms/spinning.js.coffee
georgia-0.7.5 app/assets/javascripts/georgia/components/forms/spinning.js.coffee
georgia-0.7.4 app/assets/javascripts/georgia/components/forms/spinning.js.coffee
georgia-0.7.3 app/assets/javascripts/georgia/components/forms/spinning.js.coffee
georgia-0.7.2 app/assets/javascripts/georgia/components/forms/spinning.js.coffee
georgia-0.7.1 app/assets/javascripts/georgia/components/forms/spinning.js.coffee
georgia-0.7.0 app/assets/javascripts/georgia/components/forms/spinning.js.coffee