nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jqTree / _entries / 68_tree-move.md
1 ---
2 title: tree.move
3 name: event-tree-move
4 ---
5
6 Triggered when the user moves a node.
7
8 Note that this event is called **before** the node is moved. See note about `do_move` below.
9
10 Event.move_info contains:
11
12 * moved_node
13 * target_node
14 * position: (before, after or inside)
15 * previous_parent
16
17 {% highlight js %}
18 $('#tree1').tree({
19     data: data,
20     dragAndDrop: true
21 });
22
23 $('#tree1').bind(
24     'tree.move',
25     function(event) {
26         console.log('moved_node', event.move_info.moved_node);
27         console.log('target_node', event.move_info.target_node);
28         console.log('position', event.move_info.position);
29         console.log('previous_parent', event.move_info.previous_parent);
30     }
31 );
32 {% endhighlight %}
33
34 You can prevent the move by calling **event.preventDefault()**
35
36 {% highlight js %}
37 $('#tree1').bind(
38     'tree.move',
39     function(event) {
40         event.preventDefault();
41     }
42 );
43 {% endhighlight %}
44
45 You can later call **event.move_info.move_info.do_move()** to move the node. This way you can ask the user before moving the node:
46
47 {% highlight js %}
48 $('#tree1').bind(
49     'tree.move',
50     function(event) {
51         event.preventDefault();
52
53         if (confirm('Really move?')) {
54             event.move_info.do_move();
55         }
56     }
57 );
58 {% endhighlight %}
59
60 Note that if you want to serialise the tree, for example to POST back to a server, you need to let tree complete the move first:
61
62 {% highlight js %}
63 $('#tree1').bind(
64     'tree.move',
65     function(event)
66     {
67         event.preventDefault();
68         // do the move first, and _then_ POST back.
69         event.move_info.do_move();
70         $.post('your_url', {tree: $(this).tree('toJson')});
71     }
72 );
73 {% endhighlight %}