You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4842 lines
153 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.tree.TreePanel
  17. * @extends Ext.Panel
  18. * <p>The TreePanel provides tree-structured UI representation of tree-structured data.</p>
  19. * <p>{@link Ext.tree.TreeNode TreeNode}s added to the TreePanel may each contain metadata
  20. * used by your application in their {@link Ext.tree.TreeNode#attributes attributes} property.</p>
  21. * <p><b>A TreePanel must have a {@link #root} node before it is rendered.</b> This may either be
  22. * specified using the {@link #root} config option, or using the {@link #setRootNode} method.
  23. * <p>An example of tree rendered to an existing div:</p><pre><code>
  24. var tree = new Ext.tree.TreePanel({
  25. renderTo: 'tree-div',
  26. useArrows: true,
  27. autoScroll: true,
  28. animate: true,
  29. enableDD: true,
  30. containerScroll: true,
  31. border: false,
  32. // auto create TreeLoader
  33. dataUrl: 'get-nodes.php',
  34. root: {
  35. nodeType: 'async',
  36. text: 'Ext JS',
  37. draggable: false,
  38. id: 'source'
  39. }
  40. });
  41. tree.getRootNode().expand();
  42. * </code></pre>
  43. * <p>The example above would work with a data packet similar to this:</p><pre><code>
  44. [{
  45. "text": "adapter",
  46. "id": "source\/adapter",
  47. "cls": "folder"
  48. }, {
  49. "text": "dd",
  50. "id": "source\/dd",
  51. "cls": "folder"
  52. }, {
  53. "text": "debug.js",
  54. "id": "source\/debug.js",
  55. "leaf": true,
  56. "cls": "file"
  57. }]
  58. * </code></pre>
  59. * <p>An example of tree within a Viewport:</p><pre><code>
  60. new Ext.Viewport({
  61. layout: 'border',
  62. items: [{
  63. region: 'west',
  64. collapsible: true,
  65. title: 'Navigation',
  66. xtype: 'treepanel',
  67. width: 200,
  68. autoScroll: true,
  69. split: true,
  70. loader: new Ext.tree.TreeLoader(),
  71. root: new Ext.tree.AsyncTreeNode({
  72. expanded: true,
  73. children: [{
  74. text: 'Menu Option 1',
  75. leaf: true
  76. }, {
  77. text: 'Menu Option 2',
  78. leaf: true
  79. }, {
  80. text: 'Menu Option 3',
  81. leaf: true
  82. }]
  83. }),
  84. rootVisible: false,
  85. listeners: {
  86. click: function(n) {
  87. Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
  88. }
  89. }
  90. }, {
  91. region: 'center',
  92. xtype: 'tabpanel',
  93. // remaining code not shown ...
  94. }]
  95. });
  96. </code></pre>
  97. *
  98. * @cfg {Ext.tree.TreeNode} root The root node for the tree.
  99. * @cfg {Boolean} rootVisible <tt>false</tt> to hide the root node (defaults to <tt>true</tt>)
  100. * @cfg {Boolean} lines <tt>false</tt> to disable tree lines (defaults to <tt>true</tt>)
  101. * @cfg {Boolean} enableDD <tt>true</tt> to enable drag and drop
  102. * @cfg {Boolean} enableDrag <tt>true</tt> to enable just drag
  103. * @cfg {Boolean} enableDrop <tt>true</tt> to enable just drop
  104. * @cfg {Object} dragConfig Custom config to pass to the {@link Ext.tree.TreeDragZone} instance
  105. * @cfg {Object} dropConfig Custom config to pass to the {@link Ext.tree.TreeDropZone} instance
  106. * @cfg {String} ddGroup The DD group this TreePanel belongs to
  107. * @cfg {Boolean} ddAppendOnly <tt>true</tt> if the tree should only allow append drops (use for trees which are sorted)
  108. * @cfg {Boolean} ddScroll <tt>true</tt> to enable body scrolling
  109. * @cfg {Boolean} containerScroll <tt>true</tt> to register this container with ScrollManager
  110. * @cfg {Boolean} hlDrop <tt>false</tt> to disable node highlight on drop (defaults to the value of {@link Ext#enableFx})
  111. * @cfg {String} hlColor The color of the node highlight (defaults to <tt>'C3DAF9'</tt>)
  112. * @cfg {Boolean} animate <tt>true</tt> to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx})
  113. * @cfg {Boolean} singleExpand <tt>true</tt> if only 1 node per branch may be expanded
  114. * @cfg {Object} selModel A tree selection model to use with this TreePanel (defaults to an {@link Ext.tree.DefaultSelectionModel})
  115. * @cfg {Boolean} trackMouseOver <tt>false</tt> to disable mouse over highlighting
  116. * @cfg {Ext.tree.TreeLoader} loader A {@link Ext.tree.TreeLoader} for use with this TreePanel
  117. * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to <tt>'/'</tt>)
  118. * @cfg {Boolean} useArrows <tt>true</tt> to use Vista-style arrows in the tree (defaults to <tt>false</tt>)
  119. * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
  120. *
  121. * @constructor
  122. * @param {Object} config
  123. * @xtype treepanel
  124. */
  125. Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
  126. rootVisible : true,
  127. animate : Ext.enableFx,
  128. lines : true,
  129. enableDD : false,
  130. hlDrop : Ext.enableFx,
  131. pathSeparator : '/',
  132. /**
  133. * @cfg {Array} bubbleEvents
  134. * <p>An array of events that, when fired, should be bubbled to any parent container.
  135. * See {@link Ext.util.Observable#enableBubble}.
  136. * Defaults to <tt>[]</tt>.
  137. */
  138. bubbleEvents : [],
  139. initComponent : function(){
  140. Ext.tree.TreePanel.superclass.initComponent.call(this);
  141. if(!this.eventModel){
  142. this.eventModel = new Ext.tree.TreeEventModel(this);
  143. }
  144. // initialize the loader
  145. var l = this.loader;
  146. if(!l){
  147. l = new Ext.tree.TreeLoader({
  148. dataUrl: this.dataUrl,
  149. requestMethod: this.requestMethod
  150. });
  151. }else if(Ext.isObject(l) && !l.load){
  152. l = new Ext.tree.TreeLoader(l);
  153. }
  154. this.loader = l;
  155. this.nodeHash = {};
  156. /**
  157. * The root node of this tree.
  158. * @type Ext.tree.TreeNode
  159. * @property root
  160. */
  161. if(this.root){
  162. var r = this.root;
  163. delete this.root;
  164. this.setRootNode(r);
  165. }
  166. this.addEvents(
  167. /**
  168. * @event append
  169. * Fires when a new child node is appended to a node in this tree.
  170. * @param {Tree} tree The owner tree
  171. * @param {Node} parent The parent node
  172. * @param {Node} node The newly appended node
  173. * @param {Number} index The index of the newly appended node
  174. */
  175. 'append',
  176. /**
  177. * @event remove
  178. * Fires when a child node is removed from a node in this tree.
  179. * @param {Tree} tree The owner tree
  180. * @param {Node} parent The parent node
  181. * @param {Node} node The child node removed
  182. */
  183. 'remove',
  184. /**
  185. * @event movenode
  186. * Fires when a node is moved to a new location in the tree
  187. * @param {Tree} tree The owner tree
  188. * @param {Node} node The node moved
  189. * @param {Node} oldParent The old parent of this node
  190. * @param {Node} newParent The new parent of this node
  191. * @param {Number} index The index it was moved to
  192. */
  193. 'movenode',
  194. /**
  195. * @event insert
  196. * Fires when a new child node is inserted in a node in this tree.
  197. * @param {Tree} tree The owner tree
  198. * @param {Node} parent The parent node
  199. * @param {Node} node The child node inserted
  200. * @param {Node} refNode The child node the node was inserted before
  201. */
  202. 'insert',
  203. /**
  204. * @event beforeappend
  205. * Fires before a new child is appended to a node in this tree, return false to cancel the append.
  206. * @param {Tree} tree The owner tree
  207. * @param {Node} parent The parent node
  208. * @param {Node} node The child node to be appended
  209. */
  210. 'beforeappend',
  211. /**
  212. * @event beforeremove
  213. * Fires before a child is removed from a node in this tree, return false to cancel the remove.
  214. * @param {Tree} tree The owner tree
  215. * @param {Node} parent The parent node
  216. * @param {Node} node The child node to be removed
  217. */
  218. 'beforeremove',
  219. /**
  220. * @event beforemovenode
  221. * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
  222. * @param {Tree} tree The owner tree
  223. * @param {Node} node The node being moved
  224. * @param {Node} oldParent The parent of the node
  225. * @param {Node} newParent The new parent the node is moving to
  226. * @param {Number} index The index it is being moved to
  227. */
  228. 'beforemovenode',
  229. /**
  230. * @event beforeinsert
  231. * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
  232. * @param {Tree} tree The owner tree
  233. * @param {Node} parent The parent node
  234. * @param {Node} node The child node to be inserted
  235. * @param {Node} refNode The child node the node is being inserted before
  236. */
  237. 'beforeinsert',
  238. /**
  239. * @event beforeload
  240. * Fires before a node is loaded, return false to cancel
  241. * @param {Node} node The node being loaded
  242. */
  243. 'beforeload',
  244. /**
  245. * @event load
  246. * Fires when a node is loaded
  247. * @param {Node} node The node that was loaded
  248. */
  249. 'load',
  250. /**
  251. * @event textchange
  252. * Fires when the text for a node is changed
  253. * @param {Node} node The node
  254. * @param {String} text The new text
  255. * @param {String} oldText The old text
  256. */
  257. 'textchange',
  258. /**
  259. * @event beforeexpandnode
  260. * Fires before a node is expanded, return false to cancel.
  261. * @param {Node} node The node
  262. * @param {Boolean} deep
  263. * @param {Boolean} anim
  264. */
  265. 'beforeexpandnode',
  266. /**
  267. * @event beforecollapsenode
  268. * Fires before a node is collapsed, return false to cancel.
  269. * @param {Node} node The node
  270. * @param {Boolean} deep
  271. * @param {Boolean} anim
  272. */
  273. 'beforecollapsenode',
  274. /**
  275. * @event expandnode
  276. * Fires when a node is expanded
  277. * @param {Node} node The node
  278. */
  279. 'expandnode',
  280. /**
  281. * @event disabledchange
  282. * Fires when the disabled status of a node changes
  283. * @param {Node} node The node
  284. * @param {Boolean} disabled
  285. */
  286. 'disabledchange',
  287. /**
  288. * @event collapsenode
  289. * Fires when a node is collapsed
  290. * @param {Node} node The node
  291. */
  292. 'collapsenode',
  293. /**
  294. * @event beforeclick
  295. * Fires before click processing on a node. Return false to cancel the default action.
  296. * @param {Node} node The node
  297. * @param {Ext.EventObject} e The event object
  298. */
  299. 'beforeclick',
  300. /**
  301. * @event click
  302. * Fires when a node is clicked
  303. * @param {Node} node The node
  304. * @param {Ext.EventObject} e The event object
  305. */
  306. 'click',
  307. /**
  308. * @event containerclick
  309. * Fires when the tree container is clicked
  310. * @param {Tree} this
  311. * @param {Ext.EventObject} e The event object
  312. */
  313. 'containerclick',
  314. /**
  315. * @event checkchange
  316. * Fires when a node with a checkbox's checked property changes
  317. * @param {Node} this This node
  318. * @param {Boolean} checked
  319. */
  320. 'checkchange',
  321. /**
  322. * @event beforedblclick
  323. * Fires before double click processing on a node. Return false to cancel the default action.
  324. * @param {Node} node The node
  325. * @param {Ext.EventObject} e The event object
  326. */
  327. 'beforedblclick',
  328. /**
  329. * @event dblclick
  330. * Fires when a node is double clicked
  331. * @param {Node} node The node
  332. * @param {Ext.EventObject} e The event object
  333. */
  334. 'dblclick',
  335. /**
  336. * @event containerdblclick
  337. * Fires when the tree container is double clicked
  338. * @param {Tree} this
  339. * @param {Ext.EventObject} e The event object
  340. */
  341. 'containerdblclick',
  342. /**
  343. * @event contextmenu
  344. * Fires when a node is right clicked. To display a context menu in response to this
  345. * event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add
  346. * a handler for this event:<pre><code>
  347. new Ext.tree.TreePanel({
  348. title: 'My TreePanel',
  349. root: new Ext.tree.AsyncTreeNode({
  350. text: 'The Root',
  351. children: [
  352. { text: 'Child node 1', leaf: true },
  353. { text: 'Child node 2', leaf: true }
  354. ]
  355. }),
  356. contextMenu: new Ext.menu.Menu({
  357. items: [{
  358. id: 'delete-node',
  359. text: 'Delete Node'
  360. }],
  361. listeners: {
  362. itemclick: function(item) {
  363. switch (item.id) {
  364. case 'delete-node':
  365. var n = item.parentMenu.contextNode;
  366. if (n.parentNode) {
  367. n.remove();
  368. }
  369. break;
  370. }
  371. }
  372. }
  373. }),
  374. listeners: {
  375. contextmenu: function(node, e) {
  376. // Register the context node with the menu so that a Menu Item's handler function can access
  377. // it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.
  378. node.select();
  379. var c = node.getOwnerTree().contextMenu;
  380. c.contextNode = node;
  381. c.showAt(e.getXY());
  382. }
  383. }
  384. });
  385. </code></pre>
  386. * @param {Node} node The node
  387. * @param {Ext.EventObject} e The event object
  388. */
  389. 'contextmenu',
  390. /**
  391. * @event containercontextmenu
  392. * Fires when the tree container is right clicked
  393. * @param {Tree} this
  394. * @param {Ext.EventObject} e The event object
  395. */
  396. 'containercontextmenu',
  397. /**
  398. * @event beforechildrenrendered
  399. * Fires right before the child nodes for a node are rendered
  400. * @param {Node} node The node
  401. */
  402. 'beforechildrenrendered',
  403. /**
  404. * @event startdrag
  405. * Fires when a node starts being dragged
  406. * @param {Ext.tree.TreePanel} this
  407. * @param {Ext.tree.TreeNode} node
  408. * @param {event} e The raw browser event
  409. */
  410. 'startdrag',
  411. /**
  412. * @event enddrag
  413. * Fires when a drag operation is complete
  414. * @param {Ext.tree.TreePanel} this
  415. * @param {Ext.tree.TreeNode} node
  416. * @param {event} e The raw browser event
  417. */
  418. 'enddrag',
  419. /**
  420. * @event dragdrop
  421. * Fires when a dragged node is dropped on a valid DD target
  422. * @param {Ext.tree.TreePanel} this
  423. * @param {Ext.tree.TreeNode} node
  424. * @param {DD} dd The dd it was dropped on
  425. * @param {event} e The raw browser event
  426. */
  427. 'dragdrop',
  428. /**
  429. * @event beforenodedrop
  430. * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
  431. * passed to handlers has the following properties:<br />
  432. * <ul style="padding:5px;padding-left:16px;">
  433. * <li>tree - The TreePanel</li>
  434. * <li>target - The node being targeted for the drop</li>
  435. * <li>data - The drag data from the drag source</li>
  436. * <li>point - The point of the drop - append, above or below</li>
  437. * <li>source - The drag source</li>
  438. * <li>rawEvent - Raw mouse event</li>
  439. * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
  440. * to be inserted by setting them on this object.</li>
  441. * <li>cancel - Set this to true to cancel the drop.</li>
  442. * <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true
  443. * will prevent the animated 'repair' from appearing.</li>
  444. * </ul>
  445. * @param {Object} dropEvent
  446. */
  447. 'beforenodedrop',
  448. /**
  449. * @event nodedrop
  450. * Fires after a DD object is dropped on a node in this tree. The dropEvent
  451. * passed to handlers has the following properties:<br />
  452. * <ul style="padding:5px;padding-left:16px;">
  453. * <li>tree - The TreePanel</li>
  454. * <li>target - The node being targeted for the drop</li>
  455. * <li>data - The drag data from the drag source</li>
  456. * <li>point - The point of the drop - append, above or below</li>
  457. * <li>source - The drag source</li>
  458. * <li>rawEvent - Raw mouse event</li>
  459. * <li>dropNode - Dropped node(s).</li>
  460. * </ul>
  461. * @param {Object} dropEvent
  462. */
  463. 'nodedrop',
  464. /**
  465. * @event nodedragover
  466. * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
  467. * passed to handlers has the following properties:<br />
  468. * <ul style="padding:5px;padding-left:16px;">
  469. * <li>tree - The TreePanel</li>
  470. * <li>target - The node being targeted for the drop</li>
  471. * <li>data - The drag data from the drag source</li>
  472. * <li>point - The point of the drop - append, above or below</li>
  473. * <li>source - The drag source</li>
  474. * <li>rawEvent - Raw mouse event</li>
  475. * <li>dropNode - Drop node(s) provided by the source.</li>
  476. * <li>cancel - Set this to true to signal drop not allowed.</li>
  477. * </ul>
  478. * @param {Object} dragOverEvent
  479. */
  480. 'nodedragover'
  481. );
  482. if(this.singleExpand){
  483. this.on('beforeexpandnode', this.restrictExpand, this);
  484. }
  485. },
  486. // private
  487. proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){
  488. if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){
  489. ename = ename+'node';
  490. }
  491. // args inline for performance while bubbling events
  492. return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);
  493. },
  494. /**
  495. * Returns this root node for this tree
  496. * @return {Node}
  497. */
  498. getRootNode : function(){
  499. return this.root;
  500. },
  501. /**
  502. * Sets the root node for this tree. If the TreePanel has already rendered a root node, the
  503. * previous root node (and all of its descendants) are destroyed before the new root node is rendered.
  504. * @param {Node} node
  505. * @return {Node}
  506. */
  507. setRootNode : function(node){
  508. this.destroyRoot();
  509. if(!node.render){ // attributes passed
  510. node = this.loader.createNode(node);
  511. }
  512. this.root = node;
  513. node.ownerTree = this;
  514. node.isRoot = true;
  515. this.registerNode(node);
  516. if(!this.rootVisible){
  517. var uiP = node.attributes.uiProvider;
  518. node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);
  519. }
  520. if(this.innerCt){
  521. this.clearInnerCt();
  522. this.renderRoot();
  523. }
  524. return node;
  525. },
  526. clearInnerCt : function(){
  527. this.innerCt.update('');
  528. },
  529. // private
  530. renderRoot : function(){
  531. this.root.render();
  532. if(!this.rootVisible){
  533. this.root.renderChildren();
  534. }
  535. },
  536. /**
  537. * Gets a node in this tree by its id
  538. * @param {String} id
  539. * @return {Node}
  540. */
  541. getNodeById : function(id){
  542. return this.nodeHash[id];
  543. },
  544. // private
  545. registerNode : function(node){
  546. this.nodeHash[node.id] = node;
  547. },
  548. // private
  549. unregisterNode : function(node){
  550. delete this.nodeHash[node.id];
  551. },
  552. // private
  553. toString : function(){
  554. return '[Tree'+(this.id?' '+this.id:'')+']';
  555. },
  556. // private
  557. restrictExpand : function(node){
  558. var p = node.parentNode;
  559. if(p){
  560. if(p.expandedChild && p.expandedChild.parentNode == p){
  561. p.expandedChild.collapse();
  562. }
  563. p.expandedChild = node;
  564. }
  565. },
  566. /**
  567. * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. 'id')
  568. * @param {String} attribute (optional) Defaults to null (return the actual nodes)
  569. * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
  570. * @return {Array}
  571. */
  572. getChecked : function(a, startNode){
  573. startNode = startNode || this.root;
  574. var r = [];
  575. var f = function(){
  576. if(this.attributes.checked){
  577. r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
  578. }
  579. };
  580. startNode.cascade(f);
  581. return r;
  582. },
  583. /**
  584. * Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.
  585. * @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.
  586. */
  587. getLoader : function(){
  588. return this.loader;
  589. },
  590. /**
  591. * Expand all nodes
  592. */
  593. expandAll : function(){
  594. this.root.expand(true);
  595. },
  596. /**
  597. * Collapse all nodes
  598. */
  599. collapseAll : function(){
  600. this.root.collapse(true);
  601. },
  602. /**
  603. * Returns the selection model used by this TreePanel.
  604. * @return {TreeSelectionModel} The selection model used by this TreePanel
  605. */
  606. getSelectionModel : function(){
  607. if(!this.selModel){
  608. this.selModel = new Ext.tree.DefaultSelectionModel();
  609. }
  610. return this.selModel;
  611. },
  612. /**
  613. * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
  614. * @param {String} path
  615. * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
  616. * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
  617. * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
  618. */
  619. expandPath : function(path, attr, callback){
  620. if(Ext.isEmpty(path)){
  621. if(callback){
  622. callback(false, undefined);
  623. }
  624. return;
  625. }
  626. attr = attr || 'id';
  627. var keys = path.split(this.pathSeparator);
  628. var curNode = this.root;
  629. if(curNode.attributes[attr] != keys[1]){ // invalid root
  630. if(callback){
  631. callback(false, null);
  632. }
  633. return;
  634. }
  635. var index = 1;
  636. var f = function(){
  637. if(++index == keys.length){
  638. if(callback){
  639. callback(true, curNode);
  640. }
  641. return;
  642. }
  643. var c = curNode.findChild(attr, keys[index]);
  644. if(!c){
  645. if(callback){
  646. callback(false, curNode);
  647. }
  648. return;
  649. }
  650. curNode = c;
  651. c.expand(false, false, f);
  652. };
  653. curNode.expand(false, false, f);
  654. },
  655. /**
  656. * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
  657. * @param {String} path
  658. * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
  659. * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
  660. * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
  661. */
  662. selectPath : function(path, attr, callback){
  663. if(Ext.isEmpty(path)){
  664. if(callback){
  665. callback(false, undefined);
  666. }
  667. return;
  668. }
  669. attr = attr || 'id';
  670. var keys = path.split(this.pathSeparator),
  671. v = keys.pop();
  672. if(keys.length > 1){
  673. var f = function(success, node){
  674. if(success && node){
  675. var n = node.findChild(attr, v);
  676. if(n){
  677. n.select();
  678. if(callback){
  679. callback(true, n);
  680. }
  681. }else if(callback){
  682. callback(false, n);
  683. }
  684. }else{
  685. if(callback){
  686. callback(false, n);
  687. }
  688. }
  689. };
  690. this.expandPath(keys.join(this.pathSeparator), attr, f);
  691. }else{
  692. this.root.select();
  693. if(callback){
  694. callback(true, this.root);
  695. }
  696. }
  697. },
  698. /**
  699. * Returns the underlying Element for this tree
  700. * @return {Ext.Element} The Element
  701. */
  702. getTreeEl : function(){
  703. return this.body;
  704. },
  705. // private
  706. onRender : function(ct, position){
  707. Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
  708. this.el.addClass('x-tree');
  709. this.innerCt = this.body.createChild({tag:'ul',
  710. cls:'x-tree-root-ct ' +
  711. (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')});
  712. },
  713. // private
  714. initEvents : function(){
  715. Ext.tree.TreePanel.superclass.initEvents.call(this);
  716. if(this.containerScroll){
  717. Ext.dd.ScrollManager.register(this.body);
  718. }
  719. if((this.enableDD || this.enableDrop) && !this.dropZone){
  720. /**
  721. * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
  722. * @property dropZone
  723. * @type Ext.tree.TreeDropZone
  724. */
  725. this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
  726. ddGroup: this.ddGroup || 'TreeDD', appendOnly: this.ddAppendOnly === true
  727. });
  728. }
  729. if((this.enableDD || this.enableDrag) && !this.dragZone){
  730. /**
  731. * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
  732. * @property dragZone
  733. * @type Ext.tree.TreeDragZone
  734. */
  735. this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
  736. ddGroup: this.ddGroup || 'TreeDD',
  737. scroll: this.ddScroll
  738. });
  739. }
  740. this.getSelectionModel().init(this);
  741. },
  742. // private
  743. afterRender : function(){
  744. Ext.tree.TreePanel.superclass.afterRender.call(this);
  745. this.renderRoot();
  746. },
  747. beforeDestroy : function(){
  748. if(this.rendered){
  749. Ext.dd.ScrollManager.unregister(this.body);
  750. Ext.destroy(this.dropZone, this.dragZone);
  751. }
  752. this.destroyRoot();
  753. Ext.destroy(this.loader);
  754. this.nodeHash = this.root = this.loader = null;
  755. Ext.tree.TreePanel.superclass.beforeDestroy.call(this);
  756. },
  757. /**
  758. * Destroy the root node. Not included by itself because we need to pass the silent parameter.
  759. * @private
  760. */
  761. destroyRoot : function(){
  762. if(this.root && this.root.destroy){
  763. this.root.destroy(true);
  764. }
  765. }
  766. /**
  767. * @cfg {String/Number} activeItem
  768. * @hide
  769. */
  770. /**
  771. * @cfg {Boolean} autoDestroy
  772. * @hide
  773. */
  774. /**
  775. * @cfg {Object/String/Function} autoLoad
  776. * @hide
  777. */
  778. /**
  779. * @cfg {Boolean} autoWidth
  780. * @hide
  781. */
  782. /**
  783. * @cfg {Boolean/Number} bufferResize
  784. * @hide
  785. */
  786. /**
  787. * @cfg {String} defaultType
  788. * @hide
  789. */
  790. /**
  791. * @cfg {Object} defaults
  792. * @hide
  793. */
  794. /**
  795. * @cfg {Boolean} hideBorders
  796. * @hide
  797. */
  798. /**
  799. * @cfg {Mixed} items
  800. * @hide
  801. */
  802. /**
  803. * @cfg {String} layout
  804. * @hide
  805. */
  806. /**
  807. * @cfg {Object} layoutConfig
  808. * @hide
  809. */
  810. /**
  811. * @cfg {Boolean} monitorResize
  812. * @hide
  813. */
  814. /**
  815. * @property items
  816. * @hide
  817. */
  818. /**
  819. * @method cascade
  820. * @hide
  821. */
  822. /**
  823. * @method doLayout
  824. * @hide
  825. */
  826. /**
  827. * @method find
  828. * @hide
  829. */
  830. /**
  831. * @method findBy
  832. * @hide
  833. */
  834. /**
  835. * @method findById
  836. * @hide
  837. */
  838. /**
  839. * @method findByType
  840. * @hide
  841. */
  842. /**
  843. * @method getComponent
  844. * @hide
  845. */
  846. /**
  847. * @method getLayout
  848. * @hide
  849. */
  850. /**
  851. * @method getUpdater
  852. * @hide
  853. */
  854. /**
  855. * @method insert
  856. * @hide
  857. */
  858. /**
  859. * @method load
  860. * @hide
  861. */
  862. /**
  863. * @method remove
  864. * @hide
  865. */
  866. /**
  867. * @event add
  868. * @hide
  869. */
  870. /**
  871. * @method removeAll
  872. * @hide
  873. */
  874. /**
  875. * @event afterLayout
  876. * @hide
  877. */
  878. /**
  879. * @event beforeadd
  880. * @hide
  881. */
  882. /**
  883. * @cfg {String} allowDomMove @hide
  884. */
  885. /**
  886. * @cfg {String} autoEl @hide
  887. */
  888. /**
  889. * @cfg {String} applyTo @hide
  890. */
  891. /**
  892. * @cfg {String} contentEl @hide
  893. */
  894. /**
  895. * @cfg {Mixed} data @hide
  896. */
  897. /**
  898. * @cfg {Mixed} tpl @hide
  899. */
  900. /**
  901. * @cfg {String} tplWriteMode @hide
  902. */
  903. /**
  904. * @cfg {String} disabledClass @hide
  905. */
  906. /**
  907. * @cfg {String} elements @hide
  908. */
  909. /**
  910. * @cfg {String} html @hide
  911. */
  912. /**
  913. * @cfg {Boolean} preventBodyReset
  914. * @hide
  915. */
  916. /**
  917. * @property disabled
  918. * @hide
  919. */
  920. /**
  921. * @method applyToMarkup
  922. * @hide
  923. */
  924. /**
  925. * @method enable
  926. * @hide
  927. */
  928. /**
  929. * @method disable
  930. * @hide
  931. */
  932. /**
  933. * @method setDisabled
  934. * @hide
  935. */
  936. });
  937. Ext.tree.TreePanel.nodeTypes = {};
  938. Ext.reg('treepanel', Ext.tree.TreePanel);Ext.tree.TreeEventModel = function(tree){
  939. this.tree = tree;
  940. this.tree.on('render', this.initEvents, this);
  941. };
  942. Ext.tree.TreeEventModel.prototype = {
  943. initEvents : function(){
  944. var t = this.tree;
  945. if(t.trackMouseOver !== false){
  946. t.mon(t.innerCt, {
  947. scope: this,
  948. mouseover: this.delegateOver,
  949. mouseout: this.delegateOut
  950. });
  951. }
  952. t.mon(t.getTreeEl(), {
  953. scope: this,
  954. click: this.delegateClick,
  955. dblclick: this.delegateDblClick,
  956. contextmenu: this.delegateContextMenu
  957. });
  958. },
  959. getNode : function(e){
  960. var t;
  961. if(t = e.getTarget('.x-tree-node-el', 10)){
  962. var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
  963. if(id){
  964. return this.tree.getNodeById(id);
  965. }
  966. }
  967. return null;
  968. },
  969. getNodeTarget : function(e){
  970. var t = e.getTarget('.x-tree-node-icon', 1);
  971. if(!t){
  972. t = e.getTarget('.x-tree-node-el', 6);
  973. }
  974. return t;
  975. },
  976. delegateOut : function(e, t){
  977. if(!this.beforeEvent(e)){
  978. return;
  979. }
  980. if(e.getTarget('.x-tree-ec-icon', 1)){
  981. var n = this.getNode(e);
  982. this.onIconOut(e, n);
  983. if(n == this.lastEcOver){
  984. delete this.lastEcOver;
  985. }
  986. }
  987. if((t = this.getNodeTarget(e)) && !e.within(t, true)){
  988. this.onNodeOut(e, this.getNode(e));
  989. }
  990. },
  991. delegateOver : function(e, t){
  992. if(!this.beforeEvent(e)){
  993. return;
  994. }
  995. if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
  996. Ext.getBody().on('mouseover', this.trackExit, this);
  997. this.trackingDoc = true;
  998. }
  999. if(this.lastEcOver){ // prevent hung highlight
  1000. this.onIconOut(e, this.lastEcOver);
  1001. delete this.lastEcOver;
  1002. }
  1003. if(e.getTarget('.x-tree-ec-icon', 1)){
  1004. this.lastEcOver = this.getNode(e);
  1005. this.onIconOver(e, this.lastEcOver);
  1006. }
  1007. if(t = this.getNodeTarget(e)){
  1008. this.onNodeOver(e, this.getNode(e));
  1009. }
  1010. },
  1011. trackExit : function(e){
  1012. if(this.lastOverNode){
  1013. if(this.lastOverNode.ui && !e.within(this.lastOverNode.ui.getEl())){
  1014. this.onNodeOut(e, this.lastOverNode);
  1015. }
  1016. delete this.lastOverNode;
  1017. Ext.getBody().un('mouseover', this.trackExit, this);
  1018. this.trackingDoc = false;
  1019. }
  1020. },
  1021. delegateClick : function(e, t){
  1022. if(this.beforeEvent(e)){
  1023. if(e.getTarget('input[type=checkbox]', 1)){
  1024. this.onCheckboxClick(e, this.getNode(e));
  1025. }else if(e.getTarget('.x-tree-ec-icon', 1)){
  1026. this.onIconClick(e, this.getNode(e));
  1027. }else if(this.getNodeTarget(e)){
  1028. this.onNodeClick(e, this.getNode(e));
  1029. }
  1030. }else{
  1031. this.checkContainerEvent(e, 'click');
  1032. }
  1033. },
  1034. delegateDblClick : function(e, t){
  1035. if(this.beforeEvent(e)){
  1036. if(this.getNodeTarget(e)){
  1037. this.onNodeDblClick(e, this.getNode(e));
  1038. }
  1039. }else{
  1040. this.checkContainerEvent(e, 'dblclick');
  1041. }
  1042. },
  1043. delegateContextMenu : function(e, t){
  1044. if(this.beforeEvent(e)){
  1045. if(this.getNodeTarget(e)){
  1046. this.onNodeContextMenu(e, this.getNode(e));
  1047. }
  1048. }else{
  1049. this.checkContainerEvent(e, 'contextmenu');
  1050. }
  1051. },
  1052. checkContainerEvent: function(e, type){
  1053. if(this.disabled){
  1054. e.stopEvent();
  1055. return false;
  1056. }
  1057. this.onContainerEvent(e, type);
  1058. },
  1059. onContainerEvent: function(e, type){
  1060. this.tree.fireEvent('container' + type, this.tree, e);
  1061. },
  1062. onNodeClick : function(e, node){
  1063. node.ui.onClick(e);
  1064. },
  1065. onNodeOver : function(e, node){
  1066. this.lastOverNode = node;
  1067. node.ui.onOver(e);
  1068. },
  1069. onNodeOut : function(e, node){
  1070. node.ui.onOut(e);
  1071. },
  1072. onIconOver : function(e, node){
  1073. node.ui.addClass('x-tree-ec-over');
  1074. },
  1075. onIconOut : function(e, node){
  1076. node.ui.removeClass('x-tree-ec-over');
  1077. },
  1078. onIconClick : function(e, node){
  1079. node.ui.ecClick(e);
  1080. },
  1081. onCheckboxClick : function(e, node){
  1082. node.ui.onCheckChange(e);
  1083. },
  1084. onNodeDblClick : function(e, node){
  1085. node.ui.onDblClick(e);
  1086. },
  1087. onNodeContextMenu : function(e, node){
  1088. node.ui.onContextMenu(e);
  1089. },
  1090. beforeEvent : function(e){
  1091. var node = this.getNode(e);
  1092. if(this.disabled || !node || !node.ui){
  1093. e.stopEvent();
  1094. return false;
  1095. }
  1096. return true;
  1097. },
  1098. disable: function(){
  1099. this.disabled = true;
  1100. },
  1101. enable: function(){
  1102. this.disabled = false;
  1103. }
  1104. };/**
  1105. * @class Ext.tree.DefaultSelectionModel
  1106. * @extends Ext.util.Observable
  1107. * The default single selection for a TreePanel.
  1108. */
  1109. Ext.tree.DefaultSelectionModel = Ext.extend(Ext.util.Observable, {
  1110. constructor : function(config){
  1111. this.selNode = null;
  1112. this.addEvents(
  1113. /**
  1114. * @event selectionchange
  1115. * Fires when the selected node changes
  1116. * @param {DefaultSelectionModel} this
  1117. * @param {TreeNode} node the new selection
  1118. */
  1119. 'selectionchange',
  1120. /**
  1121. * @event beforeselect
  1122. * Fires before the selected node changes, return false to cancel the change
  1123. * @param {DefaultSelectionModel} this
  1124. * @param {TreeNode} newNode the new selection
  1125. * @param {TreeNode} oldNode the old selection
  1126. */
  1127. 'beforeselect'
  1128. );
  1129. Ext.apply(this, config);
  1130. Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
  1131. },
  1132. init : function(tree){
  1133. this.tree = tree;
  1134. tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
  1135. tree.on('click', this.onNodeClick, this);
  1136. },
  1137. onNodeClick : function(node, e){
  1138. this.select(node);
  1139. },
  1140. /**
  1141. * Select a node.
  1142. * @param {TreeNode} node The node to select
  1143. * @return {TreeNode} The selected node
  1144. */
  1145. select : function(node, /* private*/ selectNextNode){
  1146. // If node is hidden, select the next node in whatever direction was being moved in.
  1147. if (!Ext.fly(node.ui.wrap).isVisible() && selectNextNode) {
  1148. return selectNextNode.call(this, node);
  1149. }
  1150. var last = this.selNode;
  1151. if(node == last){
  1152. node.ui.onSelectedChange(true);
  1153. }else if(this.fireEvent('beforeselect', this, node, last) !== false){
  1154. if(last && last.ui){
  1155. last.ui.onSelectedChange(false);
  1156. }
  1157. this.selNode = node;
  1158. node.ui.onSelectedChange(true);
  1159. this.fireEvent('selectionchange', this, node, last);
  1160. }
  1161. return node;
  1162. },
  1163. /**
  1164. * Deselect a node.
  1165. * @param {TreeNode} node The node to unselect
  1166. * @param {Boolean} silent True to stop the selectionchange event from firing.
  1167. */
  1168. unselect : function(node, silent){
  1169. if(this.selNode == node){
  1170. this.clearSelections(silent);
  1171. }
  1172. },
  1173. /**
  1174. * Clear all selections
  1175. * @param {Boolean} silent True to stop the selectionchange event from firing.
  1176. */
  1177. clearSelections : function(silent){
  1178. var n = this.selNode;
  1179. if(n){
  1180. n.ui.onSelectedChange(false);
  1181. this.selNode = null;
  1182. if(silent !== true){
  1183. this.fireEvent('selectionchange', this, null);
  1184. }
  1185. }
  1186. return n;
  1187. },
  1188. /**
  1189. * Get the selected node
  1190. * @return {TreeNode} The selected node
  1191. */
  1192. getSelectedNode : function(){
  1193. return this.selNode;
  1194. },
  1195. /**
  1196. * Returns true if the node is selected
  1197. * @param {TreeNode} node The node to check
  1198. * @return {Boolean}
  1199. */
  1200. isSelected : function(node){
  1201. return this.selNode == node;
  1202. },
  1203. /**
  1204. * Selects the node above the selected node in the tree, intelligently walking the nodes
  1205. * @return TreeNode The new selection
  1206. */
  1207. selectPrevious : function(/* private */ s){
  1208. if(!(s = s || this.selNode || this.lastSelNode)){
  1209. return null;
  1210. }
  1211. // Here we pass in the current function to select to indicate the direction we're moving
  1212. var ps = s.previousSibling;
  1213. if(ps){
  1214. if(!ps.isExpanded() || ps.childNodes.length < 1){
  1215. return this.select(ps, this.selectPrevious);
  1216. } else{
  1217. var lc = ps.lastChild;
  1218. while(lc && lc.isExpanded() && Ext.fly(lc.ui.wrap).isVisible() && lc.childNodes.length > 0){
  1219. lc = lc.lastChild;
  1220. }
  1221. return this.select(lc, this.selectPrevious);
  1222. }
  1223. } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
  1224. return this.select(s.parentNode, this.selectPrevious);
  1225. }
  1226. return null;
  1227. },
  1228. /**
  1229. * Selects the node above the selected node in the tree, intelligently walking the nodes
  1230. * @return TreeNode The new selection
  1231. */
  1232. selectNext : function(/* private */ s){
  1233. if(!(s = s || this.selNode || this.lastSelNode)){
  1234. return null;
  1235. }
  1236. // Here we pass in the current function to select to indicate the direction we're moving
  1237. if(s.firstChild && s.isExpanded() && Ext.fly(s.ui.wrap).isVisible()){
  1238. return this.select(s.firstChild, this.selectNext);
  1239. }else if(s.nextSibling){
  1240. return this.select(s.nextSibling, this.selectNext);
  1241. }else if(s.parentNode){
  1242. var newS = null;
  1243. s.parentNode.bubble(function(){
  1244. if(this.nextSibling){
  1245. newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);
  1246. return false;
  1247. }
  1248. });
  1249. return newS;
  1250. }
  1251. return null;
  1252. },
  1253. onKeyDown : function(e){
  1254. var s = this.selNode || this.lastSelNode;
  1255. // undesirable, but required
  1256. var sm = this;
  1257. if(!s){
  1258. return;
  1259. }
  1260. var k = e.getKey();
  1261. switch(k){
  1262. case e.DOWN:
  1263. e.stopEvent();
  1264. this.selectNext();
  1265. break;
  1266. case e.UP:
  1267. e.stopEvent();
  1268. this.selectPrevious();
  1269. break;
  1270. case e.RIGHT:
  1271. e.preventDefault();
  1272. if(s.hasChildNodes()){
  1273. if(!s.isExpanded()){
  1274. s.expand();
  1275. }else if(s.firstChild){
  1276. this.select(s.firstChild, e);
  1277. }
  1278. }
  1279. break;
  1280. case e.LEFT:
  1281. e.preventDefault();
  1282. if(s.hasChildNodes() && s.isExpanded()){
  1283. s.collapse();
  1284. }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
  1285. this.select(s.parentNode, e);
  1286. }
  1287. break;
  1288. };
  1289. }
  1290. });
  1291. /**
  1292. * @class Ext.tree.MultiSelectionModel
  1293. * @extends Ext.util.Observable
  1294. * Multi selection for a TreePanel.
  1295. */
  1296. Ext.tree.MultiSelectionModel = Ext.extend(Ext.util.Observable, {
  1297. constructor : function(config){
  1298. this.selNodes = [];
  1299. this.selMap = {};
  1300. this.addEvents(
  1301. /**
  1302. * @event selectionchange
  1303. * Fires when the selected nodes change
  1304. * @param {MultiSelectionModel} this
  1305. * @param {Array} nodes Array of the selected nodes
  1306. */
  1307. 'selectionchange'
  1308. );
  1309. Ext.apply(this, config);
  1310. Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
  1311. },
  1312. init : function(tree){
  1313. this.tree = tree;
  1314. tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
  1315. tree.on('click', this.onNodeClick, this);
  1316. },
  1317. onNodeClick : function(node, e){
  1318. if(e.ctrlKey && this.isSelected(node)){
  1319. this.unselect(node);
  1320. }else{
  1321. this.select(node, e, e.ctrlKey);
  1322. }
  1323. },
  1324. /**
  1325. * Select a node.
  1326. * @param {TreeNode} node The node to select
  1327. * @param {EventObject} e (optional) An event associated with the selection
  1328. * @param {Boolean} keepExisting (optional) True to retain existing selections
  1329. * @return {TreeNode} The selected node
  1330. */
  1331. select : function(node, e, keepExisting){
  1332. if(keepExisting !== true){
  1333. this.clearSelections(true);
  1334. }
  1335. if(this.isSelected(node)){
  1336. this.lastSelNode = node;
  1337. return node;
  1338. }
  1339. this.selNodes.push(node);
  1340. this.selMap[node.id] = node;
  1341. this.lastSelNode = node;
  1342. node.ui.onSelectedChange(true);
  1343. this.fireEvent('selectionchange', this, this.selNodes);
  1344. return node;
  1345. },
  1346. /**
  1347. * Deselect a node.
  1348. * @param {TreeNode} node The node to unselect
  1349. */
  1350. unselect : function(node){
  1351. if(this.selMap[node.id]){
  1352. node.ui.onSelectedChange(false);
  1353. var sn = this.selNodes;
  1354. var index = sn.indexOf(node);
  1355. if(index != -1){
  1356. this.selNodes.splice(index, 1);
  1357. }
  1358. delete this.selMap[node.id];
  1359. this.fireEvent('selectionchange', this, this.selNodes);
  1360. }
  1361. },
  1362. /**
  1363. * Clear all selections
  1364. */
  1365. clearSelections : function(suppressEvent){
  1366. var sn = this.selNodes;
  1367. if(sn.length > 0){
  1368. for(var i = 0, len = sn.length; i < len; i++){
  1369. sn[i].ui.onSelectedChange(false);
  1370. }
  1371. this.selNodes = [];
  1372. this.selMap = {};
  1373. if(suppressEvent !== true){
  1374. this.fireEvent('selectionchange', this, this.selNodes);
  1375. }
  1376. }
  1377. },
  1378. /**
  1379. * Returns true if the node is selected
  1380. * @param {TreeNode} node The node to check
  1381. * @return {Boolean}
  1382. */
  1383. isSelected : function(node){
  1384. return this.selMap[node.id] ? true : false;
  1385. },
  1386. /**
  1387. * Returns an array of the selected nodes
  1388. * @return {Array}
  1389. */
  1390. getSelectedNodes : function(){
  1391. return this.selNodes.concat([]);
  1392. },
  1393. onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
  1394. selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
  1395. selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
  1396. });/**
  1397. * @class Ext.data.Tree
  1398. * @extends Ext.util.Observable
  1399. * Represents a tree data structure and bubbles all the events for its nodes. The nodes
  1400. * in the tree have most standard DOM functionality.
  1401. * @constructor
  1402. * @param {Node} root (optional) The root node
  1403. */
  1404. Ext.data.Tree = Ext.extend(Ext.util.Observable, {
  1405. constructor: function(root){
  1406. this.nodeHash = {};
  1407. /**
  1408. * The root node for this tree
  1409. * @type Node
  1410. */
  1411. this.root = null;
  1412. if(root){
  1413. this.setRootNode(root);
  1414. }
  1415. this.addEvents(
  1416. /**
  1417. * @event append
  1418. * Fires when a new child node is appended to a node in this tree.
  1419. * @param {Tree} tree The owner tree
  1420. * @param {Node} parent The parent node
  1421. * @param {Node} node The newly appended node
  1422. * @param {Number} index The index of the newly appended node
  1423. */
  1424. "append",
  1425. /**
  1426. * @event remove
  1427. * Fires when a child node is removed from a node in this tree.
  1428. * @param {Tree} tree The owner tree
  1429. * @param {Node} parent The parent node
  1430. * @param {Node} node The child node removed
  1431. */
  1432. "remove",
  1433. /**
  1434. * @event move
  1435. * Fires when a node is moved to a new location in the tree
  1436. * @param {Tree} tree The owner tree
  1437. * @param {Node} node The node moved
  1438. * @param {Node} oldParent The old parent of this node
  1439. * @param {Node} newParent The new parent of this node
  1440. * @param {Number} index The index it was moved to
  1441. */
  1442. "move",
  1443. /**
  1444. * @event insert
  1445. * Fires when a new child node is inserted in a node in this tree.
  1446. * @param {Tree} tree The owner tree
  1447. * @param {Node} parent The parent node
  1448. * @param {Node} node The child node inserted
  1449. * @param {Node} refNode The child node the node was inserted before
  1450. */
  1451. "insert",
  1452. /**
  1453. * @event beforeappend
  1454. * Fires before a new child is appended to a node in this tree, return false to cancel the append.
  1455. * @param {Tree} tree The owner tree
  1456. * @param {Node} parent The parent node
  1457. * @param {Node} node The child node to be appended
  1458. */
  1459. "beforeappend",
  1460. /**
  1461. * @event beforeremove
  1462. * Fires before a child is removed from a node in this tree, return false to cancel the remove.
  1463. * @param {Tree} tree The owner tree
  1464. * @param {Node} parent The parent node
  1465. * @param {Node} node The child node to be removed
  1466. */
  1467. "beforeremove",
  1468. /**
  1469. * @event beforemove
  1470. * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
  1471. * @param {Tree} tree The owner tree
  1472. * @param {Node} node The node being moved
  1473. * @param {Node} oldParent The parent of the node
  1474. * @param {Node} newParent The new parent the node is moving to
  1475. * @param {Number} index The index it is being moved to
  1476. */
  1477. "beforemove",
  1478. /**
  1479. * @event beforeinsert
  1480. * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
  1481. * @param {Tree} tree The owner tree
  1482. * @param {Node} parent The parent node
  1483. * @param {Node} node The child node to be inserted
  1484. * @param {Node} refNode The child node the node is being inserted before
  1485. */
  1486. "beforeinsert"
  1487. );
  1488. Ext.data.Tree.superclass.constructor.call(this);
  1489. },
  1490. /**
  1491. * @cfg {String} pathSeparator
  1492. * The token used to separate paths in node ids (defaults to '/').
  1493. */
  1494. pathSeparator: "/",
  1495. // private
  1496. proxyNodeEvent : function(){
  1497. return this.fireEvent.apply(this, arguments);
  1498. },
  1499. /**
  1500. * Returns the root node for this tree.
  1501. * @return {Node}
  1502. */
  1503. getRootNode : function(){
  1504. return this.root;
  1505. },
  1506. /**
  1507. * Sets the root node for this tree.
  1508. * @param {Node} node
  1509. * @return {Node}
  1510. */
  1511. setRootNode : function(node){
  1512. this.root = node;
  1513. node.ownerTree = this;
  1514. node.isRoot = true;
  1515. this.registerNode(node);
  1516. return node;
  1517. },
  1518. /**
  1519. * Gets a node in this tree by its id.
  1520. * @param {String} id
  1521. * @return {Node}
  1522. */
  1523. getNodeById : function(id){
  1524. return this.nodeHash[id];
  1525. },
  1526. // private
  1527. registerNode : function(node){
  1528. this.nodeHash[node.id] = node;
  1529. },
  1530. // private
  1531. unregisterNode : function(node){
  1532. delete this.nodeHash[node.id];
  1533. },
  1534. toString : function(){
  1535. return "[Tree"+(this.id?" "+this.id:"")+"]";
  1536. }
  1537. });
  1538. /**
  1539. * @class Ext.data.Node
  1540. * @extends Ext.util.Observable
  1541. * @cfg {Boolean} leaf true if this node is a leaf and does not have children
  1542. * @cfg {String} id The id for this node. If one is not specified, one is generated.
  1543. * @constructor
  1544. * @param {Object} attributes The attributes/config for the node
  1545. */
  1546. Ext.data.Node = Ext.extend(Ext.util.Observable, {
  1547. constructor: function(attributes){
  1548. /**
  1549. * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
  1550. * @type {Object}
  1551. */
  1552. this.attributes = attributes || {};
  1553. this.leaf = this.attributes.leaf;
  1554. /**
  1555. * The node id. @type String
  1556. */
  1557. this.id = this.attributes.id;
  1558. if(!this.id){
  1559. this.id = Ext.id(null, "xnode-");
  1560. this.attributes.id = this.id;
  1561. }
  1562. /**
  1563. * All child nodes of this node. @type Array
  1564. */
  1565. this.childNodes = [];
  1566. /**
  1567. * The parent node for this node. @type Node
  1568. */
  1569. this.parentNode = null;
  1570. /**
  1571. * The first direct child node of this node, or null if this node has no child nodes. @type Node
  1572. */
  1573. this.firstChild = null;
  1574. /**
  1575. * The last direct child node of this node, or null if this node has no child nodes. @type Node
  1576. */
  1577. this.lastChild = null;
  1578. /**
  1579. * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
  1580. */
  1581. this.previousSibling = null;
  1582. /**
  1583. * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
  1584. */
  1585. this.nextSibling = null;
  1586. this.addEvents({
  1587. /**
  1588. * @event append
  1589. * Fires when a new child node is appended
  1590. * @param {Tree} tree The owner tree
  1591. * @param {Node} this This node
  1592. * @param {Node} node The newly appended node
  1593. * @param {Number} index The index of the newly appended node
  1594. */
  1595. "append" : true,
  1596. /**
  1597. * @event remove
  1598. * Fires when a child node is removed
  1599. * @param {Tree} tree The owner tree
  1600. * @param {Node} this This node
  1601. * @param {Node} node The removed node
  1602. */
  1603. "remove" : true,
  1604. /**
  1605. * @event move
  1606. * Fires when this node is moved to a new location in the tree
  1607. * @param {Tree} tree The owner tree
  1608. * @param {Node} this This node
  1609. * @param {Node} oldParent The old parent of this node
  1610. * @param {Node} newParent The new parent of this node
  1611. * @param {Number} index The index it was moved to
  1612. */
  1613. "move" : true,
  1614. /**
  1615. * @event insert
  1616. * Fires when a new child node is inserted.
  1617. * @param {Tree} tree The owner tree
  1618. * @param {Node} this This node
  1619. * @param {Node} node The child node inserted
  1620. * @param {Node} refNode The child node the node was inserted before
  1621. */
  1622. "insert" : true,
  1623. /**
  1624. * @event beforeappend
  1625. * Fires before a new child is appended, return false to cancel the append.
  1626. * @param {Tree} tree The owner tree
  1627. * @param {Node} this This node
  1628. * @param {Node} node The child node to be appended
  1629. */
  1630. "beforeappend" : true,
  1631. /**
  1632. * @event beforeremove
  1633. * Fires before a child is removed, return false to cancel the remove.
  1634. * @param {Tree} tree The owner tree
  1635. * @param {Node} this This node
  1636. * @param {Node} node The child node to be removed
  1637. */
  1638. "beforeremove" : true,
  1639. /**
  1640. * @event beforemove
  1641. * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
  1642. * @param {Tree} tree The owner tree
  1643. * @param {Node} this This node
  1644. * @param {Node} oldParent The parent of this node
  1645. * @param {Node} newParent The new parent this node is moving to
  1646. * @param {Number} index The index it is being moved to
  1647. */
  1648. "beforemove" : true,
  1649. /**
  1650. * @event beforeinsert
  1651. * Fires before a new child is inserted, return false to cancel the insert.
  1652. * @param {Tree} tree The owner tree
  1653. * @param {Node} this This node
  1654. * @param {Node} node The child node to be inserted
  1655. * @param {Node} refNode The child node the node is being inserted before
  1656. */
  1657. "beforeinsert" : true
  1658. });
  1659. this.listeners = this.attributes.listeners;
  1660. Ext.data.Node.superclass.constructor.call(this);
  1661. },
  1662. // private
  1663. fireEvent : function(evtName){
  1664. // first do standard event for this node
  1665. if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){
  1666. return false;
  1667. }
  1668. // then bubble it up to the tree if the event wasn't cancelled
  1669. var ot = this.getOwnerTree();
  1670. if(ot){
  1671. if(ot.proxyNodeEvent.apply(ot, arguments) === false){
  1672. return false;
  1673. }
  1674. }
  1675. return true;
  1676. },
  1677. /**
  1678. * Returns true if this node is a leaf
  1679. * @return {Boolean}
  1680. */
  1681. isLeaf : function(){
  1682. return this.leaf === true;
  1683. },
  1684. // private
  1685. setFirstChild : function(node){
  1686. this.firstChild = node;
  1687. },
  1688. //private
  1689. setLastChild : function(node){
  1690. this.lastChild = node;
  1691. },
  1692. /**
  1693. * Returns true if this node is the last child of its parent
  1694. * @return {Boolean}
  1695. */
  1696. isLast : function(){
  1697. return (!this.parentNode ? true : this.parentNode.lastChild == this);
  1698. },
  1699. /**
  1700. * Returns true if this node is the first child of its parent
  1701. * @return {Boolean}
  1702. */
  1703. isFirst : function(){
  1704. return (!this.parentNode ? true : this.parentNode.firstChild == this);
  1705. },
  1706. /**
  1707. * Returns true if this node has one or more child nodes, else false.
  1708. * @return {Boolean}
  1709. */
  1710. hasChildNodes : function(){
  1711. return !this.isLeaf() && this.childNodes.length > 0;
  1712. },
  1713. /**
  1714. * Returns true if this node has one or more child nodes, or if the <tt>expandable</tt>
  1715. * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
  1716. * @return {Boolean}
  1717. */
  1718. isExpandable : function(){
  1719. return this.attributes.expandable || this.hasChildNodes();
  1720. },
  1721. /**
  1722. * Insert node(s) as the last child node of this node.
  1723. * @param {Node/Array} node The node or Array of nodes to append
  1724. * @return {Node} The appended node if single append, or null if an array was passed
  1725. */
  1726. appendChild : function(node){
  1727. var multi = false;
  1728. if(Ext.isArray(node)){
  1729. multi = node;
  1730. }else if(arguments.length > 1){
  1731. multi = arguments;
  1732. }
  1733. // if passed an array or multiple args do them one by one
  1734. if(multi){
  1735. for(var i = 0, len = multi.length; i < len; i++) {
  1736. this.appendChild(multi[i]);
  1737. }
  1738. }else{
  1739. if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
  1740. return false;
  1741. }
  1742. var index = this.childNodes.length;
  1743. var oldParent = node.parentNode;
  1744. // it's a move, make sure we move it cleanly
  1745. if(oldParent){
  1746. if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
  1747. return false;
  1748. }
  1749. oldParent.removeChild(node);
  1750. }
  1751. index = this.childNodes.length;
  1752. if(index === 0){
  1753. this.setFirstChild(node);
  1754. }
  1755. this.childNodes.push(node);
  1756. node.parentNode = this;
  1757. var ps = this.childNodes[index-1];
  1758. if(ps){
  1759. node.previousSibling = ps;
  1760. ps.nextSibling = node;
  1761. }else{
  1762. node.previousSibling = null;
  1763. }
  1764. node.nextSibling = null;
  1765. this.setLastChild(node);
  1766. node.setOwnerTree(this.getOwnerTree());
  1767. this.fireEvent("append", this.ownerTree, this, node, index);
  1768. if(oldParent){
  1769. node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
  1770. }
  1771. return node;
  1772. }
  1773. },
  1774. /**
  1775. * Removes a child node from this node.
  1776. * @param {Node} node The node to remove
  1777. * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
  1778. * @return {Node} The removed node
  1779. */
  1780. removeChild : function(node, destroy){
  1781. var index = this.childNodes.indexOf(node);
  1782. if(index == -1){
  1783. return false;
  1784. }
  1785. if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
  1786. return false;
  1787. }
  1788. // remove it from childNodes collection
  1789. this.childNodes.splice(index, 1);
  1790. // update siblings
  1791. if(node.previousSibling){
  1792. node.previousSibling.nextSibling = node.nextSibling;
  1793. }
  1794. if(node.nextSibling){
  1795. node.nextSibling.previousSibling = node.previousSibling;
  1796. }
  1797. // update child refs
  1798. if(this.firstChild == node){
  1799. this.setFirstChild(node.nextSibling);
  1800. }
  1801. if(this.lastChild == node){
  1802. this.setLastChild(node.previousSibling);
  1803. }
  1804. this.fireEvent("remove", this.ownerTree, this, node);
  1805. if(destroy){
  1806. node.destroy(true);
  1807. }else{
  1808. node.clear();
  1809. }
  1810. return node;
  1811. },
  1812. // private
  1813. clear : function(destroy){
  1814. // clear any references from the node
  1815. this.setOwnerTree(null, destroy);
  1816. this.parentNode = this.previousSibling = this.nextSibling = null;
  1817. if(destroy){
  1818. this.firstChild = this.lastChild = null;
  1819. }
  1820. },
  1821. /**
  1822. * Destroys the node.
  1823. */
  1824. destroy : function(/* private */ silent){
  1825. /*
  1826. * Silent is to be used in a number of cases
  1827. * 1) When setRootNode is called.
  1828. * 2) When destroy on the tree is called
  1829. * 3) For destroying child nodes on a node
  1830. */
  1831. if(silent === true){
  1832. this.purgeListeners();
  1833. this.clear(true);
  1834. Ext.each(this.childNodes, function(n){
  1835. n.destroy(true);
  1836. });
  1837. this.childNodes = null;
  1838. }else{
  1839. this.remove(true);
  1840. }
  1841. },
  1842. /**
  1843. * Inserts the first node before the second node in this nodes childNodes collection.
  1844. * @param {Node} node The node to insert
  1845. * @param {Node} refNode The node to insert before (if null the node is appended)
  1846. * @return {Node} The inserted node
  1847. */
  1848. insertBefore : function(node, refNode){
  1849. if(!refNode){ // like standard Dom, refNode can be null for append
  1850. return this.appendChild(node);
  1851. }
  1852. // nothing to do
  1853. if(node == refNode){
  1854. return false;
  1855. }
  1856. if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
  1857. return false;
  1858. }
  1859. var index = this.childNodes.indexOf(refNode);
  1860. var oldParent = node.parentNode;
  1861. var refIndex = index;
  1862. // when moving internally, indexes will change after remove
  1863. if(oldParent == this && this.childNodes.indexOf(node) < index){
  1864. refIndex--;
  1865. }
  1866. // it's a move, make sure we move it cleanly
  1867. if(oldParent){
  1868. if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
  1869. return false;
  1870. }
  1871. oldParent.removeChild(node);
  1872. }
  1873. if(refIndex === 0){
  1874. this.setFirstChild(node);
  1875. }
  1876. this.childNodes.splice(refIndex, 0, node);
  1877. node.parentNode = this;
  1878. var ps = this.childNodes[refIndex-1];
  1879. if(ps){
  1880. node.previousSibling = ps;
  1881. ps.nextSibling = node;
  1882. }else{
  1883. node.previousSibling = null;
  1884. }
  1885. node.nextSibling = refNode;
  1886. refNode.previousSibling = node;
  1887. node.setOwnerTree(this.getOwnerTree());
  1888. this.fireEvent("insert", this.ownerTree, this, node, refNode);
  1889. if(oldParent){
  1890. node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
  1891. }
  1892. return node;
  1893. },
  1894. /**
  1895. * Removes this node from its parent
  1896. * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
  1897. * @return {Node} this
  1898. */
  1899. remove : function(destroy){
  1900. if (this.parentNode) {
  1901. this.parentNode.removeChild(this, destroy);
  1902. }
  1903. return this;
  1904. },
  1905. /**
  1906. * Removes all child nodes from this node.
  1907. * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.
  1908. * @return {Node} this
  1909. */
  1910. removeAll : function(destroy){
  1911. var cn = this.childNodes,
  1912. n;
  1913. while((n = cn[0])){
  1914. this.removeChild(n, destroy);
  1915. }
  1916. return this;
  1917. },
  1918. /**
  1919. * Returns the child node at the specified index.
  1920. * @param {Number} index
  1921. * @return {Node}
  1922. */
  1923. item : function(index){
  1924. return this.childNodes[index];
  1925. },
  1926. /**
  1927. * Replaces one child node in this node with another.
  1928. * @param {Node} newChild The replacement node
  1929. * @param {Node} oldChild The node to replace
  1930. * @return {Node} The replaced node
  1931. */
  1932. replaceChild : function(newChild, oldChild){
  1933. var s = oldChild ? oldChild.nextSibling : null;
  1934. this.removeChild(oldChild);
  1935. this.insertBefore(newChild, s);
  1936. return oldChild;
  1937. },
  1938. /**
  1939. * Returns the index of a child node
  1940. * @param {Node} node
  1941. * @return {Number} The index of the node or -1 if it was not found
  1942. */
  1943. indexOf : function(child){
  1944. return this.childNodes.indexOf(child);
  1945. },
  1946. /**
  1947. * Returns the tree this node is in.
  1948. * @return {Tree}
  1949. */
  1950. getOwnerTree : function(){
  1951. // if it doesn't have one, look for one
  1952. if(!this.ownerTree){
  1953. var p = this;
  1954. while(p){
  1955. if(p.ownerTree){
  1956. this.ownerTree = p.ownerTree;
  1957. break;
  1958. }
  1959. p = p.parentNode;
  1960. }
  1961. }
  1962. return this.ownerTree;
  1963. },
  1964. /**
  1965. * Returns depth of this node (the root node has a depth of 0)
  1966. * @return {Number}
  1967. */
  1968. getDepth : function(){
  1969. var depth = 0;
  1970. var p = this;
  1971. while(p.parentNode){
  1972. ++depth;
  1973. p = p.parentNode;
  1974. }
  1975. return depth;
  1976. },
  1977. // private
  1978. setOwnerTree : function(tree, destroy){
  1979. // if it is a move, we need to update everyone
  1980. if(tree != this.ownerTree){
  1981. if(this.ownerTree){
  1982. this.ownerTree.unregisterNode(this);
  1983. }
  1984. this.ownerTree = tree;
  1985. // If we're destroying, we don't need to recurse since it will be called on each child node
  1986. if(destroy !== true){
  1987. Ext.each(this.childNodes, function(n){
  1988. n.setOwnerTree(tree);
  1989. });
  1990. }
  1991. if(tree){
  1992. tree.registerNode(this);
  1993. }
  1994. }
  1995. },
  1996. /**
  1997. * Changes the id of this node.
  1998. * @param {String} id The new id for the node.
  1999. */
  2000. setId: function(id){
  2001. if(id !== this.id){
  2002. var t = this.ownerTree;
  2003. if(t){
  2004. t.unregisterNode(this);
  2005. }
  2006. this.id = this.attributes.id = id;
  2007. if(t){
  2008. t.registerNode(this);
  2009. }
  2010. this.onIdChange(id);
  2011. }
  2012. },
  2013. // private
  2014. onIdChange: Ext.emptyFn,
  2015. /**
  2016. * Returns the path for this node. The path can be used to expand or select this node programmatically.
  2017. * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
  2018. * @return {String} The path
  2019. */
  2020. getPath : function(attr){
  2021. attr = attr || "id";
  2022. var p = this.parentNode;
  2023. var b = [this.attributes[attr]];
  2024. while(p){
  2025. b.unshift(p.attributes[attr]);
  2026. p = p.parentNode;
  2027. }
  2028. var sep = this.getOwnerTree().pathSeparator;
  2029. return sep + b.join(sep);
  2030. },
  2031. /**
  2032. * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function
  2033. * will be the args provided or the current node. If the function returns false at any point,
  2034. * the bubble is stopped.
  2035. * @param {Function} fn The function to call
  2036. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
  2037. * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
  2038. */
  2039. bubble : function(fn, scope, args){
  2040. var p = this;
  2041. while(p){
  2042. if(fn.apply(scope || p, args || [p]) === false){
  2043. break;
  2044. }
  2045. p = p.parentNode;
  2046. }
  2047. },
  2048. /**
  2049. * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function
  2050. * will be the args provided or the current node. If the function returns false at any point,
  2051. * the cascade is stopped on that branch.
  2052. * @param {Function} fn The function to call
  2053. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
  2054. * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
  2055. */
  2056. cascade : function(fn, scope, args){
  2057. if(fn.apply(scope || this, args || [this]) !== false){
  2058. var cs = this.childNodes;
  2059. for(var i = 0, len = cs.length; i < len; i++) {
  2060. cs[i].cascade(fn, scope, args);
  2061. }
  2062. }
  2063. },
  2064. /**
  2065. * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function
  2066. * will be the args provided or the current node. If the function returns false at any point,
  2067. * the iteration stops.
  2068. * @param {Function} fn The function to call
  2069. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node in the iteration.
  2070. * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
  2071. */
  2072. eachChild : function(fn, scope, args){
  2073. var cs = this.childNodes;
  2074. for(var i = 0, len = cs.length; i < len; i++) {
  2075. if(fn.apply(scope || cs[i], args || [cs[i]]) === false){
  2076. break;
  2077. }
  2078. }
  2079. },
  2080. /**
  2081. * Finds the first child that has the attribute with the specified value.
  2082. * @param {String} attribute The attribute name
  2083. * @param {Mixed} value The value to search for
  2084. * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
  2085. * @return {Node} The found child or null if none was found
  2086. */
  2087. findChild : function(attribute, value, deep){
  2088. return this.findChildBy(function(){
  2089. return this.attributes[attribute] == value;
  2090. }, null, deep);
  2091. },
  2092. /**
  2093. * Finds the first child by a custom function. The child matches if the function passed returns <code>true</code>.
  2094. * @param {Function} fn A function which must return <code>true</code> if the passed Node is the required Node.
  2095. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Node being tested.
  2096. * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
  2097. * @return {Node} The found child or null if none was found
  2098. */
  2099. findChildBy : function(fn, scope, deep){
  2100. var cs = this.childNodes,
  2101. len = cs.length,
  2102. i = 0,
  2103. n,
  2104. res;
  2105. for(; i < len; i++){
  2106. n = cs[i];
  2107. if(fn.call(scope || n, n) === true){
  2108. return n;
  2109. }else if (deep){
  2110. res = n.findChildBy(fn, scope, deep);
  2111. if(res != null){
  2112. return res;
  2113. }
  2114. }
  2115. }
  2116. return null;
  2117. },
  2118. /**
  2119. * Sorts this nodes children using the supplied sort function.
  2120. * @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.
  2121. * @param {Object} scope (optional)The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  2122. */
  2123. sort : function(fn, scope){
  2124. var cs = this.childNodes;
  2125. var len = cs.length;
  2126. if(len > 0){
  2127. var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
  2128. cs.sort(sortFn);
  2129. for(var i = 0; i < len; i++){
  2130. var n = cs[i];
  2131. n.previousSibling = cs[i-1];
  2132. n.nextSibling = cs[i+1];
  2133. if(i === 0){
  2134. this.setFirstChild(n);
  2135. }
  2136. if(i == len-1){
  2137. this.setLastChild(n);
  2138. }
  2139. }
  2140. }
  2141. },
  2142. /**
  2143. * Returns true if this node is an ancestor (at any point) of the passed node.
  2144. * @param {Node} node
  2145. * @return {Boolean}
  2146. */
  2147. contains : function(node){
  2148. return node.isAncestor(this);
  2149. },
  2150. /**
  2151. * Returns true if the passed node is an ancestor (at any point) of this node.
  2152. * @param {Node} node
  2153. * @return {Boolean}
  2154. */
  2155. isAncestor : function(node){
  2156. var p = this.parentNode;
  2157. while(p){
  2158. if(p == node){
  2159. return true;
  2160. }
  2161. p = p.parentNode;
  2162. }
  2163. return false;
  2164. },
  2165. toString : function(){
  2166. return "[Node"+(this.id?" "+this.id:"")+"]";
  2167. }
  2168. });/**
  2169. * @class Ext.tree.TreeNode
  2170. * @extends Ext.data.Node
  2171. * @cfg {String} text The text for this node
  2172. * @cfg {Boolean} expanded true to start the node expanded
  2173. * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)
  2174. * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)
  2175. * @cfg {Boolean} disabled true to start the node disabled
  2176. * @cfg {String} icon The path to an icon for the node. The preferred way to do this
  2177. * is to use the cls or iconCls attributes and add the icon via a CSS background image.
  2178. * @cfg {String} cls A css class to be added to the node
  2179. * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
  2180. * @cfg {String} href URL of the link used for the node (defaults to #)
  2181. * @cfg {String} hrefTarget target frame for the link
  2182. * @cfg {Boolean} hidden True to render hidden. (Defaults to false).
  2183. * @cfg {String} qtip An Ext QuickTip for the node
  2184. * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
  2185. * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
  2186. * @cfg {Boolean} singleClickExpand True for single click expand on this node
  2187. * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)
  2188. * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
  2189. * (defaults to undefined with no checkbox rendered)
  2190. * @cfg {Boolean} draggable True to make this node draggable (defaults to false)
  2191. * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)
  2192. * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)
  2193. * @cfg {Boolean} editable False to not allow this node to be edited by an {@link Ext.tree.TreeEditor} (defaults to true)
  2194. * @constructor
  2195. * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
  2196. */
  2197. Ext.tree.TreeNode = Ext.extend(Ext.data.Node, {
  2198. constructor : function(attributes){
  2199. attributes = attributes || {};
  2200. if(Ext.isString(attributes)){
  2201. attributes = {text: attributes};
  2202. }
  2203. this.childrenRendered = false;
  2204. this.rendered = false;
  2205. Ext.tree.TreeNode.superclass.constructor.call(this, attributes);
  2206. this.expanded = attributes.expanded === true;
  2207. this.isTarget = attributes.isTarget !== false;
  2208. this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
  2209. this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
  2210. /**
  2211. * Read-only. The text for this node. To change it use <code>{@link #setText}</code>.
  2212. * @type String
  2213. */
  2214. this.text = attributes.text;
  2215. /**
  2216. * True if this node is disabled.
  2217. * @type Boolean
  2218. */
  2219. this.disabled = attributes.disabled === true;
  2220. /**
  2221. * True if this node is hidden.
  2222. * @type Boolean
  2223. */
  2224. this.hidden = attributes.hidden === true;
  2225. this.addEvents(
  2226. /**
  2227. * @event textchange
  2228. * Fires when the text for this node is changed
  2229. * @param {Node} this This node
  2230. * @param {String} text The new text
  2231. * @param {String} oldText The old text
  2232. */
  2233. 'textchange',
  2234. /**
  2235. * @event beforeexpand
  2236. * Fires before this node is expanded, return false to cancel.
  2237. * @param {Node} this This node
  2238. * @param {Boolean} deep
  2239. * @param {Boolean} anim
  2240. */
  2241. 'beforeexpand',
  2242. /**
  2243. * @event beforecollapse
  2244. * Fires before this node is collapsed, return false to cancel.
  2245. * @param {Node} this This node
  2246. * @param {Boolean} deep
  2247. * @param {Boolean} anim
  2248. */
  2249. 'beforecollapse',
  2250. /**
  2251. * @event expand
  2252. * Fires when this node is expanded
  2253. * @param {Node} this This node
  2254. */
  2255. 'expand',
  2256. /**
  2257. * @event disabledchange
  2258. * Fires when the disabled status of this node changes
  2259. * @param {Node} this This node
  2260. * @param {Boolean} disabled
  2261. */
  2262. 'disabledchange',
  2263. /**
  2264. * @event collapse
  2265. * Fires when this node is collapsed
  2266. * @param {Node} this This node
  2267. */
  2268. 'collapse',
  2269. /**
  2270. * @event beforeclick
  2271. * Fires before click processing. Return false to cancel the default action.
  2272. * @param {Node} this This node
  2273. * @param {Ext.EventObject} e The event object
  2274. */
  2275. 'beforeclick',
  2276. /**
  2277. * @event click
  2278. * Fires when this node is clicked
  2279. * @param {Node} this This node
  2280. * @param {Ext.EventObject} e The event object
  2281. */
  2282. 'click',
  2283. /**
  2284. * @event checkchange
  2285. * Fires when a node with a checkbox's checked property changes
  2286. * @param {Node} this This node
  2287. * @param {Boolean} checked
  2288. */
  2289. 'checkchange',
  2290. /**
  2291. * @event beforedblclick
  2292. * Fires before double click processing. Return false to cancel the default action.
  2293. * @param {Node} this This node
  2294. * @param {Ext.EventObject} e The event object
  2295. */
  2296. 'beforedblclick',
  2297. /**
  2298. * @event dblclick
  2299. * Fires when this node is double clicked
  2300. * @param {Node} this This node
  2301. * @param {Ext.EventObject} e The event object
  2302. */
  2303. 'dblclick',
  2304. /**
  2305. * @event contextmenu
  2306. * Fires when this node is right clicked
  2307. * @param {Node} this This node
  2308. * @param {Ext.EventObject} e The event object
  2309. */
  2310. 'contextmenu',
  2311. /**
  2312. * @event beforechildrenrendered
  2313. * Fires right before the child nodes for this node are rendered
  2314. * @param {Node} this This node
  2315. */
  2316. 'beforechildrenrendered'
  2317. );
  2318. var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;
  2319. /**
  2320. * Read-only. The UI for this node
  2321. * @type TreeNodeUI
  2322. */
  2323. this.ui = new uiClass(this);
  2324. },
  2325. preventHScroll : true,
  2326. /**
  2327. * Returns true if this node is expanded
  2328. * @return {Boolean}
  2329. */
  2330. isExpanded : function(){
  2331. return this.expanded;
  2332. },
  2333. /**
  2334. * Returns the UI object for this node.
  2335. * @return {TreeNodeUI} The object which is providing the user interface for this tree
  2336. * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance
  2337. * of {@link Ext.tree.TreeNodeUI}
  2338. */
  2339. getUI : function(){
  2340. return this.ui;
  2341. },
  2342. getLoader : function(){
  2343. var owner;
  2344. return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : (this.loader = new Ext.tree.TreeLoader()));
  2345. },
  2346. // private override
  2347. setFirstChild : function(node){
  2348. var of = this.firstChild;
  2349. Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);
  2350. if(this.childrenRendered && of && node != of){
  2351. of.renderIndent(true, true);
  2352. }
  2353. if(this.rendered){
  2354. this.renderIndent(true, true);
  2355. }
  2356. },
  2357. // private override
  2358. setLastChild : function(node){
  2359. var ol = this.lastChild;
  2360. Ext.tree.TreeNode.superclass.setLastChild.call(this, node);
  2361. if(this.childrenRendered && ol && node != ol){
  2362. ol.renderIndent(true, true);
  2363. }
  2364. if(this.rendered){
  2365. this.renderIndent(true, true);
  2366. }
  2367. },
  2368. // these methods are overridden to provide lazy rendering support
  2369. // private override
  2370. appendChild : function(n){
  2371. if(!n.render && !Ext.isArray(n)){
  2372. n = this.getLoader().createNode(n);
  2373. }
  2374. var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);
  2375. if(node && this.childrenRendered){
  2376. node.render();
  2377. }
  2378. this.ui.updateExpandIcon();
  2379. return node;
  2380. },
  2381. // private override
  2382. removeChild : function(node, destroy){
  2383. this.ownerTree.getSelectionModel().unselect(node);
  2384. Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
  2385. // only update the ui if we're not destroying
  2386. if(!destroy){
  2387. var rendered = node.ui.rendered;
  2388. // if it's been rendered remove dom node
  2389. if(rendered){
  2390. node.ui.remove();
  2391. }
  2392. if(rendered && this.childNodes.length < 1){
  2393. this.collapse(false, false);
  2394. }else{
  2395. this.ui.updateExpandIcon();
  2396. }
  2397. if(!this.firstChild && !this.isHiddenRoot()){
  2398. this.childrenRendered = false;
  2399. }
  2400. }
  2401. return node;
  2402. },
  2403. // private override
  2404. insertBefore : function(node, refNode){
  2405. if(!node.render){
  2406. node = this.getLoader().createNode(node);
  2407. }
  2408. var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
  2409. if(newNode && refNode && this.childrenRendered){
  2410. node.render();
  2411. }
  2412. this.ui.updateExpandIcon();
  2413. return newNode;
  2414. },
  2415. /**
  2416. * Sets the text for this node
  2417. * @param {String} text
  2418. */
  2419. setText : function(text){
  2420. var oldText = this.text;
  2421. this.text = this.attributes.text = text;
  2422. if(this.rendered){ // event without subscribing
  2423. this.ui.onTextChange(this, text, oldText);
  2424. }
  2425. this.fireEvent('textchange', this, text, oldText);
  2426. },
  2427. /**
  2428. * Sets the icon class for this node.
  2429. * @param {String} cls
  2430. */
  2431. setIconCls : function(cls){
  2432. var old = this.attributes.iconCls;
  2433. this.attributes.iconCls = cls;
  2434. if(this.rendered){
  2435. this.ui.onIconClsChange(this, cls, old);
  2436. }
  2437. },
  2438. /**
  2439. * Sets the tooltip for this node.
  2440. * @param {String} tip The text for the tip
  2441. * @param {String} title (Optional) The title for the tip
  2442. */
  2443. setTooltip : function(tip, title){
  2444. this.attributes.qtip = tip;
  2445. this.attributes.qtipTitle = title;
  2446. if(this.rendered){
  2447. this.ui.onTipChange(this, tip, title);
  2448. }
  2449. },
  2450. /**
  2451. * Sets the icon for this node.
  2452. * @param {String} icon
  2453. */
  2454. setIcon : function(icon){
  2455. this.attributes.icon = icon;
  2456. if(this.rendered){
  2457. this.ui.onIconChange(this, icon);
  2458. }
  2459. },
  2460. /**
  2461. * Sets the href for the node.
  2462. * @param {String} href The href to set
  2463. * @param {String} (Optional) target The target of the href
  2464. */
  2465. setHref : function(href, target){
  2466. this.attributes.href = href;
  2467. this.attributes.hrefTarget = target;
  2468. if(this.rendered){
  2469. this.ui.onHrefChange(this, href, target);
  2470. }
  2471. },
  2472. /**
  2473. * Sets the class on this node.
  2474. * @param {String} cls
  2475. */
  2476. setCls : function(cls){
  2477. var old = this.attributes.cls;
  2478. this.attributes.cls = cls;
  2479. if(this.rendered){
  2480. this.ui.onClsChange(this, cls, old);
  2481. }
  2482. },
  2483. /**
  2484. * Triggers selection of this node
  2485. */
  2486. select : function(){
  2487. var t = this.getOwnerTree();
  2488. if(t){
  2489. t.getSelectionModel().select(this);
  2490. }
  2491. },
  2492. /**
  2493. * Triggers deselection of this node
  2494. * @param {Boolean} silent (optional) True to stop selection change events from firing.
  2495. */
  2496. unselect : function(silent){
  2497. var t = this.getOwnerTree();
  2498. if(t){
  2499. t.getSelectionModel().unselect(this, silent);
  2500. }
  2501. },
  2502. /**
  2503. * Returns true if this node is selected
  2504. * @return {Boolean}
  2505. */
  2506. isSelected : function(){
  2507. var t = this.getOwnerTree();
  2508. return t ? t.getSelectionModel().isSelected(this) : false;
  2509. },
  2510. /**
  2511. * Expand this node.
  2512. * @param {Boolean} deep (optional) True to expand all children as well
  2513. * @param {Boolean} anim (optional) false to cancel the default animation
  2514. * @param {Function} callback (optional) A callback to be called when
  2515. * expanding this node completes (does not wait for deep expand to complete).
  2516. * Called with 1 parameter, this node.
  2517. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
  2518. */
  2519. expand : function(deep, anim, callback, scope){
  2520. if(!this.expanded){
  2521. if(this.fireEvent('beforeexpand', this, deep, anim) === false){
  2522. return;
  2523. }
  2524. if(!this.childrenRendered){
  2525. this.renderChildren();
  2526. }
  2527. this.expanded = true;
  2528. if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
  2529. this.ui.animExpand(function(){
  2530. this.fireEvent('expand', this);
  2531. this.runCallback(callback, scope || this, [this]);
  2532. if(deep === true){
  2533. this.expandChildNodes(true, true);
  2534. }
  2535. }.createDelegate(this));
  2536. return;
  2537. }else{
  2538. this.ui.expand();
  2539. this.fireEvent('expand', this);
  2540. this.runCallback(callback, scope || this, [this]);
  2541. }
  2542. }else{
  2543. this.runCallback(callback, scope || this, [this]);
  2544. }
  2545. if(deep === true){
  2546. this.expandChildNodes(true);
  2547. }
  2548. },
  2549. runCallback : function(cb, scope, args){
  2550. if(Ext.isFunction(cb)){
  2551. cb.apply(scope, args);
  2552. }
  2553. },
  2554. isHiddenRoot : function(){
  2555. return this.isRoot && !this.getOwnerTree().rootVisible;
  2556. },
  2557. /**
  2558. * Collapse this node.
  2559. * @param {Boolean} deep (optional) True to collapse all children as well
  2560. * @param {Boolean} anim (optional) false to cancel the default animation
  2561. * @param {Function} callback (optional) A callback to be called when
  2562. * expanding this node completes (does not wait for deep expand to complete).
  2563. * Called with 1 parameter, this node.
  2564. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
  2565. */
  2566. collapse : function(deep, anim, callback, scope){
  2567. if(this.expanded && !this.isHiddenRoot()){
  2568. if(this.fireEvent('beforecollapse', this, deep, anim) === false){
  2569. return;
  2570. }
  2571. this.expanded = false;
  2572. if((this.getOwnerTree().animate && anim !== false) || anim){
  2573. this.ui.animCollapse(function(){
  2574. this.fireEvent('collapse', this);
  2575. this.runCallback(callback, scope || this, [this]);
  2576. if(deep === true){
  2577. this.collapseChildNodes(true);
  2578. }
  2579. }.createDelegate(this));
  2580. return;
  2581. }else{
  2582. this.ui.collapse();
  2583. this.fireEvent('collapse', this);
  2584. this.runCallback(callback, scope || this, [this]);
  2585. }
  2586. }else if(!this.expanded){
  2587. this.runCallback(callback, scope || this, [this]);
  2588. }
  2589. if(deep === true){
  2590. var cs = this.childNodes;
  2591. for(var i = 0, len = cs.length; i < len; i++) {
  2592. cs[i].collapse(true, false);
  2593. }
  2594. }
  2595. },
  2596. // private
  2597. delayedExpand : function(delay){
  2598. if(!this.expandProcId){
  2599. this.expandProcId = this.expand.defer(delay, this);
  2600. }
  2601. },
  2602. // private
  2603. cancelExpand : function(){
  2604. if(this.expandProcId){
  2605. clearTimeout(this.expandProcId);
  2606. }
  2607. this.expandProcId = false;
  2608. },
  2609. /**
  2610. * Toggles expanded/collapsed state of the node
  2611. */
  2612. toggle : function(){
  2613. if(this.expanded){
  2614. this.collapse();
  2615. }else{
  2616. this.expand();
  2617. }
  2618. },
  2619. /**
  2620. * Ensures all parent nodes are expanded, and if necessary, scrolls
  2621. * the node into view.
  2622. * @param {Function} callback (optional) A function to call when the node has been made visible.
  2623. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
  2624. */
  2625. ensureVisible : function(callback, scope){
  2626. var tree = this.getOwnerTree();
  2627. tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){
  2628. var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime
  2629. tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
  2630. this.runCallback(callback, scope || this, [this]);
  2631. }.createDelegate(this));
  2632. },
  2633. /**
  2634. * Expand all child nodes
  2635. * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
  2636. */
  2637. expandChildNodes : function(deep, anim) {
  2638. var cs = this.childNodes,
  2639. i,
  2640. len = cs.length;
  2641. for (i = 0; i < len; i++) {
  2642. cs[i].expand(deep, anim);
  2643. }
  2644. },
  2645. /**
  2646. * Collapse all child nodes
  2647. * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
  2648. */
  2649. collapseChildNodes : function(deep){
  2650. var cs = this.childNodes;
  2651. for(var i = 0, len = cs.length; i < len; i++) {
  2652. cs[i].collapse(deep);
  2653. }
  2654. },
  2655. /**
  2656. * Disables this node
  2657. */
  2658. disable : function(){
  2659. this.disabled = true;
  2660. this.unselect();
  2661. if(this.rendered && this.ui.onDisableChange){ // event without subscribing
  2662. this.ui.onDisableChange(this, true);
  2663. }
  2664. this.fireEvent('disabledchange', this, true);
  2665. },
  2666. /**
  2667. * Enables this node
  2668. */
  2669. enable : function(){
  2670. this.disabled = false;
  2671. if(this.rendered && this.ui.onDisableChange){ // event without subscribing
  2672. this.ui.onDisableChange(this, false);
  2673. }
  2674. this.fireEvent('disabledchange', this, false);
  2675. },
  2676. // private
  2677. renderChildren : function(suppressEvent){
  2678. if(suppressEvent !== false){
  2679. this.fireEvent('beforechildrenrendered', this);
  2680. }
  2681. var cs = this.childNodes;
  2682. for(var i = 0, len = cs.length; i < len; i++){
  2683. cs[i].render(true);
  2684. }
  2685. this.childrenRendered = true;
  2686. },
  2687. // private
  2688. sort : function(fn, scope){
  2689. Ext.tree.TreeNode.superclass.sort.apply(this, arguments);
  2690. if(this.childrenRendered){
  2691. var cs = this.childNodes;
  2692. for(var i = 0, len = cs.length; i < len; i++){
  2693. cs[i].render(true);
  2694. }
  2695. }
  2696. },
  2697. // private
  2698. render : function(bulkRender){
  2699. this.ui.render(bulkRender);
  2700. if(!this.rendered){
  2701. // make sure it is registered
  2702. this.getOwnerTree().registerNode(this);
  2703. this.rendered = true;
  2704. if(this.expanded){
  2705. this.expanded = false;
  2706. this.expand(false, false);
  2707. }
  2708. }
  2709. },
  2710. // private
  2711. renderIndent : function(deep, refresh){
  2712. if(refresh){
  2713. this.ui.childIndent = null;
  2714. }
  2715. this.ui.renderIndent();
  2716. if(deep === true && this.childrenRendered){
  2717. var cs = this.childNodes;
  2718. for(var i = 0, len = cs.length; i < len; i++){
  2719. cs[i].renderIndent(true, refresh);
  2720. }
  2721. }
  2722. },
  2723. beginUpdate : function(){
  2724. this.childrenRendered = false;
  2725. },
  2726. endUpdate : function(){
  2727. if(this.expanded && this.rendered){
  2728. this.renderChildren();
  2729. }
  2730. },
  2731. //inherit docs
  2732. destroy : function(silent){
  2733. if(silent === true){
  2734. this.unselect(true);
  2735. }
  2736. Ext.tree.TreeNode.superclass.destroy.call(this, silent);
  2737. Ext.destroy(this.ui, this.loader);
  2738. this.ui = this.loader = null;
  2739. },
  2740. // private
  2741. onIdChange : function(id){
  2742. this.ui.onIdChange(id);
  2743. }
  2744. });
  2745. Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;/**
  2746. * @class Ext.tree.AsyncTreeNode
  2747. * @extends Ext.tree.TreeNode
  2748. * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
  2749. * @constructor
  2750. * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
  2751. */
  2752. Ext.tree.AsyncTreeNode = function(config){
  2753. this.loaded = config && config.loaded === true;
  2754. this.loading = false;
  2755. Ext.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
  2756. /**
  2757. * @event beforeload
  2758. * Fires before this node is loaded, return false to cancel
  2759. * @param {Node} this This node
  2760. */
  2761. this.addEvents('beforeload', 'load');
  2762. /**
  2763. * @event load
  2764. * Fires when this node is loaded
  2765. * @param {Node} this This node
  2766. */
  2767. /**
  2768. * The loader used by this node (defaults to using the tree's defined loader)
  2769. * @type TreeLoader
  2770. * @property loader
  2771. */
  2772. };
  2773. Ext.extend(Ext.tree.AsyncTreeNode, Ext.tree.TreeNode, {
  2774. expand : function(deep, anim, callback, scope){
  2775. if(this.loading){ // if an async load is already running, waiting til it's done
  2776. var timer;
  2777. var f = function(){
  2778. if(!this.loading){ // done loading
  2779. clearInterval(timer);
  2780. this.expand(deep, anim, callback, scope);
  2781. }
  2782. }.createDelegate(this);
  2783. timer = setInterval(f, 200);
  2784. return;
  2785. }
  2786. if(!this.loaded){
  2787. if(this.fireEvent("beforeload", this) === false){
  2788. return;
  2789. }
  2790. this.loading = true;
  2791. this.ui.beforeLoad(this);
  2792. var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
  2793. if(loader){
  2794. loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback, scope]), this);
  2795. return;
  2796. }
  2797. }
  2798. Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback, scope);
  2799. },
  2800. /**
  2801. * Returns true if this node is currently loading
  2802. * @return {Boolean}
  2803. */
  2804. isLoading : function(){
  2805. return this.loading;
  2806. },
  2807. loadComplete : function(deep, anim, callback, scope){
  2808. this.loading = false;
  2809. this.loaded = true;
  2810. this.ui.afterLoad(this);
  2811. this.fireEvent("load", this);
  2812. this.expand(deep, anim, callback, scope);
  2813. },
  2814. /**
  2815. * Returns true if this node has been loaded
  2816. * @return {Boolean}
  2817. */
  2818. isLoaded : function(){
  2819. return this.loaded;
  2820. },
  2821. hasChildNodes : function(){
  2822. if(!this.isLeaf() && !this.loaded){
  2823. return true;
  2824. }else{
  2825. return Ext.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
  2826. }
  2827. },
  2828. /**
  2829. * Trigger a reload for this node
  2830. * @param {Function} callback
  2831. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Node.
  2832. */
  2833. reload : function(callback, scope){
  2834. this.collapse(false, false);
  2835. while(this.firstChild){
  2836. this.removeChild(this.firstChild).destroy();
  2837. }
  2838. this.childrenRendered = false;
  2839. this.loaded = false;
  2840. if(this.isHiddenRoot()){
  2841. this.expanded = false;
  2842. }
  2843. this.expand(false, false, callback, scope);
  2844. }
  2845. });
  2846. Ext.tree.TreePanel.nodeTypes.async = Ext.tree.AsyncTreeNode;/**
  2847. * @class Ext.tree.TreeNodeUI
  2848. * This class provides the default UI implementation for Ext TreeNodes.
  2849. * The TreeNode UI implementation is separate from the
  2850. * tree implementation, and allows customizing of the appearance of
  2851. * tree nodes.<br>
  2852. * <p>
  2853. * If you are customizing the Tree's user interface, you
  2854. * may need to extend this class, but you should never need to instantiate this class.<br>
  2855. * <p>
  2856. * This class provides access to the user interface components of an Ext TreeNode, through
  2857. * {@link Ext.tree.TreeNode#getUI}
  2858. */
  2859. Ext.tree.TreeNodeUI = Ext.extend(Object, {
  2860. constructor : function(node){
  2861. Ext.apply(this, {
  2862. node: node,
  2863. rendered: false,
  2864. animating: false,
  2865. wasLeaf: true,
  2866. ecc: 'x-tree-ec-icon x-tree-elbow',
  2867. emptyIcon: Ext.BLANK_IMAGE_URL
  2868. });
  2869. },
  2870. // private
  2871. removeChild : function(node){
  2872. if(this.rendered){
  2873. this.ctNode.removeChild(node.ui.getEl());
  2874. }
  2875. },
  2876. // private
  2877. beforeLoad : function(){
  2878. this.addClass("x-tree-node-loading");
  2879. },
  2880. // private
  2881. afterLoad : function(){
  2882. this.removeClass("x-tree-node-loading");
  2883. },
  2884. // private
  2885. onTextChange : function(node, text, oldText){
  2886. if(this.rendered){
  2887. this.textNode.innerHTML = text;
  2888. }
  2889. },
  2890. // private
  2891. onIconClsChange : function(node, cls, oldCls){
  2892. if(this.rendered){
  2893. Ext.fly(this.iconNode).replaceClass(oldCls, cls);
  2894. }
  2895. },
  2896. // private
  2897. onIconChange : function(node, icon){
  2898. if(this.rendered){
  2899. //'<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
  2900. var empty = Ext.isEmpty(icon);
  2901. this.iconNode.src = empty ? this.emptyIcon : icon;
  2902. Ext.fly(this.iconNode)[empty ? 'removeClass' : 'addClass']('x-tree-node-inline-icon');
  2903. }
  2904. },
  2905. // private
  2906. onTipChange : function(node, tip, title){
  2907. if(this.rendered){
  2908. var hasTitle = Ext.isDefined(title);
  2909. if(this.textNode.setAttributeNS){
  2910. this.textNode.setAttributeNS("ext", "qtip", tip);
  2911. if(hasTitle){
  2912. this.textNode.setAttributeNS("ext", "qtitle", title);
  2913. }
  2914. }else{
  2915. this.textNode.setAttribute("ext:qtip", tip);
  2916. if(hasTitle){
  2917. this.textNode.setAttribute("ext:qtitle", title);
  2918. }
  2919. }
  2920. }
  2921. },
  2922. // private
  2923. onHrefChange : function(node, href, target){
  2924. if(this.rendered){
  2925. this.anchor.href = this.getHref(href);
  2926. if(Ext.isDefined(target)){
  2927. this.anchor.target = target;
  2928. }
  2929. }
  2930. },
  2931. // private
  2932. onClsChange : function(node, cls, oldCls){
  2933. if(this.rendered){
  2934. Ext.fly(this.elNode).replaceClass(oldCls, cls);
  2935. }
  2936. },
  2937. // private
  2938. onDisableChange : function(node, state){
  2939. this.disabled = state;
  2940. if (this.checkbox) {
  2941. this.checkbox.disabled = state;
  2942. }
  2943. this[state ? 'addClass' : 'removeClass']('x-tree-node-disabled');
  2944. },
  2945. // private
  2946. onSelectedChange : function(state){
  2947. if(state){
  2948. this.focus();
  2949. this.addClass("x-tree-selected");
  2950. }else{
  2951. //this.blur();
  2952. this.removeClass("x-tree-selected");
  2953. }
  2954. },
  2955. // private
  2956. onMove : function(tree, node, oldParent, newParent, index, refNode){
  2957. this.childIndent = null;
  2958. if(this.rendered){
  2959. var targetNode = newParent.ui.getContainer();
  2960. if(!targetNode){//target not rendered
  2961. this.holder = document.createElement("div");
  2962. this.holder.appendChild(this.wrap);
  2963. return;
  2964. }
  2965. var insertBefore = refNode ? refNode.ui.getEl() : null;
  2966. if(insertBefore){
  2967. targetNode.insertBefore(this.wrap, insertBefore);
  2968. }else{
  2969. targetNode.appendChild(this.wrap);
  2970. }
  2971. this.node.renderIndent(true, oldParent != newParent);
  2972. }
  2973. },
  2974. /**
  2975. * Adds one or more CSS classes to the node's UI element.
  2976. * Duplicate classes are automatically filtered out.
  2977. * @param {String/Array} className The CSS class to add, or an array of classes
  2978. */
  2979. addClass : function(cls){
  2980. if(this.elNode){
  2981. Ext.fly(this.elNode).addClass(cls);
  2982. }
  2983. },
  2984. /**
  2985. * Removes one or more CSS classes from the node's UI element.
  2986. * @param {String/Array} className The CSS class to remove, or an array of classes
  2987. */
  2988. removeClass : function(cls){
  2989. if(this.elNode){
  2990. Ext.fly(this.elNode).removeClass(cls);
  2991. }
  2992. },
  2993. // private
  2994. remove : function(){
  2995. if(this.rendered){
  2996. this.holder = document.createElement("div");
  2997. this.holder.appendChild(this.wrap);
  2998. }
  2999. },
  3000. // private
  3001. fireEvent : function(){
  3002. return this.node.fireEvent.apply(this.node, arguments);
  3003. },
  3004. // private
  3005. initEvents : function(){
  3006. this.node.on("move", this.onMove, this);
  3007. if(this.node.disabled){
  3008. this.onDisableChange(this.node, true);
  3009. }
  3010. if(this.node.hidden){
  3011. this.hide();
  3012. }
  3013. var ot = this.node.getOwnerTree();
  3014. var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
  3015. if(dd && (!this.node.isRoot || ot.rootVisible)){
  3016. Ext.dd.Registry.register(this.elNode, {
  3017. node: this.node,
  3018. handles: this.getDDHandles(),
  3019. isHandle: false
  3020. });
  3021. }
  3022. },
  3023. // private
  3024. getDDHandles : function(){
  3025. return [this.iconNode, this.textNode, this.elNode];
  3026. },
  3027. /**
  3028. * Hides this node.
  3029. */
  3030. hide : function(){
  3031. this.node.hidden = true;
  3032. if(this.wrap){
  3033. this.wrap.style.display = "none";
  3034. }
  3035. },
  3036. /**
  3037. * Shows this node.
  3038. */
  3039. show : function(){
  3040. this.node.hidden = false;
  3041. if(this.wrap){
  3042. this.wrap.style.display = "";
  3043. }
  3044. },
  3045. // private
  3046. onContextMenu : function(e){
  3047. if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
  3048. e.preventDefault();
  3049. this.focus();
  3050. this.fireEvent("contextmenu", this.node, e);
  3051. }
  3052. },
  3053. // private
  3054. onClick : function(e){
  3055. if(this.dropping){
  3056. e.stopEvent();
  3057. return;
  3058. }
  3059. if(this.fireEvent("beforeclick", this.node, e) !== false){
  3060. var a = e.getTarget('a');
  3061. if(!this.disabled && this.node.attributes.href && a){
  3062. this.fireEvent("click", this.node, e);
  3063. return;
  3064. }else if(a && e.ctrlKey){
  3065. e.stopEvent();
  3066. }
  3067. e.preventDefault();
  3068. if(this.disabled){
  3069. return;
  3070. }
  3071. if(this.node.attributes.singleClickExpand && !this.animating && this.node.isExpandable()){
  3072. this.node.toggle();
  3073. }
  3074. this.fireEvent("click", this.node, e);
  3075. }else{
  3076. e.stopEvent();
  3077. }
  3078. },
  3079. // private
  3080. onDblClick : function(e){
  3081. e.preventDefault();
  3082. if(this.disabled){
  3083. return;
  3084. }
  3085. if(this.fireEvent("beforedblclick", this.node, e) !== false){
  3086. if(this.checkbox){
  3087. this.toggleCheck();
  3088. }
  3089. if(!this.animating && this.node.isExpandable()){
  3090. this.node.toggle();
  3091. }
  3092. this.fireEvent("dblclick", this.node, e);
  3093. }
  3094. },
  3095. onOver : function(e){
  3096. this.addClass('x-tree-node-over');
  3097. },
  3098. onOut : function(e){
  3099. this.removeClass('x-tree-node-over');
  3100. },
  3101. // private
  3102. onCheckChange : function(){
  3103. var checked = this.checkbox.checked;
  3104. // fix for IE6
  3105. this.checkbox.defaultChecked = checked;
  3106. this.node.attributes.checked = checked;
  3107. this.fireEvent('checkchange', this.node, checked);
  3108. },
  3109. // private
  3110. ecClick : function(e){
  3111. if(!this.animating && this.node.isExpandable()){
  3112. this.node.toggle();
  3113. }
  3114. },
  3115. // private
  3116. startDrop : function(){
  3117. this.dropping = true;
  3118. },
  3119. // delayed drop so the click event doesn't get fired on a drop
  3120. endDrop : function(){
  3121. setTimeout(function(){
  3122. this.dropping = false;
  3123. }.createDelegate(this), 50);
  3124. },
  3125. // private
  3126. expand : function(){
  3127. this.updateExpandIcon();
  3128. this.ctNode.style.display = "";
  3129. },
  3130. // private
  3131. focus : function(){
  3132. if(!this.node.preventHScroll){
  3133. try{this.anchor.focus();
  3134. }catch(e){}
  3135. }else{
  3136. try{
  3137. var noscroll = this.node.getOwnerTree().getTreeEl().dom;
  3138. var l = noscroll.scrollLeft;
  3139. this.anchor.focus();
  3140. noscroll.scrollLeft = l;
  3141. }catch(e){}
  3142. }
  3143. },
  3144. /**
  3145. * Sets the checked status of the tree node to the passed value, or, if no value was passed,
  3146. * toggles the checked status. If the node was rendered with no checkbox, this has no effect.
  3147. * @param {Boolean} value (optional) The new checked status.
  3148. */
  3149. toggleCheck : function(value){
  3150. var cb = this.checkbox;
  3151. if(cb){
  3152. cb.checked = (value === undefined ? !cb.checked : value);
  3153. this.onCheckChange();
  3154. }
  3155. },
  3156. // private
  3157. blur : function(){
  3158. try{
  3159. this.anchor.blur();
  3160. }catch(e){}
  3161. },
  3162. // private
  3163. animExpand : function(callback){
  3164. var ct = Ext.get(this.ctNode);
  3165. ct.stopFx();
  3166. if(!this.node.isExpandable()){
  3167. this.updateExpandIcon();
  3168. this.ctNode.style.display = "";
  3169. Ext.callback(callback);
  3170. return;
  3171. }
  3172. this.animating = true;
  3173. this.updateExpandIcon();
  3174. ct.slideIn('t', {
  3175. callback : function(){
  3176. this.animating = false;
  3177. Ext.callback(callback);
  3178. },
  3179. scope: this,
  3180. duration: this.node.ownerTree.duration || .25
  3181. });
  3182. },
  3183. // private
  3184. highlight : function(){
  3185. var tree = this.node.getOwnerTree();
  3186. Ext.fly(this.wrap).highlight(
  3187. tree.hlColor || "C3DAF9",
  3188. {endColor: tree.hlBaseColor}
  3189. );
  3190. },
  3191. // private
  3192. collapse : function(){
  3193. this.updateExpandIcon();
  3194. this.ctNode.style.display = "none";
  3195. },
  3196. // private
  3197. animCollapse : function(callback){
  3198. var ct = Ext.get(this.ctNode);
  3199. ct.enableDisplayMode('block');
  3200. ct.stopFx();
  3201. this.animating = true;
  3202. this.updateExpandIcon();
  3203. ct.slideOut('t', {
  3204. callback : function(){
  3205. this.animating = false;
  3206. Ext.callback(callback);
  3207. },
  3208. scope: this,
  3209. duration: this.node.ownerTree.duration || .25
  3210. });
  3211. },
  3212. // private
  3213. getContainer : function(){
  3214. return this.ctNode;
  3215. },
  3216. /**
  3217. * Returns the element which encapsulates this node.
  3218. * @return {HtmlElement} The DOM element. The default implementation uses a <code>&lt;li></code>.
  3219. */
  3220. getEl : function(){
  3221. return this.wrap;
  3222. },
  3223. // private
  3224. appendDDGhost : function(ghostNode){
  3225. ghostNode.appendChild(this.elNode.cloneNode(true));
  3226. },
  3227. // private
  3228. getDDRepairXY : function(){
  3229. return Ext.lib.Dom.getXY(this.iconNode);
  3230. },
  3231. // private
  3232. onRender : function(){
  3233. this.render();
  3234. },
  3235. // private
  3236. render : function(bulkRender){
  3237. var n = this.node, a = n.attributes;
  3238. var targetNode = n.parentNode ?
  3239. n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
  3240. if(!this.rendered){
  3241. this.rendered = true;
  3242. this.renderElements(n, a, targetNode, bulkRender);
  3243. if(a.qtip){
  3244. this.onTipChange(n, a.qtip, a.qtipTitle);
  3245. }else if(a.qtipCfg){
  3246. a.qtipCfg.target = Ext.id(this.textNode);
  3247. Ext.QuickTips.register(a.qtipCfg);
  3248. }
  3249. this.initEvents();
  3250. if(!this.node.expanded){
  3251. this.updateExpandIcon(true);
  3252. }
  3253. }else{
  3254. if(bulkRender === true) {
  3255. targetNode.appendChild(this.wrap);
  3256. }
  3257. }
  3258. },
  3259. // private
  3260. renderElements : function(n, a, targetNode, bulkRender){
  3261. // add some indent caching, this helps performance when rendering a large tree
  3262. this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
  3263. var cb = Ext.isBoolean(a.checked),
  3264. nel,
  3265. href = this.getHref(a.href),
  3266. buf = ['<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf x-unselectable ', a.cls,'" unselectable="on">',
  3267. '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
  3268. '<img alt="" src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
  3269. '<img alt="" src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
  3270. cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',
  3271. '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ',
  3272. a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",
  3273. '<ul class="x-tree-node-ct" style="display:none;"></ul>',
  3274. "</li>"].join('');
  3275. if(bulkRender !== true && n.nextSibling && (nel = n.nextSibling.ui.getEl())){
  3276. this.wrap = Ext.DomHelper.insertHtml("beforeBegin", nel, buf);
  3277. }else{
  3278. this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf);
  3279. }
  3280. this.elNode = this.wrap.childNodes[0];
  3281. this.ctNode = this.wrap.childNodes[1];
  3282. var cs = this.elNode.childNodes;
  3283. this.indentNode = cs[0];
  3284. this.ecNode = cs[1];
  3285. this.iconNode = cs[2];
  3286. var index = 3;
  3287. if(cb){
  3288. this.checkbox = cs[3];
  3289. // fix for IE6
  3290. this.checkbox.defaultChecked = this.checkbox.checked;
  3291. index++;
  3292. }
  3293. this.anchor = cs[index];
  3294. this.textNode = cs[index].firstChild;
  3295. },
  3296. /**
  3297. * @private Gets a normalized href for the node.
  3298. * @param {String} href
  3299. */
  3300. getHref : function(href){
  3301. return Ext.isEmpty(href) ? (Ext.isGecko ? '' : '#') : href;
  3302. },
  3303. /**
  3304. * Returns the &lt;a> element that provides focus for the node's UI.
  3305. * @return {HtmlElement} The DOM anchor element.
  3306. */
  3307. getAnchor : function(){
  3308. return this.anchor;
  3309. },
  3310. /**
  3311. * Returns the text node.
  3312. * @return {HtmlNode} The DOM text node.
  3313. */
  3314. getTextEl : function(){
  3315. return this.textNode;
  3316. },
  3317. /**
  3318. * Returns the icon &lt;img> element.
  3319. * @return {HtmlElement} The DOM image element.
  3320. */
  3321. getIconEl : function(){
  3322. return this.iconNode;
  3323. },
  3324. /**
  3325. * Returns the checked status of the node. If the node was rendered with no
  3326. * checkbox, it returns false.
  3327. * @return {Boolean} The checked flag.
  3328. */
  3329. isChecked : function(){
  3330. return this.checkbox ? this.checkbox.checked : false;
  3331. },
  3332. // private
  3333. updateExpandIcon : function(){
  3334. if(this.rendered){
  3335. var n = this.node,
  3336. c1,
  3337. c2,
  3338. cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow",
  3339. hasChild = n.hasChildNodes();
  3340. if(hasChild || n.attributes.expandable){
  3341. if(n.expanded){
  3342. cls += "-minus";
  3343. c1 = "x-tree-node-collapsed";
  3344. c2 = "x-tree-node-expanded";
  3345. }else{
  3346. cls += "-plus";
  3347. c1 = "x-tree-node-expanded";
  3348. c2 = "x-tree-node-collapsed";
  3349. }
  3350. if(this.wasLeaf){
  3351. this.removeClass("x-tree-node-leaf");
  3352. this.wasLeaf = false;
  3353. }
  3354. if(this.c1 != c1 || this.c2 != c2){
  3355. Ext.fly(this.elNode).replaceClass(c1, c2);
  3356. this.c1 = c1; this.c2 = c2;
  3357. }
  3358. }else{
  3359. if(!this.wasLeaf){
  3360. Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-collapsed");
  3361. delete this.c1;
  3362. delete this.c2;
  3363. this.wasLeaf = true;
  3364. }
  3365. }
  3366. var ecc = "x-tree-ec-icon "+cls;
  3367. if(this.ecc != ecc){
  3368. this.ecNode.className = ecc;
  3369. this.ecc = ecc;
  3370. }
  3371. }
  3372. },
  3373. // private
  3374. onIdChange: function(id){
  3375. if(this.rendered){
  3376. this.elNode.setAttribute('ext:tree-node-id', id);
  3377. }
  3378. },
  3379. // private
  3380. getChildIndent : function(){
  3381. if(!this.childIndent){
  3382. var buf = [],
  3383. p = this.node;
  3384. while(p){
  3385. if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
  3386. if(!p.isLast()) {
  3387. buf.unshift('<img alt="" src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
  3388. } else {
  3389. buf.unshift('<img alt="" src="'+this.emptyIcon+'" class="x-tree-icon" />');
  3390. }
  3391. }
  3392. p = p.parentNode;
  3393. }
  3394. this.childIndent = buf.join("");
  3395. }
  3396. return this.childIndent;
  3397. },
  3398. // private
  3399. renderIndent : function(){
  3400. if(this.rendered){
  3401. var indent = "",
  3402. p = this.node.parentNode;
  3403. if(p){
  3404. indent = p.ui.getChildIndent();
  3405. }
  3406. if(this.indentMarkup != indent){ // don't rerender if not required
  3407. this.indentNode.innerHTML = indent;
  3408. this.indentMarkup = indent;
  3409. }
  3410. this.updateExpandIcon();
  3411. }
  3412. },
  3413. destroy : function(){
  3414. if(this.elNode){
  3415. Ext.dd.Registry.unregister(this.elNode.id);
  3416. }
  3417. Ext.each(['textnode', 'anchor', 'checkbox', 'indentNode', 'ecNode', 'iconNode', 'elNode', 'ctNode', 'wrap', 'holder'], function(el){
  3418. if(this[el]){
  3419. Ext.fly(this[el]).remove();
  3420. delete this[el];
  3421. }
  3422. }, this);
  3423. delete this.node;
  3424. }
  3425. });
  3426. /**
  3427. * @class Ext.tree.RootTreeNodeUI
  3428. * This class provides the default UI implementation for <b>root</b> Ext TreeNodes.
  3429. * The RootTreeNode UI implementation allows customizing the appearance of the root tree node.<br>
  3430. * <p>
  3431. * If you are customizing the Tree's user interface, you
  3432. * may need to extend this class, but you should never need to instantiate this class.<br>
  3433. */
  3434. Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  3435. // private
  3436. render : function(){
  3437. if(!this.rendered){
  3438. var targetNode = this.node.ownerTree.innerCt.dom;
  3439. this.node.expanded = true;
  3440. targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
  3441. this.wrap = this.ctNode = targetNode.firstChild;
  3442. }
  3443. },
  3444. collapse : Ext.emptyFn,
  3445. expand : Ext.emptyFn
  3446. });/**
  3447. * @class Ext.tree.TreeLoader
  3448. * @extends Ext.util.Observable
  3449. * A TreeLoader provides for lazy loading of an {@link Ext.tree.TreeNode}'s child
  3450. * nodes from a specified URL. The response must be a JavaScript Array definition
  3451. * whose elements are node definition objects. e.g.:
  3452. * <pre><code>
  3453. [{
  3454. id: 1,
  3455. text: 'A leaf Node',
  3456. leaf: true
  3457. },{
  3458. id: 2,
  3459. text: 'A folder Node',
  3460. children: [{
  3461. id: 3,
  3462. text: 'A child Node',
  3463. leaf: true
  3464. }]
  3465. }]
  3466. </code></pre>
  3467. * <br><br>
  3468. * A server request is sent, and child nodes are loaded only when a node is expanded.
  3469. * The loading node's id is passed to the server under the parameter name "node" to
  3470. * enable the server to produce the correct child nodes.
  3471. * <br><br>
  3472. * To pass extra parameters, an event handler may be attached to the "beforeload"
  3473. * event, and the parameters specified in the TreeLoader's baseParams property:
  3474. * <pre><code>
  3475. myTreeLoader.on("beforeload", function(treeLoader, node) {
  3476. this.baseParams.category = node.attributes.category;
  3477. }, this);
  3478. </code></pre>
  3479. * This would pass an HTTP parameter called "category" to the server containing
  3480. * the value of the Node's "category" attribute.
  3481. * @constructor
  3482. * Creates a new Treeloader.
  3483. * @param {Object} config A config object containing config properties.
  3484. */
  3485. Ext.tree.TreeLoader = function(config){
  3486. this.baseParams = {};
  3487. Ext.apply(this, config);
  3488. this.addEvents(
  3489. /**
  3490. * @event beforeload
  3491. * Fires before a network request is made to retrieve the Json text which specifies a node's children.
  3492. * @param {Object} This TreeLoader object.
  3493. * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
  3494. * @param {Object} callback The callback function specified in the {@link #load} call.
  3495. */
  3496. "beforeload",
  3497. /**
  3498. * @event load
  3499. * Fires when the node has been successfuly loaded.
  3500. * @param {Object} This TreeLoader object.
  3501. * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
  3502. * @param {Object} response The response object containing the data from the server.
  3503. */
  3504. "load",
  3505. /**
  3506. * @event loadexception
  3507. * Fires if the network request failed.
  3508. * @param {Object} This TreeLoader object.
  3509. * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
  3510. * @param {Object} response The response object containing the data from the server.
  3511. */
  3512. "loadexception"
  3513. );
  3514. Ext.tree.TreeLoader.superclass.constructor.call(this);
  3515. if(Ext.isString(this.paramOrder)){
  3516. this.paramOrder = this.paramOrder.split(/[\s,|]/);
  3517. }
  3518. };
  3519. Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, {
  3520. /**
  3521. * @cfg {String} dataUrl The URL from which to request a Json string which
  3522. * specifies an array of node definition objects representing the child nodes
  3523. * to be loaded.
  3524. */
  3525. /**
  3526. * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
  3527. */
  3528. /**
  3529. * @cfg {String} url Equivalent to {@link #dataUrl}.
  3530. */
  3531. /**
  3532. * @cfg {Boolean} preloadChildren If set to true, the loader recursively loads "children" attributes when doing the first load on nodes.
  3533. */
  3534. /**
  3535. * @cfg {Object} baseParams (optional) An object containing properties which
  3536. * specify HTTP parameters to be passed to each request for child nodes.
  3537. */
  3538. /**
  3539. * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
  3540. * created by this loader. If the attributes sent by the server have an attribute in this object,
  3541. * they take priority.
  3542. */
  3543. /**
  3544. * @cfg {Object} uiProviders (optional) An object containing properties which
  3545. * specify custom {@link Ext.tree.TreeNodeUI} implementations. If the optional
  3546. * <i>uiProvider</i> attribute of a returned child node is a string rather
  3547. * than a reference to a TreeNodeUI implementation, then that string value
  3548. * is used as a property name in the uiProviders object.
  3549. */
  3550. uiProviders : {},
  3551. /**
  3552. * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
  3553. * child nodes before loading.
  3554. */
  3555. clearOnLoad : true,
  3556. /**
  3557. * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. Only used when using directFn.
  3558. * Specifies the params in the order in which they must be passed to the server-side Direct method
  3559. * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
  3560. * comma, or pipe. For example,
  3561. * any of the following would be acceptable:<pre><code>
  3562. nodeParameter: 'node',
  3563. paramOrder: ['param1','param2','param3']
  3564. paramOrder: 'node param1 param2 param3'
  3565. paramOrder: 'param1,node,param2,param3'
  3566. paramOrder: 'param1|param2|param|node'
  3567. </code></pre>
  3568. */
  3569. paramOrder: undefined,
  3570. /**
  3571. * @cfg {Boolean} paramsAsHash Only used when using directFn.
  3572. * Send parameters as a collection of named arguments (defaults to <tt>false</tt>). Providing a
  3573. * <tt>{@link #paramOrder}</tt> nullifies this configuration.
  3574. */
  3575. paramsAsHash: false,
  3576. /**
  3577. * @cfg {String} nodeParameter The name of the parameter sent to the server which contains
  3578. * the identifier of the node. Defaults to <tt>'node'</tt>.
  3579. */
  3580. nodeParameter: 'node',
  3581. /**
  3582. * @cfg {Function} directFn
  3583. * Function to call when executing a request.
  3584. */
  3585. directFn : undefined,
  3586. /**
  3587. * Load an {@link Ext.tree.TreeNode} from the URL specified in the constructor.
  3588. * This is called automatically when a node is expanded, but may be used to reload
  3589. * a node (or append new children if the {@link #clearOnLoad} option is false.)
  3590. * @param {Ext.tree.TreeNode} node
  3591. * @param {Function} callback Function to call after the node has been loaded. The
  3592. * function is passed the TreeNode which was requested to be loaded.
  3593. * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed.
  3594. * defaults to the loaded TreeNode.
  3595. */
  3596. load : function(node, callback, scope){
  3597. if(this.clearOnLoad){
  3598. while(node.firstChild){
  3599. node.removeChild(node.firstChild);
  3600. }
  3601. }
  3602. if(this.doPreload(node)){ // preloaded json children
  3603. this.runCallback(callback, scope || node, [node]);
  3604. }else if(this.directFn || this.dataUrl || this.url){
  3605. this.requestData(node, callback, scope || node);
  3606. }
  3607. },
  3608. doPreload : function(node){
  3609. if(node.attributes.children){
  3610. if(node.childNodes.length < 1){ // preloaded?
  3611. var cs = node.attributes.children;
  3612. node.beginUpdate();
  3613. for(var i = 0, len = cs.length; i < len; i++){
  3614. var cn = node.appendChild(this.createNode(cs[i]));
  3615. if(this.preloadChildren){
  3616. this.doPreload(cn);
  3617. }
  3618. }
  3619. node.endUpdate();
  3620. }
  3621. return true;
  3622. }
  3623. return false;
  3624. },
  3625. getParams: function(node){
  3626. var bp = Ext.apply({}, this.baseParams),
  3627. np = this.nodeParameter,
  3628. po = this.paramOrder;
  3629. np && (bp[ np ] = node.id);
  3630. if(this.directFn){
  3631. var buf = [node.id];
  3632. if(po){
  3633. // reset 'buf' if the nodeParameter was included in paramOrder
  3634. if(np && po.indexOf(np) > -1){
  3635. buf = [];
  3636. }
  3637. for(var i = 0, len = po.length; i < len; i++){
  3638. buf.push(bp[ po[i] ]);
  3639. }
  3640. }else if(this.paramsAsHash){
  3641. buf = [bp];
  3642. }
  3643. return buf;
  3644. }else{
  3645. return bp;
  3646. }
  3647. },
  3648. requestData : function(node, callback, scope){
  3649. if(this.fireEvent("beforeload", this, node, callback) !== false){
  3650. if(this.directFn){
  3651. var args = this.getParams(node);
  3652. args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));
  3653. this.directFn.apply(window, args);
  3654. }else{
  3655. this.transId = Ext.Ajax.request({
  3656. method:this.requestMethod,
  3657. url: this.dataUrl||this.url,
  3658. success: this.handleResponse,
  3659. failure: this.handleFailure,
  3660. scope: this,
  3661. argument: {callback: callback, node: node, scope: scope},
  3662. params: this.getParams(node)
  3663. });
  3664. }
  3665. }else{
  3666. // if the load is cancelled, make sure we notify
  3667. // the node that we are done
  3668. this.runCallback(callback, scope || node, []);
  3669. }
  3670. },
  3671. processDirectResponse: function(result, response, args){
  3672. if(response.status){
  3673. this.handleResponse({
  3674. responseData: Ext.isArray(result) ? result : null,
  3675. responseText: result,
  3676. argument: args
  3677. });
  3678. }else{
  3679. this.handleFailure({
  3680. argument: args
  3681. });
  3682. }
  3683. },
  3684. // private
  3685. runCallback: function(cb, scope, args){
  3686. if(Ext.isFunction(cb)){
  3687. cb.apply(scope, args);
  3688. }
  3689. },
  3690. isLoading : function(){
  3691. return !!this.transId;
  3692. },
  3693. abort : function(){
  3694. if(this.isLoading()){
  3695. Ext.Ajax.abort(this.transId);
  3696. }
  3697. },
  3698. /**
  3699. * <p>Override this function for custom TreeNode node implementation, or to
  3700. * modify the attributes at creation time.</p>
  3701. * Example:<pre><code>
  3702. new Ext.tree.TreePanel({
  3703. ...
  3704. loader: new Ext.tree.TreeLoader({
  3705. url: 'dataUrl',
  3706. createNode: function(attr) {
  3707. // Allow consolidation consignments to have
  3708. // consignments dropped into them.
  3709. if (attr.isConsolidation) {
  3710. attr.iconCls = 'x-consol',
  3711. attr.allowDrop = true;
  3712. }
  3713. return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
  3714. }
  3715. }),
  3716. ...
  3717. });
  3718. </code></pre>
  3719. * @param attr {Object} The attributes from which to create the new node.
  3720. */
  3721. createNode : function(attr){
  3722. // apply baseAttrs, nice idea Corey!
  3723. if(this.baseAttrs){
  3724. Ext.applyIf(attr, this.baseAttrs);
  3725. }
  3726. if(this.applyLoader !== false && !attr.loader){
  3727. attr.loader = this;
  3728. }
  3729. if(Ext.isString(attr.uiProvider)){
  3730. attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
  3731. }
  3732. if(attr.nodeType){
  3733. return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
  3734. }else{
  3735. return attr.leaf ?
  3736. new Ext.tree.TreeNode(attr) :
  3737. new Ext.tree.AsyncTreeNode(attr);
  3738. }
  3739. },
  3740. processResponse : function(response, node, callback, scope){
  3741. var json = response.responseText;
  3742. try {
  3743. var o = response.responseData || Ext.decode(json);
  3744. node.beginUpdate();
  3745. for(var i = 0, len = o.length; i < len; i++){
  3746. var n = this.createNode(o[i]);
  3747. if(n){
  3748. node.appendChild(n);
  3749. }
  3750. }
  3751. node.endUpdate();
  3752. this.runCallback(callback, scope || node, [node]);
  3753. }catch(e){
  3754. this.handleFailure(response);
  3755. }
  3756. },
  3757. handleResponse : function(response){
  3758. this.transId = false;
  3759. var a = response.argument;
  3760. this.processResponse(response, a.node, a.callback, a.scope);
  3761. this.fireEvent("load", this, a.node, response);
  3762. },
  3763. handleFailure : function(response){
  3764. this.transId = false;
  3765. var a = response.argument;
  3766. this.fireEvent("loadexception", this, a.node, response);
  3767. this.runCallback(a.callback, a.scope || a.node, [a.node]);
  3768. },
  3769. destroy : function(){
  3770. this.abort();
  3771. this.purgeListeners();
  3772. }
  3773. });/**
  3774. * @class Ext.tree.TreeFilter
  3775. * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
  3776. * @param {TreePanel} tree
  3777. * @param {Object} config (optional)
  3778. */
  3779. Ext.tree.TreeFilter = function(tree, config){
  3780. this.tree = tree;
  3781. this.filtered = {};
  3782. Ext.apply(this, config);
  3783. };
  3784. Ext.tree.TreeFilter.prototype = {
  3785. clearBlank:false,
  3786. reverse:false,
  3787. autoClear:false,
  3788. remove:false,
  3789. /**
  3790. * Filter the data by a specific attribute.
  3791. * @param {String/RegExp} value Either string that the attribute value
  3792. * should start with or a RegExp to test against the attribute
  3793. * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
  3794. * @param {TreeNode} startNode (optional) The node to start the filter at.
  3795. */
  3796. filter : function(value, attr, startNode){
  3797. attr = attr || "text";
  3798. var f;
  3799. if(typeof value == "string"){
  3800. var vlen = value.length;
  3801. // auto clear empty filter
  3802. if(vlen == 0 && this.clearBlank){
  3803. this.clear();
  3804. return;
  3805. }
  3806. value = value.toLowerCase();
  3807. f = function(n){
  3808. return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
  3809. };
  3810. }else if(value.exec){ // regex?
  3811. f = function(n){
  3812. return value.test(n.attributes[attr]);
  3813. };
  3814. }else{
  3815. throw 'Illegal filter type, must be string or regex';
  3816. }
  3817. this.filterBy(f, null, startNode);
  3818. },
  3819. /**
  3820. * Filter by a function. The passed function will be called with each
  3821. * node in the tree (or from the startNode). If the function returns true, the node is kept
  3822. * otherwise it is filtered. If a node is filtered, its children are also filtered.
  3823. * @param {Function} fn The filter function
  3824. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
  3825. */
  3826. filterBy : function(fn, scope, startNode){
  3827. startNode = startNode || this.tree.root;
  3828. if(this.autoClear){
  3829. this.clear();
  3830. }
  3831. var af = this.filtered, rv = this.reverse;
  3832. var f = function(n){
  3833. if(n == startNode){
  3834. return true;
  3835. }
  3836. if(af[n.id]){
  3837. return false;
  3838. }
  3839. var m = fn.call(scope || n, n);
  3840. if(!m || rv){
  3841. af[n.id] = n;
  3842. n.ui.hide();
  3843. return false;
  3844. }
  3845. return true;
  3846. };
  3847. startNode.cascade(f);
  3848. if(this.remove){
  3849. for(var id in af){
  3850. if(typeof id != "function"){
  3851. var n = af[id];
  3852. if(n && n.parentNode){
  3853. n.parentNode.removeChild(n);
  3854. }
  3855. }
  3856. }
  3857. }
  3858. },
  3859. /**
  3860. * Clears the current filter. Note: with the "remove" option
  3861. * set a filter cannot be cleared.
  3862. */
  3863. clear : function(){
  3864. var t = this.tree;
  3865. var af = this.filtered;
  3866. for(var id in af){
  3867. if(typeof id != "function"){
  3868. var n = af[id];
  3869. if(n){
  3870. n.ui.show();
  3871. }
  3872. }
  3873. }
  3874. this.filtered = {};
  3875. }
  3876. };
  3877. /**
  3878. * @class Ext.tree.TreeSorter
  3879. * Provides sorting of nodes in a {@link Ext.tree.TreePanel}. The TreeSorter automatically monitors events on the
  3880. * associated TreePanel that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
  3881. * Example usage:<br />
  3882. * <pre><code>
  3883. new Ext.tree.TreeSorter(myTree, {
  3884. folderSort: true,
  3885. dir: "desc",
  3886. sortType: function(value, node) {
  3887. // sort by a custom, typed attribute:
  3888. return parseInt(node.id, 10);
  3889. }
  3890. });
  3891. </code></pre>
  3892. * @constructor
  3893. * @param {TreePanel} tree
  3894. * @param {Object} config
  3895. */
  3896. Ext.tree.TreeSorter = Ext.extend(Object, {
  3897. constructor: function(tree, config){
  3898. /**
  3899. * @cfg {Boolean} folderSort True to sort leaf nodes under non-leaf nodes (defaults to false)
  3900. */
  3901. /**
  3902. * @cfg {String} property The named attribute on the node to sort by (defaults to "text"). Note that this
  3903. * property is only used if no {@link #sortType} function is specified, otherwise it is ignored.
  3904. */
  3905. /**
  3906. * @cfg {String} dir The direction to sort ("asc" or "desc," case-insensitive, defaults to "asc")
  3907. */
  3908. /**
  3909. * @cfg {String} leafAttr The attribute used to determine leaf nodes when {@link #folderSort} = true (defaults to "leaf")
  3910. */
  3911. /**
  3912. * @cfg {Boolean} caseSensitive true for case-sensitive sort (defaults to false)
  3913. */
  3914. /**
  3915. * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting. The function
  3916. * will be called with a two parameters, the {@link #property} value for the node and the {@link Ext.tree.TreeNode} being evaluated.
  3917. * It is expected to return the node's sort value cast to the specific data type required for sorting. This could be used, for example, when
  3918. * a node's text (or other attribute) should be sorted as a date or numeric value. See the class description for
  3919. * example usage.
  3920. */
  3921. Ext.apply(this, config);
  3922. tree.on({
  3923. scope: this,
  3924. beforechildrenrendered: this.doSort,
  3925. append: this.updateSort,
  3926. insert: this.updateSort,
  3927. textchange: this.updateSortParent
  3928. });
  3929. var desc = this.dir && this.dir.toLowerCase() == 'desc',
  3930. prop = this.property || 'text',
  3931. sortType = this.sortType,
  3932. folderSort = this.folderSort,
  3933. caseSensitive = this.caseSensitive === true,
  3934. leafAttr = this.leafAttr || 'leaf';
  3935. if(Ext.isString(sortType)){
  3936. sortType = Ext.data.SortTypes[sortType];
  3937. }
  3938. this.sortFn = function(n1, n2){
  3939. var attr1 = n1.attributes,
  3940. attr2 = n2.attributes;
  3941. if(folderSort){
  3942. if(attr1[leafAttr] && !attr2[leafAttr]){
  3943. return 1;
  3944. }
  3945. if(!attr1[leafAttr] && attr2[leafAttr]){
  3946. return -1;
  3947. }
  3948. }
  3949. var prop1 = attr1[prop],
  3950. prop2 = attr2[prop],
  3951. v1 = sortType ? sortType(prop1, n1) : (caseSensitive ? prop1 : prop1.toUpperCase()),
  3952. v2 = sortType ? sortType(prop2, n2) : (caseSensitive ? prop2 : prop2.toUpperCase());
  3953. if(v1 < v2){
  3954. return desc ? 1 : -1;
  3955. }else if(v1 > v2){
  3956. return desc ? -1 : 1;
  3957. }
  3958. return 0;
  3959. };
  3960. },
  3961. doSort : function(node){
  3962. node.sort(this.sortFn);
  3963. },
  3964. updateSort : function(tree, node){
  3965. if(node.childrenRendered){
  3966. this.doSort.defer(1, this, [node]);
  3967. }
  3968. },
  3969. updateSortParent : function(node){
  3970. var p = node.parentNode;
  3971. if(p && p.childrenRendered){
  3972. this.doSort.defer(1, this, [p]);
  3973. }
  3974. }
  3975. });
  3976. /**
  3977. * @class Ext.tree.TreeDropZone
  3978. * @extends Ext.dd.DropZone
  3979. * @constructor
  3980. * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dropping
  3981. * @param {Object} config
  3982. */
  3983. if(Ext.dd.DropZone){
  3984. Ext.tree.TreeDropZone = function(tree, config){
  3985. /**
  3986. * @cfg {Boolean} allowParentInsert
  3987. * Allow inserting a dragged node between an expanded parent node and its first child that will become a
  3988. * sibling of the parent when dropped (defaults to false)
  3989. */
  3990. this.allowParentInsert = config.allowParentInsert || false;
  3991. /**
  3992. * @cfg {String} allowContainerDrop
  3993. * True if drops on the tree container (outside of a specific tree node) are allowed (defaults to false)
  3994. */
  3995. this.allowContainerDrop = config.allowContainerDrop || false;
  3996. /**
  3997. * @cfg {String} appendOnly
  3998. * True if the tree should only allow append drops (use for trees which are sorted, defaults to false)
  3999. */
  4000. this.appendOnly = config.appendOnly || false;
  4001. Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.getTreeEl(), config);
  4002. /**
  4003. * The TreePanel for this drop zone
  4004. * @type Ext.tree.TreePanel
  4005. * @property
  4006. */
  4007. this.tree = tree;
  4008. /**
  4009. * Arbitrary data that can be associated with this tree and will be included in the event object that gets
  4010. * passed to any nodedragover event handler (defaults to {})
  4011. * @type Ext.tree.TreePanel
  4012. * @property
  4013. */
  4014. this.dragOverData = {};
  4015. // private
  4016. this.lastInsertClass = "x-tree-no-status";
  4017. };
  4018. Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, {
  4019. /**
  4020. * @cfg {String} ddGroup
  4021. * A named drag drop group to which this object belongs. If a group is specified, then this object will only
  4022. * interact with other drag drop objects in the same group (defaults to 'TreeDD').
  4023. */
  4024. ddGroup : "TreeDD",
  4025. /**
  4026. * @cfg {String} expandDelay
  4027. * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node
  4028. * over the target (defaults to 1000)
  4029. */
  4030. expandDelay : 1000,
  4031. // private
  4032. expandNode : function(node){
  4033. if(node.hasChildNodes() && !node.isExpanded()){
  4034. node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
  4035. }
  4036. },
  4037. // private
  4038. queueExpand : function(node){
  4039. this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
  4040. },
  4041. // private
  4042. cancelExpand : function(){
  4043. if(this.expandProcId){
  4044. clearTimeout(this.expandProcId);
  4045. this.expandProcId = false;
  4046. }
  4047. },
  4048. // private
  4049. isValidDropPoint : function(n, pt, dd, e, data){
  4050. if(!n || !data){ return false; }
  4051. var targetNode = n.node;
  4052. var dropNode = data.node;
  4053. // default drop rules
  4054. if(!(targetNode && targetNode.isTarget && pt)){
  4055. return false;
  4056. }
  4057. if(pt == "append" && targetNode.allowChildren === false){
  4058. return false;
  4059. }
  4060. if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
  4061. return false;
  4062. }
  4063. if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
  4064. return false;
  4065. }
  4066. // reuse the object
  4067. var overEvent = this.dragOverData;
  4068. overEvent.tree = this.tree;
  4069. overEvent.target = targetNode;
  4070. overEvent.data = data;
  4071. overEvent.point = pt;
  4072. overEvent.source = dd;
  4073. overEvent.rawEvent = e;
  4074. overEvent.dropNode = dropNode;
  4075. overEvent.cancel = false;
  4076. var result = this.tree.fireEvent("nodedragover", overEvent);
  4077. return overEvent.cancel === false && result !== false;
  4078. },
  4079. // private
  4080. getDropPoint : function(e, n, dd){
  4081. var tn = n.node;
  4082. if(tn.isRoot){
  4083. return tn.allowChildren !== false ? "append" : false; // always append for root
  4084. }
  4085. var dragEl = n.ddel;
  4086. var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
  4087. var y = Ext.lib.Event.getPageY(e);
  4088. var noAppend = tn.allowChildren === false || tn.isLeaf();
  4089. if(this.appendOnly || tn.parentNode.allowChildren === false){
  4090. return noAppend ? false : "append";
  4091. }
  4092. var noBelow = false;
  4093. if(!this.allowParentInsert){
  4094. noBelow = tn.hasChildNodes() && tn.isExpanded();
  4095. }
  4096. var q = (b - t) / (noAppend ? 2 : 3);
  4097. if(y >= t && y < (t + q)){
  4098. return "above";
  4099. }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
  4100. return "below";
  4101. }else{
  4102. return "append";
  4103. }
  4104. },
  4105. // private
  4106. onNodeEnter : function(n, dd, e, data){
  4107. this.cancelExpand();
  4108. },
  4109. onContainerOver : function(dd, e, data) {
  4110. if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
  4111. return this.dropAllowed;
  4112. }
  4113. return this.dropNotAllowed;
  4114. },
  4115. // private
  4116. onNodeOver : function(n, dd, e, data){
  4117. var pt = this.getDropPoint(e, n, dd);
  4118. var node = n.node;
  4119. // auto node expand check
  4120. if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
  4121. this.queueExpand(node);
  4122. }else if(pt != "append"){
  4123. this.cancelExpand();
  4124. }
  4125. // set the insert point style on the target node
  4126. var returnCls = this.dropNotAllowed;
  4127. if(this.isValidDropPoint(n, pt, dd, e, data)){
  4128. if(pt){
  4129. var el = n.ddel;
  4130. var cls;
  4131. if(pt == "above"){
  4132. returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
  4133. cls = "x-tree-drag-insert-above";
  4134. }else if(pt == "below"){
  4135. returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
  4136. cls = "x-tree-drag-insert-below";
  4137. }else{
  4138. returnCls = "x-tree-drop-ok-append";
  4139. cls = "x-tree-drag-append";
  4140. }
  4141. if(this.lastInsertClass != cls){
  4142. Ext.fly(el).replaceClass(this.lastInsertClass, cls);
  4143. this.lastInsertClass = cls;
  4144. }
  4145. }
  4146. }
  4147. return returnCls;
  4148. },
  4149. // private
  4150. onNodeOut : function(n, dd, e, data){
  4151. this.cancelExpand();
  4152. this.removeDropIndicators(n);
  4153. },
  4154. // private
  4155. onNodeDrop : function(n, dd, e, data){
  4156. var point = this.getDropPoint(e, n, dd);
  4157. var targetNode = n.node;
  4158. targetNode.ui.startDrop();
  4159. if(!this.isValidDropPoint(n, point, dd, e, data)){
  4160. targetNode.ui.endDrop();
  4161. return false;
  4162. }
  4163. // first try to find the drop node
  4164. var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
  4165. return this.processDrop(targetNode, data, point, dd, e, dropNode);
  4166. },
  4167. onContainerDrop : function(dd, e, data){
  4168. if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
  4169. var targetNode = this.tree.getRootNode();
  4170. targetNode.ui.startDrop();
  4171. var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, 'append', e) : null);
  4172. return this.processDrop(targetNode, data, 'append', dd, e, dropNode);
  4173. }
  4174. return false;
  4175. },
  4176. // private
  4177. processDrop: function(target, data, point, dd, e, dropNode){
  4178. var dropEvent = {
  4179. tree : this.tree,
  4180. target: target,
  4181. data: data,
  4182. point: point,
  4183. source: dd,
  4184. rawEvent: e,
  4185. dropNode: dropNode,
  4186. cancel: !dropNode,
  4187. dropStatus: false
  4188. };
  4189. var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
  4190. if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
  4191. target.ui.endDrop();
  4192. return dropEvent.dropStatus;
  4193. }
  4194. target = dropEvent.target;
  4195. if(point == 'append' && !target.isExpanded()){
  4196. target.expand(false, null, function(){
  4197. this.completeDrop(dropEvent);
  4198. }.createDelegate(this));
  4199. }else{
  4200. this.completeDrop(dropEvent);
  4201. }
  4202. return true;
  4203. },
  4204. // private
  4205. completeDrop : function(de){
  4206. var ns = de.dropNode, p = de.point, t = de.target;
  4207. if(!Ext.isArray(ns)){
  4208. ns = [ns];
  4209. }
  4210. var n;
  4211. for(var i = 0, len = ns.length; i < len; i++){
  4212. n = ns[i];
  4213. if(p == "above"){
  4214. t.parentNode.insertBefore(n, t);
  4215. }else if(p == "below"){
  4216. t.parentNode.insertBefore(n, t.nextSibling);
  4217. }else{
  4218. t.appendChild(n);
  4219. }
  4220. }
  4221. n.ui.focus();
  4222. if(Ext.enableFx && this.tree.hlDrop){
  4223. n.ui.highlight();
  4224. }
  4225. t.ui.endDrop();
  4226. this.tree.fireEvent("nodedrop", de);
  4227. },
  4228. // private
  4229. afterNodeMoved : function(dd, data, e, targetNode, dropNode){
  4230. if(Ext.enableFx && this.tree.hlDrop){
  4231. dropNode.ui.focus();
  4232. dropNode.ui.highlight();
  4233. }
  4234. this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
  4235. },
  4236. // private
  4237. getTree : function(){
  4238. return this.tree;
  4239. },
  4240. // private
  4241. removeDropIndicators : function(n){
  4242. if(n && n.ddel){
  4243. var el = n.ddel;
  4244. Ext.fly(el).removeClass([
  4245. "x-tree-drag-insert-above",
  4246. "x-tree-drag-insert-below",
  4247. "x-tree-drag-append"]);
  4248. this.lastInsertClass = "_noclass";
  4249. }
  4250. },
  4251. // private
  4252. beforeDragDrop : function(target, e, id){
  4253. this.cancelExpand();
  4254. return true;
  4255. },
  4256. // private
  4257. afterRepair : function(data){
  4258. if(data && Ext.enableFx){
  4259. data.node.ui.highlight();
  4260. }
  4261. this.hideProxy();
  4262. }
  4263. });
  4264. }/**
  4265. * @class Ext.tree.TreeDragZone
  4266. * @extends Ext.dd.DragZone
  4267. * @constructor
  4268. * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dragging
  4269. * @param {Object} config
  4270. */
  4271. if(Ext.dd.DragZone){
  4272. Ext.tree.TreeDragZone = function(tree, config){
  4273. Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.innerCt, config);
  4274. /**
  4275. * The TreePanel for this drag zone
  4276. * @type Ext.tree.TreePanel
  4277. * @property
  4278. */
  4279. this.tree = tree;
  4280. };
  4281. Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, {
  4282. /**
  4283. * @cfg {String} ddGroup
  4284. * A named drag drop group to which this object belongs. If a group is specified, then this object will only
  4285. * interact with other drag drop objects in the same group (defaults to 'TreeDD').
  4286. */
  4287. ddGroup : "TreeDD",
  4288. // private
  4289. onBeforeDrag : function(data, e){
  4290. var n = data.node;
  4291. return n && n.draggable && !n.disabled;
  4292. },
  4293. // private
  4294. onInitDrag : function(e){
  4295. var data = this.dragData;
  4296. this.tree.getSelectionModel().select(data.node);
  4297. this.tree.eventModel.disable();
  4298. this.proxy.update("");
  4299. data.node.ui.appendDDGhost(this.proxy.ghost.dom);
  4300. this.tree.fireEvent("startdrag", this.tree, data.node, e);
  4301. },
  4302. // private
  4303. getRepairXY : function(e, data){
  4304. return data.node.ui.getDDRepairXY();
  4305. },
  4306. // private
  4307. onEndDrag : function(data, e){
  4308. this.tree.eventModel.enable.defer(100, this.tree.eventModel);
  4309. this.tree.fireEvent("enddrag", this.tree, data.node, e);
  4310. },
  4311. // private
  4312. onValidDrop : function(dd, e, id){
  4313. this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
  4314. this.hideProxy();
  4315. },
  4316. // private
  4317. beforeInvalidDrop : function(e, id){
  4318. // this scrolls the original position back into view
  4319. var sm = this.tree.getSelectionModel();
  4320. sm.clearSelections();
  4321. sm.select(this.dragData.node);
  4322. },
  4323. // private
  4324. afterRepair : function(){
  4325. if (Ext.enableFx && this.tree.hlDrop) {
  4326. Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
  4327. }
  4328. this.dragging = false;
  4329. }
  4330. });
  4331. }/**
  4332. * @class Ext.tree.TreeEditor
  4333. * @extends Ext.Editor
  4334. * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
  4335. * as the editor field.
  4336. * @constructor
  4337. * @param {TreePanel} tree
  4338. * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
  4339. * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
  4340. * @param {Object} config (optional) A TreeEditor config object
  4341. */
  4342. Ext.tree.TreeEditor = function(tree, fc, config){
  4343. fc = fc || {};
  4344. var field = fc.events ? fc : new Ext.form.TextField(fc);
  4345. Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
  4346. this.tree = tree;
  4347. if(!tree.rendered){
  4348. tree.on('render', this.initEditor, this);
  4349. }else{
  4350. this.initEditor(tree);
  4351. }
  4352. };
  4353. Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
  4354. /**
  4355. * @cfg {String} alignment
  4356. * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "l-l").
  4357. */
  4358. alignment: "l-l",
  4359. // inherit
  4360. autoSize: false,
  4361. /**
  4362. * @cfg {Boolean} hideEl
  4363. * True to hide the bound element while the editor is displayed (defaults to false)
  4364. */
  4365. hideEl : false,
  4366. /**
  4367. * @cfg {String} cls
  4368. * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
  4369. */
  4370. cls: "x-small-editor x-tree-editor",
  4371. /**
  4372. * @cfg {Boolean} shim
  4373. * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
  4374. */
  4375. shim:false,
  4376. // inherit
  4377. shadow:"frame",
  4378. /**
  4379. * @cfg {Number} maxWidth
  4380. * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
  4381. * the containing tree element's size, it will be automatically limited for you to the container width, taking
  4382. * scroll and client offsets into account prior to each edit.
  4383. */
  4384. maxWidth: 250,
  4385. /**
  4386. * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
  4387. * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
  4388. * the editor for the node will display, otherwise it will be processed as a regular click.
  4389. */
  4390. editDelay : 350,
  4391. initEditor : function(tree){
  4392. tree.on({
  4393. scope : this,
  4394. beforeclick: this.beforeNodeClick,
  4395. dblclick : this.onNodeDblClick
  4396. });
  4397. this.on({
  4398. scope : this,
  4399. complete : this.updateNode,
  4400. beforestartedit: this.fitToTree,
  4401. specialkey : this.onSpecialKey
  4402. });
  4403. this.on('startedit', this.bindScroll, this, {delay:10});
  4404. },
  4405. // private
  4406. fitToTree : function(ed, el){
  4407. var td = this.tree.getTreeEl().dom, nd = el.dom;
  4408. if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
  4409. td.scrollLeft = nd.offsetLeft;
  4410. }
  4411. var w = Math.min(
  4412. this.maxWidth,
  4413. (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
  4414. this.setSize(w, '');
  4415. },
  4416. /**
  4417. * Edit the text of the passed {@link Ext.tree.TreeNode TreeNode}.
  4418. * @param node {Ext.tree.TreeNode} The TreeNode to edit. The TreeNode must be {@link Ext.tree.TreeNode#editable editable}.
  4419. */
  4420. triggerEdit : function(node, defer){
  4421. this.completeEdit();
  4422. if(node.attributes.editable !== false){
  4423. /**
  4424. * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
  4425. * @type Ext.tree.TreeNode
  4426. * @property editNode
  4427. */
  4428. this.editNode = node;
  4429. if(this.tree.autoScroll){
  4430. Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
  4431. }
  4432. var value = node.text || '';
  4433. if (!Ext.isGecko && Ext.isEmpty(node.text)){
  4434. node.setText('&#160;');
  4435. }
  4436. this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
  4437. return false;
  4438. }
  4439. },
  4440. // private
  4441. bindScroll : function(){
  4442. this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
  4443. },
  4444. // private
  4445. beforeNodeClick : function(node, e){
  4446. clearTimeout(this.autoEditTimer);
  4447. if(this.tree.getSelectionModel().isSelected(node)){
  4448. e.stopEvent();
  4449. return this.triggerEdit(node);
  4450. }
  4451. },
  4452. onNodeDblClick : function(node, e){
  4453. clearTimeout(this.autoEditTimer);
  4454. },
  4455. // private
  4456. updateNode : function(ed, value){
  4457. this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
  4458. this.editNode.setText(value);
  4459. },
  4460. // private
  4461. onHide : function(){
  4462. Ext.tree.TreeEditor.superclass.onHide.call(this);
  4463. if(this.editNode){
  4464. this.editNode.ui.focus.defer(50, this.editNode.ui);
  4465. }
  4466. },
  4467. // private
  4468. onSpecialKey : function(field, e){
  4469. var k = e.getKey();
  4470. if(k == e.ESC){
  4471. e.stopEvent();
  4472. this.cancelEdit();
  4473. }else if(k == e.ENTER && !e.hasModifier()){
  4474. e.stopEvent();
  4475. this.completeEdit();
  4476. }
  4477. },
  4478. onDestroy : function(){
  4479. clearTimeout(this.autoEditTimer);
  4480. Ext.tree.TreeEditor.superclass.onDestroy.call(this);
  4481. var tree = this.tree;
  4482. tree.un('beforeclick', this.beforeNodeClick, this);
  4483. tree.un('dblclick', this.onNodeDblClick, this);
  4484. }
  4485. });