Remove the responsability of save from assigned to lightbox directive.

stable
Andrey Antukh 2014-07-23 13:30:03 +02:00
parent afbab5d966
commit 530766d245
3 changed files with 14 additions and 26 deletions

View File

@ -236,12 +236,14 @@ AssignedToDirective = ($rootscope, $confirm) ->
event.preventDefault()
title = "Remove assigned to"
subtitle = ""
$confirm.ask(title, subtitle).then =>
$model.$modelValue.assigned_to = null
renderAssignedTo($model.$modelValue)
$scope.$on "assigned-to:added", (ctx, issue) ->
renderAssignedTo(issue)
$scope.$on "assigned-to:added", (ctx, userId) ->
$model.$modelValue.assigned_to = userId
renderAssignedTo($model.$modelValue)
return {
link:link,

View File

@ -242,7 +242,7 @@ usersTemplate = _.template("""
<% } %>
""")
AssignedToLightboxDirective = ($repo) ->
AssignedToLightboxDirective = ->
link = ($scope, $el, $attrs) ->
selectedUser = null
selectedItem = null
@ -269,7 +269,6 @@ AssignedToLightboxDirective = ($repo) ->
$el.find("div.watchers").html(html)
$scope.$on "assigned-to:add", (ctx, item) ->
console.log $scope.usersSearch
selectedItem = item
assignedToId = item.assigned_to
selectedUser = $scope.usersById[assignedToId]
@ -285,32 +284,16 @@ AssignedToLightboxDirective = ($repo) ->
target = angular.element(event.currentTarget)
$el.addClass("hidden")
if not selectedItem?
return
selectedItem.assigned_to = target.data("user-id")
$scope.$apply ->
promise = $repo.save(selectedItem)
promise.then ->
$scope.$broadcast("assigned-to:added", selectedItem)
promise.then null, ->
console.log "FAIL" # TODO
$scope.$broadcast("assigned-to:added", target.data("user-id"), selectedItem)
$el.on "click", ".remove-assigned-to", (event) ->
event.preventDefault()
event.stopPropagation()
$el.addClass("hidden")
if not selectedItem?
return
selectedItem.assigned_to = null
$scope.$apply ->
promise = $repo.save(selectedItem)
promise.then ->
$scope.$broadcast("assigned-to:added", selectedItem)
promise.then null, ->
console.log "FAIL" # TODO
$scope.$broadcast("assigned-to:added", null, selectedItem)
$el.on "click", ".close", (event) ->
event.preventDefault()
@ -325,7 +308,7 @@ AssignedToLightboxDirective = ($repo) ->
}
module.directive("tgLbAssignedto", ["$tgRepo", AssignedToLightboxDirective])
module.directive("tgLbAssignedto", AssignedToLightboxDirective)
#############################################################################
@ -367,7 +350,6 @@ WatchersLightboxDirective = ($repo) ->
# $scope.filteredUsers = _.difference($scope.users, watchers)
$scope.$on "watcher:add", (ctx, item) ->
console.log "JKAJA", item
selectedItem = item
users = getFilteredUsers()

View File

@ -59,10 +59,14 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
@scope.$on("taskform:bulk:success", => @.loadTaskboard())
@scope.$on("taskform:new:success", => @.loadTaskboard())
@scope.$on("taskform:edit:success", => @.loadTaskboard())
@scope.$on("assigned-to:added", (ctx, task) => @scope.$apply(=> @repo.save(task)))
@scope.$on("taskboard:task:move", @.taskMove)
@scope.$on "assigned-to:added", (ctx, userId, task) =>
task.assigned_to = userId
promise = @repo.save(task)
promise.then null, ->
console.log "FAIL" # TODO
loadSprintStats: ->
return @rs.sprints.stats(@scope.projectId, @scope.sprintId).then (stats) =>
totalPointsSum =_.reduce(_.values(stats.total_points), ((res, n) -> res + n), 0)