Refactoring issue detail
parent
816b489c30
commit
eedc73e8f8
|
@ -219,15 +219,12 @@ WatchersDirective = ($rootscope, $confirm) ->
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</div>""")
|
</div>""")
|
||||||
|
|
||||||
renderWatchers = ($scope, $el, watcherIds, editable) ->
|
|
||||||
watchers = _.map(watcherIds, (watcherId) -> $scope.usersById[watcherId])
|
|
||||||
html = template({watchers: watchers, editable:editable})
|
|
||||||
$el.html(html)
|
|
||||||
|
|
||||||
link = ($scope, $el, $attrs, $model) ->
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
editable = $attrs.editable?
|
editable = $attrs.editable?
|
||||||
$scope.$watch $attrs.ngModel, (watcherIds) ->
|
$scope.$watch $attrs.ngModel, (watcherIds) ->
|
||||||
renderWatchers($scope, $el, watcherIds, editable)
|
watchers = _.map(watcherIds, (watcherId) -> $scope.usersById[watcherId])
|
||||||
|
html = template({watchers: watchers, editable:editable})
|
||||||
|
$el.html(html)
|
||||||
|
|
||||||
if not editable
|
if not editable
|
||||||
$el.find(".add-watcher").remove()
|
$el.find(".add-watcher").remove()
|
||||||
|
@ -263,7 +260,7 @@ module.directive("tgWatchers", ["$rootScope", "$tgConfirm", WatchersDirective])
|
||||||
## Assigned to directive
|
## Assigned to directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
AssignedToDirective = ($rootscope) ->
|
AssignedToDirective = ($rootscope, $confirm) ->
|
||||||
#TODO: i18n
|
#TODO: i18n
|
||||||
template = _.template("""
|
template = _.template("""
|
||||||
<% if (assignedTo) { %>
|
<% if (assignedTo) { %>
|
||||||
|
@ -287,24 +284,24 @@ AssignedToDirective = ($rootscope) ->
|
||||||
</div>
|
</div>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
renderAssignedTo = ($scope, $el, assignedToId, editable) ->
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
|
editable = $attrs.editable?
|
||||||
|
|
||||||
|
$scope.$watch $attrs.ngModel, (assignedToId) ->
|
||||||
assignedTo = null
|
assignedTo = null
|
||||||
assignedTo = $scope.usersById[assignedToId] if assignedToId?
|
assignedTo = $scope.usersById[assignedToId] if assignedToId?
|
||||||
html = template({assignedTo: assignedTo, editable:editable})
|
html = template({assignedTo: assignedTo, editable:editable})
|
||||||
$el.html(html)
|
$el.html(html)
|
||||||
|
|
||||||
link = ($scope, $el, $attrs, $model) ->
|
|
||||||
editable = $attrs.editable?
|
|
||||||
$scope.$watch $attrs.ngModel, (assignedToId) ->
|
|
||||||
renderAssignedTo($scope, $el, assignedToId, editable)
|
|
||||||
|
|
||||||
$el.on "click", ".icon-edit", (event) ->
|
$el.on "click", ".icon-edit", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
$rootscope.$broadcast("assigned-to:add")
|
$rootscope.$broadcast("assigned-to:add")
|
||||||
|
|
||||||
$el.on "click", ".icon-delete", (event) ->
|
$el.on "click", ".icon-delete", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
$scope.$apply ->
|
title = "Remove assigned to"
|
||||||
|
subtitle = ""
|
||||||
|
$confirm.ask(title, subtitle).then =>
|
||||||
$model.$setViewValue(null)
|
$model.$setViewValue(null)
|
||||||
|
|
||||||
$scope.$on "assigned-to:added", (ctx, user) ->
|
$scope.$on "assigned-to:added", (ctx, user) ->
|
||||||
|
@ -314,4 +311,4 @@ AssignedToDirective = ($rootscope) ->
|
||||||
|
|
||||||
return {link:link, require:"ngModel"}
|
return {link:link, require:"ngModel"}
|
||||||
|
|
||||||
module.directive("tgAssignedTo", ["$rootScope", AssignedToDirective])
|
module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", AssignedToDirective])
|
||||||
|
|
Loading…
Reference in New Issue