Refactoring issue detail

stable
Alejandro Alonso 2014-07-03 12:54:47 +02:00
parent 816b489c30
commit eedc73e8f8
1 changed files with 13 additions and 16 deletions

View File

@ -219,15 +219,12 @@ WatchersDirective = ($rootscope, $confirm) ->
<% }); %>
</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) ->
editable = $attrs.editable?
$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
$el.find(".add-watcher").remove()
@ -263,7 +260,7 @@ module.directive("tgWatchers", ["$rootScope", "$tgConfirm", WatchersDirective])
## Assigned to directive
#############################################################################
AssignedToDirective = ($rootscope) ->
AssignedToDirective = ($rootscope, $confirm) ->
#TODO: i18n
template = _.template("""
<% if (assignedTo) { %>
@ -287,24 +284,24 @@ AssignedToDirective = ($rootscope) ->
</div>
""")
renderAssignedTo = ($scope, $el, assignedToId, editable) ->
link = ($scope, $el, $attrs, $model) ->
editable = $attrs.editable?
$scope.$watch $attrs.ngModel, (assignedToId) ->
assignedTo = null
assignedTo = $scope.usersById[assignedToId] if assignedToId?
html = template({assignedTo: assignedTo, editable:editable})
$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) ->
event.preventDefault()
$rootscope.$broadcast("assigned-to:add")
$el.on "click", ".icon-delete", (event) ->
event.preventDefault()
$scope.$apply ->
title = "Remove assigned to"
subtitle = ""
$confirm.ask(title, subtitle).then =>
$model.$setViewValue(null)
$scope.$on "assigned-to:added", (ctx, user) ->
@ -314,4 +311,4 @@ AssignedToDirective = ($rootscope) ->
return {link:link, require:"ngModel"}
module.directive("tgAssignedTo", ["$rootScope", AssignedToDirective])
module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", AssignedToDirective])