From 02c0b38bff5f6566eac7ea0e700dda4ac6cfa3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Thu, 16 Oct 2014 19:14:05 +0200 Subject: [PATCH] Add loading to block button directive and lightbox --- app/coffee/modules/common/components.coffee | 10 +++++++--- app/coffee/modules/common/lightboxes.coffee | 20 ++++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/coffee/modules/common/components.coffee b/app/coffee/modules/common/components.coffee index c0803d2c..f6773f96 100644 --- a/app/coffee/modules/common/components.coffee +++ b/app/coffee/modules/common/components.coffee @@ -339,7 +339,7 @@ module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", "$tgRepo", Assigne ## Block Button directive ############################################################################# -BlockButtonDirective = ($rootscope) -> +BlockButtonDirective = ($rootscope, $loading) -> template = _.template(""" Block Unblock @@ -366,7 +366,11 @@ BlockButtonDirective = ($rootscope) -> $rootscope.$broadcast("block", $model.$modelValue) $el.on "click", ".item-unblock", (event) -> - $rootscope.$broadcast("unblock", $model.$modelValue) + $loading.start($el.find(".item-unblock")) + finish = -> + $loading.finish($el.find(".item-unblock")) + + $rootscope.$broadcast("unblock", $model.$modelValue, finish) $scope.$on "$destroy", -> $el.off() @@ -377,7 +381,7 @@ BlockButtonDirective = ($rootscope) -> require: "ngModel" } -module.directive("tgBlockButton", ["$rootScope", BlockButtonDirective]) +module.directive("tgBlockButton", ["$rootScope", "$tgLoading", BlockButtonDirective]) ############################################################################# ## Delete Button directive diff --git a/app/coffee/modules/common/lightboxes.coffee b/app/coffee/modules/common/lightboxes.coffee index 88c4494e..fa8072c2 100644 --- a/app/coffee/modules/common/lightboxes.coffee +++ b/app/coffee/modules/common/lightboxes.coffee @@ -127,7 +127,7 @@ module.directive("lightbox", ["lightboxService", LightboxDirective]) # Issue/Userstory blocking message lightbox directive. -BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService) -> +BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loading) -> link = ($scope, $el, $attrs, $model) -> $el.find("h2.title").text($attrs.title) @@ -135,22 +135,26 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService) -> $el.find(".reason").val($model.$modelValue.blocked_note) lightboxService.open($el) - $scope.$on "unblock", -> + $scope.$on "unblock", (event, model, finishCallback) -> item = $model.$modelValue.clone() item.is_blocked = false item.blocked_note = "" - $model.$setViewValue(item) - promise = $tgrepo.save($model.$modelValue) + promise = $tgrepo.save(item) promise.then -> $confirm.notify("success") $rootscope.$broadcast("history:reload") + $model.$setViewValue(item) + finishCallback() promise.then null, -> $confirm.notify("error") item.revert() $model.$setViewValue(item) + promise.finally -> + finishCallback() + $scope.$on "$destroy", -> $el.off() @@ -162,6 +166,8 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService) -> item.blocked_note = $el.find(".reason").val() $model.$setViewValue(item) + $loading.start($el.find(".button-green")) + promise = $tgrepo.save($model.$modelValue) promise.then -> $confirm.notify("success") @@ -172,7 +178,9 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService) -> item.revert() $model.$setViewValue(item) - lightboxService.close($el) + promise.finally -> + $loading.finish($el.find(".button-green")) + lightboxService.close($el) return { templateUrl: "/partials/views/modules/lightbox-block.html" @@ -180,7 +188,7 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService) -> require: "ngModel" } -module.directive("tgLbBlock", ["$rootScope", "$tgRepo", "$tgConfirm", "lightboxService", BlockLightboxDirective]) +module.directive("tgLbBlock", ["$rootScope", "$tgRepo", "$tgConfirm", "lightboxService", "$tgLoading", BlockLightboxDirective]) #############################################################################