salix/front/core/components/treeview/childs.js

68 lines
1.6 KiB
JavaScript

import ngModule from '../../module';
import Component from '../../lib/component';
class Controller extends Component {
constructor($element, $scope, $transclude) {
super($element, $scope);
this.$transclude = $transclude;
}
$onInit() {
this.transcludeFunc((tClone, $scope) => {
$scope.item = this.item;
let content = this.element.querySelector('.content');
angular.element(content).append(tClone);
});
}
toggle(event, item) {
if (event.defaultPrevented || !item.sons) return;
event.preventDefault();
this.treeview.onToggle(item);
}
select(item, value) {
this.treeview.onSelection(item, value);
}
onIconClick(icon, item, parent, index) {
let parentController = this.parentScope.$ctrl;
icon.callback.call(parentController, item, parent, index);
}
onCreate(parent) {
this.treeview.onCreate(parent);
}
onDrop(item, dragged, dropped) {
this.treeview.onDrop(item, dragged, dropped);
}
get isInsertable() {
return Array.isArray(this.parent) || this.parent.childs;
}
}
Controller.$inject = ['$element', '$scope', '$transclude'];
ngModule.component('vnTreeviewChilds', {
template: require('./childs.html'),
controller: Controller,
bindings: {
items: '<',
parent: '<',
icons: '<?',
disabled: '<?',
selectable: '<?',
editable: '<?',
draggable: '<?',
droppable: '<?',
aclRole: '<?',
parentScope: '<',
transcludeFunc: '<'
},
require: {
treeview: '^vnTreeview'
}
});