From 3552f305f9d160d1392d1e4fd6ed5dffb6b157bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Thu, 16 Oct 2014 13:41:35 +0200 Subject: [PATCH] Check permissions in tg-us-status-button directive --- app/coffee/modules/userstories/detail.coffee | 27 +++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/app/coffee/modules/userstories/detail.coffee b/app/coffee/modules/userstories/detail.coffee index 3a061603..556602e6 100644 --- a/app/coffee/modules/userstories/detail.coffee +++ b/app/coffee/modules/userstories/detail.coffee @@ -398,7 +398,7 @@ module.directive("tgUsEstimation", ["$rootScope", "$tgRepo", "$tgConfirm", UsEst ## User story status button directive ############################################################################# -UsStatusButtonDirective = ($rootScope, $repo) -> +UsStatusButtonDirective = ($rootScope, $repo, $confirm) -> # Display the status of a US and you can edit it. # # Example: @@ -407,12 +407,13 @@ UsStatusButtonDirective = ($rootScope, $repo) -> # Requirements: # - Us object (ng-model) # - scope.statusById object + # - $scope.project.my_permissions template = _.template(""" -
+
<%= status.name %> - + <% if(editable){ %><% }%> status
    @@ -425,34 +426,48 @@ UsStatusButtonDirective = ($rootScope, $repo) -> """) #TODO: i18n link = ($scope, $el, $attrs, $model) -> + isEditable = -> + return $scope.project.my_permissions.indexOf("modify_us") != -1 + render = (us) => status = $scope.statusById[us.status] + console.log isEditable() 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() us = $model.$modelValue.clone() us.status = target.data("status-id") - $model.$setViewValue(us) - $repo.save($model.$modelValue).then -> + + onSuccess = -> + $confirm.notify("success") $rootScope.$broadcast("history:reload") + onError = -> + $confirm.notify("error") + us.revert() + $model.$setViewValue(us) + $repo.save($model.$modelValue).then(onSuccess, onError) $scope.$watch $attrs.ngModel, (us) -> render(us) if us @@ -466,7 +481,7 @@ UsStatusButtonDirective = ($rootScope, $repo) -> require: "ngModel" } -module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", UsStatusButtonDirective]) +module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", UsStatusButtonDirective]) #############################################################################