Commit 2d187976 authored by Ciro Santilli's avatar Ciro Santilli

Run user select Js only where needed

Transform current implementation into regular Coffescript classes
so that the same call method can be reused on the dispatcher
as for other classes.
parent 367d4db4
...@@ -62,6 +62,7 @@ class Dispatcher ...@@ -62,6 +62,7 @@ class Dispatcher
new TeamMembers() new TeamMembers()
when 'groups:members' when 'groups:members'
new GroupMembers() new GroupMembers()
new UsersSelect()
when 'groups:new', 'groups:edit', 'admin:groups:edit' when 'groups:new', 'groups:edit', 'admin:groups:edit'
new GroupAvatar() new GroupAvatar()
when 'projects:tree:show' when 'projects:tree:show'
...@@ -81,6 +82,8 @@ class Dispatcher ...@@ -81,6 +82,8 @@ class Dispatcher
when 'admin' when 'admin'
new Admin() new Admin()
switch path[1] switch path[1]
when 'groups'
new UsersSelect()
when 'projects' when 'projects'
new NamespaceSelect() new NamespaceSelect()
when 'dashboard' when 'dashboard'
...@@ -95,6 +98,8 @@ class Dispatcher ...@@ -95,6 +98,8 @@ class Dispatcher
new ProjectNew() new ProjectNew()
when 'show' when 'show'
new ProjectShow() new ProjectShow()
when 'issues', 'merge_requests'
new ProjectUsersSelect()
when 'wikis' when 'wikis'
new Wikis() new Wikis()
shortcut_handler = new ShortcutsNavigation() shortcut_handler = new ShortcutsNavigation()
...@@ -103,6 +108,7 @@ class Dispatcher ...@@ -103,6 +108,7 @@ class Dispatcher
shortcut_handler = new ShortcutsNavigation() shortcut_handler = new ShortcutsNavigation()
when 'team_members', 'deploy_keys', 'hooks', 'services', 'protected_branches' when 'team_members', 'deploy_keys', 'hooks', 'services', 'protected_branches'
shortcut_handler = new ShortcutsNavigation() shortcut_handler = new ShortcutsNavigation()
new UsersSelect()
# If we haven't installed a custom shortcut handler, install the default one # If we haven't installed a custom shortcut handler, install the default one
......
@projectUsersSelect = class @ProjectUsersSelect
init: -> constructor: ->
$('.ajax-project-users-select').each (i, select) -> $('.ajax-project-users-select').each (i, select) =>
project_id = $(select).data('project-id') || $('body').data('project-id') project_id = $(select).data('project-id') || $('body').data('project-id')
$(select).select2 $(select).select2
...@@ -28,14 +28,16 @@ ...@@ -28,14 +28,16 @@
Api.user(id, callback) Api.user(id, callback)
formatResult: projectUsersSelect.projectUserFormatResult formatResult: (args...) =>
formatSelection: projectUsersSelect.projectUserFormatSelection @formatResult(args...)
formatSelection: (args...) =>
@formatSelection(args...)
dropdownCssClass: "ajax-project-users-dropdown" dropdownCssClass: "ajax-project-users-dropdown"
dropdownAutoWidth: true dropdownAutoWidth: true
escapeMarkup: (m) -> # we do not want to escape markup since we are displaying html in results escapeMarkup: (m) -> # we do not want to escape markup since we are displaying html in results
m m
projectUserFormatResult: (user) -> formatResult: (user) ->
if user.avatar_url if user.avatar_url
avatar = user.avatar_url avatar = user.avatar_url
else else
...@@ -52,8 +54,5 @@ ...@@ -52,8 +54,5 @@
<div class='user-username'>#{user.username}</div> <div class='user-username'>#{user.username}</div>
</div>" </div>"
projectUserFormatSelection: (user) -> formatSelection: (user) ->
user.name user.name
$ ->
projectUsersSelect.init()
$ -> class @UsersSelect
userFormatResult = (user) -> constructor: ->
if user.avatar_url $('.ajax-users-select').each (i, select) =>
avatar = user.avatar_url
else
avatar = gon.default_avatar_url
"<div class='user-result'>
<div class='user-image'><img class='avatar s24' src='#{avatar}'></div>
<div class='user-name'>#{user.name}</div>
<div class='user-username'>#{user.username}</div>
</div>"
userFormatSelection = (user) ->
user.name
$('.ajax-users-select').each (i, select) ->
$(select).select2 $(select).select2
placeholder: "Search for a user" placeholder: "Search for a user"
multiple: $(select).hasClass('multiselect') multiple: $(select).hasClass('multiselect')
...@@ -30,8 +16,25 @@ $ -> ...@@ -30,8 +16,25 @@ $ ->
Api.user(id, callback) Api.user(id, callback)
formatResult: userFormatResult formatResult: (args...) =>
formatSelection: userFormatSelection @formatResult(args...)
formatSelection: (args...) =>
@formatSelection(args...)
dropdownCssClass: "ajax-users-dropdown" dropdownCssClass: "ajax-users-dropdown"
escapeMarkup: (m) -> # we do not want to escape markup since we are displaying html in results escapeMarkup: (m) -> # we do not want to escape markup since we are displaying html in results
m m
formatResult: (user) ->
if user.avatar_url
avatar = user.avatar_url
else
avatar = gon.default_avatar_url
"<div class='user-result'>
<div class='user-image'><img class='avatar s24' src='#{avatar}'></div>
<div class='user-name'>#{user.name}</div>
<div class='user-username'>#{user.username}</div>
</div>"
formatSelection: (user) ->
user.name
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment