-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.min.js
More file actions
1 lines (1 loc) · 2.46 KB
/
tree.min.js
File metadata and controls
1 lines (1 loc) · 2.46 KB
1
"use strict";var app=angular.module("90TechSAS.angular-tree",[]);app.directive("zlTreeRow",["$compile",function($compile){return{restrict:"A",scope:{elt:"=zlTreeRoot",loadFunction:"&",toggled:"=toggle",depth:"=",zlSelected:"=",idField:"@",selectCallback:"&"},controller:["$scope",function($scope){function extractChildrenIds(elt){return _.map(elt.children,function(c){return"object"==typeof c?c[idField]:c})}$scope.zlSelected=$scope.zlSelected,$scope.depth=$scope.depth||0;var idField=$scope.idField||"id";$scope.checkme=function(elt){return $scope.zlSelected?void(_.contains($scope.zlSelected,elt[idField])?_.pull($scope.zlSelected,elt[idField]):($scope.zlSelected.push(elt[idField]),$scope.selectCallback&&$scope.selectCallback({$elt:elt}))):void($scope.selectCallback&&$scope.selectCallback({$elt:elt}))},$scope.checked=function(elt){return $scope.zlSelected?_.contains($scope.zlSelected,elt[idField]):void 0},$scope.addChildren=function(elt){$scope.zlSelected=_.union($scope.zlSelected,extractChildrenIds(elt))},$scope.removeChildren=function(elt){$scope.zlSelected=_.difference($scope.zlSelected,extractChildrenIds(elt))},$scope.loadChildren=function(){$scope.loadFunction({$id:$scope.elt.children,$parent:$scope.elt}).then(function(data){$scope.children=data,$scope.elt.children=_.pluck(data,idField),$scope.loading=!1})},$scope.toggleMe=function(){return $scope.elt.children.length?($scope.toggle=!$scope.toggle,void($scope.toggle&&!$scope.children&&($scope.loading=!0,$scope.loadChildren()))):void $scope.checkme($scope.elt)}}],compile:function(elt){var colspan=_.filter(elt.children(),"tagName","TD").length+1;return{post:function(scope,element){var tplte='<tr ng-if="toggled" ng-click="checkme(elt)" ng-class="{\'checked\': checked(elt)}"class="depth-'+scope.depth+'"><td ng-click="toggleMe(); $event.stopImmediatePropagation()"><button class="zl-tree-toggle-button" ng-class="{\'open\': toggle}" ng-if="elt.children.length"></button><div class="zl-tree-no-children" ng-if="!elt.children.length"></div></td>'+elt.html()+'</tr><tr ng-if="loading"><td style="text-align:center;" colspan="'+colspan+'"><div class="zl-tree-loading"></div></td></tr><tr ng-repeat="child in children" zl-tree-row zl-tree-root="child" load-function="loadFunction({$id: $id, $parent: $parent})" depth="depth+1"zl-selected="zlSelected"id-field="{{idField}}"toggle="!loading && toggled && toggle"select-callback="selectCallback({$elt: $elt})">'+elt.html();$compile(tplte)(scope,function(clone){element.replaceWith(clone)})}}}}}]);