Avoid conflicts between lightboxes on keypress ESC

stable
Daniel García 2018-08-13 13:28:58 +02:00 committed by Alex Hermida
parent 2fe857a970
commit 362ff5f37d
1 changed files with 28 additions and 20 deletions

View File

@ -39,7 +39,7 @@ normalizeString = @.taiga.normalizeString
class LightboxService extends taiga.Service
constructor: (@animationFrame, @q, @rootScope) ->
open: ($el, onClose, onEsc) ->
open: ($el, onClose, onEsc, ignoreEsc) ->
@.onClose = onClose
if _.isString($el)
@ -66,6 +66,7 @@ class LightboxService extends taiga.Service
lightboxContent.show()
defered.resolve()
if !ignoreEsc
docEl = angular.element(document)
docEl.on "keydown.lightbox", (e) =>
code = if e.keyCode then e.keyCode else e.which
@ -892,7 +893,7 @@ $confirm, $q, attachmentsService, $template, $compile) ->
setStatus($scope.obj.status)
render()
$scope.lightboxOpen = true
lightboxService.open($el)
lightboxService.open($el, null, null, true)
resetAttachments = () ->
attachmentsToAdd = Immutable.List()
@ -1020,7 +1021,7 @@ $confirm, $q, attachmentsService, $template, $compile) ->
deleteAttachments(data).then () ->
createAttachments(data).then () ->
currentLoading.finish()
lightboxService.close($el)
close()
$rs[schema.model].getByRef(data.project, data.ref, schema.params).then (obj) ->
$rootScope.$broadcast(broadcastEvent, obj)
promise.then null, (data) ->
@ -1031,14 +1032,27 @@ $confirm, $q, attachmentsService, $template, $compile) ->
checkClose = () ->
if !$scope.obj.isModified()
lightboxService.close($el)
close()
$scope.$apply ->
$scope.obj.revert()
else
$confirm.ask(
$translate.instant("LIGHTBOX.CREATE_EDIT.CONFIRM_CLOSE")).then (result) ->
$translate.instant("LIGHTBOX.CREATE_EDIT.CONFIRM_CLOSE"))
.then (result) ->
result.finish()
close()
close = () ->
lightboxService.close($el)
$scope.lightboxOpen = false
docEl = angular.element(document)
docEl.on "keydown.lightbox-create-edit", (event) ->
if $scope.lightboxOpen
event.stopPropagation()
code = if event.keyCode then event.keyCode else event.which
if code == 27
checkClose()
$el.on "submit", "form", submit
@ -1047,12 +1061,6 @@ $confirm, $q, attachmentsService, $template, $compile) ->
event.stopPropagation()
checkClose()
$el.keydown (event) ->
event.stopPropagation()
code = if event.keyCode then event.keyCode else event.which
if code == 27
checkClose()
$el.on "click", ".status-dropdown", (event) ->
event.preventDefault()
event.stopPropagation()