Code improvements

This commit is contained in:
Alfredo Sumaran 2016-03-18 17:35:26 -05:00
parent 79a4292ffd
commit 3898bffd62
2 changed files with 31 additions and 41 deletions

View file

@ -20,7 +20,7 @@ class GitLabDropdownFilter
blur_field = @shouldBlur e.keyCode
search_text = @input.val()
if blur_field && @filterInputBlur
if blur_field and @filterInputBlur
@input.blur()
if @options.remote
@ -88,7 +88,7 @@ class GitLabDropdown
# Set Defaults
{
# If no input is passed create a default one
@filterInput = @$(FILTER_INPUT)
@filterInput = @getElement(FILTER_INPUT)
@highlight = false
@filterInputBlur = true
} = @options
@ -97,8 +97,7 @@ class GitLabDropdown
# If selector was passed
if _.isString(@filterInput)
@filterInput = @$(@filterInput)
@filterInput = @getElement(@filterInput)
search_fields = if @options.search then @options.search.fields else [];
@ -156,8 +155,9 @@ class GitLabDropdown
if self.options.clicked
self.options.clicked()
$: (selector) ->
$(selector, @dropdown)
# Finds an element inside wrapper element
getElement: (selector) ->
@dropdown.find selector
toggleLoading: ->
$('.dropdown-menu', @dropdown).toggleClass LOADING_CLASS
@ -268,12 +268,9 @@ class GitLabDropdown
highlightTextMatches: (text, term) ->
occurrences = fuzzaldrinPlus.match(text, term)
textArr = text.split('')
textArr.forEach (character, i, textArr) ->
if i in occurrences
textArr[i] = "<b>#{character}</b>"
textArr.join ''
text.split('').map((character, i) ->
if i in occurrences then "<b>#{character}</b>" else character
).join('')
noResults: ->
html = "<li>"

View file

@ -20,15 +20,15 @@ class @SearchAutocomplete
# Dropdown Element
@dropdown = @wrap.find('.dropdown')
@locationBadgeEl = @$('.search-location-badge')
@locationText = @$('.location-text')
@scopeInputEl = @$('#scope')
@searchInput = @$('.search-input')
@projectInputEl = @$('#search_project_id')
@groupInputEl = @$('#group_id')
@searchCodeInputEl = @$('#search_code')
@repositoryInputEl = @$('#repository_ref')
@scopeInputEl = @$('#scope')
@locationBadgeEl = @getElement('.search-location-badge')
@locationText = @getElement('.location-text')
@scopeInputEl = @getElement('#scope')
@searchInput = @getElement('.search-input')
@projectInputEl = @getElement('#search_project_id')
@groupInputEl = @getElement('#group_id')
@searchCodeInputEl = @getElement('#search_code')
@repositoryInputEl = @getElement('#repository_ref')
@scopeInputEl = @getElement('#scope')
@saveOriginalState()
@ -36,7 +36,8 @@ class @SearchAutocomplete
@bindEvents()
$: (selector) ->
# Finds an element inside wrapper element
getElement: (selector) ->
@wrap.find(selector)
saveOriginalState: ->
@ -60,11 +61,9 @@ class @SearchAutocomplete
@searchInput.on 'blur', @onSearchInputBlur
enableAutocomplete: ->
self = @
@query = "?project_id=" + @projectId + "&project_ref=" + @projectRef
dropdownMenu = self.dropdown.find('.dropdown-menu')
@searchInput.glDropdown(
dropdownMenu = @dropdown.find('.dropdown-menu')
_this = @
@searchInput.glDropdown
filterInputBlur: false
filterable: true
filterRemote: true
@ -73,13 +72,11 @@ class @SearchAutocomplete
search:
fields: ['text']
data: (term, callback) ->
$.ajax
url: self.autocompletePath + self.query
data:
$.get(_this.autocompletePath, {
project_id: _this.projectId
project_ref: _this.projectRef
term: term
beforeSend: ->
# dropdownMenu.addClass 'is-loading'
success: (response) ->
}, (response) ->
data = []
# Save groups ordering according to server response
@ -101,16 +98,12 @@ class @SearchAutocomplete
data.push
text: item.label
url: item.url
callback(data)
complete: ->
# dropdownMenu.removeClass 'is-loading'
)
@dropdown.addClass('open')
@searchInput.removeClass('disabled')
@autocomplete = true;
@autocomplete = true
onDropdownOpen: (e) =>
@dropdown.dropdown('toggle')
@ -158,7 +151,7 @@ class @SearchAutocomplete
inputs = Object.keys @originalState
for input in inputs
@$("##{input}").val(@originalState[input])
@getElement("##{input}").val(@originalState[input])
if @originalState._location is ''
@ -200,6 +193,6 @@ class @SearchAutocomplete
@resetSearchState()
disableAutocomplete: ->
if @autocomplete isnt undefined
if @autocomplete?
@searchInput.addClass('disabled')
@autocomplete = undefined
@autocomplete = null