From 752f14584afb8e142efccae5737dece0becdbbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Thu, 16 Oct 2014 19:24:26 +0200 Subject: [PATCH] Add spinner to iocaine button and refactor a little the directive --- app/coffee/modules/tasks/detail.coffee | 31 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/coffee/modules/tasks/detail.coffee b/app/coffee/modules/tasks/detail.coffee index 5e8f4b5b..59c06167 100644 --- a/app/coffee/modules/tasks/detail.coffee +++ b/app/coffee/modules/tasks/detail.coffee @@ -262,7 +262,7 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm) -> module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", TaskStatusButtonDirective]) -TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm) -> +TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading) -> template = _.template("""
@@ -271,37 +271,44 @@ TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm) -> """) link = ($scope, $el, $attrs, $model) -> - render = _.once (us) -> + render = _.once (task) -> $el.html(template()) - refresh = (us) -> - if us?.is_iocaine + refresh = (task) -> + if task?.is_iocaine $el.find('.is-iocaine').addClass('active') else $el.find('.is-iocaine').removeClass('active') - $scope.$watch $attrs.ngModel, (us) -> - return if not us - render(us) - refresh(us) + $scope.$watch $attrs.ngModel, (task) -> + return if not task + render(task) + refresh(task) $scope.$on "$destroy", -> $el.off() $el.on "click", ".is-iocaine", (event) -> - us = $model.$modelValue.clone() - us.is_iocaine = not us.is_iocaine - $model.$setViewValue(us) + task = $model.$modelValue.clone() + task.is_iocaine = not task.is_iocaine + $model.$setViewValue(task) + $loading.start($el.find('label')) + promise = $tgrepo.save($model.$modelValue) promise.then -> + $confirm.notify("success") $rootscope.$broadcast("history:reload") + promise.then null, -> $confirm.notify("error") + promise.finally -> + $loading.finish($el.find('label')) + return { link: link restrict: "EA" require: "ngModel" } -module.directive("tgTaskIsIocaineButton", ["$rootScope", "$tgRepo", "$tgConfirm", TaskIsIocaineButtonDirective]) +module.directive("tgTaskIsIocaineButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", TaskIsIocaineButtonDirective])