Add some loading spiners on some save buttons

stable
Jesús Espino 2014-09-05 14:58:20 +02:00
parent 68f48f6a1c
commit 09f4b382ff
4 changed files with 39 additions and 13 deletions

View File

@ -92,18 +92,22 @@ module.controller("ProjectProfileController", ProjectProfileController)
## Project Profile Directive ## Project Profile Directive
############################################################################# #############################################################################
ProjectProfileDirective = ($rootscope, $log, $repo, $confirm) -> ProjectProfileDirective = ($rootscope, $log, $repo, $confirm, $loading) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
form = $el.find("form").checksley({"onlyOneErrorElement": true}) form = $el.find("form").checksley({"onlyOneErrorElement": true})
submit = => submit = (target) =>
return if not form.validate() return if not form.validate()
$loading.start(target)
promise = $repo.save($scope.project) promise = $repo.save($scope.project)
promise.then -> promise.then ->
$loading.finish(target)
$confirm.notify("success") $confirm.notify("success")
$scope.$emit("project:loaded", $scope.project) $scope.$emit("project:loaded", $scope.project)
promise.then null, (data) -> promise.then null, (data) ->
$loading.finish(target)
form.setErrors(data) form.setErrors(data)
if data._error_message if data._error_message
$confirm.notify("error", data._error_message) $confirm.notify("error", data._error_message)
@ -112,31 +116,41 @@ ProjectProfileDirective = ($rootscope, $log, $repo, $confirm) ->
event.preventDefault() event.preventDefault()
submit() submit()
$el.on "click", "form a.button-green", (event) -> $el.on "click", ".default-values a.button-green", (event) ->
event.preventDefault() event.preventDefault()
submit() target = angular.element(event.currentTarget)
submit(target)
$el.on "click", ".project-details a.button-green", (event) ->
event.preventDefault()
target = angular.element(event.currentTarget)
submit(target)
return {link:link} return {link:link}
module.directive("tgProjectProfile", ["$rootScope", "$log", "$tgRepo", "$tgConfirm", ProjectProfileDirective]) module.directive("tgProjectProfile", ["$rootScope", "$log", "$tgRepo", "$tgConfirm", "$tgLoading", ProjectProfileDirective])
############################################################################# #############################################################################
## Project Features Directive ## Project Features Directive
############################################################################# #############################################################################
ProjectFeaturesDirective = ($rootscope, $log, $repo, $confirm) -> ProjectFeaturesDirective = ($rootscope, $log, $repo, $confirm, $loading) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
form = $el.find("form").checksley() form = $el.find("form").checksley()
submit = => submit = =>
return if not form.validate() return if not form.validate()
target = angular.element(".admin-functionalities a.button-green")
$loading.start(target)
promise = $repo.save($scope.project) promise = $repo.save($scope.project)
promise.then -> promise.then ->
$loading.finish(target)
$confirm.notify("success") $confirm.notify("success")
$scope.$emit("project:loaded", $scope.project) $scope.$emit("project:loaded", $scope.project)
promise.then null, (data) -> promise.then null, (data) ->
$loading.finish(target)
$confirm.notify("error", data._error_message) $confirm.notify("error", data._error_message)
$el.on "submit", "form", (event) -> $el.on "submit", "form", (event) ->
@ -163,4 +177,4 @@ ProjectFeaturesDirective = ($rootscope, $log, $repo, $confirm) ->
return {link:link} return {link:link}
module.directive("tgProjectFeatures", ["$rootScope", "$log", "$tgRepo", "$tgConfirm", ProjectFeaturesDirective]) module.directive("tgProjectFeatures", ["$rootScope", "$log", "$tgRepo", "$tgConfirm", "$tgLoading", ProjectFeaturesDirective])

View File

@ -157,7 +157,7 @@ module.controller("IssueDetailController", IssueDetailController)
## Issue Main Directive ## Issue Main Directive
############################################################################# #############################################################################
IssueDirective = ($tgrepo, $log, $location, $confirm, $navUrls) -> IssueDirective = ($tgrepo, $log, $location, $confirm, $navUrls, $loading) ->
linkSidebar = ($scope, $el, $attrs, $ctrl) -> linkSidebar = ($scope, $el, $attrs, $ctrl) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
@ -172,6 +172,7 @@ IssueDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
return return
onSuccess = -> onSuccess = ->
$loading.finish(target)
$confirm.notify("success") $confirm.notify("success")
ctx = { ctx = {
project: $scope.project.slug project: $scope.project.slug
@ -180,8 +181,11 @@ IssueDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
$location.path($navUrls.resolve("project-issues-detail", ctx)) $location.path($navUrls.resolve("project-issues-detail", ctx))
onError = -> onError = ->
$loading.finish(target)
$confirm.notify("error") $confirm.notify("error")
target = angular.element(event.currentTarget)
$loading.start(target)
$tgrepo.save($scope.issue).then(onSuccess, onError) $tgrepo.save($scope.issue).then(onSuccess, onError)
$el.on "click", ".add-comment a.button-green", (event) -> $el.on "click", ".add-comment a.button-green", (event) ->
@ -207,7 +211,7 @@ IssueDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
return {link:link} return {link:link}
module.directive("tgIssueDetail", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", "$tgNavUrls", module.directive("tgIssueDetail", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", "$tgNavUrls",
IssueDirective]) "$tgLoading", IssueDirective])
############################################################################# #############################################################################

View File

@ -150,7 +150,7 @@ module.controller("TaskDetailController", TaskDetailController)
## Task Main Directive ## Task Main Directive
############################################################################# #############################################################################
TaskDirective = ($tgrepo, $log, $location, $confirm, $navUrls) -> TaskDirective = ($tgrepo, $log, $location, $confirm, $navUrls, $loading) ->
linkSidebar = ($scope, $el, $attrs, $ctrl) -> linkSidebar = ($scope, $el, $attrs, $ctrl) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
@ -165,6 +165,7 @@ TaskDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
return return
onSuccess = -> onSuccess = ->
$loading.finish(target)
$confirm.notify("success") $confirm.notify("success")
ctx = { ctx = {
project: $scope.project.slug project: $scope.project.slug
@ -173,8 +174,11 @@ TaskDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
$location.path($navUrls.resolve("project-tasks-detail", ctx)) $location.path($navUrls.resolve("project-tasks-detail", ctx))
onError = -> onError = ->
$loading.finish(target)
$confirm.notify("error") $confirm.notify("error")
target = angular.element(event.currentTarget)
$loading.start(target)
$tgrepo.save($scope.task).then(onSuccess, onError) $tgrepo.save($scope.task).then(onSuccess, onError)
$el.on "click", ".add-comment a.button-green", (event) -> $el.on "click", ".add-comment a.button-green", (event) ->
@ -200,7 +204,7 @@ TaskDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
return {link:link} return {link:link}
module.directive("tgTaskDetail", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", "$tgNavUrls", module.directive("tgTaskDetail", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", "$tgNavUrls",
TaskDirective]) "$tgLoading", TaskDirective])
############################################################################# #############################################################################

View File

@ -167,7 +167,7 @@ module.controller("UserStoryDetailController", UserStoryDetailController)
## User story Main Directive ## User story Main Directive
############################################################################# #############################################################################
UsDirective = ($tgrepo, $log, $location, $confirm, $navUrls) -> UsDirective = ($tgrepo, $log, $location, $confirm, $navUrls, $loading) ->
linkSidebar = ($scope, $el, $attrs, $ctrl) -> linkSidebar = ($scope, $el, $attrs, $ctrl) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
@ -182,6 +182,7 @@ UsDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
return return
onSuccess = -> onSuccess = ->
$loading.finish(target)
$confirm.notify("success") $confirm.notify("success")
ctx = { ctx = {
project: $scope.project.slug project: $scope.project.slug
@ -190,8 +191,11 @@ UsDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
$location.path($navUrls.resolve("project-userstories-detail", ctx)) $location.path($navUrls.resolve("project-userstories-detail", ctx))
onError = -> onError = ->
$loading.finish(target)
$confirm.notify("error") $confirm.notify("error")
target = angular.element(event.currentTarget)
$loading.start(target)
$tgrepo.save($scope.us).then(onSuccess, onError) $tgrepo.save($scope.us).then(onSuccess, onError)
$el.on "click", ".add-comment a.button-green", (event) -> $el.on "click", ".add-comment a.button-green", (event) ->
@ -216,7 +220,7 @@ UsDirective = ($tgrepo, $log, $location, $confirm, $navUrls) ->
return {link:link} return {link:link}
module.directive("tgUsDetail", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", "$tgNavUrls", UsDirective]) module.directive("tgUsDetail", ["$tgRepo", "$log", "$tgLocation", "$tgConfirm", "$tgNavUrls", "$tgLoading", UsDirective])
############################################################################# #############################################################################