1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var menu_events_1 = require("./menu/menu.events");
|
4 | var event_utils_1 = require("./utils/event.utils");
|
5 | var fn_utils_1 = require("./utils/fn.utils");
|
6 | var TreeController = (function () {
|
7 | function TreeController(component) {
|
8 | this.component = component;
|
9 | this.tree = this.component.tree;
|
10 | this.treeService = this.component.treeService;
|
11 | }
|
12 | TreeController.prototype.select = function () {
|
13 | if (!this.isSelected()) {
|
14 | this.component.onNodeSelected({ button: event_utils_1.MouseButtons.Left });
|
15 | }
|
16 | };
|
17 | TreeController.prototype.unselect = function () {
|
18 | if (this.isSelected()) {
|
19 | this.component.onNodeUnselected({ button: event_utils_1.MouseButtons.Left });
|
20 | }
|
21 | };
|
22 | TreeController.prototype.isSelected = function () {
|
23 | return this.component.isSelected;
|
24 | };
|
25 | TreeController.prototype.expand = function () {
|
26 | if (this.isCollapsed()) {
|
27 | this.component.onSwitchFoldingType();
|
28 | }
|
29 | };
|
30 | TreeController.prototype.expandToParent = function (tree) {
|
31 | if (tree === void 0) { tree = this.tree; }
|
32 | if (tree) {
|
33 | var controller = this.treeService.getController(tree.id);
|
34 | if (controller) {
|
35 | controller.expand();
|
36 | this.expandToParent(tree.parent);
|
37 | }
|
38 | }
|
39 | };
|
40 | TreeController.prototype.isExpanded = function () {
|
41 | return this.tree.isNodeExpanded();
|
42 | };
|
43 | TreeController.prototype.collapse = function () {
|
44 | if (this.isExpanded()) {
|
45 | this.component.onSwitchFoldingType();
|
46 | }
|
47 | };
|
48 | TreeController.prototype.isCollapsed = function () {
|
49 | return this.tree.isNodeCollapsed();
|
50 | };
|
51 | TreeController.prototype.toTreeModel = function () {
|
52 | return this.tree.toTreeModel();
|
53 | };
|
54 | TreeController.prototype.rename = function (newValue) {
|
55 | this.tree.markAsBeingRenamed();
|
56 | this.component.applyNewValue({ type: 'keyup', value: newValue });
|
57 | };
|
58 | TreeController.prototype.remove = function () {
|
59 | this.component.onMenuItemSelected({ nodeMenuItemAction: menu_events_1.NodeMenuItemAction.Remove });
|
60 | };
|
61 | TreeController.prototype.addChild = function (newNode) {
|
62 | if (this.tree.hasDeferredChildren() && !this.tree.childrenWereLoaded()) {
|
63 | return;
|
64 | }
|
65 | var newTree = this.tree.createNode(Array.isArray(newNode.children), newNode);
|
66 | this.treeService.fireNodeCreated(newTree);
|
67 | };
|
68 | TreeController.prototype.addChildAsync = function (newNode) {
|
69 | if (this.tree.hasDeferredChildren() && !this.tree.childrenWereLoaded()) {
|
70 | return Promise.reject(new Error('This node loads its children asynchronously, hence child cannot be added this way'));
|
71 | }
|
72 | var newTree = this.tree.createNode(Array.isArray(newNode.children), newNode);
|
73 | this.treeService.fireNodeCreated(newTree);
|
74 |
|
75 | return new Promise(function (resolve) {
|
76 | setTimeout(function () {
|
77 | resolve(newTree);
|
78 | });
|
79 | });
|
80 | };
|
81 | TreeController.prototype.changeNodeId = function (id) {
|
82 | if (!id) {
|
83 | throw Error('You should supply an id!');
|
84 | }
|
85 | if (this.treeService.hasController(id)) {
|
86 | throw Error("Controller already exists for the given id: " + id);
|
87 | }
|
88 | this.treeService.deleteController(this.tree.id);
|
89 | this.tree.id = id;
|
90 | this.treeService.setController(this.tree.id, this);
|
91 | };
|
92 | TreeController.prototype.reloadChildren = function () {
|
93 | this.tree.reloadChildren();
|
94 | };
|
95 | TreeController.prototype.setChildren = function (children) {
|
96 | if (!this.tree.isLeaf()) {
|
97 | this.tree.setChildren(children);
|
98 | }
|
99 | };
|
100 | TreeController.prototype.startRenaming = function () {
|
101 | this.tree.markAsBeingRenamed();
|
102 | };
|
103 | TreeController.prototype.check = function () {
|
104 | this.component.onNodeChecked();
|
105 | };
|
106 | TreeController.prototype.uncheck = function () {
|
107 | this.component.onNodeUnchecked();
|
108 | };
|
109 | TreeController.prototype.isChecked = function () {
|
110 | return this.tree.checked;
|
111 | };
|
112 | TreeController.prototype.isIndetermined = function () {
|
113 | return fn_utils_1.get(this.component, 'checkboxElementRef.nativeElement.indeterminate');
|
114 | };
|
115 | TreeController.prototype.allowSelection = function () {
|
116 | this.tree.selectionAllowed = true;
|
117 | };
|
118 | TreeController.prototype.forbidSelection = function () {
|
119 | this.tree.selectionAllowed = false;
|
120 | };
|
121 | TreeController.prototype.isSelectionAllowed = function () {
|
122 | return this.tree.selectionAllowed;
|
123 | };
|
124 | return TreeController;
|
125 | }());
|
126 | exports.TreeController = TreeController;
|
127 |
|
\ | No newline at end of file |