From 5b17f5bda9e50042118e21e8800f22753290cc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Thu, 18 Sep 2014 10:01:25 +0200 Subject: [PATCH] Improved confirm/ask method. It now wait results before close, and add a spinner. --- app/coffee/modules/admin/memberships.coffee | 15 ++++++------ .../modules/admin/project-values.coffee | 7 +++--- app/coffee/modules/admin/roles.coffee | 8 +++---- app/coffee/modules/backlog/lightboxes.coffee | 4 +++- app/coffee/modules/backlog/main.coffee | 8 +++++-- app/coffee/modules/base/confirm.coffee | 23 +++++++++++++------ app/coffee/modules/common/attachments.coffee | 19 +++++++-------- app/coffee/modules/common/components.coffee | 6 +++-- app/coffee/modules/issues/detail.coffee | 8 +++++-- app/coffee/modules/issues/list.coffee | 11 +++++++-- app/coffee/modules/related-tasks.coffee | 9 ++++++-- app/coffee/modules/tasks/detail.coffee | 8 +++++-- app/coffee/modules/userstories/detail.coffee | 8 +++++-- app/coffee/modules/wiki/main.coffee | 19 +++++++-------- app/coffee/modules/wiki/nav.coffee | 10 ++++++-- 15 files changed, 107 insertions(+), 56 deletions(-) diff --git a/app/coffee/modules/admin/memberships.coffee b/app/coffee/modules/admin/memberships.coffee index 3152f9e0..24d8bf40 100644 --- a/app/coffee/modules/admin/memberships.coffee +++ b/app/coffee/modules/admin/memberships.coffee @@ -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", -> diff --git a/app/coffee/modules/admin/project-values.coffee b/app/coffee/modules/admin/project-values.coffee index cf221763..152b9e89 100644 --- a/app/coffee/modules/admin/project-values.coffee +++ b/app/coffee/modules/admin/project-values.coffee @@ -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) diff --git a/app/coffee/modules/admin/roles.coffee b/app/coffee/modules/admin/roles.coffee index 402f4ae9..7cf90112 100644 --- a/app/coffee/modules/admin/roles.coffee +++ b/app/coffee/modules/admin/roles.coffee @@ -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') diff --git a/app/coffee/modules/backlog/lightboxes.coffee b/app/coffee/modules/backlog/lightboxes.coffee index 49daa9ce..6f8dc450 100644 --- a/app/coffee/modules/backlog/lightboxes.coffee +++ b/app/coffee/modules/backlog/lightboxes.coffee @@ -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) diff --git a/app/coffee/modules/backlog/main.coffee b/app/coffee/modules/backlog/main.coffee index 76524faf..eb0faefa 100644 --- a/app/coffee/modules/backlog/main.coffee +++ b/app/coffee/modules/backlog/main.coffee @@ -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 diff --git a/app/coffee/modules/base/confirm.coffee b/app/coffee/modules/base/confirm.coffee index 0f30561e..f7280630 100644 --- a/app/coffee/modules/base/confirm.coffee +++ b/app/coffee/modules/base/confirm.coffee @@ -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) diff --git a/app/coffee/modules/common/attachments.coffee b/app/coffee/modules/common/attachments.coffee index f50d0ead..39517bf1 100644 --- a/app/coffee/modules/common/attachments.coffee +++ b/app/coffee/modules/common/attachments.coffee @@ -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 diff --git a/app/coffee/modules/common/components.coffee b/app/coffee/modules/common/components.coffee index 1ca1381c..a3cc656d 100644 --- a/app/coffee/modules/common/components.coffee +++ b/app/coffee/modules/common/components.coffee @@ -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) diff --git a/app/coffee/modules/issues/detail.coffee b/app/coffee/modules/issues/detail.coffee index fd1de78e..cd1ab12f 100644 --- a/app/coffee/modules/issues/detail.coffee +++ b/app/coffee/modules/issues/detail.coffee @@ -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) diff --git a/app/coffee/modules/issues/list.coffee b/app/coffee/modules/issues/list.coffee index ab7e30fc..76374291 100644 --- a/app/coffee/modules/issues/list.coffee +++ b/app/coffee/modules/issues/list.coffee @@ -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() diff --git a/app/coffee/modules/related-tasks.coffee b/app/coffee/modules/related-tasks.coffee index 5e537821..7872a6a7 100644 --- a/app/coffee/modules/related-tasks.coffee +++ b/app/coffee/modules/related-tasks.coffee @@ -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) diff --git a/app/coffee/modules/tasks/detail.coffee b/app/coffee/modules/tasks/detail.coffee index 31bc91af..6f08f8d0 100644 --- a/app/coffee/modules/tasks/detail.coffee +++ b/app/coffee/modules/tasks/detail.coffee @@ -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) diff --git a/app/coffee/modules/userstories/detail.coffee b/app/coffee/modules/userstories/detail.coffee index 28021f19..1dd2d84c 100644 --- a/app/coffee/modules/userstories/detail.coffee +++ b/app/coffee/modules/userstories/detail.coffee @@ -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) diff --git a/app/coffee/modules/wiki/main.coffee b/app/coffee/modules/wiki/main.coffee index b28c6d5d..a26916a8 100644 --- a/app/coffee/modules/wiki/main.coffee +++ b/app/coffee/modules/wiki/main.coffee @@ -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) diff --git a/app/coffee/modules/wiki/nav.coffee b/app/coffee/modules/wiki/nav.coffee index f16ac626..0d6d8e2e 100644 --- a/app/coffee/modules/wiki/nav.coffee +++ b/app/coffee/modules/wiki/nav.coffee @@ -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()