BigW Consortium Gitlab

issues.js.coffee 2.68 KB
Newer Older
1 2 3 4
@Issues =
  init: ->
    Issues.initSearch()
    Issues.initSelects()
5
    Issues.initChecks()
6 7 8 9 10 11 12 13 14 15 16 17

    $("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
18

19 20 21 22 23 24
  reload: ->
    Issues.initSelects()
    Issues.initChecks()
    $('#filter_issue_search').val($('#issue_search').val())

  initSelects: ->
25
    $("select#update_state_event").select2(width: 'resolve', dropdownAutoWidth: true)
Dmitriy Zaporozhets committed
26 27 28
    $("select#update_assignee_id").select2(width: 'resolve', dropdownAutoWidth: true)
    $("select#update_milestone_id").select2(width: 'resolve', dropdownAutoWidth: true)
    $("select#label_name").select2(width: 'resolve', dropdownAutoWidth: true)
29 30 31 32 33
    $("#milestone_id, #assignee_id, #label_name").on "change", ->
      $(this).closest("form").submit()

  initChecks: ->
    $(".check_all_issues").click ->
34
      $(".selected_issue").prop("checked", @checked)
35 36 37 38
      Issues.checkChanged()

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

39
  # Make sure we trigger ajax request only after user stop typing
40
  initSearch: ->
41
    @timer = null
42
    $("#issue_search").keyup ->
43
      clearTimeout(@timer)
44 45 46
      @timer = setTimeout( ->
        Issues.filterResults $("#issue_search_form")
      , 500)
47

48
  filterResults: (form) =>
49 50 51 52 53 54
    $('.issues-holder, .merge-requests-holder').css("opacity", '0.5')
    formAction = form.attr('action')
    formData = form.serialize()
    issuesUrl = formAction
    issuesUrl += ("#{if formAction.indexOf("?") < 0 then '?' else '&'}")
    issuesUrl += formData
55 56 57

    $.ajax
      type: "GET"
58 59
      url: formAction
      data: formData
60
      complete: ->
61
        $('.issues-holder, .merge-requests-holder').css("opacity", '1.0')
62
      success: (data) ->
63
        $('.issues-holder, .merge-requests-holder').html(data.html)
64
        # Change url so if user reload a page - search results are saved
65
        history.replaceState {page: issuesUrl}, document.title, issuesUrl
66 67
        Issues.reload()
      dataType: "json"
68 69 70 71 72 73 74 75 76

  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
77
      $(".issues-other-filters").hide()
78 79 80 81
      $(".issues_bulk_update").show()
    else
      $("#update_issues_ids").val []
      $(".issues_bulk_update").hide()
82
      $(".issues-other-filters").show()