From 22ec3ca70e6e007fa3d2bd750d1ddf647d25f178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Thu, 9 Oct 2014 18:01:08 +0200 Subject: [PATCH] US #675: Task #1247: Create the button action to call the api --- app/coffee/modules/common/confirm.coffee | 5 +- app/coffee/modules/issues/detail.coffee | 65 ++++++++++++++++++++++-- app/partials/issues-detail.jade | 6 +-- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/app/coffee/modules/common/confirm.coffee b/app/coffee/modules/common/confirm.coffee index a0da50ac..8834066e 100644 --- a/app/coffee/modules/common/confirm.coffee +++ b/app/coffee/modules/common/confirm.coffee @@ -50,12 +50,15 @@ class ConfirmService extends taiga.Service el.off(".confirm-dialog") - ask: (title, subtitle, lightboxSelector=".lightbox_confirm-delete") -> + ask: (title, subtitle, message=null, lightboxSelector=".lightbox_confirm-delete") -> el = angular.element(lightboxSelector) # Render content el.find("h2.title").html(title) el.find("span.subtitle").html(subtitle) + if message + el.find("span.delete-question").html(message) + defered = @q.defer() # Assign event handlers diff --git a/app/coffee/modules/issues/detail.coffee b/app/coffee/modules/issues/detail.coffee index 2d9ae266..78c19e90 100644 --- a/app/coffee/modules/issues/detail.coffee +++ b/app/coffee/modules/issues/detail.coffee @@ -65,9 +65,12 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin) @location.replace() return @q.reject(xhr) - @scope.$on("attachment:create", => @rootscope.$broadcast("history:reload")) - @scope.$on("attachment:edit", => @rootscope.$broadcast("history:reload")) - @scope.$on("attachment:delete", => @rootscope.$broadcast("history:reload")) + @scope.$on "attachment:create", => @rootscope.$broadcast("history:reload") + @scope.$on "attachment:edit", => @rootscope.$broadcast("history:reload") + @scope.$on "attachment:delete", => @rootscope.$broadcast("history:reload") + @scope.$on "promote-issue-to-us:success", => + @rootscope.$broadcast("history:reload") + @.loadIssue() loadProject: -> return @rs.projects.get(@scope.projectId).then (project) => @@ -362,3 +365,59 @@ IssueStatusDirective = () -> return {link:link, require:"ngModel"} module.directive("tgIssueStatus", IssueStatusDirective) + + +############################################################################# +## Promote Issue to US button directive +############################################################################# + +PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm) -> + template = _.template(""" + + Promote to User Story + + """) # TODO: i18n + + link = ($scope, $el, $attrs, $model) -> + $el.on "click", "a", (event) -> + event.preventDefault() + issue = $model.$modelValue + + title = "Promote this issue to a new user story" # TODO: i18n + message = "Are you sure you want to create a new US from this Issue?" # TODO: i18n + subtitle = issue.subject + + $confirm.ask(title, subtitle, message).then (finish) => + data = { + generated_from_issue: issue.id + project: issue.project, + subject: issue.subject + description: issue.description + tags: issue.tags + is_blocked: issue.is_blocked + blocked_note: issue.blocked_note + } + + onSuccess = -> + finish() + $confirm.notify("success") + $rootScope.$broadcast("promote-issue-to-us:success") + + onError = -> + finish(false) + $confirm.notify("error") + + $repo.create("userstories", data).then(onSuccess, onError) + + $scope.$on "$destroy", -> + $el.off() + + return { + restrict: "AE" + require: "ngModel" + template: template + link: link + } + +module.directive("tgPromoteIssueToUsButton", ["$rootScope", "$tgRepo", "$tgConfirm", + PromoteIssueToUsButtonDirective]) diff --git a/app/partials/issues-detail.jade b/app/partials/issues-detail.jade index 19ffe3c9..fba6c3dc 100644 --- a/app/partials/issues-detail.jade +++ b/app/partials/issues-detail.jade @@ -44,8 +44,4 @@ block content section.watchers(tg-watchers, ng-model="issue") section.us-detail-settings - a.button.button-gray.clickable(tg-check-permission="add_us", - ng-click="ctrl.promoteToUs()", href="") Promote to User Story - - div.lightbox.lightbox-generic-form.lb-create-edit-userstory(tg-lb-create-edit-userstory) - include views/modules/lightbox-us-create-edit + tg-promote-issue-to-us-button(ng-model="issue")