2019-10-02 07:54:52 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
|
|
|
|
class Controller {
|
2019-10-08 05:22:38 +00:00
|
|
|
constructor($element, $scope, $compile) {
|
|
|
|
this.$scope = $scope;
|
|
|
|
this.$compile = $compile;
|
2019-10-16 06:56:13 +00:00
|
|
|
this.element = $element[0];
|
|
|
|
|
|
|
|
this.element.$ctrl = this;
|
|
|
|
this.element.droppable = true;
|
|
|
|
this.dropCount = 0;
|
|
|
|
this.element.classList.add('vn-droppable');
|
2019-10-02 07:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
2019-10-16 06:56:13 +00:00
|
|
|
const transcludeElement = this.element.querySelector('.content');
|
|
|
|
const content = angular.element(transcludeElement);
|
|
|
|
|
2019-10-08 05:22:38 +00:00
|
|
|
if (this.item.parent) {
|
|
|
|
this.treeview.$transclude(($clone, $scope) => {
|
|
|
|
this.$contentScope = $scope;
|
|
|
|
$scope.item = this.item;
|
2019-10-16 06:56:13 +00:00
|
|
|
content.append($clone);
|
2019-10-08 05:22:38 +00:00
|
|
|
});
|
2019-10-16 06:56:13 +00:00
|
|
|
|
|
|
|
this.element.draggable = true;
|
|
|
|
this.element.classList.add('vn-draggable');
|
2019-10-08 05:22:38 +00:00
|
|
|
} else {
|
|
|
|
let template = `<span translate>{{$ctrl.treeview.rootLabel}}</span>`;
|
|
|
|
let $clone = this.$compile(template)(this.$scope);
|
2019-10-16 06:56:13 +00:00
|
|
|
content.append($clone);
|
2019-10-08 05:22:38 +00:00
|
|
|
}
|
2019-10-02 07:54:52 +00:00
|
|
|
}
|
2019-10-04 10:20:49 +00:00
|
|
|
|
|
|
|
$onDestroy() {
|
|
|
|
if (this.$contentScope)
|
|
|
|
this.$contentScope.$destroy();
|
|
|
|
}
|
2019-10-16 06:56:13 +00:00
|
|
|
|
|
|
|
dragEnter() {
|
|
|
|
this.dropCount++;
|
|
|
|
|
|
|
|
if (element != this.dropping) {
|
|
|
|
this.undrop();
|
|
|
|
if (element) element.classList.add('dropping');
|
|
|
|
this.dropping = element;
|
|
|
|
}
|
|
|
|
}
|
2019-10-02 07:54:52 +00:00
|
|
|
}
|
2019-10-08 05:22:38 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', '$compile'];
|
2019-10-02 07:54:52 +00:00
|
|
|
|
2020-07-24 15:46:06 +00:00
|
|
|
ngModule.vnComponent('vnTreeviewChild', {
|
2019-10-16 06:56:13 +00:00
|
|
|
template: require('./child.html'),
|
2019-10-02 07:54:52 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
2019-10-02 12:12:17 +00:00
|
|
|
item: '<'
|
|
|
|
},
|
|
|
|
require: {
|
|
|
|
treeview: '^vnTreeview'
|
2019-10-02 07:54:52 +00:00
|
|
|
}
|
|
|
|
});
|