diff --git a/app/coffee/modules/common/components.coffee b/app/coffee/modules/common/components.coffee index 7bbbab39..22762b9d 100644 --- a/app/coffee/modules/common/components.coffee +++ b/app/coffee/modules/common/components.coffee @@ -163,30 +163,41 @@ WatchersDirective = ($rootscope, $confirm, $repo) -> # # TODO: i18n template = _.template(""" + <% if(isEditable){ %>
watchers
+ <% } else if(watchers.length > 0){ %> +
+ watchers +
+ <% }; %> <% _.each(watchers, function(watcher) { %>
- + <%- watcher.full_name_display %> - +
<%- watcher.full_name_display %> + <% if(isEditable){ %> + <% }; %>
<% }); %> """) link = ($scope, $el, $attrs, $model) -> + isEditable = -> + return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1 + save = (model) -> promise = $repo.save($model.$modelValue) promise.then -> @@ -199,20 +210,20 @@ WatchersDirective = ($rootscope, $confirm, $repo) -> $confirm.notify("error") renderWatchers = (watchers) -> - html = template({watchers: watchers}) + ctx = { + watchers: watchers + isEditable: isEditable() + } + html = template(ctx) $el.html(html) - if watchers.length == 0 + if isEditable() and watchers.length == 0 $el.find(".title").text("Add watchers") $el.find(".watchers-header").addClass("no-watchers") - $scope.$watch $attrs.ngModel, (item) -> - return if not item? - watchers = _.map(item.watchers, (watcherId) -> $scope.usersById[watcherId]) - renderWatchers(watchers) - $el.on "click", ".icon-delete", (event) -> event.preventDefault() + return if not isEditable() target = angular.element(event.currentTarget) watcherId = target.data("watcher-id") @@ -231,6 +242,7 @@ WatchersDirective = ($rootscope, $confirm, $repo) -> $el.on "click", ".add-watcher", (event) -> event.preventDefault() + return if not isEditable() $scope.$apply -> $rootscope.$broadcast("watcher:add", $model.$modelValue) @@ -244,6 +256,11 @@ WatchersDirective = ($rootscope, $confirm, $repo) -> $model.$setViewValue(item) save(item) + $scope.$watch $attrs.ngModel, (item) -> + return if not item? + watchers = _.map(item.watchers, (watcherId) -> $scope.usersById[watcherId]) + renderWatchers(watchers) + $scope.$on "$destroy", -> $el.off() @@ -271,7 +288,7 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) ->
Assigned to - + <% if (assignedTo) { %> <%- assignedTo.full_name_display %> @@ -279,15 +296,18 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) -> Not assigned <% } %> - + <% if(isEditable){ %><% }; %> - <% if (assignedTo!==null) { %> + <% if (assignedTo!==null && isEditable) { %> <% } %>
- """) + """) # TODO: i18n link = ($scope, $el, $attrs, $model) -> + isEditable = -> + return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1 + save = (model) -> $loading.start($el) @@ -304,25 +324,27 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) -> renderAssignedTo = (issue) -> assignedToId = issue?.assigned_to - assignedTo = null - assignedTo = $scope.usersById[assignedToId] if assignedToId? - html = template({assignedTo: assignedTo}) - $el.html(html) + assignedTo = if assignedToId? then $scope.usersById[assignedToId] else null - $scope.$watch $attrs.ngModel, (instance) -> - renderAssignedTo(instance) + ctx = { + assignedTo: assignedTo + isEditable: isEditable() + } + html = template(ctx) + $el.html(html) $el.on "click", ".user-assigned", (event) -> event.preventDefault() + return if not isEditable() $scope.$apply -> $rootscope.$broadcast("assigned-to:add", $model.$modelValue) $el.on "click", ".icon-delete", (event) -> event.preventDefault() - title = "Remove assigned to" - subtitle = "" + return if not isEditable() + title = "Are you sure you want to leave it unassigned?" # TODO: i18n - $confirm.ask(title, subtitle).then (finish) => + $confirm.ask(title).then (finish) => finish() $model.$modelValue.assigned_to = null save($model.$modelValue) @@ -331,6 +353,9 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) -> $model.$modelValue.assigned_to = userId save($model.$modelValue) + $scope.$watch $attrs.ngModel, (instance) -> + renderAssignedTo(instance) + $scope.$on "$destroy", -> $el.off() @@ -339,7 +364,6 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading) -> require:"ngModel" } - module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgLoading", AssignedToDirective]) diff --git a/app/partials/issues-detail.jade b/app/partials/issues-detail.jade index dc88a0eb..c4cdfb72 100644 --- a/app/partials/issues-detail.jade +++ b/app/partials/issues-detail.jade @@ -50,9 +50,9 @@ block content div.duty-data(tg-issue-priority-button, ng-model="issue") div.duty-data(tg-issue-status-button, ng-model="issue") - section.duty-assigned-to(tg-assigned-to, ng-model="issue") + section.duty-assigned-to(tg-assigned-to, ng-model="issue", required-perm="modify_issue") - section.watchers(tg-watchers, ng-model="issue") + section.watchers(tg-watchers, ng-model="issue", required-perm="modify_issue") section.us-detail-settings tg-promote-issue-to-us-button(tg-check-permission="add_us", ng-model="issue") diff --git a/app/partials/task-detail.jade b/app/partials/task-detail.jade index c1a83251..bce0de6c 100644 --- a/app/partials/task-detail.jade +++ b/app/partials/task-detail.jade @@ -50,9 +50,9 @@ block content div.duty-data-container div.duty-data(tg-task-status-button, ng-model="task") - section.duty-assigned-to(tg-assigned-to, ng-model="task") + section.duty-assigned-to(tg-assigned-to, ng-model="task", required-perm="modify_task") - section.watchers(tg-watchers, ng-model="task") + section.watchers(tg-watchers, ng-model="task", required-perm="modify_task") section.us-detail-settings fieldset(tg-task-is-iocaine-button, tg-check-permission="modify_task", ng-model="task") diff --git a/app/partials/us-detail.jade b/app/partials/us-detail.jade index 83b3b5ca..93fe31ce 100644 --- a/app/partials/us-detail.jade +++ b/app/partials/us-detail.jade @@ -55,9 +55,9 @@ block content div.duty-data-container div.duty-data(tg-us-status-button, ng-model="us") - section.duty-assigned-to(tg-assigned-to, ng-model="us") + section.duty-assigned-to(tg-assigned-to, ng-model="us", required-perm="modify_us") - section.watchers(tg-watchers, ng-model="us") + section.watchers(tg-watchers, ng-model="us", required-perm="modify_us") section.us-detail-settings tg-us-team-requirement-button(ng-model="us")