Check permissions in tg-us-status-button directive

stable
David Barragán Merino 2014-10-16 13:41:35 +02:00
parent 4ab0512e22
commit 3552f305f9
1 changed files with 21 additions and 6 deletions

View File

@ -398,7 +398,7 @@ module.directive("tgUsEstimation", ["$rootScope", "$tgRepo", "$tgConfirm", UsEst
## User story status button directive ## User story status button directive
############################################################################# #############################################################################
UsStatusButtonDirective = ($rootScope, $repo) -> UsStatusButtonDirective = ($rootScope, $repo, $confirm) ->
# Display the status of a US and you can edit it. # Display the status of a US and you can edit it.
# #
# Example: # Example:
@ -407,12 +407,13 @@ UsStatusButtonDirective = ($rootScope, $repo) ->
# Requirements: # Requirements:
# - Us object (ng-model) # - Us object (ng-model)
# - scope.statusById object # - scope.statusById object
# - $scope.project.my_permissions
template = _.template(""" template = _.template("""
<div class="status-data clickable"> <div class="status-data <% if(editable){ %>clickable<% }%>">
<span class="level" style="background-color:<%= status.color %>"></span> <span class="level" style="background-color:<%= status.color %>"></span>
<span class="status-status"><%= status.name %></span> <span class="status-status"><%= status.name %></span>
<span class="icon icon-arrow-bottom"></span> <% if(editable){ %><span class="icon icon-arrow-bottom"></span><% }%>
<span class="level-name">status</span> <span class="level-name">status</span>
<ul class="popover pop-status"> <ul class="popover pop-status">
@ -425,34 +426,48 @@ UsStatusButtonDirective = ($rootScope, $repo) ->
""") #TODO: i18n """) #TODO: i18n
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
isEditable = ->
return $scope.project.my_permissions.indexOf("modify_us") != -1
render = (us) => render = (us) =>
status = $scope.statusById[us.status] status = $scope.statusById[us.status]
console.log isEditable()
html = template({ html = template({
status: status status: status
statuses: $scope.statusList statuses: $scope.statusList
editable: isEditable()
}) })
$el.html(html) $el.html(html)
$el.on "click", ".status-data", (event) -> $el.on "click", ".status-data", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
return if not isEditable()
$el.find(".pop-status").popover().open() $el.find(".pop-status").popover().open()
$el.on "click", ".status", (event) -> $el.on "click", ".status", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
return if not isEditable()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
$.fn.popover().closeAll() $.fn.popover().closeAll()
us = $model.$modelValue.clone() us = $model.$modelValue.clone()
us.status = target.data("status-id") us.status = target.data("status-id")
$model.$setViewValue(us) $model.$setViewValue(us)
$repo.save($model.$modelValue).then ->
onSuccess = ->
$confirm.notify("success")
$rootScope.$broadcast("history:reload") $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) -> $scope.$watch $attrs.ngModel, (us) ->
render(us) if us render(us) if us
@ -466,7 +481,7 @@ UsStatusButtonDirective = ($rootScope, $repo) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", UsStatusButtonDirective]) module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", UsStatusButtonDirective])
############################################################################# #############################################################################