From 36ec352fc5fc5037875786ae3f7d4a7c93962aae Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 7 Aug 2014 08:37:24 +0200 Subject: [PATCH] limiting drag&drop in backlog according to permissions --- app/coffee/modules/backlog/main.coffee | 3 +- app/coffee/modules/backlog/sortable.coffee | 99 ++++++++++++---------- 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/app/coffee/modules/backlog/main.coffee b/app/coffee/modules/backlog/main.coffee index 3348a839..560710e7 100644 --- a/app/coffee/modules/backlog/main.coffee +++ b/app/coffee/modules/backlog/main.coffee @@ -27,6 +27,7 @@ scopeDefer = @.taiga.scopeDefer bindOnce = @.taiga.bindOnce groupBy = @.taiga.groupBy textToColor = @.taiga.textToColor +bindOnce = @.taiga.bindOnce module = angular.module("taigaBacklog") @@ -707,7 +708,7 @@ UsPointsDirective = ($repo) -> $repo.refresh(us).then -> $ctrl.loadProjectStats() - taiga.bindOnce $scope, "project", (project) -> + bindOnce $scope, "project", (project) -> # If the user has not enough permissions the click events are unbinded if project.my_permissions.indexOf("modify_us") == -1 $el.unbind("click") diff --git a/app/coffee/modules/backlog/sortable.coffee b/app/coffee/modules/backlog/sortable.coffee index ec1b55cd..b871ffcb 100644 --- a/app/coffee/modules/backlog/sortable.coffee +++ b/app/coffee/modules/backlog/sortable.coffee @@ -46,40 +46,44 @@ BacklogSortableDirective = ($repo, $rs, $rootscope) -> # helper-in-wrong-place-when-scrolled-down-page link = ($scope, $el, $attrs) -> - $el.sortable({ - connectWith: ".sprint-table" - handle: ".icon-drag-v", - containment: ".wrapper" - dropOnEmpty: true - placeholder: "row us-item-row us-item-drag sortable-placeholder" - # With scroll activated, it has strange behavior - # with not full screen browser window. - scroll: false - # A consequence of length of backlog user story item - # the default tolerance ("intersection") not works properly. - tolerance: "pointer" - # Revert on backlog is disabled bacause it works bad. Something - # on the current taiga backlog structure or style makes jquery ui - # works unexpectly (in some circumstances calculates wrong - # position for revert). - revert: false - }) + bindOnce $scope, "project", (project) -> + # If the user has not enough permissions we don't enable the sortable + if project.my_permissions.indexOf("modify_us") > -1 - $el.on "sortreceive", (event, ui) -> - itemUs = ui.item.scope().us - itemIndex = ui.item.index() + $el.sortable({ + connectWith: ".sprint-table" + handle: ".icon-drag-v", + containment: ".wrapper" + dropOnEmpty: true + placeholder: "row us-item-row us-item-drag sortable-placeholder" + # With scroll activated, it has strange behavior + # with not full screen browser window. + scroll: false + # A consequence of length of backlog user story item + # the default tolerance ("intersection") not works properly. + tolerance: "pointer" + # Revert on backlog is disabled bacause it works bad. Something + # on the current taiga backlog structure or style makes jquery ui + # works unexpectly (in some circumstances calculates wrong + # position for revert). + revert: false + }) - deleteElement(ui.item) - $scope.$emit("sprint:us:move", itemUs, itemIndex, null) + $el.on "sortreceive", (event, ui) -> + itemUs = ui.item.scope().us + itemIndex = ui.item.index() - $el.on "sortstop", (event, ui) -> - # When parent not exists, do nothing - if ui.item.parent().length == 0 - return + deleteElement(ui.item) + $scope.$emit("sprint:us:move", itemUs, itemIndex, null) - itemUs = ui.item.scope().us - itemIndex = ui.item.index() - $scope.$emit("sprint:us:move", itemUs, itemIndex, null) + $el.on "sortstop", (event, ui) -> + # When parent not exists, do nothing + if ui.item.parent().length == 0 + return + + itemUs = ui.item.scope().us + itemIndex = ui.item.index() + $scope.$emit("sprint:us:move", itemUs, itemIndex, null) $scope.$on "$destroy", -> $el.off() @@ -89,27 +93,30 @@ BacklogSortableDirective = ($repo, $rs, $rootscope) -> SprintSortableDirective = ($repo, $rs, $rootscope) -> link = ($scope, $el, $attrs) -> - $el.sortable({ - dropOnEmpty: true - connectWith: ".sprint-table,.backlog-table-body" - }) + bindOnce $scope, "project", (project) -> + # If the user has not enough permissions we don't enable the sortable + if project.my_permissions.indexOf("modify_us") > -1 + $el.sortable({ + dropOnEmpty: true + connectWith: ".sprint-table,.backlog-table-body" + }) - $el.on "sortreceive", (event, ui) -> - itemUs = ui.item.scope().us - itemIndex = ui.item.index() + $el.on "sortreceive", (event, ui) -> + itemUs = ui.item.scope().us + itemIndex = ui.item.index() - deleteElement(ui.item) - $scope.$emit("sprint:us:move", itemUs, itemIndex, $scope.sprint.id) + deleteElement(ui.item) + $scope.$emit("sprint:us:move", itemUs, itemIndex, $scope.sprint.id) - $el.on "sortstop", (event, ui) -> - # When parent not exists, do nothing - if ui.item.parent().length == 0 - return + $el.on "sortstop", (event, ui) -> + # When parent not exists, do nothing + if ui.item.parent().length == 0 + return - itemUs = ui.item.scope().us - itemIndex = ui.item.index() + itemUs = ui.item.scope().us + itemIndex = ui.item.index() - $scope.$emit("sprint:us:move", itemUs, itemIndex, $scope.sprint.id) + $scope.$emit("sprint:us:move", itemUs, itemIndex, $scope.sprint.id) return {link:link}