blob: 681c8f9e67615222068eabb1d8601d18fbecd78b (
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
55
56
57
 | @selectTable = ->
  $('.select_table').each ->
    selection = []
    toolbox = $(this).children('.select_toolbox')
    $(this).on 'click', "[type='checkbox']", (e)->
      if e.currentTarget.id == '0'
        selection = []
        if e.currentTarget.checked
          $(this).closest('.table').find("[type='checkbox']").each ->
            $(this).prop('checked', true)
            # Add each element to selection
            selection.push($(this).attr('id'))
          # Remove th checkbox from selection
          selection.splice(0, 1)
        else
          $(this).closest('.table').find("[type='checkbox']").each ->
            $(this).prop('checked', false)
          # Empty selection
          selection = []
      else
        if e.currentTarget.checked
          selection.push(e.currentTarget.id)
        else
          elm = selection.indexOf(e.currentTarget.id)
          selection.splice(elm, 1)
      # console.log(selection)
      # Updating toolbox, according to selection
      if selection.length > 0
        toolbox
          .removeClass 'noselect'
          .children('.info-msg').children('span').text(selection.length)
        # Injecting selection into action urls
        toolbox.find('.st_action').each ->
          actionURL = $(this).children('a').attr('data-path')
          newSelection = []
          i = 0
          while i < selection.length
            newSelection[i] = 'referentials[]=' + selection[i] + ''
            i++
          $(this).children('a').attr('href', actionURL + '?' + newSelection.join('&'))
      else
        toolbox
          .addClass 'noselect'
          .children('.info-msg').children('span').text(selection.length)
$ ->
  selectTable()
 |