Improved confirm/ask method.

It now wait results before close, and add a spinner.
stable
Jesús Espino 2014-09-18 10:01:25 +02:00 committed by Andrey Antukh
parent db34a5c39c
commit 5b17f5bda9
15 changed files with 107 additions and 56 deletions

View File

@ -430,15 +430,16 @@ MembershipsRowActionsDirective = ($log, $repo, $rs, $confirm) ->
title = "Delete member" # TODO: i18n
subtitle = if member.user then member.full_name else "the invitation to #{member.email}" # TODO: i18n
onSuccess = ->
$ctrl.loadMembers()
$confirm.notify("success", null, "We've deleted #{subtitle}.") # TODO: i18n
$confirm.ask(title, subtitle).then (finish) ->
onSuccess = ->
finish()
$ctrl.loadMembers()
$confirm.notify("success", null, "We've deleted #{subtitle}.") # TODO: i18n
onError = ->
# TODO: i18in
$confirm.notify("error", null, "We have not been able to delete #{subtitle}.")
onError = ->
# TODO: i18in
$confirm.notify("error", null, "We have not been able to delete #{subtitle}.")
$confirm.ask(title, subtitle).then ->
$repo.remove(member).then(onSuccess, onError)
$scope.$on "$destroy", ->

View File

@ -267,12 +267,13 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame) ->
if _.keys(choices).length == 0
return $confirm.error("You can't delete all values.")
return $confirm.askChoice(title, subtitle, choices).then (selected) =>
return $confirm.askChoice(title, subtitle, choices).then (response) ->
onSucces = ->
$ctrl.loadValues()
$ctrl.loadValues().finally ->
response.finish()
onError = ->
$confirm.notify("error")
$repo.remove(value, {"moveTo": selected}).then(onSucces, onError)
$repo.remove(value, {"moveTo": response.selected}).then(onSucces, onError)
link = ($scope, $el, $attrs) ->
linkDragAndDrop($scope, $el, $attrs)

View File

@ -100,11 +100,11 @@ class RolesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fil
if _.keys(choices).length == 0
return @confirm.error("You can't delete all values.")
return @confirm.askChoice(title, subtitle, choices).then (selected) =>
promise = @repo.remove(@scope.role, {moveTo: selected})
return @confirm.askChoice(title, subtitle, choices).then (response) =>
promise = @repo.remove(@scope.role, {moveTo: response.selected})
promise.then =>
@confirm.notify('success')
@.loadRoles()
@.loadRoles().finally ->
response.finish()
promise.then null, =>
@confirm.notify('error')

View File

@ -80,11 +80,13 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading)
title = "Delete sprint"
subtitle = $scope.sprint.name
$confirm.ask(title, subtitle).then =>
$confirm.ask(title, subtitle).then (finish) =>
onSuccess = ->
finish()
$scope.milestonesCounter -= 1
lightboxService.close($el)
$rootscope.$broadcast("sprintform:remove:success")
onError = ->
$confirm.notify("error")
$repo.remove($scope.sprint).then(onSuccess, onError)

View File

@ -411,12 +411,16 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
title = "Delete User Story"
subtitle = us.subject
@confirm.ask(title, subtitle).then =>
@confirm.ask(title, subtitle).then (finish) =>
# We modify the userstories in scope so the user doesn't see the removed US for a while
@scope.userstories = _.without(@scope.userstories, us)
@filterVisibleUserstories()
@.repo.remove(us).then =>
promise = @.repo.remove(us)
promise.then =>
finish()
@.loadBacklog()
promise.then null, =>
@confirm.notify("error")
addNewUs: (type) ->
switch type

View File

@ -38,9 +38,9 @@ NOTIFICATION_MSG = {
class ConfirmService extends taiga.Service
@.$inject = ["$q", "lightboxService"]
@.$inject = ["$q", "lightboxService", "$tgLoading"]
constructor: (@q, @lightboxService) ->
constructor: (@q, @lightboxService, @loading) ->
_.bindAll(@)
hide: ->
@ -61,8 +61,11 @@ class ConfirmService extends taiga.Service
# Assign event handlers
@.el.on "click.confirm-dialog", "a.button-green", (event) =>
event.preventDefault()
defered.resolve()
@.hide()
target = angular.element(event.currentTarget)
@loading.start(target)
defered.resolve =>
@loading.finish(target)
@.hide()
@.el.on "click.confirm-dialog", "a.button-red", (event) =>
event.preventDefault()
@ -88,8 +91,14 @@ class ConfirmService extends taiga.Service
# Assign event handlers
@.el.on "click.confirm-dialog", "a.button-green", (event) =>
event.preventDefault()
defered.resolve(choicesField.val())
@.hide()
target = angular.element(event.currentTarget)
@loading.start(target)
defered.resolve {
selected: choicesField.val()
finish: =>
@loading.finish(target)
@.hide()
}
@.el.on "click.confirm-dialog", "a.button-red", (event) =>
event.preventDefault()
@ -190,4 +199,4 @@ class ConfirmService extends taiga.Service
module = angular.module("taigaBase")
module.service("$tgConfirm", ["$q", "lightboxService", ConfirmService])
module.service("$tgConfirm", ConfirmService)

View File

@ -129,17 +129,18 @@ class AttachmentsController extends taiga.Controller
title = "Delete attachment" #TODO: i18in
subtitle = "the attachment '#{attachment.name}'" #TODO: i18in
onSuccess = =>
index = @.attachments.indexOf(attachment)
@.attachments.splice(index, 1)
@.updateCounters()
@rootscope.$broadcast("attachment:delete")
return @confirm.ask(title, subtitle).then (finish) =>
onSuccess = =>
finish()
index = @.attachments.indexOf(attachment)
@.attachments.splice(index, 1)
@.updateCounters()
@rootscope.$broadcast("attachment:delete")
onError = =>
@confirm.notify("error", null, "We have not been able to delete #{subtitle}.")
return @q.reject()
onError = =>
@confirm.notify("error", null, "We have not been able to delete #{subtitle}.")
return @q.reject()
return @confirm.ask(title, subtitle).then =>
return @repo.remove(attachment).then(onSuccess, onError)
# Function used in template for filter visible attachments

View File

@ -177,7 +177,8 @@ WatchersDirective = ($rootscope, $confirm) ->
title = "Remove watcher"
subtitle = $scope.usersById[watcherId].full_name_display
$confirm.ask(title, subtitle).then =>
$confirm.ask(title, subtitle).then (finish) =>
finish()
watcherIds = _.clone($model.$modelValue.watchers, false)
watcherIds = _.pull(watcherIds, watcherId)
@ -260,7 +261,8 @@ AssignedToDirective = ($rootscope, $confirm) ->
title = "Remove assigned to"
subtitle = ""
$confirm.ask(title, subtitle).then =>
$confirm.ask(title, subtitle).then (finish) =>
finish()
$model.$modelValue.assigned_to = null
renderAssignedTo($model.$modelValue)

View File

@ -129,9 +129,13 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
title = "Delete Issue"
subtitle = @scope.issue.subject
@confirm.ask(title, subtitle).then =>
@.repo.remove(@scope.issue).then =>
@confirm.ask(title, subtitle).then (finish) =>
promise = @.repo.remove(@scope.issue)
promise.then =>
finish()
@location.path(@navUrls.resolve("project-issues", {project: @scope.project.slug}))
promise.then null, =>
@confirm.notify("error")
module.controller("IssueDetailController", IssueDetailController)

View File

@ -621,11 +621,18 @@ IssuesFiltersDirective = ($log, $location, $rs, $confirm) ->
title = "Delete custom filter" # TODO: i18n
subtitle = "the custom filter '#{customFilterName}'" # TODO: i18n
$confirm.ask(title, subtitle).then ->
$ctrl.deleteMyFilter(customFilterName).then ->
$confirm.ask(title, subtitle).then (finish) ->
promise = $ctrl.deleteMyFilter(customFilterName)
promise.then ->
$ctrl.loadMyFilters().then (filters) ->
finish()
$scope.filters.myFilters = filters
renderFilters($scope.filters.myFilters)
$ctrl.loadMyFilters().then null, ->
finish()
promise.then null, ->
$confirm.notify("error")
$el.on "click", ".save-filters", (event) ->
event.preventDefault()

View File

@ -133,11 +133,16 @@ RelatedTaskRowDirective = ($repo, $compile, $confirm, $rootscope) ->
title = "Delete Task"
subtitle = task.subject
$confirm.ask(title, subtitle).then ->
$repo.remove(task).then ->
$confirm.ask(title, subtitle).then (finish) ->
promise = $repo.remove(task)
promise.then ->
finish()
$confirm.notify("success")
$scope.$emit("related-tasks:delete")
promise.then null, ->
$confirm.notify("error")
$scope.$watch $attrs.ngModel, (val) ->
return if not val
renderView(val)

View File

@ -130,9 +130,13 @@ class TaskDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
title = "Delete Task"
subtitle = @scope.task.subject
@confirm.ask(title, subtitle).then =>
@.repo.remove(@scope.task).then =>
@confirm.ask(title, subtitle).then (finish) =>
promise = @.repo.remove(@scope.task)
promise.then =>
finish()
@location.path(@navUrls.resolve("project-backlog", {project: @scope.project.slug}))
promise.then null, =>
@confirm.notify("error")
module.controller("TaskDetailController", TaskDetailController)

View File

@ -139,9 +139,13 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
title = "Delete User Story"
subtitle = @scope.us.subject
@confirm.ask(title, subtitle).then =>
@.repo.remove(@scope.us).then =>
@confirm.ask(title, subtitle).then (finish) =>
promise = @.repo.remove(@scope.us)
promise.then =>
finish()
@location.path(@navUrls.resolve("project-backlog", {project: @scope.project.slug}))
promise.then null, =>
$confirm.notify("error")
module.controller("UserStoryDetailController", UserStoryDetailController)

View File

@ -134,19 +134,20 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
@location.path(@navUrls.resolve("project-wiki-page", ctx))
delete: ->
onSuccess = =>
ctx = {project: @scope.projectSlug}
@location.path(@navUrls.resolve("project-wiki", ctx))
@confirm.notify("success")
onError = =>
@confirm.notify("error")
# TODO: i18n
title = "Delete Wiki Page"
subtitle = unslugify(@scope.wiki.slug)
@confirm.ask(title, subtitle).then =>
@confirm.ask(title, subtitle).then (finish) =>
onSuccess = =>
finish()
ctx = {project: @scope.projectSlug}
@location.path(@navUrls.resolve("project-wiki", ctx))
@confirm.notify("success")
onError = =>
@confirm.notify("error")
@repo.remove(@scope.wiki).then onSuccess, onError
module.controller("WikiDetailController", WikiDetailController)

View File

@ -109,10 +109,16 @@ WikiNavDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
title = "Delete Wiki Link"
subtitle = $scope.wikiLinks[linkId].title
$confirm.ask(title, subtitle).then =>
$tgrepo.remove($scope.wikiLinks[linkId]).then ->
$confirm.ask(title, subtitle).then (finish) =>
promise = $tgrepo.remove($scope.wikiLinks[linkId])
promise.then ->
$ctrl.loadWikiLinks().then ->
finish()
render($scope.wikiLinks)
$ctrl.loadWikiLinks().then null, ->
finish()
promise.then null, ->
$confirm.notify("error")
$el.on "keyup", ".new input", (event) ->
event.preventDefault()