Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
b4593a1b
Commit
b4593a1b
authored
Mar 18, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix multiple ajax calls and plugin instantiation
parent
9008457a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
17 deletions
+38
-17
app/assets/javascripts/search_autocomplete.js.coffee
app/assets/javascripts/search_autocomplete.js.coffee
+38
-17
No files found.
app/assets/javascripts/search_autocomplete.js.coffee
View file @
b4593a1b
...
@@ -33,6 +33,7 @@ class @SearchAutocomplete
...
@@ -33,6 +33,7 @@ class @SearchAutocomplete
@
saveOriginalState
()
@
saveOriginalState
()
@
searchInput
.
addClass
(
'disabled'
)
@
searchInput
.
addClass
(
'disabled'
)
@
autocomplete
=
false
@
bindEvents
()
@
bindEvents
()
...
@@ -61,8 +62,12 @@ class @SearchAutocomplete
...
@@ -61,8 +62,12 @@ class @SearchAutocomplete
@
searchInput
.
on
'blur'
,
@
onSearchInputBlur
@
searchInput
.
on
'blur'
,
@
onSearchInputBlur
enableAutocomplete
:
->
enableAutocomplete
:
->
return
if
@
autocomplete
dropdownMenu
=
@
dropdown
.
find
(
'.dropdown-menu'
)
dropdownMenu
=
@
dropdown
.
find
(
'.dropdown-menu'
)
_this
=
@
_this
=
@
loading
=
false
@
searchInput
.
glDropdown
@
searchInput
.
glDropdown
filterInputBlur
:
false
filterInputBlur
:
false
filterable
:
true
filterable
:
true
...
@@ -72,7 +77,19 @@ class @SearchAutocomplete
...
@@ -72,7 +77,19 @@ class @SearchAutocomplete
search
:
search
:
fields
:
[
'text'
]
fields
:
[
'text'
]
data
:
(
term
,
callback
)
->
data
:
(
term
,
callback
)
->
$
.
get
(
_this
.
autocompletePath
,
{
# Ensure this is not called when autocomplete is disabled because
# this method still will be called because `GitLabDropdownFilter` is triggering this on keyup
return
if
_this
.
autocomplete
is
false
# Do not trigger request if input is empty
return
if
_this
.
searchInput
.
val
()
is
''
# Prevent multiple ajax calls
return
if
loading
loading
=
true
jqXHR
=
$
.
get
(
_this
.
autocompletePath
,
{
project_id
:
_this
.
projectId
project_id
:
_this
.
projectId
project_ref
:
_this
.
projectRef
project_ref
:
_this
.
projectRef
term
:
term
term
:
term
...
@@ -99,7 +116,8 @@ class @SearchAutocomplete
...
@@ -99,7 +116,8 @@ class @SearchAutocomplete
text
:
item
.
label
text
:
item
.
label
url
:
item
.
url
url
:
item
.
url
callback
(
data
)
callback
(
data
)
)
).
always
->
loading
=
false
@
dropdown
.
addClass
(
'open'
)
@
dropdown
.
addClass
(
'open'
)
@
searchInput
.
removeClass
(
'disabled'
)
@
searchInput
.
removeClass
(
'disabled'
)
...
@@ -109,23 +127,26 @@ class @SearchAutocomplete
...
@@ -109,23 +127,26 @@ class @SearchAutocomplete
@
dropdown
.
dropdown
(
'toggle'
)
@
dropdown
.
dropdown
(
'toggle'
)
onSearchInputKeyDown
:
(
e
)
=>
onSearchInputKeyDown
:
(
e
)
=>
# Remove tag when pressing backspace and input search is empty
switch
e
.
keyCode
if
e
.
keyCode
is
KEYCODE
.
BACKSPACE
and
e
.
currentTarget
.
value
is
''
when
KEYCODE
.
BACKSPACE
if
e
.
currentTarget
.
value
is
''
@
removeLocationBadge
()
@
removeLocationBadge
()
@
searchInput
.
focus
()
@
searchInput
.
focus
()
when
KEYCODE
.
ESCAPE
else
if
e
.
keyCode
is
KEYCODE
.
ESCAPE
if
@
badgePresent
()
@
searchInput
.
val
(
''
)
@
restoreOriginalState
()
else
else
# Create new autocomplete if it hasn't been created yet and there's no badge
@
restoreOriginalState
()
if
@
autocomplete
is
undefined
if
!
@
badgePresent
()
# If after restoring there's a badge
@
enableAutocomplete
()
@
disableAutocomplete
()
if
@
badgePresent
()
else
else
# There's a badge
if
@
badgePresent
()
if
@
badgePresent
()
@
disableAutocomplete
()
@
disableAutocomplete
()
else
@
enableAutocomplete
()
# Avoid falsy value to be returned
return
onSearchInputFocus
:
=>
onSearchInputFocus
:
=>
@
wrap
.
addClass
(
'search-active'
)
@
wrap
.
addClass
(
'search-active'
)
...
@@ -193,6 +214,6 @@ class @SearchAutocomplete
...
@@ -193,6 +214,6 @@ class @SearchAutocomplete
@
resetSearchState
()
@
resetSearchState
()
disableAutocomplete
:
->
disableAutocomplete
:
->
if
@
autocomplete
?
if
@
autocomplete
@
searchInput
.
addClass
(
'disabled'
)
@
searchInput
.
addClass
(
'disabled'
)
@
autocomplete
=
null
@
autocomplete
=
false
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment