Check permissions in tg-issue-status-button, tg-issue-type-button, tg-issue-severity-button and tg-issue-priority-button directives

stable
David Barragán Merino 2014-10-16 14:37:33 +02:00
parent 3552f305f9
commit 4d39f8a3c1
1 changed files with 80 additions and 24 deletions

View File

@ -186,7 +186,7 @@ module.directive("tgIssueStatusDisplay", IssueStatusDisplayDirective)
## Issue status button directive ## Issue status button directive
############################################################################# #############################################################################
IssueStatusButtonDirective = ($rootScope, $repo) -> IssueStatusButtonDirective = ($rootScope, $repo, $confirm) ->
# Display the status of Issue and you can edit it. # Display the status of Issue and you can edit it.
# #
# Example: # Example:
@ -195,12 +195,13 @@ IssueStatusButtonDirective = ($rootScope, $repo) ->
# Requirements: # Requirements:
# - Issue object (ng-model) # - Issue 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">
@ -213,34 +214,47 @@ IssueStatusButtonDirective = ($rootScope, $repo) ->
""") #TODO: i18n """) #TODO: i18n
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
isEditable = ->
return $scope.project.my_permissions.indexOf("modify_issue") != -1
render = (issue) => render = (issue) =>
status = $scope.statusById[issue.status] status = $scope.statusById[issue.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()
issue = $model.$modelValue.clone() issue = $model.$modelValue.clone()
issue.status = target.data("status-id") issue.status = target.data("status-id")
$model.$setViewValue(issue) $model.$setViewValue(issue)
$repo.save($model.$modelValue).then ->
onSuccess = ->
$confirm.notify("success")
$rootScope.$broadcast("history:reload") $rootScope.$broadcast("history:reload")
onError = ->
$confirm.notify("error")
issue.revert()
$model.$setViewValue(issue)
$repo.save($model.$modelValue).then(onSuccess, onError)
$scope.$watch $attrs.ngModel, (issue) -> $scope.$watch $attrs.ngModel, (issue) ->
render(issue) if issue render(issue) if issue
@ -254,13 +268,13 @@ IssueStatusButtonDirective = ($rootScope, $repo) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgIssueStatusButton", ["$rootScope", "$tgRepo", IssueStatusButtonDirective]) module.directive("tgIssueStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", IssueStatusButtonDirective])
############################################################################# #############################################################################
## Issue type button directive ## Issue type button directive
############################################################################# #############################################################################
IssueTypeButtonDirective = ($rootScope, $repo) -> IssueTypeButtonDirective = ($rootScope, $repo, $confirm) ->
# Display the type of Issue and you can edit it. # Display the type of Issue and you can edit it.
# #
# Example: # Example:
@ -269,12 +283,13 @@ IssueTypeButtonDirective = ($rootScope, $repo) ->
# Requirements: # Requirements:
# - Issue object (ng-model) # - Issue object (ng-model)
# - scope.typeById object # - scope.typeById object
# - $scope.project.my_permissions
template = _.template(""" template = _.template("""
<div class="type-data clickable"> <div class="type-data <% if(editable){ %>clickable<% }%>">
<span class="level" style="background-color:<%= type.color %>"></span> <span class="level" style="background-color:<%= type.color %>"></span>
<span class="type-type"><%= type.name %></span> <span class="type-type"><%= type.name %></span>
<span class="icon icon-arrow-bottom"></span> <% if(editable){ %><span class="icon icon-arrow-bottom"></span><% }%>
<span class="level-name">type</span> <span class="level-name">type</span>
<ul class="popover pop-type"> <ul class="popover pop-type">
@ -287,34 +302,47 @@ IssueTypeButtonDirective = ($rootScope, $repo) ->
""") #TODO: i18n """) #TODO: i18n
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
isEditable = ->
return $scope.project.my_permissions.indexOf("modify_issue") != -1
render = (issue) => render = (issue) =>
type = $scope.typeById[issue.type] type = $scope.typeById[issue.type]
html = template({ html = template({
type: type type: type
typees: $scope.typeList typees: $scope.typeList
editable: isEditable()
}) })
$el.html(html) $el.html(html)
$el.on "click", ".type-data", (event) -> $el.on "click", ".type-data", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
return if not isEditable()
$el.find(".pop-type").popover().open() $el.find(".pop-type").popover().open()
$el.on "click", ".type", (event) -> $el.on "click", ".type", (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()
issue = $model.$modelValue.clone() issue = $model.$modelValue.clone()
issue.type = target.data("type-id") issue.type = target.data("type-id")
$model.$setViewValue(issue) $model.$setViewValue(issue)
$repo.save($model.$modelValue).then ->
onSuccess = ->
$confirm.notify("success")
$rootScope.$broadcast("history:reload") $rootScope.$broadcast("history:reload")
onError = ->
$confirm.notify("error")
issue.revert()
$model.$setViewValue(issue)
$repo.save($model.$modelValue).then(onSuccess, onError)
$scope.$watch $attrs.ngModel, (issue) -> $scope.$watch $attrs.ngModel, (issue) ->
render(issue) if issue render(issue) if issue
@ -328,14 +356,14 @@ IssueTypeButtonDirective = ($rootScope, $repo) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgIssueTypeButton", ["$rootScope", "$tgRepo", IssueTypeButtonDirective]) module.directive("tgIssueTypeButton", ["$rootScope", "$tgRepo", "$tgConfirm", IssueTypeButtonDirective])
############################################################################# #############################################################################
## Issue severity button directive ## Issue severity button directive
############################################################################# #############################################################################
IssueSeverityButtonDirective = ($rootScope, $repo) -> IssueSeverityButtonDirective = ($rootScope, $repo, $confirm) ->
# Display the severity of Issue and you can edit it. # Display the severity of Issue and you can edit it.
# #
# Example: # Example:
@ -344,12 +372,13 @@ IssueSeverityButtonDirective = ($rootScope, $repo) ->
# Requirements: # Requirements:
# - Issue object (ng-model) # - Issue object (ng-model)
# - scope.severityById object # - scope.severityById object
# - $scope.project.my_permissions
template = _.template(""" template = _.template("""
<div class="severity-data clickable"> <div class="severity-data <% if(editable){ %>clickable<% }%>">
<span class="level" style="background-color:<%= severity.color %>"></span> <span class="level" style="background-color:<%= severity.color %>"></span>
<span class="severity-severity"><%= severity.name %></span> <span class="severity-severity"><%= severity.name %></span>
<span class="icon icon-arrow-bottom"></span> <% if(editable){ %><span class="icon icon-arrow-bottom"></span><% }%>
<span class="level-name">severity</span> <span class="level-name">severity</span>
<ul class="popover pop-severity"> <ul class="popover pop-severity">
@ -362,34 +391,47 @@ IssueSeverityButtonDirective = ($rootScope, $repo) ->
""") #TODO: i18n """) #TODO: i18n
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
isEditable = ->
return $scope.project.my_permissions.indexOf("modify_issue") != -1
render = (issue) => render = (issue) =>
severity = $scope.severityById[issue.severity] severity = $scope.severityById[issue.severity]
html = template({ html = template({
severity: severity severity: severity
severityes: $scope.severityList severityes: $scope.severityList
editable: isEditable()
}) })
$el.html(html) $el.html(html)
$el.on "click", ".severity-data", (event) -> $el.on "click", ".severity-data", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
return if not isEditable()
$el.find(".pop-severity").popover().open() $el.find(".pop-severity").popover().open()
$el.on "click", ".severity", (event) -> $el.on "click", ".severity", (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()
issue = $model.$modelValue.clone() issue = $model.$modelValue.clone()
issue.severity = target.data("severity-id") issue.severity = target.data("severity-id")
$model.$setViewValue(issue) $model.$setViewValue(issue)
$repo.save($model.$modelValue).then ->
onSuccess = ->
$confirm.notify("success")
$rootScope.$broadcast("history:reload") $rootScope.$broadcast("history:reload")
onError = ->
$confirm.notify("error")
issue.revert()
$model.$setViewValue(issue)
$repo.save($model.$modelValue).then(onSuccess, onError)
$scope.$watch $attrs.ngModel, (issue) -> $scope.$watch $attrs.ngModel, (issue) ->
render(issue) if issue render(issue) if issue
@ -403,14 +445,14 @@ IssueSeverityButtonDirective = ($rootScope, $repo) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgIssueSeverityButton", ["$rootScope", "$tgRepo", IssueSeverityButtonDirective]) module.directive("tgIssueSeverityButton", ["$rootScope", "$tgRepo", "$tgConfirm", IssueSeverityButtonDirective])
############################################################################# #############################################################################
## Issue priority button directive ## Issue priority button directive
############################################################################# #############################################################################
IssuePriorityButtonDirective = ($rootScope, $repo) -> IssuePriorityButtonDirective = ($rootScope, $repo, $confirm) ->
# Display the priority of Issue and you can edit it. # Display the priority of Issue and you can edit it.
# #
# Example: # Example:
@ -419,12 +461,13 @@ IssuePriorityButtonDirective = ($rootScope, $repo) ->
# Requirements: # Requirements:
# - Issue object (ng-model) # - Issue object (ng-model)
# - scope.priorityById object # - scope.priorityById object
# - $scope.project.my_permissions
template = _.template(""" template = _.template("""
<div class="priority-data clickable"> <div class="priority-data <% if(editable){ %>clickable<% }%>">
<span class="level" style="background-color:<%= priority.color %>"></span> <span class="level" style="background-color:<%= priority.color %>"></span>
<span class="priority-priority"><%= priority.name %></span> <span class="priority-priority"><%= priority.name %></span>
<span class="icon icon-arrow-bottom"></span> <% if(editable){ %><span class="icon icon-arrow-bottom"></span><% }%>
<span class="level-name">priority</span> <span class="level-name">priority</span>
<ul class="popover pop-priority"> <ul class="popover pop-priority">
@ -437,34 +480,47 @@ IssuePriorityButtonDirective = ($rootScope, $repo) ->
""") #TODO: i18n """) #TODO: i18n
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
isEditable = ->
return $scope.project.my_permissions.indexOf("modify_issue") != -1
render = (issue) => render = (issue) =>
priority = $scope.priorityById[issue.priority] priority = $scope.priorityById[issue.priority]
html = template({ html = template({
priority: priority priority: priority
priorityes: $scope.priorityList priorityes: $scope.priorityList
editable: isEditable()
}) })
$el.html(html) $el.html(html)
$el.on "click", ".priority-data", (event) -> $el.on "click", ".priority-data", (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
return if not isEditable()
$el.find(".pop-priority").popover().open() $el.find(".pop-priority").popover().open()
$el.on "click", ".priority", (event) -> $el.on "click", ".priority", (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()
issue = $model.$modelValue.clone() issue = $model.$modelValue.clone()
issue.priority = target.data("priority-id") issue.priority = target.data("priority-id")
$model.$setViewValue(issue) $model.$setViewValue(issue)
$repo.save($model.$modelValue).then ->
onSuccess = ->
$confirm.notify("success")
$rootScope.$broadcast("history:reload") $rootScope.$broadcast("history:reload")
onError = ->
$confirm.notify("error")
issue.revert()
$model.$setViewValue(issue)
$repo.save($model.$modelValue).then(onSuccess, onError)
$scope.$watch $attrs.ngModel, (issue) -> $scope.$watch $attrs.ngModel, (issue) ->
render(issue) if issue render(issue) if issue
@ -478,7 +534,7 @@ IssuePriorityButtonDirective = ($rootScope, $repo) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgIssuePriorityButton", ["$rootScope", "$tgRepo", IssuePriorityButtonDirective]) module.directive("tgIssuePriorityButton", ["$rootScope", "$tgRepo", "$tgConfirm", IssuePriorityButtonDirective])
############################################################################# #############################################################################