Check permissions in tg-task-status-button

stable
David Barragán Merino 2014-10-16 17:41:11 +02:00
parent 4d39f8a3c1
commit 58f4195e0e
1 changed files with 20 additions and 6 deletions

View File

@ -177,7 +177,7 @@ module.directive("tgTaskStatusDisplay", TaskStatusDisplayDirective)
## Task status button directive ## Task status button directive
############################################################################# #############################################################################
TaskStatusButtonDirective = ($rootScope, $repo) -> TaskStatusButtonDirective = ($rootScope, $repo, $confirm) ->
# Display the status of Task and you can edit it. # Display the status of Task and you can edit it.
# #
# Example: # Example:
@ -186,12 +186,13 @@ TaskStatusButtonDirective = ($rootScope, $repo) ->
# Requirements: # Requirements:
# - Task object (ng-model) # - Task 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">
@ -204,34 +205,47 @@ TaskStatusButtonDirective = ($rootScope, $repo) ->
""") #TODO: i18n """) #TODO: i18n
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
isEditable = ->
return $scope.project.my_permissions.indexOf("modify_task") != -1
render = (task) => render = (task) =>
status = $scope.statusById[task.status] status = $scope.statusById[task.status]
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()
task = $model.$modelValue.clone() task = $model.$modelValue.clone()
task.status = target.data("status-id") task.status = target.data("status-id")
$model.$setViewValue(task) $model.$setViewValue(task)
$repo.save($model.$modelValue).then ->
onSuccess = ->
$confirm.notify("success")
$rootScope.$broadcast("history:reload") $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) -> $scope.$watch $attrs.ngModel, (task) ->
render(task) if task render(task) if task
@ -245,7 +259,7 @@ TaskStatusButtonDirective = ($rootScope, $repo) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", TaskStatusButtonDirective]) module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", TaskStatusButtonDirective])
TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm) -> TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm) ->