Web Interface For Lite Argus Control modules
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.

4835 lines
153 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext.tree.TreePanel
  9. * @extends Ext.Panel
  10. * <p>The TreePanel provides tree-structured UI representation of tree-structured data.</p>
  11. * <p>{@link Ext.tree.TreeNode TreeNode}s added to the TreePanel may each contain metadata
  12. * used by your application in their {@link Ext.tree.TreeNode#attributes attributes} property.</p>
  13. * <p><b>A TreePanel must have a {@link #root} node before it is rendered.</b> This may either be
  14. * specified using the {@link #root} config option, or using the {@link #setRootNode} method.
  15. * <p>An example of tree rendered to an existing div:</p><pre><code>
  16. var tree = new Ext.tree.TreePanel({
  17. renderTo: 'tree-div',
  18. useArrows: true,
  19. autoScroll: true,
  20. animate: true,
  21. enableDD: true,
  22. containerScroll: true,
  23. border: false,
  24. // auto create TreeLoader
  25. dataUrl: 'get-nodes.php',
  26. root: {
  27. nodeType: 'async',
  28. text: 'Ext JS',
  29. draggable: false,
  30. id: 'source'
  31. }
  32. });
  33. tree.getRootNode().expand();
  34. * </code></pre>
  35. * <p>The example above would work with a data packet similar to this:</p><pre><code>
  36. [{
  37. "text": "adapter",
  38. "id": "source\/adapter",
  39. "cls": "folder"
  40. }, {
  41. "text": "dd",
  42. "id": "source\/dd",
  43. "cls": "folder"
  44. }, {
  45. "text": "debug.js",
  46. "id": "source\/debug.js",
  47. "leaf": true,
  48. "cls": "file"
  49. }]
  50. * </code></pre>
  51. * <p>An example of tree within a Viewport:</p><pre><code>
  52. new Ext.Viewport({
  53. layout: 'border',
  54. items: [{
  55. region: 'west',
  56. collapsible: true,
  57. title: 'Navigation',
  58. xtype: 'treepanel',
  59. width: 200,
  60. autoScroll: true,
  61. split: true,
  62. loader: new Ext.tree.TreeLoader(),
  63. root: new Ext.tree.AsyncTreeNode({
  64. expanded: true,
  65. children: [{
  66. text: 'Menu Option 1',
  67. leaf: true
  68. }, {
  69. text: 'Menu Option 2',
  70. leaf: true
  71. }, {
  72. text: 'Menu Option 3',
  73. leaf: true
  74. }]
  75. }),
  76. rootVisible: false,
  77. listeners: {
  78. click: function(n) {
  79. Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
  80. }
  81. }
  82. }, {
  83. region: 'center',
  84. xtype: 'tabpanel',
  85. // remaining code not shown ...
  86. }]
  87. });
  88. </code></pre>
  89. *
  90. * @cfg {Ext.tree.TreeNode} root The root node for the tree.
  91. * @cfg {Boolean} rootVisible <tt>false</tt> to hide the root node (defaults to <tt>true</tt>)
  92. * @cfg {Boolean} lines <tt>false</tt> to disable tree lines (defaults to <tt>true</tt>)
  93. * @cfg {Boolean} enableDD <tt>true</tt> to enable drag and drop
  94. * @cfg {Boolean} enableDrag <tt>true</tt> to enable just drag
  95. * @cfg {Boolean} enableDrop <tt>true</tt> to enable just drop
  96. * @cfg {Object} dragConfig Custom config to pass to the {@link Ext.tree.TreeDragZone} instance
  97. * @cfg {Object} dropConfig Custom config to pass to the {@link Ext.tree.TreeDropZone} instance
  98. * @cfg {String} ddGroup The DD group this TreePanel belongs to
  99. * @cfg {Boolean} ddAppendOnly <tt>true</tt> if the tree should only allow append drops (use for trees which are sorted)
  100. * @cfg {Boolean} ddScroll <tt>true</tt> to enable body scrolling
  101. * @cfg {Boolean} containerScroll <tt>true</tt> to register this container with ScrollManager
  102. * @cfg {Boolean} hlDrop <tt>false</tt> to disable node highlight on drop (defaults to the value of {@link Ext#enableFx})
  103. * @cfg {String} hlColor The color of the node highlight (defaults to <tt>'C3DAF9'</tt>)
  104. * @cfg {Boolean} animate <tt>true</tt> to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx})
  105. * @cfg {Boolean} singleExpand <tt>true</tt> if only 1 node per branch may be expanded
  106. * @cfg {Object} selModel A tree selection model to use with this TreePanel (defaults to an {@link Ext.tree.DefaultSelectionModel})
  107. * @cfg {Boolean} trackMouseOver <tt>false</tt> to disable mouse over highlighting
  108. * @cfg {Ext.tree.TreeLoader} loader A {@link Ext.tree.TreeLoader} for use with this TreePanel
  109. * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to <tt>'/'</tt>)
  110. * @cfg {Boolean} useArrows <tt>true</tt> to use Vista-style arrows in the tree (defaults to <tt>false</tt>)
  111. * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
  112. *
  113. * @constructor
  114. * @param {Object} config
  115. * @xtype treepanel
  116. */
  117. Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
  118. rootVisible : true,
  119. animate : Ext.enableFx,
  120. lines : true,
  121. enableDD : false,
  122. hlDrop : Ext.enableFx,
  123. pathSeparator : '/',
  124. /**
  125. * @cfg {Array} bubbleEvents
  126. * <p>An array of events that, when fired, should be bubbled to any parent container.
  127. * See {@link Ext.util.Observable#enableBubble}.
  128. * Defaults to <tt>[]</tt>.
  129. */
  130. bubbleEvents : [],
  131. initComponent : function(){
  132. Ext.tree.TreePanel.superclass.initComponent.call(this);
  133. if(!this.eventModel){
  134. this.eventModel = new Ext.tree.TreeEventModel(this);
  135. }
  136. // initialize the loader
  137. var l = this.loader;
  138. if(!l){
  139. l = new Ext.tree.TreeLoader({
  140. dataUrl: this.dataUrl,
  141. requestMethod: this.requestMethod
  142. });
  143. }else if(Ext.isObject(l) && !l.load){
  144. l = new Ext.tree.TreeLoader(l);
  145. }
  146. this.loader = l;
  147. this.nodeHash = {};
  148. /**
  149. * The root node of this tree.
  150. * @type Ext.tree.TreeNode
  151. * @property root
  152. */
  153. if(this.root){
  154. var r = this.root;
  155. delete this.root;
  156. this.setRootNode(r);
  157. }
  158. this.addEvents(
  159. /**
  160. * @event append
  161. * Fires when a new child node is appended to a node in this tree.
  162. * @param {Tree} tree The owner tree
  163. * @param {Node} parent The parent node
  164. * @param {Node} node The newly appended node
  165. * @param {Number} index The index of the newly appended node
  166. */
  167. 'append',
  168. /**
  169. * @event remove
  170. * Fires when a child node is removed from a node in this tree.
  171. * @param {Tree} tree The owner tree
  172. * @param {Node} parent The parent node
  173. * @param {Node} node The child node removed
  174. */
  175. 'remove',
  176. /**
  177. * @event movenode
  178. * Fires when a node is moved to a new location in the tree
  179. * @param {Tree} tree The owner tree
  180. * @param {Node} node The node moved
  181. * @param {Node} oldParent The old parent of this node
  182. * @param {Node} newParent The new parent of this node
  183. * @param {Number} index The index it was moved to
  184. */
  185. 'movenode',
  186. /**
  187. * @event insert
  188. * Fires when a new child node is inserted in a node in this tree.
  189. * @param {Tree} tree The owner tree
  190. * @param {Node} parent The parent node
  191. * @param {Node} node The child node inserted
  192. * @param {Node} refNode The child node the node was inserted before
  193. */
  194. 'insert',
  195. /**
  196. * @event beforeappend
  197. * Fires before a new child is appended to a node in this tree, return false to cancel the append.
  198. * @param {Tree} tree The owner tree
  199. * @param {Node} parent The parent node
  200. * @param {Node} node The child node to be appended
  201. */
  202. 'beforeappend',
  203. /**
  204. * @event beforeremove
  205. * Fires before a child is removed from a node in this tree, return false to cancel the remove.
  206. * @param {Tree} tree The owner tree
  207. * @param {Node} parent The parent node
  208. * @param {Node} node The child node to be removed
  209. */
  210. 'beforeremove',
  211. /**
  212. * @event beforemovenode
  213. * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
  214. * @param {Tree} tree The owner tree
  215. * @param {Node} node The node being moved
  216. * @param {Node} oldParent The parent of the node
  217. * @param {Node} newParent The new parent the node is moving to
  218. * @param {Number} index The index it is being moved to
  219. */
  220. 'beforemovenode',
  221. /**
  222. * @event beforeinsert
  223. * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
  224. * @param {Tree} tree The owner tree
  225. * @param {Node} parent The parent node
  226. * @param {Node} node The child node to be inserted
  227. * @param {Node} refNode The child node the node is being inserted before
  228. */
  229. 'beforeinsert',
  230. /**
  231. * @event beforeload
  232. * Fires before a node is loaded, return false to cancel
  233. * @param {Node} node The node being loaded
  234. */
  235. 'beforeload',
  236. /**
  237. * @event load
  238. * Fires when a node is loaded
  239. * @param {Node} node The node that was loaded
  240. */
  241. 'load',
  242. /**
  243. * @event textchange
  244. * Fires when the text for a node is changed
  245. * @param {Node} node The node
  246. * @param {String} text The new text
  247. * @param {String} oldText The old text
  248. */
  249. 'textchange',
  250. /**
  251. * @event beforeexpandnode
  252. * Fires before a node is expanded, return false to cancel.
  253. * @param {Node} node The node
  254. * @param {Boolean} deep
  255. * @param {Boolean} anim
  256. */
  257. 'beforeexpandnode',
  258. /**
  259. * @event beforecollapsenode
  260. * Fires before a node is collapsed, return false to cancel.
  261. * @param {Node} node The node
  262. * @param {Boolean} deep
  263. * @param {Boolean} anim
  264. */
  265. 'beforecollapsenode',
  266. /**
  267. * @event expandnode
  268. * Fires when a node is expanded
  269. * @param {Node} node The node
  270. */
  271. 'expandnode',
  272. /**
  273. * @event disabledchange
  274. * Fires when the disabled status of a node changes
  275. * @param {Node} node The node
  276. * @param {Boolean} disabled
  277. */
  278. 'disabledchange',
  279. /**
  280. * @event collapsenode
  281. * Fires when a node is collapsed
  282. * @param {Node} node The node
  283. */
  284. 'collapsenode',
  285. /**
  286. * @event beforeclick
  287. * Fires before click processing on a node. Return false to cancel the default action.
  288. * @param {Node} node The node
  289. * @param {Ext.EventObject} e The event object
  290. */
  291. 'beforeclick',
  292. /**
  293. * @event click
  294. * Fires when a node is clicked
  295. * @param {Node} node The node
  296. * @param {Ext.EventObject} e The event object
  297. */
  298. 'click',
  299. /**
  300. * @event containerclick
  301. * Fires when the tree container is clicked
  302. * @param {Tree} this
  303. * @param {Ext.EventObject} e The event object
  304. */
  305. 'containerclick',
  306. /**
  307. * @event checkchange
  308. * Fires when a node with a checkbox's checked property changes
  309. * @param {Node} this This node
  310. * @param {Boolean} checked
  311. */
  312. 'checkchange',
  313. /**
  314. * @event beforedblclick
  315. * Fires before double click processing on a node. Return false to cancel the default action.
  316. * @param {Node} node The node
  317. * @param {Ext.EventObject} e The event object
  318. */
  319. 'beforedblclick',
  320. /**
  321. * @event dblclick
  322. * Fires when a node is double clicked
  323. * @param {Node} node The node
  324. * @param {Ext.EventObject} e The event object
  325. */
  326. 'dblclick',
  327. /**
  328. * @event containerdblclick
  329. * Fires when the tree container is double clicked
  330. * @param {Tree} this
  331. * @param {Ext.EventObject} e The event object
  332. */
  333. 'containerdblclick',
  334. /**
  335. * @event contextmenu
  336. * Fires when a node is right clicked. To display a context menu in response to this
  337. * event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add
  338. * a handler for this event:<pre><code>
  339. new Ext.tree.TreePanel({
  340. title: 'My TreePanel',
  341. root: new Ext.tree.AsyncTreeNode({
  342. text: 'The Root',
  343. children: [
  344. { text: 'Child node 1', leaf: true },
  345. { text: 'Child node 2', leaf: true }
  346. ]
  347. }),
  348. contextMenu: new Ext.menu.Menu({
  349. items: [{
  350. id: 'delete-node',
  351. text: 'Delete Node'
  352. }],
  353. listeners: {
  354. itemclick: function(item) {
  355. switch (item.id) {
  356. case 'delete-node':
  357. var n = item.parentMenu.contextNode;
  358. if (n.parentNode) {
  359. n.remove();
  360. }
  361. break;
  362. }
  363. }
  364. }
  365. }),
  366. listeners: {
  367. contextmenu: function(node, e) {
  368. // Register the context node with the menu so that a Menu Item's handler function can access
  369. // it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.
  370. node.select();
  371. var c = node.getOwnerTree().contextMenu;
  372. c.contextNode = node;
  373. c.showAt(e.getXY());
  374. }
  375. }
  376. });
  377. </code></pre>
  378. * @param {Node} node The node
  379. * @param {Ext.EventObject} e The event object
  380. */
  381. 'contextmenu',
  382. /**
  383. * @event containercontextmenu
  384. * Fires when the tree container is right clicked
  385. * @param {Tree} this
  386. * @param {Ext.EventObject} e The event object
  387. */
  388. 'containercontextmenu',
  389. /**
  390. * @event beforechildrenrendered
  391. * Fires right before the child nodes for a node are rendered
  392. * @param {Node} node The node
  393. */
  394. 'beforechildrenrendered',
  395. /**
  396. * @event startdrag
  397. * Fires when a node starts being dragged
  398. * @param {Ext.tree.TreePanel} this
  399. * @param {Ext.tree.TreeNode} node
  400. * @param {event} e The raw browser event
  401. */
  402. 'startdrag',
  403. /**
  404. * @event enddrag
  405. * Fires when a drag operation is complete
  406. * @param {Ext.tree.TreePanel} this
  407. * @param {Ext.tree.TreeNode} node
  408. * @param {event} e The raw browser event
  409. */
  410. 'enddrag',
  411. /**
  412. * @event dragdrop
  413. * Fires when a dragged node is dropped on a valid DD target
  414. * @param {Ext.tree.TreePanel} this
  415. * @param {Ext.tree.TreeNode} node
  416. * @param {DD} dd The dd it was dropped on
  417. * @param {event} e The raw browser event
  418. */
  419. 'dragdrop',
  420. /**
  421. * @event beforenodedrop
  422. * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
  423. * passed to handlers has the following properties:<br />
  424. * <ul style="padding:5px;padding-left:16px;">
  425. * <li>tree - The TreePanel</li>
  426. * <li>target - The node being targeted for the drop</li>
  427. * <li>data - The drag data from the drag source</li>
  428. * <li>point - The point of the drop - append, above or below</li>
  429. * <li>source - The drag source</li>
  430. * <li>rawEvent - Raw mouse event</li>
  431. * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
  432. * to be inserted by setting them on this object.</li>
  433. * <li>cancel - Set this to true to cancel the drop.</li>
  434. * <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true
  435. * will prevent the animated 'repair' from appearing.</li>
  436. * </ul>
  437. * @param {Object} dropEvent
  438. */
  439. 'beforenodedrop',
  440. /**
  441. * @event nodedrop
  442. * Fires after a DD object is dropped on a node in this tree. The dropEvent
  443. * passed to handlers has the following properties:<br />
  444. * <ul style="padding:5px;padding-left:16px;">
  445. * <li>tree - The TreePanel</li>
  446. * <li>target - The node being targeted for the drop</li>
  447. * <li>data - The drag data from the drag source</li>
  448. * <li>point - The point of the drop - append, above or below</li>
  449. * <li>source - The drag source</li>
  450. * <li>rawEvent - Raw mouse event</li>
  451. * <li>dropNode - Dropped node(s).</li>
  452. * </ul>
  453. * @param {Object} dropEvent
  454. */
  455. 'nodedrop',
  456. /**
  457. * @event nodedragover
  458. * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
  459. * passed to handlers has the following properties:<br />
  460. * <ul style="padding:5px;padding-left:16px;">
  461. * <li>tree - The TreePanel</li>
  462. * <li>target - The node being targeted for the drop</li>
  463. * <li>data - The drag data from the drag source</li>
  464. * <li>point - The point of the drop - append, above or below</li>
  465. * <li>source - The drag source</li>
  466. * <li>rawEvent - Raw mouse event</li>
  467. * <li>dropNode - Drop node(s) provided by the source.</li>
  468. * <li>cancel - Set this to true to signal drop not allowed.</li>
  469. * </ul>
  470. * @param {Object} dragOverEvent
  471. */
  472. 'nodedragover'
  473. );
  474. if(this.singleExpand){
  475. this.on('beforeexpandnode', this.restrictExpand, this);
  476. }
  477. },
  478. // private
  479. proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){
  480. if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){
  481. ename = ename+'node';
  482. }
  483. // args inline for performance while bubbling events
  484. return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);
  485. },
  486. /**
  487. * Returns this root node for this tree
  488. * @return {Node}
  489. */
  490. getRootNode : function(){
  491. return this.root;
  492. },
  493. /**
  494. * Sets the root node for this tree. If the TreePanel has already rendered a root node, the
  495. * previous root node (and all of its descendants) are destroyed before the new root node is rendered.
  496. * @param {Node} node
  497. * @return {Node}
  498. */
  499. setRootNode : function(node){
  500. this.destroyRoot();
  501. if(!node.render){ // attributes passed
  502. node = this.loader.createNode(node);
  503. }
  504. this.root = node;
  505. node.ownerTree = this;
  506. node.isRoot = true;
  507. this.registerNode(node);
  508. if(!this.rootVisible){
  509. var uiP = node.attributes.uiProvider;
  510. node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);
  511. }
  512. if(this.innerCt){
  513. this.clearInnerCt();
  514. this.renderRoot();
  515. }
  516. return node;
  517. },
  518. clearInnerCt : function(){
  519. this.innerCt.update('');
  520. },
  521. // private
  522. renderRoot : function(){
  523. this.root.render();
  524. if(!this.rootVisible){
  525. this.root.renderChildren();
  526. }
  527. },
  528. /**
  529. * Gets a node in this tree by its id
  530. * @param {String} id
  531. * @return {Node}
  532. */
  533. getNodeById : function(id){
  534. return this.nodeHash[id];
  535. },
  536. // private
  537. registerNode : function(node){
  538. this.nodeHash[node.id] = node;
  539. },
  540. // private
  541. unregisterNode : function(node){
  542. delete this.nodeHash[node.id];
  543. },
  544. // private
  545. toString : function(){
  546. return '[Tree'+(this.id?' '+this.id:'')+']';
  547. },
  548. // private
  549. restrictExpand : function(node){
  550. var p = node.parentNode;
  551. if(p){
  552. if(p.expandedChild && p.expandedChild.parentNode == p){
  553. p.expandedChild.collapse();
  554. }
  555. p.expandedChild = node;
  556. }
  557. },
  558. /**
  559. * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. 'id')
  560. * @param {String} attribute (optional) Defaults to null (return the actual nodes)
  561. * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
  562. * @return {Array}
  563. */
  564. getChecked : function(a, startNode){
  565. startNode = startNode || this.root;
  566. var r = [];
  567. var f = function(){
  568. if(this.attributes.checked){
  569. r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
  570. }
  571. };
  572. startNode.cascade(f);
  573. return r;
  574. },
  575. /**
  576. * Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.
  577. * @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.
  578. */
  579. getLoader : function(){
  580. return this.loader;
  581. },
  582. /**
  583. * Expand all nodes
  584. */
  585. expandAll : function(){
  586. this.root.expand(true);
  587. },
  588. /**
  589. * Collapse all nodes
  590. */
  591. collapseAll : function(){
  592. this.root.collapse(true);
  593. },
  594. /**
  595. * Returns the selection model used by this TreePanel.
  596. * @return {TreeSelectionModel} The selection model used by this TreePanel
  597. */
  598. getSelectionModel : function(){
  599. if(!this.selModel){
  600. this.selModel = new Ext.tree.DefaultSelectionModel();
  601. }
  602. return this.selModel;
  603. },
  604. /**
  605. * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
  606. * @param {String} path
  607. * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
  608. * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
  609. * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
  610. */
  611. expandPath : function(path, attr, callback){
  612. if(Ext.isEmpty(path)){
  613. if(callback){
  614. callback(false, undefined);
  615. }
  616. return;
  617. }
  618. attr = attr || 'id';
  619. var keys = path.split(this.pathSeparator);
  620. var curNode = this.root;
  621. if(curNode.attributes[attr] != keys[1]){ // invalid root
  622. if(callback){
  623. callback(false, null);
  624. }
  625. return;
  626. }
  627. var index = 1;
  628. var f = function(){
  629. if(++index == keys.length){
  630. if(callback){
  631. callback(true, curNode);
  632. }
  633. return;
  634. }
  635. var c = curNode.findChild(attr, keys[index]);
  636. if(!c){
  637. if(callback){
  638. callback(false, curNode);
  639. }
  640. return;
  641. }
  642. curNode = c;
  643. c.expand(false, false, f);
  644. };
  645. curNode.expand(false, false, f);
  646. },
  647. /**
  648. * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
  649. * @param {String} path
  650. * @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
  651. * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
  652. * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
  653. */
  654. selectPath : function(path, attr, callback){
  655. if(Ext.isEmpty(path)){
  656. if(callback){
  657. callback(false, undefined);
  658. }
  659. return;
  660. }
  661. attr = attr || 'id';
  662. var keys = path.split(this.pathSeparator),
  663. v = keys.pop();
  664. if(keys.length > 1){
  665. var f = function(success, node){
  666. if(success && node){
  667. var n = node.findChild(attr, v);
  668. if(n){
  669. n.select();
  670. if(callback){
  671. callback(true, n);
  672. }
  673. }else if(callback){
  674. callback(false, n);
  675. }
  676. }else{
  677. if(callback){
  678. callback(false, n);
  679. }
  680. }
  681. };
  682. this.expandPath(keys.join(this.pathSeparator), attr, f);
  683. }else{
  684. this.root.select();
  685. if(callback){
  686. callback(true, this.root);
  687. }
  688. }
  689. },
  690. /**
  691. * Returns the underlying Element for this tree
  692. * @return {Ext.Element} The Element
  693. */
  694. getTreeEl : function(){
  695. return this.body;
  696. },
  697. // private
  698. onRender : function(ct, position){
  699. Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
  700. this.el.addClass('x-tree');
  701. this.innerCt = this.body.createChild({tag:'ul',
  702. cls:'x-tree-root-ct ' +
  703. (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')});
  704. },
  705. // private
  706. initEvents : function(){
  707. Ext.tree.TreePanel.superclass.initEvents.call(this);
  708. if(this.containerScroll){
  709. Ext.dd.ScrollManager.register(this.body);
  710. }
  711. if((this.enableDD || this.enableDrop) && !this.dropZone){
  712. /**
  713. * The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
  714. * @property dropZone
  715. * @type Ext.tree.TreeDropZone
  716. */
  717. this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
  718. ddGroup: this.ddGroup || 'TreeDD', appendOnly: this.ddAppendOnly === true
  719. });
  720. }
  721. if((this.enableDD || this.enableDrag) && !this.dragZone){
  722. /**
  723. * The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
  724. * @property dragZone
  725. * @type Ext.tree.TreeDragZone
  726. */
  727. this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
  728. ddGroup: this.ddGroup || 'TreeDD',
  729. scroll: this.ddScroll
  730. });
  731. }
  732. this.getSelectionModel().init(this);
  733. },
  734. // private
  735. afterRender : function(){
  736. Ext.tree.TreePanel.superclass.afterRender.call(this);
  737. this.renderRoot();
  738. },
  739. beforeDestroy : function(){
  740. if(this.rendered){
  741. Ext.dd.ScrollManager.unregister(this.body);
  742. Ext.destroy(this.dropZone, this.dragZone);
  743. }
  744. this.destroyRoot();
  745. Ext.destroy(this.loader);
  746. this.nodeHash = this.root = this.loader = null;
  747. Ext.tree.TreePanel.superclass.beforeDestroy.call(this);
  748. },
  749. /**
  750. * Destroy the root node. Not included by itself because we need to pass the silent parameter.
  751. * @private
  752. */
  753. destroyRoot : function(){
  754. if(this.root && this.root.destroy){
  755. this.root.destroy(true);
  756. }
  757. }
  758. /**
  759. * @cfg {String/Number} activeItem
  760. * @hide
  761. */
  762. /**
  763. * @cfg {Boolean} autoDestroy
  764. * @hide
  765. */
  766. /**
  767. * @cfg {Object/String/Function} autoLoad
  768. * @hide
  769. */
  770. /**
  771. * @cfg {Boolean} autoWidth
  772. * @hide
  773. */
  774. /**
  775. * @cfg {Boolean/Number} bufferResize
  776. * @hide
  777. */
  778. /**
  779. * @cfg {String} defaultType
  780. * @hide
  781. */
  782. /**
  783. * @cfg {Object} defaults
  784. * @hide
  785. */
  786. /**
  787. * @cfg {Boolean} hideBorders
  788. * @hide
  789. */
  790. /**
  791. * @cfg {Mixed} items
  792. * @hide
  793. */
  794. /**
  795. * @cfg {String} layout
  796. * @hide
  797. */
  798. /**
  799. * @cfg {Object} layoutConfig
  800. * @hide
  801. */
  802. /**
  803. * @cfg {Boolean} monitorResize
  804. * @hide
  805. */
  806. /**
  807. * @property items
  808. * @hide
  809. */
  810. /**
  811. * @method cascade
  812. * @hide
  813. */
  814. /**
  815. * @method doLayout
  816. * @hide
  817. */
  818. /**
  819. * @method find
  820. * @hide
  821. */
  822. /**
  823. * @method findBy
  824. * @hide
  825. */
  826. /**
  827. * @method findById
  828. * @hide
  829. */
  830. /**
  831. * @method findByType
  832. * @hide
  833. */
  834. /**
  835. * @method getComponent
  836. * @hide
  837. */
  838. /**
  839. * @method getLayout
  840. * @hide
  841. */
  842. /**
  843. * @method getUpdater
  844. * @hide
  845. */
  846. /**
  847. * @method insert
  848. * @hide
  849. */
  850. /**
  851. * @method load
  852. * @hide
  853. */
  854. /**
  855. * @method remove
  856. * @hide
  857. */
  858. /**
  859. * @event add
  860. * @hide
  861. */
  862. /**
  863. * @method removeAll
  864. * @hide
  865. */
  866. /**
  867. * @event afterLayout
  868. * @hide
  869. */
  870. /**
  871. * @event beforeadd
  872. * @hide
  873. */
  874. /**
  875. * @event beforeremove
  876. * @hide
  877. */
  878. /**
  879. * @event remove
  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} node the new selection
  1125. * @param {TreeNode} node 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 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(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 single parameter (the {@link Ext.tree.TreeNode} being evaluated) and is expected to return
  3917. * 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. Note that if a sortType is specified, any {@link #property} config will be ignored.
  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) : (caseSensitive ? prop1 : prop1.toUpperCase());
  3952. v2 = sortType ? sortType(prop2) : (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. * @class Ext.tree.TreeDropZone
  3977. * @extends Ext.dd.DropZone
  3978. * @constructor
  3979. * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dropping
  3980. * @param {Object} config
  3981. */
  3982. if(Ext.dd.DropZone){
  3983. Ext.tree.TreeDropZone = function(tree, config){
  3984. /**
  3985. * @cfg {Boolean} allowParentInsert
  3986. * Allow inserting a dragged node between an expanded parent node and its first child that will become a
  3987. * sibling of the parent when dropped (defaults to false)
  3988. */
  3989. this.allowParentInsert = config.allowParentInsert || false;
  3990. /**
  3991. * @cfg {String} allowContainerDrop
  3992. * True if drops on the tree container (outside of a specific tree node) are allowed (defaults to false)
  3993. */
  3994. this.allowContainerDrop = config.allowContainerDrop || false;
  3995. /**
  3996. * @cfg {String} appendOnly
  3997. * True if the tree should only allow append drops (use for trees which are sorted, defaults to false)
  3998. */
  3999. this.appendOnly = config.appendOnly || false;
  4000. Ext.tree.TreeDropZone.superclass.constructor.call(this, tree.getTreeEl(), config);
  4001. /**
  4002. * The TreePanel for this drop zone
  4003. * @type Ext.tree.TreePanel
  4004. * @property
  4005. */
  4006. this.tree = tree;
  4007. /**
  4008. * Arbitrary data that can be associated with this tree and will be included in the event object that gets
  4009. * passed to any nodedragover event handler (defaults to {})
  4010. * @type Ext.tree.TreePanel
  4011. * @property
  4012. */
  4013. this.dragOverData = {};
  4014. // private
  4015. this.lastInsertClass = "x-tree-no-status";
  4016. };
  4017. Ext.extend(Ext.tree.TreeDropZone, Ext.dd.DropZone, {
  4018. /**
  4019. * @cfg {String} ddGroup
  4020. * A named drag drop group to which this object belongs. If a group is specified, then this object will only
  4021. * interact with other drag drop objects in the same group (defaults to 'TreeDD').
  4022. */
  4023. ddGroup : "TreeDD",
  4024. /**
  4025. * @cfg {String} expandDelay
  4026. * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node
  4027. * over the target (defaults to 1000)
  4028. */
  4029. expandDelay : 1000,
  4030. // private
  4031. expandNode : function(node){
  4032. if(node.hasChildNodes() && !node.isExpanded()){
  4033. node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
  4034. }
  4035. },
  4036. // private
  4037. queueExpand : function(node){
  4038. this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
  4039. },
  4040. // private
  4041. cancelExpand : function(){
  4042. if(this.expandProcId){
  4043. clearTimeout(this.expandProcId);
  4044. this.expandProcId = false;
  4045. }
  4046. },
  4047. // private
  4048. isValidDropPoint : function(n, pt, dd, e, data){
  4049. if(!n || !data){ return false; }
  4050. var targetNode = n.node;
  4051. var dropNode = data.node;
  4052. // default drop rules
  4053. if(!(targetNode && targetNode.isTarget && pt)){
  4054. return false;
  4055. }
  4056. if(pt == "append" && targetNode.allowChildren === false){
  4057. return false;
  4058. }
  4059. if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
  4060. return false;
  4061. }
  4062. if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
  4063. return false;
  4064. }
  4065. // reuse the object
  4066. var overEvent = this.dragOverData;
  4067. overEvent.tree = this.tree;
  4068. overEvent.target = targetNode;
  4069. overEvent.data = data;
  4070. overEvent.point = pt;
  4071. overEvent.source = dd;
  4072. overEvent.rawEvent = e;
  4073. overEvent.dropNode = dropNode;
  4074. overEvent.cancel = false;
  4075. var result = this.tree.fireEvent("nodedragover", overEvent);
  4076. return overEvent.cancel === false && result !== false;
  4077. },
  4078. // private
  4079. getDropPoint : function(e, n, dd){
  4080. var tn = n.node;
  4081. if(tn.isRoot){
  4082. return tn.allowChildren !== false ? "append" : false; // always append for root
  4083. }
  4084. var dragEl = n.ddel;
  4085. var t = Ext.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
  4086. var y = Ext.lib.Event.getPageY(e);
  4087. var noAppend = tn.allowChildren === false || tn.isLeaf();
  4088. if(this.appendOnly || tn.parentNode.allowChildren === false){
  4089. return noAppend ? false : "append";
  4090. }
  4091. var noBelow = false;
  4092. if(!this.allowParentInsert){
  4093. noBelow = tn.hasChildNodes() && tn.isExpanded();
  4094. }
  4095. var q = (b - t) / (noAppend ? 2 : 3);
  4096. if(y >= t && y < (t + q)){
  4097. return "above";
  4098. }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
  4099. return "below";
  4100. }else{
  4101. return "append";
  4102. }
  4103. },
  4104. // private
  4105. onNodeEnter : function(n, dd, e, data){
  4106. this.cancelExpand();
  4107. },
  4108. onContainerOver : function(dd, e, data) {
  4109. if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
  4110. return this.dropAllowed;
  4111. }
  4112. return this.dropNotAllowed;
  4113. },
  4114. // private
  4115. onNodeOver : function(n, dd, e, data){
  4116. var pt = this.getDropPoint(e, n, dd);
  4117. var node = n.node;
  4118. // auto node expand check
  4119. if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
  4120. this.queueExpand(node);
  4121. }else if(pt != "append"){
  4122. this.cancelExpand();
  4123. }
  4124. // set the insert point style on the target node
  4125. var returnCls = this.dropNotAllowed;
  4126. if(this.isValidDropPoint(n, pt, dd, e, data)){
  4127. if(pt){
  4128. var el = n.ddel;
  4129. var cls;
  4130. if(pt == "above"){
  4131. returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
  4132. cls = "x-tree-drag-insert-above";
  4133. }else if(pt == "below"){
  4134. returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
  4135. cls = "x-tree-drag-insert-below";
  4136. }else{
  4137. returnCls = "x-tree-drop-ok-append";
  4138. cls = "x-tree-drag-append";
  4139. }
  4140. if(this.lastInsertClass != cls){
  4141. Ext.fly(el).replaceClass(this.lastInsertClass, cls);
  4142. this.lastInsertClass = cls;
  4143. }
  4144. }
  4145. }
  4146. return returnCls;
  4147. },
  4148. // private
  4149. onNodeOut : function(n, dd, e, data){
  4150. this.cancelExpand();
  4151. this.removeDropIndicators(n);
  4152. },
  4153. // private
  4154. onNodeDrop : function(n, dd, e, data){
  4155. var point = this.getDropPoint(e, n, dd);
  4156. var targetNode = n.node;
  4157. targetNode.ui.startDrop();
  4158. if(!this.isValidDropPoint(n, point, dd, e, data)){
  4159. targetNode.ui.endDrop();
  4160. return false;
  4161. }
  4162. // first try to find the drop node
  4163. var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
  4164. return this.processDrop(targetNode, data, point, dd, e, dropNode);
  4165. },
  4166. onContainerDrop : function(dd, e, data){
  4167. if (this.allowContainerDrop && this.isValidDropPoint({ ddel: this.tree.getRootNode().ui.elNode, node: this.tree.getRootNode() }, "append", dd, e, data)) {
  4168. var targetNode = this.tree.getRootNode();
  4169. targetNode.ui.startDrop();
  4170. var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, 'append', e) : null);
  4171. return this.processDrop(targetNode, data, 'append', dd, e, dropNode);
  4172. }
  4173. return false;
  4174. },
  4175. // private
  4176. processDrop: function(target, data, point, dd, e, dropNode){
  4177. var dropEvent = {
  4178. tree : this.tree,
  4179. target: target,
  4180. data: data,
  4181. point: point,
  4182. source: dd,
  4183. rawEvent: e,
  4184. dropNode: dropNode,
  4185. cancel: !dropNode,
  4186. dropStatus: false
  4187. };
  4188. var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
  4189. if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
  4190. target.ui.endDrop();
  4191. return dropEvent.dropStatus;
  4192. }
  4193. target = dropEvent.target;
  4194. if(point == 'append' && !target.isExpanded()){
  4195. target.expand(false, null, function(){
  4196. this.completeDrop(dropEvent);
  4197. }.createDelegate(this));
  4198. }else{
  4199. this.completeDrop(dropEvent);
  4200. }
  4201. return true;
  4202. },
  4203. // private
  4204. completeDrop : function(de){
  4205. var ns = de.dropNode, p = de.point, t = de.target;
  4206. if(!Ext.isArray(ns)){
  4207. ns = [ns];
  4208. }
  4209. var n;
  4210. for(var i = 0, len = ns.length; i < len; i++){
  4211. n = ns[i];
  4212. if(p == "above"){
  4213. t.parentNode.insertBefore(n, t);
  4214. }else if(p == "below"){
  4215. t.parentNode.insertBefore(n, t.nextSibling);
  4216. }else{
  4217. t.appendChild(n);
  4218. }
  4219. }
  4220. n.ui.focus();
  4221. if(Ext.enableFx && this.tree.hlDrop){
  4222. n.ui.highlight();
  4223. }
  4224. t.ui.endDrop();
  4225. this.tree.fireEvent("nodedrop", de);
  4226. },
  4227. // private
  4228. afterNodeMoved : function(dd, data, e, targetNode, dropNode){
  4229. if(Ext.enableFx && this.tree.hlDrop){
  4230. dropNode.ui.focus();
  4231. dropNode.ui.highlight();
  4232. }
  4233. this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
  4234. },
  4235. // private
  4236. getTree : function(){
  4237. return this.tree;
  4238. },
  4239. // private
  4240. removeDropIndicators : function(n){
  4241. if(n && n.ddel){
  4242. var el = n.ddel;
  4243. Ext.fly(el).removeClass([
  4244. "x-tree-drag-insert-above",
  4245. "x-tree-drag-insert-below",
  4246. "x-tree-drag-append"]);
  4247. this.lastInsertClass = "_noclass";
  4248. }
  4249. },
  4250. // private
  4251. beforeDragDrop : function(target, e, id){
  4252. this.cancelExpand();
  4253. return true;
  4254. },
  4255. // private
  4256. afterRepair : function(data){
  4257. if(data && Ext.enableFx){
  4258. data.node.ui.highlight();
  4259. }
  4260. this.hideProxy();
  4261. }
  4262. });
  4263. }/**
  4264. * @class Ext.tree.TreeDragZone
  4265. * @extends Ext.dd.DragZone
  4266. * @constructor
  4267. * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dragging
  4268. * @param {Object} config
  4269. */
  4270. if(Ext.dd.DragZone){
  4271. Ext.tree.TreeDragZone = function(tree, config){
  4272. Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.innerCt, config);
  4273. /**
  4274. * The TreePanel for this drag zone
  4275. * @type Ext.tree.TreePanel
  4276. * @property
  4277. */
  4278. this.tree = tree;
  4279. };
  4280. Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, {
  4281. /**
  4282. * @cfg {String} ddGroup
  4283. * A named drag drop group to which this object belongs. If a group is specified, then this object will only
  4284. * interact with other drag drop objects in the same group (defaults to 'TreeDD').
  4285. */
  4286. ddGroup : "TreeDD",
  4287. // private
  4288. onBeforeDrag : function(data, e){
  4289. var n = data.node;
  4290. return n && n.draggable && !n.disabled;
  4291. },
  4292. // private
  4293. onInitDrag : function(e){
  4294. var data = this.dragData;
  4295. this.tree.getSelectionModel().select(data.node);
  4296. this.tree.eventModel.disable();
  4297. this.proxy.update("");
  4298. data.node.ui.appendDDGhost(this.proxy.ghost.dom);
  4299. this.tree.fireEvent("startdrag", this.tree, data.node, e);
  4300. },
  4301. // private
  4302. getRepairXY : function(e, data){
  4303. return data.node.ui.getDDRepairXY();
  4304. },
  4305. // private
  4306. onEndDrag : function(data, e){
  4307. this.tree.eventModel.enable.defer(100, this.tree.eventModel);
  4308. this.tree.fireEvent("enddrag", this.tree, data.node, e);
  4309. },
  4310. // private
  4311. onValidDrop : function(dd, e, id){
  4312. this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
  4313. this.hideProxy();
  4314. },
  4315. // private
  4316. beforeInvalidDrop : function(e, id){
  4317. // this scrolls the original position back into view
  4318. var sm = this.tree.getSelectionModel();
  4319. sm.clearSelections();
  4320. sm.select(this.dragData.node);
  4321. },
  4322. // private
  4323. afterRepair : function(){
  4324. if (Ext.enableFx && this.tree.hlDrop) {
  4325. Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
  4326. }
  4327. this.dragging = false;
  4328. }
  4329. });
  4330. }/**
  4331. * @class Ext.tree.TreeEditor
  4332. * @extends Ext.Editor
  4333. * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
  4334. * as the editor field.
  4335. * @constructor
  4336. * @param {TreePanel} tree
  4337. * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
  4338. * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
  4339. * @param {Object} config (optional) A TreeEditor config object
  4340. */
  4341. Ext.tree.TreeEditor = function(tree, fc, config){
  4342. fc = fc || {};
  4343. var field = fc.events ? fc : new Ext.form.TextField(fc);
  4344. Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
  4345. this.tree = tree;
  4346. if(!tree.rendered){
  4347. tree.on('render', this.initEditor, this);
  4348. }else{
  4349. this.initEditor(tree);
  4350. }
  4351. };
  4352. Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
  4353. /**
  4354. * @cfg {String} alignment
  4355. * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "l-l").
  4356. */
  4357. alignment: "l-l",
  4358. // inherit
  4359. autoSize: false,
  4360. /**
  4361. * @cfg {Boolean} hideEl
  4362. * True to hide the bound element while the editor is displayed (defaults to false)
  4363. */
  4364. hideEl : false,
  4365. /**
  4366. * @cfg {String} cls
  4367. * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
  4368. */
  4369. cls: "x-small-editor x-tree-editor",
  4370. /**
  4371. * @cfg {Boolean} shim
  4372. * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
  4373. */
  4374. shim:false,
  4375. // inherit
  4376. shadow:"frame",
  4377. /**
  4378. * @cfg {Number} maxWidth
  4379. * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
  4380. * the containing tree element's size, it will be automatically limited for you to the container width, taking
  4381. * scroll and client offsets into account prior to each edit.
  4382. */
  4383. maxWidth: 250,
  4384. /**
  4385. * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
  4386. * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
  4387. * the editor for the node will display, otherwise it will be processed as a regular click.
  4388. */
  4389. editDelay : 350,
  4390. initEditor : function(tree){
  4391. tree.on({
  4392. scope : this,
  4393. beforeclick: this.beforeNodeClick,
  4394. dblclick : this.onNodeDblClick
  4395. });
  4396. this.on({
  4397. scope : this,
  4398. complete : this.updateNode,
  4399. beforestartedit: this.fitToTree,
  4400. specialkey : this.onSpecialKey
  4401. });
  4402. this.on('startedit', this.bindScroll, this, {delay:10});
  4403. },
  4404. // private
  4405. fitToTree : function(ed, el){
  4406. var td = this.tree.getTreeEl().dom, nd = el.dom;
  4407. if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
  4408. td.scrollLeft = nd.offsetLeft;
  4409. }
  4410. var w = Math.min(
  4411. this.maxWidth,
  4412. (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
  4413. this.setSize(w, '');
  4414. },
  4415. /**
  4416. * Edit the text of the passed {@link Ext.tree.TreeNode TreeNode}.
  4417. * @param node {Ext.tree.TreeNode} The TreeNode to edit. The TreeNode must be {@link Ext.tree.TreeNode#editable editable}.
  4418. */
  4419. triggerEdit : function(node, defer){
  4420. this.completeEdit();
  4421. if(node.attributes.editable !== false){
  4422. /**
  4423. * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
  4424. * @type Ext.tree.TreeNode
  4425. * @property editNode
  4426. */
  4427. this.editNode = node;
  4428. if(this.tree.autoScroll){
  4429. Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
  4430. }
  4431. var value = node.text || '';
  4432. if (!Ext.isGecko && Ext.isEmpty(node.text)){
  4433. node.setText('&#160;');
  4434. }
  4435. this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
  4436. return false;
  4437. }
  4438. },
  4439. // private
  4440. bindScroll : function(){
  4441. this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
  4442. },
  4443. // private
  4444. beforeNodeClick : function(node, e){
  4445. clearTimeout(this.autoEditTimer);
  4446. if(this.tree.getSelectionModel().isSelected(node)){
  4447. e.stopEvent();
  4448. return this.triggerEdit(node);
  4449. }
  4450. },
  4451. onNodeDblClick : function(node, e){
  4452. clearTimeout(this.autoEditTimer);
  4453. },
  4454. // private
  4455. updateNode : function(ed, value){
  4456. this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
  4457. this.editNode.setText(value);
  4458. },
  4459. // private
  4460. onHide : function(){
  4461. Ext.tree.TreeEditor.superclass.onHide.call(this);
  4462. if(this.editNode){
  4463. this.editNode.ui.focus.defer(50, this.editNode.ui);
  4464. }
  4465. },
  4466. // private
  4467. onSpecialKey : function(field, e){
  4468. var k = e.getKey();
  4469. if(k == e.ESC){
  4470. e.stopEvent();
  4471. this.cancelEdit();
  4472. }else if(k == e.ENTER && !e.hasModifier()){
  4473. e.stopEvent();
  4474. this.completeEdit();
  4475. }
  4476. },
  4477. onDestroy : function(){
  4478. clearTimeout(this.autoEditTimer);
  4479. Ext.tree.TreeEditor.superclass.onDestroy.call(this);
  4480. var tree = this.tree;
  4481. tree.un('beforeclick', this.beforeNodeClick, this);
  4482. tree.un('dblclick', this.onNodeDblClick, this);
  4483. }
  4484. });