From bfa66bdad437780b02da47414b07cacad5f089d2 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Mon, 7 Jul 2014 12:09:57 +0200 Subject: [PATCH] Removing sprints from backlog --- app/coffee/modules/backlog/lightboxes.coffee | 47 +++++++++++++++++-- app/coffee/modules/backlog/main.coffee | 9 +++- app/partials/backlog.jade | 4 +- ...int.jade => lightbox_add-edit-sprint.jade} | 5 +- 4 files changed, 53 insertions(+), 12 deletions(-) rename app/partials/views/modules/{lightbox_add-sprint.jade => lightbox_add-edit-sprint.jade} (77%) diff --git a/app/coffee/modules/backlog/lightboxes.coffee b/app/coffee/modules/backlog/lightboxes.coffee index f23bfcf1..57d9a071 100644 --- a/app/coffee/modules/backlog/lightboxes.coffee +++ b/app/coffee/modules/backlog/lightboxes.coffee @@ -135,8 +135,9 @@ CreateBulkUserstoriesDirective = ($repo, $rs, $rootscope) -> return {link: link} -CreateSprint = ($repo, $rs, $rootscope) -> +CreateEditSprint = ($repo, $confirm, $rs, $rootscope) -> link = ($scope, $el, attrs) -> + createSprint = true $scope.milestonesCounter = "--" bindOnce $scope, "sprints", (sprints) -> $scope.milestonesCounter = sprints.length @@ -146,17 +147,34 @@ CreateSprint = ($repo, $rs, $rootscope) -> if not form.validate() return - promise = $repo.create("milestones", $scope.sprint) + if createSprint + promise = $repo.create("milestones", $scope.sprint) + else + promise = $repo.save($scope.sprint) + promise.then (data) -> - $scope.milestonesCounter += 1 + if createSprint + $scope.milestonesCounter += 1 + $el.addClass("hidden") $rootscope.$broadcast("sprintform:create:success", data) promise.then null, (data) -> form.setErrors(data) + remove = -> + #TODO: i18n + title = "Delete sprint" + subtitle = $scope.sprint.name + + $confirm.ask(title, subtitle).then => + $repo.remove($scope.sprint).then -> + $scope.milestonesCounter -= 1 + $el.addClass("hidden") + $rootscope.$broadcast("sprintform:remove:success") + $scope.$on "sprintform:create", -> - $el.removeClass("hidden") + createSprint = true $scope.sprint = { project: $scope.projectId name: null @@ -169,6 +187,21 @@ CreateSprint = ($repo, $rs, $rootscope) -> if sprintName? lastSprintNameDom.html(" last sprint is #{sprintName} ;-) ") + $el.find(".delete-sprint").hide() + $el.find(".title").text("New sprint") #TODO i18n + $el.find(".button-green").text("Create") #TODO i18n + $el.removeClass("hidden") + + $scope.$on "sprintform:edit", (ctx, sprint) -> + createSprint = false + $scope.$apply -> + $scope.sprint = sprint + + $el.find(".delete-sprint").show() + $el.find(".title").text("Edit sprint") #TODO i18n + $el.find(".button-green").text("Save") #TODO i18n + $el.removeClass("hidden") + $el.on "click", ".close", (event) -> event.preventDefault() $el.addClass("hidden") @@ -177,6 +210,10 @@ CreateSprint = ($repo, $rs, $rootscope) -> event.preventDefault() submit() + $el.on "click", ".delete-sprint .icon-delete", (event) -> + event.preventDefault() + remove() + $scope.$on "$destroy", -> $el.off() @@ -188,4 +225,4 @@ module.directive("tgLbCreateEditUserstory", ["$tgRepo", "$tgModel", "$tgResource CreateEditUserstoryDirective]) module.directive("tgLbCreateBulkUserstories", ["$tgRepo", "$tgResources", "$rootScope", CreateBulkUserstoriesDirective]) -module.directive("tgLbCreateSprint", ["$tgRepo", "$tgResources", "$rootScope", CreateSprint]) +module.directive("tgLbCreateEditSprint", ["$tgRepo", "$tgConfirm", "$tgResources", "$rootScope", CreateEditSprint]) diff --git a/app/coffee/modules/backlog/main.coffee b/app/coffee/modules/backlog/main.coffee index 59ca14d1..51328648 100644 --- a/app/coffee/modules/backlog/main.coffee +++ b/app/coffee/modules/backlog/main.coffee @@ -57,6 +57,8 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F @scope.$on("usform:bulk:success", @.loadUserstories) @scope.$on("sprintform:create:success", @.loadSprints) @scope.$on("sprintform:create:success", @.loadProjectStats) + @scope.$on("sprintform:remove:success", @.loadSprints) + @scope.$on("sprintform:remove:success", @.loadProjectStats) @scope.$on("usform:new:success", @.loadUserstories) @scope.$on("usform:edit:success", @.loadUserstories) @@ -402,7 +404,7 @@ BacklogDirective = ($repo, $rootscope) -> ## Sprint Directive ############################################################################# -BacklogSprintDirective = ($repo) -> +BacklogSprintDirective = ($repo, $rootscope) -> ######################### ## Common parts @@ -430,6 +432,9 @@ BacklogSprintDirective = ($repo) -> target.toggleClass('active') $el.find(".sprint-table").toggleClass('open') + $el.on "click", ".sprint-name > .icon-edit", (event) -> + $rootscope.$broadcast("sprintform:edit", sprint) + ######################### ## Drag & Drop Link ######################### @@ -819,7 +824,7 @@ GmBacklogGraphDirective = -> module.directive("tgBacklog", ["$tgRepo", "$rootScope", BacklogDirective]) -module.directive("tgBacklogSprint", ["$tgRepo", BacklogSprintDirective]) +module.directive("tgBacklogSprint", ["$tgRepo", "$rootScope", BacklogSprintDirective]) module.directive("tgUsPoints", ["$tgRepo", UsPointsDirective]) module.directive("tgUsRolePointsSelector", ["$rootScope", UsRolePointsSelectorDirective]) module.directive("tgGmBacklogGraph", GmBacklogGraphDirective) diff --git a/app/partials/backlog.jade b/app/partials/backlog.jade index e22885bd..362fa043 100644 --- a/app/partials/backlog.jade +++ b/app/partials/backlog.jade @@ -32,5 +32,5 @@ block content include views/modules/lightbox_add-new-us div.lightbox.lightbox_add-bulk.hidden(tg-lb-create-bulk-userstories) include views/modules/lightbox_add-bulk - div.lightbox.lightbox_add-sprint.hidden(tg-lb-create-sprint) - include views/modules/lightbox_add-sprint + div.lightbox.lightbox_add-sprint.hidden(tg-lb-create-edit-sprint) + include views/modules/lightbox_add-edit-sprint diff --git a/app/partials/views/modules/lightbox_add-sprint.jade b/app/partials/views/modules/lightbox_add-edit-sprint.jade similarity index 77% rename from app/partials/views/modules/lightbox_add-sprint.jade rename to app/partials/views/modules/lightbox_add-edit-sprint.jade index 64058796..ae3441db 100644 --- a/app/partials/views/modules/lightbox_add-sprint.jade +++ b/app/partials/views/modules/lightbox_add-edit-sprint.jade @@ -10,6 +10,5 @@ form input.date-end(tg-date-selector, ng-model="sprint.estimated_finish", type="text", placeholder="Estimated End", data-required="true") a.button.button-green(href="", title="Save") span Create - //-Should be only visible when in editable lightbox - span.delete-sprint Do you want to delete this sprint? - a.icon.icon-delete(href="", title="delete sprint") + span.delete-sprint.hidden Do you want to delete this sprint? + a.icon.icon-delete(href="", title="delete sprint")