Adding loading service to allow set a spinner on button during request
parent
dcdd9d8d8f
commit
58923eaa81
|
@ -146,7 +146,7 @@ module.directive("tgLbBlock", ["lightboxService", BlockLightboxDirective])
|
||||||
## Create/Edit Userstory Lightbox Directive
|
## Create/Edit Userstory Lightbox Directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService) ->
|
CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService, $loading) ->
|
||||||
link = ($scope, $el, attrs) ->
|
link = ($scope, $el, attrs) ->
|
||||||
isNew = true
|
isNew = true
|
||||||
|
|
||||||
|
@ -202,32 +202,25 @@ CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService)
|
||||||
form = $el.find("form").checksley()
|
form = $el.find("form").checksley()
|
||||||
target = angular.element(event.currentTarget)
|
target = angular.element(event.currentTarget)
|
||||||
|
|
||||||
loading = "<span class='icon icon-spinner'></span>" #Create spinner item
|
|
||||||
finish = target.text() #Save current text
|
|
||||||
|
|
||||||
if not form.validate()
|
if not form.validate()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
$loading.start(target)
|
||||||
if isNew
|
if isNew
|
||||||
target.addClass('loading').html(loading) # Add item
|
|
||||||
|
|
||||||
promise = $repo.create("userstories", $scope.us)
|
promise = $repo.create("userstories", $scope.us)
|
||||||
broadcastEvent = "usform:new:success"
|
broadcastEvent = "usform:new:success"
|
||||||
|
|
||||||
else
|
else
|
||||||
target.addClass('loading').html(loading) # Add item
|
|
||||||
promise = $repo.save($scope.us)
|
promise = $repo.save($scope.us)
|
||||||
broadcastEvent = "usform:edit:success"
|
broadcastEvent = "usform:edit:success"
|
||||||
|
|
||||||
promise.then (data) ->
|
promise.then (data) ->
|
||||||
target.removeClass('loading').html(finish) # Add item
|
$loading.finish(target)
|
||||||
|
|
||||||
lightboxService.close($el)
|
lightboxService.close($el)
|
||||||
$rootScope.$broadcast(broadcastEvent, data)
|
$rootScope.$broadcast(broadcastEvent, data)
|
||||||
|
|
||||||
promise.then null, (data) ->
|
promise.then null, (data) ->
|
||||||
target.removeClass('loading').html(finish) # Add item
|
$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)
|
||||||
|
@ -260,6 +253,7 @@ module.directive("tgLbCreateEditUserstory", [
|
||||||
"$tgResources",
|
"$tgResources",
|
||||||
"$rootScope",
|
"$rootScope",
|
||||||
"lightboxService",
|
"lightboxService",
|
||||||
|
"loadingService",
|
||||||
CreateEditUserstoryDirective
|
CreateEditUserstoryDirective
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
###
|
||||||
|
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||||
|
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
|
||||||
|
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# File: modules/lightboxes.coffee
|
||||||
|
###
|
||||||
|
|
||||||
|
module = angular.module("taigaCommon")
|
||||||
|
|
||||||
|
class LoadingService extends taiga.Service
|
||||||
|
start: (target) ->
|
||||||
|
target.data('loading-old-content', target.html())
|
||||||
|
target.addClass('loading')
|
||||||
|
target.html("<span class='icon icon-spinner'></span>")
|
||||||
|
|
||||||
|
finish: (target) ->
|
||||||
|
oldContent = target.data('loading-old-content')
|
||||||
|
target.data('loading-old-content', null)
|
||||||
|
target.html(oldContent)
|
||||||
|
target.removeClass('loading')
|
||||||
|
|
||||||
|
module.service("loadingService", LoadingService)
|
Loading…
Reference in New Issue