Fix #tg-2147: set focus to the search input when assigned-to/watchers lightbox is opened

stable
David Barragán Merino 2015-02-02 12:57:32 +01:00 committed by Jesús Espino
parent 20b29f09a4
commit e992eabf35
1 changed files with 16 additions and 9 deletions

View File

@ -31,9 +31,11 @@ debounce = @.taiga.debounce
# the lightboxContent hide/show doesn't have sense because is an IE hack # the lightboxContent hide/show doesn't have sense because is an IE hack
class LightboxService extends taiga.Service class LightboxService extends taiga.Service
constructor: (@animationFrame) -> constructor: (@animationFrame, @q) ->
open: ($el) -> open: ($el) ->
defered = @q.defer()
lightboxContent = $el.children().not(".close") lightboxContent = $el.children().not(".close")
lightboxContent.hide() lightboxContent.hide()
@ -44,12 +46,15 @@ class LightboxService extends taiga.Service
@animationFrame.add => @animationFrame.add =>
$el.addClass("open") $el.addClass("open")
lightboxContent.show() lightboxContent.show()
defered.resolve()
docEl = angular.element(document) docEl = angular.element(document)
docEl.on "keydown.lightbox", (e) => docEl.on "keydown.lightbox", (e) =>
code = if e.keyCode then e.keyCode else e.which code = if e.keyCode then e.keyCode else e.which
@.close($el) if code == 27 @.close($el) if code == 27
return defered.promise
close: ($el) -> close: ($el) ->
docEl = angular.element(document) docEl = angular.element(document)
docEl.off(".lightbox") docEl.off(".lightbox")
@ -66,7 +71,7 @@ class LightboxService extends taiga.Service
@.close($(lightboxEl)) @.close($(lightboxEl))
module.service("lightboxService", ["animationFrame", LightboxService]) module.service("lightboxService", ["animationFrame", "$q", LightboxService])
class LightboxKeyboardNavigationService extends taiga.Service class LightboxKeyboardNavigationService extends taiga.Service
@ -442,8 +447,6 @@ AssignedToLightboxDirective = (lightboxService, lightboxKeyboardNavigationServic
return _.contains(username, text) return _.contains(username, text)
render = (selected, text) -> render = (selected, text) ->
$el.find("input").focus()
users = _.clone($scope.activeUsers, true) users = _.clone($scope.activeUsers, true)
users = _.reject(users, {"id": selected.id}) if selected? users = _.reject(users, {"id": selected.id}) if selected?
users = _.filter(users, _.partial(filterUsers, text)) if text? users = _.filter(users, _.partial(filterUsers, text)) if text?
@ -468,11 +471,14 @@ AssignedToLightboxDirective = (lightboxService, lightboxKeyboardNavigationServic
selectedUser = $scope.usersById[assignedToId] selectedUser = $scope.usersById[assignedToId]
render(selectedUser) render(selectedUser)
lightboxService.open($el) lightboxService.open($el).then ->
$el.find('input').focus() $el.find('input').focus()
$scope.$watch "usersSearch", (searchingText) -> $scope.$watch "usersSearch", (searchingText) ->
render(selectedUser, searchingText) if searchingText? if searchingText?
render(selectedUser, searchingText)
$el.find('input').focus()
$el.on "click", ".watcher-single", (event) -> $el.on "click", ".watcher-single", (event) ->
event.preventDefault() event.preventDefault()
@ -540,7 +546,6 @@ WatchersLightboxDirective = ($repo, lightboxService, lightboxKeyboardNavigationS
# Render the specific list of users. # Render the specific list of users.
render = (users) -> render = (users) ->
$el.find("input").focus()
ctx = { ctx = {
selected: false selected: false
users: _.first(users, 5) users: _.first(users, 5)
@ -560,7 +565,8 @@ WatchersLightboxDirective = ($repo, lightboxService, lightboxKeyboardNavigationS
users = getFilteredUsers() users = getFilteredUsers()
render(users) render(users)
lightboxService.open($el) lightboxService.open($el).then ->
$el.find("input").focus()
lightboxKeyboardNavigationService.init($el) lightboxKeyboardNavigationService.init($el)
$scope.$watch "usersSearch", (searchingText) -> $scope.$watch "usersSearch", (searchingText) ->
@ -569,6 +575,7 @@ WatchersLightboxDirective = ($repo, lightboxService, lightboxKeyboardNavigationS
users = getFilteredUsers(searchingText) users = getFilteredUsers(searchingText)
render(users) render(users)
$el.find("input").focus()
$el.on "click", ".watcher-single", debounce 2000, (event) -> $el.on "click", ".watcher-single", debounce 2000, (event) ->
closeLightbox() closeLightbox()