summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issues.js.coffee
blob: c273ddbd39147b0ab9aaf916d91fce01428b9303 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@Issues =
  init: ->
    Issues.initSearch()
    Issues.initSelects()
    Issues.initChecks()

    $("body").on "ajax:success", ".close_issue, .reopen_issue", ->
      t = $(this)
      totalIssues = undefined
      reopen = t.hasClass("reopen_issue")
      $(".issue_counter").each ->
        issue = $(this)
        totalIssues = parseInt($(this).html(), 10)
        if reopen and issue.closest(".main_menu").length
          $(this).html totalIssues + 1
        else
          $(this).html totalIssues - 1
    $("body").on "click", ".issues-filters .dropdown-menu a", ->
      $('.issues-list').block(
        message: null,
        overlayCSS:
          backgroundColor: '#DDD'
          opacity: .4
      )

  reload: ->
    Issues.initSelects()
    Issues.initChecks()
    $('#filter_issue_search').val($('#issue_search').val())

  initSelects: ->
    $("#update_status").chosen()
    $("#update_assignee_id").chosen()
    $("#update_milestone_id").chosen()
    $("#label_name").chosen()
    $("#assignee_id").chosen()
    $("#milestone_id").chosen()
    $("#milestone_id, #assignee_id, #label_name").on "change", ->
      $(this).closest("form").submit()

  initChecks: ->
    $(".check_all_issues").click ->
      $(".selected_issue").attr "checked", @checked
      Issues.checkChanged()

    $(".selected_issue").bind "change", Issues.checkChanged


  initSearch: ->
    form = $("#issue_search_form")
    last_terms = ""
    $("#issue_search").keyup ->
      terms = $(this).val()
      unless terms is last_terms
        last_terms = terms
        if terms.length >= 2 or terms.length is 0
          $.ajax
            type: "GET"
            url: location.href
            data: "issue_search=" + terms
            complete: ->
              $(".loading").hide()
            success: (data) ->
              $('.issues-holder').html(data.html)
              Issues.reload()
            dataType: "json"

  checkChanged: ->
    checked_issues = $(".selected_issue:checked")
    if checked_issues.length > 0
      ids = []
      $.each checked_issues, (index, value) ->
        ids.push $(value).attr("data-id")

      $("#update_issues_ids").val ids
      $(".issues-filters").hide()
      $(".issues_bulk_update").show()
    else
      $("#update_issues_ids").val []
      $(".issues_bulk_update").hide()
      $(".issues-filters").show()