2018-11-12 10:31:58 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
import Component from '../../lib/component';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple tooltip.
|
|
|
|
*
|
|
|
|
* @property {String} position The relative position to the parent
|
|
|
|
*/
|
|
|
|
export default class Treeview extends Component {
|
2019-01-21 10:45:53 +00:00
|
|
|
constructor($element, $scope) {
|
2018-11-12 10:31:58 +00:00
|
|
|
super($element, $scope);
|
2019-01-21 10:45:53 +00:00
|
|
|
this.data = [];
|
2018-11-12 10:31:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 10:45:53 +00:00
|
|
|
$onInit() {
|
|
|
|
this.refresh();
|
2018-11-12 10:31:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 10:45:53 +00:00
|
|
|
refresh() {
|
|
|
|
this.model.refresh().then(() => {
|
|
|
|
this.data = this.model.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-18 07:37:26 +00:00
|
|
|
/* hasCheckedChilds(node) {
|
2019-01-21 10:45:53 +00:00
|
|
|
if (!node.childs) return false;
|
|
|
|
|
|
|
|
const childs = node.childs;
|
|
|
|
for (let i = 0; i < childs.length; i++) {
|
|
|
|
if (childs[i].selected || this.hasCheckedChilds(childs[i]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasCheckedParents(node) {
|
|
|
|
if (!node.parent) return false;
|
|
|
|
|
|
|
|
const parent = node.parent;
|
|
|
|
if (parent.selected || this.hasCheckedParents(parent))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2019-02-18 07:37:26 +00:00
|
|
|
} */
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-02-18 07:37:26 +00:00
|
|
|
onSelection(item, value) {
|
|
|
|
this.emit('selection', {item, value});
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onToggle(item) {
|
2019-02-18 07:37:26 +00:00
|
|
|
if (item.active)
|
2019-01-21 10:45:53 +00:00
|
|
|
item.childs = undefined;
|
|
|
|
else {
|
|
|
|
this.model.applyFilter({}, {parentFk: item.id}).then(() => {
|
2019-02-18 07:37:26 +00:00
|
|
|
const newData = this.model.data;
|
|
|
|
|
|
|
|
if (item.childs) {
|
|
|
|
let childs = item.childs;
|
|
|
|
childs.forEach(child => {
|
|
|
|
let index = newData.findIndex(newChild => {
|
|
|
|
return newChild.id == child.id;
|
|
|
|
});
|
|
|
|
newData[index] = child;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
item.childs = newData.sort((a, b) => b.isIncluded - a.isIncluded);
|
2019-01-21 10:45:53 +00:00
|
|
|
});
|
|
|
|
}
|
2019-02-18 07:37:26 +00:00
|
|
|
|
|
|
|
item.active = !item.active;
|
2018-11-12 10:31:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 10:45:53 +00:00
|
|
|
Treeview.$inject = ['$element', '$scope'];
|
2018-11-12 10:31:58 +00:00
|
|
|
|
|
|
|
ngModule.component('vnTreeview', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Treeview,
|
|
|
|
bindings: {
|
|
|
|
model: '<'
|
|
|
|
}
|
|
|
|
});
|