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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
163908b3
Commit
163908b3
authored
Mar 13, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user select2 javascript
parent
1bba46d6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
app/assets/javascripts/users_select.js.coffee
app/assets/javascripts/users_select.js.coffee
+47
-0
No files found.
app/assets/javascripts/users_select.js.coffee
0 → 100644
View file @
163908b3
$
->
userFormatResult
=
(
user
)
->
avatar
=
gon
.
gravatar_url
avatar
=
avatar
.
replace
(
'%{hash}'
,
md5
(
user
.
email
))
avatar
=
avatar
.
replace
(
'%{size}'
,
'24'
)
markup
=
"<div class='user-result'>"
markup
+=
"<div class='user-image'><img class='avatar s24' src='"
+
avatar
+
"'></div>"
markup
+=
"<div class='user-name'>"
+
user
.
name
+
"</div>"
markup
+=
"<div class='user-username'>"
+
user
.
username
+
"</div>"
markup
+=
"</div>"
markup
$
(
'.ajax-users-select'
).
select2
placeholder
:
"Search for a user"
minimumInputLength
:
0
ajax
:
# instead of writing the function to execute the request we use Select2's convenient helper
url
:
"/api/v3/users.json"
dataType
:
"json"
data
:
(
term
,
page
)
->
search
:
term
# search term
per_page
:
10
private_token
:
gon
.
api_token
results
:
(
data
,
page
)
->
# parse the results into the format expected by Select2.
# since we are using custom formatting functions we do not need to alter remote JSON data
results
:
data
initSelection
:
(
element
,
callback
)
->
id
=
$
(
element
).
val
()
if
id
isnt
""
$
.
ajax
(
"http://api.rottentomatoes.com/api/public/v1.0/users/"
+
id
+
".json"
,
data
:
apikey
:
"ju6z9mjyajq2djue3gbvv26t"
dataType
:
"jsonp"
).
done
(
data
)
->
callback
data
formatResult
:
userFormatResult
# omitted for brevity, see the source of this page
#formatSelection: userFormatSelection # omitted for brevity, see the source of this page
dropdownCssClass
:
"ajax-users-dropdown"
# apply css that makes the dropdown taller
escapeMarkup
:
(
m
)
->
# we do not want to escape markup since we are displaying html in results
m
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