aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts/forms.coffee
blob: 12d82fef1be7ca55fd45e3417f6133170a3234c6 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# IE fix
isIE = false || !!document.documentMode
isEdge = !isIE && !!window.StyleMedia

@togglableFilter = ->
  $('.form-filter').on 'click', '.form-group.togglable', (e)->
    if $(e.target).hasClass('togglable') || $(e.target).parent().hasClass('togglable')
      $(this).siblings().removeClass 'open'
      $(this).toggleClass 'open'

@switchInput = ->
  $('.form-group.has_switch').each ->
    labelCont = $(this).find('.switch-label')

    if labelCont.text() == ''
      labelCont.text(labelCont.data('uncheckedvalue'))

    $(this).on 'click', "input[type='checkbox']", ->
      if labelCont.text() == labelCont.data('checkedvalue')
        labelCont.text(labelCont.data('uncheckedvalue'))
      else
        labelCont.text(labelCont.data('checkedvalue'))

@submitMover = ->
  if $('.page-action').children('.formSubmitr').length > 0
    $('.page-action').children('.formSubmitr').remove()

  $('.formSubmitr').appendTo('.page-action')

  if isIE || isEdge
    $('.formSubmitr').off()

@colorSelector = ->
  $('.form-group .dropdown.color_selector').each ->
    selectedStatus = $(this).children('.dropdown-toggle').children('.fa-circle')

    $(this).on 'click', "input[type='radio']", (e) ->
      selectedValue = e.currentTarget.value
      if selectedValue == ''
        $(selectedStatus).css('color', 'transparent')
      else
        $(selectedStatus).css('color', selectedValue)

$ ->
  togglableFilter()
  submitMover()
  switchInput()
  colorSelector()

if isIE || isEdge
  $(document).on 'click', '.formSubmitr', (e)->
    e.preventDefault()
    target = $(this).attr('form')
    $('#' + target).submit()