Welcome to mirror list, hosted at ThFree Co, Russian Federation.

search.js.coffee « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 661e1195f60e4407cb6425b864b5da393e13d83c (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
class @Search
  constructor: ->
    $groupDropdown = $('.js-search-group-dropdown')
    $projectDropdown = $('.js-search-project-dropdown')
    @eventListeners()

    $groupDropdown.glDropdown(
      selectable: true
      filterable: true
      fieldName: 'group_id'
      data: (term, callback) ->
        Api.groups term, null, (data) ->
          data.unshift(
            name: 'Any'
          )
          data.splice 1, 0, 'divider'

          callback(data)
      id: (obj) ->
        obj.id
      text: (obj) ->
        obj.name
      toggleLabel: (obj) ->
        "#{$groupDropdown.data('default-label')} #{obj.name}"
      clicked: =>
        @submitSearch()
    )

    $projectDropdown.glDropdown(
      selectable: true
      filterable: true
      fieldName: 'project_id'
      data: (term, callback) ->
        Api.projects term, 'id', (data) ->
          data.unshift(
            name_with_namespace: 'Any'
          )
          data.splice 1, 0, 'divider'

          callback(data)
      id: (obj) ->
        obj.id
      text: (obj) ->
        obj.name_with_namespace
      toggleLabel: (obj) ->
        "#{$projectDropdown.data('default-label')} #{obj.name_with_namespace}"
      clicked: =>
        @submitSearch()
    )

  eventListeners: ->
    $(document)
      .off 'keyup', '.js-search-input'
      .on 'keyup', '.js-search-input', @searchKeyUp

    $(document)
      .off 'click', '.js-search-clear'
      .on 'click', '.js-search-clear', @clearSearchField

  submitSearch: ->
    $('.js-search-form').submit()

  searchKeyUp: ->
    $input = $(@)

    if $input.val() is ''
      $('.js-search-clear').addClass 'hidden'
    else
      $('.js-search-clear').removeClass 'hidden'

  clearSearchField: ->
    $('.js-search-input')
      .val ''
      .trigger 'keyup'
      .focus()