angular-ui-tree
Version:
An AngularJS UI component that can sort nested lists, provides drag & drop support and doesn't depend on jQuery
60 lines (50 loc) • 1.86 kB
JavaScript
(function () {
'use strict';
angular.module('ui.tree')
.controller('TreeController', ['$scope', '$element',
function ($scope, $element) {
this.scope = $scope;
$scope.$element = $element;
$scope.$nodesScope = null; // root nodes
$scope.$type = 'uiTree';
$scope.$emptyElm = null;
$scope.$dropzoneElm = null;
$scope.$callbacks = null;
$scope.dragEnabled = true;
$scope.emptyPlaceholderEnabled = true;
$scope.maxDepth = 0;
$scope.dragDelay = 0;
$scope.cloneEnabled = false;
$scope.nodropEnabled = false;
$scope.dropzoneEnabled = false;
// Check if it's a empty tree
$scope.isEmpty = function () {
return ($scope.$nodesScope && $scope.$nodesScope.$modelValue
&& $scope.$nodesScope.$modelValue.length === 0);
};
// add placeholder to empty tree
$scope.place = function (placeElm) {
$scope.$nodesScope.$element.append(placeElm);
$scope.$emptyElm.remove();
};
this.resetEmptyElement = function () {
if ((!$scope.$nodesScope.$modelValue || $scope.$nodesScope.$modelValue.length === 0) &&
$scope.emptyPlaceholderEnabled) {
$element.append($scope.$emptyElm);
} else {
$scope.$emptyElm.remove();
}
};
this.resetDropzoneElement = function () {
if ((!$scope.$nodesScope.$modelValue || $scope.$nodesScope.$modelValue.length !== 0) &&
$scope.dropzoneEnabled) {
$element.append($scope.$dropzoneElm);
} else {
$scope.$dropzoneElm.remove();
}
};
$scope.resetEmptyElement = this.resetEmptyElement;
$scope.resetDropzoneElement = this.resetDropzoneElement;
}
]);
})();