summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/profile.js.coffee
blob: bb0b66b86e1a91587f157ca9d9d0ef8f4d4cdac1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class @Profile
  constructor: ->
    # Automatically submit the Preferences form when any of its radio buttons change
    $('.js-preferences-form').on 'change.preference', 'input[type=radio]', ->
      $(this).parents('form').submit()

    $('.update-username form').on 'ajax:before', ->
      $('.loading-gif').show()
      $(this).find('.update-success').hide()
      $(this).find('.update-failed').hide()

    $('.update-username form').on 'ajax:complete', ->
      $(this).find('.btn-save').enable()
      $(this).find('.loading-gif').hide()

    $('.update-notifications').on 'ajax:complete', ->
      $(this).find('.btn-save').enable()

    $('.js-choose-user-avatar-button').bind "click", ->
      form = $(this).closest("form")
      form.find(".js-user-avatar-input").click()

    $('.js-user-avatar-input').bind "change", ->
      form = $(this).closest("form")
      filename = $(this).val().replace(/^.*[\\\/]/, '')
      form.find(".js-avatar-filename").text(filename)