diff --git a/app/coffee/modules/common/lightboxes.coffee b/app/coffee/modules/common/lightboxes.coffee
index b75e280d..ff5b6298 100644
--- a/app/coffee/modules/common/lightboxes.coffee
+++ b/app/coffee/modules/common/lightboxes.coffee
@@ -194,20 +194,83 @@ module.directive("tgBlockingMessageInput", ["$log", BlockingMessageInputDirectiv
#############################################################################
CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService, $loading) ->
+ usPointsTemplate = _.template("""
+
+ -
+ <%- totalPoints %>
+ total
+
+ <% _.each(rolePoints, function(rolePoint) { %>
+ -
+ <%- rolePoint.points %>
+ <%- rolePoint.name %>
+ <% }); %>
+
+ """)
+
+ selectionPointsTemplate = _.template("""
+
+ """)
+
+
link = ($scope, $el, attrs) ->
isNew = true
+ renderUSPoints = () ->
+ totalPoints = $scope.us.total_points or 0
+ rolePoints = _.clone(_.filter($scope.project.roles, "computable"), true)
+ _.map rolePoints, (v, k) ->
+ val = $scope.pointsById[$scope.us.points[v.id]]?.name
+ val = $scope.pointsById[$scope.project.default_points]?.name if not val
+ val = "#" if not val
+ v.points = val
+
+ html = usPointsTemplate({
+ totalPoints: totalPoints
+ rolePoints: rolePoints
+ })
+
+ $el.find("fieldset.estimation").html(html)
+
+ renderSelectPoints = (roleId, onCloseCallback) ->
+ html = selectionPointsTemplate({
+ roleId: roleId
+ points: $scope.project.points
+ })
+ $el.find(".pop-points-open").remove()
+ $el.find(".points-per-role").append(html)
+ $el.find(".pop-points-open a[data-point-id='#{$scope.us.points[roleId]}']").addClass("active")
+ # If not showing role selection let's move to the left
+ $el.find(".pop-points-open").popover().open(onCloseCallback)
+
+ calculateTotalPoints = ->
+ values = _.map($scope.us.points, (v, k) -> $scope.pointsById[v]?.value or 0)
+ if values.length == 0
+ return "0"
+
+ return _.reduce(values, (acc, num) -> acc + num)
+
$scope.$on "usform:new", (ctx, projectId, status, statusList) ->
+ isNew = true
$scope.usStatusList = statusList
$scope.us = {
project: projectId
+ points : {}
status: status
is_archived: false
tags: []
}
- isNew = true
+ # Show role points
+ renderUSPoints()
+
# Update texts for creation
$el.find(".button-green span").html("Create") #TODO: i18n
$el.find(".title").html("New user story ") #TODO: i18n
@@ -222,6 +285,10 @@ CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService,
$scope.$on "usform:edit", (ctx, us) ->
$scope.us = us
isNew = false
+
+ # Show role points
+ renderUSPoints()
+
# Update texts for edition
$el.find(".button-green span").html("Save") #TODO: i18n
$el.find(".title").html("Edit user story ") #TODO: i18n
@@ -245,6 +312,34 @@ CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService,
lightboxService.open($el)
+ $el.on "click", ".total.clickable", (event) ->
+ event.preventDefault()
+ event.stopPropagation()
+ target = angular.element(event.currentTarget)
+
+ roleId = target.data("role-id")
+
+ target.siblings().removeClass('active')
+ target.addClass('active')
+ renderSelectPoints(roleId, () -> target.removeClass('active'))
+
+ $el.on "click", ".point", (event) ->
+ event.preventDefault()
+ event.stopPropagation()
+
+ target = angular.element(event.currentTarget)
+ roleId = target.data("role-id")
+ pointId = target.data("point-id")
+
+ $.fn.popover().closeAll()
+
+ $scope.$apply () ->
+ usPoints = _.clone($scope.us.points, true)
+ usPoints[roleId] = pointId
+ $scope.us.points = usPoints
+ $scope.us.total_points = calculateTotalPoints()
+ renderUSPoints()
+
$el.on "click", ".button-green", (event) ->
event.preventDefault()
form = $el.find("form").checksley()
@@ -254,6 +349,7 @@ CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService,
return
$loading.start(target)
+
if isNew
promise = $repo.create("userstories", $scope.us)
broadcastEvent = "usform:new:success"
diff --git a/app/partials/views/modules/lightbox-us-create-edit.jade b/app/partials/views/modules/lightbox-us-create-edit.jade
index 377a068d..9e189700 100644
--- a/app/partials/views/modules/lightbox-us-create-edit.jade
+++ b/app/partials/views/modules/lightbox-us-create-edit.jade
@@ -5,25 +5,14 @@ form
fieldset
input(type="text", name="subject", ng-model="us.subject", tg-i18n="placeholder:common.subject",
data-required="true", data-maxlength="500")
- // Add estimation points
+
fieldset.estimation
- ul.points-per-role
- li.total
- span.points 40
- span.role UX
- li.total
- span.points 30
- span.role Front
- li.total
- span.points 20
- span.role Design
- li.total
- span.points 10
- span.role Back
- // Remove status input
- //-fieldset
- //- select(name="status", ng-model="us.status", ng-options="s.id as s.name for s in usStatusList",
- //- tg-i18n="placeholder:common.status")
+ //- Render by tg-lb-create-edit-userstory
+
+ fieldset
+ select(name="status", ng-model="us.status", ng-options="s.id as s.name for s in usStatusList",
+ tg-i18n="placeholder:common.status")
+
fieldset
div(tg-tag-line, editable="true", ng-model="us.tags")