watcher & assigned to works with keyboard arrows
parent
e27fc72197
commit
d030c277a3
|
@ -67,6 +67,45 @@ LightboxDirective = (lightboxService) ->
|
||||||
|
|
||||||
module.directive("lightbox", ["lightboxService", LightboxDirective])
|
module.directive("lightbox", ["lightboxService", LightboxDirective])
|
||||||
|
|
||||||
|
class LightboxListNavigationService
|
||||||
|
stop: () ->
|
||||||
|
$(document).off "keydown.list-navigation"
|
||||||
|
|
||||||
|
init: ($el) ->
|
||||||
|
$(document).on "keydown.list-navigation", (e) =>
|
||||||
|
code = if e.keyCode then e.keyCode else e.which
|
||||||
|
|
||||||
|
if code == 40 || code == 38 || code == 13
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
active = $el.find('.active')
|
||||||
|
|
||||||
|
if code == 13
|
||||||
|
active.trigger('click')
|
||||||
|
|
||||||
|
if code == 40
|
||||||
|
if active.length
|
||||||
|
next = active.next('.watcher-single')
|
||||||
|
|
||||||
|
if next.length
|
||||||
|
active.removeClass('active')
|
||||||
|
next.addClass('active')
|
||||||
|
else
|
||||||
|
$el.find('.watcher-single:first').addClass('active')
|
||||||
|
|
||||||
|
if code == 38
|
||||||
|
if active.length
|
||||||
|
prev = active.prev('.watcher-single')
|
||||||
|
|
||||||
|
if prev.length
|
||||||
|
active.removeClass('active')
|
||||||
|
prev.addClass('active')
|
||||||
|
else
|
||||||
|
$el.find('.watcher-single:last').addClass('active')
|
||||||
|
|
||||||
|
module.service("lightboxListNavigationService", LightboxListNavigationService)
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
## Block Lightbox Directive
|
## Block Lightbox Directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
@ -299,7 +338,7 @@ usersTemplate = _.template("""
|
||||||
<% } %>
|
<% } %>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
AssignedToLightboxDirective = (lightboxService) ->
|
AssignedToLightboxDirective = (lightboxService, lightboxListNavigationService) ->
|
||||||
link = ($scope, $el, $attrs) ->
|
link = ($scope, $el, $attrs) ->
|
||||||
selectedUser = null
|
selectedUser = null
|
||||||
selectedItem = null
|
selectedItem = null
|
||||||
|
@ -324,6 +363,11 @@ AssignedToLightboxDirective = (lightboxService) ->
|
||||||
|
|
||||||
html = usersTemplate(ctx)
|
html = usersTemplate(ctx)
|
||||||
$el.find("div.watchers").html(html)
|
$el.find("div.watchers").html(html)
|
||||||
|
lightboxListNavigationService.init($el)
|
||||||
|
|
||||||
|
closeLightbox = () ->
|
||||||
|
lightboxListNavigationService.stop()
|
||||||
|
lightboxService.close($el)
|
||||||
|
|
||||||
$scope.$on "assigned-to:add", (ctx, item) ->
|
$scope.$on "assigned-to:add", (ctx, item) ->
|
||||||
selectedItem = item
|
selectedItem = item
|
||||||
|
@ -340,7 +384,7 @@ AssignedToLightboxDirective = (lightboxService) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
target = angular.element(event.currentTarget)
|
target = angular.element(event.currentTarget)
|
||||||
|
|
||||||
lightboxService.close($el)
|
closeLightbox()
|
||||||
|
|
||||||
$scope.$apply ->
|
$scope.$apply ->
|
||||||
$scope.$broadcast("assigned-to:added", target.data("user-id"), selectedItem)
|
$scope.$broadcast("assigned-to:added", target.data("user-id"), selectedItem)
|
||||||
|
@ -350,7 +394,7 @@ AssignedToLightboxDirective = (lightboxService) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
|
||||||
lightboxService.close($el)
|
closeLightbox()
|
||||||
|
|
||||||
$scope.$apply ->
|
$scope.$apply ->
|
||||||
$scope.usersSearch = null
|
$scope.usersSearch = null
|
||||||
|
@ -358,7 +402,9 @@ AssignedToLightboxDirective = (lightboxService) ->
|
||||||
|
|
||||||
$el.on "click", ".close", (event) ->
|
$el.on "click", ".close", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
lightboxService.close($el)
|
|
||||||
|
closeLightbox()
|
||||||
|
|
||||||
$scope.$apply ->
|
$scope.$apply ->
|
||||||
$scope.usersSearch = null
|
$scope.usersSearch = null
|
||||||
|
|
||||||
|
@ -371,14 +417,14 @@ AssignedToLightboxDirective = (lightboxService) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.directive("tgLbAssignedto", ["lightboxService", AssignedToLightboxDirective])
|
module.directive("tgLbAssignedto", ["lightboxService", "lightboxListNavigationService", AssignedToLightboxDirective])
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
## Watchers Lightbox directive
|
## Watchers Lightbox directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
WatchersLightboxDirective = ($repo, lightboxService) ->
|
WatchersLightboxDirective = ($repo, lightboxService, lightboxListNavigationService) ->
|
||||||
link = ($scope, $el, $attrs) ->
|
link = ($scope, $el, $attrs) ->
|
||||||
selectedItem = null
|
selectedItem = null
|
||||||
|
|
||||||
|
@ -409,6 +455,10 @@ WatchersLightboxDirective = ($repo, lightboxService) ->
|
||||||
html = usersTemplate(ctx)
|
html = usersTemplate(ctx)
|
||||||
$el.find("div.watchers").html(html)
|
$el.find("div.watchers").html(html)
|
||||||
|
|
||||||
|
closeLightbox = () ->
|
||||||
|
lightboxListNavigationService.stop()
|
||||||
|
lightboxService.close($el)
|
||||||
|
|
||||||
$scope.$on "watcher:add", (ctx, item) ->
|
$scope.$on "watcher:add", (ctx, item) ->
|
||||||
selectedItem = item
|
selectedItem = item
|
||||||
|
|
||||||
|
@ -416,6 +466,7 @@ WatchersLightboxDirective = ($repo, lightboxService) ->
|
||||||
render(users)
|
render(users)
|
||||||
|
|
||||||
lightboxService.open($el)
|
lightboxService.open($el)
|
||||||
|
lightboxListNavigationService.init($el)
|
||||||
|
|
||||||
$scope.$watch "usersSearch", (searchingText) ->
|
$scope.$watch "usersSearch", (searchingText) ->
|
||||||
if not searchingText?
|
if not searchingText?
|
||||||
|
@ -425,7 +476,7 @@ WatchersLightboxDirective = ($repo, lightboxService) ->
|
||||||
render(users)
|
render(users)
|
||||||
|
|
||||||
$el.on "click", ".watcher-single", (event) ->
|
$el.on "click", ".watcher-single", (event) ->
|
||||||
lightboxService.close($el)
|
closeLightbox()
|
||||||
|
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
target = angular.element(event.currentTarget)
|
target = angular.element(event.currentTarget)
|
||||||
|
@ -436,7 +487,9 @@ WatchersLightboxDirective = ($repo, lightboxService) ->
|
||||||
|
|
||||||
$el.on "click", ".close", (event) ->
|
$el.on "click", ".close", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
lightboxService.close($el)
|
|
||||||
|
closeLightbox()
|
||||||
|
|
||||||
$scope.$apply ->
|
$scope.$apply ->
|
||||||
$scope.usersSearch = null
|
$scope.usersSearch = null
|
||||||
|
|
||||||
|
@ -448,4 +501,4 @@ WatchersLightboxDirective = ($repo, lightboxService) ->
|
||||||
link:link
|
link:link
|
||||||
}
|
}
|
||||||
|
|
||||||
module.directive("tgLbWatchers", ["$tgRepo", "lightboxService", WatchersLightboxDirective])
|
module.directive("tgLbWatchers", ["$tgRepo", "lightboxService", "lightboxListNavigationService", WatchersLightboxDirective])
|
||||||
|
|
Loading…
Reference in New Issue