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>""") </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,16 +284,14 @@ AssignedToDirective = ($rootscope) ->
</div> </div>
""") """)
renderAssignedTo = ($scope, $el, assignedToId, editable) ->
assignedTo = null
assignedTo = $scope.usersById[assignedToId] if assignedToId?
html = template({assignedTo: assignedTo, 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, (assignedToId) -> $scope.$watch $attrs.ngModel, (assignedToId) ->
renderAssignedTo($scope, $el, assignedToId, editable) assignedTo = null
assignedTo = $scope.usersById[assignedToId] if assignedToId?
html = template({assignedTo: assignedTo, editable:editable})
$el.html(html)
$el.on "click", ".icon-edit", (event) -> $el.on "click", ".icon-edit", (event) ->
event.preventDefault() event.preventDefault()
@ -304,7 +299,9 @@ AssignedToDirective = ($rootscope) ->
$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])