1 var $, SelectNodeHandler;
5 SelectNodeHandler = (function() {
6 function SelectNodeHandler(tree_widget) {
7 this.tree_widget = tree_widget;
11 SelectNodeHandler.prototype.getSelectedNode = function() {
13 selected_nodes = this.getSelectedNodes();
14 if (selected_nodes.length) {
15 return selected_nodes[0];
21 SelectNodeHandler.prototype.getSelectedNodes = function() {
22 var id, node, selected_nodes;
23 if (this.selected_single_node) {
24 return [this.selected_single_node];
27 for (id in this.selected_nodes) {
28 node = this.tree_widget.getNodeById(id);
30 selected_nodes.push(node);
33 return selected_nodes;
37 SelectNodeHandler.prototype.getSelectedNodesUnder = function(parent) {
38 var id, node, selected_nodes;
39 if (this.selected_single_node) {
40 if (parent.isParentOf(this.selected_single_node)) {
41 return [this.selected_single_node];
47 for (id in this.selected_nodes) {
48 node = this.tree_widget.getNodeById(id);
49 if (node && parent.isParentOf(node)) {
50 selected_nodes.push(node);
53 return selected_nodes;
57 SelectNodeHandler.prototype.isNodeSelected = function(node) {
61 if (this.selected_nodes[node.id]) {
66 } else if (this.selected_single_node) {
67 return this.selected_single_node.element === node.element;
73 SelectNodeHandler.prototype.clear = function() {
74 this.selected_nodes = {};
75 return this.selected_single_node = null;
78 SelectNodeHandler.prototype.removeFromSelection = function(node, include_children) {
79 if (include_children == null) {
80 include_children = false;
83 if (this.selected_single_node && node.element === this.selected_single_node.element) {
84 return this.selected_single_node = null;
87 delete this.selected_nodes[node.id];
88 if (include_children) {
89 return node.iterate((function(_this) {
91 delete _this.selected_nodes[node.id];
99 SelectNodeHandler.prototype.addToSelection = function(node) {
101 return this.selected_nodes[node.id] = true;
103 return this.selected_single_node = node;
107 return SelectNodeHandler;
111 module.exports = SelectNodeHandler;