2016-04-15 10:55:31 -04:00
|
|
|
class @Search
|
2016-04-15 09:13:21 -04:00
|
|
|
constructor: ->
|
2016-04-15 11:06:21 -04:00
|
|
|
$groupDropdown = $('.js-search-group-dropdown')
|
|
|
|
$projectDropdown = $('.js-search-project-dropdown')
|
2016-04-15 10:55:31 -04:00
|
|
|
@eventListeners()
|
|
|
|
|
2016-04-15 11:06:21 -04:00
|
|
|
$groupDropdown.glDropdown(
|
2016-04-15 09:13:21 -04:00
|
|
|
selectable: true
|
|
|
|
filterable: true
|
2016-04-15 10:12:04 -04:00
|
|
|
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
|
2016-04-15 11:06:21 -04:00
|
|
|
toggleLabel: (obj) ->
|
|
|
|
"#{$groupDropdown.data('default-label')} #{obj.name}"
|
2016-04-15 10:12:04 -04:00
|
|
|
clicked: =>
|
|
|
|
@submitSearch()
|
2016-04-15 09:13:21 -04:00
|
|
|
)
|
2016-04-15 10:12:04 -04:00
|
|
|
|
2016-04-15 11:06:21 -04:00
|
|
|
$projectDropdown.glDropdown(
|
2016-04-15 10:12:04 -04:00
|
|
|
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
|
2016-04-15 11:06:21 -04:00
|
|
|
toggleLabel: (obj) ->
|
|
|
|
"#{$projectDropdown.data('default-label')} #{obj.name_with_namespace}"
|
2016-04-15 10:12:04 -04:00
|
|
|
clicked: =>
|
|
|
|
@submitSearch()
|
|
|
|
)
|
|
|
|
|
2016-04-15 10:55:31 -04:00
|
|
|
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
|
|
|
|
|
2016-04-15 10:12:04 -04:00
|
|
|
submitSearch: ->
|
|
|
|
$('.js-search-form').submit()
|
2016-04-15 10:55:31 -04:00
|
|
|
|
|
|
|
searchKeyUp: ->
|
|
|
|
$input = $(@)
|
|
|
|
|
|
|
|
if $input.val() is ''
|
|
|
|
$('.js-search-clear').addClass 'hidden'
|
|
|
|
else
|
|
|
|
$('.js-search-clear').removeClass 'hidden'
|
|
|
|
|
|
|
|
clearSearchField: ->
|
|
|
|
$('.js-search-input')
|
|
|
|
.val ''
|
|
|
|
.trigger 'keyup'
|
2016-04-15 11:29:35 -04:00
|
|
|
.focus()
|