From 50bc2c27a815b4578cb1d1064b480a76629c1fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Thu, 2 Oct 2014 19:26:13 +0200 Subject: [PATCH] Catch destroy event in some directives --- app/coffee/modules/kanban/main.coffee | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/coffee/modules/kanban/main.coffee b/app/coffee/modules/kanban/main.coffee index ae487649..0efb39ad 100644 --- a/app/coffee/modules/kanban/main.coffee +++ b/app/coffee/modules/kanban/main.coffee @@ -257,13 +257,16 @@ module.controller("KanbanController", KanbanController) KanbanDirective = ($repo, $rootscope) -> link = ($scope, $el, $attrs) -> - tableBodyDom = $el.find(".kanban-table-body") + tableBodyDom.on "scroll", (event) -> target = angular.element(event.currentTarget) tableHeaderDom = $el.find(".kanban-table-header .kanban-table-inner") tableHeaderDom.css("left", -1 * target.scrollLeft()) + $scope.$on "$destroy", -> + $el.off() + return {link: link} module.directive("tgKanban", ["$tgRepo", "$rootScope", KanbanDirective]) @@ -280,10 +283,14 @@ KanbanRowWidthFixerDirective = -> size = (statuses.length * itemSize) - 10 $el.css("width", "#{size}px") + $scope.$on "$destroy", -> + $el.off() + return {link: link} module.directive("tgKanbanRowWidthFixer", KanbanRowWidthFixerDirective) + ############################################################################# ## Kanban Column Height Fixer Directive ############################################################################# @@ -301,6 +308,9 @@ KanbanColumnHeightFixerDirective = -> link = ($scope, $el, $attrs) -> timeout(500, -> renderSize($el)) + $scope.$on "$destroy", -> + $el.off() + return {link:link} @@ -312,14 +322,19 @@ module.directive("tgKanbanColumnHeightFixer", KanbanColumnHeightFixerDirective) KanbanUserstoryDirective = ($rootscope) -> link = ($scope, $el, $attrs, $model) -> + $el.disableSelection() + $el.find(".icon-edit").on "click", (event) -> if $el.find(".icon-edit").hasClass("noclick") return + $scope.$apply -> $rootscope.$broadcast("usform:edit", $model.$modelValue) if $scope.us.is_blocked $el.addClass("blocked") - $el.disableSelection() + + $scope.$on "$destroy", -> + $el.off() return { templateUrl: "/partials/views/components/kanban-task.html" @@ -327,7 +342,6 @@ KanbanUserstoryDirective = ($rootscope) -> require: "ngModel" } - module.directive("tgKanbanUserstory", ["$rootScope", KanbanUserstoryDirective]) @@ -351,6 +365,9 @@ KanbanWipLimitDirective = -> $scope.$on "usform:new:success", redrawWipLimit $scope.$on "usform:bulk:success", redrawWipLimit + $scope.$on "$destroy", -> + $el.off() + return {link: link} module.directive("tgKanbanWipLimit", KanbanWipLimitDirective) @@ -412,7 +429,9 @@ KanbanUserDirective = ($log) -> $ctrl = $el.controller() $ctrl.changeUsAssignedTo(us) + $scope.$on "$destroy", -> + $el.off() + return {link: link, require:"ngModel"} - module.directive("tgKanbanUserAvatar", ["$log", KanbanUserDirective])