From 9a5d87ef194a2d698d9b2c73eff6610c4808e370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Mon, 13 Oct 2014 18:40:32 +0200 Subject: [PATCH] Refactor of task buttons --- app/coffee/modules/tasks/detail.coffee | 94 ++++++++++++++++++++------ app/partials/issues-detail.jade | 2 + app/partials/task-detail.jade | 5 +- app/partials/us-detail.jade | 2 +- 4 files changed, 80 insertions(+), 23 deletions(-) diff --git a/app/coffee/modules/tasks/detail.coffee b/app/coffee/modules/tasks/detail.coffee index de3b715d..0cd795a5 100644 --- a/app/coffee/modules/tasks/detail.coffee +++ b/app/coffee/modules/tasks/detail.coffee @@ -127,25 +127,6 @@ class TaskDetailController extends mixOf(taiga.Controller, taiga.PageMixin) unblock: -> @rootscope.$broadcast("unblock", @scope.task) - delete: -> - #TODO: i18n - title = "Delete Task" - message = @scope.task.subject - - @confirm.askOnDelete(title, message).then (finish) => - promise = @.repo.remove(@scope.task) - promise.then => - finish() - - if @scope.task.milestone - @location.path(@navUrls.resolve("project-taskboard", {project: @scope.project.slug, sprint: @scope.sprint.slug})) - else if @scope.us - @location.path(@navUrls.resolve("project-userstories-detail", {project: @scope.project.slug, ref: @scope.us.ref})) - - promise.then null, => - finish(false) - @confirm.notify("error") - module.controller("TaskDetailController", TaskDetailController) @@ -273,3 +254,78 @@ TaskStatusDirective = () -> return {link:link, require:"ngModel"} module.directive("tgTaskStatus", TaskStatusDirective) + +TaskButtonsDirective = ($rootscope, $tgrepo, $confirm, $navurls, $location) -> + template = _.template(""" +
+ + +
+ Block + Unblock + <% if (deletePerm) { %> + Delete + <% } %> + """) + + link = ($scope, $el, $attrs, $model) -> + render = _.once (us) -> + deletePerm = $scope.project.my_permissions.indexOf("delete_us") != -1 + html = template({deletePerm: deletePerm}) + $el.html(html) + + refresh = (us) -> + if us?.is_blocked + $el.find('.task-block').hide() + $el.find('.task-unblock').show() + else + $el.find('.task-block').show() + $el.find('.task-unblock').hide() + + if us?.is_iocaine + $el.find('.is-iocaine').addClass('active') + else + $el.find('.is-iocaine').removeClass('active') + + $scope.$watch $attrs.ngModel, (us) -> + return if not us + render(us) + refresh(us) + + $scope.$on "$destroy", -> + $el.off() + + $el.on "click", ".is-iocaine", (event) -> + us = $model.$modelValue.clone() + us.is_iocaine = not us.is_iocaine + $model.$setViewValue(us) + $tgrepo.save($model.$modelValue).then -> + $rootscope.$broadcast("history:reload") + + $el.on "click", ".task-block", (event) -> + $rootscope.$broadcast("block", $model.$modelValue) + + $el.on "click", ".task-unblock", (event) -> + $rootscope.$broadcast("unblock", $model.$modelValue) + + $el.on "click", ".task-delete", (event) -> + #TODO: i18n + title = "Delete Task" + subtitle = $model.$modelValue.subject + + $confirm.ask(title, subtitle).then (finish) => + promise = $tgrepo.remove($model.$modelValue) + promise.then => + finish() + $location.path($navurls.resolve("project-backlog", {project: $scope.project.slug})) + promise.then null, => + finish(false) + $confirm.notify("error") + + return { + link: link + restrict: "EA" + require: "ngModel" + } + +module.directive("tgTaskButtons", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgNavUrls", "$tgLocation", TaskButtonsDirective]) diff --git a/app/partials/issues-detail.jade b/app/partials/issues-detail.jade index 6064630c..08ad02e3 100644 --- a/app/partials/issues-detail.jade +++ b/app/partials/issues-detail.jade @@ -47,6 +47,8 @@ block content section.us-detail-settings tg-promote-issue-to-us-button(ng-model="issue") + a.button.button-gray.clickable(title="Click to block the issue", ng-show="!issue.is_blocked", ng-click="ctrl.block()") Block + a.button.button-red(title="Click to delete the issue", tg-check-permission="delete_issue", ng-click="ctrl.delete()", href="") Delete div.lightbox.lightbox-select-user(tg-lb-assignedto) div.lightbox.lightbox-select-user(tg-lb-watchers) diff --git a/app/partials/task-detail.jade b/app/partials/task-detail.jade index 0d365d6e..375246fd 100644 --- a/app/partials/task-detail.jade +++ b/app/partials/task-detail.jade @@ -49,9 +49,8 @@ block content section.us-status(tg-task-status, ng-model="task") section.us-assigned-to(tg-assigned-to, ng-model="task") section.watchers(tg-watchers, ng-model="task") + section.us-detail-settings(tg-task-buttons, ng-model="task") - section.us-detail-settings - span.button.button-gray(href="", ng-class="{'active': task.is_iocaine }", title="Feeling a bit overwhelmed by a task? Make sure others know about it by clicking on Iocaine when editing a task. It's possible to become immune to this (fictional) deadly poison by consuming small amounts over time just as it's possible to get better at what you do by occasionally taking on extra challenges!") Iocaine - + div.lightbox.lightbox-block.hidden(tg-lb-block, title="Blocking task", ng-model="task") div.lightbox.lightbox-select-user(tg-lb-assignedto) div.lightbox.lightbox-select-user(tg-lb-watchers) diff --git a/app/partials/us-detail.jade b/app/partials/us-detail.jade index d9db1180..ce05d706 100644 --- a/app/partials/us-detail.jade +++ b/app/partials/us-detail.jade @@ -56,6 +56,6 @@ block content section.watchers(tg-watchers, ng-model="us") section.us-detail-settings(tg-us-buttons, ng-model="us") - div.lightbox.lightbox_block.hidden(tg-lb-block, title="Blocking issue", ng-model="us") + div.lightbox.lightbox-block.hidden(tg-lb-block, title="Blocking issue", ng-model="us") div.lightbox.lightbox-select-user.hidden(tg-lb-assignedto) div.lightbox.lightbox-select-user.hidden(tg-lb-watchers)