Catch destroy event in some directives

stable
David Barragán Merino 2014-10-02 19:26:13 +02:00
parent 33d723f4ec
commit 50bc2c27a8
1 changed files with 23 additions and 4 deletions

View File

@ -257,13 +257,16 @@ module.controller("KanbanController", KanbanController)
KanbanDirective = ($repo, $rootscope) -> KanbanDirective = ($repo, $rootscope) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
tableBodyDom = $el.find(".kanban-table-body") tableBodyDom = $el.find(".kanban-table-body")
tableBodyDom.on "scroll", (event) -> tableBodyDom.on "scroll", (event) ->
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
tableHeaderDom = $el.find(".kanban-table-header .kanban-table-inner") tableHeaderDom = $el.find(".kanban-table-header .kanban-table-inner")
tableHeaderDom.css("left", -1 * target.scrollLeft()) tableHeaderDom.css("left", -1 * target.scrollLeft())
$scope.$on "$destroy", ->
$el.off()
return {link: link} return {link: link}
module.directive("tgKanban", ["$tgRepo", "$rootScope", KanbanDirective]) module.directive("tgKanban", ["$tgRepo", "$rootScope", KanbanDirective])
@ -280,10 +283,14 @@ KanbanRowWidthFixerDirective = ->
size = (statuses.length * itemSize) - 10 size = (statuses.length * itemSize) - 10
$el.css("width", "#{size}px") $el.css("width", "#{size}px")
$scope.$on "$destroy", ->
$el.off()
return {link: link} return {link: link}
module.directive("tgKanbanRowWidthFixer", KanbanRowWidthFixerDirective) module.directive("tgKanbanRowWidthFixer", KanbanRowWidthFixerDirective)
############################################################################# #############################################################################
## Kanban Column Height Fixer Directive ## Kanban Column Height Fixer Directive
############################################################################# #############################################################################
@ -301,6 +308,9 @@ KanbanColumnHeightFixerDirective = ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
timeout(500, -> renderSize($el)) timeout(500, -> renderSize($el))
$scope.$on "$destroy", ->
$el.off()
return {link:link} return {link:link}
@ -312,14 +322,19 @@ module.directive("tgKanbanColumnHeightFixer", KanbanColumnHeightFixerDirective)
KanbanUserstoryDirective = ($rootscope) -> KanbanUserstoryDirective = ($rootscope) ->
link = ($scope, $el, $attrs, $model) -> link = ($scope, $el, $attrs, $model) ->
$el.disableSelection()
$el.find(".icon-edit").on "click", (event) -> $el.find(".icon-edit").on "click", (event) ->
if $el.find(".icon-edit").hasClass("noclick") if $el.find(".icon-edit").hasClass("noclick")
return return
$scope.$apply -> $scope.$apply ->
$rootscope.$broadcast("usform:edit", $model.$modelValue) $rootscope.$broadcast("usform:edit", $model.$modelValue)
if $scope.us.is_blocked if $scope.us.is_blocked
$el.addClass("blocked") $el.addClass("blocked")
$el.disableSelection()
$scope.$on "$destroy", ->
$el.off()
return { return {
templateUrl: "/partials/views/components/kanban-task.html" templateUrl: "/partials/views/components/kanban-task.html"
@ -327,7 +342,6 @@ KanbanUserstoryDirective = ($rootscope) ->
require: "ngModel" require: "ngModel"
} }
module.directive("tgKanbanUserstory", ["$rootScope", KanbanUserstoryDirective]) module.directive("tgKanbanUserstory", ["$rootScope", KanbanUserstoryDirective])
@ -351,6 +365,9 @@ KanbanWipLimitDirective = ->
$scope.$on "usform:new:success", redrawWipLimit $scope.$on "usform:new:success", redrawWipLimit
$scope.$on "usform:bulk:success", redrawWipLimit $scope.$on "usform:bulk:success", redrawWipLimit
$scope.$on "$destroy", ->
$el.off()
return {link: link} return {link: link}
module.directive("tgKanbanWipLimit", KanbanWipLimitDirective) module.directive("tgKanbanWipLimit", KanbanWipLimitDirective)
@ -412,7 +429,9 @@ KanbanUserDirective = ($log) ->
$ctrl = $el.controller() $ctrl = $el.controller()
$ctrl.changeUsAssignedTo(us) $ctrl.changeUsAssignedTo(us)
$scope.$on "$destroy", ->
$el.off()
return {link: link, require:"ngModel"} return {link: link, require:"ngModel"}
module.directive("tgKanbanUserAvatar", ["$log", KanbanUserDirective]) module.directive("tgKanbanUserAvatar", ["$log", KanbanUserDirective])