From 58f4195e0eaf80013cc0b28ef281bea282c76f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Thu, 16 Oct 2014 17:41:11 +0200 Subject: [PATCH] Check permissions in tg-task-status-button --- app/coffee/modules/tasks/detail.coffee | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/coffee/modules/tasks/detail.coffee b/app/coffee/modules/tasks/detail.coffee index acfd6dca..5e8f4b5b 100644 --- a/app/coffee/modules/tasks/detail.coffee +++ b/app/coffee/modules/tasks/detail.coffee @@ -177,7 +177,7 @@ module.directive("tgTaskStatusDisplay", TaskStatusDisplayDirective) ## Task status button directive ############################################################################# -TaskStatusButtonDirective = ($rootScope, $repo) -> +TaskStatusButtonDirective = ($rootScope, $repo, $confirm) -> # Display the status of Task and you can edit it. # # Example: @@ -186,12 +186,13 @@ TaskStatusButtonDirective = ($rootScope, $repo) -> # Requirements: # - Task object (ng-model) # - scope.statusById object + # - $scope.project.my_permissions template = _.template(""" -
+
<%= status.name %> - + <% if(editable){ %><% }%> status
    @@ -204,34 +205,47 @@ TaskStatusButtonDirective = ($rootScope, $repo) -> """) #TODO: i18n link = ($scope, $el, $attrs, $model) -> + isEditable = -> + return $scope.project.my_permissions.indexOf("modify_task") != -1 + render = (task) => status = $scope.statusById[task.status] html = template({ status: status statuses: $scope.statusList + editable: isEditable() }) $el.html(html) $el.on "click", ".status-data", (event) -> event.preventDefault() event.stopPropagation() + return if not isEditable() $el.find(".pop-status").popover().open() $el.on "click", ".status", (event) -> event.preventDefault() event.stopPropagation() + return if not isEditable() + target = angular.element(event.currentTarget) $.fn.popover().closeAll() task = $model.$modelValue.clone() task.status = target.data("status-id") - $model.$setViewValue(task) - $repo.save($model.$modelValue).then -> + + onSuccess = -> + $confirm.notify("success") $rootScope.$broadcast("history:reload") + onError = -> + $confirm.notify("error") + task.revert() + $model.$setViewValue(task) + $repo.save($model.$modelValue).then(onSuccess, onError) $scope.$watch $attrs.ngModel, (task) -> render(task) if task @@ -245,7 +259,7 @@ TaskStatusButtonDirective = ($rootScope, $repo) -> require: "ngModel" } -module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", TaskStatusButtonDirective]) +module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", TaskStatusButtonDirective]) TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm) ->