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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
dcea1913
Commit
dcea1913
authored
Nov 15, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Select2 tag for namespaces with ajax loading
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
0759dd45
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
0 deletions
+48
-0
app/assets/javascripts/api.js.coffee
app/assets/javascripts/api.js.coffee
+15
-0
app/assets/javascripts/namespace_select.js.coffee
app/assets/javascripts/namespace_select.js.coffee
+24
-0
app/helpers/namespaces_helper.rb
app/helpers/namespaces_helper.rb
+9
-0
No files found.
app/assets/javascripts/api.js.coffee
View file @
dcea1913
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
users_path
:
"/api/:version/users.json"
users_path
:
"/api/:version/users.json"
user_path
:
"/api/:version/users/:id.json"
user_path
:
"/api/:version/users/:id.json"
notes_path
:
"/api/:version/projects/:id/notes.json"
notes_path
:
"/api/:version/projects/:id/notes.json"
namespaces_path
:
"/api/:version/namespaces.json"
# Get 20 (depends on api) recent notes
# Get 20 (depends on api) recent notes
# and sort the ascending from oldest to newest
# and sort the ascending from oldest to newest
...
@@ -49,6 +50,20 @@
...
@@ -49,6 +50,20 @@
).
done
(
users
)
->
).
done
(
users
)
->
callback
(
users
)
callback
(
users
)
# Return namespaces list. Filtered by query
namespaces
:
(
query
,
callback
)
->
url
=
Api
.
buildUrl
(
Api
.
namespaces_path
)
$
.
ajax
(
url
:
url
data
:
private_token
:
gon
.
api_token
search
:
query
per_page
:
20
dataType
:
"json"
).
done
(
namespaces
)
->
callback
(
namespaces
)
buildUrl
:
(
url
)
->
buildUrl
:
(
url
)
->
url
=
gon
.
relative_url_root
+
url
if
gon
.
relative_url_root
?
url
=
gon
.
relative_url_root
+
url
if
gon
.
relative_url_root
?
return
url
.
replace
(
':version'
,
gon
.
api_version
)
return
url
.
replace
(
':version'
,
gon
.
api_version
)
app/assets/javascripts/namespace_select.js.coffee
0 → 100644
View file @
dcea1913
$
->
namespaceFormatResult
=
(
namespace
)
->
markup
=
"<div class='namespace-result'>"
markup
+=
"<span class='namespace-kind'>"
+
namespace
.
kind
+
"</span>"
markup
+=
"<span class='namespace-path'>"
+
namespace
.
path
+
"</span>"
markup
+=
"</div>"
markup
formatSelection
=
(
namespace
)
->
namespace
.
kind
+
": "
+
namespace
.
path
$
(
'.ajax-namespace-select'
).
each
(
i
,
select
)
->
$
(
select
).
select2
placeholder
:
"Search for namespace"
multiple
:
$
(
select
).
hasClass
(
'multiselect'
)
minimumInputLength
:
0
query
:
(
query
)
->
Api
.
namespaces
query
.
term
,
(
namespaces
)
->
data
=
{
results
:
namespaces
}
query
.
callback
(
data
)
dropdownCssClass
:
"ajax-namespace-dropdown"
formatResult
:
namespaceFormatResult
formatSelection
:
formatSelection
app/helpers/namespaces_helper.rb
View file @
dcea1913
...
@@ -16,4 +16,13 @@ module NamespacesHelper
...
@@ -16,4 +16,13 @@ module NamespacesHelper
grouped_options_for_select
(
options
,
selected
)
grouped_options_for_select
(
options
,
selected
)
end
end
def
namespace_select_tag
(
id
,
opts
=
{})
css_class
=
"ajax-namespace-select "
css_class
<<
"multiselect "
if
opts
[
:multiple
]
css_class
<<
(
opts
[
:class
]
||
''
)
value
=
opts
[
:selected
]
||
''
hidden_field_tag
(
id
,
value
,
class:
css_class
)
end
end
end
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