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.

14765 lines
542 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
2 years ago
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.ComponentMgr
  17. * <p>Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
  18. * thereof) on a page so that they can be easily accessed by {@link Ext.Component component}
  19. * {@link Ext.Component#id id} (see {@link #get}, or the convenience method {@link Ext#getCmp Ext.getCmp}).</p>
  20. * <p>This object also provides a registry of available Component <i>classes</i>
  21. * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
  22. * The <code>{@link Ext.Component#xtype xtype}</code> provides a way to avoid instantiating child Components
  23. * when creating a full, nested config object for a complete Ext page.</p>
  24. * <p>A child Component may be specified simply as a <i>config object</i>
  25. * as long as the correct <code>{@link Ext.Component#xtype xtype}</code> is specified so that if and when the Component
  26. * needs rendering, the correct type can be looked up for lazy instantiation.</p>
  27. * <p>For a list of all available <code>{@link Ext.Component#xtype xtypes}</code>, see {@link Ext.Component}.</p>
  28. * @singleton
  29. */
  30. Ext.ComponentMgr = function(){
  31. var all = new Ext.util.MixedCollection();
  32. var types = {};
  33. var ptypes = {};
  34. return {
  35. /**
  36. * Registers a component.
  37. * @param {Ext.Component} c The component
  38. */
  39. register : function(c){
  40. all.add(c);
  41. },
  42. /**
  43. * Unregisters a component.
  44. * @param {Ext.Component} c The component
  45. */
  46. unregister : function(c){
  47. all.remove(c);
  48. },
  49. /**
  50. * Returns a component by {@link Ext.Component#id id}.
  51. * For additional details see {@link Ext.util.MixedCollection#get}.
  52. * @param {String} id The component {@link Ext.Component#id id}
  53. * @return Ext.Component The Component, <code>undefined</code> if not found, or <code>null</code> if a
  54. * Class was found.
  55. */
  56. get : function(id){
  57. return all.get(id);
  58. },
  59. /**
  60. * Registers a function that will be called when a Component with the specified id is added to ComponentMgr. This will happen on instantiation.
  61. * @param {String} id The component {@link Ext.Component#id id}
  62. * @param {Function} fn The callback function
  63. * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the Component.
  64. */
  65. onAvailable : function(id, fn, scope){
  66. all.on("add", function(index, o){
  67. if(o.id == id){
  68. fn.call(scope || o, o);
  69. all.un("add", fn, scope);
  70. }
  71. });
  72. },
  73. /**
  74. * The MixedCollection used internally for the component cache. An example usage may be subscribing to
  75. * events on the MixedCollection to monitor addition or removal. Read-only.
  76. * @type {MixedCollection}
  77. */
  78. all : all,
  79. /**
  80. * The xtypes that have been registered with the component manager.
  81. * @type {Object}
  82. */
  83. types : types,
  84. /**
  85. * The ptypes that have been registered with the component manager.
  86. * @type {Object}
  87. */
  88. ptypes: ptypes,
  89. /**
  90. * Checks if a Component type is registered.
  91. * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
  92. * @return {Boolean} Whether the type is registered.
  93. */
  94. isRegistered : function(xtype){
  95. return types[xtype] !== undefined;
  96. },
  97. /**
  98. * Checks if a Plugin type is registered.
  99. * @param {Ext.Component} ptype The mnemonic string by which the Plugin class may be looked up
  100. * @return {Boolean} Whether the type is registered.
  101. */
  102. isPluginRegistered : function(ptype){
  103. return ptypes[ptype] !== undefined;
  104. },
  105. /**
  106. * <p>Registers a new Component constructor, keyed by a new
  107. * {@link Ext.Component#xtype}.</p>
  108. * <p>Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
  109. * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
  110. * child Components.
  111. * see {@link Ext.Container#items}</p>
  112. * @param {String} xtype The mnemonic string by which the Component class may be looked up.
  113. * @param {Constructor} cls The new Component class.
  114. */
  115. registerType : function(xtype, cls){
  116. types[xtype] = cls;
  117. cls.xtype = xtype;
  118. },
  119. /**
  120. * Creates a new Component from the specified config object using the
  121. * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
  122. * @param {Object} config A configuration object for the Component you wish to create.
  123. * @param {Constructor} defaultType The constructor to provide the default Component type if
  124. * the config object does not contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
  125. * @return {Ext.Component} The newly instantiated Component.
  126. */
  127. create : function(config, defaultType){
  128. return config.render ? config : new types[config.xtype || defaultType](config);
  129. },
  130. /**
  131. * <p>Registers a new Plugin constructor, keyed by a new
  132. * {@link Ext.Component#ptype}.</p>
  133. * <p>Use this method (or its alias {@link Ext#preg Ext.preg}) to register new
  134. * plugins for {@link Ext.Component}s so that lazy instantiation may be used when specifying
  135. * Plugins.</p>
  136. * @param {String} ptype The mnemonic string by which the Plugin class may be looked up.
  137. * @param {Constructor} cls The new Plugin class.
  138. */
  139. registerPlugin : function(ptype, cls){
  140. ptypes[ptype] = cls;
  141. cls.ptype = ptype;
  142. },
  143. /**
  144. * Creates a new Plugin from the specified config object using the
  145. * config object's {@link Ext.component#ptype ptype} to determine the class to instantiate.
  146. * @param {Object} config A configuration object for the Plugin you wish to create.
  147. * @param {Constructor} defaultType The constructor to provide the default Plugin type if
  148. * the config object does not contain a <code>ptype</code>. (Optional if the config contains a <code>ptype</code>).
  149. * @return {Ext.Component} The newly instantiated Plugin.
  150. */
  151. createPlugin : function(config, defaultType){
  152. var PluginCls = ptypes[config.ptype || defaultType];
  153. if (PluginCls.init) {
  154. return PluginCls;
  155. } else {
  156. return new PluginCls(config);
  157. }
  158. }
  159. };
  160. }();
  161. /**
  162. * Shorthand for {@link Ext.ComponentMgr#registerType}
  163. * @param {String} xtype The {@link Ext.component#xtype mnemonic string} by which the Component class
  164. * may be looked up.
  165. * @param {Constructor} cls The new Component class.
  166. * @member Ext
  167. * @method reg
  168. */
  169. Ext.reg = Ext.ComponentMgr.registerType; // this will be called a lot internally, shorthand to keep the bytes down
  170. /**
  171. * Shorthand for {@link Ext.ComponentMgr#registerPlugin}
  172. * @param {String} ptype The {@link Ext.component#ptype mnemonic string} by which the Plugin class
  173. * may be looked up.
  174. * @param {Constructor} cls The new Plugin class.
  175. * @member Ext
  176. * @method preg
  177. */
  178. Ext.preg = Ext.ComponentMgr.registerPlugin;
  179. /**
  180. * Shorthand for {@link Ext.ComponentMgr#create}
  181. * Creates a new Component from the specified config object using the
  182. * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
  183. * @param {Object} config A configuration object for the Component you wish to create.
  184. * @param {Constructor} defaultType The constructor to provide the default Component type if
  185. * the config object does not contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
  186. * @return {Ext.Component} The newly instantiated Component.
  187. * @member Ext
  188. * @method create
  189. */
  190. Ext.create = Ext.ComponentMgr.create;/**
  191. * @class Ext.Component
  192. * @extends Ext.util.Observable
  193. * <p>Base class for all Ext components. All subclasses of Component may participate in the automated
  194. * Ext component lifecycle of creation, rendering and destruction which is provided by the {@link Ext.Container Container} class.
  195. * Components may be added to a Container through the {@link Ext.Container#items items} config option at the time the Container is created,
  196. * or they may be added dynamically via the {@link Ext.Container#add add} method.</p>
  197. * <p>The Component base class has built-in support for basic hide/show and enable/disable behavior.</p>
  198. * <p>All Components are registered with the {@link Ext.ComponentMgr} on construction so that they can be referenced at any time via
  199. * {@link Ext#getCmp}, passing the {@link #id}.</p>
  200. * <p>All user-developed visual widgets that are required to participate in automated lifecycle and size management should subclass Component (or
  201. * {@link Ext.BoxComponent} if managed box model handling is required, ie height and width management).</p>
  202. * <p>See the <a href="http://extjs.com/learn/Tutorial:Creating_new_UI_controls">Creating new UI controls</a> tutorial for details on how
  203. * and to either extend or augment ExtJs base classes to create custom Components.</p>
  204. * <p>Every component has a specific xtype, which is its Ext-specific type name, along with methods for checking the
  205. * xtype like {@link #getXType} and {@link #isXType}. This is the list of all valid xtypes:</p>
  206. * <pre>
  207. xtype Class
  208. ------------- ------------------
  209. box {@link Ext.BoxComponent}
  210. button {@link Ext.Button}
  211. buttongroup {@link Ext.ButtonGroup}
  212. colorpalette {@link Ext.ColorPalette}
  213. component {@link Ext.Component}
  214. container {@link Ext.Container}
  215. cycle {@link Ext.CycleButton}
  216. dataview {@link Ext.DataView}
  217. datepicker {@link Ext.DatePicker}
  218. editor {@link Ext.Editor}
  219. editorgrid {@link Ext.grid.EditorGridPanel}
  220. flash {@link Ext.FlashComponent}
  221. grid {@link Ext.grid.GridPanel}
  222. listview {@link Ext.ListView}
  223. multislider {@link Ext.slider.MultiSlider}
  224. panel {@link Ext.Panel}
  225. progress {@link Ext.ProgressBar}
  226. propertygrid {@link Ext.grid.PropertyGrid}
  227. slider {@link Ext.slider.SingleSlider}
  228. spacer {@link Ext.Spacer}
  229. splitbutton {@link Ext.SplitButton}
  230. tabpanel {@link Ext.TabPanel}
  231. treepanel {@link Ext.tree.TreePanel}
  232. viewport {@link Ext.ViewPort}
  233. window {@link Ext.Window}
  234. Toolbar components
  235. ---------------------------------------
  236. paging {@link Ext.PagingToolbar}
  237. toolbar {@link Ext.Toolbar}
  238. tbbutton {@link Ext.Toolbar.Button} (deprecated; use button)
  239. tbfill {@link Ext.Toolbar.Fill}
  240. tbitem {@link Ext.Toolbar.Item}
  241. tbseparator {@link Ext.Toolbar.Separator}
  242. tbspacer {@link Ext.Toolbar.Spacer}
  243. tbsplit {@link Ext.Toolbar.SplitButton} (deprecated; use splitbutton)
  244. tbtext {@link Ext.Toolbar.TextItem}
  245. Menu components
  246. ---------------------------------------
  247. menu {@link Ext.menu.Menu}
  248. colormenu {@link Ext.menu.ColorMenu}
  249. datemenu {@link Ext.menu.DateMenu}
  250. menubaseitem {@link Ext.menu.BaseItem}
  251. menucheckitem {@link Ext.menu.CheckItem}
  252. menuitem {@link Ext.menu.Item}
  253. menuseparator {@link Ext.menu.Separator}
  254. menutextitem {@link Ext.menu.TextItem}
  255. Form components
  256. ---------------------------------------
  257. form {@link Ext.form.FormPanel}
  258. checkbox {@link Ext.form.Checkbox}
  259. checkboxgroup {@link Ext.form.CheckboxGroup}
  260. combo {@link Ext.form.ComboBox}
  261. compositefield {@link Ext.form.CompositeField}
  262. datefield {@link Ext.form.DateField}
  263. displayfield {@link Ext.form.DisplayField}
  264. field {@link Ext.form.Field}
  265. fieldset {@link Ext.form.FieldSet}
  266. hidden {@link Ext.form.Hidden}
  267. htmleditor {@link Ext.form.HtmlEditor}
  268. label {@link Ext.form.Label}
  269. numberfield {@link Ext.form.NumberField}
  270. radio {@link Ext.form.Radio}
  271. radiogroup {@link Ext.form.RadioGroup}
  272. textarea {@link Ext.form.TextArea}
  273. textfield {@link Ext.form.TextField}
  274. timefield {@link Ext.form.TimeField}
  275. trigger {@link Ext.form.TriggerField}
  276. twintrigger {@link Ext.form.TwinTriggerField}
  277. Chart components
  278. ---------------------------------------
  279. chart {@link Ext.chart.Chart}
  280. barchart {@link Ext.chart.BarChart}
  281. cartesianchart {@link Ext.chart.CartesianChart}
  282. columnchart {@link Ext.chart.ColumnChart}
  283. linechart {@link Ext.chart.LineChart}
  284. piechart {@link Ext.chart.PieChart}
  285. Store xtypes
  286. ---------------------------------------
  287. arraystore {@link Ext.data.ArrayStore}
  288. directstore {@link Ext.data.DirectStore}
  289. groupingstore {@link Ext.data.GroupingStore}
  290. jsonstore {@link Ext.data.JsonStore}
  291. simplestore {@link Ext.data.SimpleStore} (deprecated; use arraystore)
  292. store {@link Ext.data.Store}
  293. xmlstore {@link Ext.data.XmlStore}
  294. </pre>
  295. * @constructor
  296. * @param {Ext.Element/String/Object} config The configuration options may be specified as either:
  297. * <div class="mdetail-params"><ul>
  298. * <li><b>an element</b> :
  299. * <p class="sub-desc">it is set as the internal element and its id used as the component id</p></li>
  300. * <li><b>a string</b> :
  301. * <p class="sub-desc">it is assumed to be the id of an existing element and is used as the component id</p></li>
  302. * <li><b>anything else</b> :
  303. * <p class="sub-desc">it is assumed to be a standard config object and is applied to the component</p></li>
  304. * </ul></div>
  305. */
  306. Ext.Component = function(config){
  307. config = config || {};
  308. if(config.initialConfig){
  309. if(config.isAction){ // actions
  310. this.baseAction = config;
  311. }
  312. config = config.initialConfig; // component cloning / action set up
  313. }else if(config.tagName || config.dom || Ext.isString(config)){ // element object
  314. config = {applyTo: config, id: config.id || config};
  315. }
  316. /**
  317. * This Component's initial configuration specification. Read-only.
  318. * @type Object
  319. * @property initialConfig
  320. */
  321. this.initialConfig = config;
  322. Ext.apply(this, config);
  323. this.addEvents(
  324. /**
  325. * @event added
  326. * Fires when a component is added to an Ext.Container
  327. * @param {Ext.Component} this
  328. * @param {Ext.Container} ownerCt Container which holds the component
  329. * @param {number} index Position at which the component was added
  330. */
  331. 'added',
  332. /**
  333. * @event disable
  334. * Fires after the component is disabled.
  335. * @param {Ext.Component} this
  336. */
  337. 'disable',
  338. /**
  339. * @event enable
  340. * Fires after the component is enabled.
  341. * @param {Ext.Component} this
  342. */
  343. 'enable',
  344. /**
  345. * @event beforeshow
  346. * Fires before the component is shown by calling the {@link #show} method.
  347. * Return false from an event handler to stop the show.
  348. * @param {Ext.Component} this
  349. */
  350. 'beforeshow',
  351. /**
  352. * @event show
  353. * Fires after the component is shown when calling the {@link #show} method.
  354. * @param {Ext.Component} this
  355. */
  356. 'show',
  357. /**
  358. * @event beforehide
  359. * Fires before the component is hidden by calling the {@link #hide} method.
  360. * Return false from an event handler to stop the hide.
  361. * @param {Ext.Component} this
  362. */
  363. 'beforehide',
  364. /**
  365. * @event hide
  366. * Fires after the component is hidden.
  367. * Fires after the component is hidden when calling the {@link #hide} method.
  368. * @param {Ext.Component} this
  369. */
  370. 'hide',
  371. /**
  372. * @event removed
  373. * Fires when a component is removed from an Ext.Container
  374. * @param {Ext.Component} this
  375. * @param {Ext.Container} ownerCt Container which holds the component
  376. */
  377. 'removed',
  378. /**
  379. * @event beforerender
  380. * Fires before the component is {@link #rendered}. Return false from an
  381. * event handler to stop the {@link #render}.
  382. * @param {Ext.Component} this
  383. */
  384. 'beforerender',
  385. /**
  386. * @event render
  387. * Fires after the component markup is {@link #rendered}.
  388. * @param {Ext.Component} this
  389. */
  390. 'render',
  391. /**
  392. * @event afterrender
  393. * <p>Fires after the component rendering is finished.</p>
  394. * <p>The afterrender event is fired after this Component has been {@link #rendered}, been postprocesed
  395. * by any afterRender method defined for the Component, and, if {@link #stateful}, after state
  396. * has been restored.</p>
  397. * @param {Ext.Component} this
  398. */
  399. 'afterrender',
  400. /**
  401. * @event beforedestroy
  402. * Fires before the component is {@link #destroy}ed. Return false from an event handler to stop the {@link #destroy}.
  403. * @param {Ext.Component} this
  404. */
  405. 'beforedestroy',
  406. /**
  407. * @event destroy
  408. * Fires after the component is {@link #destroy}ed.
  409. * @param {Ext.Component} this
  410. */
  411. 'destroy',
  412. /**
  413. * @event beforestaterestore
  414. * Fires before the state of the component is restored. Return false from an event handler to stop the restore.
  415. * @param {Ext.Component} this
  416. * @param {Object} state The hash of state values returned from the StateProvider. If this
  417. * event is not vetoed, then the state object is passed to <b><tt>applyState</tt></b>. By default,
  418. * that simply copies property values into this Component. The method maybe overriden to
  419. * provide custom state restoration.
  420. */
  421. 'beforestaterestore',
  422. /**
  423. * @event staterestore
  424. * Fires after the state of the component is restored.
  425. * @param {Ext.Component} this
  426. * @param {Object} state The hash of state values returned from the StateProvider. This is passed
  427. * to <b><tt>applyState</tt></b>. By default, that simply copies property values into this
  428. * Component. The method maybe overriden to provide custom state restoration.
  429. */
  430. 'staterestore',
  431. /**
  432. * @event beforestatesave
  433. * Fires before the state of the component is saved to the configured state provider. Return false to stop the save.
  434. * @param {Ext.Component} this
  435. * @param {Object} state The hash of state values. This is determined by calling
  436. * <b><tt>getState()</tt></b> on the Component. This method must be provided by the
  437. * developer to return whetever representation of state is required, by default, Ext.Component
  438. * has a null implementation.
  439. */
  440. 'beforestatesave',
  441. /**
  442. * @event statesave
  443. * Fires after the state of the component is saved to the configured state provider.
  444. * @param {Ext.Component} this
  445. * @param {Object} state The hash of state values. This is determined by calling
  446. * <b><tt>getState()</tt></b> on the Component. This method must be provided by the
  447. * developer to return whetever representation of state is required, by default, Ext.Component
  448. * has a null implementation.
  449. */
  450. 'statesave'
  451. );
  452. this.getId();
  453. Ext.ComponentMgr.register(this);
  454. Ext.Component.superclass.constructor.call(this);
  455. if(this.baseAction){
  456. this.baseAction.addComponent(this);
  457. }
  458. this.initComponent();
  459. if(this.plugins){
  460. if(Ext.isArray(this.plugins)){
  461. for(var i = 0, len = this.plugins.length; i < len; i++){
  462. this.plugins[i] = this.initPlugin(this.plugins[i]);
  463. }
  464. }else{
  465. this.plugins = this.initPlugin(this.plugins);
  466. }
  467. }
  468. if(this.stateful !== false){
  469. this.initState();
  470. }
  471. if(this.applyTo){
  472. this.applyToMarkup(this.applyTo);
  473. delete this.applyTo;
  474. }else if(this.renderTo){
  475. this.render(this.renderTo);
  476. delete this.renderTo;
  477. }
  478. };
  479. // private
  480. Ext.Component.AUTO_ID = 1000;
  481. Ext.extend(Ext.Component, Ext.util.Observable, {
  482. // Configs below are used for all Components when rendered by FormLayout.
  483. /**
  484. * @cfg {String} fieldLabel <p>The label text to display next to this Component (defaults to '').</p>
  485. * <br><p><b>Note</b>: this config is only used when this Component is rendered by a Container which
  486. * has been configured to use the <b>{@link Ext.layout.FormLayout FormLayout}</b> layout manager (e.g.
  487. * {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>).</p><br>
  488. * <p>Also see <tt>{@link #hideLabel}</tt> and
  489. * {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl}.</p>
  490. * Example use:<pre><code>
  491. new Ext.FormPanel({
  492. height: 100,
  493. renderTo: Ext.getBody(),
  494. items: [{
  495. xtype: 'textfield',
  496. fieldLabel: 'Name'
  497. }]
  498. });
  499. </code></pre>
  500. */
  501. /**
  502. * @cfg {String} labelStyle <p>A CSS style specification string to apply directly to this field's
  503. * label. Defaults to the container's labelStyle value if set (e.g.,
  504. * <tt>{@link Ext.layout.FormLayout#labelStyle}</tt> , or '').</p>
  505. * <br><p><b>Note</b>: see the note for <code>{@link #clearCls}</code>.</p><br>
  506. * <p>Also see <code>{@link #hideLabel}</code> and
  507. * <code>{@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl}.</code></p>
  508. * Example use:<pre><code>
  509. new Ext.FormPanel({
  510. height: 100,
  511. renderTo: Ext.getBody(),
  512. items: [{
  513. xtype: 'textfield',
  514. fieldLabel: 'Name',
  515. labelStyle: 'font-weight:bold;'
  516. }]
  517. });
  518. </code></pre>
  519. */
  520. /**
  521. * @cfg {String} labelSeparator <p>The separator to display after the text of each
  522. * <tt>{@link #fieldLabel}</tt>. This property may be configured at various levels.
  523. * The order of precedence is:
  524. * <div class="mdetail-params"><ul>
  525. * <li>field / component level</li>
  526. * <li>container level</li>
  527. * <li>{@link Ext.layout.FormLayout#labelSeparator layout level} (defaults to colon <tt>':'</tt>)</li>
  528. * </ul></div>
  529. * To display no separator for this field's label specify empty string ''.</p>
  530. * <br><p><b>Note</b>: see the note for <tt>{@link #clearCls}</tt>.</p><br>
  531. * <p>Also see <tt>{@link #hideLabel}</tt> and
  532. * {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl}.</p>
  533. * Example use:<pre><code>
  534. new Ext.FormPanel({
  535. height: 100,
  536. renderTo: Ext.getBody(),
  537. layoutConfig: {
  538. labelSeparator: '~' // layout config has lowest priority (defaults to ':')
  539. },
  540. {@link Ext.layout.FormLayout#labelSeparator labelSeparator}: '>>', // config at container level
  541. items: [{
  542. xtype: 'textfield',
  543. fieldLabel: 'Field 1',
  544. labelSeparator: '...' // field/component level config supersedes others
  545. },{
  546. xtype: 'textfield',
  547. fieldLabel: 'Field 2' // labelSeparator will be '='
  548. }]
  549. });
  550. </code></pre>
  551. */
  552. /**
  553. * @cfg {Boolean} hideLabel <p><tt>true</tt> to completely hide the label element
  554. * ({@link #fieldLabel label} and {@link #labelSeparator separator}). Defaults to <tt>false</tt>.
  555. * By default, even if you do not specify a <tt>{@link #fieldLabel}</tt> the space will still be
  556. * reserved so that the field will line up with other fields that do have labels.
  557. * Setting this to <tt>true</tt> will cause the field to not reserve that space.</p>
  558. * <br><p><b>Note</b>: see the note for <tt>{@link #clearCls}</tt>.</p><br>
  559. * Example use:<pre><code>
  560. new Ext.FormPanel({
  561. height: 100,
  562. renderTo: Ext.getBody(),
  563. items: [{
  564. xtype: 'textfield'
  565. hideLabel: true
  566. }]
  567. });
  568. </code></pre>
  569. */
  570. /**
  571. * @cfg {String} clearCls <p>The CSS class used to to apply to the special clearing div rendered
  572. * directly after each form field wrapper to provide field clearing (defaults to
  573. * <tt>'x-form-clear-left'</tt>).</p>
  574. * <br><p><b>Note</b>: this config is only used when this Component is rendered by a Container
  575. * which has been configured to use the <b>{@link Ext.layout.FormLayout FormLayout}</b> layout
  576. * manager (e.g. {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>) and either a
  577. * <tt>{@link #fieldLabel}</tt> is specified or <tt>isFormField=true</tt> is specified.</p><br>
  578. * <p>See {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl} also.</p>
  579. */
  580. /**
  581. * @cfg {String} itemCls
  582. * <p><b>Note</b>: this config is only used when this Component is rendered by a Container which
  583. * has been configured to use the <b>{@link Ext.layout.FormLayout FormLayout}</b> layout manager (e.g.
  584. * {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>).</p><br>
  585. * <p>An additional CSS class to apply to the div wrapping the form item
  586. * element of this field. If supplied, <tt>itemCls</tt> at the <b>field</b> level will override
  587. * the default <tt>itemCls</tt> supplied at the <b>container</b> level. The value specified for
  588. * <tt>itemCls</tt> will be added to the default class (<tt>'x-form-item'</tt>).</p>
  589. * <p>Since it is applied to the item wrapper (see
  590. * {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl}), it allows
  591. * you to write standard CSS rules that can apply to the field, the label (if specified), or
  592. * any other element within the markup for the field.</p>
  593. * <br><p><b>Note</b>: see the note for <tt>{@link #fieldLabel}</tt>.</p><br>
  594. * Example use:<pre><code>
  595. // Apply a style to the field&#39;s label:
  596. &lt;style>
  597. .required .x-form-item-label {font-weight:bold;color:red;}
  598. &lt;/style>
  599. new Ext.FormPanel({
  600. height: 100,
  601. renderTo: Ext.getBody(),
  602. items: [{
  603. xtype: 'textfield',
  604. fieldLabel: 'Name',
  605. itemCls: 'required' //this label will be styled
  606. },{
  607. xtype: 'textfield',
  608. fieldLabel: 'Favorite Color'
  609. }]
  610. });
  611. </code></pre>
  612. */
  613. /**
  614. * @cfg {String} id
  615. * <p>The <b>unique</b> id of this component (defaults to an {@link #getId auto-assigned id}).
  616. * You should assign an id if you need to be able to access the component later and you do
  617. * not have an object reference available (e.g., using {@link Ext}.{@link Ext#getCmp getCmp}).</p>
  618. * <p>Note that this id will also be used as the element id for the containing HTML element
  619. * that is rendered to the page for this component. This allows you to write id-based CSS
  620. * rules to style the specific instance of this component uniquely, and also to select
  621. * sub-elements using this component's id as the parent.</p>
  622. * <p><b>Note</b>: to avoid complications imposed by a unique <tt>id</tt> also see
  623. * <code>{@link #itemId}</code> and <code>{@link #ref}</code>.</p>
  624. * <p><b>Note</b>: to access the container of an item see <code>{@link #ownerCt}</code>.</p>
  625. */
  626. /**
  627. * @cfg {String} itemId
  628. * <p>An <tt>itemId</tt> can be used as an alternative way to get a reference to a component
  629. * when no object reference is available. Instead of using an <code>{@link #id}</code> with
  630. * {@link Ext}.{@link Ext#getCmp getCmp}, use <code>itemId</code> with
  631. * {@link Ext.Container}.{@link Ext.Container#getComponent getComponent} which will retrieve
  632. * <code>itemId</code>'s or <tt>{@link #id}</tt>'s. Since <code>itemId</code>'s are an index to the
  633. * container's internal MixedCollection, the <code>itemId</code> is scoped locally to the container --
  634. * avoiding potential conflicts with {@link Ext.ComponentMgr} which requires a <b>unique</b>
  635. * <code>{@link #id}</code>.</p>
  636. * <pre><code>
  637. var c = new Ext.Panel({ //
  638. {@link Ext.BoxComponent#height height}: 300,
  639. {@link #renderTo}: document.body,
  640. {@link Ext.Container#layout layout}: 'auto',
  641. {@link Ext.Container#items items}: [
  642. {
  643. itemId: 'p1',
  644. {@link Ext.Panel#title title}: 'Panel 1',
  645. {@link Ext.BoxComponent#height height}: 150
  646. },
  647. {
  648. itemId: 'p2',
  649. {@link Ext.Panel#title title}: 'Panel 2',
  650. {@link Ext.BoxComponent#height height}: 150
  651. }
  652. ]
  653. })
  654. p1 = c.{@link Ext.Container#getComponent getComponent}('p1'); // not the same as {@link Ext#getCmp Ext.getCmp()}
  655. p2 = p1.{@link #ownerCt}.{@link Ext.Container#getComponent getComponent}('p2'); // reference via a sibling
  656. * </code></pre>
  657. * <p>Also see <tt>{@link #id}</tt> and <code>{@link #ref}</code>.</p>
  658. * <p><b>Note</b>: to access the container of an item see <tt>{@link #ownerCt}</tt>.</p>
  659. */
  660. /**
  661. * @cfg {String} xtype
  662. * The registered <tt>xtype</tt> to create. This config option is not used when passing
  663. * a config object into a constructor. This config option is used only when
  664. * lazy instantiation is being used, and a child item of a Container is being
  665. * specified not as a fully instantiated Component, but as a <i>Component config
  666. * object</i>. The <tt>xtype</tt> will be looked up at render time up to determine what
  667. * type of child Component to create.<br><br>
  668. * The predefined xtypes are listed {@link Ext.Component here}.
  669. * <br><br>
  670. * If you subclass Components to create your own Components, you may register
  671. * them using {@link Ext.ComponentMgr#registerType} in order to be able to
  672. * take advantage of lazy instantiation and rendering.
  673. */
  674. /**
  675. * @cfg {String} ptype
  676. * The registered <tt>ptype</tt> to create. This config option is not used when passing
  677. * a config object into a constructor. This config option is used only when
  678. * lazy instantiation is being used, and a Plugin is being
  679. * specified not as a fully instantiated Component, but as a <i>Component config
  680. * object</i>. The <tt>ptype</tt> will be looked up at render time up to determine what
  681. * type of Plugin to create.<br><br>
  682. * If you create your own Plugins, you may register them using
  683. * {@link Ext.ComponentMgr#registerPlugin} in order to be able to
  684. * take advantage of lazy instantiation and rendering.
  685. */
  686. /**
  687. * @cfg {String} cls
  688. * An optional extra CSS class that will be added to this component's Element (defaults to ''). This can be
  689. * useful for adding customized styles to the component or any of its children using standard CSS rules.
  690. */
  691. /**
  692. * @cfg {String} overCls
  693. * An optional extra CSS class that will be added to this component's Element when the mouse moves
  694. * over the Element, and removed when the mouse moves out. (defaults to ''). This can be
  695. * useful for adding customized 'active' or 'hover' styles to the component or any of its children using standard CSS rules.
  696. */
  697. /**
  698. * @cfg {String} style
  699. * A custom style specification to be applied to this component's Element. Should be a valid argument to
  700. * {@link Ext.Element#applyStyles}.
  701. * <pre><code>
  702. new Ext.Panel({
  703. title: 'Some Title',
  704. renderTo: Ext.getBody(),
  705. width: 400, height: 300,
  706. layout: 'form',
  707. items: [{
  708. xtype: 'textarea',
  709. style: {
  710. width: '95%',
  711. marginBottom: '10px'
  712. }
  713. },
  714. new Ext.Button({
  715. text: 'Send',
  716. minWidth: '100',
  717. style: {
  718. marginBottom: '10px'
  719. }
  720. })
  721. ]
  722. });
  723. * </code></pre>
  724. */
  725. /**
  726. * @cfg {String} ctCls
  727. * <p>An optional extra CSS class that will be added to this component's container. This can be useful for
  728. * adding customized styles to the container or any of its children using standard CSS rules. See
  729. * {@link Ext.layout.ContainerLayout}.{@link Ext.layout.ContainerLayout#extraCls extraCls} also.</p>
  730. * <p><b>Note</b>: <tt>ctCls</tt> defaults to <tt>''</tt> except for the following class
  731. * which assigns a value by default:
  732. * <div class="mdetail-params"><ul>
  733. * <li>{@link Ext.layout.Box Box Layout} : <tt>'x-box-layout-ct'</tt></li>
  734. * </ul></div>
  735. * To configure the above Class with an extra CSS class append to the default. For example,
  736. * for BoxLayout (Hbox and Vbox):<pre><code>
  737. * ctCls: 'x-box-layout-ct custom-class'
  738. * </code></pre>
  739. * </p>
  740. */
  741. /**
  742. * @cfg {Boolean} disabled
  743. * Render this component disabled (default is false).
  744. */
  745. disabled : false,
  746. /**
  747. * @cfg {Boolean} hidden
  748. * Render this component hidden (default is false). If <tt>true</tt>, the
  749. * {@link #hide} method will be called internally.
  750. */
  751. hidden : false,
  752. /**
  753. * @cfg {Object/Array} plugins
  754. * An object or array of objects that will provide custom functionality for this component. The only
  755. * requirement for a valid plugin is that it contain an init method that accepts a reference of type Ext.Component.
  756. * When a component is created, if any plugins are available, the component will call the init method on each
  757. * plugin, passing a reference to itself. Each plugin can then call methods or respond to events on the
  758. * component as needed to provide its functionality.
  759. */
  760. /**
  761. * @cfg {Mixed} applyTo
  762. * <p>Specify the id of the element, a DOM element or an existing Element corresponding to a DIV
  763. * that is already present in the document that specifies some structural markup for this
  764. * component.</p><div><ul>
  765. * <li><b>Description</b> : <ul>
  766. * <div class="sub-desc">When <tt>applyTo</tt> is used, constituent parts of the component can also be specified
  767. * by id or CSS class name within the main element, and the component being created may attempt
  768. * to create its subcomponents from that markup if applicable.</div>
  769. * </ul></li>
  770. * <li><b>Notes</b> : <ul>
  771. * <div class="sub-desc">When using this config, a call to render() is not required.</div>
  772. * <div class="sub-desc">If applyTo is specified, any value passed for {@link #renderTo} will be ignored and the target
  773. * element's parent node will automatically be used as the component's container.</div>
  774. * </ul></li>
  775. * </ul></div>
  776. */
  777. /**
  778. * @cfg {Mixed} renderTo
  779. * <p>Specify the id of the element, a DOM element or an existing Element that this component
  780. * will be rendered into.</p><div><ul>
  781. * <li><b>Notes</b> : <ul>
  782. * <div class="sub-desc">Do <u>not</u> use this option if the Component is to be a child item of
  783. * a {@link Ext.Container Container}. It is the responsibility of the
  784. * {@link Ext.Container Container}'s {@link Ext.Container#layout layout manager}
  785. * to render and manage its child items.</div>
  786. * <div class="sub-desc">When using this config, a call to render() is not required.</div>
  787. * </ul></li>
  788. * </ul></div>
  789. * <p>See <tt>{@link #render}</tt> also.</p>
  790. */
  791. /**
  792. * @cfg {Boolean} stateful
  793. * <p>A flag which causes the Component to attempt to restore the state of
  794. * internal properties from a saved state on startup. The component must have
  795. * either a <code>{@link #stateId}</code> or <code>{@link #id}</code> assigned
  796. * for state to be managed. Auto-generated ids are not guaranteed to be stable
  797. * across page loads and cannot be relied upon to save and restore the same
  798. * state for a component.<p>
  799. * <p>For state saving to work, the state manager's provider must have been
  800. * set to an implementation of {@link Ext.state.Provider} which overrides the
  801. * {@link Ext.state.Provider#set set} and {@link Ext.state.Provider#get get}
  802. * methods to save and recall name/value pairs. A built-in implementation,
  803. * {@link Ext.state.CookieProvider} is available.</p>
  804. * <p>To set the state provider for the current page:</p>
  805. * <pre><code>
  806. Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
  807. expires: new Date(new Date().getTime()+(1000*60*60*24*7)), //7 days from now
  808. }));
  809. * </code></pre>
  810. * <p>A stateful Component attempts to save state when one of the events
  811. * listed in the <code>{@link #stateEvents}</code> configuration fires.</p>
  812. * <p>To save state, a stateful Component first serializes its state by
  813. * calling <b><code>getState</code></b>. By default, this function does
  814. * nothing. The developer must provide an implementation which returns an
  815. * object hash which represents the Component's restorable state.</p>
  816. * <p>The value yielded by getState is passed to {@link Ext.state.Manager#set}
  817. * which uses the configured {@link Ext.state.Provider} to save the object
  818. * keyed by the Component's <code>{@link stateId}</code>, or, if that is not
  819. * specified, its <code>{@link #id}</code>.</p>
  820. * <p>During construction, a stateful Component attempts to <i>restore</i>
  821. * its state by calling {@link Ext.state.Manager#get} passing the
  822. * <code>{@link #stateId}</code>, or, if that is not specified, the
  823. * <code>{@link #id}</code>.</p>
  824. * <p>The resulting object is passed to <b><code>applyState</code></b>.
  825. * The default implementation of <code>applyState</code> simply copies
  826. * properties into the object, but a developer may override this to support
  827. * more behaviour.</p>
  828. * <p>You can perform extra processing on state save and restore by attaching
  829. * handlers to the {@link #beforestaterestore}, {@link #staterestore},
  830. * {@link #beforestatesave} and {@link #statesave} events.</p>
  831. */
  832. /**
  833. * @cfg {String} stateId
  834. * The unique id for this component to use for state management purposes
  835. * (defaults to the component id if one was set, otherwise null if the
  836. * component is using a generated id).
  837. * <p>See <code>{@link #stateful}</code> for an explanation of saving and
  838. * restoring Component state.</p>
  839. */
  840. /**
  841. * @cfg {Array} stateEvents
  842. * <p>An array of events that, when fired, should trigger this component to
  843. * save its state (defaults to none). <code>stateEvents</code> may be any type
  844. * of event supported by this component, including browser or custom events
  845. * (e.g., <tt>['click', 'customerchange']</tt>).</p>
  846. * <p>See <code>{@link #stateful}</code> for an explanation of saving and
  847. * restoring Component state.</p>
  848. */
  849. /**
  850. * @cfg {Mixed} autoEl
  851. * <p>A tag name or {@link Ext.DomHelper DomHelper} spec used to create the {@link #getEl Element} which will
  852. * encapsulate this Component.</p>
  853. * <p>You do not normally need to specify this. For the base classes {@link Ext.Component}, {@link Ext.BoxComponent},
  854. * and {@link Ext.Container}, this defaults to <b><tt>'div'</tt></b>. The more complex Ext classes use a more complex
  855. * DOM structure created by their own onRender methods.</p>
  856. * <p>This is intended to allow the developer to create application-specific utility Components encapsulated by
  857. * different DOM elements. Example usage:</p><pre><code>
  858. {
  859. xtype: 'box',
  860. autoEl: {
  861. tag: 'img',
  862. src: 'http://www.example.com/example.jpg'
  863. }
  864. }, {
  865. xtype: 'box',
  866. autoEl: {
  867. tag: 'blockquote',
  868. html: 'autoEl is cool!'
  869. }
  870. }, {
  871. xtype: 'container',
  872. autoEl: 'ul',
  873. cls: 'ux-unordered-list',
  874. items: {
  875. xtype: 'box',
  876. autoEl: 'li',
  877. html: 'First list item'
  878. }
  879. }
  880. </code></pre>
  881. */
  882. autoEl : 'div',
  883. /**
  884. * @cfg {String} disabledClass
  885. * CSS class added to the component when it is disabled (defaults to 'x-item-disabled').
  886. */
  887. disabledClass : 'x-item-disabled',
  888. /**
  889. * @cfg {Boolean} allowDomMove
  890. * Whether the component can move the Dom node when rendering (defaults to true).
  891. */
  892. allowDomMove : true,
  893. /**
  894. * @cfg {Boolean} autoShow
  895. * True if the component should check for hidden classes (e.g. 'x-hidden' or 'x-hide-display') and remove
  896. * them on render (defaults to false).
  897. */
  898. autoShow : false,
  899. /**
  900. * @cfg {String} hideMode
  901. * <p>How this component should be hidden. Supported values are <tt>'visibility'</tt>
  902. * (css visibility), <tt>'offsets'</tt> (negative offset position) and <tt>'display'</tt>
  903. * (css display).</p>
  904. * <br><p><b>Note</b>: the default of <tt>'display'</tt> is generally preferred
  905. * since items are automatically laid out when they are first shown (no sizing
  906. * is done while hidden).</p>
  907. */
  908. hideMode : 'display',
  909. /**
  910. * @cfg {Boolean} hideParent
  911. * True to hide and show the component's container when hide/show is called on the component, false to hide
  912. * and show the component itself (defaults to false). For example, this can be used as a shortcut for a hide
  913. * button on a window by setting hide:true on the button when adding it to its parent container.
  914. */
  915. hideParent : false,
  916. /**
  917. * <p>The {@link Ext.Element} which encapsulates this Component. Read-only.</p>
  918. * <p>This will <i>usually</i> be a &lt;DIV> element created by the class's onRender method, but
  919. * that may be overridden using the <code>{@link #autoEl}</code> config.</p>
  920. * <br><p><b>Note</b>: this element will not be available until this Component has been rendered.</p><br>
  921. * <p>To add listeners for <b>DOM events</b> to this Component (as opposed to listeners
  922. * for this Component's own Observable events), see the {@link Ext.util.Observable#listeners listeners}
  923. * config for a suggestion, or use a render listener directly:</p><pre><code>
  924. new Ext.Panel({
  925. title: 'The Clickable Panel',
  926. listeners: {
  927. render: function(p) {
  928. // Append the Panel to the click handler&#39;s argument list.
  929. p.getEl().on('click', handlePanelClick.createDelegate(null, [p], true));
  930. },
  931. single: true // Remove the listener after first invocation
  932. }
  933. });
  934. </code></pre>
  935. * <p>See also <tt>{@link #getEl getEl}</tt></p>
  936. * @type Ext.Element
  937. * @property el
  938. */
  939. /**
  940. * This Component's owner {@link Ext.Container Container} (defaults to undefined, and is set automatically when
  941. * this Component is added to a Container). Read-only.
  942. * <p><b>Note</b>: to access items within the Container see <tt>{@link #itemId}</tt>.</p>
  943. * @type Ext.Container
  944. * @property ownerCt
  945. */
  946. /**
  947. * True if this component is hidden. Read-only.
  948. * @type Boolean
  949. * @property hidden
  950. */
  951. /**
  952. * True if this component is disabled. Read-only.
  953. * @type Boolean
  954. * @property disabled
  955. */
  956. /**
  957. * True if this component has been rendered. Read-only.
  958. * @type Boolean
  959. * @property rendered
  960. */
  961. rendered : false,
  962. /**
  963. * @cfg {String} contentEl
  964. * <p>Optional. Specify an existing HTML element, or the <code>id</code> of an existing HTML element to use as the content
  965. * for this component.</p>
  966. * <ul>
  967. * <li><b>Description</b> :
  968. * <div class="sub-desc">This config option is used to take an existing HTML element and place it in the layout element
  969. * of a new component (it simply moves the specified DOM element <i>after the Component is rendered</i> to use as the content.</div></li>
  970. * <li><b>Notes</b> :
  971. * <div class="sub-desc">The specified HTML element is appended to the layout element of the component <i>after any configured
  972. * {@link #html HTML} has been inserted</i>, and so the document will not contain this element at the time the {@link #render} event is fired.</div>
  973. * <div class="sub-desc">The specified HTML element used will not participate in any <code><b>{@link Ext.Container#layout layout}</b></code>
  974. * scheme that the Component may use. It is just HTML. Layouts operate on child <code><b>{@link Ext.Container#items items}</b></code>.</div>
  975. * <div class="sub-desc">Add either the <code>x-hidden</code> or the <code>x-hide-display</code> CSS class to
  976. * prevent a brief flicker of the content before it is rendered to the panel.</div></li>
  977. * </ul>
  978. */
  979. /**
  980. * @cfg {String/Object} html
  981. * An HTML fragment, or a {@link Ext.DomHelper DomHelper} specification to use as the layout element
  982. * content (defaults to ''). The HTML content is added after the component is rendered,
  983. * so the document will not contain this HTML at the time the {@link #render} event is fired.
  984. * This content is inserted into the body <i>before</i> any configured {@link #contentEl} is appended.
  985. */
  986. /**
  987. * @cfg {Mixed} tpl
  988. * An <bold>{@link Ext.Template}</bold>, <bold>{@link Ext.XTemplate}</bold>
  989. * or an array of strings to form an Ext.XTemplate.
  990. * Used in conjunction with the <code>{@link #data}</code> and
  991. * <code>{@link #tplWriteMode}</code> configurations.
  992. */
  993. /**
  994. * @cfg {String} tplWriteMode The Ext.(X)Template method to use when
  995. * updating the content area of the Component. Defaults to <tt>'overwrite'</tt>
  996. * (see <code>{@link Ext.XTemplate#overwrite}</code>).
  997. */
  998. tplWriteMode : 'overwrite',
  999. /**
  1000. * @cfg {Mixed} data
  1001. * The initial set of data to apply to the <code>{@link #tpl}</code> to
  1002. * update the content area of the Component.
  1003. */
  1004. /**
  1005. * @cfg {Array} bubbleEvents
  1006. * <p>An array of events that, when fired, should be bubbled to any parent container.
  1007. * See {@link Ext.util.Observable#enableBubble}.
  1008. * Defaults to <tt>[]</tt>.
  1009. */
  1010. bubbleEvents: [],
  1011. // private
  1012. ctype : 'Ext.Component',
  1013. // private
  1014. actionMode : 'el',
  1015. // private
  1016. getActionEl : function(){
  1017. return this[this.actionMode];
  1018. },
  1019. initPlugin : function(p){
  1020. if(p.ptype && !Ext.isFunction(p.init)){
  1021. p = Ext.ComponentMgr.createPlugin(p);
  1022. }else if(Ext.isString(p)){
  1023. p = Ext.ComponentMgr.createPlugin({
  1024. ptype: p
  1025. });
  1026. }
  1027. p.init(this);
  1028. return p;
  1029. },
  1030. /* // protected
  1031. * Function to be implemented by Component subclasses to be part of standard component initialization flow (it is empty by default).
  1032. * <pre><code>
  1033. // Traditional constructor:
  1034. Ext.Foo = function(config){
  1035. // call superclass constructor:
  1036. Ext.Foo.superclass.constructor.call(this, config);
  1037. this.addEvents({
  1038. // add events
  1039. });
  1040. };
  1041. Ext.extend(Ext.Foo, Ext.Bar, {
  1042. // class body
  1043. }
  1044. // initComponent replaces the constructor:
  1045. Ext.Foo = Ext.extend(Ext.Bar, {
  1046. initComponent : function(){
  1047. // call superclass initComponent
  1048. Ext.Container.superclass.initComponent.call(this);
  1049. this.addEvents({
  1050. // add events
  1051. });
  1052. }
  1053. }
  1054. </code></pre>
  1055. */
  1056. initComponent : function(){
  1057. /*
  1058. * this is double processing, however it allows people to be able to do
  1059. * Ext.apply(this, {
  1060. * listeners: {
  1061. * //here
  1062. * }
  1063. * });
  1064. * MyClass.superclass.initComponent.call(this);
  1065. */
  1066. if(this.listeners){
  1067. this.on(this.listeners);
  1068. delete this.listeners;
  1069. }
  1070. this.enableBubble(this.bubbleEvents);
  1071. },
  1072. /**
  1073. * <p>Render this Component into the passed HTML element.</p>
  1074. * <p><b>If you are using a {@link Ext.Container Container} object to house this Component, then
  1075. * do not use the render method.</b></p>
  1076. * <p>A Container's child Components are rendered by that Container's
  1077. * {@link Ext.Container#layout layout} manager when the Container is first rendered.</p>
  1078. * <p>Certain layout managers allow dynamic addition of child components. Those that do
  1079. * include {@link Ext.layout.CardLayout}, {@link Ext.layout.AnchorLayout},
  1080. * {@link Ext.layout.FormLayout}, {@link Ext.layout.TableLayout}.</p>
  1081. * <p>If the Container is already rendered when a new child Component is added, you may need to call
  1082. * the Container's {@link Ext.Container#doLayout doLayout} to refresh the view which causes any
  1083. * unrendered child Components to be rendered. This is required so that you can add multiple
  1084. * child components if needed while only refreshing the layout once.</p>
  1085. * <p>When creating complex UIs, it is important to remember that sizing and positioning
  1086. * of child items is the responsibility of the Container's {@link Ext.Container#layout layout} manager.
  1087. * If you expect child items to be sized in response to user interactions, you must
  1088. * configure the Container with a layout manager which creates and manages the type of layout you
  1089. * have in mind.</p>
  1090. * <p><b>Omitting the Container's {@link Ext.Container#layout layout} config means that a basic
  1091. * layout manager is used which does nothing but render child components sequentially into the
  1092. * Container. No sizing or positioning will be performed in this situation.</b></p>
  1093. * @param {Element/HTMLElement/String} container (optional) The element this Component should be
  1094. * rendered into. If it is being created from existing markup, this should be omitted.
  1095. * @param {String/Number} position (optional) The element ID or DOM node index within the container <b>before</b>
  1096. * which this component will be inserted (defaults to appending to the end of the container)
  1097. */
  1098. render : function(container, position){
  1099. if(!this.rendered && this.fireEvent('beforerender', this) !== false){
  1100. if(!container && this.el){
  1101. this.el = Ext.get(this.el);
  1102. container = this.el.dom.parentNode;
  1103. this.allowDomMove = false;
  1104. }
  1105. this.container = Ext.get(container);
  1106. if(this.ctCls){
  1107. this.container.addClass(this.ctCls);
  1108. }
  1109. this.rendered = true;
  1110. if(position !== undefined){
  1111. if(Ext.isNumber(position)){
  1112. position = this.container.dom.childNodes[position];
  1113. }else{
  1114. position = Ext.getDom(position);
  1115. }
  1116. }
  1117. this.onRender(this.container, position || null);
  1118. if(this.autoShow){
  1119. this.el.removeClass(['x-hidden','x-hide-' + this.hideMode]);
  1120. }
  1121. if(this.cls){
  1122. this.el.addClass(this.cls);
  1123. delete this.cls;
  1124. }
  1125. if(this.style){
  1126. this.el.applyStyles(this.style);
  1127. delete this.style;
  1128. }
  1129. if(this.overCls){
  1130. this.el.addClassOnOver(this.overCls);
  1131. }
  1132. this.fireEvent('render', this);
  1133. // Populate content of the component with html, contentEl or
  1134. // a tpl.
  1135. var contentTarget = this.getContentTarget();
  1136. if (this.html){
  1137. contentTarget.update(Ext.DomHelper.markup(this.html));
  1138. delete this.html;
  1139. }
  1140. if (this.contentEl){
  1141. var ce = Ext.getDom(this.contentEl);
  1142. Ext.fly(ce).removeClass(['x-hidden', 'x-hide-display']);
  1143. contentTarget.appendChild(ce);
  1144. }
  1145. if (this.tpl) {
  1146. if (!this.tpl.compile) {
  1147. this.tpl = new Ext.XTemplate(this.tpl);
  1148. }
  1149. if (this.data) {
  1150. this.tpl[this.tplWriteMode](contentTarget, this.data);
  1151. delete this.data;
  1152. }
  1153. }
  1154. this.afterRender(this.container);
  1155. if(this.hidden){
  1156. // call this so we don't fire initial hide events.
  1157. this.doHide();
  1158. }
  1159. if(this.disabled){
  1160. // pass silent so the event doesn't fire the first time.
  1161. this.disable(true);
  1162. }
  1163. if(this.stateful !== false){
  1164. this.initStateEvents();
  1165. }
  1166. this.fireEvent('afterrender', this);
  1167. }
  1168. return this;
  1169. },
  1170. /**
  1171. * Update the content area of a component.
  1172. * @param {Mixed} htmlOrData
  1173. * If this component has been configured with a template via the tpl config
  1174. * then it will use this argument as data to populate the template.
  1175. * If this component was not configured with a template, the components
  1176. * content area will be updated via Ext.Element update
  1177. * @param {Boolean} loadScripts
  1178. * (optional) Only legitimate when using the html configuration. Defaults to false
  1179. * @param {Function} callback
  1180. * (optional) Only legitimate when using the html configuration. Callback to execute when scripts have finished loading
  1181. */
  1182. update: function(htmlOrData, loadScripts, cb) {
  1183. var contentTarget = this.getContentTarget();
  1184. if (this.tpl && typeof htmlOrData !== "string") {
  1185. this.tpl[this.tplWriteMode](contentTarget, htmlOrData || {});
  1186. } else {
  1187. var html = Ext.isObject(htmlOrData) ? Ext.DomHelper.markup(htmlOrData) : htmlOrData;
  1188. contentTarget.update(html, loadScripts, cb);
  1189. }
  1190. },
  1191. /**
  1192. * @private
  1193. * Method to manage awareness of when components are added to their
  1194. * respective Container, firing an added event.
  1195. * References are established at add time rather than at render time.
  1196. * @param {Ext.Container} container Container which holds the component
  1197. * @param {number} pos Position at which the component was added
  1198. */
  1199. onAdded : function(container, pos) {
  1200. this.ownerCt = container;
  1201. this.initRef();
  1202. this.fireEvent('added', this, container, pos);
  1203. },
  1204. /**
  1205. * @private
  1206. * Method to manage awareness of when components are removed from their
  1207. * respective Container, firing an removed event. References are properly
  1208. * cleaned up after removing a component from its owning container.
  1209. */
  1210. onRemoved : function() {
  1211. this.removeRef();
  1212. this.fireEvent('removed', this, this.ownerCt);
  1213. delete this.ownerCt;
  1214. },
  1215. /**
  1216. * @private
  1217. * Method to establish a reference to a component.
  1218. */
  1219. initRef : function() {
  1220. /**
  1221. * @cfg {String} ref
  1222. * <p>A path specification, relative to the Component's <code>{@link #ownerCt}</code>
  1223. * specifying into which ancestor Container to place a named reference to this Component.</p>
  1224. * <p>The ancestor axis can be traversed by using '/' characters in the path.
  1225. * For example, to put a reference to a Toolbar Button into <i>the Panel which owns the Toolbar</i>:</p><pre><code>
  1226. var myGrid = new Ext.grid.EditorGridPanel({
  1227. title: 'My EditorGridPanel',
  1228. store: myStore,
  1229. colModel: myColModel,
  1230. tbar: [{
  1231. text: 'Save',
  1232. handler: saveChanges,
  1233. disabled: true,
  1234. ref: '../saveButton'
  1235. }],
  1236. listeners: {
  1237. afteredit: function() {
  1238. // The button reference is in the GridPanel
  1239. myGrid.saveButton.enable();
  1240. }
  1241. }
  1242. });
  1243. </code></pre>
  1244. * <p>In the code above, if the <code>ref</code> had been <code>'saveButton'</code>
  1245. * the reference would have been placed into the Toolbar. Each '/' in the <code>ref</code>
  1246. * moves up one level from the Component's <code>{@link #ownerCt}</code>.</p>
  1247. * <p>Also see the <code>{@link #added}</code> and <code>{@link #removed}</code> events.</p>
  1248. */
  1249. if(this.ref && !this.refOwner){
  1250. var levels = this.ref.split('/'),
  1251. last = levels.length,
  1252. i = 0,
  1253. t = this;
  1254. while(t && i < last){
  1255. t = t.ownerCt;
  1256. ++i;
  1257. }
  1258. if(t){
  1259. t[this.refName = levels[--i]] = this;
  1260. /**
  1261. * @type Ext.Container
  1262. * @property refOwner
  1263. * The ancestor Container into which the {@link #ref} reference was inserted if this Component
  1264. * is a child of a Container, and has been configured with a <code>ref</code>.
  1265. */
  1266. this.refOwner = t;
  1267. }
  1268. }
  1269. },
  1270. removeRef : function() {
  1271. if (this.refOwner && this.refName) {
  1272. delete this.refOwner[this.refName];
  1273. delete this.refOwner;
  1274. }
  1275. },
  1276. // private
  1277. initState : function(){
  1278. if(Ext.state.Manager){
  1279. var id = this.getStateId();
  1280. if(id){
  1281. var state = Ext.state.Manager.get(id);
  1282. if(state){
  1283. if(this.fireEvent('beforestaterestore', this, state) !== false){
  1284. this.applyState(Ext.apply({}, state));
  1285. this.fireEvent('staterestore', this, state);
  1286. }
  1287. }
  1288. }
  1289. }
  1290. },
  1291. // private
  1292. getStateId : function(){
  1293. return this.stateId || ((/^(ext-comp-|ext-gen)/).test(String(this.id)) ? null : this.id);
  1294. },
  1295. // private
  1296. initStateEvents : function(){
  1297. if(this.stateEvents){
  1298. for(var i = 0, e; e = this.stateEvents[i]; i++){
  1299. this.on(e, this.saveState, this, {delay:100});
  1300. }
  1301. }
  1302. },
  1303. // private
  1304. applyState : function(state){
  1305. if(state){
  1306. Ext.apply(this, state);
  1307. }
  1308. },
  1309. // private
  1310. getState : function(){
  1311. return null;
  1312. },
  1313. // private
  1314. saveState : function(){
  1315. if(Ext.state.Manager && this.stateful !== false){
  1316. var id = this.getStateId();
  1317. if(id){
  1318. var state = this.getState();
  1319. if(this.fireEvent('beforestatesave', this, state) !== false){
  1320. Ext.state.Manager.set(id, state);
  1321. this.fireEvent('statesave', this, state);
  1322. }
  1323. }
  1324. }
  1325. },
  1326. /**
  1327. * Apply this component to existing markup that is valid. With this function, no call to render() is required.
  1328. * @param {String/HTMLElement} el
  1329. */
  1330. applyToMarkup : function(el){
  1331. this.allowDomMove = false;
  1332. this.el = Ext.get(el);
  1333. this.render(this.el.dom.parentNode);
  1334. },
  1335. /**
  1336. * Adds a CSS class to the component's underlying element.
  1337. * @param {string} cls The CSS class name to add
  1338. * @return {Ext.Component} this
  1339. */
  1340. addClass : function(cls){
  1341. if(this.el){
  1342. this.el.addClass(cls);
  1343. }else{
  1344. this.cls = this.cls ? this.cls + ' ' + cls : cls;
  1345. }
  1346. return this;
  1347. },
  1348. /**
  1349. * Removes a CSS class from the component's underlying element.
  1350. * @param {string} cls The CSS class name to remove
  1351. * @return {Ext.Component} this
  1352. */
  1353. removeClass : function(cls){
  1354. if(this.el){
  1355. this.el.removeClass(cls);
  1356. }else if(this.cls){
  1357. this.cls = this.cls.split(' ').remove(cls).join(' ');
  1358. }
  1359. return this;
  1360. },
  1361. // private
  1362. // default function is not really useful
  1363. onRender : function(ct, position){
  1364. if(!this.el && this.autoEl){
  1365. if(Ext.isString(this.autoEl)){
  1366. this.el = document.createElement(this.autoEl);
  1367. }else{
  1368. var div = document.createElement('div');
  1369. Ext.DomHelper.overwrite(div, this.autoEl);
  1370. this.el = div.firstChild;
  1371. }
  1372. if (!this.el.id) {
  1373. this.el.id = this.getId();
  1374. }
  1375. }
  1376. if(this.el){
  1377. this.el = Ext.get(this.el);
  1378. if(this.allowDomMove !== false){
  1379. ct.dom.insertBefore(this.el.dom, position);
  1380. if (div) {
  1381. Ext.removeNode(div);
  1382. div = null;
  1383. }
  1384. }
  1385. }
  1386. },
  1387. // private
  1388. getAutoCreate : function(){
  1389. var cfg = Ext.isObject(this.autoCreate) ?
  1390. this.autoCreate : Ext.apply({}, this.defaultAutoCreate);
  1391. if(this.id && !cfg.id){
  1392. cfg.id = this.id;
  1393. }
  1394. return cfg;
  1395. },
  1396. // private
  1397. afterRender : Ext.emptyFn,
  1398. /**
  1399. * Destroys this component by purging any event listeners, removing the component's element from the DOM,
  1400. * removing the component from its {@link Ext.Container} (if applicable) and unregistering it from
  1401. * {@link Ext.ComponentMgr}. Destruction is generally handled automatically by the framework and this method
  1402. * should usually not need to be called directly.
  1403. *
  1404. */
  1405. destroy : function(){
  1406. if(!this.isDestroyed){
  1407. if(this.fireEvent('beforedestroy', this) !== false){
  1408. this.destroying = true;
  1409. this.beforeDestroy();
  1410. if(this.ownerCt && this.ownerCt.remove){
  1411. this.ownerCt.remove(this, false);
  1412. }
  1413. if(this.rendered){
  1414. this.el.remove();
  1415. if(this.actionMode == 'container' || this.removeMode == 'container'){
  1416. this.container.remove();
  1417. }
  1418. }
  1419. // Stop any buffered tasks
  1420. if(this.focusTask && this.focusTask.cancel){
  1421. this.focusTask.cancel();
  1422. }
  1423. this.onDestroy();
  1424. Ext.ComponentMgr.unregister(this);
  1425. this.fireEvent('destroy', this);
  1426. this.purgeListeners();
  1427. this.destroying = false;
  1428. this.isDestroyed = true;
  1429. }
  1430. }
  1431. },
  1432. deleteMembers : function(){
  1433. var args = arguments;
  1434. for(var i = 0, len = args.length; i < len; ++i){
  1435. delete this[args[i]];
  1436. }
  1437. },
  1438. // private
  1439. beforeDestroy : Ext.emptyFn,
  1440. // private
  1441. onDestroy : Ext.emptyFn,
  1442. /**
  1443. * <p>Returns the {@link Ext.Element} which encapsulates this Component.</p>
  1444. * <p>This will <i>usually</i> be a &lt;DIV> element created by the class's onRender method, but
  1445. * that may be overridden using the {@link #autoEl} config.</p>
  1446. * <br><p><b>Note</b>: this element will not be available until this Component has been rendered.</p><br>
  1447. * <p>To add listeners for <b>DOM events</b> to this Component (as opposed to listeners
  1448. * for this Component's own Observable events), see the {@link #listeners} config for a suggestion,
  1449. * or use a render listener directly:</p><pre><code>
  1450. new Ext.Panel({
  1451. title: 'The Clickable Panel',
  1452. listeners: {
  1453. render: function(p) {
  1454. // Append the Panel to the click handler&#39;s argument list.
  1455. p.getEl().on('click', handlePanelClick.createDelegate(null, [p], true));
  1456. },
  1457. single: true // Remove the listener after first invocation
  1458. }
  1459. });
  1460. </code></pre>
  1461. * @return {Ext.Element} The Element which encapsulates this Component.
  1462. */
  1463. getEl : function(){
  1464. return this.el;
  1465. },
  1466. // private
  1467. getContentTarget : function(){
  1468. return this.el;
  1469. },
  1470. /**
  1471. * Returns the <code>id</code> of this component or automatically generates and
  1472. * returns an <code>id</code> if an <code>id</code> is not defined yet:<pre><code>
  1473. * 'ext-comp-' + (++Ext.Component.AUTO_ID)
  1474. * </code></pre>
  1475. * @return {String} id
  1476. */
  1477. getId : function(){
  1478. return this.id || (this.id = 'ext-comp-' + (++Ext.Component.AUTO_ID));
  1479. },
  1480. /**
  1481. * Returns the <code>{@link #itemId}</code> of this component. If an
  1482. * <code>{@link #itemId}</code> was not assigned through configuration the
  1483. * <code>id</code> is returned using <code>{@link #getId}</code>.
  1484. * @return {String}
  1485. */
  1486. getItemId : function(){
  1487. return this.itemId || this.getId();
  1488. },
  1489. /**
  1490. * Try to focus this component.
  1491. * @param {Boolean} selectText (optional) If applicable, true to also select the text in this component
  1492. * @param {Boolean/Number} delay (optional) Delay the focus this number of milliseconds (true for 10 milliseconds)
  1493. * @return {Ext.Component} this
  1494. */
  1495. focus : function(selectText, delay){
  1496. if(delay){
  1497. this.focusTask = new Ext.util.DelayedTask(this.focus, this, [selectText, false]);
  1498. this.focusTask.delay(Ext.isNumber(delay) ? delay : 10);
  1499. return this;
  1500. }
  1501. if(this.rendered && !this.isDestroyed){
  1502. this.el.focus();
  1503. if(selectText === true){
  1504. this.el.dom.select();
  1505. }
  1506. }
  1507. return this;
  1508. },
  1509. // private
  1510. blur : function(){
  1511. if(this.rendered){
  1512. this.el.blur();
  1513. }
  1514. return this;
  1515. },
  1516. /**
  1517. * Disable this component and fire the 'disable' event.
  1518. * @return {Ext.Component} this
  1519. */
  1520. disable : function(/* private */ silent){
  1521. if(this.rendered){
  1522. this.onDisable();
  1523. }
  1524. this.disabled = true;
  1525. if(silent !== true){
  1526. this.fireEvent('disable', this);
  1527. }
  1528. return this;
  1529. },
  1530. // private
  1531. onDisable : function(){
  1532. this.getActionEl().addClass(this.disabledClass);
  1533. this.el.dom.disabled = true;
  1534. },
  1535. /**
  1536. * Enable this component and fire the 'enable' event.
  1537. * @return {Ext.Component} this
  1538. */
  1539. enable : function(){
  1540. if(this.rendered){
  1541. this.onEnable();
  1542. }
  1543. this.disabled = false;
  1544. this.fireEvent('enable', this);
  1545. return this;
  1546. },
  1547. // private
  1548. onEnable : function(){
  1549. this.getActionEl().removeClass(this.disabledClass);
  1550. this.el.dom.disabled = false;
  1551. },
  1552. /**
  1553. * Convenience function for setting disabled/enabled by boolean.
  1554. * @param {Boolean} disabled
  1555. * @return {Ext.Component} this
  1556. */
  1557. setDisabled : function(disabled){
  1558. return this[disabled ? 'disable' : 'enable']();
  1559. },
  1560. /**
  1561. * Show this component. Listen to the '{@link #beforeshow}' event and return
  1562. * <tt>false</tt> to cancel showing the component. Fires the '{@link #show}'
  1563. * event after showing the component.
  1564. * @return {Ext.Component} this
  1565. */
  1566. show : function(){
  1567. if(this.fireEvent('beforeshow', this) !== false){
  1568. this.hidden = false;
  1569. if(this.autoRender){
  1570. this.render(Ext.isBoolean(this.autoRender) ? Ext.getBody() : this.autoRender);
  1571. }
  1572. if(this.rendered){
  1573. this.onShow();
  1574. }
  1575. this.fireEvent('show', this);
  1576. }
  1577. return this;
  1578. },
  1579. // private
  1580. onShow : function(){
  1581. this.getVisibilityEl().removeClass('x-hide-' + this.hideMode);
  1582. },
  1583. /**
  1584. * Hide this component. Listen to the '{@link #beforehide}' event and return
  1585. * <tt>false</tt> to cancel hiding the component. Fires the '{@link #hide}'
  1586. * event after hiding the component. Note this method is called internally if
  1587. * the component is configured to be <code>{@link #hidden}</code>.
  1588. * @return {Ext.Component} this
  1589. */
  1590. hide : function(){
  1591. if(this.fireEvent('beforehide', this) !== false){
  1592. this.doHide();
  1593. this.fireEvent('hide', this);
  1594. }
  1595. return this;
  1596. },
  1597. // private
  1598. doHide: function(){
  1599. this.hidden = true;
  1600. if(this.rendered){
  1601. this.onHide();
  1602. }
  1603. },
  1604. // private
  1605. onHide : function(){
  1606. this.getVisibilityEl().addClass('x-hide-' + this.hideMode);
  1607. },
  1608. // private
  1609. getVisibilityEl : function(){
  1610. return this.hideParent ? this.container : this.getActionEl();
  1611. },
  1612. /**
  1613. * Convenience function to hide or show this component by boolean.
  1614. * @param {Boolean} visible True to show, false to hide
  1615. * @return {Ext.Component} this
  1616. */
  1617. setVisible : function(visible){
  1618. return this[visible ? 'show' : 'hide']();
  1619. },
  1620. /**
  1621. * Returns true if this component is visible.
  1622. * @return {Boolean} True if this component is visible, false otherwise.
  1623. */
  1624. isVisible : function(){
  1625. return this.rendered && this.getVisibilityEl().isVisible();
  1626. },
  1627. /**
  1628. * Clone the current component using the original config values passed into this instance by default.
  1629. * @param {Object} overrides A new config containing any properties to override in the cloned version.
  1630. * An id property can be passed on this object, otherwise one will be generated to avoid duplicates.
  1631. * @return {Ext.Component} clone The cloned copy of this component
  1632. */
  1633. cloneConfig : function(overrides){
  1634. overrides = overrides || {};
  1635. var id = overrides.id || Ext.id();
  1636. var cfg = Ext.applyIf(overrides, this.initialConfig);
  1637. cfg.id = id; // prevent dup id
  1638. return new this.constructor(cfg);
  1639. },
  1640. /**
  1641. * Gets the xtype for this component as registered with {@link Ext.ComponentMgr}. For a list of all
  1642. * available xtypes, see the {@link Ext.Component} header. Example usage:
  1643. * <pre><code>
  1644. var t = new Ext.form.TextField();
  1645. alert(t.getXType()); // alerts 'textfield'
  1646. </code></pre>
  1647. * @return {String} The xtype
  1648. */
  1649. getXType : function(){
  1650. return this.constructor.xtype;
  1651. },
  1652. /**
  1653. * <p>Tests whether or not this Component is of a specific xtype. This can test whether this Component is descended
  1654. * from the xtype (default) or whether it is directly of the xtype specified (shallow = true).</p>
  1655. * <p><b>If using your own subclasses, be aware that a Component must register its own xtype
  1656. * to participate in determination of inherited xtypes.</b></p>
  1657. * <p>For a list of all available xtypes, see the {@link Ext.Component} header.</p>
  1658. * <p>Example usage:</p>
  1659. * <pre><code>
  1660. var t = new Ext.form.TextField();
  1661. var isText = t.isXType('textfield'); // true
  1662. var isBoxSubclass = t.isXType('box'); // true, descended from BoxComponent
  1663. var isBoxInstance = t.isXType('box', true); // false, not a direct BoxComponent instance
  1664. </code></pre>
  1665. * @param {String/Ext.Component/Class} xtype The xtype to check for this Component. Note that the the component can either be an instance
  1666. * or a component class:
  1667. * <pre><code>
  1668. var c = new Ext.Component();
  1669. console.log(c.isXType(c));
  1670. console.log(c.isXType(Ext.Component));
  1671. </code></pre>
  1672. * @param {Boolean} shallow (optional) False to check whether this Component is descended from the xtype (this is
  1673. * the default), or true to check whether this Component is directly of the specified xtype.
  1674. * @return {Boolean} True if this component descends from the specified xtype, false otherwise.
  1675. */
  1676. isXType : function(xtype, shallow){
  1677. //assume a string by default
  1678. if (Ext.isFunction(xtype)){
  1679. xtype = xtype.xtype; //handle being passed the class, e.g. Ext.Component
  1680. }else if (Ext.isObject(xtype)){
  1681. xtype = xtype.constructor.xtype; //handle being passed an instance
  1682. }
  1683. return !shallow ? ('/' + this.getXTypes() + '/').indexOf('/' + xtype + '/') != -1 : this.constructor.xtype == xtype;
  1684. },
  1685. /**
  1686. * <p>Returns this Component's xtype hierarchy as a slash-delimited string. For a list of all
  1687. * available xtypes, see the {@link Ext.Component} header.</p>
  1688. * <p><b>If using your own subclasses, be aware that a Component must register its own xtype
  1689. * to participate in determination of inherited xtypes.</b></p>
  1690. * <p>Example usage:</p>
  1691. * <pre><code>
  1692. var t = new Ext.form.TextField();
  1693. alert(t.getXTypes()); // alerts 'component/box/field/textfield'
  1694. </code></pre>
  1695. * @return {String} The xtype hierarchy string
  1696. */
  1697. getXTypes : function(){
  1698. var tc = this.constructor;
  1699. if(!tc.xtypes){
  1700. var c = [], sc = this;
  1701. while(sc && sc.constructor.xtype){
  1702. c.unshift(sc.constructor.xtype);
  1703. sc = sc.constructor.superclass;
  1704. }
  1705. tc.xtypeChain = c;
  1706. tc.xtypes = c.join('/');
  1707. }
  1708. return tc.xtypes;
  1709. },
  1710. /**
  1711. * Find a container above this component at any level by a custom function. If the passed function returns
  1712. * true, the container will be returned.
  1713. * @param {Function} fn The custom function to call with the arguments (container, this component).
  1714. * @return {Ext.Container} The first Container for which the custom function returns true
  1715. */
  1716. findParentBy : function(fn) {
  1717. for (var p = this.ownerCt; (p != null) && !fn(p, this); p = p.ownerCt);
  1718. return p || null;
  1719. },
  1720. /**
  1721. * Find a container above this component at any level by xtype or class
  1722. * @param {String/Ext.Component/Class} xtype The xtype to check for this Component. Note that the the component can either be an instance
  1723. * or a component class:
  1724. * @param {Boolean} shallow (optional) False to check whether this Component is descended from the xtype (this is
  1725. * the default), or true to check whether this Component is directly of the specified xtype.
  1726. * @return {Ext.Container} The first Container which matches the given xtype or class
  1727. */
  1728. findParentByType : function(xtype, shallow){
  1729. return this.findParentBy(function(c){
  1730. return c.isXType(xtype, shallow);
  1731. });
  1732. },
  1733. /**
  1734. * Bubbles up the component/container heirarchy, calling the specified function with each component. The scope (<i>this</i>) of
  1735. * function call will be the scope provided or the current component. The arguments to the function
  1736. * will be the args provided or the current component. If the function returns false at any point,
  1737. * the bubble is stopped.
  1738. * @param {Function} fn The function to call
  1739. * @param {Object} scope (optional) The scope of the function (defaults to current node)
  1740. * @param {Array} args (optional) The args to call the function with (default to passing the current component)
  1741. * @return {Ext.Component} this
  1742. */
  1743. bubble : function(fn, scope, args){
  1744. var p = this;
  1745. while(p){
  1746. if(fn.apply(scope || p, args || [p]) === false){
  1747. break;
  1748. }
  1749. p = p.ownerCt;
  1750. }
  1751. return this;
  1752. },
  1753. // protected
  1754. getPositionEl : function(){
  1755. return this.positionEl || this.el;
  1756. },
  1757. // private
  1758. purgeListeners : function(){
  1759. Ext.Component.superclass.purgeListeners.call(this);
  1760. if(this.mons){
  1761. this.on('beforedestroy', this.clearMons, this, {single: true});
  1762. }
  1763. },
  1764. // private
  1765. clearMons : function(){
  1766. Ext.each(this.mons, function(m){
  1767. m.item.un(m.ename, m.fn, m.scope);
  1768. }, this);
  1769. this.mons = [];
  1770. },
  1771. // private
  1772. createMons: function(){
  1773. if(!this.mons){
  1774. this.mons = [];
  1775. this.on('beforedestroy', this.clearMons, this, {single: true});
  1776. }
  1777. },
  1778. /**
  1779. * <p>Adds listeners to any Observable object (or Elements) which are automatically removed when this Component
  1780. * is destroyed. Usage:</p><code><pre>
  1781. myGridPanel.mon(myGridPanel.getSelectionModel(), 'selectionchange', handleSelectionChange, null, {buffer: 50});
  1782. </pre></code>
  1783. * <p>or:</p><code><pre>
  1784. myGridPanel.mon(myGridPanel.getSelectionModel(), {
  1785. selectionchange: handleSelectionChange,
  1786. buffer: 50
  1787. });
  1788. </pre></code>
  1789. * @param {Observable|Element} item The item to which to add a listener/listeners.
  1790. * @param {Object|String} ename The event name, or an object containing event name properties.
  1791. * @param {Function} fn Optional. If the <code>ename</code> parameter was an event name, this
  1792. * is the handler function.
  1793. * @param {Object} scope Optional. If the <code>ename</code> parameter was an event name, this
  1794. * is the scope (<code>this</code> reference) in which the handler function is executed.
  1795. * @param {Object} opt Optional. If the <code>ename</code> parameter was an event name, this
  1796. * is the {@link Ext.util.Observable#addListener addListener} options.
  1797. */
  1798. mon : function(item, ename, fn, scope, opt){
  1799. this.createMons();
  1800. if(Ext.isObject(ename)){
  1801. var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
  1802. var o = ename;
  1803. for(var e in o){
  1804. if(propRe.test(e)){
  1805. continue;
  1806. }
  1807. if(Ext.isFunction(o[e])){
  1808. // shared options
  1809. this.mons.push({
  1810. item: item, ename: e, fn: o[e], scope: o.scope
  1811. });
  1812. item.on(e, o[e], o.scope, o);
  1813. }else{
  1814. // individual options
  1815. this.mons.push({
  1816. item: item, ename: e, fn: o[e], scope: o.scope
  1817. });
  1818. item.on(e, o[e]);
  1819. }
  1820. }
  1821. return;
  1822. }
  1823. this.mons.push({
  1824. item: item, ename: ename, fn: fn, scope: scope
  1825. });
  1826. item.on(ename, fn, scope, opt);
  1827. },
  1828. /**
  1829. * Removes listeners that were added by the {@link #mon} method.
  1830. * @param {Observable|Element} item The item from which to remove a listener/listeners.
  1831. * @param {Object|String} ename The event name, or an object containing event name properties.
  1832. * @param {Function} fn Optional. If the <code>ename</code> parameter was an event name, this
  1833. * is the handler function.
  1834. * @param {Object} scope Optional. If the <code>ename</code> parameter was an event name, this
  1835. * is the scope (<code>this</code> reference) in which the handler function is executed.
  1836. */
  1837. mun : function(item, ename, fn, scope){
  1838. var found, mon;
  1839. this.createMons();
  1840. for(var i = 0, len = this.mons.length; i < len; ++i){
  1841. mon = this.mons[i];
  1842. if(item === mon.item && ename == mon.ename && fn === mon.fn && scope === mon.scope){
  1843. this.mons.splice(i, 1);
  1844. item.un(ename, fn, scope);
  1845. found = true;
  1846. break;
  1847. }
  1848. }
  1849. return found;
  1850. },
  1851. /**
  1852. * Returns the next component in the owning container
  1853. * @return Ext.Component
  1854. */
  1855. nextSibling : function(){
  1856. if(this.ownerCt){
  1857. var index = this.ownerCt.items.indexOf(this);
  1858. if(index != -1 && index+1 < this.ownerCt.items.getCount()){
  1859. return this.ownerCt.items.itemAt(index+1);
  1860. }
  1861. }
  1862. return null;
  1863. },
  1864. /**
  1865. * Returns the previous component in the owning container
  1866. * @return Ext.Component
  1867. */
  1868. previousSibling : function(){
  1869. if(this.ownerCt){
  1870. var index = this.ownerCt.items.indexOf(this);
  1871. if(index > 0){
  1872. return this.ownerCt.items.itemAt(index-1);
  1873. }
  1874. }
  1875. return null;
  1876. },
  1877. /**
  1878. * Provides the link for Observable's fireEvent method to bubble up the ownership hierarchy.
  1879. * @return {Ext.Container} the Container which owns this Component.
  1880. */
  1881. getBubbleTarget : function(){
  1882. return this.ownerCt;
  1883. }
  1884. });
  1885. Ext.reg('component', Ext.Component);
  1886. /**
  1887. * @class Ext.Action
  1888. * <p>An Action is a piece of reusable functionality that can be abstracted out of any particular component so that it
  1889. * can be usefully shared among multiple components. Actions let you share handlers, configuration options and UI
  1890. * updates across any components that support the Action interface (primarily {@link Ext.Toolbar}, {@link Ext.Button}
  1891. * and {@link Ext.menu.Menu} components).</p>
  1892. * <p>Aside from supporting the config object interface, any component that needs to use Actions must also support
  1893. * the following method list, as these will be called as needed by the Action class: setText(string), setIconCls(string),
  1894. * setDisabled(boolean), setVisible(boolean) and setHandler(function).</p>
  1895. * Example usage:<br>
  1896. * <pre><code>
  1897. // Define the shared action. Each component below will have the same
  1898. // display text and icon, and will display the same message on click.
  1899. var action = new Ext.Action({
  1900. {@link #text}: 'Do something',
  1901. {@link #handler}: function(){
  1902. Ext.Msg.alert('Click', 'You did something.');
  1903. },
  1904. {@link #iconCls}: 'do-something',
  1905. {@link #itemId}: 'myAction'
  1906. });
  1907. var panel = new Ext.Panel({
  1908. title: 'Actions',
  1909. width: 500,
  1910. height: 300,
  1911. tbar: [
  1912. // Add the action directly to a toolbar as a menu button
  1913. action,
  1914. {
  1915. text: 'Action Menu',
  1916. // Add the action to a menu as a text item
  1917. menu: [action]
  1918. }
  1919. ],
  1920. items: [
  1921. // Add the action to the panel body as a standard button
  1922. new Ext.Button(action)
  1923. ],
  1924. renderTo: Ext.getBody()
  1925. });
  1926. // Change the text for all components using the action
  1927. action.setText('Something else');
  1928. // Reference an action through a container using the itemId
  1929. var btn = panel.getComponent('myAction');
  1930. var aRef = btn.baseAction;
  1931. aRef.setText('New text');
  1932. </code></pre>
  1933. * @constructor
  1934. * @param {Object} config The configuration options
  1935. */
  1936. Ext.Action = Ext.extend(Object, {
  1937. /**
  1938. * @cfg {String} text The text to set for all components using this action (defaults to '').
  1939. */
  1940. /**
  1941. * @cfg {String} iconCls
  1942. * The CSS class selector that specifies a background image to be used as the header icon for
  1943. * all components using this action (defaults to '').
  1944. * <p>An example of specifying a custom icon class would be something like:
  1945. * </p><pre><code>
  1946. // specify the property in the config for the class:
  1947. ...
  1948. iconCls: 'do-something'
  1949. // css class that specifies background image to be used as the icon image:
  1950. .do-something { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }
  1951. </code></pre>
  1952. */
  1953. /**
  1954. * @cfg {Boolean} disabled True to disable all components using this action, false to enable them (defaults to false).
  1955. */
  1956. /**
  1957. * @cfg {Boolean} hidden True to hide all components using this action, false to show them (defaults to false).
  1958. */
  1959. /**
  1960. * @cfg {Function} handler The function that will be invoked by each component tied to this action
  1961. * when the component's primary event is triggered (defaults to undefined).
  1962. */
  1963. /**
  1964. * @cfg {String} itemId
  1965. * See {@link Ext.Component}.{@link Ext.Component#itemId itemId}.
  1966. */
  1967. /**
  1968. * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
  1969. * <code>{@link #handler}</code> is executed. Defaults to this Button.
  1970. */
  1971. constructor : function(config){
  1972. this.initialConfig = config;
  1973. this.itemId = config.itemId = (config.itemId || config.id || Ext.id());
  1974. this.items = [];
  1975. },
  1976. // private
  1977. isAction : true,
  1978. /**
  1979. * Sets the text to be displayed by all components using this action.
  1980. * @param {String} text The text to display
  1981. */
  1982. setText : function(text){
  1983. this.initialConfig.text = text;
  1984. this.callEach('setText', [text]);
  1985. },
  1986. /**
  1987. * Gets the text currently displayed by all components using this action.
  1988. */
  1989. getText : function(){
  1990. return this.initialConfig.text;
  1991. },
  1992. /**
  1993. * Sets the icon CSS class for all components using this action. The class should supply
  1994. * a background image that will be used as the icon image.
  1995. * @param {String} cls The CSS class supplying the icon image
  1996. */
  1997. setIconClass : function(cls){
  1998. this.initialConfig.iconCls = cls;
  1999. this.callEach('setIconClass', [cls]);
  2000. },
  2001. /**
  2002. * Gets the icon CSS class currently used by all components using this action.
  2003. */
  2004. getIconClass : function(){
  2005. return this.initialConfig.iconCls;
  2006. },
  2007. /**
  2008. * Sets the disabled state of all components using this action. Shortcut method
  2009. * for {@link #enable} and {@link #disable}.
  2010. * @param {Boolean} disabled True to disable the component, false to enable it
  2011. */
  2012. setDisabled : function(v){
  2013. this.initialConfig.disabled = v;
  2014. this.callEach('setDisabled', [v]);
  2015. },
  2016. /**
  2017. * Enables all components using this action.
  2018. */
  2019. enable : function(){
  2020. this.setDisabled(false);
  2021. },
  2022. /**
  2023. * Disables all components using this action.
  2024. */
  2025. disable : function(){
  2026. this.setDisabled(true);
  2027. },
  2028. /**
  2029. * Returns true if the components using this action are currently disabled, else returns false.
  2030. */
  2031. isDisabled : function(){
  2032. return this.initialConfig.disabled;
  2033. },
  2034. /**
  2035. * Sets the hidden state of all components using this action. Shortcut method
  2036. * for <code>{@link #hide}</code> and <code>{@link #show}</code>.
  2037. * @param {Boolean} hidden True to hide the component, false to show it
  2038. */
  2039. setHidden : function(v){
  2040. this.initialConfig.hidden = v;
  2041. this.callEach('setVisible', [!v]);
  2042. },
  2043. /**
  2044. * Shows all components using this action.
  2045. */
  2046. show : function(){
  2047. this.setHidden(false);
  2048. },
  2049. /**
  2050. * Hides all components using this action.
  2051. */
  2052. hide : function(){
  2053. this.setHidden(true);
  2054. },
  2055. /**
  2056. * Returns true if the components using this action are currently hidden, else returns false.
  2057. */
  2058. isHidden : function(){
  2059. return this.initialConfig.hidden;
  2060. },
  2061. /**
  2062. * Sets the function that will be called by each Component using this action when its primary event is triggered.
  2063. * @param {Function} fn The function that will be invoked by the action's components. The function
  2064. * will be called with no arguments.
  2065. * @param {Object} scope The scope (<code>this</code> reference) in which the function is executed. Defaults to the Component firing the event.
  2066. */
  2067. setHandler : function(fn, scope){
  2068. this.initialConfig.handler = fn;
  2069. this.initialConfig.scope = scope;
  2070. this.callEach('setHandler', [fn, scope]);
  2071. },
  2072. /**
  2073. * Executes the specified function once for each Component currently tied to this action. The function passed
  2074. * in should accept a single argument that will be an object that supports the basic Action config/method interface.
  2075. * @param {Function} fn The function to execute for each component
  2076. * @param {Object} scope The scope (<code>this</code> reference) in which the function is executed. Defaults to the Component.
  2077. */
  2078. each : function(fn, scope){
  2079. Ext.each(this.items, fn, scope);
  2080. },
  2081. // private
  2082. callEach : function(fnName, args){
  2083. var cs = this.items;
  2084. for(var i = 0, len = cs.length; i < len; i++){
  2085. cs[i][fnName].apply(cs[i], args);
  2086. }
  2087. },
  2088. // private
  2089. addComponent : function(comp){
  2090. this.items.push(comp);
  2091. comp.on('destroy', this.removeComponent, this);
  2092. },
  2093. // private
  2094. removeComponent : function(comp){
  2095. this.items.remove(comp);
  2096. },
  2097. /**
  2098. * Executes this action manually using the handler function specified in the original config object
  2099. * or the handler function set with <code>{@link #setHandler}</code>. Any arguments passed to this
  2100. * function will be passed on to the handler function.
  2101. * @param {Mixed...} args Variable number of arguments passed to the handler function
  2102. */
  2103. execute : function(){
  2104. this.initialConfig.handler.apply(this.initialConfig.scope || window, arguments);
  2105. }
  2106. });
  2107. /**
  2108. * @class Ext.Layer
  2109. * @extends Ext.Element
  2110. * An extended {@link Ext.Element} object that supports a shadow and shim, constrain to viewport and
  2111. * automatic maintaining of shadow/shim positions.
  2112. * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
  2113. * @cfg {String/Boolean} shadow True to automatically create an {@link Ext.Shadow}, or a string indicating the
  2114. * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow. (defaults to false)
  2115. * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: 'div', cls: 'x-layer'}).
  2116. * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
  2117. * @cfg {String} cls CSS class to add to the element
  2118. * @cfg {Number} zindex Starting z-index (defaults to 11000)
  2119. * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 4)
  2120. * @cfg {Boolean} useDisplay
  2121. * Defaults to use css offsets to hide the Layer. Specify <tt>true</tt>
  2122. * to use css style <tt>'display:none;'</tt> to hide the Layer.
  2123. * @constructor
  2124. * @param {Object} config An object with config options.
  2125. * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
  2126. */
  2127. (function(){
  2128. Ext.Layer = function(config, existingEl){
  2129. config = config || {};
  2130. var dh = Ext.DomHelper,
  2131. cp = config.parentEl, pel = cp ? Ext.getDom(cp) : document.body;
  2132. if (existingEl) {
  2133. this.dom = Ext.getDom(existingEl);
  2134. }
  2135. if(!this.dom){
  2136. var o = config.dh || {tag: 'div', cls: 'x-layer'};
  2137. this.dom = dh.append(pel, o);
  2138. }
  2139. if(config.cls){
  2140. this.addClass(config.cls);
  2141. }
  2142. this.constrain = config.constrain !== false;
  2143. this.setVisibilityMode(Ext.Element.VISIBILITY);
  2144. if(config.id){
  2145. this.id = this.dom.id = config.id;
  2146. }else{
  2147. this.id = Ext.id(this.dom);
  2148. }
  2149. this.zindex = config.zindex || this.getZIndex();
  2150. this.position('absolute', this.zindex);
  2151. if(config.shadow){
  2152. this.shadowOffset = config.shadowOffset || 4;
  2153. this.shadow = new Ext.Shadow({
  2154. offset : this.shadowOffset,
  2155. mode : config.shadow
  2156. });
  2157. }else{
  2158. this.shadowOffset = 0;
  2159. }
  2160. this.useShim = config.shim !== false && Ext.useShims;
  2161. this.useDisplay = config.useDisplay;
  2162. this.hide();
  2163. };
  2164. var supr = Ext.Element.prototype;
  2165. // shims are shared among layer to keep from having 100 iframes
  2166. var shims = [];
  2167. Ext.extend(Ext.Layer, Ext.Element, {
  2168. getZIndex : function(){
  2169. return this.zindex || parseInt((this.getShim() || this).getStyle('z-index'), 10) || 11000;
  2170. },
  2171. getShim : function(){
  2172. if(!this.useShim){
  2173. return null;
  2174. }
  2175. if(this.shim){
  2176. return this.shim;
  2177. }
  2178. var shim = shims.shift();
  2179. if(!shim){
  2180. shim = this.createShim();
  2181. shim.enableDisplayMode('block');
  2182. shim.dom.style.display = 'none';
  2183. shim.dom.style.visibility = 'visible';
  2184. }
  2185. var pn = this.dom.parentNode;
  2186. if(shim.dom.parentNode != pn){
  2187. pn.insertBefore(shim.dom, this.dom);
  2188. }
  2189. shim.setStyle('z-index', this.getZIndex()-2);
  2190. this.shim = shim;
  2191. return shim;
  2192. },
  2193. hideShim : function(){
  2194. if(this.shim){
  2195. this.shim.setDisplayed(false);
  2196. shims.push(this.shim);
  2197. delete this.shim;
  2198. }
  2199. },
  2200. disableShadow : function(){
  2201. if(this.shadow){
  2202. this.shadowDisabled = true;
  2203. this.shadow.hide();
  2204. this.lastShadowOffset = this.shadowOffset;
  2205. this.shadowOffset = 0;
  2206. }
  2207. },
  2208. enableShadow : function(show){
  2209. if(this.shadow){
  2210. this.shadowDisabled = false;
  2211. if(Ext.isDefined(this.lastShadowOffset)) {
  2212. this.shadowOffset = this.lastShadowOffset;
  2213. delete this.lastShadowOffset;
  2214. }
  2215. if(show){
  2216. this.sync(true);
  2217. }
  2218. }
  2219. },
  2220. // private
  2221. // this code can execute repeatedly in milliseconds (i.e. during a drag) so
  2222. // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
  2223. sync : function(doShow){
  2224. var shadow = this.shadow;
  2225. if(!this.updating && this.isVisible() && (shadow || this.useShim)){
  2226. var shim = this.getShim(),
  2227. w = this.getWidth(),
  2228. h = this.getHeight(),
  2229. l = this.getLeft(true),
  2230. t = this.getTop(true);
  2231. if(shadow && !this.shadowDisabled){
  2232. if(doShow && !shadow.isVisible()){
  2233. shadow.show(this);
  2234. }else{
  2235. shadow.realign(l, t, w, h);
  2236. }
  2237. if(shim){
  2238. if(doShow){
  2239. shim.show();
  2240. }
  2241. // fit the shim behind the shadow, so it is shimmed too
  2242. var shadowAdj = shadow.el.getXY(), shimStyle = shim.dom.style,
  2243. shadowSize = shadow.el.getSize();
  2244. shimStyle.left = (shadowAdj[0])+'px';
  2245. shimStyle.top = (shadowAdj[1])+'px';
  2246. shimStyle.width = (shadowSize.width)+'px';
  2247. shimStyle.height = (shadowSize.height)+'px';
  2248. }
  2249. }else if(shim){
  2250. if(doShow){
  2251. shim.show();
  2252. }
  2253. shim.setSize(w, h);
  2254. shim.setLeftTop(l, t);
  2255. }
  2256. }
  2257. },
  2258. // private
  2259. destroy : function(){
  2260. this.hideShim();
  2261. if(this.shadow){
  2262. this.shadow.hide();
  2263. }
  2264. this.removeAllListeners();
  2265. Ext.removeNode(this.dom);
  2266. delete this.dom;
  2267. },
  2268. remove : function(){
  2269. this.destroy();
  2270. },
  2271. // private
  2272. beginUpdate : function(){
  2273. this.updating = true;
  2274. },
  2275. // private
  2276. endUpdate : function(){
  2277. this.updating = false;
  2278. this.sync(true);
  2279. },
  2280. // private
  2281. hideUnders : function(negOffset){
  2282. if(this.shadow){
  2283. this.shadow.hide();
  2284. }
  2285. this.hideShim();
  2286. },
  2287. // private
  2288. constrainXY : function(){
  2289. if(this.constrain){
  2290. var vw = Ext.lib.Dom.getViewWidth(),
  2291. vh = Ext.lib.Dom.getViewHeight();
  2292. var s = Ext.getDoc().getScroll();
  2293. var xy = this.getXY();
  2294. var x = xy[0], y = xy[1];
  2295. var so = this.shadowOffset;
  2296. var w = this.dom.offsetWidth+so, h = this.dom.offsetHeight+so;
  2297. // only move it if it needs it
  2298. var moved = false;
  2299. // first validate right/bottom
  2300. if((x + w) > vw+s.left){
  2301. x = vw - w - so;
  2302. moved = true;
  2303. }
  2304. if((y + h) > vh+s.top){
  2305. y = vh - h - so;
  2306. moved = true;
  2307. }
  2308. // then make sure top/left isn't negative
  2309. if(x < s.left){
  2310. x = s.left;
  2311. moved = true;
  2312. }
  2313. if(y < s.top){
  2314. y = s.top;
  2315. moved = true;
  2316. }
  2317. if(moved){
  2318. if(this.avoidY){
  2319. var ay = this.avoidY;
  2320. if(y <= ay && (y+h) >= ay){
  2321. y = ay-h-5;
  2322. }
  2323. }
  2324. xy = [x, y];
  2325. this.storeXY(xy);
  2326. supr.setXY.call(this, xy);
  2327. this.sync();
  2328. }
  2329. }
  2330. return this;
  2331. },
  2332. getConstrainOffset : function(){
  2333. return this.shadowOffset;
  2334. },
  2335. isVisible : function(){
  2336. return this.visible;
  2337. },
  2338. // private
  2339. showAction : function(){
  2340. this.visible = true; // track visibility to prevent getStyle calls
  2341. if(this.useDisplay === true){
  2342. this.setDisplayed('');
  2343. }else if(this.lastXY){
  2344. supr.setXY.call(this, this.lastXY);
  2345. }else if(this.lastLT){
  2346. supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
  2347. }
  2348. },
  2349. // private
  2350. hideAction : function(){
  2351. this.visible = false;
  2352. if(this.useDisplay === true){
  2353. this.setDisplayed(false);
  2354. }else{
  2355. this.setLeftTop(-10000,-10000);
  2356. }
  2357. },
  2358. // overridden Element method
  2359. setVisible : function(v, a, d, c, e){
  2360. if(v){
  2361. this.showAction();
  2362. }
  2363. if(a && v){
  2364. var cb = function(){
  2365. this.sync(true);
  2366. if(c){
  2367. c();
  2368. }
  2369. }.createDelegate(this);
  2370. supr.setVisible.call(this, true, true, d, cb, e);
  2371. }else{
  2372. if(!v){
  2373. this.hideUnders(true);
  2374. }
  2375. var cb = c;
  2376. if(a){
  2377. cb = function(){
  2378. this.hideAction();
  2379. if(c){
  2380. c();
  2381. }
  2382. }.createDelegate(this);
  2383. }
  2384. supr.setVisible.call(this, v, a, d, cb, e);
  2385. if(v){
  2386. this.sync(true);
  2387. }else if(!a){
  2388. this.hideAction();
  2389. }
  2390. }
  2391. return this;
  2392. },
  2393. storeXY : function(xy){
  2394. delete this.lastLT;
  2395. this.lastXY = xy;
  2396. },
  2397. storeLeftTop : function(left, top){
  2398. delete this.lastXY;
  2399. this.lastLT = [left, top];
  2400. },
  2401. // private
  2402. beforeFx : function(){
  2403. this.beforeAction();
  2404. return Ext.Layer.superclass.beforeFx.apply(this, arguments);
  2405. },
  2406. // private
  2407. afterFx : function(){
  2408. Ext.Layer.superclass.afterFx.apply(this, arguments);
  2409. this.sync(this.isVisible());
  2410. },
  2411. // private
  2412. beforeAction : function(){
  2413. if(!this.updating && this.shadow){
  2414. this.shadow.hide();
  2415. }
  2416. },
  2417. // overridden Element method
  2418. setLeft : function(left){
  2419. this.storeLeftTop(left, this.getTop(true));
  2420. supr.setLeft.apply(this, arguments);
  2421. this.sync();
  2422. return this;
  2423. },
  2424. setTop : function(top){
  2425. this.storeLeftTop(this.getLeft(true), top);
  2426. supr.setTop.apply(this, arguments);
  2427. this.sync();
  2428. return this;
  2429. },
  2430. setLeftTop : function(left, top){
  2431. this.storeLeftTop(left, top);
  2432. supr.setLeftTop.apply(this, arguments);
  2433. this.sync();
  2434. return this;
  2435. },
  2436. setXY : function(xy, a, d, c, e){
  2437. this.fixDisplay();
  2438. this.beforeAction();
  2439. this.storeXY(xy);
  2440. var cb = this.createCB(c);
  2441. supr.setXY.call(this, xy, a, d, cb, e);
  2442. if(!a){
  2443. cb();
  2444. }
  2445. return this;
  2446. },
  2447. // private
  2448. createCB : function(c){
  2449. var el = this;
  2450. return function(){
  2451. el.constrainXY();
  2452. el.sync(true);
  2453. if(c){
  2454. c();
  2455. }
  2456. };
  2457. },
  2458. // overridden Element method
  2459. setX : function(x, a, d, c, e){
  2460. this.setXY([x, this.getY()], a, d, c, e);
  2461. return this;
  2462. },
  2463. // overridden Element method
  2464. setY : function(y, a, d, c, e){
  2465. this.setXY([this.getX(), y], a, d, c, e);
  2466. return this;
  2467. },
  2468. // overridden Element method
  2469. setSize : function(w, h, a, d, c, e){
  2470. this.beforeAction();
  2471. var cb = this.createCB(c);
  2472. supr.setSize.call(this, w, h, a, d, cb, e);
  2473. if(!a){
  2474. cb();
  2475. }
  2476. return this;
  2477. },
  2478. // overridden Element method
  2479. setWidth : function(w, a, d, c, e){
  2480. this.beforeAction();
  2481. var cb = this.createCB(c);
  2482. supr.setWidth.call(this, w, a, d, cb, e);
  2483. if(!a){
  2484. cb();
  2485. }
  2486. return this;
  2487. },
  2488. // overridden Element method
  2489. setHeight : function(h, a, d, c, e){
  2490. this.beforeAction();
  2491. var cb = this.createCB(c);
  2492. supr.setHeight.call(this, h, a, d, cb, e);
  2493. if(!a){
  2494. cb();
  2495. }
  2496. return this;
  2497. },
  2498. // overridden Element method
  2499. setBounds : function(x, y, w, h, a, d, c, e){
  2500. this.beforeAction();
  2501. var cb = this.createCB(c);
  2502. if(!a){
  2503. this.storeXY([x, y]);
  2504. supr.setXY.call(this, [x, y]);
  2505. supr.setSize.call(this, w, h, a, d, cb, e);
  2506. cb();
  2507. }else{
  2508. supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
  2509. }
  2510. return this;
  2511. },
  2512. /**
  2513. * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
  2514. * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
  2515. * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
  2516. * @param {Number} zindex The new z-index to set
  2517. * @return {this} The Layer
  2518. */
  2519. setZIndex : function(zindex){
  2520. this.zindex = zindex;
  2521. this.setStyle('z-index', zindex + 2);
  2522. if(this.shadow){
  2523. this.shadow.setZIndex(zindex + 1);
  2524. }
  2525. if(this.shim){
  2526. this.shim.setStyle('z-index', zindex);
  2527. }
  2528. return this;
  2529. }
  2530. });
  2531. })();
  2532. /**
  2533. * @class Ext.Shadow
  2534. * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
  2535. * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
  2536. * functionality that can also provide the same shadow effect, see the {@link Ext.Layer} class.
  2537. * @constructor
  2538. * Create a new Shadow
  2539. * @param {Object} config The config object
  2540. */
  2541. Ext.Shadow = function(config) {
  2542. Ext.apply(this, config);
  2543. if (typeof this.mode != "string") {
  2544. this.mode = this.defaultMode;
  2545. }
  2546. var o = this.offset,
  2547. a = {
  2548. h: 0
  2549. },
  2550. rad = Math.floor(this.offset / 2);
  2551. switch (this.mode.toLowerCase()) {
  2552. // all this hideous nonsense calculates the various offsets for shadows
  2553. case "drop":
  2554. a.w = 0;
  2555. a.l = a.t = o;
  2556. a.t -= 1;
  2557. if (Ext.isIE9m) {
  2558. a.l -= this.offset + rad;
  2559. a.t -= this.offset + rad;
  2560. a.w -= rad;
  2561. a.h -= rad;
  2562. a.t += 1;
  2563. }
  2564. break;
  2565. case "sides":
  2566. a.w = (o * 2);
  2567. a.l = -o;
  2568. a.t = o - 1;
  2569. if (Ext.isIE9m) {
  2570. a.l -= (this.offset - rad);
  2571. a.t -= this.offset + rad;
  2572. a.l += 1;
  2573. a.w -= (this.offset - rad) * 2;
  2574. a.w -= rad + 1;
  2575. a.h -= 1;
  2576. }
  2577. break;
  2578. case "frame":
  2579. a.w = a.h = (o * 2);
  2580. a.l = a.t = -o;
  2581. a.t += 1;
  2582. a.h -= 2;
  2583. if (Ext.isIE9m) {
  2584. a.l -= (this.offset - rad);
  2585. a.t -= (this.offset - rad);
  2586. a.l += 1;
  2587. a.w -= (this.offset + rad + 1);
  2588. a.h -= (this.offset + rad);
  2589. a.h += 1;
  2590. }
  2591. break;
  2592. };
  2593. this.adjusts = a;
  2594. };
  2595. Ext.Shadow.prototype = {
  2596. /**
  2597. * @cfg {String} mode
  2598. * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
  2599. * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
  2600. * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
  2601. * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
  2602. * </ul></div>
  2603. */
  2604. /**
  2605. * @cfg {String} offset
  2606. * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
  2607. */
  2608. offset: 4,
  2609. // private
  2610. defaultMode: "drop",
  2611. /**
  2612. * Displays the shadow under the target element
  2613. * @param {Mixed} targetEl The id or element under which the shadow should display
  2614. */
  2615. show: function(target) {
  2616. target = Ext.get(target);
  2617. if (!this.el) {
  2618. this.el = Ext.Shadow.Pool.pull();
  2619. if (this.el.dom.nextSibling != target.dom) {
  2620. this.el.insertBefore(target);
  2621. }
  2622. }
  2623. this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10) - 1);
  2624. if (Ext.isIE9m) {
  2625. this.el.dom.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (this.offset) + ")";
  2626. }
  2627. this.realign(
  2628. target.getLeft(true),
  2629. target.getTop(true),
  2630. target.getWidth(),
  2631. target.getHeight()
  2632. );
  2633. this.el.dom.style.display = "block";
  2634. },
  2635. /**
  2636. * Returns true if the shadow is visible, else false
  2637. */
  2638. isVisible: function() {
  2639. return this.el ? true: false;
  2640. },
  2641. /**
  2642. * Direct alignment when values are already available. Show must be called at least once before
  2643. * calling this method to ensure it is initialized.
  2644. * @param {Number} left The target element left position
  2645. * @param {Number} top The target element top position
  2646. * @param {Number} width The target element width
  2647. * @param {Number} height The target element height
  2648. */
  2649. realign: function(l, t, w, h) {
  2650. if (!this.el) {
  2651. return;
  2652. }
  2653. var a = this.adjusts,
  2654. d = this.el.dom,
  2655. s = d.style,
  2656. iea = 0,
  2657. sw = (w + a.w),
  2658. sh = (h + a.h),
  2659. sws = sw + "px",
  2660. shs = sh + "px",
  2661. cn,
  2662. sww;
  2663. s.left = (l + a.l) + "px";
  2664. s.top = (t + a.t) + "px";
  2665. if (s.width != sws || s.height != shs) {
  2666. s.width = sws;
  2667. s.height = shs;
  2668. if (!Ext.isIE9m) {
  2669. cn = d.childNodes;
  2670. sww = Math.max(0, (sw - 12)) + "px";
  2671. cn[0].childNodes[1].style.width = sww;
  2672. cn[1].childNodes[1].style.width = sww;
  2673. cn[2].childNodes[1].style.width = sww;
  2674. cn[1].style.height = Math.max(0, (sh - 12)) + "px";
  2675. }
  2676. }
  2677. },
  2678. /**
  2679. * Hides this shadow
  2680. */
  2681. hide: function() {
  2682. if (this.el) {
  2683. this.el.dom.style.display = "none";
  2684. Ext.Shadow.Pool.push(this.el);
  2685. delete this.el;
  2686. }
  2687. },
  2688. /**
  2689. * Adjust the z-index of this shadow
  2690. * @param {Number} zindex The new z-index
  2691. */
  2692. setZIndex: function(z) {
  2693. this.zIndex = z;
  2694. if (this.el) {
  2695. this.el.setStyle("z-index", z);
  2696. }
  2697. }
  2698. };
  2699. // Private utility class that manages the internal Shadow cache
  2700. Ext.Shadow.Pool = function() {
  2701. var p = [],
  2702. markup = Ext.isIE9m ?
  2703. '<div class="x-ie-shadow"></div>':
  2704. '<div class="x-shadow"><div class="xst"><div class="xstl"></div><div class="xstc"></div><div class="xstr"></div></div><div class="xsc"><div class="xsml"></div><div class="xsmc"></div><div class="xsmr"></div></div><div class="xsb"><div class="xsbl"></div><div class="xsbc"></div><div class="xsbr"></div></div></div>';
  2705. return {
  2706. pull: function() {
  2707. var sh = p.shift();
  2708. if (!sh) {
  2709. sh = Ext.get(Ext.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
  2710. sh.autoBoxAdjust = false;
  2711. }
  2712. return sh;
  2713. },
  2714. push: function(sh) {
  2715. p.push(sh);
  2716. }
  2717. };
  2718. }();/**
  2719. * @class Ext.BoxComponent
  2720. * @extends Ext.Component
  2721. * <p>Base class for any {@link Ext.Component Component} that is to be sized as a box, using width and height.</p>
  2722. * <p>BoxComponent provides automatic box model adjustments for sizing and positioning and will work correctly
  2723. * within the Component rendering model.</p>
  2724. * <p>A BoxComponent may be created as a custom Component which encapsulates any HTML element, either a pre-existing
  2725. * element, or one that is created to your specifications at render time. Usually, to participate in layouts,
  2726. * a Component will need to be a <b>Box</b>Component in order to have its width and height managed.</p>
  2727. * <p>To use a pre-existing element as a BoxComponent, configure it so that you preset the <b>el</b> property to the
  2728. * element to reference:<pre><code>
  2729. var pageHeader = new Ext.BoxComponent({
  2730. el: 'my-header-div'
  2731. });</code></pre>
  2732. * This may then be {@link Ext.Container#add added} to a {@link Ext.Container Container} as a child item.</p>
  2733. * <p>To create a BoxComponent based around a HTML element to be created at render time, use the
  2734. * {@link Ext.Component#autoEl autoEl} config option which takes the form of a
  2735. * {@link Ext.DomHelper DomHelper} specification:<pre><code>
  2736. var myImage = new Ext.BoxComponent({
  2737. autoEl: {
  2738. tag: 'img',
  2739. src: '/images/my-image.jpg'
  2740. }
  2741. });</code></pre></p>
  2742. * @constructor
  2743. * @param {Ext.Element/String/Object} config The configuration options.
  2744. * @xtype box
  2745. */
  2746. Ext.BoxComponent = Ext.extend(Ext.Component, {
  2747. // Configs below are used for all Components when rendered by BoxLayout.
  2748. /**
  2749. * @cfg {Number} flex
  2750. * <p><b>Note</b>: this config is only used when this Component is rendered
  2751. * by a Container which has been configured to use a <b>{@link Ext.layout.BoxLayout BoxLayout}.</b>
  2752. * Each child Component with a <code>flex</code> property will be flexed either vertically (by a VBoxLayout)
  2753. * or horizontally (by an HBoxLayout) according to the item's <b>relative</b> <code>flex</code> value
  2754. * compared to the sum of all Components with <code>flex</code> value specified. Any child items that have
  2755. * either a <code>flex = 0</code> or <code>flex = undefined</code> will not be 'flexed' (the initial size will not be changed).
  2756. */
  2757. // Configs below are used for all Components when rendered by AnchorLayout.
  2758. /**
  2759. * @cfg {String} anchor <p><b>Note</b>: this config is only used when this Component is rendered
  2760. * by a Container which has been configured to use an <b>{@link Ext.layout.AnchorLayout AnchorLayout} (or subclass thereof).</b>
  2761. * based layout manager, for example:<div class="mdetail-params"><ul>
  2762. * <li>{@link Ext.form.FormPanel}</li>
  2763. * <li>specifying <code>layout: 'anchor' // or 'form', or 'absolute'</code></li>
  2764. * </ul></div></p>
  2765. * <p>See {@link Ext.layout.AnchorLayout}.{@link Ext.layout.AnchorLayout#anchor anchor} also.</p>
  2766. */
  2767. // tabTip config is used when a BoxComponent is a child of a TabPanel
  2768. /**
  2769. * @cfg {String} tabTip
  2770. * <p><b>Note</b>: this config is only used when this BoxComponent is a child item of a TabPanel.</p>
  2771. * A string to be used as innerHTML (html tags are accepted) to show in a tooltip when mousing over
  2772. * the associated tab selector element. {@link Ext.QuickTips}.init()
  2773. * must be called in order for the tips to render.
  2774. */
  2775. // Configs below are used for all Components when rendered by BorderLayout.
  2776. /**
  2777. * @cfg {String} region <p><b>Note</b>: this config is only used when this BoxComponent is rendered
  2778. * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
  2779. * layout manager (e.g. specifying <tt>layout:'border'</tt>).</p><br>
  2780. * <p>See {@link Ext.layout.BorderLayout} also.</p>
  2781. */
  2782. // margins config is used when a BoxComponent is rendered by BorderLayout or BoxLayout.
  2783. /**
  2784. * @cfg {Object} margins <p><b>Note</b>: this config is only used when this BoxComponent is rendered
  2785. * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
  2786. * or one of the two <b>{@link Ext.layout.BoxLayout BoxLayout} subclasses.</b></p>
  2787. * <p>An object containing margins to apply to this BoxComponent in the
  2788. * format:</p><pre><code>
  2789. {
  2790. top: (top margin),
  2791. right: (right margin),
  2792. bottom: (bottom margin),
  2793. left: (left margin)
  2794. }</code></pre>
  2795. * <p>May also be a string containing space-separated, numeric margin values. The order of the
  2796. * sides associated with each value matches the way CSS processes margin values:</p>
  2797. * <p><div class="mdetail-params"><ul>
  2798. * <li>If there is only one value, it applies to all sides.</li>
  2799. * <li>If there are two values, the top and bottom borders are set to the first value and the
  2800. * right and left are set to the second.</li>
  2801. * <li>If there are three values, the top is set to the first value, the left and right are set
  2802. * to the second, and the bottom is set to the third.</li>
  2803. * <li>If there are four values, they apply to the top, right, bottom, and left, respectively.</li>
  2804. * </ul></div></p>
  2805. * <p>Defaults to:</p><pre><code>
  2806. * {top:0, right:0, bottom:0, left:0}
  2807. * </code></pre>
  2808. */
  2809. /**
  2810. * @cfg {Number} x
  2811. * The local x (left) coordinate for this component if contained within a positioning container.
  2812. */
  2813. /**
  2814. * @cfg {Number} y
  2815. * The local y (top) coordinate for this component if contained within a positioning container.
  2816. */
  2817. /**
  2818. * @cfg {Number} pageX
  2819. * The page level x coordinate for this component if contained within a positioning container.
  2820. */
  2821. /**
  2822. * @cfg {Number} pageY
  2823. * The page level y coordinate for this component if contained within a positioning container.
  2824. */
  2825. /**
  2826. * @cfg {Number} height
  2827. * The height of this component in pixels (defaults to auto).
  2828. * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
  2829. */
  2830. /**
  2831. * @cfg {Number} width
  2832. * The width of this component in pixels (defaults to auto).
  2833. * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
  2834. */
  2835. /**
  2836. * @cfg {Number} boxMinHeight
  2837. * <p>The minimum value in pixels which this BoxComponent will set its height to.</p>
  2838. * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
  2839. */
  2840. /**
  2841. * @cfg {Number} boxMinWidth
  2842. * <p>The minimum value in pixels which this BoxComponent will set its width to.</p>
  2843. * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
  2844. */
  2845. /**
  2846. * @cfg {Number} boxMaxHeight
  2847. * <p>The maximum value in pixels which this BoxComponent will set its height to.</p>
  2848. * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
  2849. */
  2850. /**
  2851. * @cfg {Number} boxMaxWidth
  2852. * <p>The maximum value in pixels which this BoxComponent will set its width to.</p>
  2853. * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
  2854. */
  2855. /**
  2856. * @cfg {Boolean} autoHeight
  2857. * <p>True to use height:'auto', false to use fixed height (or allow it to be managed by its parent
  2858. * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
  2859. * <p><b>Note</b>: Although many components inherit this config option, not all will
  2860. * function as expected with a height of 'auto'. Setting autoHeight:true means that the
  2861. * browser will manage height based on the element's contents, and that Ext will not manage it at all.</p>
  2862. * <p>If the <i>browser</i> is managing the height, be aware that resizes performed by the browser in response
  2863. * to changes within the structure of the Component cannot be detected. Therefore changes to the height might
  2864. * result in elements needing to be synchronized with the new height. Example:</p><pre><code>
  2865. var w = new Ext.Window({
  2866. title: 'Window',
  2867. width: 600,
  2868. autoHeight: true,
  2869. items: {
  2870. title: 'Collapse Me',
  2871. height: 400,
  2872. collapsible: true,
  2873. border: false,
  2874. listeners: {
  2875. beforecollapse: function() {
  2876. w.el.shadow.hide();
  2877. },
  2878. beforeexpand: function() {
  2879. w.el.shadow.hide();
  2880. },
  2881. collapse: function() {
  2882. w.syncShadow();
  2883. },
  2884. expand: function() {
  2885. w.syncShadow();
  2886. }
  2887. }
  2888. }
  2889. }).show();
  2890. </code></pre>
  2891. */
  2892. /**
  2893. * @cfg {Boolean} autoWidth
  2894. * <p>True to use width:'auto', false to use fixed width (or allow it to be managed by its parent
  2895. * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
  2896. * <p><b>Note</b>: Although many components inherit this config option, not all will
  2897. * function as expected with a width of 'auto'. Setting autoWidth:true means that the
  2898. * browser will manage width based on the element's contents, and that Ext will not manage it at all.</p>
  2899. * <p>If the <i>browser</i> is managing the width, be aware that resizes performed by the browser in response
  2900. * to changes within the structure of the Component cannot be detected. Therefore changes to the width might
  2901. * result in elements needing to be synchronized with the new width. For example, where the target element is:</p><pre><code>
  2902. &lt;div id='grid-container' style='margin-left:25%;width:50%'>&lt;/div>
  2903. </code></pre>
  2904. * A Panel rendered into that target element must listen for browser window resize in order to relay its
  2905. * child items when the browser changes its width:<pre><code>
  2906. var myPanel = new Ext.Panel({
  2907. renderTo: 'grid-container',
  2908. monitorResize: true, // relay on browser resize
  2909. title: 'Panel',
  2910. height: 400,
  2911. autoWidth: true,
  2912. layout: 'hbox',
  2913. layoutConfig: {
  2914. align: 'stretch'
  2915. },
  2916. defaults: {
  2917. flex: 1
  2918. },
  2919. items: [{
  2920. title: 'Box 1',
  2921. }, {
  2922. title: 'Box 2'
  2923. }, {
  2924. title: 'Box 3'
  2925. }],
  2926. });
  2927. </code></pre>
  2928. */
  2929. /**
  2930. * @cfg {Boolean} autoScroll
  2931. * <code>true</code> to use overflow:'auto' on the components layout element and show scroll bars automatically when
  2932. * necessary, <code>false</code> to clip any overflowing content (defaults to <code>false</code>).
  2933. */
  2934. /* // private internal config
  2935. * {Boolean} deferHeight
  2936. * True to defer height calculations to an external component, false to allow this component to set its own
  2937. * height (defaults to false).
  2938. */
  2939. // private
  2940. initComponent : function(){
  2941. Ext.BoxComponent.superclass.initComponent.call(this);
  2942. this.addEvents(
  2943. /**
  2944. * @event resize
  2945. * Fires after the component is resized.
  2946. * @param {Ext.Component} this
  2947. * @param {Number} adjWidth The box-adjusted width that was set
  2948. * @param {Number} adjHeight The box-adjusted height that was set
  2949. * @param {Number} rawWidth The width that was originally specified
  2950. * @param {Number} rawHeight The height that was originally specified
  2951. */
  2952. 'resize',
  2953. /**
  2954. * @event move
  2955. * Fires after the component is moved.
  2956. * @param {Ext.Component} this
  2957. * @param {Number} x The new x position
  2958. * @param {Number} y The new y position
  2959. */
  2960. 'move'
  2961. );
  2962. },
  2963. // private, set in afterRender to signify that the component has been rendered
  2964. boxReady : false,
  2965. // private, used to defer height settings to subclasses
  2966. deferHeight: false,
  2967. /**
  2968. * Sets the width and height of this BoxComponent. This method fires the {@link #resize} event. This method can accept
  2969. * either width and height as separate arguments, or you can pass a size object like <code>{width:10, height:20}</code>.
  2970. * @param {Mixed} width The new width to set. This may be one of:<div class="mdetail-params"><ul>
  2971. * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
  2972. * <li>A String used to set the CSS width style.</li>
  2973. * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
  2974. * <li><code>undefined</code> to leave the width unchanged.</li>
  2975. * </ul></div>
  2976. * @param {Mixed} height The new height to set (not required if a size object is passed as the first arg).
  2977. * This may be one of:<div class="mdetail-params"><ul>
  2978. * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
  2979. * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
  2980. * <li><code>undefined</code> to leave the height unchanged.</li>
  2981. * </ul></div>
  2982. * @return {Ext.BoxComponent} this
  2983. */
  2984. setSize : function(w, h){
  2985. // support for standard size objects
  2986. if(typeof w == 'object'){
  2987. h = w.height;
  2988. w = w.width;
  2989. }
  2990. if (Ext.isDefined(w) && Ext.isDefined(this.boxMinWidth) && (w < this.boxMinWidth)) {
  2991. w = this.boxMinWidth;
  2992. }
  2993. if (Ext.isDefined(h) && Ext.isDefined(this.boxMinHeight) && (h < this.boxMinHeight)) {
  2994. h = this.boxMinHeight;
  2995. }
  2996. if (Ext.isDefined(w) && Ext.isDefined(this.boxMaxWidth) && (w > this.boxMaxWidth)) {
  2997. w = this.boxMaxWidth;
  2998. }
  2999. if (Ext.isDefined(h) && Ext.isDefined(this.boxMaxHeight) && (h > this.boxMaxHeight)) {
  3000. h = this.boxMaxHeight;
  3001. }
  3002. // not rendered
  3003. if(!this.boxReady){
  3004. this.width = w;
  3005. this.height = h;
  3006. return this;
  3007. }
  3008. // prevent recalcs when not needed
  3009. if(this.cacheSizes !== false && this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
  3010. return this;
  3011. }
  3012. this.lastSize = {width: w, height: h};
  3013. var adj = this.adjustSize(w, h),
  3014. aw = adj.width,
  3015. ah = adj.height,
  3016. rz;
  3017. if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
  3018. rz = this.getResizeEl();
  3019. if(!this.deferHeight && aw !== undefined && ah !== undefined){
  3020. rz.setSize(aw, ah);
  3021. }else if(!this.deferHeight && ah !== undefined){
  3022. rz.setHeight(ah);
  3023. }else if(aw !== undefined){
  3024. rz.setWidth(aw);
  3025. }
  3026. this.onResize(aw, ah, w, h);
  3027. this.fireEvent('resize', this, aw, ah, w, h);
  3028. }
  3029. return this;
  3030. },
  3031. /**
  3032. * Sets the width of the component. This method fires the {@link #resize} event.
  3033. * @param {Mixed} width The new width to set. This may be one of:<div class="mdetail-params"><ul>
  3034. * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit defaultUnit}s (by default, pixels).</li>
  3035. * <li>A String used to set the CSS width style.</li>
  3036. * </ul></div>
  3037. * @return {Ext.BoxComponent} this
  3038. */
  3039. setWidth : function(width){
  3040. return this.setSize(width);
  3041. },
  3042. /**
  3043. * Sets the height of the component. This method fires the {@link #resize} event.
  3044. * @param {Mixed} height The new height to set. This may be one of:<div class="mdetail-params"><ul>
  3045. * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit defaultUnit}s (by default, pixels).</li>
  3046. * <li>A String used to set the CSS height style.</li>
  3047. * <li><i>undefined</i> to leave the height unchanged.</li>
  3048. * </ul></div>
  3049. * @return {Ext.BoxComponent} this
  3050. */
  3051. setHeight : function(height){
  3052. return this.setSize(undefined, height);
  3053. },
  3054. /**
  3055. * Gets the current size of the component's underlying element.
  3056. * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
  3057. */
  3058. getSize : function(){
  3059. return this.getResizeEl().getSize();
  3060. },
  3061. /**
  3062. * Gets the current width of the component's underlying element.
  3063. * @return {Number}
  3064. */
  3065. getWidth : function(){
  3066. return this.getResizeEl().getWidth();
  3067. },
  3068. /**
  3069. * Gets the current height of the component's underlying element.
  3070. * @return {Number}
  3071. */
  3072. getHeight : function(){
  3073. return this.getResizeEl().getHeight();
  3074. },
  3075. /**
  3076. * Gets the current size of the component's underlying element, including space taken by its margins.
  3077. * @return {Object} An object containing the element's size {width: (element width + left/right margins), height: (element height + top/bottom margins)}
  3078. */
  3079. getOuterSize : function(){
  3080. var el = this.getResizeEl();
  3081. return {width: el.getWidth() + el.getMargins('lr'),
  3082. height: el.getHeight() + el.getMargins('tb')};
  3083. },
  3084. /**
  3085. * Gets the current XY position of the component's underlying element.
  3086. * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
  3087. * @return {Array} The XY position of the element (e.g., [100, 200])
  3088. */
  3089. getPosition : function(local){
  3090. var el = this.getPositionEl();
  3091. if(local === true){
  3092. return [el.getLeft(true), el.getTop(true)];
  3093. }
  3094. return this.xy || el.getXY();
  3095. },
  3096. /**
  3097. * Gets the current box measurements of the component's underlying element.
  3098. * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
  3099. * @return {Object} box An object in the format {x, y, width, height}
  3100. */
  3101. getBox : function(local){
  3102. var pos = this.getPosition(local);
  3103. var s = this.getSize();
  3104. s.x = pos[0];
  3105. s.y = pos[1];
  3106. return s;
  3107. },
  3108. /**
  3109. * Sets the current box measurements of the component's underlying element.
  3110. * @param {Object} box An object in the format {x, y, width, height}
  3111. * @return {Ext.BoxComponent} this
  3112. */
  3113. updateBox : function(box){
  3114. this.setSize(box.width, box.height);
  3115. this.setPagePosition(box.x, box.y);
  3116. return this;
  3117. },
  3118. /**
  3119. * <p>Returns the outermost Element of this Component which defines the Components overall size.</p>
  3120. * <p><i>Usually</i> this will return the same Element as <code>{@link #getEl}</code>,
  3121. * but in some cases, a Component may have some more wrapping Elements around its main
  3122. * active Element.</p>
  3123. * <p>An example is a ComboBox. It is encased in a <i>wrapping</i> Element which
  3124. * contains both the <code>&lt;input></code> Element (which is what would be returned
  3125. * by its <code>{@link #getEl}</code> method, <i>and</i> the trigger button Element.
  3126. * This Element is returned as the <code>resizeEl</code>.
  3127. * @return {Ext.Element} The Element which is to be resized by size managing layouts.
  3128. */
  3129. getResizeEl : function(){
  3130. return this.resizeEl || this.el;
  3131. },
  3132. /**
  3133. * Sets the overflow on the content element of the component.
  3134. * @param {Boolean} scroll True to allow the Component to auto scroll.
  3135. * @return {Ext.BoxComponent} this
  3136. */
  3137. setAutoScroll : function(scroll){
  3138. if(this.rendered){
  3139. this.getContentTarget().setOverflow(scroll ? 'auto' : '');
  3140. }
  3141. this.autoScroll = scroll;
  3142. return this;
  3143. },
  3144. /**
  3145. * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
  3146. * This method fires the {@link #move} event.
  3147. * @param {Number} left The new left
  3148. * @param {Number} top The new top
  3149. * @return {Ext.BoxComponent} this
  3150. */
  3151. setPosition : function(x, y){
  3152. if(x && typeof x[1] == 'number'){
  3153. y = x[1];
  3154. x = x[0];
  3155. }
  3156. this.x = x;
  3157. this.y = y;
  3158. if(!this.boxReady){
  3159. return this;
  3160. }
  3161. var adj = this.adjustPosition(x, y);
  3162. var ax = adj.x, ay = adj.y;
  3163. var el = this.getPositionEl();
  3164. if(ax !== undefined || ay !== undefined){
  3165. if(ax !== undefined && ay !== undefined){
  3166. el.setLeftTop(ax, ay);
  3167. }else if(ax !== undefined){
  3168. el.setLeft(ax);
  3169. }else if(ay !== undefined){
  3170. el.setTop(ay);
  3171. }
  3172. this.onPosition(ax, ay);
  3173. this.fireEvent('move', this, ax, ay);
  3174. }
  3175. return this;
  3176. },
  3177. /**
  3178. * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
  3179. * This method fires the {@link #move} event.
  3180. * @param {Number} x The new x position
  3181. * @param {Number} y The new y position
  3182. * @return {Ext.BoxComponent} this
  3183. */
  3184. setPagePosition : function(x, y){
  3185. if(x && typeof x[1] == 'number'){
  3186. y = x[1];
  3187. x = x[0];
  3188. }
  3189. this.pageX = x;
  3190. this.pageY = y;
  3191. if(!this.boxReady){
  3192. return;
  3193. }
  3194. if(x === undefined || y === undefined){ // cannot translate undefined points
  3195. return;
  3196. }
  3197. var p = this.getPositionEl().translatePoints(x, y);
  3198. this.setPosition(p.left, p.top);
  3199. return this;
  3200. },
  3201. // private
  3202. afterRender : function(){
  3203. Ext.BoxComponent.superclass.afterRender.call(this);
  3204. if(this.resizeEl){
  3205. this.resizeEl = Ext.get(this.resizeEl);
  3206. }
  3207. if(this.positionEl){
  3208. this.positionEl = Ext.get(this.positionEl);
  3209. }
  3210. this.boxReady = true;
  3211. Ext.isDefined(this.autoScroll) && this.setAutoScroll(this.autoScroll);
  3212. this.setSize(this.width, this.height);
  3213. if(this.x || this.y){
  3214. this.setPosition(this.x, this.y);
  3215. }else if(this.pageX || this.pageY){
  3216. this.setPagePosition(this.pageX, this.pageY);
  3217. }
  3218. },
  3219. /**
  3220. * Force the component's size to recalculate based on the underlying element's current height and width.
  3221. * @return {Ext.BoxComponent} this
  3222. */
  3223. syncSize : function(){
  3224. delete this.lastSize;
  3225. this.setSize(this.autoWidth ? undefined : this.getResizeEl().getWidth(), this.autoHeight ? undefined : this.getResizeEl().getHeight());
  3226. return this;
  3227. },
  3228. /* // protected
  3229. * Called after the component is resized, this method is empty by default but can be implemented by any
  3230. * subclass that needs to perform custom logic after a resize occurs.
  3231. * @param {Number} adjWidth The box-adjusted width that was set
  3232. * @param {Number} adjHeight The box-adjusted height that was set
  3233. * @param {Number} rawWidth The width that was originally specified
  3234. * @param {Number} rawHeight The height that was originally specified
  3235. */
  3236. onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
  3237. },
  3238. /* // protected
  3239. * Called after the component is moved, this method is empty by default but can be implemented by any
  3240. * subclass that needs to perform custom logic after a move occurs.
  3241. * @param {Number} x The new x position
  3242. * @param {Number} y The new y position
  3243. */
  3244. onPosition : function(x, y){
  3245. },
  3246. // private
  3247. adjustSize : function(w, h){
  3248. if(this.autoWidth){
  3249. w = 'auto';
  3250. }
  3251. if(this.autoHeight){
  3252. h = 'auto';
  3253. }
  3254. return {width : w, height: h};
  3255. },
  3256. // private
  3257. adjustPosition : function(x, y){
  3258. return {x : x, y: y};
  3259. }
  3260. });
  3261. Ext.reg('box', Ext.BoxComponent);
  3262. /**
  3263. * @class Ext.Spacer
  3264. * @extends Ext.BoxComponent
  3265. * <p>Used to provide a sizable space in a layout.</p>
  3266. * @constructor
  3267. * @param {Object} config
  3268. */
  3269. Ext.Spacer = Ext.extend(Ext.BoxComponent, {
  3270. autoEl:'div'
  3271. });
  3272. Ext.reg('spacer', Ext.Spacer);/**
  3273. * @class Ext.SplitBar
  3274. * @extends Ext.util.Observable
  3275. * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
  3276. * <br><br>
  3277. * Usage:
  3278. * <pre><code>
  3279. var split = new Ext.SplitBar("elementToDrag", "elementToSize",
  3280. Ext.SplitBar.HORIZONTAL, Ext.SplitBar.LEFT);
  3281. split.setAdapter(new Ext.SplitBar.AbsoluteLayoutAdapter("container"));
  3282. split.minSize = 100;
  3283. split.maxSize = 600;
  3284. split.animate = true;
  3285. split.on('moved', splitterMoved);
  3286. </code></pre>
  3287. * @constructor
  3288. * Create a new SplitBar
  3289. * @param {Mixed} dragElement The element to be dragged and act as the SplitBar.
  3290. * @param {Mixed} resizingElement The element to be resized based on where the SplitBar element is dragged
  3291. * @param {Number} orientation (optional) Either Ext.SplitBar.HORIZONTAL or Ext.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
  3292. * @param {Number} placement (optional) Either Ext.SplitBar.LEFT or Ext.SplitBar.RIGHT for horizontal or
  3293. Ext.SplitBar.TOP or Ext.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
  3294. position of the SplitBar).
  3295. */
  3296. Ext.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
  3297. /** @private */
  3298. this.el = Ext.get(dragElement, true);
  3299. this.el.unselectable();
  3300. /** @private */
  3301. this.resizingEl = Ext.get(resizingElement, true);
  3302. /**
  3303. * @private
  3304. * The orientation of the split. Either Ext.SplitBar.HORIZONTAL or Ext.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
  3305. * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
  3306. * @type Number
  3307. */
  3308. this.orientation = orientation || Ext.SplitBar.HORIZONTAL;
  3309. /**
  3310. * The increment, in pixels by which to move this SplitBar. When <i>undefined</i>, the SplitBar moves smoothly.
  3311. * @type Number
  3312. * @property tickSize
  3313. */
  3314. /**
  3315. * The minimum size of the resizing element. (Defaults to 0)
  3316. * @type Number
  3317. */
  3318. this.minSize = 0;
  3319. /**
  3320. * The maximum size of the resizing element. (Defaults to 2000)
  3321. * @type Number
  3322. */
  3323. this.maxSize = 2000;
  3324. /**
  3325. * Whether to animate the transition to the new size
  3326. * @type Boolean
  3327. */
  3328. this.animate = false;
  3329. /**
  3330. * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
  3331. * @type Boolean
  3332. */
  3333. this.useShim = false;
  3334. /** @private */
  3335. this.shim = null;
  3336. if(!existingProxy){
  3337. /** @private */
  3338. this.proxy = Ext.SplitBar.createProxy(this.orientation);
  3339. }else{
  3340. this.proxy = Ext.get(existingProxy).dom;
  3341. }
  3342. /** @private */
  3343. this.dd = new Ext.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
  3344. /** @private */
  3345. this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
  3346. /** @private */
  3347. this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
  3348. /** @private */
  3349. this.dragSpecs = {};
  3350. /**
  3351. * @private The adapter to use to positon and resize elements
  3352. */
  3353. this.adapter = new Ext.SplitBar.BasicLayoutAdapter();
  3354. this.adapter.init(this);
  3355. if(this.orientation == Ext.SplitBar.HORIZONTAL){
  3356. /** @ignore */
  3357. this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Ext.SplitBar.LEFT : Ext.SplitBar.RIGHT);
  3358. this.el.addClass("x-splitbar-h");
  3359. }else{
  3360. /** @ignore */
  3361. this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Ext.SplitBar.TOP : Ext.SplitBar.BOTTOM);
  3362. this.el.addClass("x-splitbar-v");
  3363. }
  3364. this.addEvents(
  3365. /**
  3366. * @event resize
  3367. * Fires when the splitter is moved (alias for {@link #moved})
  3368. * @param {Ext.SplitBar} this
  3369. * @param {Number} newSize the new width or height
  3370. */
  3371. "resize",
  3372. /**
  3373. * @event moved
  3374. * Fires when the splitter is moved
  3375. * @param {Ext.SplitBar} this
  3376. * @param {Number} newSize the new width or height
  3377. */
  3378. "moved",
  3379. /**
  3380. * @event beforeresize
  3381. * Fires before the splitter is dragged
  3382. * @param {Ext.SplitBar} this
  3383. */
  3384. "beforeresize",
  3385. "beforeapply"
  3386. );
  3387. Ext.SplitBar.superclass.constructor.call(this);
  3388. };
  3389. Ext.extend(Ext.SplitBar, Ext.util.Observable, {
  3390. onStartProxyDrag : function(x, y){
  3391. this.fireEvent("beforeresize", this);
  3392. this.overlay = Ext.DomHelper.append(document.body, {cls: "x-drag-overlay", html: "&#160;"}, true);
  3393. this.overlay.unselectable();
  3394. this.overlay.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
  3395. this.overlay.show();
  3396. Ext.get(this.proxy).setDisplayed("block");
  3397. var size = this.adapter.getElementSize(this);
  3398. this.activeMinSize = this.getMinimumSize();
  3399. this.activeMaxSize = this.getMaximumSize();
  3400. var c1 = size - this.activeMinSize;
  3401. var c2 = Math.max(this.activeMaxSize - size, 0);
  3402. if(this.orientation == Ext.SplitBar.HORIZONTAL){
  3403. this.dd.resetConstraints();
  3404. this.dd.setXConstraint(
  3405. this.placement == Ext.SplitBar.LEFT ? c1 : c2,
  3406. this.placement == Ext.SplitBar.LEFT ? c2 : c1,
  3407. this.tickSize
  3408. );
  3409. this.dd.setYConstraint(0, 0);
  3410. }else{
  3411. this.dd.resetConstraints();
  3412. this.dd.setXConstraint(0, 0);
  3413. this.dd.setYConstraint(
  3414. this.placement == Ext.SplitBar.TOP ? c1 : c2,
  3415. this.placement == Ext.SplitBar.TOP ? c2 : c1,
  3416. this.tickSize
  3417. );
  3418. }
  3419. this.dragSpecs.startSize = size;
  3420. this.dragSpecs.startPoint = [x, y];
  3421. Ext.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
  3422. },
  3423. /**
  3424. * @private Called after the drag operation by the DDProxy
  3425. */
  3426. onEndProxyDrag : function(e){
  3427. Ext.get(this.proxy).setDisplayed(false);
  3428. var endPoint = Ext.lib.Event.getXY(e);
  3429. if(this.overlay){
  3430. Ext.destroy(this.overlay);
  3431. delete this.overlay;
  3432. }
  3433. var newSize;
  3434. if(this.orientation == Ext.SplitBar.HORIZONTAL){
  3435. newSize = this.dragSpecs.startSize +
  3436. (this.placement == Ext.SplitBar.LEFT ?
  3437. endPoint[0] - this.dragSpecs.startPoint[0] :
  3438. this.dragSpecs.startPoint[0] - endPoint[0]
  3439. );
  3440. }else{
  3441. newSize = this.dragSpecs.startSize +
  3442. (this.placement == Ext.SplitBar.TOP ?
  3443. endPoint[1] - this.dragSpecs.startPoint[1] :
  3444. this.dragSpecs.startPoint[1] - endPoint[1]
  3445. );
  3446. }
  3447. newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
  3448. if(newSize != this.dragSpecs.startSize){
  3449. if(this.fireEvent('beforeapply', this, newSize) !== false){
  3450. this.adapter.setElementSize(this, newSize);
  3451. this.fireEvent("moved", this, newSize);
  3452. this.fireEvent("resize", this, newSize);
  3453. }
  3454. }
  3455. },
  3456. /**
  3457. * Get the adapter this SplitBar uses
  3458. * @return The adapter object
  3459. */
  3460. getAdapter : function(){
  3461. return this.adapter;
  3462. },
  3463. /**
  3464. * Set the adapter this SplitBar uses
  3465. * @param {Object} adapter A SplitBar adapter object
  3466. */
  3467. setAdapter : function(adapter){
  3468. this.adapter = adapter;
  3469. this.adapter.init(this);
  3470. },
  3471. /**
  3472. * Gets the minimum size for the resizing element
  3473. * @return {Number} The minimum size
  3474. */
  3475. getMinimumSize : function(){
  3476. return this.minSize;
  3477. },
  3478. /**
  3479. * Sets the minimum size for the resizing element
  3480. * @param {Number} minSize The minimum size
  3481. */
  3482. setMinimumSize : function(minSize){
  3483. this.minSize = minSize;
  3484. },
  3485. /**
  3486. * Gets the maximum size for the resizing element
  3487. * @return {Number} The maximum size
  3488. */
  3489. getMaximumSize : function(){
  3490. return this.maxSize;
  3491. },
  3492. /**
  3493. * Sets the maximum size for the resizing element
  3494. * @param {Number} maxSize The maximum size
  3495. */
  3496. setMaximumSize : function(maxSize){
  3497. this.maxSize = maxSize;
  3498. },
  3499. /**
  3500. * Sets the initialize size for the resizing element
  3501. * @param {Number} size The initial size
  3502. */
  3503. setCurrentSize : function(size){
  3504. var oldAnimate = this.animate;
  3505. this.animate = false;
  3506. this.adapter.setElementSize(this, size);
  3507. this.animate = oldAnimate;
  3508. },
  3509. /**
  3510. * Destroy this splitbar.
  3511. * @param {Boolean} removeEl True to remove the element
  3512. */
  3513. destroy : function(removeEl){
  3514. Ext.destroy(this.shim, Ext.get(this.proxy));
  3515. this.dd.unreg();
  3516. if(removeEl){
  3517. this.el.remove();
  3518. }
  3519. this.purgeListeners();
  3520. }
  3521. });
  3522. /**
  3523. * @private static Create our own proxy element element. So it will be the same same size on all browsers, we won't use borders. Instead we use a background color.
  3524. */
  3525. Ext.SplitBar.createProxy = function(dir){
  3526. var proxy = new Ext.Element(document.createElement("div"));
  3527. document.body.appendChild(proxy.dom);
  3528. proxy.unselectable();
  3529. var cls = 'x-splitbar-proxy';
  3530. proxy.addClass(cls + ' ' + (dir == Ext.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
  3531. return proxy.dom;
  3532. };
  3533. /**
  3534. * @class Ext.SplitBar.BasicLayoutAdapter
  3535. * Default Adapter. It assumes the splitter and resizing element are not positioned
  3536. * elements and only gets/sets the width of the element. Generally used for table based layouts.
  3537. */
  3538. Ext.SplitBar.BasicLayoutAdapter = function(){
  3539. };
  3540. Ext.SplitBar.BasicLayoutAdapter.prototype = {
  3541. // do nothing for now
  3542. init : function(s){
  3543. },
  3544. /**
  3545. * Called before drag operations to get the current size of the resizing element.
  3546. * @param {Ext.SplitBar} s The SplitBar using this adapter
  3547. */
  3548. getElementSize : function(s){
  3549. if(s.orientation == Ext.SplitBar.HORIZONTAL){
  3550. return s.resizingEl.getWidth();
  3551. }else{
  3552. return s.resizingEl.getHeight();
  3553. }
  3554. },
  3555. /**
  3556. * Called after drag operations to set the size of the resizing element.
  3557. * @param {Ext.SplitBar} s The SplitBar using this adapter
  3558. * @param {Number} newSize The new size to set
  3559. * @param {Function} onComplete A function to be invoked when resizing is complete
  3560. */
  3561. setElementSize : function(s, newSize, onComplete){
  3562. if(s.orientation == Ext.SplitBar.HORIZONTAL){
  3563. if(!s.animate){
  3564. s.resizingEl.setWidth(newSize);
  3565. if(onComplete){
  3566. onComplete(s, newSize);
  3567. }
  3568. }else{
  3569. s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
  3570. }
  3571. }else{
  3572. if(!s.animate){
  3573. s.resizingEl.setHeight(newSize);
  3574. if(onComplete){
  3575. onComplete(s, newSize);
  3576. }
  3577. }else{
  3578. s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
  3579. }
  3580. }
  3581. }
  3582. };
  3583. /**
  3584. *@class Ext.SplitBar.AbsoluteLayoutAdapter
  3585. * @extends Ext.SplitBar.BasicLayoutAdapter
  3586. * Adapter that moves the splitter element to align with the resized sizing element.
  3587. * Used with an absolute positioned SplitBar.
  3588. * @param {Mixed} container The container that wraps around the absolute positioned content. If it's
  3589. * document.body, make sure you assign an id to the body element.
  3590. */
  3591. Ext.SplitBar.AbsoluteLayoutAdapter = function(container){
  3592. this.basic = new Ext.SplitBar.BasicLayoutAdapter();
  3593. this.container = Ext.get(container);
  3594. };
  3595. Ext.SplitBar.AbsoluteLayoutAdapter.prototype = {
  3596. init : function(s){
  3597. this.basic.init(s);
  3598. },
  3599. getElementSize : function(s){
  3600. return this.basic.getElementSize(s);
  3601. },
  3602. setElementSize : function(s, newSize, onComplete){
  3603. this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
  3604. },
  3605. moveSplitter : function(s){
  3606. var yes = Ext.SplitBar;
  3607. switch(s.placement){
  3608. case yes.LEFT:
  3609. s.el.setX(s.resizingEl.getRight());
  3610. break;
  3611. case yes.RIGHT:
  3612. s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
  3613. break;
  3614. case yes.TOP:
  3615. s.el.setY(s.resizingEl.getBottom());
  3616. break;
  3617. case yes.BOTTOM:
  3618. s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
  3619. break;
  3620. }
  3621. }
  3622. };
  3623. /**
  3624. * Orientation constant - Create a vertical SplitBar
  3625. * @static
  3626. * @type Number
  3627. */
  3628. Ext.SplitBar.VERTICAL = 1;
  3629. /**
  3630. * Orientation constant - Create a horizontal SplitBar
  3631. * @static
  3632. * @type Number
  3633. */
  3634. Ext.SplitBar.HORIZONTAL = 2;
  3635. /**
  3636. * Placement constant - The resizing element is to the left of the splitter element
  3637. * @static
  3638. * @type Number
  3639. */
  3640. Ext.SplitBar.LEFT = 1;
  3641. /**
  3642. * Placement constant - The resizing element is to the right of the splitter element
  3643. * @static
  3644. * @type Number
  3645. */
  3646. Ext.SplitBar.RIGHT = 2;
  3647. /**
  3648. * Placement constant - The resizing element is positioned above the splitter element
  3649. * @static
  3650. * @type Number
  3651. */
  3652. Ext.SplitBar.TOP = 3;
  3653. /**
  3654. * Placement constant - The resizing element is positioned under splitter element
  3655. * @static
  3656. * @type Number
  3657. */
  3658. Ext.SplitBar.BOTTOM = 4;
  3659. /**
  3660. * @class Ext.Container
  3661. * @extends Ext.BoxComponent
  3662. * <p>Base class for any {@link Ext.BoxComponent} that may contain other Components. Containers handle the
  3663. * basic behavior of containing items, namely adding, inserting and removing items.</p>
  3664. *
  3665. * <p>The most commonly used Container classes are {@link Ext.Panel}, {@link Ext.Window} and {@link Ext.TabPanel}.
  3666. * If you do not need the capabilities offered by the aforementioned classes you can create a lightweight
  3667. * Container to be encapsulated by an HTML element to your specifications by using the
  3668. * <code><b>{@link Ext.Component#autoEl autoEl}</b></code> config option. This is a useful technique when creating
  3669. * embedded {@link Ext.layout.ColumnLayout column} layouts inside {@link Ext.form.FormPanel FormPanels}
  3670. * for example.</p>
  3671. *
  3672. * <p>The code below illustrates both how to explicitly create a Container, and how to implicitly
  3673. * create one using the <b><code>'container'</code></b> xtype:<pre><code>
  3674. // explicitly create a Container
  3675. var embeddedColumns = new Ext.Container({
  3676. autoEl: 'div', // This is the default
  3677. layout: 'column',
  3678. defaults: {
  3679. // implicitly create Container by specifying xtype
  3680. xtype: 'container',
  3681. autoEl: 'div', // This is the default.
  3682. layout: 'form',
  3683. columnWidth: 0.5,
  3684. style: {
  3685. padding: '10px'
  3686. }
  3687. },
  3688. // The two items below will be Ext.Containers, each encapsulated by a &lt;DIV> element.
  3689. items: [{
  3690. items: {
  3691. xtype: 'datefield',
  3692. name: 'startDate',
  3693. fieldLabel: 'Start date'
  3694. }
  3695. }, {
  3696. items: {
  3697. xtype: 'datefield',
  3698. name: 'endDate',
  3699. fieldLabel: 'End date'
  3700. }
  3701. }]
  3702. });</code></pre></p>
  3703. *
  3704. * <p><u><b>Layout</b></u></p>
  3705. * <p>Container classes delegate the rendering of child Components to a layout
  3706. * manager class which must be configured into the Container using the
  3707. * <code><b>{@link #layout}</b></code> configuration property.</p>
  3708. * <p>When either specifying child <code>{@link #items}</code> of a Container,
  3709. * or dynamically {@link #add adding} Components to a Container, remember to
  3710. * consider how you wish the Container to arrange those child elements, and
  3711. * whether those child elements need to be sized using one of Ext's built-in
  3712. * <b><code>{@link #layout}</code></b> schemes. By default, Containers use the
  3713. * {@link Ext.layout.ContainerLayout ContainerLayout} scheme which only
  3714. * renders child components, appending them one after the other inside the
  3715. * Container, and <b>does not apply any sizing</b> at all.</p>
  3716. * <p>A common mistake is when a developer neglects to specify a
  3717. * <b><code>{@link #layout}</code></b> (e.g. widgets like GridPanels or
  3718. * TreePanels are added to Containers for which no <code><b>{@link #layout}</b></code>
  3719. * has been specified). If a Container is left to use the default
  3720. * {@link Ext.layout.ContainerLayout ContainerLayout} scheme, none of its
  3721. * child components will be resized, or changed in any way when the Container
  3722. * is resized.</p>
  3723. * <p>Certain layout managers allow dynamic addition of child components.
  3724. * Those that do include {@link Ext.layout.CardLayout},
  3725. * {@link Ext.layout.AnchorLayout}, {@link Ext.layout.FormLayout}, and
  3726. * {@link Ext.layout.TableLayout}. For example:<pre><code>
  3727. // Create the GridPanel.
  3728. var myNewGrid = new Ext.grid.GridPanel({
  3729. store: myStore,
  3730. columns: myColumnModel,
  3731. title: 'Results', // the title becomes the title of the tab
  3732. });
  3733. myTabPanel.add(myNewGrid); // {@link Ext.TabPanel} implicitly uses {@link Ext.layout.CardLayout CardLayout}
  3734. myTabPanel.{@link Ext.TabPanel#setActiveTab setActiveTab}(myNewGrid);
  3735. * </code></pre></p>
  3736. * <p>The example above adds a newly created GridPanel to a TabPanel. Note that
  3737. * a TabPanel uses {@link Ext.layout.CardLayout} as its layout manager which
  3738. * means all its child items are sized to {@link Ext.layout.FitLayout fit}
  3739. * exactly into its client area.
  3740. * <p><b><u>Overnesting is a common problem</u></b>.
  3741. * An example of overnesting occurs when a GridPanel is added to a TabPanel
  3742. * by wrapping the GridPanel <i>inside</i> a wrapping Panel (that has no
  3743. * <code><b>{@link #layout}</b></code> specified) and then add that wrapping Panel
  3744. * to the TabPanel. The point to realize is that a GridPanel <b>is</b> a
  3745. * Component which can be added directly to a Container. If the wrapping Panel
  3746. * has no <code><b>{@link #layout}</b></code> configuration, then the overnested
  3747. * GridPanel will not be sized as expected.<p>
  3748. *
  3749. * <p><u><b>Adding via remote configuration</b></u></p>
  3750. *
  3751. * <p>A server side script can be used to add Components which are generated dynamically on the server.
  3752. * An example of adding a GridPanel to a TabPanel where the GridPanel is generated by the server
  3753. * based on certain parameters:
  3754. * </p><pre><code>
  3755. // execute an Ajax request to invoke server side script:
  3756. Ext.Ajax.request({
  3757. url: 'gen-invoice-grid.php',
  3758. // send additional parameters to instruct server script
  3759. params: {
  3760. startDate: Ext.getCmp('start-date').getValue(),
  3761. endDate: Ext.getCmp('end-date').getValue()
  3762. },
  3763. // process the response object to add it to the TabPanel:
  3764. success: function(xhr) {
  3765. var newComponent = eval(xhr.responseText); // see discussion below
  3766. myTabPanel.add(newComponent); // add the component to the TabPanel
  3767. myTabPanel.setActiveTab(newComponent);
  3768. },
  3769. failure: function() {
  3770. Ext.Msg.alert("Grid create failed", "Server communication failure");
  3771. }
  3772. });
  3773. </code></pre>
  3774. * <p>The server script needs to return an executable Javascript statement which, when processed
  3775. * using <code>eval()</code>, will return either a config object with an {@link Ext.Component#xtype xtype},
  3776. * or an instantiated Component. The server might return this for example:</p><pre><code>
  3777. (function() {
  3778. function formatDate(value){
  3779. return value ? value.dateFormat('M d, Y') : '';
  3780. };
  3781. var store = new Ext.data.Store({
  3782. url: 'get-invoice-data.php',
  3783. baseParams: {
  3784. startDate: '01/01/2008',
  3785. endDate: '01/31/2008'
  3786. },
  3787. reader: new Ext.data.JsonReader({
  3788. record: 'transaction',
  3789. idProperty: 'id',
  3790. totalRecords: 'total'
  3791. }, [
  3792. 'customer',
  3793. 'invNo',
  3794. {name: 'date', type: 'date', dateFormat: 'm/d/Y'},
  3795. {name: 'value', type: 'float'}
  3796. ])
  3797. });
  3798. var grid = new Ext.grid.GridPanel({
  3799. title: 'Invoice Report',
  3800. bbar: new Ext.PagingToolbar(store),
  3801. store: store,
  3802. columns: [
  3803. {header: "Customer", width: 250, dataIndex: 'customer', sortable: true},
  3804. {header: "Invoice Number", width: 120, dataIndex: 'invNo', sortable: true},
  3805. {header: "Invoice Date", width: 100, dataIndex: 'date', renderer: formatDate, sortable: true},
  3806. {header: "Value", width: 120, dataIndex: 'value', renderer: 'usMoney', sortable: true}
  3807. ],
  3808. });
  3809. store.load();
  3810. return grid; // return instantiated component
  3811. })();
  3812. </code></pre>
  3813. * <p>When the above code fragment is passed through the <code>eval</code> function in the success handler
  3814. * of the Ajax request, the code is executed by the Javascript processor, and the anonymous function
  3815. * runs, and returns the instantiated grid component.</p>
  3816. * <p>Note: since the code above is <i>generated</i> by a server script, the <code>baseParams</code> for
  3817. * the Store, the metadata to allow generation of the Record layout, and the ColumnModel
  3818. * can all be generated into the code since these are all known on the server.</p>
  3819. *
  3820. * @xtype container
  3821. */
  3822. Ext.Container = Ext.extend(Ext.BoxComponent, {
  3823. /**
  3824. * @cfg {Boolean} monitorResize
  3825. * True to automatically monitor window resize events to handle anything that is sensitive to the current size
  3826. * of the viewport. This value is typically managed by the chosen <code>{@link #layout}</code> and should not need
  3827. * to be set manually.
  3828. */
  3829. /**
  3830. * @cfg {String/Object} layout
  3831. * <p><b>*Important</b>: In order for child items to be correctly sized and
  3832. * positioned, typically a layout manager <b>must</b> be specified through
  3833. * the <code>layout</code> configuration option.</p>
  3834. * <br><p>The sizing and positioning of child {@link items} is the responsibility of
  3835. * the Container's layout manager which creates and manages the type of layout
  3836. * you have in mind. For example:</p><pre><code>
  3837. new Ext.Window({
  3838. width:300, height: 300,
  3839. layout: 'fit', // explicitly set layout manager: override the default (layout:'auto')
  3840. items: [{
  3841. title: 'Panel inside a Window'
  3842. }]
  3843. }).show();
  3844. * </code></pre>
  3845. * <p>If the {@link #layout} configuration is not explicitly specified for
  3846. * a general purpose container (e.g. Container or Panel) the
  3847. * {@link Ext.layout.ContainerLayout default layout manager} will be used
  3848. * which does nothing but render child components sequentially into the
  3849. * Container (no sizing or positioning will be performed in this situation).
  3850. * Some container classes implicitly specify a default layout
  3851. * (e.g. FormPanel specifies <code>layout:'form'</code>). Other specific
  3852. * purpose classes internally specify/manage their internal layout (e.g.
  3853. * GridPanel, TabPanel, TreePanel, Toolbar, Menu, etc.).</p>
  3854. * <br><p><b><code>layout</code></b> may be specified as either as an Object or
  3855. * as a String:</p><div><ul class="mdetail-params">
  3856. *
  3857. * <li><u>Specify as an Object</u></li>
  3858. * <div><ul class="mdetail-params">
  3859. * <li>Example usage:</li>
  3860. <pre><code>
  3861. layout: {
  3862. type: 'vbox',
  3863. padding: '5',
  3864. align: 'left'
  3865. }
  3866. </code></pre>
  3867. *
  3868. * <li><code><b>type</b></code></li>
  3869. * <br/><p>The layout type to be used for this container. If not specified,
  3870. * a default {@link Ext.layout.ContainerLayout} will be created and used.</p>
  3871. * <br/><p>Valid layout <code>type</code> values are:</p>
  3872. * <div class="sub-desc"><ul class="mdetail-params">
  3873. * <li><code><b>{@link Ext.layout.AbsoluteLayout absolute}</b></code></li>
  3874. * <li><code><b>{@link Ext.layout.AccordionLayout accordion}</b></code></li>
  3875. * <li><code><b>{@link Ext.layout.AnchorLayout anchor}</b></code></li>
  3876. * <li><code><b>{@link Ext.layout.ContainerLayout auto}</b></code> &nbsp;&nbsp;&nbsp; <b>Default</b></li>
  3877. * <li><code><b>{@link Ext.layout.BorderLayout border}</b></code></li>
  3878. * <li><code><b>{@link Ext.layout.CardLayout card}</b></code></li>
  3879. * <li><code><b>{@link Ext.layout.ColumnLayout column}</b></code></li>
  3880. * <li><code><b>{@link Ext.layout.FitLayout fit}</b></code></li>
  3881. * <li><code><b>{@link Ext.layout.FormLayout form}</b></code></li>
  3882. * <li><code><b>{@link Ext.layout.HBoxLayout hbox}</b></code></li>
  3883. * <li><code><b>{@link Ext.layout.MenuLayout menu}</b></code></li>
  3884. * <li><code><b>{@link Ext.layout.TableLayout table}</b></code></li>
  3885. * <li><code><b>{@link Ext.layout.ToolbarLayout toolbar}</b></code></li>
  3886. * <li><code><b>{@link Ext.layout.VBoxLayout vbox}</b></code></li>
  3887. * </ul></div>
  3888. *
  3889. * <li>Layout specific configuration properties</li>
  3890. * <br/><p>Additional layout specific configuration properties may also be
  3891. * specified. For complete details regarding the valid config options for
  3892. * each layout type, see the layout class corresponding to the <code>type</code>
  3893. * specified.</p>
  3894. *
  3895. * </ul></div>
  3896. *
  3897. * <li><u>Specify as a String</u></li>
  3898. * <div><ul class="mdetail-params">
  3899. * <li>Example usage:</li>
  3900. <pre><code>
  3901. layout: 'vbox',
  3902. layoutConfig: {
  3903. padding: '5',
  3904. align: 'left'
  3905. }
  3906. </code></pre>
  3907. * <li><code><b>layout</b></code></li>
  3908. * <br/><p>The layout <code>type</code> to be used for this container (see list
  3909. * of valid layout type values above).</p><br/>
  3910. * <li><code><b>{@link #layoutConfig}</b></code></li>
  3911. * <br/><p>Additional layout specific configuration properties. For complete
  3912. * details regarding the valid config options for each layout type, see the
  3913. * layout class corresponding to the <code>layout</code> specified.</p>
  3914. * </ul></div></ul></div>
  3915. */
  3916. /**
  3917. * @cfg {Object} layoutConfig
  3918. * This is a config object containing properties specific to the chosen
  3919. * <b><code>{@link #layout}</code></b> if <b><code>{@link #layout}</code></b>
  3920. * has been specified as a <i>string</i>.</p>
  3921. */
  3922. /**
  3923. * @cfg {Boolean/Number} bufferResize
  3924. * When set to true (50 milliseconds) or a number of milliseconds, the layout assigned for this container will buffer
  3925. * the frequency it calculates and does a re-layout of components. This is useful for heavy containers or containers
  3926. * with a large quantity of sub-components for which frequent layout calls would be expensive. Defaults to <code>50</code>.
  3927. */
  3928. bufferResize: 50,
  3929. /**
  3930. * @cfg {String/Number} activeItem
  3931. * A string component id or the numeric index of the component that should be initially activated within the
  3932. * container's layout on render. For example, activeItem: 'item-1' or activeItem: 0 (index 0 = the first
  3933. * item in the container's collection). activeItem only applies to layout styles that can display
  3934. * items one at a time (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout} and
  3935. * {@link Ext.layout.FitLayout}). Related to {@link Ext.layout.ContainerLayout#activeItem}.
  3936. */
  3937. /**
  3938. * @cfg {Object/Array} items
  3939. * <pre><b>** IMPORTANT</b>: be sure to <b>{@link #layout specify a <code>layout</code>} if needed ! **</b></pre>
  3940. * <p>A single item, or an array of child Components to be added to this container,
  3941. * for example:</p>
  3942. * <pre><code>
  3943. // specifying a single item
  3944. items: {...},
  3945. layout: 'fit', // specify a layout!
  3946. // specifying multiple items
  3947. items: [{...}, {...}],
  3948. layout: 'anchor', // specify a layout!
  3949. * </code></pre>
  3950. * <p>Each item may be:</p>
  3951. * <div><ul class="mdetail-params">
  3952. * <li>any type of object based on {@link Ext.Component}</li>
  3953. * <li>a fully instanciated object or</li>
  3954. * <li>an object literal that:</li>
  3955. * <div><ul class="mdetail-params">
  3956. * <li>has a specified <code>{@link Ext.Component#xtype xtype}</code></li>
  3957. * <li>the {@link Ext.Component#xtype} specified is associated with the Component
  3958. * desired and should be chosen from one of the available xtypes as listed
  3959. * in {@link Ext.Component}.</li>
  3960. * <li>If an <code>{@link Ext.Component#xtype xtype}</code> is not explicitly
  3961. * specified, the {@link #defaultType} for that Container is used.</li>
  3962. * <li>will be "lazily instanciated", avoiding the overhead of constructing a fully
  3963. * instanciated Component object</li>
  3964. * </ul></div></ul></div>
  3965. * <p><b>Notes</b>:</p>
  3966. * <div><ul class="mdetail-params">
  3967. * <li>Ext uses lazy rendering. Child Components will only be rendered
  3968. * should it become necessary. Items are automatically laid out when they are first
  3969. * shown (no sizing is done while hidden), or in response to a {@link #doLayout} call.</li>
  3970. * <li>Do not specify <code>{@link Ext.Panel#contentEl contentEl}</code>/
  3971. * <code>{@link Ext.Panel#html html}</code> with <code>items</code>.</li>
  3972. * </ul></div>
  3973. */
  3974. /**
  3975. * @cfg {Object|Function} defaults
  3976. * <p>This option is a means of applying default settings to all added items whether added through the {@link #items}
  3977. * config or via the {@link #add} or {@link #insert} methods.</p>
  3978. * <p>If an added item is a config object, and <b>not</b> an instantiated Component, then the default properties are
  3979. * unconditionally applied. If the added item <b>is</b> an instantiated Component, then the default properties are
  3980. * applied conditionally so as not to override existing properties in the item.</p>
  3981. * <p>If the defaults option is specified as a function, then the function will be called using this Container as the
  3982. * scope (<code>this</code> reference) and passing the added item as the first parameter. Any resulting object
  3983. * from that call is then applied to the item as default properties.</p>
  3984. * <p>For example, to automatically apply padding to the body of each of a set of
  3985. * contained {@link Ext.Panel} items, you could pass: <code>defaults: {bodyStyle:'padding:15px'}</code>.</p>
  3986. * <p>Usage:</p><pre><code>
  3987. defaults: { // defaults are applied to items, not the container
  3988. autoScroll:true
  3989. },
  3990. items: [
  3991. {
  3992. xtype: 'panel', // defaults <b>do not</b> have precedence over
  3993. id: 'panel1', // options in config objects, so the defaults
  3994. autoScroll: false // will not be applied here, panel1 will be autoScroll:false
  3995. },
  3996. new Ext.Panel({ // defaults <b>do</b> have precedence over options
  3997. id: 'panel2', // options in components, so the defaults
  3998. autoScroll: false // will be applied here, panel2 will be autoScroll:true.
  3999. })
  4000. ]
  4001. * </code></pre>
  4002. */
  4003. /** @cfg {Boolean} autoDestroy
  4004. * If true the container will automatically destroy any contained component that is removed from it, else
  4005. * destruction must be handled manually (defaults to true).
  4006. */
  4007. autoDestroy : true,
  4008. /** @cfg {Boolean} forceLayout
  4009. * If true the container will force a layout initially even if hidden or collapsed. This option
  4010. * is useful for forcing forms to render in collapsed or hidden containers. (defaults to false).
  4011. */
  4012. forceLayout: false,
  4013. /** @cfg {Boolean} hideBorders
  4014. * True to hide the borders of each contained component, false to defer to the component's existing
  4015. * border settings (defaults to false).
  4016. */
  4017. /** @cfg {String} defaultType
  4018. * <p>The default {@link Ext.Component xtype} of child Components to create in this Container when
  4019. * a child item is specified as a raw configuration object, rather than as an instantiated Component.</p>
  4020. * <p>Defaults to <code>'panel'</code>, except {@link Ext.menu.Menu} which defaults to <code>'menuitem'</code>,
  4021. * and {@link Ext.Toolbar} and {@link Ext.ButtonGroup} which default to <code>'button'</code>.</p>
  4022. */
  4023. defaultType : 'panel',
  4024. /** @cfg {String} resizeEvent
  4025. * The event to listen to for resizing in layouts. Defaults to <code>'resize'</code>.
  4026. */
  4027. resizeEvent: 'resize',
  4028. /**
  4029. * @cfg {Array} bubbleEvents
  4030. * <p>An array of events that, when fired, should be bubbled to any parent container.
  4031. * See {@link Ext.util.Observable#enableBubble}.
  4032. * Defaults to <code>['add', 'remove']</code>.
  4033. */
  4034. bubbleEvents: ['add', 'remove'],
  4035. // private
  4036. initComponent : function(){
  4037. Ext.Container.superclass.initComponent.call(this);
  4038. this.addEvents(
  4039. /**
  4040. * @event afterlayout
  4041. * Fires when the components in this container are arranged by the associated layout manager.
  4042. * @param {Ext.Container} this
  4043. * @param {ContainerLayout} layout The ContainerLayout implementation for this container
  4044. */
  4045. 'afterlayout',
  4046. /**
  4047. * @event beforeadd
  4048. * Fires before any {@link Ext.Component} is added or inserted into the container.
  4049. * A handler can return false to cancel the add.
  4050. * @param {Ext.Container} this
  4051. * @param {Ext.Component} component The component being added
  4052. * @param {Number} index The index at which the component will be added to the container's items collection
  4053. */
  4054. 'beforeadd',
  4055. /**
  4056. * @event beforeremove
  4057. * Fires before any {@link Ext.Component} is removed from the container. A handler can return
  4058. * false to cancel the remove.
  4059. * @param {Ext.Container} this
  4060. * @param {Ext.Component} component The component being removed
  4061. */
  4062. 'beforeremove',
  4063. /**
  4064. * @event add
  4065. * @bubbles
  4066. * Fires after any {@link Ext.Component} is added or inserted into the container.
  4067. * @param {Ext.Container} this
  4068. * @param {Ext.Component} component The component that was added
  4069. * @param {Number} index The index at which the component was added to the container's items collection
  4070. */
  4071. 'add',
  4072. /**
  4073. * @event remove
  4074. * @bubbles
  4075. * Fires after any {@link Ext.Component} is removed from the container.
  4076. * @param {Ext.Container} this
  4077. * @param {Ext.Component} component The component that was removed
  4078. */
  4079. 'remove'
  4080. );
  4081. /**
  4082. * The collection of components in this container as a {@link Ext.util.MixedCollection}
  4083. * @type MixedCollection
  4084. * @property items
  4085. */
  4086. var items = this.items;
  4087. if(items){
  4088. delete this.items;
  4089. this.add(items);
  4090. }
  4091. },
  4092. // private
  4093. initItems : function(){
  4094. if(!this.items){
  4095. this.items = new Ext.util.MixedCollection(false, this.getComponentId);
  4096. this.getLayout(); // initialize the layout
  4097. }
  4098. },
  4099. // private
  4100. setLayout : function(layout){
  4101. if(this.layout && this.layout != layout){
  4102. this.layout.setContainer(null);
  4103. }
  4104. this.layout = layout;
  4105. this.initItems();
  4106. layout.setContainer(this);
  4107. },
  4108. afterRender: function(){
  4109. // Render this Container, this should be done before setLayout is called which
  4110. // will hook onResize
  4111. Ext.Container.superclass.afterRender.call(this);
  4112. if(!this.layout){
  4113. this.layout = 'auto';
  4114. }
  4115. if(Ext.isObject(this.layout) && !this.layout.layout){
  4116. this.layoutConfig = this.layout;
  4117. this.layout = this.layoutConfig.type;
  4118. }
  4119. if(Ext.isString(this.layout)){
  4120. this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig);
  4121. }
  4122. this.setLayout(this.layout);
  4123. // If a CardLayout, the active item set
  4124. if(this.activeItem !== undefined && this.layout.setActiveItem){
  4125. var item = this.activeItem;
  4126. delete this.activeItem;
  4127. this.layout.setActiveItem(item);
  4128. }
  4129. // If we have no ownerCt, render and size all children
  4130. if(!this.ownerCt){
  4131. this.doLayout(false, true);
  4132. }
  4133. // This is a manually configured flag set by users in conjunction with renderTo.
  4134. // Not to be confused with the flag by the same name used in Layouts.
  4135. if(this.monitorResize === true){
  4136. Ext.EventManager.onWindowResize(this.doLayout, this, [false]);
  4137. }
  4138. },
  4139. /**
  4140. * <p>Returns the Element to be used to contain the child Components of this Container.</p>
  4141. * <p>An implementation is provided which returns the Container's {@link #getEl Element}, but
  4142. * if there is a more complex structure to a Container, this may be overridden to return
  4143. * the element into which the {@link #layout layout} renders child Components.</p>
  4144. * @return {Ext.Element} The Element to render child Components into.
  4145. */
  4146. getLayoutTarget : function(){
  4147. return this.el;
  4148. },
  4149. // private - used as the key lookup function for the items collection
  4150. getComponentId : function(comp){
  4151. return comp.getItemId();
  4152. },
  4153. /**
  4154. * <p>Adds {@link Ext.Component Component}(s) to this Container.</p>
  4155. * <br><p><b>Description</b></u> :
  4156. * <div><ul class="mdetail-params">
  4157. * <li>Fires the {@link #beforeadd} event before adding</li>
  4158. * <li>The Container's {@link #defaults default config values} will be applied
  4159. * accordingly (see <code>{@link #defaults}</code> for details).</li>
  4160. * <li>Fires the {@link #add} event after the component has been added.</li>
  4161. * </ul></div>
  4162. * <br><p><b>Notes</b></u> :
  4163. * <div><ul class="mdetail-params">
  4164. * <li>If the Container is <i>already rendered</i> when <code>add</code>
  4165. * is called, you may need to call {@link #doLayout} to refresh the view which causes
  4166. * any unrendered child Components to be rendered. This is required so that you can
  4167. * <code>add</code> multiple child components if needed while only refreshing the layout
  4168. * once. For example:<pre><code>
  4169. var tb = new {@link Ext.Toolbar}();
  4170. tb.render(document.body); // toolbar is rendered
  4171. tb.add({text:'Button 1'}); // add multiple items ({@link #defaultType} for {@link Ext.Toolbar Toolbar} is 'button')
  4172. tb.add({text:'Button 2'});
  4173. tb.{@link #doLayout}(); // refresh the layout
  4174. * </code></pre></li>
  4175. * <li><i>Warning:</i> Containers directly managed by the BorderLayout layout manager
  4176. * may not be removed or added. See the Notes for {@link Ext.layout.BorderLayout BorderLayout}
  4177. * for more details.</li>
  4178. * </ul></div>
  4179. * @param {...Object/Array} component
  4180. * <p>Either one or more Components to add or an Array of Components to add. See
  4181. * <code>{@link #items}</code> for additional information.</p>
  4182. * @return {Ext.Component/Array} The Components that were added.
  4183. */
  4184. add : function(comp){
  4185. this.initItems();
  4186. var args = arguments.length > 1;
  4187. if(args || Ext.isArray(comp)){
  4188. var result = [];
  4189. Ext.each(args ? arguments : comp, function(c){
  4190. result.push(this.add(c));
  4191. }, this);
  4192. return result;
  4193. }
  4194. var c = this.lookupComponent(this.applyDefaults(comp));
  4195. var index = this.items.length;
  4196. if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
  4197. this.items.add(c);
  4198. // *onAdded
  4199. c.onAdded(this, index);
  4200. this.onAdd(c);
  4201. this.fireEvent('add', this, c, index);
  4202. }
  4203. return c;
  4204. },
  4205. onAdd : function(c){
  4206. // Empty template method
  4207. },
  4208. // private
  4209. onAdded : function(container, pos) {
  4210. //overridden here so we can cascade down, not worth creating a template method.
  4211. this.ownerCt = container;
  4212. this.initRef();
  4213. //initialize references for child items
  4214. this.cascade(function(c){
  4215. c.initRef();
  4216. });
  4217. this.fireEvent('added', this, container, pos);
  4218. },
  4219. /**
  4220. * Inserts a Component into this Container at a specified index. Fires the
  4221. * {@link #beforeadd} event before inserting, then fires the {@link #add} event after the
  4222. * Component has been inserted.
  4223. * @param {Number} index The index at which the Component will be inserted
  4224. * into the Container's items collection
  4225. * @param {Ext.Component} component The child Component to insert.<br><br>
  4226. * Ext uses lazy rendering, and will only render the inserted Component should
  4227. * it become necessary.<br><br>
  4228. * A Component config object may be passed in order to avoid the overhead of
  4229. * constructing a real Component object if lazy rendering might mean that the
  4230. * inserted Component will not be rendered immediately. To take advantage of
  4231. * this 'lazy instantiation', set the {@link Ext.Component#xtype} config
  4232. * property to the registered type of the Component wanted.<br><br>
  4233. * For a list of all available xtypes, see {@link Ext.Component}.
  4234. * @return {Ext.Component} component The Component (or config object) that was
  4235. * inserted with the Container's default config values applied.
  4236. */
  4237. insert : function(index, comp) {
  4238. var args = arguments,
  4239. length = args.length,
  4240. result = [],
  4241. i, c;
  4242. this.initItems();
  4243. if (length > 2) {
  4244. for (i = length - 1; i >= 1; --i) {
  4245. result.push(this.insert(index, args[i]));
  4246. }
  4247. return result;
  4248. }
  4249. c = this.lookupComponent(this.applyDefaults(comp));
  4250. index = Math.min(index, this.items.length);
  4251. if (this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false) {
  4252. if (c.ownerCt == this) {
  4253. this.items.remove(c);
  4254. }
  4255. this.items.insert(index, c);
  4256. c.onAdded(this, index);
  4257. this.onAdd(c);
  4258. this.fireEvent('add', this, c, index);
  4259. }
  4260. return c;
  4261. },
  4262. // private
  4263. applyDefaults : function(c){
  4264. var d = this.defaults;
  4265. if(d){
  4266. if(Ext.isFunction(d)){
  4267. d = d.call(this, c);
  4268. }
  4269. if(Ext.isString(c)){
  4270. c = Ext.ComponentMgr.get(c);
  4271. Ext.apply(c, d);
  4272. }else if(!c.events){
  4273. Ext.applyIf(c.isAction ? c.initialConfig : c, d);
  4274. }else{
  4275. Ext.apply(c, d);
  4276. }
  4277. }
  4278. return c;
  4279. },
  4280. // private
  4281. onBeforeAdd : function(item){
  4282. if(item.ownerCt){
  4283. item.ownerCt.remove(item, false);
  4284. }
  4285. if(this.hideBorders === true){
  4286. item.border = (item.border === true);
  4287. }
  4288. },
  4289. /**
  4290. * Removes a component from this container. Fires the {@link #beforeremove} event before removing, then fires
  4291. * the {@link #remove} event after the component has been removed.
  4292. * @param {Component/String} component The component reference or id to remove.
  4293. * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
  4294. * Defaults to the value of this Container's {@link #autoDestroy} config.
  4295. * @return {Ext.Component} component The Component that was removed.
  4296. */
  4297. remove : function(comp, autoDestroy){
  4298. this.initItems();
  4299. var c = this.getComponent(comp);
  4300. if(c && this.fireEvent('beforeremove', this, c) !== false){
  4301. this.doRemove(c, autoDestroy);
  4302. this.fireEvent('remove', this, c);
  4303. }
  4304. return c;
  4305. },
  4306. onRemove: function(c){
  4307. // Empty template method
  4308. },
  4309. // private
  4310. doRemove: function(c, autoDestroy){
  4311. var l = this.layout,
  4312. hasLayout = l && this.rendered;
  4313. if(hasLayout){
  4314. l.onRemove(c);
  4315. }
  4316. this.items.remove(c);
  4317. c.onRemoved();
  4318. this.onRemove(c);
  4319. if(autoDestroy === true || (autoDestroy !== false && this.autoDestroy)){
  4320. c.destroy();
  4321. }
  4322. if(hasLayout){
  4323. l.afterRemove(c);
  4324. }
  4325. },
  4326. /**
  4327. * Removes all components from this container.
  4328. * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
  4329. * Defaults to the value of this Container's {@link #autoDestroy} config.
  4330. * @return {Array} Array of the destroyed components
  4331. */
  4332. removeAll: function(autoDestroy){
  4333. this.initItems();
  4334. var item, rem = [], items = [];
  4335. this.items.each(function(i){
  4336. rem.push(i);
  4337. });
  4338. for (var i = 0, len = rem.length; i < len; ++i){
  4339. item = rem[i];
  4340. this.remove(item, autoDestroy);
  4341. if(item.ownerCt !== this){
  4342. items.push(item);
  4343. }
  4344. }
  4345. return items;
  4346. },
  4347. /**
  4348. * Examines this container's <code>{@link #items}</code> <b>property</b>
  4349. * and gets a direct child component of this container.
  4350. * @param {String/Number} comp This parameter may be any of the following:
  4351. * <div><ul class="mdetail-params">
  4352. * <li>a <b><code>String</code></b> : representing the <code>{@link Ext.Component#itemId itemId}</code>
  4353. * or <code>{@link Ext.Component#id id}</code> of the child component </li>
  4354. * <li>a <b><code>Number</code></b> : representing the position of the child component
  4355. * within the <code>{@link #items}</code> <b>property</b></li>
  4356. * </ul></div>
  4357. * <p>For additional information see {@link Ext.util.MixedCollection#get}.
  4358. * @return Ext.Component The component (if found).
  4359. */
  4360. getComponent : function(comp){
  4361. if(Ext.isObject(comp)){
  4362. comp = comp.getItemId();
  4363. }
  4364. return this.items.get(comp);
  4365. },
  4366. // private
  4367. lookupComponent : function(comp){
  4368. if(Ext.isString(comp)){
  4369. return Ext.ComponentMgr.get(comp);
  4370. }else if(!comp.events){
  4371. return this.createComponent(comp);
  4372. }
  4373. return comp;
  4374. },
  4375. // private
  4376. createComponent : function(config, defaultType){
  4377. if (config.render) {
  4378. return config;
  4379. }
  4380. // add in ownerCt at creation time but then immediately
  4381. // remove so that onBeforeAdd can handle it
  4382. var c = Ext.create(Ext.apply({
  4383. ownerCt: this
  4384. }, config), defaultType || this.defaultType);
  4385. delete c.initialConfig.ownerCt;
  4386. delete c.ownerCt;
  4387. return c;
  4388. },
  4389. /**
  4390. * @private
  4391. * We can only lay out if there is a view area in which to layout.
  4392. * display:none on the layout target, *or any of its parent elements* will mean it has no view area.
  4393. */
  4394. canLayout : function() {
  4395. var el = this.getVisibilityEl();
  4396. return el && el.dom && !el.isStyle("display", "none");
  4397. },
  4398. /**
  4399. * Force this container's layout to be recalculated. A call to this function is required after adding a new component
  4400. * to an already rendered container, or possibly after changing sizing/position properties of child components.
  4401. * @param {Boolean} shallow (optional) True to only calc the layout of this component, and let child components auto
  4402. * calc layouts as required (defaults to false, which calls doLayout recursively for each subcontainer)
  4403. * @param {Boolean} force (optional) True to force a layout to occur, even if the item is hidden.
  4404. * @return {Ext.Container} this
  4405. */
  4406. doLayout : function(shallow, force){
  4407. var rendered = this.rendered,
  4408. forceLayout = force || this.forceLayout;
  4409. if(this.collapsed || !this.canLayout()){
  4410. this.deferLayout = this.deferLayout || !shallow;
  4411. if(!forceLayout){
  4412. return;
  4413. }
  4414. shallow = shallow && !this.deferLayout;
  4415. } else {
  4416. delete this.deferLayout;
  4417. }
  4418. if(rendered && this.layout){
  4419. this.layout.layout();
  4420. }
  4421. if(shallow !== true && this.items){
  4422. var cs = this.items.items;
  4423. for(var i = 0, len = cs.length; i < len; i++){
  4424. var c = cs[i];
  4425. if(c.doLayout){
  4426. c.doLayout(false, forceLayout);
  4427. }
  4428. }
  4429. }
  4430. if(rendered){
  4431. this.onLayout(shallow, forceLayout);
  4432. }
  4433. // Initial layout completed
  4434. this.hasLayout = true;
  4435. delete this.forceLayout;
  4436. },
  4437. onLayout : Ext.emptyFn,
  4438. // private
  4439. shouldBufferLayout: function(){
  4440. /*
  4441. * Returns true if the container should buffer a layout.
  4442. * This is true only if the container has previously been laid out
  4443. * and has a parent container that is pending a layout.
  4444. */
  4445. var hl = this.hasLayout;
  4446. if(this.ownerCt){
  4447. // Only ever buffer if we've laid out the first time and we have one pending.
  4448. return hl ? !this.hasLayoutPending() : false;
  4449. }
  4450. // Never buffer initial layout
  4451. return hl;
  4452. },
  4453. // private
  4454. hasLayoutPending: function(){
  4455. // Traverse hierarchy to see if any parent container has a pending layout.
  4456. var pending = false;
  4457. this.ownerCt.bubble(function(c){
  4458. if(c.layoutPending){
  4459. pending = true;
  4460. return false;
  4461. }
  4462. });
  4463. return pending;
  4464. },
  4465. onShow : function(){
  4466. // removes css classes that were added to hide
  4467. Ext.Container.superclass.onShow.call(this);
  4468. // If we were sized during the time we were hidden, layout.
  4469. if(Ext.isDefined(this.deferLayout)){
  4470. delete this.deferLayout;
  4471. this.doLayout(true);
  4472. }
  4473. },
  4474. /**
  4475. * Returns the layout currently in use by the container. If the container does not currently have a layout
  4476. * set, a default {@link Ext.layout.ContainerLayout} will be created and set as the container's layout.
  4477. * @return {ContainerLayout} layout The container's layout
  4478. */
  4479. getLayout : function(){
  4480. if(!this.layout){
  4481. var layout = new Ext.layout.AutoLayout(this.layoutConfig);
  4482. this.setLayout(layout);
  4483. }
  4484. return this.layout;
  4485. },
  4486. // private
  4487. beforeDestroy : function(){
  4488. var c;
  4489. if(this.items){
  4490. while(c = this.items.first()){
  4491. this.doRemove(c, true);
  4492. }
  4493. }
  4494. if(this.monitorResize){
  4495. Ext.EventManager.removeResizeListener(this.doLayout, this);
  4496. }
  4497. Ext.destroy(this.layout);
  4498. Ext.Container.superclass.beforeDestroy.call(this);
  4499. },
  4500. /**
  4501. * Cascades down the component/container heirarchy from this component (called first), calling the specified function with
  4502. * each component. The scope (<i>this</i>) of
  4503. * function call will be the scope provided or the current component. The arguments to the function
  4504. * will be the args provided or the current component. If the function returns false at any point,
  4505. * the cascade is stopped on that branch.
  4506. * @param {Function} fn The function to call
  4507. * @param {Object} scope (optional) The scope of the function (defaults to current component)
  4508. * @param {Array} args (optional) The args to call the function with (defaults to passing the current component)
  4509. * @return {Ext.Container} this
  4510. */
  4511. cascade : function(fn, scope, args){
  4512. if(fn.apply(scope || this, args || [this]) !== false){
  4513. if(this.items){
  4514. var cs = this.items.items;
  4515. for(var i = 0, len = cs.length; i < len; i++){
  4516. if(cs[i].cascade){
  4517. cs[i].cascade(fn, scope, args);
  4518. }else{
  4519. fn.apply(scope || cs[i], args || [cs[i]]);
  4520. }
  4521. }
  4522. }
  4523. }
  4524. return this;
  4525. },
  4526. /**
  4527. * Find a component under this container at any level by id
  4528. * @param {String} id
  4529. * @deprecated Fairly useless method, since you can just use Ext.getCmp. Should be removed for 4.0
  4530. * If you need to test if an id belongs to a container, you can use getCmp and findParent*.
  4531. * @return Ext.Component
  4532. */
  4533. findById : function(id){
  4534. var m = null,
  4535. ct = this;
  4536. this.cascade(function(c){
  4537. if(ct != c && c.id === id){
  4538. m = c;
  4539. return false;
  4540. }
  4541. });
  4542. return m;
  4543. },
  4544. /**
  4545. * Find a component under this container at any level by xtype or class
  4546. * @param {String/Class} xtype The xtype string for a component, or the class of the component directly
  4547. * @param {Boolean} shallow (optional) False to check whether this Component is descended from the xtype (this is
  4548. * the default), or true to check whether this Component is directly of the specified xtype.
  4549. * @return {Array} Array of Ext.Components
  4550. */
  4551. findByType : function(xtype, shallow){
  4552. return this.findBy(function(c){
  4553. return c.isXType(xtype, shallow);
  4554. });
  4555. },
  4556. /**
  4557. * Find a component under this container at any level by property
  4558. * @param {String} prop
  4559. * @param {String} value
  4560. * @return {Array} Array of Ext.Components
  4561. */
  4562. find : function(prop, value){
  4563. return this.findBy(function(c){
  4564. return c[prop] === value;
  4565. });
  4566. },
  4567. /**
  4568. * Find a component under this container at any level by a custom function. If the passed function returns
  4569. * true, the component will be included in the results. The passed function is called with the arguments (component, this container).
  4570. * @param {Function} fn The function to call
  4571. * @param {Object} scope (optional)
  4572. * @return {Array} Array of Ext.Components
  4573. */
  4574. findBy : function(fn, scope){
  4575. var m = [], ct = this;
  4576. this.cascade(function(c){
  4577. if(ct != c && fn.call(scope || c, c, ct) === true){
  4578. m.push(c);
  4579. }
  4580. });
  4581. return m;
  4582. },
  4583. /**
  4584. * Get a component contained by this container (alias for items.get(key))
  4585. * @param {String/Number} key The index or id of the component
  4586. * @deprecated Should be removed in 4.0, since getComponent does the same thing.
  4587. * @return {Ext.Component} Ext.Component
  4588. */
  4589. get : function(key){
  4590. return this.getComponent(key);
  4591. }
  4592. });
  4593. Ext.Container.LAYOUTS = {};
  4594. Ext.reg('container', Ext.Container);
  4595. /**
  4596. * @class Ext.layout.ContainerLayout
  4597. * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
  4598. * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
  4599. */
  4600. Ext.layout.ContainerLayout = Ext.extend(Object, {
  4601. /**
  4602. * @cfg {String} extraCls
  4603. * <p>An optional extra CSS class that will be added to the container. This can be useful for adding
  4604. * customized styles to the container or any of its children using standard CSS rules. See
  4605. * {@link Ext.Component}.{@link Ext.Component#ctCls ctCls} also.</p>
  4606. * <p><b>Note</b>: <tt>extraCls</tt> defaults to <tt>''</tt> except for the following classes
  4607. * which assign a value by default:
  4608. * <div class="mdetail-params"><ul>
  4609. * <li>{@link Ext.layout.AbsoluteLayout Absolute Layout} : <tt>'x-abs-layout-item'</tt></li>
  4610. * <li>{@link Ext.layout.Box Box Layout} : <tt>'x-box-item'</tt></li>
  4611. * <li>{@link Ext.layout.ColumnLayout Column Layout} : <tt>'x-column'</tt></li>
  4612. * </ul></div>
  4613. * To configure the above Classes with an extra CSS class append to the default. For example,
  4614. * for ColumnLayout:<pre><code>
  4615. * extraCls: 'x-column custom-class'
  4616. * </code></pre>
  4617. * </p>
  4618. */
  4619. /**
  4620. * @cfg {Boolean} renderHidden
  4621. * True to hide each contained item on render (defaults to false).
  4622. */
  4623. /**
  4624. * A reference to the {@link Ext.Component} that is active. For example, <pre><code>
  4625. * if(myPanel.layout.activeItem.id == 'item-1') { ... }
  4626. * </code></pre>
  4627. * <tt>activeItem</tt> only applies to layout styles that can display items one at a time
  4628. * (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout}
  4629. * and {@link Ext.layout.FitLayout}). Read-only. Related to {@link Ext.Container#activeItem}.
  4630. * @type {Ext.Component}
  4631. * @property activeItem
  4632. */
  4633. // private
  4634. monitorResize:false,
  4635. // private
  4636. activeItem : null,
  4637. constructor : function(config){
  4638. this.id = Ext.id(null, 'ext-layout-');
  4639. Ext.apply(this, config);
  4640. },
  4641. type: 'container',
  4642. /* Workaround for how IE measures autoWidth elements. It prefers bottom-up measurements
  4643. whereas other browser prefer top-down. We will hide all target child elements before we measure and
  4644. put them back to get an accurate measurement.
  4645. */
  4646. IEMeasureHack : function(target, viewFlag) {
  4647. var tChildren = target.dom.childNodes, tLen = tChildren.length, c, d = [], e, i, ret;
  4648. for (i = 0 ; i < tLen ; i++) {
  4649. c = tChildren[i];
  4650. e = Ext.get(c);
  4651. if (e) {
  4652. d[i] = e.getStyle('display');
  4653. e.setStyle({display: 'none'});
  4654. }
  4655. }
  4656. ret = target ? target.getViewSize(viewFlag) : {};
  4657. for (i = 0 ; i < tLen ; i++) {
  4658. c = tChildren[i];
  4659. e = Ext.get(c);
  4660. if (e) {
  4661. e.setStyle({display: d[i]});
  4662. }
  4663. }
  4664. return ret;
  4665. },
  4666. // Placeholder for the derived layouts
  4667. getLayoutTargetSize : Ext.EmptyFn,
  4668. // private
  4669. layout : function(){
  4670. var ct = this.container, target = ct.getLayoutTarget();
  4671. if(!(this.hasLayout || Ext.isEmpty(this.targetCls))){
  4672. target.addClass(this.targetCls);
  4673. }
  4674. this.onLayout(ct, target);
  4675. ct.fireEvent('afterlayout', ct, this);
  4676. },
  4677. // private
  4678. onLayout : function(ct, target){
  4679. this.renderAll(ct, target);
  4680. },
  4681. // private
  4682. isValidParent : function(c, target){
  4683. return target && c.getPositionEl().dom.parentNode == (target.dom || target);
  4684. },
  4685. // private
  4686. renderAll : function(ct, target){
  4687. var items = ct.items.items, i, c, len = items.length;
  4688. for(i = 0; i < len; i++) {
  4689. c = items[i];
  4690. if(c && (!c.rendered || !this.isValidParent(c, target))){
  4691. this.renderItem(c, i, target);
  4692. }
  4693. }
  4694. },
  4695. /**
  4696. * @private
  4697. * Renders the given Component into the target Element. If the Component is already rendered,
  4698. * it is moved to the provided target instead.
  4699. * @param {Ext.Component} c The Component to render
  4700. * @param {Number} position The position within the target to render the item to
  4701. * @param {Ext.Element} target The target Element
  4702. */
  4703. renderItem : function(c, position, target){
  4704. if (c) {
  4705. if (!c.rendered) {
  4706. c.render(target, position);
  4707. this.configureItem(c);
  4708. } else if (!this.isValidParent(c, target)) {
  4709. if (Ext.isNumber(position)) {
  4710. position = target.dom.childNodes[position];
  4711. }
  4712. target.dom.insertBefore(c.getPositionEl().dom, position || null);
  4713. c.container = target;
  4714. this.configureItem(c);
  4715. }
  4716. }
  4717. },
  4718. // private.
  4719. // Get all rendered items to lay out.
  4720. getRenderedItems: function(ct){
  4721. var t = ct.getLayoutTarget(), cti = ct.items.items, len = cti.length, i, c, items = [];
  4722. for (i = 0; i < len; i++) {
  4723. if((c = cti[i]).rendered && this.isValidParent(c, t) && c.shouldLayout !== false){
  4724. items.push(c);
  4725. }
  4726. };
  4727. return items;
  4728. },
  4729. /**
  4730. * @private
  4731. * Applies extraCls and hides the item if renderHidden is true
  4732. */
  4733. configureItem: function(c){
  4734. if (this.extraCls) {
  4735. var t = c.getPositionEl ? c.getPositionEl() : c;
  4736. t.addClass(this.extraCls);
  4737. }
  4738. // If we are forcing a layout, do so *before* we hide so elements have height/width
  4739. if (c.doLayout && this.forceLayout) {
  4740. c.doLayout();
  4741. }
  4742. if (this.renderHidden && c != this.activeItem) {
  4743. c.hide();
  4744. }
  4745. },
  4746. onRemove: function(c){
  4747. if(this.activeItem == c){
  4748. delete this.activeItem;
  4749. }
  4750. if(c.rendered && this.extraCls){
  4751. var t = c.getPositionEl ? c.getPositionEl() : c;
  4752. t.removeClass(this.extraCls);
  4753. }
  4754. },
  4755. afterRemove: function(c){
  4756. if(c.removeRestore){
  4757. c.removeMode = 'container';
  4758. delete c.removeRestore;
  4759. }
  4760. },
  4761. // private
  4762. onResize: function(){
  4763. var ct = this.container,
  4764. b;
  4765. if(ct.collapsed){
  4766. return;
  4767. }
  4768. if(b = ct.bufferResize && ct.shouldBufferLayout()){
  4769. if(!this.resizeTask){
  4770. this.resizeTask = new Ext.util.DelayedTask(this.runLayout, this);
  4771. this.resizeBuffer = Ext.isNumber(b) ? b : 50;
  4772. }
  4773. ct.layoutPending = true;
  4774. this.resizeTask.delay(this.resizeBuffer);
  4775. }else{
  4776. this.runLayout();
  4777. }
  4778. },
  4779. runLayout: function(){
  4780. var ct = this.container;
  4781. this.layout();
  4782. ct.onLayout();
  4783. delete ct.layoutPending;
  4784. },
  4785. // private
  4786. setContainer : function(ct){
  4787. /*
  4788. * This monitorResize flag will be renamed soon as to avoid confusion
  4789. * with the Container version which hooks onWindowResize to doLayout
  4790. *
  4791. * monitorResize flag in this context attaches the resize event between
  4792. * a container and it's layout
  4793. */
  4794. if(this.monitorResize && ct != this.container){
  4795. var old = this.container;
  4796. if(old){
  4797. old.un(old.resizeEvent, this.onResize, this);
  4798. }
  4799. if(ct){
  4800. ct.on(ct.resizeEvent, this.onResize, this);
  4801. }
  4802. }
  4803. this.container = ct;
  4804. },
  4805. /**
  4806. * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
  4807. * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
  4808. * @param {Number|String} v The encoded margins
  4809. * @return {Object} An object with margin sizes for top, right, bottom and left
  4810. */
  4811. parseMargins : function(v){
  4812. if (Ext.isNumber(v)) {
  4813. v = v.toString();
  4814. }
  4815. var ms = v.split(' '),
  4816. len = ms.length;
  4817. if (len == 1) {
  4818. ms[1] = ms[2] = ms[3] = ms[0];
  4819. } else if(len == 2) {
  4820. ms[2] = ms[0];
  4821. ms[3] = ms[1];
  4822. } else if(len == 3) {
  4823. ms[3] = ms[1];
  4824. }
  4825. return {
  4826. top :parseInt(ms[0], 10) || 0,
  4827. right :parseInt(ms[1], 10) || 0,
  4828. bottom:parseInt(ms[2], 10) || 0,
  4829. left :parseInt(ms[3], 10) || 0
  4830. };
  4831. },
  4832. /**
  4833. * The {@link Ext.Template Ext.Template} used by Field rendering layout classes (such as
  4834. * {@link Ext.layout.FormLayout}) to create the DOM structure of a fully wrapped,
  4835. * labeled and styled form Field. A default Template is supplied, but this may be
  4836. * overriden to create custom field structures. The template processes values returned from
  4837. * {@link Ext.layout.FormLayout#getTemplateArgs}.
  4838. * @property fieldTpl
  4839. * @type Ext.Template
  4840. */
  4841. fieldTpl: (function() {
  4842. var t = new Ext.Template(
  4843. '<div class="x-form-item {itemCls}" tabIndex="-1">',
  4844. '<label for="{id}" style="{labelStyle}" class="x-form-item-label">{label}{labelSeparator}</label>',
  4845. '<div class="x-form-element" id="x-form-el-{id}" style="{elementStyle}">',
  4846. '</div><div class="{clearCls}"></div>',
  4847. '</div>'
  4848. );
  4849. t.disableFormats = true;
  4850. return t.compile();
  4851. })(),
  4852. /*
  4853. * Destroys this layout. This is a template method that is empty by default, but should be implemented
  4854. * by subclasses that require explicit destruction to purge event handlers or remove DOM nodes.
  4855. * @protected
  4856. */
  4857. destroy : function(){
  4858. // Stop any buffered layout tasks
  4859. if(this.resizeTask && this.resizeTask.cancel){
  4860. this.resizeTask.cancel();
  4861. }
  4862. if(this.container) {
  4863. this.container.un(this.container.resizeEvent, this.onResize, this);
  4864. }
  4865. if(!Ext.isEmpty(this.targetCls)){
  4866. var target = this.container.getLayoutTarget();
  4867. if(target){
  4868. target.removeClass(this.targetCls);
  4869. }
  4870. }
  4871. }
  4872. });/**
  4873. * @class Ext.layout.AutoLayout
  4874. * <p>The AutoLayout is the default layout manager delegated by {@link Ext.Container} to
  4875. * render any child Components when no <tt>{@link Ext.Container#layout layout}</tt> is configured into
  4876. * a {@link Ext.Container Container}.</tt>. AutoLayout provides only a passthrough of any layout calls
  4877. * to any child containers.</p>
  4878. */
  4879. Ext.layout.AutoLayout = Ext.extend(Ext.layout.ContainerLayout, {
  4880. type: 'auto',
  4881. monitorResize: true,
  4882. onLayout : function(ct, target){
  4883. Ext.layout.AutoLayout.superclass.onLayout.call(this, ct, target);
  4884. var cs = this.getRenderedItems(ct), len = cs.length, i, c;
  4885. for(i = 0; i < len; i++){
  4886. c = cs[i];
  4887. if (c.doLayout){
  4888. // Shallow layout children
  4889. c.doLayout(true);
  4890. }
  4891. }
  4892. }
  4893. });
  4894. Ext.Container.LAYOUTS['auto'] = Ext.layout.AutoLayout;
  4895. /**
  4896. * @class Ext.layout.FitLayout
  4897. * @extends Ext.layout.ContainerLayout
  4898. * <p>This is a base class for layouts that contain <b>a single item</b> that automatically expands to fill the layout's
  4899. * container. This class is intended to be extended or created via the <tt>layout:'fit'</tt> {@link Ext.Container#layout}
  4900. * config, and should generally not need to be created directly via the new keyword.</p>
  4901. * <p>FitLayout does not have any direct config options (other than inherited ones). To fit a panel to a container
  4902. * using FitLayout, simply set layout:'fit' on the container and add a single panel to it. If the container has
  4903. * multiple panels, only the first one will be displayed. Example usage:</p>
  4904. * <pre><code>
  4905. var p = new Ext.Panel({
  4906. title: 'Fit Layout',
  4907. layout:'fit',
  4908. items: {
  4909. title: 'Inner Panel',
  4910. html: '&lt;p&gt;This is the inner panel content&lt;/p&gt;',
  4911. border: false
  4912. }
  4913. });
  4914. </code></pre>
  4915. */
  4916. Ext.layout.FitLayout = Ext.extend(Ext.layout.ContainerLayout, {
  4917. // private
  4918. monitorResize:true,
  4919. type: 'fit',
  4920. getLayoutTargetSize : function() {
  4921. var target = this.container.getLayoutTarget();
  4922. if (!target) {
  4923. return {};
  4924. }
  4925. // Style Sized (scrollbars not included)
  4926. return target.getStyleSize();
  4927. },
  4928. // private
  4929. onLayout : function(ct, target){
  4930. Ext.layout.FitLayout.superclass.onLayout.call(this, ct, target);
  4931. if(!ct.collapsed){
  4932. this.setItemSize(this.activeItem || ct.items.itemAt(0), this.getLayoutTargetSize());
  4933. }
  4934. },
  4935. // private
  4936. setItemSize : function(item, size){
  4937. if(item && size.height > 0){ // display none?
  4938. item.setSize(size);
  4939. }
  4940. }
  4941. });
  4942. Ext.Container.LAYOUTS['fit'] = Ext.layout.FitLayout;/**
  4943. * @class Ext.layout.CardLayout
  4944. * @extends Ext.layout.FitLayout
  4945. * <p>This layout manages multiple child Components, each fitted to the Container, where only a single child Component can be
  4946. * visible at any given time. This layout style is most commonly used for wizards, tab implementations, etc.
  4947. * This class is intended to be extended or created via the layout:'card' {@link Ext.Container#layout} config,
  4948. * and should generally not need to be created directly via the new keyword.</p>
  4949. * <p>The CardLayout's focal method is {@link #setActiveItem}. Since only one panel is displayed at a time,
  4950. * the only way to move from one Component to the next is by calling setActiveItem, passing the id or index of
  4951. * the next panel to display. The layout itself does not provide a user interface for handling this navigation,
  4952. * so that functionality must be provided by the developer.</p>
  4953. * <p>In the following example, a simplistic wizard setup is demonstrated. A button bar is added
  4954. * to the footer of the containing panel to provide navigation buttons. The buttons will be handled by a
  4955. * common navigation routine -- for this example, the implementation of that routine has been ommitted since
  4956. * it can be any type of custom logic. Note that other uses of a CardLayout (like a tab control) would require a
  4957. * completely different implementation. For serious implementations, a better approach would be to extend
  4958. * CardLayout to provide the custom functionality needed. Example usage:</p>
  4959. * <pre><code>
  4960. var navHandler = function(direction){
  4961. // This routine could contain business logic required to manage the navigation steps.
  4962. // It would call setActiveItem as needed, manage navigation button state, handle any
  4963. // branching logic that might be required, handle alternate actions like cancellation
  4964. // or finalization, etc. A complete wizard implementation could get pretty
  4965. // sophisticated depending on the complexity required, and should probably be
  4966. // done as a subclass of CardLayout in a real-world implementation.
  4967. };
  4968. var card = new Ext.Panel({
  4969. title: 'Example Wizard',
  4970. layout:'card',
  4971. activeItem: 0, // make sure the active item is set on the container config!
  4972. bodyStyle: 'padding:15px',
  4973. defaults: {
  4974. // applied to each contained panel
  4975. border:false
  4976. },
  4977. // just an example of one possible navigation scheme, using buttons
  4978. bbar: [
  4979. {
  4980. id: 'move-prev',
  4981. text: 'Back',
  4982. handler: navHandler.createDelegate(this, [-1]),
  4983. disabled: true
  4984. },
  4985. '->', // greedy spacer so that the buttons are aligned to each side
  4986. {
  4987. id: 'move-next',
  4988. text: 'Next',
  4989. handler: navHandler.createDelegate(this, [1])
  4990. }
  4991. ],
  4992. // the panels (or "cards") within the layout
  4993. items: [{
  4994. id: 'card-0',
  4995. html: '&lt;h1&gt;Welcome to the Wizard!&lt;/h1&gt;&lt;p&gt;Step 1 of 3&lt;/p&gt;'
  4996. },{
  4997. id: 'card-1',
  4998. html: '&lt;p&gt;Step 2 of 3&lt;/p&gt;'
  4999. },{
  5000. id: 'card-2',
  5001. html: '&lt;h1&gt;Congratulations!&lt;/h1&gt;&lt;p&gt;Step 3 of 3 - Complete&lt;/p&gt;'
  5002. }]
  5003. });
  5004. </code></pre>
  5005. */
  5006. Ext.layout.CardLayout = Ext.extend(Ext.layout.FitLayout, {
  5007. /**
  5008. * @cfg {Boolean} deferredRender
  5009. * True to render each contained item at the time it becomes active, false to render all contained items
  5010. * as soon as the layout is rendered (defaults to false). If there is a significant amount of content or
  5011. * a lot of heavy controls being rendered into panels that are not displayed by default, setting this to
  5012. * true might improve performance.
  5013. */
  5014. deferredRender : false,
  5015. /**
  5016. * @cfg {Boolean} layoutOnCardChange
  5017. * True to force a layout of the active item when the active card is changed. Defaults to false.
  5018. */
  5019. layoutOnCardChange : false,
  5020. /**
  5021. * @cfg {Boolean} renderHidden @hide
  5022. */
  5023. // private
  5024. renderHidden : true,
  5025. type: 'card',
  5026. /**
  5027. * Sets the active (visible) item in the layout.
  5028. * @param {String/Number} item The string component id or numeric index of the item to activate
  5029. */
  5030. setActiveItem : function(item){
  5031. var ai = this.activeItem,
  5032. ct = this.container;
  5033. item = ct.getComponent(item);
  5034. // Is this a valid, different card?
  5035. if(item && ai != item){
  5036. // Changing cards, hide the current one
  5037. if(ai){
  5038. ai.hide();
  5039. if (ai.hidden !== true) {
  5040. return false;
  5041. }
  5042. ai.fireEvent('deactivate', ai);
  5043. }
  5044. var layout = item.doLayout && (this.layoutOnCardChange || !item.rendered);
  5045. // Change activeItem reference
  5046. this.activeItem = item;
  5047. // The container is about to get a recursive layout, remove any deferLayout reference
  5048. // because it will trigger a redundant layout.
  5049. delete item.deferLayout;
  5050. // Show the new component
  5051. item.show();
  5052. this.layout();
  5053. if(layout){
  5054. item.doLayout();
  5055. }
  5056. item.fireEvent('activate', item);
  5057. }
  5058. },
  5059. // private
  5060. renderAll : function(ct, target){
  5061. if(this.deferredRender){
  5062. this.renderItem(this.activeItem, undefined, target);
  5063. }else{
  5064. Ext.layout.CardLayout.superclass.renderAll.call(this, ct, target);
  5065. }
  5066. }
  5067. });
  5068. Ext.Container.LAYOUTS['card'] = Ext.layout.CardLayout;
  5069. /**
  5070. * @class Ext.layout.AnchorLayout
  5071. * @extends Ext.layout.ContainerLayout
  5072. * <p>This is a layout that enables anchoring of contained elements relative to the container's dimensions.
  5073. * If the container is resized, all anchored items are automatically rerendered according to their
  5074. * <b><tt>{@link #anchor}</tt></b> rules.</p>
  5075. * <p>This class is intended to be extended or created via the layout:'anchor' {@link Ext.Container#layout}
  5076. * config, and should generally not need to be created directly via the new keyword.</p>
  5077. * <p>AnchorLayout does not have any direct config options (other than inherited ones). By default,
  5078. * AnchorLayout will calculate anchor measurements based on the size of the container itself. However, the
  5079. * container using the AnchorLayout can supply an anchoring-specific config property of <b>anchorSize</b>.
  5080. * If anchorSize is specifed, the layout will use it as a virtual container for the purposes of calculating
  5081. * anchor measurements based on it instead, allowing the container to be sized independently of the anchoring
  5082. * logic if necessary. For example:</p>
  5083. * <pre><code>
  5084. var viewport = new Ext.Viewport({
  5085. layout:'anchor',
  5086. anchorSize: {width:800, height:600},
  5087. items:[{
  5088. title:'Item 1',
  5089. html:'Content 1',
  5090. width:800,
  5091. anchor:'right 20%'
  5092. },{
  5093. title:'Item 2',
  5094. html:'Content 2',
  5095. width:300,
  5096. anchor:'50% 30%'
  5097. },{
  5098. title:'Item 3',
  5099. html:'Content 3',
  5100. width:600,
  5101. anchor:'-100 50%'
  5102. }]
  5103. });
  5104. * </code></pre>
  5105. */
  5106. Ext.layout.AnchorLayout = Ext.extend(Ext.layout.ContainerLayout, {
  5107. /**
  5108. * @cfg {String} anchor
  5109. * <p>This configuation option is to be applied to <b>child <tt>items</tt></b> of a container managed by
  5110. * this layout (ie. configured with <tt>layout:'anchor'</tt>).</p><br/>
  5111. *
  5112. * <p>This value is what tells the layout how an item should be anchored to the container. <tt>items</tt>
  5113. * added to an AnchorLayout accept an anchoring-specific config property of <b>anchor</b> which is a string
  5114. * containing two values: the horizontal anchor value and the vertical anchor value (for example, '100% 50%').
  5115. * The following types of anchor values are supported:<div class="mdetail-params"><ul>
  5116. *
  5117. * <li><b>Percentage</b> : Any value between 1 and 100, expressed as a percentage.<div class="sub-desc">
  5118. * The first anchor is the percentage width that the item should take up within the container, and the
  5119. * second is the percentage height. For example:<pre><code>
  5120. // two values specified
  5121. anchor: '100% 50%' // render item complete width of the container and
  5122. // 1/2 height of the container
  5123. // one value specified
  5124. anchor: '100%' // the width value; the height will default to auto
  5125. * </code></pre></div></li>
  5126. *
  5127. * <li><b>Offsets</b> : Any positive or negative integer value.<div class="sub-desc">
  5128. * This is a raw adjustment where the first anchor is the offset from the right edge of the container,
  5129. * and the second is the offset from the bottom edge. For example:<pre><code>
  5130. // two values specified
  5131. anchor: '-50 -100' // render item the complete width of the container
  5132. // minus 50 pixels and
  5133. // the complete height minus 100 pixels.
  5134. // one value specified
  5135. anchor: '-50' // anchor value is assumed to be the right offset value
  5136. // bottom offset will default to 0
  5137. * </code></pre></div></li>
  5138. *
  5139. * <li><b>Sides</b> : Valid values are <tt>'right'</tt> (or <tt>'r'</tt>) and <tt>'bottom'</tt>
  5140. * (or <tt>'b'</tt>).<div class="sub-desc">
  5141. * Either the container must have a fixed size or an anchorSize config value defined at render time in
  5142. * order for these to have any effect.</div></li>
  5143. *
  5144. * <li><b>Mixed</b> : <div class="sub-desc">
  5145. * Anchor values can also be mixed as needed. For example, to render the width offset from the container
  5146. * right edge by 50 pixels and 75% of the container's height use:
  5147. * <pre><code>
  5148. anchor: '-50 75%'
  5149. * </code></pre></div></li>
  5150. *
  5151. *
  5152. * </ul></div>
  5153. */
  5154. // private
  5155. monitorResize : true,
  5156. type : 'anchor',
  5157. /**
  5158. * @cfg {String} defaultAnchor
  5159. *
  5160. * default anchor for all child container items applied if no anchor or specific width is set on the child item. Defaults to '100%'.
  5161. *
  5162. */
  5163. defaultAnchor : '100%',
  5164. parseAnchorRE : /^(r|right|b|bottom)$/i,
  5165. getLayoutTargetSize : function() {
  5166. var target = this.container.getLayoutTarget(), ret = {};
  5167. if (target) {
  5168. ret = target.getViewSize();
  5169. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  5170. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  5171. // with getViewSize
  5172. if (Ext.isIE9m && Ext.isStrict && ret.width == 0){
  5173. ret = target.getStyleSize();
  5174. }
  5175. ret.width -= target.getPadding('lr');
  5176. ret.height -= target.getPadding('tb');
  5177. }
  5178. return ret;
  5179. },
  5180. // private
  5181. onLayout : function(container, target) {
  5182. Ext.layout.AnchorLayout.superclass.onLayout.call(this, container, target);
  5183. var size = this.getLayoutTargetSize(),
  5184. containerWidth = size.width,
  5185. containerHeight = size.height,
  5186. overflow = target.getStyle('overflow'),
  5187. components = this.getRenderedItems(container),
  5188. len = components.length,
  5189. boxes = [],
  5190. box,
  5191. anchorWidth,
  5192. anchorHeight,
  5193. component,
  5194. anchorSpec,
  5195. calcWidth,
  5196. calcHeight,
  5197. anchorsArray,
  5198. totalHeight = 0,
  5199. i,
  5200. el;
  5201. if(containerWidth < 20 && containerHeight < 20){
  5202. return;
  5203. }
  5204. // find the container anchoring size
  5205. if(container.anchorSize) {
  5206. if(typeof container.anchorSize == 'number') {
  5207. anchorWidth = container.anchorSize;
  5208. } else {
  5209. anchorWidth = container.anchorSize.width;
  5210. anchorHeight = container.anchorSize.height;
  5211. }
  5212. } else {
  5213. anchorWidth = container.initialConfig.width;
  5214. anchorHeight = container.initialConfig.height;
  5215. }
  5216. for(i = 0; i < len; i++) {
  5217. component = components[i];
  5218. el = component.getPositionEl();
  5219. // If a child container item has no anchor and no specific width, set the child to the default anchor size
  5220. if (!component.anchor && component.items && !Ext.isNumber(component.width) && !(Ext.isIE6 && Ext.isStrict)){
  5221. component.anchor = this.defaultAnchor;
  5222. }
  5223. if(component.anchor) {
  5224. anchorSpec = component.anchorSpec;
  5225. // cache all anchor values
  5226. if(!anchorSpec){
  5227. anchorsArray = component.anchor.split(' ');
  5228. component.anchorSpec = anchorSpec = {
  5229. right: this.parseAnchor(anchorsArray[0], component.initialConfig.width, anchorWidth),
  5230. bottom: this.parseAnchor(anchorsArray[1], component.initialConfig.height, anchorHeight)
  5231. };
  5232. }
  5233. calcWidth = anchorSpec.right ? this.adjustWidthAnchor(anchorSpec.right(containerWidth) - el.getMargins('lr'), component) : undefined;
  5234. calcHeight = anchorSpec.bottom ? this.adjustHeightAnchor(anchorSpec.bottom(containerHeight) - el.getMargins('tb'), component) : undefined;
  5235. if(calcWidth || calcHeight) {
  5236. boxes.push({
  5237. component: component,
  5238. width: calcWidth || undefined,
  5239. height: calcHeight || undefined
  5240. });
  5241. }
  5242. }
  5243. }
  5244. for (i = 0, len = boxes.length; i < len; i++) {
  5245. box = boxes[i];
  5246. box.component.setSize(box.width, box.height);
  5247. }
  5248. if (overflow && overflow != 'hidden' && !this.adjustmentPass) {
  5249. var newTargetSize = this.getLayoutTargetSize();
  5250. if (newTargetSize.width != size.width || newTargetSize.height != size.height){
  5251. this.adjustmentPass = true;
  5252. this.onLayout(container, target);
  5253. }
  5254. }
  5255. delete this.adjustmentPass;
  5256. },
  5257. // private
  5258. parseAnchor : function(a, start, cstart) {
  5259. if (a && a != 'none') {
  5260. var last;
  5261. // standard anchor
  5262. if (this.parseAnchorRE.test(a)) {
  5263. var diff = cstart - start;
  5264. return function(v){
  5265. if(v !== last){
  5266. last = v;
  5267. return v - diff;
  5268. }
  5269. };
  5270. // percentage
  5271. } else if(a.indexOf('%') != -1) {
  5272. var ratio = parseFloat(a.replace('%', ''))*.01;
  5273. return function(v){
  5274. if(v !== last){
  5275. last = v;
  5276. return Math.floor(v*ratio);
  5277. }
  5278. };
  5279. // simple offset adjustment
  5280. } else {
  5281. a = parseInt(a, 10);
  5282. if (!isNaN(a)) {
  5283. return function(v) {
  5284. if (v !== last) {
  5285. last = v;
  5286. return v + a;
  5287. }
  5288. };
  5289. }
  5290. }
  5291. }
  5292. return false;
  5293. },
  5294. // private
  5295. adjustWidthAnchor : function(value, comp){
  5296. return value;
  5297. },
  5298. // private
  5299. adjustHeightAnchor : function(value, comp){
  5300. return value;
  5301. }
  5302. /**
  5303. * @property activeItem
  5304. * @hide
  5305. */
  5306. });
  5307. Ext.Container.LAYOUTS['anchor'] = Ext.layout.AnchorLayout;
  5308. /**
  5309. * @class Ext.layout.ColumnLayout
  5310. * @extends Ext.layout.ContainerLayout
  5311. * <p>This is the layout style of choice for creating structural layouts in a multi-column format where the width of
  5312. * each column can be specified as a percentage or fixed width, but the height is allowed to vary based on the content.
  5313. * This class is intended to be extended or created via the layout:'column' {@link Ext.Container#layout} config,
  5314. * and should generally not need to be created directly via the new keyword.</p>
  5315. * <p>ColumnLayout does not have any direct config options (other than inherited ones), but it does support a
  5316. * specific config property of <b><tt>columnWidth</tt></b> that can be included in the config of any panel added to it. The
  5317. * layout will use the columnWidth (if present) or width of each panel during layout to determine how to size each panel.
  5318. * If width or columnWidth is not specified for a given panel, its width will default to the panel's width (or auto).</p>
  5319. * <p>The width property is always evaluated as pixels, and must be a number greater than or equal to 1.
  5320. * The columnWidth property is always evaluated as a percentage, and must be a decimal value greater than 0 and
  5321. * less than 1 (e.g., .25).</p>
  5322. * <p>The basic rules for specifying column widths are pretty simple. The logic makes two passes through the
  5323. * set of contained panels. During the first layout pass, all panels that either have a fixed width or none
  5324. * specified (auto) are skipped, but their widths are subtracted from the overall container width. During the second
  5325. * pass, all panels with columnWidths are assigned pixel widths in proportion to their percentages based on
  5326. * the total <b>remaining</b> container width. In other words, percentage width panels are designed to fill the space
  5327. * left over by all the fixed-width and/or auto-width panels. Because of this, while you can specify any number of columns
  5328. * with different percentages, the columnWidths must always add up to 1 (or 100%) when added together, otherwise your
  5329. * layout may not render as expected. Example usage:</p>
  5330. * <pre><code>
  5331. // All columns are percentages -- they must add up to 1
  5332. var p = new Ext.Panel({
  5333. title: 'Column Layout - Percentage Only',
  5334. layout:'column',
  5335. items: [{
  5336. title: 'Column 1',
  5337. columnWidth: .25
  5338. },{
  5339. title: 'Column 2',
  5340. columnWidth: .6
  5341. },{
  5342. title: 'Column 3',
  5343. columnWidth: .15
  5344. }]
  5345. });
  5346. // Mix of width and columnWidth -- all columnWidth values must add up
  5347. // to 1. The first column will take up exactly 120px, and the last two
  5348. // columns will fill the remaining container width.
  5349. var p = new Ext.Panel({
  5350. title: 'Column Layout - Mixed',
  5351. layout:'column',
  5352. items: [{
  5353. title: 'Column 1',
  5354. width: 120
  5355. },{
  5356. title: 'Column 2',
  5357. columnWidth: .8
  5358. },{
  5359. title: 'Column 3',
  5360. columnWidth: .2
  5361. }]
  5362. });
  5363. </code></pre>
  5364. */
  5365. Ext.layout.ColumnLayout = Ext.extend(Ext.layout.ContainerLayout, {
  5366. // private
  5367. monitorResize:true,
  5368. type: 'column',
  5369. extraCls: 'x-column',
  5370. scrollOffset : 0,
  5371. // private
  5372. targetCls: 'x-column-layout-ct',
  5373. isValidParent : function(c, target){
  5374. return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
  5375. },
  5376. getLayoutTargetSize : function() {
  5377. var target = this.container.getLayoutTarget(), ret;
  5378. if (target) {
  5379. ret = target.getViewSize();
  5380. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  5381. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  5382. // with getViewSize
  5383. if (Ext.isIE9m && Ext.isStrict && ret.width == 0){
  5384. ret = target.getStyleSize();
  5385. }
  5386. ret.width -= target.getPadding('lr');
  5387. ret.height -= target.getPadding('tb');
  5388. }
  5389. return ret;
  5390. },
  5391. renderAll : function(ct, target) {
  5392. if(!this.innerCt){
  5393. // the innerCt prevents wrapping and shuffling while
  5394. // the container is resizing
  5395. this.innerCt = target.createChild({cls:'x-column-inner'});
  5396. this.innerCt.createChild({cls:'x-clear'});
  5397. }
  5398. Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
  5399. },
  5400. // private
  5401. onLayout : function(ct, target){
  5402. var cs = ct.items.items,
  5403. len = cs.length,
  5404. c,
  5405. i,
  5406. m,
  5407. margins = [];
  5408. this.renderAll(ct, target);
  5409. var size = this.getLayoutTargetSize();
  5410. if (Ext.isIE9m && (size.width < 1 && size.height < 1)) { // display none?
  5411. return;
  5412. }
  5413. var w = size.width - this.scrollOffset,
  5414. h = size.height,
  5415. pw = w;
  5416. this.innerCt.setWidth(w);
  5417. // some columns can be percentages while others are fixed
  5418. // so we need to make 2 passes
  5419. for(i = 0; i < len; i++){
  5420. c = cs[i];
  5421. m = c.getPositionEl().getMargins('lr');
  5422. margins[i] = m;
  5423. if(!c.columnWidth){
  5424. pw -= (c.getWidth() + m);
  5425. }
  5426. }
  5427. pw = pw < 0 ? 0 : pw;
  5428. for(i = 0; i < len; i++){
  5429. c = cs[i];
  5430. m = margins[i];
  5431. if(c.columnWidth){
  5432. c.setSize(Math.floor(c.columnWidth * pw) - m);
  5433. }
  5434. }
  5435. // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
  5436. // spaces were accounted for properly. If not, re-layout.
  5437. if (Ext.isIE9m) {
  5438. if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
  5439. var ts = this.getLayoutTargetSize();
  5440. if (ts.width != size.width){
  5441. this.adjustmentPass = true;
  5442. this.onLayout(ct, target);
  5443. }
  5444. }
  5445. }
  5446. delete this.adjustmentPass;
  5447. }
  5448. /**
  5449. * @property activeItem
  5450. * @hide
  5451. */
  5452. });
  5453. Ext.Container.LAYOUTS['column'] = Ext.layout.ColumnLayout;
  5454. /**
  5455. * @class Ext.layout.BorderLayout
  5456. * @extends Ext.layout.ContainerLayout
  5457. * <p>This is a multi-pane, application-oriented UI layout style that supports multiple
  5458. * nested panels, automatic {@link Ext.layout.BorderLayout.Region#split split} bars between
  5459. * {@link Ext.layout.BorderLayout.Region#BorderLayout.Region regions} and built-in
  5460. * {@link Ext.layout.BorderLayout.Region#collapsible expanding and collapsing} of regions.</p>
  5461. * <p>This class is intended to be extended or created via the <tt>layout:'border'</tt>
  5462. * {@link Ext.Container#layout} config, and should generally not need to be created directly
  5463. * via the new keyword.</p>
  5464. * <p>BorderLayout does not have any direct config options (other than inherited ones).
  5465. * All configuration options available for customizing the BorderLayout are at the
  5466. * {@link Ext.layout.BorderLayout.Region} and {@link Ext.layout.BorderLayout.SplitRegion}
  5467. * levels.</p>
  5468. * <p>Example usage:</p>
  5469. * <pre><code>
  5470. var myBorderPanel = new Ext.Panel({
  5471. {@link Ext.Component#renderTo renderTo}: document.body,
  5472. {@link Ext.BoxComponent#width width}: 700,
  5473. {@link Ext.BoxComponent#height height}: 500,
  5474. {@link Ext.Panel#title title}: 'Border Layout',
  5475. {@link Ext.Container#layout layout}: 'border',
  5476. {@link Ext.Container#items items}: [{
  5477. {@link Ext.Panel#title title}: 'South Region is resizable',
  5478. {@link Ext.layout.BorderLayout.Region#BorderLayout.Region region}: 'south', // position for region
  5479. {@link Ext.BoxComponent#height height}: 100,
  5480. {@link Ext.layout.BorderLayout.Region#split split}: true, // enable resizing
  5481. {@link Ext.SplitBar#minSize minSize}: 75, // defaults to {@link Ext.layout.BorderLayout.Region#minHeight 50}
  5482. {@link Ext.SplitBar#maxSize maxSize}: 150,
  5483. {@link Ext.layout.BorderLayout.Region#margins margins}: '0 5 5 5'
  5484. },{
  5485. // xtype: 'panel' implied by default
  5486. {@link Ext.Panel#title title}: 'West Region is collapsible',
  5487. {@link Ext.layout.BorderLayout.Region#BorderLayout.Region region}:'west',
  5488. {@link Ext.layout.BorderLayout.Region#margins margins}: '5 0 0 5',
  5489. {@link Ext.BoxComponent#width width}: 200,
  5490. {@link Ext.layout.BorderLayout.Region#collapsible collapsible}: true, // make collapsible
  5491. {@link Ext.layout.BorderLayout.Region#cmargins cmargins}: '5 5 0 5', // adjust top margin when collapsed
  5492. {@link Ext.Component#id id}: 'west-region-container',
  5493. {@link Ext.Container#layout layout}: 'fit',
  5494. {@link Ext.Panel#unstyled unstyled}: true
  5495. },{
  5496. {@link Ext.Panel#title title}: 'Center Region',
  5497. {@link Ext.layout.BorderLayout.Region#BorderLayout.Region region}: 'center', // center region is required, no width/height specified
  5498. {@link Ext.Component#xtype xtype}: 'container',
  5499. {@link Ext.Container#layout layout}: 'fit',
  5500. {@link Ext.layout.BorderLayout.Region#margins margins}: '5 5 0 0'
  5501. }]
  5502. });
  5503. </code></pre>
  5504. * <p><b><u>Notes</u></b>:</p><div class="mdetail-params"><ul>
  5505. * <li>Any container using the BorderLayout <b>must</b> have a child item with <tt>region:'center'</tt>.
  5506. * The child item in the center region will always be resized to fill the remaining space not used by
  5507. * the other regions in the layout.</li>
  5508. * <li>Any child items with a region of <tt>west</tt> or <tt>east</tt> must have <tt>width</tt> defined
  5509. * (an integer representing the number of pixels that the region should take up).</li>
  5510. * <li>Any child items with a region of <tt>north</tt> or <tt>south</tt> must have <tt>height</tt> defined.</li>
  5511. * <li>The regions of a BorderLayout are <b>fixed at render time</b> and thereafter, its child Components may not be removed or added</b>. To add/remove
  5512. * Components within a BorderLayout, have them wrapped by an additional Container which is directly
  5513. * managed by the BorderLayout. If the region is to be collapsible, the Container used directly
  5514. * by the BorderLayout manager should be a Panel. In the following example a Container (an Ext.Panel)
  5515. * is added to the west region:
  5516. * <div style="margin-left:16px"><pre><code>
  5517. wrc = {@link Ext#getCmp Ext.getCmp}('west-region-container');
  5518. wrc.{@link Ext.Panel#removeAll removeAll}();
  5519. wrc.{@link Ext.Container#add add}({
  5520. title: 'Added Panel',
  5521. html: 'Some content'
  5522. });
  5523. wrc.{@link Ext.Container#doLayout doLayout}();
  5524. * </code></pre></div>
  5525. * </li>
  5526. * <li> To reference a {@link Ext.layout.BorderLayout.Region Region}:
  5527. * <div style="margin-left:16px"><pre><code>
  5528. wr = myBorderPanel.layout.west;
  5529. * </code></pre></div>
  5530. * </li>
  5531. * </ul></div>
  5532. */
  5533. Ext.layout.BorderLayout = Ext.extend(Ext.layout.ContainerLayout, {
  5534. // private
  5535. monitorResize:true,
  5536. // private
  5537. rendered : false,
  5538. type: 'border',
  5539. targetCls: 'x-border-layout-ct',
  5540. getLayoutTargetSize : function() {
  5541. var target = this.container.getLayoutTarget();
  5542. return target ? target.getViewSize() : {};
  5543. },
  5544. // private
  5545. onLayout : function(ct, target){
  5546. var collapsed, i, c, pos, items = ct.items.items, len = items.length;
  5547. if(!this.rendered){
  5548. collapsed = [];
  5549. for(i = 0; i < len; i++) {
  5550. c = items[i];
  5551. pos = c.region;
  5552. if(c.collapsed){
  5553. collapsed.push(c);
  5554. }
  5555. c.collapsed = false;
  5556. if(!c.rendered){
  5557. c.render(target, i);
  5558. c.getPositionEl().addClass('x-border-panel');
  5559. }
  5560. this[pos] = pos != 'center' && c.split ?
  5561. new Ext.layout.BorderLayout.SplitRegion(this, c.initialConfig, pos) :
  5562. new Ext.layout.BorderLayout.Region(this, c.initialConfig, pos);
  5563. this[pos].render(target, c);
  5564. }
  5565. this.rendered = true;
  5566. }
  5567. var size = this.getLayoutTargetSize();
  5568. if(size.width < 20 || size.height < 20){ // display none?
  5569. if(collapsed){
  5570. this.restoreCollapsed = collapsed;
  5571. }
  5572. return;
  5573. }else if(this.restoreCollapsed){
  5574. collapsed = this.restoreCollapsed;
  5575. delete this.restoreCollapsed;
  5576. }
  5577. var w = size.width, h = size.height,
  5578. centerW = w, centerH = h, centerY = 0, centerX = 0,
  5579. n = this.north, s = this.south, west = this.west, e = this.east, c = this.center,
  5580. b, m, totalWidth, totalHeight;
  5581. if(!c && Ext.layout.BorderLayout.WARN !== false){
  5582. throw 'No center region defined in BorderLayout ' + ct.id;
  5583. }
  5584. if(n && n.isVisible()){
  5585. b = n.getSize();
  5586. m = n.getMargins();
  5587. b.width = w - (m.left+m.right);
  5588. b.x = m.left;
  5589. b.y = m.top;
  5590. centerY = b.height + b.y + m.bottom;
  5591. centerH -= centerY;
  5592. n.applyLayout(b);
  5593. }
  5594. if(s && s.isVisible()){
  5595. b = s.getSize();
  5596. m = s.getMargins();
  5597. b.width = w - (m.left+m.right);
  5598. b.x = m.left;
  5599. totalHeight = (b.height + m.top + m.bottom);
  5600. b.y = h - totalHeight + m.top;
  5601. centerH -= totalHeight;
  5602. s.applyLayout(b);
  5603. }
  5604. if(west && west.isVisible()){
  5605. b = west.getSize();
  5606. m = west.getMargins();
  5607. b.height = centerH - (m.top+m.bottom);
  5608. b.x = m.left;
  5609. b.y = centerY + m.top;
  5610. totalWidth = (b.width + m.left + m.right);
  5611. centerX += totalWidth;
  5612. centerW -= totalWidth;
  5613. west.applyLayout(b);
  5614. }
  5615. if(e && e.isVisible()){
  5616. b = e.getSize();
  5617. m = e.getMargins();
  5618. b.height = centerH - (m.top+m.bottom);
  5619. totalWidth = (b.width + m.left + m.right);
  5620. b.x = w - totalWidth + m.left;
  5621. b.y = centerY + m.top;
  5622. centerW -= totalWidth;
  5623. e.applyLayout(b);
  5624. }
  5625. if(c){
  5626. m = c.getMargins();
  5627. var centerBox = {
  5628. x: centerX + m.left,
  5629. y: centerY + m.top,
  5630. width: centerW - (m.left+m.right),
  5631. height: centerH - (m.top+m.bottom)
  5632. };
  5633. c.applyLayout(centerBox);
  5634. }
  5635. if(collapsed){
  5636. for(i = 0, len = collapsed.length; i < len; i++){
  5637. collapsed[i].collapse(false);
  5638. }
  5639. }
  5640. if(Ext.isIE9m && Ext.isStrict){ // workaround IE strict repainting issue
  5641. target.repaint();
  5642. }
  5643. // Putting a border layout into an overflowed container is NOT correct and will make a second layout pass necessary.
  5644. if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
  5645. var ts = this.getLayoutTargetSize();
  5646. if (ts.width != size.width || ts.height != size.height){
  5647. this.adjustmentPass = true;
  5648. this.onLayout(ct, target);
  5649. }
  5650. }
  5651. delete this.adjustmentPass;
  5652. },
  5653. destroy: function() {
  5654. var r = ['north', 'south', 'east', 'west'], i, region;
  5655. for (i = 0; i < r.length; i++) {
  5656. region = this[r[i]];
  5657. if(region){
  5658. if(region.destroy){
  5659. region.destroy();
  5660. }else if (region.split){
  5661. region.split.destroy(true);
  5662. }
  5663. }
  5664. }
  5665. Ext.layout.BorderLayout.superclass.destroy.call(this);
  5666. }
  5667. /**
  5668. * @property activeItem
  5669. * @hide
  5670. */
  5671. });
  5672. /**
  5673. * @class Ext.layout.BorderLayout.Region
  5674. * <p>This is a region of a {@link Ext.layout.BorderLayout BorderLayout} that acts as a subcontainer
  5675. * within the layout. Each region in the layout is a component, the region itself is constructed on top
  5676. * of that component, acting like a mixin. Each region has its own {@link Ext.layout.ContainerLayout layout}
  5677. * that is independent of other regions and the containing BorderLayout, and can be any of the
  5678. * {@link Ext.layout.ContainerLayout valid Ext layout types}.</p>
  5679. * <p>Region size is managed automatically and cannot be changed by the user -- for
  5680. * {@link #split resizable regions}, see {@link Ext.layout.BorderLayout.SplitRegion}.</p>
  5681. * @constructor
  5682. * Create a new Region.
  5683. * @param {Layout} layout The {@link Ext.layout.BorderLayout BorderLayout} instance that is managing this Region.
  5684. * @param {Object} config The configuration options
  5685. * @param {String} position The region position. Valid values are: <tt>north</tt>, <tt>south</tt>,
  5686. * <tt>east</tt>, <tt>west</tt> and <tt>center</tt>. Every {@link Ext.layout.BorderLayout BorderLayout}
  5687. * <b>must have a center region</b> for the primary content -- all other regions are optional.
  5688. */
  5689. Ext.layout.BorderLayout.Region = function(layout, config, pos){
  5690. Ext.apply(this, config);
  5691. this.layout = layout;
  5692. this.position = pos;
  5693. this.state = {};
  5694. if(typeof this.margins == 'string'){
  5695. this.margins = this.layout.parseMargins(this.margins);
  5696. }
  5697. this.margins = Ext.applyIf(this.margins || {}, this.defaultMargins);
  5698. if(this.collapsible){
  5699. if(typeof this.cmargins == 'string'){
  5700. this.cmargins = this.layout.parseMargins(this.cmargins);
  5701. }
  5702. if(this.collapseMode == 'mini' && !this.cmargins){
  5703. this.cmargins = {left:0,top:0,right:0,bottom:0};
  5704. }else{
  5705. this.cmargins = Ext.applyIf(this.cmargins || {},
  5706. pos == 'north' || pos == 'south' ? this.defaultNSCMargins : this.defaultEWCMargins);
  5707. }
  5708. }
  5709. };
  5710. Ext.layout.BorderLayout.Region.prototype = {
  5711. /**
  5712. * @cfg {Boolean} animFloat
  5713. * When a collapsed region's bar is clicked, the region's panel will be displayed as a floated
  5714. * panel that will close again once the user mouses out of that panel (or clicks out if
  5715. * <tt>{@link #autoHide} = false</tt>). Setting <tt>{@link #animFloat} = false</tt> will
  5716. * prevent the open and close of these floated panels from being animated (defaults to <tt>true</tt>).
  5717. */
  5718. /**
  5719. * @cfg {Boolean} autoHide
  5720. * When a collapsed region's bar is clicked, the region's panel will be displayed as a floated
  5721. * panel. If <tt>autoHide = true</tt>, the panel will automatically hide after the user mouses
  5722. * out of the panel. If <tt>autoHide = false</tt>, the panel will continue to display until the
  5723. * user clicks outside of the panel (defaults to <tt>true</tt>).
  5724. */
  5725. /**
  5726. * @cfg {String} collapseMode
  5727. * <tt>collapseMode</tt> supports two configuration values:<div class="mdetail-params"><ul>
  5728. * <li><b><tt>undefined</tt></b> (default)<div class="sub-desc">By default, {@link #collapsible}
  5729. * regions are collapsed by clicking the expand/collapse tool button that renders into the region's
  5730. * title bar.</div></li>
  5731. * <li><b><tt>'mini'</tt></b><div class="sub-desc">Optionally, when <tt>collapseMode</tt> is set to
  5732. * <tt>'mini'</tt> the region's split bar will also display a small collapse button in the center of
  5733. * the bar. In <tt>'mini'</tt> mode the region will collapse to a thinner bar than in normal mode.
  5734. * </div></li>
  5735. * </ul></div></p>
  5736. * <p><b>Note</b>: if a collapsible region does not have a title bar, then set <tt>collapseMode =
  5737. * 'mini'</tt> and <tt>{@link #split} = true</tt> in order for the region to be {@link #collapsible}
  5738. * by the user as the expand/collapse tool button (that would go in the title bar) will not be rendered.</p>
  5739. * <p>See also <tt>{@link #cmargins}</tt>.</p>
  5740. */
  5741. /**
  5742. * @cfg {Object} margins
  5743. * An object containing margins to apply to the region when in the expanded state in the
  5744. * format:<pre><code>
  5745. {
  5746. top: (top margin),
  5747. right: (right margin),
  5748. bottom: (bottom margin),
  5749. left: (left margin)
  5750. }</code></pre>
  5751. * <p>May also be a string containing space-separated, numeric margin values. The order of the
  5752. * sides associated with each value matches the way CSS processes margin values:</p>
  5753. * <p><div class="mdetail-params"><ul>
  5754. * <li>If there is only one value, it applies to all sides.</li>
  5755. * <li>If there are two values, the top and bottom borders are set to the first value and the
  5756. * right and left are set to the second.</li>
  5757. * <li>If there are three values, the top is set to the first value, the left and right are set
  5758. * to the second, and the bottom is set to the third.</li>
  5759. * <li>If there are four values, they apply to the top, right, bottom, and left, respectively.</li>
  5760. * </ul></div></p>
  5761. * <p>Defaults to:</p><pre><code>
  5762. * {top:0, right:0, bottom:0, left:0}
  5763. * </code></pre>
  5764. */
  5765. /**
  5766. * @cfg {Object} cmargins
  5767. * An object containing margins to apply to the region when in the collapsed state in the
  5768. * format:<pre><code>
  5769. {
  5770. top: (top margin),
  5771. right: (right margin),
  5772. bottom: (bottom margin),
  5773. left: (left margin)
  5774. }</code></pre>
  5775. * <p>May also be a string containing space-separated, numeric margin values. The order of the
  5776. * sides associated with each value matches the way CSS processes margin values.</p>
  5777. * <p><ul>
  5778. * <li>If there is only one value, it applies to all sides.</li>
  5779. * <li>If there are two values, the top and bottom borders are set to the first value and the
  5780. * right and left are set to the second.</li>
  5781. * <li>If there are three values, the top is set to the first value, the left and right are set
  5782. * to the second, and the bottom is set to the third.</li>
  5783. * <li>If there are four values, they apply to the top, right, bottom, and left, respectively.</li>
  5784. * </ul></p>
  5785. */
  5786. /**
  5787. * @cfg {Boolean} collapsible
  5788. * <p><tt>true</tt> to allow the user to collapse this region (defaults to <tt>false</tt>). If
  5789. * <tt>true</tt>, an expand/collapse tool button will automatically be rendered into the title
  5790. * bar of the region, otherwise the button will not be shown.</p>
  5791. * <p><b>Note</b>: that a title bar is required to display the collapse/expand toggle button -- if
  5792. * no <tt>title</tt> is specified for the region's panel, the region will only be collapsible if
  5793. * <tt>{@link #collapseMode} = 'mini'</tt> and <tt>{@link #split} = true</tt>.
  5794. */
  5795. collapsible : false,
  5796. /**
  5797. * @cfg {Boolean} split
  5798. * <p><tt>true</tt> to create a {@link Ext.layout.BorderLayout.SplitRegion SplitRegion} and
  5799. * display a 5px wide {@link Ext.SplitBar} between this region and its neighbor, allowing the user to
  5800. * resize the regions dynamically. Defaults to <tt>false</tt> creating a
  5801. * {@link Ext.layout.BorderLayout.Region Region}.</p><br>
  5802. * <p><b>Notes</b>:</p><div class="mdetail-params"><ul>
  5803. * <li>this configuration option is ignored if <tt>region='center'</tt></li>
  5804. * <li>when <tt>split == true</tt>, it is common to specify a
  5805. * <tt>{@link Ext.SplitBar#minSize minSize}</tt> and <tt>{@link Ext.SplitBar#maxSize maxSize}</tt>
  5806. * for the {@link Ext.BoxComponent BoxComponent} representing the region. These are not native
  5807. * configs of {@link Ext.BoxComponent BoxComponent}, and are used only by this class.</li>
  5808. * <li>if <tt>{@link #collapseMode} = 'mini'</tt> requires <tt>split = true</tt> to reserve space
  5809. * for the collapse tool</tt></li>
  5810. * </ul></div>
  5811. */
  5812. split:false,
  5813. /**
  5814. * @cfg {Boolean} floatable
  5815. * <tt>true</tt> to allow clicking a collapsed region's bar to display the region's panel floated
  5816. * above the layout, <tt>false</tt> to force the user to fully expand a collapsed region by
  5817. * clicking the expand button to see it again (defaults to <tt>true</tt>).
  5818. */
  5819. floatable: true,
  5820. /**
  5821. * @cfg {Number} minWidth
  5822. * <p>The minimum allowable width in pixels for this region (defaults to <tt>50</tt>).
  5823. * <tt>maxWidth</tt> may also be specified.</p><br>
  5824. * <p><b>Note</b>: setting the <tt>{@link Ext.SplitBar#minSize minSize}</tt> /
  5825. * <tt>{@link Ext.SplitBar#maxSize maxSize}</tt> supersedes any specified
  5826. * <tt>minWidth</tt> / <tt>maxWidth</tt>.</p>
  5827. */
  5828. minWidth:50,
  5829. /**
  5830. * @cfg {Number} minHeight
  5831. * The minimum allowable height in pixels for this region (defaults to <tt>50</tt>)
  5832. * <tt>maxHeight</tt> may also be specified.</p><br>
  5833. * <p><b>Note</b>: setting the <tt>{@link Ext.SplitBar#minSize minSize}</tt> /
  5834. * <tt>{@link Ext.SplitBar#maxSize maxSize}</tt> supersedes any specified
  5835. * <tt>minHeight</tt> / <tt>maxHeight</tt>.</p>
  5836. */
  5837. minHeight:50,
  5838. // private
  5839. defaultMargins : {left:0,top:0,right:0,bottom:0},
  5840. // private
  5841. defaultNSCMargins : {left:5,top:5,right:5,bottom:5},
  5842. // private
  5843. defaultEWCMargins : {left:5,top:0,right:5,bottom:0},
  5844. floatingZIndex: 100,
  5845. /**
  5846. * True if this region is collapsed. Read-only.
  5847. * @type Boolean
  5848. * @property
  5849. */
  5850. isCollapsed : false,
  5851. /**
  5852. * This region's panel. Read-only.
  5853. * @type Ext.Panel
  5854. * @property panel
  5855. */
  5856. /**
  5857. * This region's layout. Read-only.
  5858. * @type Layout
  5859. * @property layout
  5860. */
  5861. /**
  5862. * This region's layout position (north, south, east, west or center). Read-only.
  5863. * @type String
  5864. * @property position
  5865. */
  5866. // private
  5867. render : function(ct, p){
  5868. this.panel = p;
  5869. p.el.enableDisplayMode();
  5870. this.targetEl = ct;
  5871. this.el = p.el;
  5872. var gs = p.getState, ps = this.position;
  5873. p.getState = function(){
  5874. return Ext.apply(gs.call(p) || {}, this.state);
  5875. }.createDelegate(this);
  5876. if(ps != 'center'){
  5877. p.allowQueuedExpand = false;
  5878. p.on({
  5879. beforecollapse: this.beforeCollapse,
  5880. collapse: this.onCollapse,
  5881. beforeexpand: this.beforeExpand,
  5882. expand: this.onExpand,
  5883. hide: this.onHide,
  5884. show: this.onShow,
  5885. scope: this
  5886. });
  5887. if(this.collapsible || this.floatable){
  5888. p.collapseEl = 'el';
  5889. p.slideAnchor = this.getSlideAnchor();
  5890. }
  5891. if(p.tools && p.tools.toggle){
  5892. p.tools.toggle.addClass('x-tool-collapse-'+ps);
  5893. p.tools.toggle.addClassOnOver('x-tool-collapse-'+ps+'-over');
  5894. }
  5895. }
  5896. },
  5897. // private
  5898. getCollapsedEl : function(){
  5899. if(!this.collapsedEl){
  5900. if(!this.toolTemplate){
  5901. var tt = new Ext.Template(
  5902. '<div class="x-tool x-tool-{id}">&#160;</div>'
  5903. );
  5904. tt.disableFormats = true;
  5905. tt.compile();
  5906. Ext.layout.BorderLayout.Region.prototype.toolTemplate = tt;
  5907. }
  5908. this.collapsedEl = this.targetEl.createChild({
  5909. cls: "x-layout-collapsed x-layout-collapsed-"+this.position,
  5910. id: this.panel.id + '-xcollapsed'
  5911. });
  5912. this.collapsedEl.enableDisplayMode('block');
  5913. if(this.collapseMode == 'mini'){
  5914. this.collapsedEl.addClass('x-layout-cmini-'+this.position);
  5915. this.miniCollapsedEl = this.collapsedEl.createChild({
  5916. cls: "x-layout-mini x-layout-mini-"+this.position, html: "&#160;"
  5917. });
  5918. this.miniCollapsedEl.addClassOnOver('x-layout-mini-over');
  5919. this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
  5920. this.collapsedEl.on('click', this.onExpandClick, this, {stopEvent:true});
  5921. }else {
  5922. if(this.collapsible !== false && !this.hideCollapseTool) {
  5923. var t = this.expandToolEl = this.toolTemplate.append(
  5924. this.collapsedEl.dom,
  5925. {id:'expand-'+this.position}, true);
  5926. t.addClassOnOver('x-tool-expand-'+this.position+'-over');
  5927. t.on('click', this.onExpandClick, this, {stopEvent:true});
  5928. }
  5929. if(this.floatable !== false || this.titleCollapse){
  5930. this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
  5931. this.collapsedEl.on("click", this[this.floatable ? 'collapseClick' : 'onExpandClick'], this);
  5932. }
  5933. }
  5934. }
  5935. return this.collapsedEl;
  5936. },
  5937. // private
  5938. onExpandClick : function(e){
  5939. if(this.isSlid){
  5940. this.panel.expand(false);
  5941. }else{
  5942. this.panel.expand();
  5943. }
  5944. },
  5945. // private
  5946. onCollapseClick : function(e){
  5947. this.panel.collapse();
  5948. },
  5949. // private
  5950. beforeCollapse : function(p, animate){
  5951. this.lastAnim = animate;
  5952. if(this.splitEl){
  5953. this.splitEl.hide();
  5954. }
  5955. this.getCollapsedEl().show();
  5956. var el = this.panel.getEl();
  5957. this.originalZIndex = el.getStyle('z-index');
  5958. el.setStyle('z-index', 100);
  5959. this.isCollapsed = true;
  5960. this.layout.layout();
  5961. },
  5962. // private
  5963. onCollapse : function(animate){
  5964. this.panel.el.setStyle('z-index', 1);
  5965. if(this.lastAnim === false || this.panel.animCollapse === false){
  5966. this.getCollapsedEl().dom.style.visibility = 'visible';
  5967. }else{
  5968. this.getCollapsedEl().slideIn(this.panel.slideAnchor, {duration:.2});
  5969. }
  5970. this.state.collapsed = true;
  5971. this.panel.saveState();
  5972. },
  5973. // private
  5974. beforeExpand : function(animate){
  5975. if(this.isSlid){
  5976. this.afterSlideIn();
  5977. }
  5978. var c = this.getCollapsedEl();
  5979. this.el.show();
  5980. if(this.position == 'east' || this.position == 'west'){
  5981. this.panel.setSize(undefined, c.getHeight());
  5982. }else{
  5983. this.panel.setSize(c.getWidth(), undefined);
  5984. }
  5985. c.hide();
  5986. c.dom.style.visibility = 'hidden';
  5987. this.panel.el.setStyle('z-index', this.floatingZIndex);
  5988. },
  5989. // private
  5990. onExpand : function(){
  5991. this.isCollapsed = false;
  5992. if(this.splitEl){
  5993. this.splitEl.show();
  5994. }
  5995. this.layout.layout();
  5996. this.panel.el.setStyle('z-index', this.originalZIndex);
  5997. this.state.collapsed = false;
  5998. this.panel.saveState();
  5999. },
  6000. // private
  6001. collapseClick : function(e){
  6002. if(this.isSlid){
  6003. e.stopPropagation();
  6004. this.slideIn();
  6005. }else{
  6006. e.stopPropagation();
  6007. this.slideOut();
  6008. }
  6009. },
  6010. // private
  6011. onHide : function(){
  6012. if(this.isCollapsed){
  6013. this.getCollapsedEl().hide();
  6014. }else if(this.splitEl){
  6015. this.splitEl.hide();
  6016. }
  6017. },
  6018. // private
  6019. onShow : function(){
  6020. if(this.isCollapsed){
  6021. this.getCollapsedEl().show();
  6022. }else if(this.splitEl){
  6023. this.splitEl.show();
  6024. }
  6025. },
  6026. /**
  6027. * True if this region is currently visible, else false.
  6028. * @return {Boolean}
  6029. */
  6030. isVisible : function(){
  6031. return !this.panel.hidden;
  6032. },
  6033. /**
  6034. * Returns the current margins for this region. If the region is collapsed, the
  6035. * {@link #cmargins} (collapsed margins) value will be returned, otherwise the
  6036. * {@link #margins} value will be returned.
  6037. * @return {Object} An object containing the element's margins: <tt>{left: (left
  6038. * margin), top: (top margin), right: (right margin), bottom: (bottom margin)}</tt>
  6039. */
  6040. getMargins : function(){
  6041. return this.isCollapsed && this.cmargins ? this.cmargins : this.margins;
  6042. },
  6043. /**
  6044. * Returns the current size of this region. If the region is collapsed, the size of the
  6045. * collapsedEl will be returned, otherwise the size of the region's panel will be returned.
  6046. * @return {Object} An object containing the element's size: <tt>{width: (element width),
  6047. * height: (element height)}</tt>
  6048. */
  6049. getSize : function(){
  6050. return this.isCollapsed ? this.getCollapsedEl().getSize() : this.panel.getSize();
  6051. },
  6052. /**
  6053. * Sets the specified panel as the container element for this region.
  6054. * @param {Ext.Panel} panel The new panel
  6055. */
  6056. setPanel : function(panel){
  6057. this.panel = panel;
  6058. },
  6059. /**
  6060. * Returns the minimum allowable width for this region.
  6061. * @return {Number} The minimum width
  6062. */
  6063. getMinWidth: function(){
  6064. return this.minWidth;
  6065. },
  6066. /**
  6067. * Returns the minimum allowable height for this region.
  6068. * @return {Number} The minimum height
  6069. */
  6070. getMinHeight: function(){
  6071. return this.minHeight;
  6072. },
  6073. // private
  6074. applyLayoutCollapsed : function(box){
  6075. var ce = this.getCollapsedEl();
  6076. ce.setLeftTop(box.x, box.y);
  6077. ce.setSize(box.width, box.height);
  6078. },
  6079. // private
  6080. applyLayout : function(box){
  6081. if(this.isCollapsed){
  6082. this.applyLayoutCollapsed(box);
  6083. }else{
  6084. this.panel.setPosition(box.x, box.y);
  6085. this.panel.setSize(box.width, box.height);
  6086. }
  6087. },
  6088. // private
  6089. beforeSlide: function(){
  6090. this.panel.beforeEffect();
  6091. },
  6092. // private
  6093. afterSlide : function(){
  6094. this.panel.afterEffect();
  6095. },
  6096. // private
  6097. initAutoHide : function(){
  6098. if(this.autoHide !== false){
  6099. if(!this.autoHideHd){
  6100. this.autoHideSlideTask = new Ext.util.DelayedTask(this.slideIn, this);
  6101. this.autoHideHd = {
  6102. "mouseout": function(e){
  6103. if(!e.within(this.el, true)){
  6104. this.autoHideSlideTask.delay(500);
  6105. }
  6106. },
  6107. "mouseover" : function(e){
  6108. this.autoHideSlideTask.cancel();
  6109. },
  6110. scope : this
  6111. };
  6112. }
  6113. this.el.on(this.autoHideHd);
  6114. this.collapsedEl.on(this.autoHideHd);
  6115. }
  6116. },
  6117. // private
  6118. clearAutoHide : function(){
  6119. if(this.autoHide !== false){
  6120. this.el.un("mouseout", this.autoHideHd.mouseout);
  6121. this.el.un("mouseover", this.autoHideHd.mouseover);
  6122. this.collapsedEl.un("mouseout", this.autoHideHd.mouseout);
  6123. this.collapsedEl.un("mouseover", this.autoHideHd.mouseover);
  6124. }
  6125. },
  6126. // private
  6127. clearMonitor : function(){
  6128. Ext.getDoc().un("click", this.slideInIf, this);
  6129. },
  6130. /**
  6131. * If this Region is {@link #floatable}, this method slides this Region into full visibility <i>over the top
  6132. * of the center Region</i> where it floats until either {@link #slideIn} is called, or other regions of the layout
  6133. * are clicked, or the mouse exits the Region.
  6134. */
  6135. slideOut : function(){
  6136. if(this.isSlid || this.el.hasActiveFx()){
  6137. return;
  6138. }
  6139. this.isSlid = true;
  6140. var ts = this.panel.tools, dh, pc;
  6141. if(ts && ts.toggle){
  6142. ts.toggle.hide();
  6143. }
  6144. this.el.show();
  6145. // Temporarily clear the collapsed flag so we can onResize the panel on the slide
  6146. pc = this.panel.collapsed;
  6147. this.panel.collapsed = false;
  6148. if(this.position == 'east' || this.position == 'west'){
  6149. // Temporarily clear the deferHeight flag so we can size the height on the slide
  6150. dh = this.panel.deferHeight;
  6151. this.panel.deferHeight = false;
  6152. this.panel.setSize(undefined, this.collapsedEl.getHeight());
  6153. // Put the deferHeight flag back after setSize
  6154. this.panel.deferHeight = dh;
  6155. }else{
  6156. this.panel.setSize(this.collapsedEl.getWidth(), undefined);
  6157. }
  6158. // Put the collapsed flag back after onResize
  6159. this.panel.collapsed = pc;
  6160. this.restoreLT = [this.el.dom.style.left, this.el.dom.style.top];
  6161. this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
  6162. this.el.setStyle("z-index", this.floatingZIndex+2);
  6163. this.panel.el.replaceClass('x-panel-collapsed', 'x-panel-floating');
  6164. if(this.animFloat !== false){
  6165. this.beforeSlide();
  6166. this.el.slideIn(this.getSlideAnchor(), {
  6167. callback: function(){
  6168. this.afterSlide();
  6169. this.initAutoHide();
  6170. Ext.getDoc().on("click", this.slideInIf, this);
  6171. },
  6172. scope: this,
  6173. block: true
  6174. });
  6175. }else{
  6176. this.initAutoHide();
  6177. Ext.getDoc().on("click", this.slideInIf, this);
  6178. }
  6179. },
  6180. // private
  6181. afterSlideIn : function(){
  6182. this.clearAutoHide();
  6183. this.isSlid = false;
  6184. this.clearMonitor();
  6185. this.el.setStyle("z-index", "");
  6186. this.panel.el.replaceClass('x-panel-floating', 'x-panel-collapsed');
  6187. this.el.dom.style.left = this.restoreLT[0];
  6188. this.el.dom.style.top = this.restoreLT[1];
  6189. var ts = this.panel.tools;
  6190. if(ts && ts.toggle){
  6191. ts.toggle.show();
  6192. }
  6193. },
  6194. /**
  6195. * If this Region is {@link #floatable}, and this Region has been slid into floating visibility, then this method slides
  6196. * this region back into its collapsed state.
  6197. */
  6198. slideIn : function(cb){
  6199. if(!this.isSlid || this.el.hasActiveFx()){
  6200. Ext.callback(cb);
  6201. return;
  6202. }
  6203. this.isSlid = false;
  6204. if(this.animFloat !== false){
  6205. this.beforeSlide();
  6206. this.el.slideOut(this.getSlideAnchor(), {
  6207. callback: function(){
  6208. this.el.hide();
  6209. this.afterSlide();
  6210. this.afterSlideIn();
  6211. Ext.callback(cb);
  6212. },
  6213. scope: this,
  6214. block: true
  6215. });
  6216. }else{
  6217. this.el.hide();
  6218. this.afterSlideIn();
  6219. }
  6220. },
  6221. // private
  6222. slideInIf : function(e){
  6223. if(!e.within(this.el)){
  6224. this.slideIn();
  6225. }
  6226. },
  6227. // private
  6228. anchors : {
  6229. "west" : "left",
  6230. "east" : "right",
  6231. "north" : "top",
  6232. "south" : "bottom"
  6233. },
  6234. // private
  6235. sanchors : {
  6236. "west" : "l",
  6237. "east" : "r",
  6238. "north" : "t",
  6239. "south" : "b"
  6240. },
  6241. // private
  6242. canchors : {
  6243. "west" : "tl-tr",
  6244. "east" : "tr-tl",
  6245. "north" : "tl-bl",
  6246. "south" : "bl-tl"
  6247. },
  6248. // private
  6249. getAnchor : function(){
  6250. return this.anchors[this.position];
  6251. },
  6252. // private
  6253. getCollapseAnchor : function(){
  6254. return this.canchors[this.position];
  6255. },
  6256. // private
  6257. getSlideAnchor : function(){
  6258. return this.sanchors[this.position];
  6259. },
  6260. // private
  6261. getAlignAdj : function(){
  6262. var cm = this.cmargins;
  6263. switch(this.position){
  6264. case "west":
  6265. return [0, 0];
  6266. break;
  6267. case "east":
  6268. return [0, 0];
  6269. break;
  6270. case "north":
  6271. return [0, 0];
  6272. break;
  6273. case "south":
  6274. return [0, 0];
  6275. break;
  6276. }
  6277. },
  6278. // private
  6279. getExpandAdj : function(){
  6280. var c = this.collapsedEl, cm = this.cmargins;
  6281. switch(this.position){
  6282. case "west":
  6283. return [-(cm.right+c.getWidth()+cm.left), 0];
  6284. break;
  6285. case "east":
  6286. return [cm.right+c.getWidth()+cm.left, 0];
  6287. break;
  6288. case "north":
  6289. return [0, -(cm.top+cm.bottom+c.getHeight())];
  6290. break;
  6291. case "south":
  6292. return [0, cm.top+cm.bottom+c.getHeight()];
  6293. break;
  6294. }
  6295. },
  6296. destroy : function(){
  6297. if (this.autoHideSlideTask && this.autoHideSlideTask.cancel){
  6298. this.autoHideSlideTask.cancel();
  6299. }
  6300. Ext.destroyMembers(this, 'miniCollapsedEl', 'collapsedEl', 'expandToolEl');
  6301. }
  6302. };
  6303. /**
  6304. * @class Ext.layout.BorderLayout.SplitRegion
  6305. * @extends Ext.layout.BorderLayout.Region
  6306. * <p>This is a specialized type of {@link Ext.layout.BorderLayout.Region BorderLayout region} that
  6307. * has a built-in {@link Ext.SplitBar} for user resizing of regions. The movement of the split bar
  6308. * is configurable to move either {@link #tickSize smooth or incrementally}.</p>
  6309. * @constructor
  6310. * Create a new SplitRegion.
  6311. * @param {Layout} layout The {@link Ext.layout.BorderLayout BorderLayout} instance that is managing this Region.
  6312. * @param {Object} config The configuration options
  6313. * @param {String} position The region position. Valid values are: north, south, east, west and center. Every
  6314. * BorderLayout must have a center region for the primary content -- all other regions are optional.
  6315. */
  6316. Ext.layout.BorderLayout.SplitRegion = function(layout, config, pos){
  6317. Ext.layout.BorderLayout.SplitRegion.superclass.constructor.call(this, layout, config, pos);
  6318. // prevent switch
  6319. this.applyLayout = this.applyFns[pos];
  6320. };
  6321. Ext.extend(Ext.layout.BorderLayout.SplitRegion, Ext.layout.BorderLayout.Region, {
  6322. /**
  6323. * @cfg {Number} tickSize
  6324. * The increment, in pixels by which to move this Region's {@link Ext.SplitBar SplitBar}.
  6325. * By default, the {@link Ext.SplitBar SplitBar} moves smoothly.
  6326. */
  6327. /**
  6328. * @cfg {String} splitTip
  6329. * The tooltip to display when the user hovers over a
  6330. * {@link Ext.layout.BorderLayout.Region#collapsible non-collapsible} region's split bar
  6331. * (defaults to <tt>"Drag to resize."</tt>). Only applies if
  6332. * <tt>{@link #useSplitTips} = true</tt>.
  6333. */
  6334. splitTip : "Drag to resize.",
  6335. /**
  6336. * @cfg {String} collapsibleSplitTip
  6337. * The tooltip to display when the user hovers over a
  6338. * {@link Ext.layout.BorderLayout.Region#collapsible collapsible} region's split bar
  6339. * (defaults to "Drag to resize. Double click to hide."). Only applies if
  6340. * <tt>{@link #useSplitTips} = true</tt>.
  6341. */
  6342. collapsibleSplitTip : "Drag to resize. Double click to hide.",
  6343. /**
  6344. * @cfg {Boolean} useSplitTips
  6345. * <tt>true</tt> to display a tooltip when the user hovers over a region's split bar
  6346. * (defaults to <tt>false</tt>). The tooltip text will be the value of either
  6347. * <tt>{@link #splitTip}</tt> or <tt>{@link #collapsibleSplitTip}</tt> as appropriate.
  6348. */
  6349. useSplitTips : false,
  6350. // private
  6351. splitSettings : {
  6352. north : {
  6353. orientation: Ext.SplitBar.VERTICAL,
  6354. placement: Ext.SplitBar.TOP,
  6355. maxFn : 'getVMaxSize',
  6356. minProp: 'minHeight',
  6357. maxProp: 'maxHeight'
  6358. },
  6359. south : {
  6360. orientation: Ext.SplitBar.VERTICAL,
  6361. placement: Ext.SplitBar.BOTTOM,
  6362. maxFn : 'getVMaxSize',
  6363. minProp: 'minHeight',
  6364. maxProp: 'maxHeight'
  6365. },
  6366. east : {
  6367. orientation: Ext.SplitBar.HORIZONTAL,
  6368. placement: Ext.SplitBar.RIGHT,
  6369. maxFn : 'getHMaxSize',
  6370. minProp: 'minWidth',
  6371. maxProp: 'maxWidth'
  6372. },
  6373. west : {
  6374. orientation: Ext.SplitBar.HORIZONTAL,
  6375. placement: Ext.SplitBar.LEFT,
  6376. maxFn : 'getHMaxSize',
  6377. minProp: 'minWidth',
  6378. maxProp: 'maxWidth'
  6379. }
  6380. },
  6381. // private
  6382. applyFns : {
  6383. west : function(box){
  6384. if(this.isCollapsed){
  6385. return this.applyLayoutCollapsed(box);
  6386. }
  6387. var sd = this.splitEl.dom, s = sd.style;
  6388. this.panel.setPosition(box.x, box.y);
  6389. var sw = sd.offsetWidth;
  6390. s.left = (box.x+box.width-sw)+'px';
  6391. s.top = (box.y)+'px';
  6392. s.height = Math.max(0, box.height)+'px';
  6393. this.panel.setSize(box.width-sw, box.height);
  6394. },
  6395. east : function(box){
  6396. if(this.isCollapsed){
  6397. return this.applyLayoutCollapsed(box);
  6398. }
  6399. var sd = this.splitEl.dom, s = sd.style;
  6400. var sw = sd.offsetWidth;
  6401. this.panel.setPosition(box.x+sw, box.y);
  6402. s.left = (box.x)+'px';
  6403. s.top = (box.y)+'px';
  6404. s.height = Math.max(0, box.height)+'px';
  6405. this.panel.setSize(box.width-sw, box.height);
  6406. },
  6407. north : function(box){
  6408. if(this.isCollapsed){
  6409. return this.applyLayoutCollapsed(box);
  6410. }
  6411. var sd = this.splitEl.dom, s = sd.style;
  6412. var sh = sd.offsetHeight;
  6413. this.panel.setPosition(box.x, box.y);
  6414. s.left = (box.x)+'px';
  6415. s.top = (box.y+box.height-sh)+'px';
  6416. s.width = Math.max(0, box.width)+'px';
  6417. this.panel.setSize(box.width, box.height-sh);
  6418. },
  6419. south : function(box){
  6420. if(this.isCollapsed){
  6421. return this.applyLayoutCollapsed(box);
  6422. }
  6423. var sd = this.splitEl.dom, s = sd.style;
  6424. var sh = sd.offsetHeight;
  6425. this.panel.setPosition(box.x, box.y+sh);
  6426. s.left = (box.x)+'px';
  6427. s.top = (box.y)+'px';
  6428. s.width = Math.max(0, box.width)+'px';
  6429. this.panel.setSize(box.width, box.height-sh);
  6430. }
  6431. },
  6432. // private
  6433. render : function(ct, p){
  6434. Ext.layout.BorderLayout.SplitRegion.superclass.render.call(this, ct, p);
  6435. var ps = this.position;
  6436. this.splitEl = ct.createChild({
  6437. cls: "x-layout-split x-layout-split-"+ps, html: "&#160;",
  6438. id: this.panel.id + '-xsplit'
  6439. });
  6440. if(this.collapseMode == 'mini'){
  6441. this.miniSplitEl = this.splitEl.createChild({
  6442. cls: "x-layout-mini x-layout-mini-"+ps, html: "&#160;"
  6443. });
  6444. this.miniSplitEl.addClassOnOver('x-layout-mini-over');
  6445. this.miniSplitEl.on('click', this.onCollapseClick, this, {stopEvent:true});
  6446. }
  6447. var s = this.splitSettings[ps];
  6448. this.split = new Ext.SplitBar(this.splitEl.dom, p.el, s.orientation);
  6449. this.split.tickSize = this.tickSize;
  6450. this.split.placement = s.placement;
  6451. this.split.getMaximumSize = this[s.maxFn].createDelegate(this);
  6452. this.split.minSize = this.minSize || this[s.minProp];
  6453. this.split.on("beforeapply", this.onSplitMove, this);
  6454. this.split.useShim = this.useShim === true;
  6455. this.maxSize = this.maxSize || this[s.maxProp];
  6456. if(p.hidden){
  6457. this.splitEl.hide();
  6458. }
  6459. if(this.useSplitTips){
  6460. this.splitEl.dom.title = this.collapsible ? this.collapsibleSplitTip : this.splitTip;
  6461. }
  6462. if(this.collapsible){
  6463. this.splitEl.on("dblclick", this.onCollapseClick, this);
  6464. }
  6465. },
  6466. //docs inherit from superclass
  6467. getSize : function(){
  6468. if(this.isCollapsed){
  6469. return this.collapsedEl.getSize();
  6470. }
  6471. var s = this.panel.getSize();
  6472. if(this.position == 'north' || this.position == 'south'){
  6473. s.height += this.splitEl.dom.offsetHeight;
  6474. }else{
  6475. s.width += this.splitEl.dom.offsetWidth;
  6476. }
  6477. return s;
  6478. },
  6479. // private
  6480. getHMaxSize : function(){
  6481. var cmax = this.maxSize || 10000;
  6482. var center = this.layout.center;
  6483. return Math.min(cmax, (this.el.getWidth()+center.el.getWidth())-center.getMinWidth());
  6484. },
  6485. // private
  6486. getVMaxSize : function(){
  6487. var cmax = this.maxSize || 10000;
  6488. var center = this.layout.center;
  6489. return Math.min(cmax, (this.el.getHeight()+center.el.getHeight())-center.getMinHeight());
  6490. },
  6491. // private
  6492. onSplitMove : function(split, newSize){
  6493. var s = this.panel.getSize();
  6494. this.lastSplitSize = newSize;
  6495. if(this.position == 'north' || this.position == 'south'){
  6496. this.panel.setSize(s.width, newSize);
  6497. this.state.height = newSize;
  6498. }else{
  6499. this.panel.setSize(newSize, s.height);
  6500. this.state.width = newSize;
  6501. }
  6502. this.layout.layout();
  6503. this.panel.saveState();
  6504. return false;
  6505. },
  6506. /**
  6507. * Returns a reference to the split bar in use by this region.
  6508. * @return {Ext.SplitBar} The split bar
  6509. */
  6510. getSplitBar : function(){
  6511. return this.split;
  6512. },
  6513. // inherit docs
  6514. destroy : function() {
  6515. Ext.destroy(this.miniSplitEl, this.split, this.splitEl);
  6516. Ext.layout.BorderLayout.SplitRegion.superclass.destroy.call(this);
  6517. }
  6518. });
  6519. Ext.Container.LAYOUTS['border'] = Ext.layout.BorderLayout;
  6520. /**
  6521. * @class Ext.layout.FormLayout
  6522. * @extends Ext.layout.AnchorLayout
  6523. * <p>This layout manager is specifically designed for rendering and managing child Components of
  6524. * {@link Ext.form.FormPanel forms}. It is responsible for rendering the labels of
  6525. * {@link Ext.form.Field Field}s.</p>
  6526. *
  6527. * <p>This layout manager is used when a Container is configured with the <tt>layout:'form'</tt>
  6528. * {@link Ext.Container#layout layout} config option, and should generally not need to be created directly
  6529. * via the new keyword. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
  6530. *
  6531. * <p>In an application, it will usually be preferrable to use a {@link Ext.form.FormPanel FormPanel}
  6532. * (which is configured with FormLayout as its layout class by default) since it also provides built-in
  6533. * functionality for {@link Ext.form.BasicForm#doAction loading, validating and submitting} the form.</p>
  6534. *
  6535. * <p>A {@link Ext.Container Container} <i>using</i> the FormLayout layout manager (e.g.
  6536. * {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>) can also accept the following
  6537. * layout-specific config properties:<div class="mdetail-params"><ul>
  6538. * <li><b><tt>{@link Ext.form.FormPanel#hideLabels hideLabels}</tt></b></li>
  6539. * <li><b><tt>{@link Ext.form.FormPanel#labelAlign labelAlign}</tt></b></li>
  6540. * <li><b><tt>{@link Ext.form.FormPanel#labelPad labelPad}</tt></b></li>
  6541. * <li><b><tt>{@link Ext.form.FormPanel#labelSeparator labelSeparator}</tt></b></li>
  6542. * <li><b><tt>{@link Ext.form.FormPanel#labelWidth labelWidth}</tt></b></li>
  6543. * </ul></div></p>
  6544. *
  6545. * <p>Any Component (including Fields) managed by FormLayout accepts the following as a config option:
  6546. * <div class="mdetail-params"><ul>
  6547. * <li><b><tt>{@link Ext.Component#anchor anchor}</tt></b></li>
  6548. * </ul></div></p>
  6549. *
  6550. * <p>Any Component managed by FormLayout may be rendered as a form field (with an associated label) by
  6551. * configuring it with a non-null <b><tt>{@link Ext.Component#fieldLabel fieldLabel}</tt></b>. Components configured
  6552. * in this way may be configured with the following options which affect the way the FormLayout renders them:
  6553. * <div class="mdetail-params"><ul>
  6554. * <li><b><tt>{@link Ext.Component#clearCls clearCls}</tt></b></li>
  6555. * <li><b><tt>{@link Ext.Component#fieldLabel fieldLabel}</tt></b></li>
  6556. * <li><b><tt>{@link Ext.Component#hideLabel hideLabel}</tt></b></li>
  6557. * <li><b><tt>{@link Ext.Component#itemCls itemCls}</tt></b></li>
  6558. * <li><b><tt>{@link Ext.Component#labelSeparator labelSeparator}</tt></b></li>
  6559. * <li><b><tt>{@link Ext.Component#labelStyle labelStyle}</tt></b></li>
  6560. * </ul></div></p>
  6561. *
  6562. * <p>Example usage:</p>
  6563. * <pre><code>
  6564. // Required if showing validation messages
  6565. Ext.QuickTips.init();
  6566. // While you can create a basic Panel with layout:'form', practically
  6567. // you should usually use a FormPanel to also get its form functionality
  6568. // since it already creates a FormLayout internally.
  6569. var form = new Ext.form.FormPanel({
  6570. title: 'Form Layout',
  6571. bodyStyle: 'padding:15px',
  6572. width: 350,
  6573. defaultType: 'textfield',
  6574. defaults: {
  6575. // applied to each contained item
  6576. width: 230,
  6577. msgTarget: 'side'
  6578. },
  6579. items: [{
  6580. fieldLabel: 'First Name',
  6581. name: 'first',
  6582. allowBlank: false,
  6583. {@link Ext.Component#labelSeparator labelSeparator}: ':' // override labelSeparator layout config
  6584. },{
  6585. fieldLabel: 'Last Name',
  6586. name: 'last'
  6587. },{
  6588. fieldLabel: 'Email',
  6589. name: 'email',
  6590. vtype:'email'
  6591. }, {
  6592. xtype: 'textarea',
  6593. hideLabel: true, // override hideLabels layout config
  6594. name: 'msg',
  6595. anchor: '100% -53'
  6596. }
  6597. ],
  6598. buttons: [
  6599. {text: 'Save'},
  6600. {text: 'Cancel'}
  6601. ],
  6602. layoutConfig: {
  6603. {@link #labelSeparator}: '~' // superseded by assignment below
  6604. },
  6605. // config options applicable to container when layout='form':
  6606. hideLabels: false,
  6607. labelAlign: 'left', // or 'right' or 'top'
  6608. {@link Ext.form.FormPanel#labelSeparator labelSeparator}: '>>', // takes precedence over layoutConfig value
  6609. labelWidth: 65, // defaults to 100
  6610. labelPad: 8 // defaults to 5, must specify labelWidth to be honored
  6611. });
  6612. </code></pre>
  6613. */
  6614. Ext.layout.FormLayout = Ext.extend(Ext.layout.AnchorLayout, {
  6615. /**
  6616. * @cfg {String} labelSeparator
  6617. * See {@link Ext.form.FormPanel}.{@link Ext.form.FormPanel#labelSeparator labelSeparator}. Configuration
  6618. * of this property at the <b>container</b> level takes precedence.
  6619. */
  6620. labelSeparator : ':',
  6621. /**
  6622. * Read only. The CSS style specification string added to field labels in this layout if not
  6623. * otherwise {@link Ext.Component#labelStyle specified by each contained field}.
  6624. * @type String
  6625. * @property labelStyle
  6626. */
  6627. /**
  6628. * @cfg {Boolean} trackLabels
  6629. * True to show/hide the field label when the field is hidden. Defaults to <tt>true</tt>.
  6630. */
  6631. trackLabels: true,
  6632. type: 'form',
  6633. onRemove: function(c){
  6634. Ext.layout.FormLayout.superclass.onRemove.call(this, c);
  6635. if(this.trackLabels){
  6636. c.un('show', this.onFieldShow, this);
  6637. c.un('hide', this.onFieldHide, this);
  6638. }
  6639. // check for itemCt, since we may be removing a fieldset or something similar
  6640. var el = c.getPositionEl(),
  6641. ct = c.getItemCt && c.getItemCt();
  6642. if (c.rendered && ct) {
  6643. if (el && el.dom) {
  6644. el.insertAfter(ct);
  6645. }
  6646. Ext.destroy(ct);
  6647. Ext.destroyMembers(c, 'label', 'itemCt');
  6648. if (c.customItemCt) {
  6649. Ext.destroyMembers(c, 'getItemCt', 'customItemCt');
  6650. }
  6651. }
  6652. },
  6653. // private
  6654. setContainer : function(ct){
  6655. Ext.layout.FormLayout.superclass.setContainer.call(this, ct);
  6656. ct.labelAlign = ct.labelAlign || this.labelAlign;
  6657. if (ct.labelAlign) {
  6658. ct.addClass('x-form-label-' + ct.labelAlign);
  6659. }
  6660. if (ct.hideLabels || this.hideLabels) {
  6661. Ext.apply(this, {
  6662. labelStyle: 'display:none',
  6663. elementStyle: 'padding-left:0;',
  6664. labelAdjust: 0
  6665. });
  6666. } else {
  6667. this.labelSeparator = Ext.isDefined(ct.labelSeparator) ? ct.labelSeparator : this.labelSeparator;
  6668. ct.labelWidth = ct.labelWidth || this.labelWidth || 100;
  6669. if(Ext.isNumber(ct.labelWidth)){
  6670. var pad = ct.labelPad || this.labelPad;
  6671. pad = Ext.isNumber(pad) ? pad : 5;
  6672. Ext.apply(this, {
  6673. labelAdjust: ct.labelWidth + pad,
  6674. labelStyle: 'width:' + ct.labelWidth + 'px;',
  6675. elementStyle: 'padding-left:' + (ct.labelWidth + pad) + 'px'
  6676. });
  6677. }
  6678. if(ct.labelAlign == 'top'){
  6679. Ext.apply(this, {
  6680. labelStyle: 'width:auto;',
  6681. labelAdjust: 0,
  6682. elementStyle: 'padding-left:0;'
  6683. });
  6684. }
  6685. }
  6686. },
  6687. // private
  6688. isHide: function(c){
  6689. return c.hideLabel || this.container.hideLabels;
  6690. },
  6691. onFieldShow: function(c){
  6692. c.getItemCt().removeClass('x-hide-' + c.hideMode);
  6693. // Composite fields will need to layout after the container is made visible
  6694. if (c.isComposite) {
  6695. c.doLayout();
  6696. }
  6697. },
  6698. onFieldHide: function(c){
  6699. c.getItemCt().addClass('x-hide-' + c.hideMode);
  6700. },
  6701. //private
  6702. getLabelStyle: function(s){
  6703. var ls = '', items = [this.labelStyle, s];
  6704. for (var i = 0, len = items.length; i < len; ++i){
  6705. if (items[i]){
  6706. ls += items[i];
  6707. if (ls.substr(-1, 1) != ';'){
  6708. ls += ';';
  6709. }
  6710. }
  6711. }
  6712. return ls;
  6713. },
  6714. /**
  6715. * @cfg {Ext.Template} fieldTpl
  6716. * A {@link Ext.Template#compile compile}d {@link Ext.Template} for rendering
  6717. * the fully wrapped, labeled and styled form Field. Defaults to:</p><pre><code>
  6718. new Ext.Template(
  6719. &#39;&lt;div class="x-form-item {itemCls}" tabIndex="-1">&#39;,
  6720. &#39;&lt;&#108;abel for="{id}" style="{labelStyle}" class="x-form-item-&#108;abel">{&#108;abel}{labelSeparator}&lt;/&#108;abel>&#39;,
  6721. &#39;&lt;div class="x-form-element" id="x-form-el-{id}" style="{elementStyle}">&#39;,
  6722. &#39;&lt;/div>&lt;div class="{clearCls}">&lt;/div>&#39;,
  6723. '&lt;/div>'
  6724. );
  6725. </code></pre>
  6726. * <p>This may be specified to produce a different DOM structure when rendering form Fields.</p>
  6727. * <p>A description of the properties within the template follows:</p><div class="mdetail-params"><ul>
  6728. * <li><b><tt>itemCls</tt></b> : String<div class="sub-desc">The CSS class applied to the outermost div wrapper
  6729. * that contains this field label and field element (the default class is <tt>'x-form-item'</tt> and <tt>itemCls</tt>
  6730. * will be added to that). If supplied, <tt>itemCls</tt> at the field level will override the default <tt>itemCls</tt>
  6731. * supplied at the container level.</div></li>
  6732. * <li><b><tt>id</tt></b> : String<div class="sub-desc">The id of the Field</div></li>
  6733. * <li><b><tt>{@link #labelStyle}</tt></b> : String<div class="sub-desc">
  6734. * A CSS style specification string to add to the field label for this field (defaults to <tt>''</tt> or the
  6735. * {@link #labelStyle layout's value for <tt>labelStyle</tt>}).</div></li>
  6736. * <li><b><tt>label</tt></b> : String<div class="sub-desc">The text to display as the label for this
  6737. * field (defaults to <tt>''</tt>)</div></li>
  6738. * <li><b><tt>{@link #labelSeparator}</tt></b> : String<div class="sub-desc">The separator to display after
  6739. * the text of the label for this field (defaults to a colon <tt>':'</tt> or the
  6740. * {@link #labelSeparator layout's value for labelSeparator}). To hide the separator use empty string ''.</div></li>
  6741. * <li><b><tt>elementStyle</tt></b> : String<div class="sub-desc">The styles text for the input element's wrapper.</div></li>
  6742. * <li><b><tt>clearCls</tt></b> : String<div class="sub-desc">The CSS class to apply to the special clearing div
  6743. * rendered directly after each form field wrapper (defaults to <tt>'x-form-clear-left'</tt>)</div></li>
  6744. * </ul></div>
  6745. * <p>Also see <tt>{@link #getTemplateArgs}</tt></p>
  6746. */
  6747. /**
  6748. * @private
  6749. *
  6750. */
  6751. renderItem : function(c, position, target){
  6752. if(c && (c.isFormField || c.fieldLabel) && c.inputType != 'hidden'){
  6753. var args = this.getTemplateArgs(c);
  6754. if(Ext.isNumber(position)){
  6755. position = target.dom.childNodes[position] || null;
  6756. }
  6757. if(position){
  6758. c.itemCt = this.fieldTpl.insertBefore(position, args, true);
  6759. }else{
  6760. c.itemCt = this.fieldTpl.append(target, args, true);
  6761. }
  6762. if(!c.getItemCt){
  6763. // Non form fields don't have getItemCt, apply it here
  6764. // This will get cleaned up in onRemove
  6765. Ext.apply(c, {
  6766. getItemCt: function(){
  6767. return c.itemCt;
  6768. },
  6769. customItemCt: true
  6770. });
  6771. }
  6772. c.label = c.getItemCt().child('label.x-form-item-label');
  6773. if(!c.rendered){
  6774. c.render('x-form-el-' + c.id);
  6775. }else if(!this.isValidParent(c, target)){
  6776. Ext.fly('x-form-el-' + c.id).appendChild(c.getPositionEl());
  6777. }
  6778. if(this.trackLabels){
  6779. if(c.hidden){
  6780. this.onFieldHide(c);
  6781. }
  6782. c.on({
  6783. scope: this,
  6784. show: this.onFieldShow,
  6785. hide: this.onFieldHide
  6786. });
  6787. }
  6788. this.configureItem(c);
  6789. }else {
  6790. Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
  6791. }
  6792. },
  6793. /**
  6794. * <p>Provides template arguments for rendering the fully wrapped, labeled and styled form Field.</p>
  6795. * <p>This method returns an object hash containing properties used by the layout's {@link #fieldTpl}
  6796. * to create a correctly wrapped, labeled and styled form Field. This may be overriden to
  6797. * create custom layouts. The properties which must be returned are:</p><div class="mdetail-params"><ul>
  6798. * <li><b><tt>itemCls</tt></b> : String<div class="sub-desc">The CSS class applied to the outermost div wrapper
  6799. * that contains this field label and field element (the default class is <tt>'x-form-item'</tt> and <tt>itemCls</tt>
  6800. * will be added to that). If supplied, <tt>itemCls</tt> at the field level will override the default <tt>itemCls</tt>
  6801. * supplied at the container level.</div></li>
  6802. * <li><b><tt>id</tt></b> : String<div class="sub-desc">The id of the Field</div></li>
  6803. * <li><b><tt>{@link #labelStyle}</tt></b> : String<div class="sub-desc">
  6804. * A CSS style specification string to add to the field label for this field (defaults to <tt>''</tt> or the
  6805. * {@link #labelStyle layout's value for <tt>labelStyle</tt>}).</div></li>
  6806. * <li><b><tt>label</tt></b> : String<div class="sub-desc">The text to display as the label for this
  6807. * field (defaults to the field's configured fieldLabel property)</div></li>
  6808. * <li><b><tt>{@link #labelSeparator}</tt></b> : String<div class="sub-desc">The separator to display after
  6809. * the text of the label for this field (defaults to a colon <tt>':'</tt> or the
  6810. * {@link #labelSeparator layout's value for labelSeparator}). To hide the separator use empty string ''.</div></li>
  6811. * <li><b><tt>elementStyle</tt></b> : String<div class="sub-desc">The styles text for the input element's wrapper.</div></li>
  6812. * <li><b><tt>clearCls</tt></b> : String<div class="sub-desc">The CSS class to apply to the special clearing div
  6813. * rendered directly after each form field wrapper (defaults to <tt>'x-form-clear-left'</tt>)</div></li>
  6814. * </ul></div>
  6815. * @param (Ext.form.Field} field The {@link Ext.form.Field Field} being rendered.
  6816. * @return {Object} An object hash containing the properties required to render the Field.
  6817. */
  6818. getTemplateArgs: function(field) {
  6819. var noLabelSep = !field.fieldLabel || field.hideLabel,
  6820. itemCls = (field.itemCls || this.container.itemCls || '') + (field.hideLabel ? ' x-hide-label' : '');
  6821. // IE9 quirks needs an extra, identifying class on wrappers of TextFields
  6822. if (Ext.isIE9 && Ext.isIEQuirks && field instanceof Ext.form.TextField) {
  6823. itemCls += ' x-input-wrapper';
  6824. }
  6825. return {
  6826. id : field.id,
  6827. label : field.fieldLabel,
  6828. itemCls : itemCls,
  6829. clearCls : field.clearCls || 'x-form-clear-left',
  6830. labelStyle : this.getLabelStyle(field.labelStyle),
  6831. elementStyle : this.elementStyle || '',
  6832. labelSeparator: noLabelSep ? '' : (Ext.isDefined(field.labelSeparator) ? field.labelSeparator : this.labelSeparator)
  6833. };
  6834. },
  6835. // private
  6836. adjustWidthAnchor: function(value, c){
  6837. if(c.label && !this.isHide(c) && (this.container.labelAlign != 'top')){
  6838. var adjust = Ext.isIE6 || Ext.isIEQuirks;
  6839. return value - this.labelAdjust + (adjust ? -3 : 0);
  6840. }
  6841. return value;
  6842. },
  6843. adjustHeightAnchor : function(value, c){
  6844. if(c.label && !this.isHide(c) && (this.container.labelAlign == 'top')){
  6845. return value - c.label.getHeight();
  6846. }
  6847. return value;
  6848. },
  6849. // private
  6850. isValidParent : function(c, target){
  6851. return target && this.container.getEl().contains(c.getPositionEl());
  6852. }
  6853. /**
  6854. * @property activeItem
  6855. * @hide
  6856. */
  6857. });
  6858. Ext.Container.LAYOUTS['form'] = Ext.layout.FormLayout;
  6859. /**
  6860. * @class Ext.layout.AccordionLayout
  6861. * @extends Ext.layout.FitLayout
  6862. * <p>This is a layout that manages multiple Panels in an expandable accordion style such that only
  6863. * <b>one Panel can be expanded at any given time</b>. Each Panel has built-in support for expanding and collapsing.</p>
  6864. * <p>Note: Only Ext.Panels <b>and all subclasses of Ext.Panel</b> may be used in an accordion layout Container.</p>
  6865. * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
  6866. * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
  6867. * <p>Example usage:</p>
  6868. * <pre><code>
  6869. var accordion = new Ext.Panel({
  6870. title: 'Accordion Layout',
  6871. layout:'accordion',
  6872. defaults: {
  6873. // applied to each contained panel
  6874. bodyStyle: 'padding:15px'
  6875. },
  6876. layoutConfig: {
  6877. // layout-specific configs go here
  6878. titleCollapse: false,
  6879. animate: true,
  6880. activeOnTop: true
  6881. },
  6882. items: [{
  6883. title: 'Panel 1',
  6884. html: '&lt;p&gt;Panel content!&lt;/p&gt;'
  6885. },{
  6886. title: 'Panel 2',
  6887. html: '&lt;p&gt;Panel content!&lt;/p&gt;'
  6888. },{
  6889. title: 'Panel 3',
  6890. html: '&lt;p&gt;Panel content!&lt;/p&gt;'
  6891. }]
  6892. });
  6893. </code></pre>
  6894. */
  6895. Ext.layout.AccordionLayout = Ext.extend(Ext.layout.FitLayout, {
  6896. /**
  6897. * @cfg {Boolean} fill
  6898. * True to adjust the active item's height to fill the available space in the container, false to use the
  6899. * item's current height, or auto height if not explicitly set (defaults to true).
  6900. */
  6901. fill : true,
  6902. /**
  6903. * @cfg {Boolean} autoWidth
  6904. * True to set each contained item's width to 'auto', false to use the item's current width (defaults to true).
  6905. * Note that some components, in particular the {@link Ext.grid.GridPanel grid}, will not function properly within
  6906. * layouts if they have auto width, so in such cases this config should be set to false.
  6907. */
  6908. autoWidth : true,
  6909. /**
  6910. * @cfg {Boolean} titleCollapse
  6911. * True to allow expand/collapse of each contained panel by clicking anywhere on the title bar, false to allow
  6912. * expand/collapse only when the toggle tool button is clicked (defaults to true). When set to false,
  6913. * {@link #hideCollapseTool} should be false also.
  6914. */
  6915. titleCollapse : true,
  6916. /**
  6917. * @cfg {Boolean} hideCollapseTool
  6918. * True to hide the contained panels' collapse/expand toggle buttons, false to display them (defaults to false).
  6919. * When set to true, {@link #titleCollapse} should be true also.
  6920. */
  6921. hideCollapseTool : false,
  6922. /**
  6923. * @cfg {Boolean} collapseFirst
  6924. * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools
  6925. * in the contained panels' title bars, false to render it last (defaults to false).
  6926. */
  6927. collapseFirst : false,
  6928. /**
  6929. * @cfg {Boolean} animate
  6930. * True to slide the contained panels open and closed during expand/collapse using animation, false to open and
  6931. * close directly with no animation (defaults to false). Note: to defer to the specific config setting of each
  6932. * contained panel for this property, set this to undefined at the layout level.
  6933. */
  6934. animate : false,
  6935. /**
  6936. * @cfg {Boolean} sequence
  6937. * <b>Experimental</b>. If animate is set to true, this will result in each animation running in sequence.
  6938. */
  6939. sequence : false,
  6940. /**
  6941. * @cfg {Boolean} activeOnTop
  6942. * True to swap the position of each panel as it is expanded so that it becomes the first item in the container,
  6943. * false to keep the panels in the rendered order. <b>This is NOT compatible with "animate:true"</b> (defaults to false).
  6944. */
  6945. activeOnTop : false,
  6946. type: 'accordion',
  6947. renderItem : function(c){
  6948. if(this.animate === false){
  6949. c.animCollapse = false;
  6950. }
  6951. c.collapsible = true;
  6952. if(this.autoWidth){
  6953. c.autoWidth = true;
  6954. }
  6955. if(this.titleCollapse){
  6956. c.titleCollapse = true;
  6957. }
  6958. if(this.hideCollapseTool){
  6959. c.hideCollapseTool = true;
  6960. }
  6961. if(this.collapseFirst !== undefined){
  6962. c.collapseFirst = this.collapseFirst;
  6963. }
  6964. if(!this.activeItem && !c.collapsed){
  6965. this.setActiveItem(c, true);
  6966. }else if(this.activeItem && this.activeItem != c){
  6967. c.collapsed = true;
  6968. }
  6969. Ext.layout.AccordionLayout.superclass.renderItem.apply(this, arguments);
  6970. c.header.addClass('x-accordion-hd');
  6971. c.on('beforeexpand', this.beforeExpand, this);
  6972. },
  6973. onRemove: function(c){
  6974. Ext.layout.AccordionLayout.superclass.onRemove.call(this, c);
  6975. if(c.rendered){
  6976. c.header.removeClass('x-accordion-hd');
  6977. }
  6978. c.un('beforeexpand', this.beforeExpand, this);
  6979. },
  6980. // private
  6981. beforeExpand : function(p, anim){
  6982. var ai = this.activeItem;
  6983. if(ai){
  6984. if(this.sequence){
  6985. delete this.activeItem;
  6986. if (!ai.collapsed){
  6987. ai.collapse({callback:function(){
  6988. p.expand(anim || true);
  6989. }, scope: this});
  6990. return false;
  6991. }
  6992. }else{
  6993. ai.collapse(this.animate);
  6994. }
  6995. }
  6996. this.setActive(p);
  6997. if(this.activeOnTop){
  6998. p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);
  6999. }
  7000. // Items have been hidden an possibly rearranged, we need to get the container size again.
  7001. this.layout();
  7002. },
  7003. // private
  7004. setItemSize : function(item, size){
  7005. if(this.fill && item){
  7006. var hh = 0, i, ct = this.getRenderedItems(this.container), len = ct.length, p;
  7007. // Add up all the header heights
  7008. for (i = 0; i < len; i++) {
  7009. if((p = ct[i]) != item && !p.hidden){
  7010. hh += p.header.getHeight();
  7011. }
  7012. };
  7013. // Subtract the header heights from the container size
  7014. size.height -= hh;
  7015. // Call setSize on the container to set the correct height. For Panels, deferedHeight
  7016. // will simply store this size for when the expansion is done.
  7017. item.setSize(size);
  7018. }
  7019. },
  7020. /**
  7021. * Sets the active (expanded) item in the layout.
  7022. * @param {String/Number} item The string component id or numeric index of the item to activate
  7023. */
  7024. setActiveItem : function(item){
  7025. this.setActive(item, true);
  7026. },
  7027. // private
  7028. setActive : function(item, expand){
  7029. var ai = this.activeItem;
  7030. item = this.container.getComponent(item);
  7031. if(ai != item){
  7032. if(item.rendered && item.collapsed && expand){
  7033. item.expand();
  7034. }else{
  7035. if(ai){
  7036. ai.fireEvent('deactivate', ai);
  7037. }
  7038. this.activeItem = item;
  7039. item.fireEvent('activate', item);
  7040. }
  7041. }
  7042. }
  7043. });
  7044. Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;
  7045. //backwards compat
  7046. Ext.layout.Accordion = Ext.layout.AccordionLayout;/**
  7047. * @class Ext.layout.TableLayout
  7048. * @extends Ext.layout.ContainerLayout
  7049. * <p>This layout allows you to easily render content into an HTML table. The total number of columns can be
  7050. * specified, and rowspan and colspan can be used to create complex layouts within the table.
  7051. * This class is intended to be extended or created via the layout:'table' {@link Ext.Container#layout} config,
  7052. * and should generally not need to be created directly via the new keyword.</p>
  7053. * <p>Note that when creating a layout via config, the layout-specific config properties must be passed in via
  7054. * the {@link Ext.Container#layoutConfig} object which will then be applied internally to the layout. In the
  7055. * case of TableLayout, the only valid layout config property is {@link #columns}. However, the items added to a
  7056. * TableLayout can supply the following table-specific config properties:</p>
  7057. * <ul>
  7058. * <li><b>rowspan</b> Applied to the table cell containing the item.</li>
  7059. * <li><b>colspan</b> Applied to the table cell containing the item.</li>
  7060. * <li><b>cellId</b> An id applied to the table cell containing the item.</li>
  7061. * <li><b>cellCls</b> A CSS class name added to the table cell containing the item.</li>
  7062. * </ul>
  7063. * <p>The basic concept of building up a TableLayout is conceptually very similar to building up a standard
  7064. * HTML table. You simply add each panel (or "cell") that you want to include along with any span attributes
  7065. * specified as the special config properties of rowspan and colspan which work exactly like their HTML counterparts.
  7066. * Rather than explicitly creating and nesting rows and columns as you would in HTML, you simply specify the
  7067. * total column count in the layoutConfig and start adding panels in their natural order from left to right,
  7068. * top to bottom. The layout will automatically figure out, based on the column count, rowspans and colspans,
  7069. * how to position each panel within the table. Just like with HTML tables, your rowspans and colspans must add
  7070. * up correctly in your overall layout or you'll end up with missing and/or extra cells! Example usage:</p>
  7071. * <pre><code>
  7072. // This code will generate a layout table that is 3 columns by 2 rows
  7073. // with some spanning included. The basic layout will be:
  7074. // +--------+-----------------+
  7075. // | A | B |
  7076. // | |--------+--------|
  7077. // | | C | D |
  7078. // +--------+--------+--------+
  7079. var table = new Ext.Panel({
  7080. title: 'Table Layout',
  7081. layout:'table',
  7082. defaults: {
  7083. // applied to each contained panel
  7084. bodyStyle:'padding:20px'
  7085. },
  7086. layoutConfig: {
  7087. // The total column count must be specified here
  7088. columns: 3
  7089. },
  7090. items: [{
  7091. html: '&lt;p&gt;Cell A content&lt;/p&gt;',
  7092. rowspan: 2
  7093. },{
  7094. html: '&lt;p&gt;Cell B content&lt;/p&gt;',
  7095. colspan: 2
  7096. },{
  7097. html: '&lt;p&gt;Cell C content&lt;/p&gt;',
  7098. cellCls: 'highlight'
  7099. },{
  7100. html: '&lt;p&gt;Cell D content&lt;/p&gt;'
  7101. }]
  7102. });
  7103. </code></pre>
  7104. */
  7105. Ext.layout.TableLayout = Ext.extend(Ext.layout.ContainerLayout, {
  7106. /**
  7107. * @cfg {Number} columns
  7108. * The total number of columns to create in the table for this layout. If not specified, all Components added to
  7109. * this layout will be rendered into a single row using one column per Component.
  7110. */
  7111. // private
  7112. monitorResize:false,
  7113. type: 'table',
  7114. targetCls: 'x-table-layout-ct',
  7115. /**
  7116. * @cfg {Object} tableAttrs
  7117. * <p>An object containing properties which are added to the {@link Ext.DomHelper DomHelper} specification
  7118. * used to create the layout's <tt>&lt;table&gt;</tt> element. Example:</p><pre><code>
  7119. {
  7120. xtype: 'panel',
  7121. layout: 'table',
  7122. layoutConfig: {
  7123. tableAttrs: {
  7124. style: {
  7125. width: '100%'
  7126. }
  7127. },
  7128. columns: 3
  7129. }
  7130. }</code></pre>
  7131. */
  7132. tableAttrs:null,
  7133. // private
  7134. setContainer : function(ct){
  7135. Ext.layout.TableLayout.superclass.setContainer.call(this, ct);
  7136. this.currentRow = 0;
  7137. this.currentColumn = 0;
  7138. this.cells = [];
  7139. },
  7140. // private
  7141. onLayout : function(ct, target){
  7142. var cs = ct.items.items, len = cs.length, c, i;
  7143. if(!this.table){
  7144. target.addClass('x-table-layout-ct');
  7145. this.table = target.createChild(
  7146. Ext.apply({tag:'table', cls:'x-table-layout', cellspacing: 0, cn: {tag: 'tbody'}}, this.tableAttrs), null, true);
  7147. }
  7148. this.renderAll(ct, target);
  7149. },
  7150. // private
  7151. getRow : function(index){
  7152. var row = this.table.tBodies[0].childNodes[index];
  7153. if(!row){
  7154. row = document.createElement('tr');
  7155. this.table.tBodies[0].appendChild(row);
  7156. }
  7157. return row;
  7158. },
  7159. // private
  7160. getNextCell : function(c){
  7161. var cell = this.getNextNonSpan(this.currentColumn, this.currentRow);
  7162. var curCol = this.currentColumn = cell[0], curRow = this.currentRow = cell[1];
  7163. for(var rowIndex = curRow; rowIndex < curRow + (c.rowspan || 1); rowIndex++){
  7164. if(!this.cells[rowIndex]){
  7165. this.cells[rowIndex] = [];
  7166. }
  7167. for(var colIndex = curCol; colIndex < curCol + (c.colspan || 1); colIndex++){
  7168. this.cells[rowIndex][colIndex] = true;
  7169. }
  7170. }
  7171. var td = document.createElement('td');
  7172. if(c.cellId){
  7173. td.id = c.cellId;
  7174. }
  7175. var cls = 'x-table-layout-cell';
  7176. if(c.cellCls){
  7177. cls += ' ' + c.cellCls;
  7178. }
  7179. td.className = cls;
  7180. if(c.colspan){
  7181. td.colSpan = c.colspan;
  7182. }
  7183. if(c.rowspan){
  7184. td.rowSpan = c.rowspan;
  7185. }
  7186. this.getRow(curRow).appendChild(td);
  7187. return td;
  7188. },
  7189. // private
  7190. getNextNonSpan: function(colIndex, rowIndex){
  7191. var cols = this.columns;
  7192. while((cols && colIndex >= cols) || (this.cells[rowIndex] && this.cells[rowIndex][colIndex])) {
  7193. if(cols && colIndex >= cols){
  7194. rowIndex++;
  7195. colIndex = 0;
  7196. }else{
  7197. colIndex++;
  7198. }
  7199. }
  7200. return [colIndex, rowIndex];
  7201. },
  7202. // private
  7203. renderItem : function(c, position, target){
  7204. // Ensure we have our inner table to get cells to render into.
  7205. if(!this.table){
  7206. this.table = target.createChild(
  7207. Ext.apply({tag:'table', cls:'x-table-layout', cellspacing: 0, cn: {tag: 'tbody'}}, this.tableAttrs), null, true);
  7208. }
  7209. if(c && !c.rendered){
  7210. c.render(this.getNextCell(c));
  7211. this.configureItem(c);
  7212. }else if(c && !this.isValidParent(c, target)){
  7213. var container = this.getNextCell(c);
  7214. container.insertBefore(c.getPositionEl().dom, null);
  7215. c.container = Ext.get(container);
  7216. this.configureItem(c);
  7217. }
  7218. },
  7219. // private
  7220. isValidParent : function(c, target){
  7221. return c.getPositionEl().up('table', 5).dom.parentNode === (target.dom || target);
  7222. },
  7223. destroy: function(){
  7224. delete this.table;
  7225. Ext.layout.TableLayout.superclass.destroy.call(this);
  7226. }
  7227. /**
  7228. * @property activeItem
  7229. * @hide
  7230. */
  7231. });
  7232. Ext.Container.LAYOUTS['table'] = Ext.layout.TableLayout;/**
  7233. * @class Ext.layout.AbsoluteLayout
  7234. * @extends Ext.layout.AnchorLayout
  7235. * <p>This is a layout that inherits the anchoring of <b>{@link Ext.layout.AnchorLayout}</b> and adds the
  7236. * ability for x/y positioning using the standard x and y component config options.</p>
  7237. * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
  7238. * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
  7239. * <p>Example usage:</p>
  7240. * <pre><code>
  7241. var form = new Ext.form.FormPanel({
  7242. title: 'Absolute Layout',
  7243. layout:'absolute',
  7244. layoutConfig: {
  7245. // layout-specific configs go here
  7246. extraCls: 'x-abs-layout-item',
  7247. },
  7248. baseCls: 'x-plain',
  7249. url:'save-form.php',
  7250. defaultType: 'textfield',
  7251. items: [{
  7252. x: 0,
  7253. y: 5,
  7254. xtype:'label',
  7255. text: 'Send To:'
  7256. },{
  7257. x: 60,
  7258. y: 0,
  7259. name: 'to',
  7260. anchor:'100%' // anchor width by percentage
  7261. },{
  7262. x: 0,
  7263. y: 35,
  7264. xtype:'label',
  7265. text: 'Subject:'
  7266. },{
  7267. x: 60,
  7268. y: 30,
  7269. name: 'subject',
  7270. anchor: '100%' // anchor width by percentage
  7271. },{
  7272. x:0,
  7273. y: 60,
  7274. xtype: 'textarea',
  7275. name: 'msg',
  7276. anchor: '100% 100%' // anchor width and height
  7277. }]
  7278. });
  7279. </code></pre>
  7280. */
  7281. Ext.layout.AbsoluteLayout = Ext.extend(Ext.layout.AnchorLayout, {
  7282. extraCls: 'x-abs-layout-item',
  7283. type: 'absolute',
  7284. onLayout : function(ct, target){
  7285. target.position();
  7286. this.paddingLeft = target.getPadding('l');
  7287. this.paddingTop = target.getPadding('t');
  7288. Ext.layout.AbsoluteLayout.superclass.onLayout.call(this, ct, target);
  7289. },
  7290. // private
  7291. adjustWidthAnchor : function(value, comp){
  7292. return value ? value - comp.getPosition(true)[0] + this.paddingLeft : value;
  7293. },
  7294. // private
  7295. adjustHeightAnchor : function(value, comp){
  7296. return value ? value - comp.getPosition(true)[1] + this.paddingTop : value;
  7297. }
  7298. /**
  7299. * @property activeItem
  7300. * @hide
  7301. */
  7302. });
  7303. Ext.Container.LAYOUTS['absolute'] = Ext.layout.AbsoluteLayout;
  7304. /**
  7305. * @class Ext.layout.BoxLayout
  7306. * @extends Ext.layout.ContainerLayout
  7307. * <p>Base Class for HBoxLayout and VBoxLayout Classes. Generally it should not need to be used directly.</p>
  7308. */
  7309. Ext.layout.BoxLayout = Ext.extend(Ext.layout.ContainerLayout, {
  7310. /**
  7311. * @cfg {Object} defaultMargins
  7312. * <p>If the individual contained items do not have a <tt>margins</tt>
  7313. * property specified, the default margins from this property will be
  7314. * applied to each item.</p>
  7315. * <br><p>This property may be specified as an object containing margins
  7316. * to apply in the format:</p><pre><code>
  7317. {
  7318. top: (top margin),
  7319. right: (right margin),
  7320. bottom: (bottom margin),
  7321. left: (left margin)
  7322. }</code></pre>
  7323. * <p>This property may also be specified as a string containing
  7324. * space-separated, numeric margin values. The order of the sides associated
  7325. * with each value matches the way CSS processes margin values:</p>
  7326. * <div class="mdetail-params"><ul>
  7327. * <li>If there is only one value, it applies to all sides.</li>
  7328. * <li>If there are two values, the top and bottom borders are set to the
  7329. * first value and the right and left are set to the second.</li>
  7330. * <li>If there are three values, the top is set to the first value, the left
  7331. * and right are set to the second, and the bottom is set to the third.</li>
  7332. * <li>If there are four values, they apply to the top, right, bottom, and
  7333. * left, respectively.</li>
  7334. * </ul></div>
  7335. * <p>Defaults to:</p><pre><code>
  7336. * {top:0, right:0, bottom:0, left:0}
  7337. * </code></pre>
  7338. */
  7339. defaultMargins : {left:0,top:0,right:0,bottom:0},
  7340. /**
  7341. * @cfg {String} padding
  7342. * <p>Sets the padding to be applied to all child items managed by this layout.</p>
  7343. * <p>This property must be specified as a string containing
  7344. * space-separated, numeric padding values. The order of the sides associated
  7345. * with each value matches the way CSS processes padding values:</p>
  7346. * <div class="mdetail-params"><ul>
  7347. * <li>If there is only one value, it applies to all sides.</li>
  7348. * <li>If there are two values, the top and bottom borders are set to the
  7349. * first value and the right and left are set to the second.</li>
  7350. * <li>If there are three values, the top is set to the first value, the left
  7351. * and right are set to the second, and the bottom is set to the third.</li>
  7352. * <li>If there are four values, they apply to the top, right, bottom, and
  7353. * left, respectively.</li>
  7354. * </ul></div>
  7355. * <p>Defaults to: <code>"0"</code></p>
  7356. */
  7357. padding : '0',
  7358. // documented in subclasses
  7359. pack : 'start',
  7360. // private
  7361. monitorResize : true,
  7362. type: 'box',
  7363. scrollOffset : 0,
  7364. extraCls : 'x-box-item',
  7365. targetCls : 'x-box-layout-ct',
  7366. innerCls : 'x-box-inner',
  7367. constructor : function(config){
  7368. Ext.layout.BoxLayout.superclass.constructor.call(this, config);
  7369. if (Ext.isString(this.defaultMargins)) {
  7370. this.defaultMargins = this.parseMargins(this.defaultMargins);
  7371. }
  7372. var handler = this.overflowHandler;
  7373. if (typeof handler == 'string') {
  7374. handler = {
  7375. type: handler
  7376. };
  7377. }
  7378. var handlerType = 'none';
  7379. if (handler && handler.type != undefined) {
  7380. handlerType = handler.type;
  7381. }
  7382. var constructor = Ext.layout.boxOverflow[handlerType];
  7383. if (constructor[this.type]) {
  7384. constructor = constructor[this.type];
  7385. }
  7386. this.overflowHandler = new constructor(this, handler);
  7387. },
  7388. /**
  7389. * @private
  7390. * Runs the child box calculations and caches them in childBoxCache. Subclasses can used these cached values
  7391. * when laying out
  7392. */
  7393. onLayout: function(container, target) {
  7394. Ext.layout.BoxLayout.superclass.onLayout.call(this, container, target);
  7395. var tSize = this.getLayoutTargetSize(),
  7396. items = this.getVisibleItems(container),
  7397. calcs = this.calculateChildBoxes(items, tSize),
  7398. boxes = calcs.boxes,
  7399. meta = calcs.meta;
  7400. //invoke the overflow handler, if one is configured
  7401. if (tSize.width > 0) {
  7402. var handler = this.overflowHandler,
  7403. method = meta.tooNarrow ? 'handleOverflow' : 'clearOverflow';
  7404. var results = handler[method](calcs, tSize);
  7405. if (results) {
  7406. if (results.targetSize) {
  7407. tSize = results.targetSize;
  7408. }
  7409. if (results.recalculate) {
  7410. items = this.getVisibleItems(container);
  7411. calcs = this.calculateChildBoxes(items, tSize);
  7412. boxes = calcs.boxes;
  7413. }
  7414. }
  7415. }
  7416. /**
  7417. * @private
  7418. * @property layoutTargetLastSize
  7419. * @type Object
  7420. * Private cache of the last measured size of the layout target. This should never be used except by
  7421. * BoxLayout subclasses during their onLayout run.
  7422. */
  7423. this.layoutTargetLastSize = tSize;
  7424. /**
  7425. * @private
  7426. * @property childBoxCache
  7427. * @type Array
  7428. * Array of the last calculated height, width, top and left positions of each visible rendered component
  7429. * within the Box layout.
  7430. */
  7431. this.childBoxCache = calcs;
  7432. this.updateInnerCtSize(tSize, calcs);
  7433. this.updateChildBoxes(boxes);
  7434. // Putting a box layout into an overflowed container is NOT correct and will make a second layout pass necessary.
  7435. this.handleTargetOverflow(tSize, container, target);
  7436. },
  7437. /**
  7438. * Resizes and repositions each child component
  7439. * @param {Array} boxes The box measurements
  7440. */
  7441. updateChildBoxes: function(boxes) {
  7442. for (var i = 0, length = boxes.length; i < length; i++) {
  7443. var box = boxes[i],
  7444. comp = box.component;
  7445. if (box.dirtySize) {
  7446. comp.setSize(box.width, box.height);
  7447. }
  7448. // Don't set positions to NaN
  7449. if (isNaN(box.left) || isNaN(box.top)) {
  7450. continue;
  7451. }
  7452. comp.setPosition(box.left, box.top);
  7453. }
  7454. },
  7455. /**
  7456. * @private
  7457. * Called by onRender just before the child components are sized and positioned. This resizes the innerCt
  7458. * to make sure all child items fit within it. We call this before sizing the children because if our child
  7459. * items are larger than the previous innerCt size the browser will insert scrollbars and then remove them
  7460. * again immediately afterwards, giving a performance hit.
  7461. * Subclasses should provide an implementation.
  7462. * @param {Object} currentSize The current height and width of the innerCt
  7463. * @param {Array} calculations The new box calculations of all items to be laid out
  7464. */
  7465. updateInnerCtSize: function(tSize, calcs) {
  7466. var align = this.align,
  7467. padding = this.padding,
  7468. width = tSize.width,
  7469. height = tSize.height;
  7470. if (this.type == 'hbox') {
  7471. var innerCtWidth = width,
  7472. innerCtHeight = calcs.meta.maxHeight + padding.top + padding.bottom;
  7473. if (align == 'stretch') {
  7474. innerCtHeight = height;
  7475. } else if (align == 'middle') {
  7476. innerCtHeight = Math.max(height, innerCtHeight);
  7477. }
  7478. } else {
  7479. var innerCtHeight = height,
  7480. innerCtWidth = calcs.meta.maxWidth + padding.left + padding.right;
  7481. if (align == 'stretch') {
  7482. innerCtWidth = width;
  7483. } else if (align == 'center') {
  7484. innerCtWidth = Math.max(width, innerCtWidth);
  7485. }
  7486. }
  7487. this.innerCt.setSize(innerCtWidth || undefined, innerCtHeight || undefined);
  7488. },
  7489. /**
  7490. * @private
  7491. * This should be called after onLayout of any BoxLayout subclass. If the target's overflow is not set to 'hidden',
  7492. * we need to lay out a second time because the scrollbars may have modified the height and width of the layout
  7493. * target. Having a Box layout inside such a target is therefore not recommended.
  7494. * @param {Object} previousTargetSize The size and height of the layout target before we just laid out
  7495. * @param {Ext.Container} container The container
  7496. * @param {Ext.Element} target The target element
  7497. */
  7498. handleTargetOverflow: function(previousTargetSize, container, target) {
  7499. var overflow = target.getStyle('overflow');
  7500. if (overflow && overflow != 'hidden' &&!this.adjustmentPass) {
  7501. var newTargetSize = this.getLayoutTargetSize();
  7502. if (newTargetSize.width != previousTargetSize.width || newTargetSize.height != previousTargetSize.height){
  7503. this.adjustmentPass = true;
  7504. this.onLayout(container, target);
  7505. }
  7506. }
  7507. delete this.adjustmentPass;
  7508. },
  7509. // private
  7510. isValidParent : function(c, target) {
  7511. return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
  7512. },
  7513. /**
  7514. * @private
  7515. * Returns all items that are both rendered and visible
  7516. * @return {Array} All matching items
  7517. */
  7518. getVisibleItems: function(ct) {
  7519. var ct = ct || this.container,
  7520. t = ct.getLayoutTarget(),
  7521. cti = ct.items.items,
  7522. len = cti.length,
  7523. i, c, items = [];
  7524. for (i = 0; i < len; i++) {
  7525. if((c = cti[i]).rendered && this.isValidParent(c, t) && c.hidden !== true && c.collapsed !== true && c.shouldLayout !== false){
  7526. items.push(c);
  7527. }
  7528. }
  7529. return items;
  7530. },
  7531. // private
  7532. renderAll : function(ct, target) {
  7533. if (!this.innerCt) {
  7534. // the innerCt prevents wrapping and shuffling while the container is resizing
  7535. this.innerCt = target.createChild({cls:this.innerCls});
  7536. this.padding = this.parseMargins(this.padding);
  7537. }
  7538. Ext.layout.BoxLayout.superclass.renderAll.call(this, ct, this.innerCt);
  7539. },
  7540. getLayoutTargetSize : function() {
  7541. var target = this.container.getLayoutTarget(), ret;
  7542. if (target) {
  7543. ret = target.getViewSize();
  7544. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  7545. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  7546. // with getViewSize
  7547. if (Ext.isIE9m && Ext.isStrict && ret.width == 0){
  7548. ret = target.getStyleSize();
  7549. }
  7550. ret.width -= target.getPadding('lr');
  7551. ret.height -= target.getPadding('tb');
  7552. }
  7553. return ret;
  7554. },
  7555. // private
  7556. renderItem : function(c) {
  7557. if(Ext.isString(c.margins)){
  7558. c.margins = this.parseMargins(c.margins);
  7559. }else if(!c.margins){
  7560. c.margins = this.defaultMargins;
  7561. }
  7562. Ext.layout.BoxLayout.superclass.renderItem.apply(this, arguments);
  7563. },
  7564. /**
  7565. * @private
  7566. */
  7567. destroy: function() {
  7568. Ext.destroy(this.overflowHandler);
  7569. Ext.layout.BoxLayout.superclass.destroy.apply(this, arguments);
  7570. }
  7571. });
  7572. /**
  7573. * @class Ext.layout.boxOverflow.None
  7574. * @extends Object
  7575. * Base class for Box Layout overflow handlers. These specialized classes are invoked when a Box Layout
  7576. * (either an HBox or a VBox) has child items that are either too wide (for HBox) or too tall (for VBox)
  7577. * for its container.
  7578. */
  7579. Ext.layout.boxOverflow.None = Ext.extend(Object, {
  7580. constructor: function(layout, config) {
  7581. this.layout = layout;
  7582. Ext.apply(this, config || {});
  7583. },
  7584. handleOverflow: Ext.emptyFn,
  7585. clearOverflow: Ext.emptyFn
  7586. });
  7587. Ext.layout.boxOverflow.none = Ext.layout.boxOverflow.None;
  7588. /**
  7589. * @class Ext.layout.boxOverflow.Menu
  7590. * @extends Ext.layout.boxOverflow.None
  7591. * Description
  7592. */
  7593. Ext.layout.boxOverflow.Menu = Ext.extend(Ext.layout.boxOverflow.None, {
  7594. /**
  7595. * @cfg afterCls
  7596. * @type String
  7597. * CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
  7598. * which must always be present at the rightmost edge of the Container
  7599. */
  7600. afterCls: 'x-strip-right',
  7601. /**
  7602. * @property noItemsMenuText
  7603. * @type String
  7604. * HTML fragment to render into the toolbar overflow menu if there are no items to display
  7605. */
  7606. noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
  7607. constructor: function(layout) {
  7608. Ext.layout.boxOverflow.Menu.superclass.constructor.apply(this, arguments);
  7609. /**
  7610. * @property menuItems
  7611. * @type Array
  7612. * Array of all items that are currently hidden and should go into the dropdown menu
  7613. */
  7614. this.menuItems = [];
  7615. },
  7616. /**
  7617. * @private
  7618. * Creates the beforeCt, innerCt and afterCt elements if they have not already been created
  7619. * @param {Ext.Container} container The Container attached to this Layout instance
  7620. * @param {Ext.Element} target The target Element
  7621. */
  7622. createInnerElements: function() {
  7623. if (!this.afterCt) {
  7624. this.afterCt = this.layout.innerCt.insertSibling({cls: this.afterCls}, 'before');
  7625. }
  7626. },
  7627. /**
  7628. * @private
  7629. */
  7630. clearOverflow: function(calculations, targetSize) {
  7631. var newWidth = targetSize.width + (this.afterCt ? this.afterCt.getWidth() : 0),
  7632. items = this.menuItems;
  7633. this.hideTrigger();
  7634. for (var index = 0, length = items.length; index < length; index++) {
  7635. items.pop().component.show();
  7636. }
  7637. return {
  7638. targetSize: {
  7639. height: targetSize.height,
  7640. width : newWidth
  7641. }
  7642. };
  7643. },
  7644. /**
  7645. * @private
  7646. */
  7647. showTrigger: function() {
  7648. this.createMenu();
  7649. this.menuTrigger.show();
  7650. },
  7651. /**
  7652. * @private
  7653. */
  7654. hideTrigger: function() {
  7655. if (this.menuTrigger != undefined) {
  7656. this.menuTrigger.hide();
  7657. }
  7658. },
  7659. /**
  7660. * @private
  7661. * Called before the overflow menu is shown. This constructs the menu's items, caching them for as long as it can.
  7662. */
  7663. beforeMenuShow: function(menu) {
  7664. var items = this.menuItems,
  7665. len = items.length,
  7666. item,
  7667. prev;
  7668. var needsSep = function(group, item){
  7669. return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
  7670. };
  7671. this.clearMenu();
  7672. menu.removeAll();
  7673. for (var i = 0; i < len; i++) {
  7674. item = items[i].component;
  7675. if (prev && (needsSep(item, prev) || needsSep(prev, item))) {
  7676. menu.add('-');
  7677. }
  7678. this.addComponentToMenu(menu, item);
  7679. prev = item;
  7680. }
  7681. // put something so the menu isn't empty if no compatible items found
  7682. if (menu.items.length < 1) {
  7683. menu.add(this.noItemsMenuText);
  7684. }
  7685. },
  7686. /**
  7687. * @private
  7688. * Returns a menu config for a given component. This config is used to create a menu item
  7689. * to be added to the expander menu
  7690. * @param {Ext.Component} component The component to create the config for
  7691. * @param {Boolean} hideOnClick Passed through to the menu item
  7692. */
  7693. createMenuConfig : function(component, hideOnClick){
  7694. var config = Ext.apply({}, component.initialConfig),
  7695. group = component.toggleGroup;
  7696. Ext.copyTo(config, component, [
  7697. 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
  7698. ]);
  7699. Ext.apply(config, {
  7700. text : component.overflowText || component.text,
  7701. hideOnClick: hideOnClick
  7702. });
  7703. if (group || component.enableToggle) {
  7704. Ext.apply(config, {
  7705. group : group,
  7706. checked: component.pressed,
  7707. listeners: {
  7708. checkchange: function(item, checked){
  7709. component.toggle(checked);
  7710. }
  7711. }
  7712. });
  7713. }
  7714. delete config.ownerCt;
  7715. delete config.xtype;
  7716. delete config.id;
  7717. return config;
  7718. },
  7719. /**
  7720. * @private
  7721. * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
  7722. * @param {Ext.menu.Menu} menu The menu to add to
  7723. * @param {Ext.Component} component The component to add
  7724. */
  7725. addComponentToMenu : function(menu, component) {
  7726. if (component instanceof Ext.Toolbar.Separator) {
  7727. menu.add('-');
  7728. } else if (Ext.isFunction(component.isXType)) {
  7729. if (component.isXType('splitbutton')) {
  7730. menu.add(this.createMenuConfig(component, true));
  7731. } else if (component.isXType('button')) {
  7732. menu.add(this.createMenuConfig(component, !component.menu));
  7733. } else if (component.isXType('buttongroup')) {
  7734. component.items.each(function(item){
  7735. this.addComponentToMenu(menu, item);
  7736. }, this);
  7737. }
  7738. }
  7739. },
  7740. /**
  7741. * @private
  7742. * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
  7743. * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
  7744. */
  7745. clearMenu : function(){
  7746. var menu = this.moreMenu;
  7747. if (menu && menu.items) {
  7748. menu.items.each(function(item){
  7749. delete item.menu;
  7750. });
  7751. }
  7752. },
  7753. /**
  7754. * @private
  7755. * Creates the overflow trigger and menu used when enableOverflow is set to true and the items
  7756. * in the layout are too wide to fit in the space available
  7757. */
  7758. createMenu: function() {
  7759. if (!this.menuTrigger) {
  7760. this.createInnerElements();
  7761. /**
  7762. * @private
  7763. * @property menu
  7764. * @type Ext.menu.Menu
  7765. * The expand menu - holds items for every item that cannot be shown
  7766. * because the container is currently not large enough.
  7767. */
  7768. this.menu = new Ext.menu.Menu({
  7769. ownerCt : this.layout.container,
  7770. listeners: {
  7771. scope: this,
  7772. beforeshow: this.beforeMenuShow
  7773. }
  7774. });
  7775. /**
  7776. * @private
  7777. * @property menuTrigger
  7778. * @type Ext.Button
  7779. * The expand button which triggers the overflow menu to be shown
  7780. */
  7781. this.menuTrigger = new Ext.Button({
  7782. iconCls : 'x-toolbar-more-icon',
  7783. cls : 'x-toolbar-more',
  7784. menu : this.menu,
  7785. renderTo: this.afterCt
  7786. });
  7787. }
  7788. },
  7789. /**
  7790. * @private
  7791. */
  7792. destroy: function() {
  7793. Ext.destroy(this.menu, this.menuTrigger);
  7794. }
  7795. });
  7796. Ext.layout.boxOverflow.menu = Ext.layout.boxOverflow.Menu;
  7797. /**
  7798. * @class Ext.layout.boxOverflow.HorizontalMenu
  7799. * @extends Ext.layout.boxOverflow.Menu
  7800. * Description
  7801. */
  7802. Ext.layout.boxOverflow.HorizontalMenu = Ext.extend(Ext.layout.boxOverflow.Menu, {
  7803. constructor: function() {
  7804. Ext.layout.boxOverflow.HorizontalMenu.superclass.constructor.apply(this, arguments);
  7805. var me = this,
  7806. layout = me.layout,
  7807. origFunction = layout.calculateChildBoxes;
  7808. layout.calculateChildBoxes = function(visibleItems, targetSize) {
  7809. var calcs = origFunction.apply(layout, arguments),
  7810. meta = calcs.meta,
  7811. items = me.menuItems;
  7812. //calculate the width of the items currently hidden solely because there is not enough space
  7813. //to display them
  7814. var hiddenWidth = 0;
  7815. for (var index = 0, length = items.length; index < length; index++) {
  7816. hiddenWidth += items[index].width;
  7817. }
  7818. meta.minimumWidth += hiddenWidth;
  7819. meta.tooNarrow = meta.minimumWidth > targetSize.width;
  7820. return calcs;
  7821. };
  7822. },
  7823. handleOverflow: function(calculations, targetSize) {
  7824. this.showTrigger();
  7825. var newWidth = targetSize.width - this.afterCt.getWidth(),
  7826. boxes = calculations.boxes,
  7827. usedWidth = 0,
  7828. recalculate = false;
  7829. //calculate the width of all visible items and any spare width
  7830. for (var index = 0, length = boxes.length; index < length; index++) {
  7831. usedWidth += boxes[index].width;
  7832. }
  7833. var spareWidth = newWidth - usedWidth,
  7834. showCount = 0;
  7835. //see if we can re-show any of the hidden components
  7836. for (var index = 0, length = this.menuItems.length; index < length; index++) {
  7837. var hidden = this.menuItems[index],
  7838. comp = hidden.component,
  7839. width = hidden.width;
  7840. if (width < spareWidth) {
  7841. comp.show();
  7842. spareWidth -= width;
  7843. showCount ++;
  7844. recalculate = true;
  7845. } else {
  7846. break;
  7847. }
  7848. }
  7849. if (recalculate) {
  7850. this.menuItems = this.menuItems.slice(showCount);
  7851. } else {
  7852. for (var i = boxes.length - 1; i >= 0; i--) {
  7853. var item = boxes[i].component,
  7854. right = boxes[i].left + boxes[i].width;
  7855. if (right >= newWidth) {
  7856. this.menuItems.unshift({
  7857. component: item,
  7858. width : boxes[i].width
  7859. });
  7860. item.hide();
  7861. } else {
  7862. break;
  7863. }
  7864. }
  7865. }
  7866. if (this.menuItems.length == 0) {
  7867. this.hideTrigger();
  7868. }
  7869. return {
  7870. targetSize: {
  7871. height: targetSize.height,
  7872. width : newWidth
  7873. },
  7874. recalculate: recalculate
  7875. };
  7876. }
  7877. });
  7878. Ext.layout.boxOverflow.menu.hbox = Ext.layout.boxOverflow.HorizontalMenu;/**
  7879. * @class Ext.layout.boxOverflow.Scroller
  7880. * @extends Ext.layout.boxOverflow.None
  7881. * Description
  7882. */
  7883. Ext.layout.boxOverflow.Scroller = Ext.extend(Ext.layout.boxOverflow.None, {
  7884. /**
  7885. * @cfg animateScroll
  7886. * @type Boolean
  7887. * True to animate the scrolling of items within the layout (defaults to true, ignored if enableScroll is false)
  7888. */
  7889. animateScroll: true,
  7890. /**
  7891. * @cfg scrollIncrement
  7892. * @type Number
  7893. * The number of pixels to scroll by on scroller click (defaults to 100)
  7894. */
  7895. scrollIncrement: 100,
  7896. /**
  7897. * @cfg wheelIncrement
  7898. * @type Number
  7899. * The number of pixels to increment on mouse wheel scrolling (defaults to <tt>3</tt>).
  7900. */
  7901. wheelIncrement: 3,
  7902. /**
  7903. * @cfg scrollRepeatInterval
  7904. * @type Number
  7905. * Number of milliseconds between each scroll while a scroller button is held down (defaults to 400)
  7906. */
  7907. scrollRepeatInterval: 400,
  7908. /**
  7909. * @cfg scrollDuration
  7910. * @type Number
  7911. * Number of seconds that each scroll animation lasts (defaults to 0.4)
  7912. */
  7913. scrollDuration: 0.4,
  7914. /**
  7915. * @cfg beforeCls
  7916. * @type String
  7917. * CSS class added to the beforeCt element. This is the element that holds any special items such as scrollers,
  7918. * which must always be present at the leftmost edge of the Container
  7919. */
  7920. beforeCls: 'x-strip-left',
  7921. /**
  7922. * @cfg afterCls
  7923. * @type String
  7924. * CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
  7925. * which must always be present at the rightmost edge of the Container
  7926. */
  7927. afterCls: 'x-strip-right',
  7928. /**
  7929. * @cfg scrollerCls
  7930. * @type String
  7931. * CSS class added to both scroller elements if enableScroll is used
  7932. */
  7933. scrollerCls: 'x-strip-scroller',
  7934. /**
  7935. * @cfg beforeScrollerCls
  7936. * @type String
  7937. * CSS class added to the left scroller element if enableScroll is used
  7938. */
  7939. beforeScrollerCls: 'x-strip-scroller-left',
  7940. /**
  7941. * @cfg afterScrollerCls
  7942. * @type String
  7943. * CSS class added to the right scroller element if enableScroll is used
  7944. */
  7945. afterScrollerCls: 'x-strip-scroller-right',
  7946. /**
  7947. * @private
  7948. * Sets up an listener to scroll on the layout's innerCt mousewheel event
  7949. */
  7950. createWheelListener: function() {
  7951. this.layout.innerCt.on({
  7952. scope : this,
  7953. mousewheel: function(e) {
  7954. e.stopEvent();
  7955. this.scrollBy(e.getWheelDelta() * this.wheelIncrement * -1, false);
  7956. }
  7957. });
  7958. },
  7959. /**
  7960. * @private
  7961. * Most of the heavy lifting is done in the subclasses
  7962. */
  7963. handleOverflow: function(calculations, targetSize) {
  7964. this.createInnerElements();
  7965. this.showScrollers();
  7966. },
  7967. /**
  7968. * @private
  7969. */
  7970. clearOverflow: function() {
  7971. this.hideScrollers();
  7972. },
  7973. /**
  7974. * @private
  7975. * Shows the scroller elements in the beforeCt and afterCt. Creates the scrollers first if they are not already
  7976. * present.
  7977. */
  7978. showScrollers: function() {
  7979. this.createScrollers();
  7980. this.beforeScroller.show();
  7981. this.afterScroller.show();
  7982. this.updateScrollButtons();
  7983. },
  7984. /**
  7985. * @private
  7986. * Hides the scroller elements in the beforeCt and afterCt
  7987. */
  7988. hideScrollers: function() {
  7989. if (this.beforeScroller != undefined) {
  7990. this.beforeScroller.hide();
  7991. this.afterScroller.hide();
  7992. }
  7993. },
  7994. /**
  7995. * @private
  7996. * Creates the clickable scroller elements and places them into the beforeCt and afterCt
  7997. */
  7998. createScrollers: function() {
  7999. if (!this.beforeScroller && !this.afterScroller) {
  8000. var before = this.beforeCt.createChild({
  8001. cls: String.format("{0} {1} ", this.scrollerCls, this.beforeScrollerCls)
  8002. });
  8003. var after = this.afterCt.createChild({
  8004. cls: String.format("{0} {1}", this.scrollerCls, this.afterScrollerCls)
  8005. });
  8006. before.addClassOnOver(this.beforeScrollerCls + '-hover');
  8007. after.addClassOnOver(this.afterScrollerCls + '-hover');
  8008. before.setVisibilityMode(Ext.Element.DISPLAY);
  8009. after.setVisibilityMode(Ext.Element.DISPLAY);
  8010. this.beforeRepeater = new Ext.util.ClickRepeater(before, {
  8011. interval: this.scrollRepeatInterval,
  8012. handler : this.scrollLeft,
  8013. scope : this
  8014. });
  8015. this.afterRepeater = new Ext.util.ClickRepeater(after, {
  8016. interval: this.scrollRepeatInterval,
  8017. handler : this.scrollRight,
  8018. scope : this
  8019. });
  8020. /**
  8021. * @property beforeScroller
  8022. * @type Ext.Element
  8023. * The left scroller element. Only created when needed.
  8024. */
  8025. this.beforeScroller = before;
  8026. /**
  8027. * @property afterScroller
  8028. * @type Ext.Element
  8029. * The left scroller element. Only created when needed.
  8030. */
  8031. this.afterScroller = after;
  8032. }
  8033. },
  8034. /**
  8035. * @private
  8036. */
  8037. destroy: function() {
  8038. Ext.destroy(this.beforeScroller, this.afterScroller, this.beforeRepeater, this.afterRepeater, this.beforeCt, this.afterCt);
  8039. },
  8040. /**
  8041. * @private
  8042. * Scrolls left or right by the number of pixels specified
  8043. * @param {Number} delta Number of pixels to scroll to the right by. Use a negative number to scroll left
  8044. */
  8045. scrollBy: function(delta, animate) {
  8046. this.scrollTo(this.getScrollPosition() + delta, animate);
  8047. },
  8048. /**
  8049. * @private
  8050. * Normalizes an item reference, string id or numerical index into a reference to the item
  8051. * @param {Ext.Component|String|Number} item The item reference, id or index
  8052. * @return {Ext.Component} The item
  8053. */
  8054. getItem: function(item) {
  8055. if (Ext.isString(item)) {
  8056. item = Ext.getCmp(item);
  8057. } else if (Ext.isNumber(item)) {
  8058. item = this.items[item];
  8059. }
  8060. return item;
  8061. },
  8062. /**
  8063. * @private
  8064. * @return {Object} Object passed to scrollTo when scrolling
  8065. */
  8066. getScrollAnim: function() {
  8067. return {
  8068. duration: this.scrollDuration,
  8069. callback: this.updateScrollButtons,
  8070. scope : this
  8071. };
  8072. },
  8073. /**
  8074. * @private
  8075. * Enables or disables each scroller button based on the current scroll position
  8076. */
  8077. updateScrollButtons: function() {
  8078. if (this.beforeScroller == undefined || this.afterScroller == undefined) {
  8079. return;
  8080. }
  8081. var beforeMeth = this.atExtremeBefore() ? 'addClass' : 'removeClass',
  8082. afterMeth = this.atExtremeAfter() ? 'addClass' : 'removeClass',
  8083. beforeCls = this.beforeScrollerCls + '-disabled',
  8084. afterCls = this.afterScrollerCls + '-disabled';
  8085. this.beforeScroller[beforeMeth](beforeCls);
  8086. this.afterScroller[afterMeth](afterCls);
  8087. this.scrolling = false;
  8088. },
  8089. /**
  8090. * @private
  8091. * Returns true if the innerCt scroll is already at its left-most point
  8092. * @return {Boolean} True if already at furthest left point
  8093. */
  8094. atExtremeBefore: function() {
  8095. return this.getScrollPosition() === 0;
  8096. },
  8097. /**
  8098. * @private
  8099. * Scrolls to the left by the configured amount
  8100. */
  8101. scrollLeft: function(animate) {
  8102. this.scrollBy(-this.scrollIncrement, animate);
  8103. },
  8104. /**
  8105. * @private
  8106. * Scrolls to the right by the configured amount
  8107. */
  8108. scrollRight: function(animate) {
  8109. this.scrollBy(this.scrollIncrement, animate);
  8110. },
  8111. /**
  8112. * Scrolls to the given component.
  8113. * @param {String|Number|Ext.Component} item The item to scroll to. Can be a numerical index, component id
  8114. * or a reference to the component itself.
  8115. * @param {Boolean} animate True to animate the scrolling
  8116. */
  8117. scrollToItem: function(item, animate) {
  8118. item = this.getItem(item);
  8119. if (item != undefined) {
  8120. var visibility = this.getItemVisibility(item);
  8121. if (!visibility.fullyVisible) {
  8122. var box = item.getBox(true, true),
  8123. newX = box.x;
  8124. if (visibility.hiddenRight) {
  8125. newX -= (this.layout.innerCt.getWidth() - box.width);
  8126. }
  8127. this.scrollTo(newX, animate);
  8128. }
  8129. }
  8130. },
  8131. /**
  8132. * @private
  8133. * For a given item in the container, return an object with information on whether the item is visible
  8134. * with the current innerCt scroll value.
  8135. * @param {Ext.Component} item The item
  8136. * @return {Object} Values for fullyVisible, hiddenLeft and hiddenRight
  8137. */
  8138. getItemVisibility: function(item) {
  8139. var box = this.getItem(item).getBox(true, true),
  8140. itemLeft = box.x,
  8141. itemRight = box.x + box.width,
  8142. scrollLeft = this.getScrollPosition(),
  8143. scrollRight = this.layout.innerCt.getWidth() + scrollLeft;
  8144. return {
  8145. hiddenLeft : itemLeft < scrollLeft,
  8146. hiddenRight : itemRight > scrollRight,
  8147. fullyVisible: itemLeft > scrollLeft && itemRight < scrollRight
  8148. };
  8149. }
  8150. });
  8151. Ext.layout.boxOverflow.scroller = Ext.layout.boxOverflow.Scroller;
  8152. /**
  8153. * @class Ext.layout.boxOverflow.VerticalScroller
  8154. * @extends Ext.layout.boxOverflow.Scroller
  8155. * Description
  8156. */
  8157. Ext.layout.boxOverflow.VerticalScroller = Ext.extend(Ext.layout.boxOverflow.Scroller, {
  8158. scrollIncrement: 75,
  8159. wheelIncrement : 2,
  8160. handleOverflow: function(calculations, targetSize) {
  8161. Ext.layout.boxOverflow.VerticalScroller.superclass.handleOverflow.apply(this, arguments);
  8162. return {
  8163. targetSize: {
  8164. height: targetSize.height - (this.beforeCt.getHeight() + this.afterCt.getHeight()),
  8165. width : targetSize.width
  8166. }
  8167. };
  8168. },
  8169. /**
  8170. * @private
  8171. * Creates the beforeCt and afterCt elements if they have not already been created
  8172. */
  8173. createInnerElements: function() {
  8174. var target = this.layout.innerCt;
  8175. //normal items will be rendered to the innerCt. beforeCt and afterCt allow for fixed positioning of
  8176. //special items such as scrollers or dropdown menu triggers
  8177. if (!this.beforeCt) {
  8178. this.beforeCt = target.insertSibling({cls: this.beforeCls}, 'before');
  8179. this.afterCt = target.insertSibling({cls: this.afterCls}, 'after');
  8180. this.createWheelListener();
  8181. }
  8182. },
  8183. /**
  8184. * @private
  8185. * Scrolls to the given position. Performs bounds checking.
  8186. * @param {Number} position The position to scroll to. This is constrained.
  8187. * @param {Boolean} animate True to animate. If undefined, falls back to value of this.animateScroll
  8188. */
  8189. scrollTo: function(position, animate) {
  8190. var oldPosition = this.getScrollPosition(),
  8191. newPosition = position.constrain(0, this.getMaxScrollBottom());
  8192. if (newPosition != oldPosition && !this.scrolling) {
  8193. if (animate == undefined) {
  8194. animate = this.animateScroll;
  8195. }
  8196. this.layout.innerCt.scrollTo('top', newPosition, animate ? this.getScrollAnim() : false);
  8197. if (animate) {
  8198. this.scrolling = true;
  8199. } else {
  8200. this.scrolling = false;
  8201. this.updateScrollButtons();
  8202. }
  8203. }
  8204. },
  8205. /**
  8206. * Returns the current scroll position of the innerCt element
  8207. * @return {Number} The current scroll position
  8208. */
  8209. getScrollPosition: function(){
  8210. return parseInt(this.layout.innerCt.dom.scrollTop, 10) || 0;
  8211. },
  8212. /**
  8213. * @private
  8214. * Returns the maximum value we can scrollTo
  8215. * @return {Number} The max scroll value
  8216. */
  8217. getMaxScrollBottom: function() {
  8218. return this.layout.innerCt.dom.scrollHeight - this.layout.innerCt.getHeight();
  8219. },
  8220. /**
  8221. * @private
  8222. * Returns true if the innerCt scroll is already at its right-most point
  8223. * @return {Boolean} True if already at furthest right point
  8224. */
  8225. atExtremeAfter: function() {
  8226. return this.getScrollPosition() >= this.getMaxScrollBottom();
  8227. }
  8228. });
  8229. Ext.layout.boxOverflow.scroller.vbox = Ext.layout.boxOverflow.VerticalScroller;
  8230. /**
  8231. * @class Ext.layout.boxOverflow.HorizontalScroller
  8232. * @extends Ext.layout.boxOverflow.Scroller
  8233. * Description
  8234. */
  8235. Ext.layout.boxOverflow.HorizontalScroller = Ext.extend(Ext.layout.boxOverflow.Scroller, {
  8236. handleOverflow: function(calculations, targetSize) {
  8237. Ext.layout.boxOverflow.HorizontalScroller.superclass.handleOverflow.apply(this, arguments);
  8238. return {
  8239. targetSize: {
  8240. height: targetSize.height,
  8241. width : targetSize.width - (this.beforeCt.getWidth() + this.afterCt.getWidth())
  8242. }
  8243. };
  8244. },
  8245. /**
  8246. * @private
  8247. * Creates the beforeCt and afterCt elements if they have not already been created
  8248. */
  8249. createInnerElements: function() {
  8250. var target = this.layout.innerCt;
  8251. //normal items will be rendered to the innerCt. beforeCt and afterCt allow for fixed positioning of
  8252. //special items such as scrollers or dropdown menu triggers
  8253. if (!this.beforeCt) {
  8254. this.afterCt = target.insertSibling({cls: this.afterCls}, 'before');
  8255. this.beforeCt = target.insertSibling({cls: this.beforeCls}, 'before');
  8256. this.createWheelListener();
  8257. }
  8258. },
  8259. /**
  8260. * @private
  8261. * Scrolls to the given position. Performs bounds checking.
  8262. * @param {Number} position The position to scroll to. This is constrained.
  8263. * @param {Boolean} animate True to animate. If undefined, falls back to value of this.animateScroll
  8264. */
  8265. scrollTo: function(position, animate) {
  8266. var oldPosition = this.getScrollPosition(),
  8267. newPosition = position.constrain(0, this.getMaxScrollRight());
  8268. if (newPosition != oldPosition && !this.scrolling) {
  8269. if (animate == undefined) {
  8270. animate = this.animateScroll;
  8271. }
  8272. this.layout.innerCt.scrollTo('left', newPosition, animate ? this.getScrollAnim() : false);
  8273. if (animate) {
  8274. this.scrolling = true;
  8275. } else {
  8276. this.scrolling = false;
  8277. this.updateScrollButtons();
  8278. }
  8279. }
  8280. },
  8281. /**
  8282. * Returns the current scroll position of the innerCt element
  8283. * @return {Number} The current scroll position
  8284. */
  8285. getScrollPosition: function(){
  8286. return parseInt(this.layout.innerCt.dom.scrollLeft, 10) || 0;
  8287. },
  8288. /**
  8289. * @private
  8290. * Returns the maximum value we can scrollTo
  8291. * @return {Number} The max scroll value
  8292. */
  8293. getMaxScrollRight: function() {
  8294. return this.layout.innerCt.dom.scrollWidth - this.layout.innerCt.getWidth();
  8295. },
  8296. /**
  8297. * @private
  8298. * Returns true if the innerCt scroll is already at its right-most point
  8299. * @return {Boolean} True if already at furthest right point
  8300. */
  8301. atExtremeAfter: function() {
  8302. return this.getScrollPosition() >= this.getMaxScrollRight();
  8303. }
  8304. });
  8305. Ext.layout.boxOverflow.scroller.hbox = Ext.layout.boxOverflow.HorizontalScroller;/**
  8306. * @class Ext.layout.HBoxLayout
  8307. * @extends Ext.layout.BoxLayout
  8308. * <p>A layout that arranges items horizontally across a Container. This layout optionally divides available horizontal
  8309. * space between child items containing a numeric <code>flex</code> configuration.</p>
  8310. * This layout may also be used to set the heights of child items by configuring it with the {@link #align} option.
  8311. */
  8312. Ext.layout.HBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
  8313. /**
  8314. * @cfg {String} align
  8315. * Controls how the child items of the container are aligned. Acceptable configuration values for this
  8316. * property are:
  8317. * <div class="mdetail-params"><ul>
  8318. * <li><b><tt>top</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned vertically
  8319. * at the <b>top</b> of the container</div></li>
  8320. * <li><b><tt>middle</tt></b> : <div class="sub-desc">child items are aligned vertically in the
  8321. * <b>middle</b> of the container</div></li>
  8322. * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched vertically to fill
  8323. * the height of the container</div></li>
  8324. * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched vertically to
  8325. * the height of the largest item.</div></li>
  8326. * </ul></div>
  8327. */
  8328. align: 'top', // top, middle, stretch, strechmax
  8329. type : 'hbox',
  8330. /**
  8331. * @cfg {String} pack
  8332. * Controls how the child items of the container are packed together. Acceptable configuration values
  8333. * for this property are:
  8334. * <div class="mdetail-params"><ul>
  8335. * <li><b><tt>start</tt></b> : <b>Default</b><div class="sub-desc">child items are packed together at
  8336. * <b>left</b> side of container</div></li>
  8337. * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are packed together at
  8338. * <b>mid-width</b> of container</div></li>
  8339. * <li><b><tt>end</tt></b> : <div class="sub-desc">child items are packed together at <b>right</b>
  8340. * side of container</div></li>
  8341. * </ul></div>
  8342. */
  8343. /**
  8344. * @cfg {Number} flex
  8345. * This configuation option is to be applied to <b>child <tt>items</tt></b> of the container managed
  8346. * by this layout. Each child item with a <tt>flex</tt> property will be flexed <b>horizontally</b>
  8347. * according to each item's <b>relative</b> <tt>flex</tt> value compared to the sum of all items with
  8348. * a <tt>flex</tt> value specified. Any child items that have either a <tt>flex = 0</tt> or
  8349. * <tt>flex = undefined</tt> will not be 'flexed' (the initial size will not be changed).
  8350. */
  8351. /**
  8352. * @private
  8353. * Calculates the size and positioning of each item in the HBox. This iterates over all of the rendered,
  8354. * visible items and returns a height, width, top and left for each, as well as a reference to each. Also
  8355. * returns meta data such as maxHeight which are useful when resizing layout wrappers such as this.innerCt.
  8356. * @param {Array} visibleItems The array of all rendered, visible items to be calculated for
  8357. * @param {Object} targetSize Object containing target size and height
  8358. * @return {Object} Object containing box measurements for each child, plus meta data
  8359. */
  8360. calculateChildBoxes: function(visibleItems, targetSize) {
  8361. var visibleCount = visibleItems.length,
  8362. padding = this.padding,
  8363. topOffset = padding.top,
  8364. leftOffset = padding.left,
  8365. paddingVert = topOffset + padding.bottom,
  8366. paddingHoriz = leftOffset + padding.right,
  8367. width = targetSize.width - this.scrollOffset,
  8368. height = targetSize.height,
  8369. availHeight = Math.max(0, height - paddingVert),
  8370. isStart = this.pack == 'start',
  8371. isCenter = this.pack == 'center',
  8372. isEnd = this.pack == 'end',
  8373. nonFlexWidth = 0,
  8374. maxHeight = 0,
  8375. totalFlex = 0,
  8376. desiredWidth = 0,
  8377. minimumWidth = 0,
  8378. //used to cache the calculated size and position values for each child item
  8379. boxes = [],
  8380. //used in the for loops below, just declared here for brevity
  8381. child, childWidth, childHeight, childSize, childMargins, canLayout, i, calcs, flexedWidth,
  8382. horizMargins, vertMargins, stretchHeight;
  8383. //gather the total flex of all flexed items and the width taken up by fixed width items
  8384. for (i = 0; i < visibleCount; i++) {
  8385. child = visibleItems[i];
  8386. childHeight = child.height;
  8387. childWidth = child.width;
  8388. canLayout = !child.hasLayout && typeof child.doLayout == 'function';
  8389. // Static width (numeric) requires no calcs
  8390. if (typeof childWidth != 'number') {
  8391. // flex and not 'auto' width
  8392. if (child.flex && !childWidth) {
  8393. totalFlex += child.flex;
  8394. // Not flexed or 'auto' width or undefined width
  8395. } else {
  8396. //Render and layout sub-containers without a flex or width defined, as otherwise we
  8397. //don't know how wide the sub-container should be and cannot calculate flexed widths
  8398. if (!childWidth && canLayout) {
  8399. child.doLayout();
  8400. }
  8401. childSize = child.getSize();
  8402. childWidth = childSize.width;
  8403. childHeight = childSize.height;
  8404. }
  8405. }
  8406. childMargins = child.margins;
  8407. horizMargins = childMargins.left + childMargins.right;
  8408. nonFlexWidth += horizMargins + (childWidth || 0);
  8409. desiredWidth += horizMargins + (child.flex ? child.minWidth || 0 : childWidth);
  8410. minimumWidth += horizMargins + (child.minWidth || childWidth || 0);
  8411. // Max height for align - force layout of non-laid out subcontainers without a numeric height
  8412. if (typeof childHeight != 'number') {
  8413. if (canLayout) {
  8414. child.doLayout();
  8415. }
  8416. childHeight = child.getHeight();
  8417. }
  8418. maxHeight = Math.max(maxHeight, childHeight + childMargins.top + childMargins.bottom);
  8419. //cache the size of each child component. Don't set height or width to 0, keep undefined instead
  8420. boxes.push({
  8421. component: child,
  8422. height : childHeight || undefined,
  8423. width : childWidth || undefined
  8424. });
  8425. }
  8426. var shortfall = desiredWidth - width,
  8427. tooNarrow = minimumWidth > width;
  8428. //the width available to the flexed items
  8429. var availableWidth = Math.max(0, width - nonFlexWidth - paddingHoriz);
  8430. if (tooNarrow) {
  8431. for (i = 0; i < visibleCount; i++) {
  8432. boxes[i].width = visibleItems[i].minWidth || visibleItems[i].width || boxes[i].width;
  8433. }
  8434. } else {
  8435. //all flexed items should be sized to their minimum width, other items should be shrunk down until
  8436. //the shortfall has been accounted for
  8437. if (shortfall > 0) {
  8438. var minWidths = [];
  8439. // When we have a shortfall but are not tooNarrow, we need to shrink the width of each non-flexed item.
  8440. // Flexed items are immediately reduced to their minWidth and anything already at minWidth is ignored.
  8441. // The remaining items are collected into the minWidths array, which is later used to distribute the shortfall.
  8442. for (var index = 0, length = visibleCount; index < length; index++) {
  8443. var item = visibleItems[index],
  8444. minWidth = item.minWidth || 0;
  8445. //shrink each non-flex tab by an equal amount to make them all fit. Flexed items are all
  8446. //shrunk to their minWidth because they're flexible and should be the first to lose width
  8447. if (item.flex) {
  8448. boxes[index].width = minWidth;
  8449. } else {
  8450. minWidths.push({
  8451. minWidth : minWidth,
  8452. available: boxes[index].width - minWidth,
  8453. index : index
  8454. });
  8455. }
  8456. }
  8457. //sort by descending amount of width remaining before minWidth is reached
  8458. minWidths.sort(function(a, b) {
  8459. return a.available > b.available ? 1 : -1;
  8460. });
  8461. /*
  8462. * Distribute the shortfall (difference between total desired with of all items and actual width available)
  8463. * between the non-flexed items. We try to distribute the shortfall evenly, but apply it to items with the
  8464. * smallest difference between their width and minWidth first, so that if reducing the width by the average
  8465. * amount would make that item less than its minWidth, we carry the remainder over to the next item.
  8466. */
  8467. for (var i = 0, length = minWidths.length; i < length; i++) {
  8468. var itemIndex = minWidths[i].index;
  8469. if (itemIndex == undefined) {
  8470. continue;
  8471. }
  8472. var item = visibleItems[itemIndex],
  8473. box = boxes[itemIndex],
  8474. oldWidth = box.width,
  8475. minWidth = item.minWidth,
  8476. newWidth = Math.max(minWidth, oldWidth - Math.ceil(shortfall / (length - i))),
  8477. reduction = oldWidth - newWidth;
  8478. boxes[itemIndex].width = newWidth;
  8479. shortfall -= reduction;
  8480. }
  8481. } else {
  8482. //temporary variables used in the flex width calculations below
  8483. var remainingWidth = availableWidth,
  8484. remainingFlex = totalFlex;
  8485. //calculate the widths of each flexed item
  8486. for (i = 0; i < visibleCount; i++) {
  8487. child = visibleItems[i];
  8488. calcs = boxes[i];
  8489. childMargins = child.margins;
  8490. vertMargins = childMargins.top + childMargins.bottom;
  8491. if (isStart && child.flex && !child.width) {
  8492. flexedWidth = Math.ceil((child.flex / remainingFlex) * remainingWidth);
  8493. remainingWidth -= flexedWidth;
  8494. remainingFlex -= child.flex;
  8495. calcs.width = flexedWidth;
  8496. calcs.dirtySize = true;
  8497. }
  8498. }
  8499. }
  8500. }
  8501. if (isCenter) {
  8502. leftOffset += availableWidth / 2;
  8503. } else if (isEnd) {
  8504. leftOffset += availableWidth;
  8505. }
  8506. //finally, calculate the left and top position of each item
  8507. for (i = 0; i < visibleCount; i++) {
  8508. child = visibleItems[i];
  8509. calcs = boxes[i];
  8510. childMargins = child.margins;
  8511. leftOffset += childMargins.left;
  8512. vertMargins = childMargins.top + childMargins.bottom;
  8513. calcs.left = leftOffset;
  8514. calcs.top = topOffset + childMargins.top;
  8515. switch (this.align) {
  8516. case 'stretch':
  8517. stretchHeight = availHeight - vertMargins;
  8518. calcs.height = stretchHeight.constrain(child.minHeight || 0, child.maxHeight || 1000000);
  8519. calcs.dirtySize = true;
  8520. break;
  8521. case 'stretchmax':
  8522. stretchHeight = maxHeight - vertMargins;
  8523. calcs.height = stretchHeight.constrain(child.minHeight || 0, child.maxHeight || 1000000);
  8524. calcs.dirtySize = true;
  8525. break;
  8526. case 'middle':
  8527. var diff = availHeight - calcs.height - vertMargins;
  8528. if (diff > 0) {
  8529. calcs.top = topOffset + vertMargins + (diff / 2);
  8530. }
  8531. }
  8532. leftOffset += calcs.width + childMargins.right;
  8533. }
  8534. return {
  8535. boxes: boxes,
  8536. meta : {
  8537. maxHeight : maxHeight,
  8538. nonFlexWidth: nonFlexWidth,
  8539. desiredWidth: desiredWidth,
  8540. minimumWidth: minimumWidth,
  8541. shortfall : desiredWidth - width,
  8542. tooNarrow : tooNarrow
  8543. }
  8544. };
  8545. }
  8546. });
  8547. Ext.Container.LAYOUTS.hbox = Ext.layout.HBoxLayout;/**
  8548. * @class Ext.layout.VBoxLayout
  8549. * @extends Ext.layout.BoxLayout
  8550. * <p>A layout that arranges items vertically down a Container. This layout optionally divides available vertical
  8551. * space between child items containing a numeric <code>flex</code> configuration.</p>
  8552. * This layout may also be used to set the widths of child items by configuring it with the {@link #align} option.
  8553. */
  8554. Ext.layout.VBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
  8555. /**
  8556. * @cfg {String} align
  8557. * Controls how the child items of the container are aligned. Acceptable configuration values for this
  8558. * property are:
  8559. * <div class="mdetail-params"><ul>
  8560. * <li><b><tt>left</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned horizontally
  8561. * at the <b>left</b> side of the container</div></li>
  8562. * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are aligned horizontally at the
  8563. * <b>mid-width</b> of the container</div></li>
  8564. * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched horizontally to fill
  8565. * the width of the container</div></li>
  8566. * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched horizontally to
  8567. * the size of the largest item.</div></li>
  8568. * </ul></div>
  8569. */
  8570. align : 'left', // left, center, stretch, strechmax
  8571. type: 'vbox',
  8572. /**
  8573. * @cfg {String} pack
  8574. * Controls how the child items of the container are packed together. Acceptable configuration values
  8575. * for this property are:
  8576. * <div class="mdetail-params"><ul>
  8577. * <li><b><tt>start</tt></b> : <b>Default</b><div class="sub-desc">child items are packed together at
  8578. * <b>top</b> side of container</div></li>
  8579. * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are packed together at
  8580. * <b>mid-height</b> of container</div></li>
  8581. * <li><b><tt>end</tt></b> : <div class="sub-desc">child items are packed together at <b>bottom</b>
  8582. * side of container</div></li>
  8583. * </ul></div>
  8584. */
  8585. /**
  8586. * @cfg {Number} flex
  8587. * This configuation option is to be applied to <b>child <tt>items</tt></b> of the container managed
  8588. * by this layout. Each child item with a <tt>flex</tt> property will be flexed <b>vertically</b>
  8589. * according to each item's <b>relative</b> <tt>flex</tt> value compared to the sum of all items with
  8590. * a <tt>flex</tt> value specified. Any child items that have either a <tt>flex = 0</tt> or
  8591. * <tt>flex = undefined</tt> will not be 'flexed' (the initial size will not be changed).
  8592. */
  8593. /**
  8594. * @private
  8595. * Calculates the size and positioning of each item in the VBox. This iterates over all of the rendered,
  8596. * visible items and returns a height, width, top and left for each, as well as a reference to each. Also
  8597. * returns meta data such as maxHeight which are useful when resizing layout wrappers such as this.innerCt.
  8598. * @param {Array} visibleItems The array of all rendered, visible items to be calculated for
  8599. * @param {Object} targetSize Object containing target size and height
  8600. * @return {Object} Object containing box measurements for each child, plus meta data
  8601. */
  8602. calculateChildBoxes: function(visibleItems, targetSize) {
  8603. var visibleCount = visibleItems.length,
  8604. padding = this.padding,
  8605. topOffset = padding.top,
  8606. leftOffset = padding.left,
  8607. paddingVert = topOffset + padding.bottom,
  8608. paddingHoriz = leftOffset + padding.right,
  8609. width = targetSize.width - this.scrollOffset,
  8610. height = targetSize.height,
  8611. availWidth = Math.max(0, width - paddingHoriz),
  8612. isStart = this.pack == 'start',
  8613. isCenter = this.pack == 'center',
  8614. isEnd = this.pack == 'end',
  8615. nonFlexHeight= 0,
  8616. maxWidth = 0,
  8617. totalFlex = 0,
  8618. desiredHeight= 0,
  8619. minimumHeight= 0,
  8620. //used to cache the calculated size and position values for each child item
  8621. boxes = [],
  8622. //used in the for loops below, just declared here for brevity
  8623. child, childWidth, childHeight, childSize, childMargins, canLayout, i, calcs, flexedHeight,
  8624. horizMargins, vertMargins, stretchWidth, length;
  8625. //gather the total flex of all flexed items and the width taken up by fixed width items
  8626. for (i = 0; i < visibleCount; i++) {
  8627. child = visibleItems[i];
  8628. childHeight = child.height;
  8629. childWidth = child.width;
  8630. canLayout = !child.hasLayout && typeof child.doLayout == 'function';
  8631. // Static height (numeric) requires no calcs
  8632. if (typeof childHeight != 'number') {
  8633. // flex and not 'auto' height
  8634. if (child.flex && !childHeight) {
  8635. totalFlex += child.flex;
  8636. // Not flexed or 'auto' height or undefined height
  8637. } else {
  8638. //Render and layout sub-containers without a flex or width defined, as otherwise we
  8639. //don't know how wide the sub-container should be and cannot calculate flexed widths
  8640. if (!childHeight && canLayout) {
  8641. child.doLayout();
  8642. }
  8643. childSize = child.getSize();
  8644. childWidth = childSize.width;
  8645. childHeight = childSize.height;
  8646. }
  8647. }
  8648. childMargins = child.margins;
  8649. vertMargins = childMargins.top + childMargins.bottom;
  8650. nonFlexHeight += vertMargins + (childHeight || 0);
  8651. desiredHeight += vertMargins + (child.flex ? child.minHeight || 0 : childHeight);
  8652. minimumHeight += vertMargins + (child.minHeight || childHeight || 0);
  8653. // Max width for align - force layout of non-layed out subcontainers without a numeric width
  8654. if (typeof childWidth != 'number') {
  8655. if (canLayout) {
  8656. child.doLayout();
  8657. }
  8658. childWidth = child.getWidth();
  8659. }
  8660. maxWidth = Math.max(maxWidth, childWidth + childMargins.left + childMargins.right);
  8661. //cache the size of each child component
  8662. boxes.push({
  8663. component: child,
  8664. height : childHeight || undefined,
  8665. width : childWidth || undefined
  8666. });
  8667. }
  8668. var shortfall = desiredHeight - height,
  8669. tooNarrow = minimumHeight > height;
  8670. //the height available to the flexed items
  8671. var availableHeight = Math.max(0, (height - nonFlexHeight - paddingVert));
  8672. if (tooNarrow) {
  8673. for (i = 0, length = visibleCount; i < length; i++) {
  8674. boxes[i].height = visibleItems[i].minHeight || visibleItems[i].height || boxes[i].height;
  8675. }
  8676. } else {
  8677. //all flexed items should be sized to their minimum width, other items should be shrunk down until
  8678. //the shortfall has been accounted for
  8679. if (shortfall > 0) {
  8680. var minHeights = [];
  8681. // When we have a shortfall but are not tooNarrow, we need to shrink the height of each non-flexed item.
  8682. // Flexed items are immediately reduced to their minHeight and anything already at minHeight is ignored.
  8683. // The remaining items are collected into the minHeights array, which is later used to distribute the shortfall.
  8684. for (var index = 0, length = visibleCount; index < length; index++) {
  8685. var item = visibleItems[index],
  8686. minHeight = item.minHeight || 0;
  8687. //shrink each non-flex tab by an equal amount to make them all fit. Flexed items are all
  8688. //shrunk to their minHeight because they're flexible and should be the first to lose height
  8689. if (item.flex) {
  8690. boxes[index].height = minHeight;
  8691. } else {
  8692. minHeights.push({
  8693. minHeight: minHeight,
  8694. available: boxes[index].height - minHeight,
  8695. index : index
  8696. });
  8697. }
  8698. }
  8699. //sort by descending minHeight value
  8700. minHeights.sort(function(a, b) {
  8701. return a.available > b.available ? 1 : -1;
  8702. });
  8703. /*
  8704. * Distribute the shortfall (difference between total desired with of all items and actual height available)
  8705. * between the non-flexed items. We try to distribute the shortfall evenly, but apply it to items with the
  8706. * smallest difference between their height and minHeight first, so that if reducing the height by the average
  8707. * amount would make that item less than its minHeight, we carry the remainder over to the next item.
  8708. */
  8709. for (var i = 0, length = minHeights.length; i < length; i++) {
  8710. var itemIndex = minHeights[i].index;
  8711. if (itemIndex == undefined) {
  8712. continue;
  8713. }
  8714. var item = visibleItems[itemIndex],
  8715. box = boxes[itemIndex],
  8716. oldHeight = box.height,
  8717. minHeight = item.minHeight,
  8718. newHeight = Math.max(minHeight, oldHeight - Math.ceil(shortfall / (length - i))),
  8719. reduction = oldHeight - newHeight;
  8720. boxes[itemIndex].height = newHeight;
  8721. shortfall -= reduction;
  8722. }
  8723. } else {
  8724. //temporary variables used in the flex height calculations below
  8725. var remainingHeight = availableHeight,
  8726. remainingFlex = totalFlex;
  8727. //calculate the height of each flexed item
  8728. for (i = 0; i < visibleCount; i++) {
  8729. child = visibleItems[i];
  8730. calcs = boxes[i];
  8731. childMargins = child.margins;
  8732. horizMargins = childMargins.left + childMargins.right;
  8733. if (isStart && child.flex && !child.height) {
  8734. flexedHeight = Math.ceil((child.flex / remainingFlex) * remainingHeight);
  8735. remainingHeight -= flexedHeight;
  8736. remainingFlex -= child.flex;
  8737. calcs.height = flexedHeight;
  8738. calcs.dirtySize = true;
  8739. }
  8740. }
  8741. }
  8742. }
  8743. if (isCenter) {
  8744. topOffset += availableHeight / 2;
  8745. } else if (isEnd) {
  8746. topOffset += availableHeight;
  8747. }
  8748. //finally, calculate the left and top position of each item
  8749. for (i = 0; i < visibleCount; i++) {
  8750. child = visibleItems[i];
  8751. calcs = boxes[i];
  8752. childMargins = child.margins;
  8753. topOffset += childMargins.top;
  8754. horizMargins = childMargins.left + childMargins.right;
  8755. calcs.left = leftOffset + childMargins.left;
  8756. calcs.top = topOffset;
  8757. switch (this.align) {
  8758. case 'stretch':
  8759. stretchWidth = availWidth - horizMargins;
  8760. calcs.width = stretchWidth.constrain(child.minWidth || 0, child.maxWidth || 1000000);
  8761. calcs.dirtySize = true;
  8762. break;
  8763. case 'stretchmax':
  8764. stretchWidth = maxWidth - horizMargins;
  8765. calcs.width = stretchWidth.constrain(child.minWidth || 0, child.maxWidth || 1000000);
  8766. calcs.dirtySize = true;
  8767. break;
  8768. case 'center':
  8769. var diff = availWidth - calcs.width - horizMargins;
  8770. if (diff > 0) {
  8771. calcs.left = leftOffset + horizMargins + (diff / 2);
  8772. }
  8773. }
  8774. topOffset += calcs.height + childMargins.bottom;
  8775. }
  8776. return {
  8777. boxes: boxes,
  8778. meta : {
  8779. maxWidth : maxWidth,
  8780. nonFlexHeight: nonFlexHeight,
  8781. desiredHeight: desiredHeight,
  8782. minimumHeight: minimumHeight,
  8783. shortfall : desiredHeight - height,
  8784. tooNarrow : tooNarrow
  8785. }
  8786. };
  8787. }
  8788. });
  8789. Ext.Container.LAYOUTS.vbox = Ext.layout.VBoxLayout;
  8790. /**
  8791. * @class Ext.layout.ToolbarLayout
  8792. * @extends Ext.layout.ContainerLayout
  8793. * Layout manager used by Ext.Toolbar. This is highly specialised for use by Toolbars and would not
  8794. * usually be used by any other class.
  8795. */
  8796. Ext.layout.ToolbarLayout = Ext.extend(Ext.layout.ContainerLayout, {
  8797. monitorResize : true,
  8798. type: 'toolbar',
  8799. /**
  8800. * @property triggerWidth
  8801. * @type Number
  8802. * The width allocated for the menu trigger at the extreme right end of the Toolbar
  8803. */
  8804. triggerWidth: 18,
  8805. /**
  8806. * @property noItemsMenuText
  8807. * @type String
  8808. * HTML fragment to render into the toolbar overflow menu if there are no items to display
  8809. */
  8810. noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
  8811. /**
  8812. * @private
  8813. * @property lastOverflow
  8814. * @type Boolean
  8815. * Used internally to record whether the last layout caused an overflow or not
  8816. */
  8817. lastOverflow: false,
  8818. /**
  8819. * @private
  8820. * @property tableHTML
  8821. * @type String
  8822. * String used to build the HTML injected to support the Toolbar's layout. The align property is
  8823. * injected into this string inside the td.x-toolbar-left element during onLayout.
  8824. */
  8825. tableHTML: [
  8826. '<table cellspacing="0" class="x-toolbar-ct">',
  8827. '<tbody>',
  8828. '<tr>',
  8829. '<td class="x-toolbar-left" align="{0}">',
  8830. '<table cellspacing="0">',
  8831. '<tbody>',
  8832. '<tr class="x-toolbar-left-row"></tr>',
  8833. '</tbody>',
  8834. '</table>',
  8835. '</td>',
  8836. '<td class="x-toolbar-right" align="right">',
  8837. '<table cellspacing="0" class="x-toolbar-right-ct">',
  8838. '<tbody>',
  8839. '<tr>',
  8840. '<td>',
  8841. '<table cellspacing="0">',
  8842. '<tbody>',
  8843. '<tr class="x-toolbar-right-row"></tr>',
  8844. '</tbody>',
  8845. '</table>',
  8846. '</td>',
  8847. '<td>',
  8848. '<table cellspacing="0">',
  8849. '<tbody>',
  8850. '<tr class="x-toolbar-extras-row"></tr>',
  8851. '</tbody>',
  8852. '</table>',
  8853. '</td>',
  8854. '</tr>',
  8855. '</tbody>',
  8856. '</table>',
  8857. '</td>',
  8858. '</tr>',
  8859. '</tbody>',
  8860. '</table>'
  8861. ].join(""),
  8862. /**
  8863. * @private
  8864. * Create the wrapping Toolbar HTML and render/move all the items into the correct places
  8865. */
  8866. onLayout : function(ct, target) {
  8867. //render the Toolbar <table> HTML if it's not already present
  8868. if (!this.leftTr) {
  8869. var align = ct.buttonAlign == 'center' ? 'center' : 'left';
  8870. target.addClass('x-toolbar-layout-ct');
  8871. target.insertHtml('beforeEnd', String.format(this.tableHTML, align));
  8872. this.leftTr = target.child('tr.x-toolbar-left-row', true);
  8873. this.rightTr = target.child('tr.x-toolbar-right-row', true);
  8874. this.extrasTr = target.child('tr.x-toolbar-extras-row', true);
  8875. if (this.hiddenItem == undefined) {
  8876. /**
  8877. * @property hiddenItems
  8878. * @type Array
  8879. * Holds all items that are currently hidden due to there not being enough space to render them
  8880. * These items will appear on the expand menu.
  8881. */
  8882. this.hiddenItems = [];
  8883. }
  8884. }
  8885. var side = ct.buttonAlign == 'right' ? this.rightTr : this.leftTr,
  8886. items = ct.items.items,
  8887. position = 0;
  8888. //render each item if not already rendered, place it into the correct (left or right) target
  8889. for (var i = 0, len = items.length, c; i < len; i++, position++) {
  8890. c = items[i];
  8891. if (c.isFill) {
  8892. side = this.rightTr;
  8893. position = -1;
  8894. } else if (!c.rendered) {
  8895. c.render(this.insertCell(c, side, position));
  8896. this.configureItem(c);
  8897. } else {
  8898. if (!c.xtbHidden && !this.isValidParent(c, side.childNodes[position])) {
  8899. var td = this.insertCell(c, side, position);
  8900. td.appendChild(c.getPositionEl().dom);
  8901. c.container = Ext.get(td);
  8902. }
  8903. }
  8904. }
  8905. //strip extra empty cells
  8906. this.cleanup(this.leftTr);
  8907. this.cleanup(this.rightTr);
  8908. this.cleanup(this.extrasTr);
  8909. this.fitToSize(target);
  8910. },
  8911. /**
  8912. * @private
  8913. * Removes any empty nodes from the given element
  8914. * @param {Ext.Element} el The element to clean up
  8915. */
  8916. cleanup : function(el) {
  8917. var cn = el.childNodes, i, c;
  8918. for (i = cn.length-1; i >= 0 && (c = cn[i]); i--) {
  8919. if (!c.firstChild) {
  8920. el.removeChild(c);
  8921. }
  8922. }
  8923. },
  8924. /**
  8925. * @private
  8926. * Inserts the given Toolbar item into the given element
  8927. * @param {Ext.Component} c The component to add
  8928. * @param {Ext.Element} target The target to add the component to
  8929. * @param {Number} position The position to add the component at
  8930. */
  8931. insertCell : function(c, target, position) {
  8932. var td = document.createElement('td');
  8933. td.className = 'x-toolbar-cell';
  8934. target.insertBefore(td, target.childNodes[position] || null);
  8935. return td;
  8936. },
  8937. /**
  8938. * @private
  8939. * Hides an item because it will not fit in the available width. The item will be unhidden again
  8940. * if the Toolbar is resized to be large enough to show it
  8941. * @param {Ext.Component} item The item to hide
  8942. */
  8943. hideItem : function(item) {
  8944. this.hiddenItems.push(item);
  8945. item.xtbHidden = true;
  8946. item.xtbWidth = item.getPositionEl().dom.parentNode.offsetWidth;
  8947. item.hide();
  8948. },
  8949. /**
  8950. * @private
  8951. * Unhides an item that was previously hidden due to there not being enough space left on the Toolbar
  8952. * @param {Ext.Component} item The item to show
  8953. */
  8954. unhideItem : function(item) {
  8955. item.show();
  8956. item.xtbHidden = false;
  8957. this.hiddenItems.remove(item);
  8958. },
  8959. /**
  8960. * @private
  8961. * Returns the width of the given toolbar item. If the item is currently hidden because there
  8962. * is not enough room to render it, its previous width is returned
  8963. * @param {Ext.Component} c The component to measure
  8964. * @return {Number} The width of the item
  8965. */
  8966. getItemWidth : function(c) {
  8967. return c.hidden ? (c.xtbWidth || 0) : c.getPositionEl().dom.parentNode.offsetWidth;
  8968. },
  8969. /**
  8970. * @private
  8971. * Called at the end of onLayout. At this point the Toolbar has already been resized, so we need
  8972. * to fit the items into the available width. We add up the width required by all of the items in
  8973. * the toolbar - if we don't have enough space we hide the extra items and render the expand menu
  8974. * trigger.
  8975. * @param {Ext.Element} target The Element the Toolbar is currently laid out within
  8976. */
  8977. fitToSize : function(target) {
  8978. if (this.container.enableOverflow === false) {
  8979. return;
  8980. }
  8981. var width = target.dom.clientWidth,
  8982. tableWidth = target.dom.firstChild.offsetWidth,
  8983. clipWidth = width - this.triggerWidth,
  8984. lastWidth = this.lastWidth || 0,
  8985. hiddenItems = this.hiddenItems,
  8986. hasHiddens = hiddenItems.length != 0,
  8987. isLarger = width >= lastWidth;
  8988. this.lastWidth = width;
  8989. if (tableWidth > width || (hasHiddens && isLarger)) {
  8990. var items = this.container.items.items,
  8991. len = items.length,
  8992. loopWidth = 0,
  8993. item;
  8994. for (var i = 0; i < len; i++) {
  8995. item = items[i];
  8996. if (!item.isFill) {
  8997. loopWidth += this.getItemWidth(item);
  8998. if (loopWidth > clipWidth) {
  8999. if (!(item.hidden || item.xtbHidden)) {
  9000. this.hideItem(item);
  9001. }
  9002. } else if (item.xtbHidden) {
  9003. this.unhideItem(item);
  9004. }
  9005. }
  9006. }
  9007. }
  9008. //test for number of hidden items again here because they may have changed above
  9009. hasHiddens = hiddenItems.length != 0;
  9010. if (hasHiddens) {
  9011. this.initMore();
  9012. if (!this.lastOverflow) {
  9013. this.container.fireEvent('overflowchange', this.container, true);
  9014. this.lastOverflow = true;
  9015. }
  9016. } else if (this.more) {
  9017. this.clearMenu();
  9018. this.more.destroy();
  9019. delete this.more;
  9020. if (this.lastOverflow) {
  9021. this.container.fireEvent('overflowchange', this.container, false);
  9022. this.lastOverflow = false;
  9023. }
  9024. }
  9025. },
  9026. /**
  9027. * @private
  9028. * Returns a menu config for a given component. This config is used to create a menu item
  9029. * to be added to the expander menu
  9030. * @param {Ext.Component} component The component to create the config for
  9031. * @param {Boolean} hideOnClick Passed through to the menu item
  9032. */
  9033. createMenuConfig : function(component, hideOnClick){
  9034. var config = Ext.apply({}, component.initialConfig),
  9035. group = component.toggleGroup;
  9036. Ext.copyTo(config, component, [
  9037. 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
  9038. ]);
  9039. Ext.apply(config, {
  9040. text : component.overflowText || component.text,
  9041. hideOnClick: hideOnClick
  9042. });
  9043. if (group || component.enableToggle) {
  9044. Ext.apply(config, {
  9045. group : group,
  9046. checked: component.pressed,
  9047. listeners: {
  9048. checkchange: function(item, checked){
  9049. component.toggle(checked);
  9050. }
  9051. }
  9052. });
  9053. }
  9054. delete config.ownerCt;
  9055. delete config.xtype;
  9056. delete config.id;
  9057. return config;
  9058. },
  9059. /**
  9060. * @private
  9061. * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
  9062. * @param {Ext.menu.Menu} menu The menu to add to
  9063. * @param {Ext.Component} component The component to add
  9064. */
  9065. addComponentToMenu : function(menu, component) {
  9066. if (component instanceof Ext.Toolbar.Separator) {
  9067. menu.add('-');
  9068. } else if (Ext.isFunction(component.isXType)) {
  9069. if (component.isXType('splitbutton')) {
  9070. menu.add(this.createMenuConfig(component, true));
  9071. } else if (component.isXType('button')) {
  9072. menu.add(this.createMenuConfig(component, !component.menu));
  9073. } else if (component.isXType('buttongroup')) {
  9074. component.items.each(function(item){
  9075. this.addComponentToMenu(menu, item);
  9076. }, this);
  9077. }
  9078. }
  9079. },
  9080. /**
  9081. * @private
  9082. * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
  9083. * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
  9084. */
  9085. clearMenu : function(){
  9086. var menu = this.moreMenu;
  9087. if (menu && menu.items) {
  9088. menu.items.each(function(item){
  9089. delete item.menu;
  9090. });
  9091. }
  9092. },
  9093. /**
  9094. * @private
  9095. * Called before the expand menu is shown, this rebuilds the menu since it was last shown because
  9096. * it is possible that the items hidden due to space limitations on the Toolbar have changed since.
  9097. * @param {Ext.menu.Menu} m The menu
  9098. */
  9099. beforeMoreShow : function(menu) {
  9100. var items = this.container.items.items,
  9101. len = items.length,
  9102. item,
  9103. prev;
  9104. var needsSep = function(group, item){
  9105. return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
  9106. };
  9107. this.clearMenu();
  9108. menu.removeAll();
  9109. for (var i = 0; i < len; i++) {
  9110. item = items[i];
  9111. if (item.xtbHidden) {
  9112. if (prev && (needsSep(item, prev) || needsSep(prev, item))) {
  9113. menu.add('-');
  9114. }
  9115. this.addComponentToMenu(menu, item);
  9116. prev = item;
  9117. }
  9118. }
  9119. // put something so the menu isn't empty if no compatible items found
  9120. if (menu.items.length < 1) {
  9121. menu.add(this.noItemsMenuText);
  9122. }
  9123. },
  9124. /**
  9125. * @private
  9126. * Creates the expand trigger and menu, adding them to the <tr> at the extreme right of the
  9127. * Toolbar table
  9128. */
  9129. initMore : function(){
  9130. if (!this.more) {
  9131. /**
  9132. * @private
  9133. * @property moreMenu
  9134. * @type Ext.menu.Menu
  9135. * The expand menu - holds items for every Toolbar item that cannot be shown
  9136. * because the Toolbar is currently not wide enough.
  9137. */
  9138. this.moreMenu = new Ext.menu.Menu({
  9139. ownerCt : this.container,
  9140. listeners: {
  9141. beforeshow: this.beforeMoreShow,
  9142. scope: this
  9143. }
  9144. });
  9145. /**
  9146. * @private
  9147. * @property more
  9148. * @type Ext.Button
  9149. * The expand button which triggers the overflow menu to be shown
  9150. */
  9151. this.more = new Ext.Button({
  9152. iconCls: 'x-toolbar-more-icon',
  9153. cls : 'x-toolbar-more',
  9154. menu : this.moreMenu,
  9155. ownerCt: this.container
  9156. });
  9157. var td = this.insertCell(this.more, this.extrasTr, 100);
  9158. this.more.render(td);
  9159. }
  9160. },
  9161. destroy : function(){
  9162. Ext.destroy(this.more, this.moreMenu);
  9163. delete this.leftTr;
  9164. delete this.rightTr;
  9165. delete this.extrasTr;
  9166. Ext.layout.ToolbarLayout.superclass.destroy.call(this);
  9167. }
  9168. });
  9169. Ext.Container.LAYOUTS.toolbar = Ext.layout.ToolbarLayout;
  9170. /**
  9171. * @class Ext.layout.MenuLayout
  9172. * @extends Ext.layout.ContainerLayout
  9173. * <p>Layout manager used by {@link Ext.menu.Menu}. Generally this class should not need to be used directly.</p>
  9174. */
  9175. Ext.layout.MenuLayout = Ext.extend(Ext.layout.ContainerLayout, {
  9176. monitorResize : true,
  9177. type: 'menu',
  9178. setContainer : function(ct){
  9179. this.monitorResize = !ct.floating;
  9180. // This event is only fired by the menu in IE, used so we don't couple
  9181. // the menu with the layout.
  9182. ct.on('autosize', this.doAutoSize, this);
  9183. Ext.layout.MenuLayout.superclass.setContainer.call(this, ct);
  9184. },
  9185. renderItem : function(c, position, target){
  9186. if (!this.itemTpl) {
  9187. this.itemTpl = Ext.layout.MenuLayout.prototype.itemTpl = new Ext.XTemplate(
  9188. '<li id="{itemId}" class="{itemCls}">',
  9189. '<tpl if="needsIcon">',
  9190. '<img alt="{altText}" src="{icon}" class="{iconCls}"/>',
  9191. '</tpl>',
  9192. '</li>'
  9193. );
  9194. }
  9195. if(c && !c.rendered){
  9196. if(Ext.isNumber(position)){
  9197. position = target.dom.childNodes[position];
  9198. }
  9199. var a = this.getItemArgs(c);
  9200. // The Component's positionEl is the <li> it is rendered into
  9201. c.render(c.positionEl = position ?
  9202. this.itemTpl.insertBefore(position, a, true) :
  9203. this.itemTpl.append(target, a, true));
  9204. // Link the containing <li> to the item.
  9205. c.positionEl.menuItemId = c.getItemId();
  9206. // If rendering a regular Component, and it needs an icon,
  9207. // move the Component rightwards.
  9208. if (!a.isMenuItem && a.needsIcon) {
  9209. c.positionEl.addClass('x-menu-list-item-indent');
  9210. }
  9211. this.configureItem(c);
  9212. }else if(c && !this.isValidParent(c, target)){
  9213. if(Ext.isNumber(position)){
  9214. position = target.dom.childNodes[position];
  9215. }
  9216. target.dom.insertBefore(c.getActionEl().dom, position || null);
  9217. }
  9218. },
  9219. getItemArgs : function(c) {
  9220. var isMenuItem = c instanceof Ext.menu.Item,
  9221. canHaveIcon = !(isMenuItem || c instanceof Ext.menu.Separator);
  9222. return {
  9223. isMenuItem: isMenuItem,
  9224. needsIcon: canHaveIcon && (c.icon || c.iconCls),
  9225. icon: c.icon || Ext.BLANK_IMAGE_URL,
  9226. iconCls: 'x-menu-item-icon ' + (c.iconCls || ''),
  9227. itemId: 'x-menu-el-' + c.id,
  9228. itemCls: 'x-menu-list-item ',
  9229. altText: c.altText || ''
  9230. };
  9231. },
  9232. // Valid if the Component is in a <li> which is part of our target <ul>
  9233. isValidParent : function(c, target) {
  9234. return c.el.up('li.x-menu-list-item', 5).dom.parentNode === (target.dom || target);
  9235. },
  9236. onLayout : function(ct, target){
  9237. Ext.layout.MenuLayout.superclass.onLayout.call(this, ct, target);
  9238. this.doAutoSize();
  9239. },
  9240. doAutoSize : function(){
  9241. var ct = this.container, w = ct.width;
  9242. if(ct.floating){
  9243. if(w){
  9244. ct.setWidth(w);
  9245. }else if(Ext.isIE9m){
  9246. ct.setWidth(Ext.isStrict && (Ext.isIE7 || Ext.isIE8 || Ext.isIE9) ? 'auto' : ct.minWidth);
  9247. var el = ct.getEl(), t = el.dom.offsetWidth; // force recalc
  9248. ct.setWidth(ct.getLayoutTarget().getWidth() + el.getFrameWidth('lr'));
  9249. }
  9250. }
  9251. }
  9252. });
  9253. Ext.Container.LAYOUTS['menu'] = Ext.layout.MenuLayout;
  9254. /**
  9255. * @class Ext.Viewport
  9256. * @extends Ext.Container
  9257. * <p>A specialized container representing the viewable application area (the browser viewport).</p>
  9258. * <p>The Viewport renders itself to the document body, and automatically sizes itself to the size of
  9259. * the browser viewport and manages window resizing. There may only be one Viewport created
  9260. * in a page. Inner layouts are available by virtue of the fact that all {@link Ext.Panel Panel}s
  9261. * added to the Viewport, either through its {@link #items}, or through the items, or the {@link #add}
  9262. * method of any of its child Panels may themselves have a layout.</p>
  9263. * <p>The Viewport does not provide scrolling, so child Panels within the Viewport should provide
  9264. * for scrolling if needed using the {@link #autoScroll} config.</p>
  9265. * <p>An example showing a classic application border layout:</p><pre><code>
  9266. new Ext.Viewport({
  9267. layout: 'border',
  9268. items: [{
  9269. region: 'north',
  9270. html: '&lt;h1 class="x-panel-header">Page Title&lt;/h1>',
  9271. autoHeight: true,
  9272. border: false,
  9273. margins: '0 0 5 0'
  9274. }, {
  9275. region: 'west',
  9276. collapsible: true,
  9277. title: 'Navigation',
  9278. width: 200
  9279. // the west region might typically utilize a {@link Ext.tree.TreePanel TreePanel} or a Panel with {@link Ext.layout.AccordionLayout Accordion layout}
  9280. }, {
  9281. region: 'south',
  9282. title: 'Title for Panel',
  9283. collapsible: true,
  9284. html: 'Information goes here',
  9285. split: true,
  9286. height: 100,
  9287. minHeight: 100
  9288. }, {
  9289. region: 'east',
  9290. title: 'Title for the Grid Panel',
  9291. collapsible: true,
  9292. split: true,
  9293. width: 200,
  9294. xtype: 'grid',
  9295. // remaining grid configuration not shown ...
  9296. // notice that the GridPanel is added directly as the region
  9297. // it is not "overnested" inside another Panel
  9298. }, {
  9299. region: 'center',
  9300. xtype: 'tabpanel', // TabPanel itself has no title
  9301. items: {
  9302. title: 'Default Tab',
  9303. html: 'The first tab\'s content. Others may be added dynamically'
  9304. }
  9305. }]
  9306. });
  9307. </code></pre>
  9308. * @constructor
  9309. * Create a new Viewport
  9310. * @param {Object} config The config object
  9311. * @xtype viewport
  9312. */
  9313. Ext.Viewport = Ext.extend(Ext.Container, {
  9314. /*
  9315. * Privatize config options which, if used, would interfere with the
  9316. * correct operation of the Viewport as the sole manager of the
  9317. * layout of the document body.
  9318. */
  9319. /**
  9320. * @cfg {Mixed} applyTo @hide
  9321. */
  9322. /**
  9323. * @cfg {Boolean} allowDomMove @hide
  9324. */
  9325. /**
  9326. * @cfg {Boolean} hideParent @hide
  9327. */
  9328. /**
  9329. * @cfg {Mixed} renderTo @hide
  9330. */
  9331. /**
  9332. * @cfg {Number} height @hide
  9333. */
  9334. /**
  9335. * @cfg {Number} width @hide
  9336. */
  9337. /**
  9338. * @cfg {Boolean} autoHeight @hide
  9339. */
  9340. /**
  9341. * @cfg {Boolean} autoWidth @hide
  9342. */
  9343. /**
  9344. * @cfg {Boolean} deferHeight @hide
  9345. */
  9346. /**
  9347. * @cfg {Boolean} monitorResize @hide
  9348. */
  9349. initComponent : function() {
  9350. Ext.Viewport.superclass.initComponent.call(this);
  9351. document.getElementsByTagName('html')[0].className += ' x-viewport';
  9352. this.el = Ext.getBody();
  9353. this.el.setHeight = Ext.emptyFn;
  9354. this.el.setWidth = Ext.emptyFn;
  9355. this.el.setSize = Ext.emptyFn;
  9356. this.el.dom.scroll = 'no';
  9357. this.allowDomMove = false;
  9358. this.autoWidth = true;
  9359. this.autoHeight = true;
  9360. Ext.EventManager.onWindowResize(this.fireResize, this);
  9361. this.renderTo = this.el;
  9362. },
  9363. fireResize : function(w, h){
  9364. this.fireEvent('resize', this, w, h, w, h);
  9365. }
  9366. });
  9367. Ext.reg('viewport', Ext.Viewport);
  9368. /**
  9369. * @class Ext.Panel
  9370. * @extends Ext.Container
  9371. * <p>Panel is a container that has specific functionality and structural components that make
  9372. * it the perfect building block for application-oriented user interfaces.</p>
  9373. * <p>Panels are, by virtue of their inheritance from {@link Ext.Container}, capable
  9374. * of being configured with a {@link Ext.Container#layout layout}, and containing child Components.</p>
  9375. * <p>When either specifying child {@link Ext.Component#items items} of a Panel, or dynamically {@link Ext.Container#add adding} Components
  9376. * to a Panel, remember to consider how you wish the Panel to arrange those child elements, and whether
  9377. * those child elements need to be sized using one of Ext's built-in <code><b>{@link Ext.Container#layout layout}</b></code> schemes. By
  9378. * default, Panels use the {@link Ext.layout.ContainerLayout ContainerLayout} scheme. This simply renders
  9379. * child components, appending them one after the other inside the Container, and <b>does not apply any sizing</b>
  9380. * at all.</p>
  9381. * <p>A Panel may also contain {@link #bbar bottom} and {@link #tbar top} toolbars, along with separate
  9382. * {@link #header}, {@link #footer} and {@link #body} sections (see {@link #frame} for additional
  9383. * information).</p>
  9384. * <p>Panel also provides built-in {@link #collapsible expandable and collapsible behavior}, along with
  9385. * a variety of {@link #tools prebuilt tool buttons} that can be wired up to provide other customized
  9386. * behavior. Panels can be easily dropped into any {@link Ext.Container Container} or layout, and the
  9387. * layout and rendering pipeline is {@link Ext.Container#add completely managed by the framework}.</p>
  9388. * @constructor
  9389. * @param {Object} config The config object
  9390. * @xtype panel
  9391. */
  9392. Ext.Panel = Ext.extend(Ext.Container, {
  9393. /**
  9394. * The Panel's header {@link Ext.Element Element}. Read-only.
  9395. * <p>This Element is used to house the {@link #title} and {@link #tools}</p>
  9396. * <br><p><b>Note</b>: see the Note for <code>{@link Ext.Component#el el}</code> also.</p>
  9397. * @type Ext.Element
  9398. * @property header
  9399. */
  9400. /**
  9401. * The Panel's body {@link Ext.Element Element} which may be used to contain HTML content.
  9402. * The content may be specified in the {@link #html} config, or it may be loaded using the
  9403. * {@link autoLoad} config, or through the Panel's {@link #getUpdater Updater}. Read-only.
  9404. * <p>If this is used to load visible HTML elements in either way, then
  9405. * the Panel may not be used as a Layout for hosting nested Panels.</p>
  9406. * <p>If this Panel is intended to be used as the host of a Layout (See {@link #layout}
  9407. * then the body Element must not be loaded or changed - it is under the control
  9408. * of the Panel's Layout.
  9409. * <br><p><b>Note</b>: see the Note for <code>{@link Ext.Component#el el}</code> also.</p>
  9410. * @type Ext.Element
  9411. * @property body
  9412. */
  9413. /**
  9414. * The Panel's bwrap {@link Ext.Element Element} used to contain other Panel elements
  9415. * (tbar, body, bbar, footer). See {@link #bodyCfg}. Read-only.
  9416. * @type Ext.Element
  9417. * @property bwrap
  9418. */
  9419. /**
  9420. * True if this panel is collapsed. Read-only.
  9421. * @type Boolean
  9422. * @property collapsed
  9423. */
  9424. /**
  9425. * @cfg {Object} bodyCfg
  9426. * <p>A {@link Ext.DomHelper DomHelper} element specification object may be specified for any
  9427. * Panel Element.</p>
  9428. * <p>By default, the Default element in the table below will be used for the html markup to
  9429. * create a child element with the commensurate Default class name (<code>baseCls</code> will be
  9430. * replaced by <code>{@link #baseCls}</code>):</p>
  9431. * <pre>
  9432. * Panel Default Default Custom Additional Additional
  9433. * Element element class element class style
  9434. * ======== ========================== ========= ============== ===========
  9435. * {@link #header} div {@link #baseCls}+'-header' {@link #headerCfg} headerCssClass headerStyle
  9436. * {@link #bwrap} div {@link #baseCls}+'-bwrap' {@link #bwrapCfg} bwrapCssClass bwrapStyle
  9437. * + tbar div {@link #baseCls}+'-tbar' {@link #tbarCfg} tbarCssClass tbarStyle
  9438. * + {@link #body} div {@link #baseCls}+'-body' {@link #bodyCfg} {@link #bodyCssClass} {@link #bodyStyle}
  9439. * + bbar div {@link #baseCls}+'-bbar' {@link #bbarCfg} bbarCssClass bbarStyle
  9440. * + {@link #footer} div {@link #baseCls}+'-footer' {@link #footerCfg} footerCssClass footerStyle
  9441. * </pre>
  9442. * <p>Configuring a Custom element may be used, for example, to force the {@link #body} Element
  9443. * to use a different form of markup than is created by default. An example of this might be
  9444. * to {@link Ext.Element#createChild create a child} Panel containing a custom content, such as
  9445. * a header, or forcing centering of all Panel content by having the body be a &lt;center&gt;
  9446. * element:</p>
  9447. * <pre><code>
  9448. new Ext.Panel({
  9449. title: 'Message Title',
  9450. renderTo: Ext.getBody(),
  9451. width: 200, height: 130,
  9452. <b>bodyCfg</b>: {
  9453. tag: 'center',
  9454. cls: 'x-panel-body', // Default class not applied if Custom element specified
  9455. html: 'Message'
  9456. },
  9457. footerCfg: {
  9458. tag: 'h2',
  9459. cls: 'x-panel-footer', // same as the Default class
  9460. html: 'footer html'
  9461. },
  9462. footerCssClass: 'custom-footer', // additional css class, see {@link Ext.element#addClass addClass}
  9463. footerStyle: 'background-color:red' // see {@link #bodyStyle}
  9464. });
  9465. * </code></pre>
  9466. * <p>The example above also explicitly creates a <code>{@link #footer}</code> with custom markup and
  9467. * styling applied.</p>
  9468. */
  9469. /**
  9470. * @cfg {Object} headerCfg
  9471. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9472. * of this Panel's {@link #header} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9473. */
  9474. /**
  9475. * @cfg {Object} bwrapCfg
  9476. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9477. * of this Panel's {@link #bwrap} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9478. */
  9479. /**
  9480. * @cfg {Object} tbarCfg
  9481. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9482. * of this Panel's {@link #tbar} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9483. */
  9484. /**
  9485. * @cfg {Object} bbarCfg
  9486. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9487. * of this Panel's {@link #bbar} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9488. */
  9489. /**
  9490. * @cfg {Object} footerCfg
  9491. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9492. * of this Panel's {@link #footer} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9493. */
  9494. /**
  9495. * @cfg {Boolean} closable
  9496. * Panels themselves do not directly support being closed, but some Panel subclasses do (like
  9497. * {@link Ext.Window}) or a Panel Class within an {@link Ext.TabPanel}. Specify <code>true</code>
  9498. * to enable closing in such situations. Defaults to <code>false</code>.
  9499. */
  9500. /**
  9501. * The Panel's footer {@link Ext.Element Element}. Read-only.
  9502. * <p>This Element is used to house the Panel's <code>{@link #buttons}</code> or <code>{@link #fbar}</code>.</p>
  9503. * <br><p><b>Note</b>: see the Note for <code>{@link Ext.Component#el el}</code> also.</p>
  9504. * @type Ext.Element
  9505. * @property footer
  9506. */
  9507. /**
  9508. * @cfg {Mixed} applyTo
  9509. * <p>The id of the node, a DOM node or an existing Element corresponding to a DIV that is already present in
  9510. * the document that specifies some panel-specific structural markup. When <code>applyTo</code> is used,
  9511. * constituent parts of the panel can be specified by CSS class name within the main element, and the panel
  9512. * will automatically create those components from that markup. Any required components not specified in the
  9513. * markup will be autogenerated if necessary.</p>
  9514. * <p>The following class names are supported (baseCls will be replaced by {@link #baseCls}):</p>
  9515. * <ul><li>baseCls + '-header'</li>
  9516. * <li>baseCls + '-header-text'</li>
  9517. * <li>baseCls + '-bwrap'</li>
  9518. * <li>baseCls + '-tbar'</li>
  9519. * <li>baseCls + '-body'</li>
  9520. * <li>baseCls + '-bbar'</li>
  9521. * <li>baseCls + '-footer'</li></ul>
  9522. * <p>Using this config, a call to render() is not required. If applyTo is specified, any value passed for
  9523. * {@link #renderTo} will be ignored and the target element's parent node will automatically be used as the
  9524. * panel's container.</p>
  9525. */
  9526. /**
  9527. * @cfg {Object/Array} tbar
  9528. * <p>The top toolbar of the panel. This can be a {@link Ext.Toolbar} object, a toolbar config, or an array of
  9529. * buttons/button configs to be added to the toolbar. Note that this is not available as a property after render.
  9530. * To access the top toolbar after render, use {@link #getTopToolbar}.</p>
  9531. * <p><b>Note:</b> Although a Toolbar may contain Field components, these will <b>not</b> be updated by a load
  9532. * of an ancestor FormPanel. A Panel's toolbars are not part of the standard Container->Component hierarchy, and
  9533. * so are not scanned to collect form items. However, the values <b>will</b> be submitted because form
  9534. * submission parameters are collected from the DOM tree.</p>
  9535. */
  9536. /**
  9537. * @cfg {Object/Array} bbar
  9538. * <p>The bottom toolbar of the panel. This can be a {@link Ext.Toolbar} object, a toolbar config, or an array of
  9539. * buttons/button configs to be added to the toolbar. Note that this is not available as a property after render.
  9540. * To access the bottom toolbar after render, use {@link #getBottomToolbar}.</p>
  9541. * <p><b>Note:</b> Although a Toolbar may contain Field components, these will <b>not</b> be updated by a load
  9542. * of an ancestor FormPanel. A Panel's toolbars are not part of the standard Container->Component hierarchy, and
  9543. * so are not scanned to collect form items. However, the values <b>will</b> be submitted because form
  9544. * submission parameters are collected from the DOM tree.</p>
  9545. */
  9546. /** @cfg {Object/Array} fbar
  9547. * <p>A {@link Ext.Toolbar Toolbar} object, a Toolbar config, or an array of
  9548. * {@link Ext.Button Button}s/{@link Ext.Button Button} configs, describing a {@link Ext.Toolbar Toolbar} to be rendered into this Panel's footer element.</p>
  9549. * <p>After render, the <code>fbar</code> property will be an {@link Ext.Toolbar Toolbar} instance.</p>
  9550. * <p>If <code>{@link #buttons}</code> are specified, they will supersede the <code>fbar</code> configuration property.</p>
  9551. * The Panel's <code>{@link #buttonAlign}</code> configuration affects the layout of these items, for example:
  9552. * <pre><code>
  9553. var w = new Ext.Window({
  9554. height: 250,
  9555. width: 500,
  9556. bbar: new Ext.Toolbar({
  9557. items: [{
  9558. text: 'bbar Left'
  9559. },'->',{
  9560. text: 'bbar Right'
  9561. }]
  9562. }),
  9563. {@link #buttonAlign}: 'left', // anything but 'center' or 'right' and you can use '-', and '->'
  9564. // to control the alignment of fbar items
  9565. fbar: [{
  9566. text: 'fbar Left'
  9567. },'->',{
  9568. text: 'fbar Right'
  9569. }]
  9570. }).show();
  9571. * </code></pre>
  9572. * <p><b>Note:</b> Although a Toolbar may contain Field components, these will <b>not</b> be updated by a load
  9573. * of an ancestor FormPanel. A Panel's toolbars are not part of the standard Container->Component hierarchy, and
  9574. * so are not scanned to collect form items. However, the values <b>will</b> be submitted because form
  9575. * submission parameters are collected from the DOM tree.</p>
  9576. */
  9577. /**
  9578. * @cfg {Boolean} header
  9579. * <code>true</code> to create the Panel's header element explicitly, <code>false</code> to skip creating
  9580. * it. If a <code>{@link #title}</code> is set the header will be created automatically, otherwise it will not.
  9581. * If a <code>{@link #title}</code> is set but <code>header</code> is explicitly set to <code>false</code>, the header
  9582. * will not be rendered.
  9583. */
  9584. /**
  9585. * @cfg {Boolean} footer
  9586. * <code>true</code> to create the footer element explicitly, false to skip creating it. The footer
  9587. * will be created automatically if <code>{@link #buttons}</code> or a <code>{@link #fbar}</code> have
  9588. * been configured. See <code>{@link #bodyCfg}</code> for an example.
  9589. */
  9590. /**
  9591. * @cfg {String} title
  9592. * The title text to be used as innerHTML (html tags are accepted) to display in the panel
  9593. * <code>{@link #header}</code> (defaults to ''). When a <code>title</code> is specified the
  9594. * <code>{@link #header}</code> element will automatically be created and displayed unless
  9595. * {@link #header} is explicitly set to <code>false</code>. If you do not want to specify a
  9596. * <code>title</code> at config time, but you may want one later, you must either specify a non-empty
  9597. * <code>title</code> (a blank space ' ' will do) or <code>header:true</code> so that the container
  9598. * element will get created.
  9599. */
  9600. /**
  9601. * @cfg {Array} buttons
  9602. * <code>buttons</code> will be used as <code>{@link Ext.Container#items items}</code> for the toolbar in
  9603. * the footer (<code>{@link #fbar}</code>). Typically the value of this configuration property will be
  9604. * an array of {@link Ext.Button}s or {@link Ext.Button} configuration objects.
  9605. * If an item is configured with <code>minWidth</code> or the Panel is configured with <code>minButtonWidth</code>,
  9606. * that width will be applied to the item.
  9607. */
  9608. /**
  9609. * @cfg {Object/String/Function} autoLoad
  9610. * A valid url spec according to the Updater {@link Ext.Updater#update} method.
  9611. * If autoLoad is not null, the panel will attempt to load its contents
  9612. * immediately upon render.<p>
  9613. * The URL will become the default URL for this panel's {@link #body} element,
  9614. * so it may be {@link Ext.Element#refresh refresh}ed at any time.</p>
  9615. */
  9616. /**
  9617. * @cfg {Boolean} frame
  9618. * <code>false</code> by default to render with plain 1px square borders. <code>true</code> to render with
  9619. * 9 elements, complete with custom rounded corners (also see {@link Ext.Element#boxWrap}).
  9620. * <p>The template generated for each condition is depicted below:</p><pre><code>
  9621. *
  9622. // frame = false
  9623. &lt;div id="developer-specified-id-goes-here" class="x-panel">
  9624. &lt;div class="x-panel-header">&lt;span class="x-panel-header-text">Title: (frame:false)&lt;/span>&lt;/div>
  9625. &lt;div class="x-panel-bwrap">
  9626. &lt;div class="x-panel-body">&lt;p>html value goes here&lt;/p>&lt;/div>
  9627. &lt;/div>
  9628. &lt;/div>
  9629. // frame = true (create 9 elements)
  9630. &lt;div id="developer-specified-id-goes-here" class="x-panel">
  9631. &lt;div class="x-panel-tl">&lt;div class="x-panel-tr">&lt;div class="x-panel-tc">
  9632. &lt;div class="x-panel-header">&lt;span class="x-panel-header-text">Title: (frame:true)&lt;/span>&lt;/div>
  9633. &lt;/div>&lt;/div>&lt;/div>
  9634. &lt;div class="x-panel-bwrap">
  9635. &lt;div class="x-panel-ml">&lt;div class="x-panel-mr">&lt;div class="x-panel-mc">
  9636. &lt;div class="x-panel-body">&lt;p>html value goes here&lt;/p>&lt;/div>
  9637. &lt;/div>&lt;/div>&lt;/div>
  9638. &lt;div class="x-panel-bl">&lt;div class="x-panel-br">&lt;div class="x-panel-bc"/>
  9639. &lt;/div>&lt;/div>&lt;/div>
  9640. &lt;/div>
  9641. * </code></pre>
  9642. */
  9643. /**
  9644. * @cfg {Boolean} border
  9645. * True to display the borders of the panel's body element, false to hide them (defaults to true). By default,
  9646. * the border is a 2px wide inset border, but this can be further altered by setting {@link #bodyBorder} to false.
  9647. */
  9648. /**
  9649. * @cfg {Boolean} bodyBorder
  9650. * True to display an interior border on the body element of the panel, false to hide it (defaults to true).
  9651. * This only applies when {@link #border} == true. If border == true and bodyBorder == false, the border will display
  9652. * as a 1px wide inset border, giving the entire body element an inset appearance.
  9653. */
  9654. /**
  9655. * @cfg {String/Object/Function} bodyCssClass
  9656. * Additional css class selector to be applied to the {@link #body} element in the format expected by
  9657. * {@link Ext.Element#addClass} (defaults to null). See {@link #bodyCfg}.
  9658. */
  9659. /**
  9660. * @cfg {String/Object/Function} bodyStyle
  9661. * Custom CSS styles to be applied to the {@link #body} element in the format expected by
  9662. * {@link Ext.Element#applyStyles} (defaults to null). See {@link #bodyCfg}.
  9663. */
  9664. /**
  9665. * @cfg {String} iconCls
  9666. * The CSS class selector that specifies a background image to be used as the header icon (defaults to '').
  9667. * <p>An example of specifying a custom icon class would be something like:
  9668. * </p><pre><code>
  9669. // specify the property in the config for the class:
  9670. ...
  9671. iconCls: 'my-icon'
  9672. // css class that specifies background image to be used as the icon image:
  9673. .my-icon { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }
  9674. </code></pre>
  9675. */
  9676. /**
  9677. * @cfg {Boolean} collapsible
  9678. * True to make the panel collapsible and have the expand/collapse toggle button automatically rendered into
  9679. * the header tool button area, false to keep the panel statically sized with no button (defaults to false).
  9680. */
  9681. /**
  9682. * @cfg {Array} tools
  9683. * An array of tool button configs to be added to the header tool area. When rendered, each tool is
  9684. * stored as an {@link Ext.Element Element} referenced by a public property called <code><b></b>tools.<i>&lt;tool-type&gt;</i></code>
  9685. * <p>Each tool config may contain the following properties:
  9686. * <div class="mdetail-params"><ul>
  9687. * <li><b>id</b> : String<div class="sub-desc"><b>Required.</b> The type
  9688. * of tool to create. By default, this assigns a CSS class of the form <code>x-tool-<i>&lt;tool-type&gt;</i></code> to the
  9689. * resulting tool Element. Ext provides CSS rules, and an icon sprite containing images for the tool types listed below.
  9690. * The developer may implement custom tools by supplying alternate CSS rules and background images:
  9691. * <ul>
  9692. * <div class="x-tool x-tool-toggle" style="float:left; margin-right:5;"> </div><div><code> toggle</code> (Created by default when {@link #collapsible} is <code>true</code>)</div>
  9693. * <div class="x-tool x-tool-close" style="float:left; margin-right:5;"> </div><div><code> close</code></div>
  9694. * <div class="x-tool x-tool-minimize" style="float:left; margin-right:5;"> </div><div><code> minimize</code></div>
  9695. * <div class="x-tool x-tool-maximize" style="float:left; margin-right:5;"> </div><div><code> maximize</code></div>
  9696. * <div class="x-tool x-tool-restore" style="float:left; margin-right:5;"> </div><div><code> restore</code></div>
  9697. * <div class="x-tool x-tool-gear" style="float:left; margin-right:5;"> </div><div><code> gear</code></div>
  9698. * <div class="x-tool x-tool-pin" style="float:left; margin-right:5;"> </div><div><code> pin</code></div>
  9699. * <div class="x-tool x-tool-unpin" style="float:left; margin-right:5;"> </div><div><code> unpin</code></div>
  9700. * <div class="x-tool x-tool-right" style="float:left; margin-right:5;"> </div><div><code> right</code></div>
  9701. * <div class="x-tool x-tool-left" style="float:left; margin-right:5;"> </div><div><code> left</code></div>
  9702. * <div class="x-tool x-tool-up" style="float:left; margin-right:5;"> </div><div><code> up</code></div>
  9703. * <div class="x-tool x-tool-down" style="float:left; margin-right:5;"> </div><div><code> down</code></div>
  9704. * <div class="x-tool x-tool-refresh" style="float:left; margin-right:5;"> </div><div><code> refresh</code></div>
  9705. * <div class="x-tool x-tool-minus" style="float:left; margin-right:5;"> </div><div><code> minus</code></div>
  9706. * <div class="x-tool x-tool-plus" style="float:left; margin-right:5;"> </div><div><code> plus</code></div>
  9707. * <div class="x-tool x-tool-help" style="float:left; margin-right:5;"> </div><div><code> help</code></div>
  9708. * <div class="x-tool x-tool-search" style="float:left; margin-right:5;"> </div><div><code> search</code></div>
  9709. * <div class="x-tool x-tool-save" style="float:left; margin-right:5;"> </div><div><code> save</code></div>
  9710. * <div class="x-tool x-tool-print" style="float:left; margin-right:5;"> </div><div><code> print</code></div>
  9711. * </ul></div></li>
  9712. * <li><b>handler</b> : Function<div class="sub-desc"><b>Required.</b> The function to
  9713. * call when clicked. Arguments passed are:<ul>
  9714. * <li><b>event</b> : Ext.EventObject<div class="sub-desc">The click event.</div></li>
  9715. * <li><b>toolEl</b> : Ext.Element<div class="sub-desc">The tool Element.</div></li>
  9716. * <li><b>panel</b> : Ext.Panel<div class="sub-desc">The host Panel</div></li>
  9717. * <li><b>tc</b> : Object<div class="sub-desc">The tool configuration object</div></li>
  9718. * </ul></div></li>
  9719. * <li><b>stopEvent</b> : Boolean<div class="sub-desc">Defaults to true. Specify as false to allow click event to propagate.</div></li>
  9720. * <li><b>scope</b> : Object<div class="sub-desc">The scope in which to call the handler.</div></li>
  9721. * <li><b>qtip</b> : String/Object<div class="sub-desc">A tip string, or
  9722. * a config argument to {@link Ext.QuickTip#register}</div></li>
  9723. * <li><b>hidden</b> : Boolean<div class="sub-desc">True to initially render hidden.</div></li>
  9724. * <li><b>on</b> : Object<div class="sub-desc">A listener config object specifiying
  9725. * event listeners in the format of an argument to {@link #addListener}</div></li>
  9726. * </ul></div>
  9727. * <p>Note that, apart from the toggle tool which is provided when a panel is collapsible, these
  9728. * tools only provide the visual button. Any required functionality must be provided by adding
  9729. * handlers that implement the necessary behavior.</p>
  9730. * <p>Example usage:</p>
  9731. * <pre><code>
  9732. tools:[{
  9733. id:'refresh',
  9734. qtip: 'Refresh form Data',
  9735. // hidden:true,
  9736. handler: function(event, toolEl, panel){
  9737. // refresh logic
  9738. }
  9739. },
  9740. {
  9741. id:'help',
  9742. qtip: 'Get Help',
  9743. handler: function(event, toolEl, panel){
  9744. // whatever
  9745. }
  9746. }]
  9747. </code></pre>
  9748. * <p>For the custom id of <code>'help'</code> define two relevant css classes with a link to
  9749. * a 15x15 image:</p>
  9750. * <pre><code>
  9751. .x-tool-help {background-image: url(images/help.png);}
  9752. .x-tool-help-over {background-image: url(images/help_over.png);}
  9753. // if using an image sprite:
  9754. .x-tool-help {background-image: url(images/help.png) no-repeat 0 0;}
  9755. .x-tool-help-over {background-position:-15px 0;}
  9756. </code></pre>
  9757. */
  9758. /**
  9759. * @cfg {Ext.Template/Ext.XTemplate} toolTemplate
  9760. * <p>A Template used to create {@link #tools} in the {@link #header} Element. Defaults to:</p><pre><code>
  9761. new Ext.Template('&lt;div class="x-tool x-tool-{id}">&amp;#160;&lt;/div>')</code></pre>
  9762. * <p>This may may be overridden to provide a custom DOM structure for tools based upon a more
  9763. * complex XTemplate. The template's data is a single tool configuration object (Not the entire Array)
  9764. * as specified in {@link #tools}. In the following example an &lt;a> tag is used to provide a
  9765. * visual indication when hovering over the tool:</p><pre><code>
  9766. var win = new Ext.Window({
  9767. tools: [{
  9768. id: 'download',
  9769. href: '/MyPdfDoc.pdf'
  9770. }],
  9771. toolTemplate: new Ext.XTemplate(
  9772. '&lt;tpl if="id==\'download\'">',
  9773. '&lt;a class="x-tool x-tool-pdf" href="{href}">&lt;/a>',
  9774. '&lt;/tpl>',
  9775. '&lt;tpl if="id!=\'download\'">',
  9776. '&lt;div class="x-tool x-tool-{id}">&amp;#160;&lt;/div>',
  9777. '&lt;/tpl>'
  9778. ),
  9779. width:500,
  9780. height:300,
  9781. closeAction:'hide'
  9782. });</code></pre>
  9783. * <p>Note that the CSS class 'x-tool-pdf' should have an associated style rule which provides an
  9784. * appropriate background image, something like:</p>
  9785. <pre><code>
  9786. a.x-tool-pdf {background-image: url(../shared/extjs/images/pdf.gif)!important;}
  9787. </code></pre>
  9788. */
  9789. /**
  9790. * @cfg {Boolean} hideCollapseTool
  9791. * <code>true</code> to hide the expand/collapse toggle button when <code>{@link #collapsible} == true</code>,
  9792. * <code>false</code> to display it (defaults to <code>false</code>).
  9793. */
  9794. /**
  9795. * @cfg {Boolean} titleCollapse
  9796. * <code>true</code> to allow expanding and collapsing the panel (when <code>{@link #collapsible} = true</code>)
  9797. * by clicking anywhere in the header bar, <code>false</code>) to allow it only by clicking to tool button
  9798. * (defaults to <code>false</code>)). If this panel is a child item of a border layout also see the
  9799. * {@link Ext.layout.BorderLayout.Region BorderLayout.Region}
  9800. * <code>{@link Ext.layout.BorderLayout.Region#floatable floatable}</code> config option.
  9801. */
  9802. /**
  9803. * @cfg {Mixed} floating
  9804. * <p>This property is used to configure the underlying {@link Ext.Layer}. Acceptable values for this
  9805. * configuration property are:</p><div class="mdetail-params"><ul>
  9806. * <li><b><code>false</code></b> : <b>Default.</b><div class="sub-desc">Display the panel inline where it is
  9807. * rendered.</div></li>
  9808. * <li><b><code>true</code></b> : <div class="sub-desc">Float the panel (absolute position it with automatic
  9809. * shimming and shadow).<ul>
  9810. * <div class="sub-desc">Setting floating to true will create an Ext.Layer for this panel and display the
  9811. * panel at negative offsets so that it is hidden.</div>
  9812. * <div class="sub-desc">Since the panel will be absolute positioned, the position must be set explicitly
  9813. * <i>after</i> render (e.g., <code>myPanel.setPosition(100,100);</code>).</div>
  9814. * <div class="sub-desc"><b>Note</b>: when floating a panel you should always assign a fixed width,
  9815. * otherwise it will be auto width and will expand to fill to the right edge of the viewport.</div>
  9816. * </ul></div></li>
  9817. * <li><b><code>{@link Ext.Layer object}</code></b> : <div class="sub-desc">The specified object will be used
  9818. * as the configuration object for the {@link Ext.Layer} that will be created.</div></li>
  9819. * </ul></div>
  9820. */
  9821. /**
  9822. * @cfg {Boolean/String} shadow
  9823. * <code>true</code> (or a valid Ext.Shadow {@link Ext.Shadow#mode} value) to display a shadow behind the
  9824. * panel, <code>false</code> to display no shadow (defaults to <code>'sides'</code>). Note that this option
  9825. * only applies when <code>{@link #floating} = true</code>.
  9826. */
  9827. /**
  9828. * @cfg {Number} shadowOffset
  9829. * The number of pixels to offset the shadow if displayed (defaults to <code>4</code>). Note that this
  9830. * option only applies when <code>{@link #floating} = true</code>.
  9831. */
  9832. /**
  9833. * @cfg {Boolean} shim
  9834. * <code>false</code> to disable the iframe shim in browsers which need one (defaults to <code>true</code>).
  9835. * Note that this option only applies when <code>{@link #floating} = true</code>.
  9836. */
  9837. /**
  9838. * @cfg {Object/Array} keys
  9839. * A {@link Ext.KeyMap} config object (in the format expected by {@link Ext.KeyMap#addBinding}
  9840. * used to assign custom key handling to this panel (defaults to <code>null</code>).
  9841. */
  9842. /**
  9843. * @cfg {Boolean/Object} draggable
  9844. * <p><code>true</code> to enable dragging of this Panel (defaults to <code>false</code>).</p>
  9845. * <p>For custom drag/drop implementations, an <b>Ext.Panel.DD</b> config could also be passed
  9846. * in this config instead of <code>true</code>. Ext.Panel.DD is an internal, undocumented class which
  9847. * moves a proxy Element around in place of the Panel's element, but provides no other behaviour
  9848. * during dragging or on drop. It is a subclass of {@link Ext.dd.DragSource}, so behaviour may be
  9849. * added by implementing the interface methods of {@link Ext.dd.DragDrop} e.g.:
  9850. * <pre><code>
  9851. new Ext.Panel({
  9852. title: 'Drag me',
  9853. x: 100,
  9854. y: 100,
  9855. renderTo: Ext.getBody(),
  9856. floating: true,
  9857. frame: true,
  9858. width: 400,
  9859. height: 200,
  9860. draggable: {
  9861. // Config option of Ext.Panel.DD class.
  9862. // It&#39;s a floating Panel, so do not show a placeholder proxy in the original position.
  9863. insertProxy: false,
  9864. // Called for each mousemove event while dragging the DD object.
  9865. onDrag : function(e){
  9866. // Record the x,y position of the drag proxy so that we can
  9867. // position the Panel at end of drag.
  9868. var pel = this.proxy.getEl();
  9869. this.x = pel.getLeft(true);
  9870. this.y = pel.getTop(true);
  9871. // Keep the Shadow aligned if there is one.
  9872. var s = this.panel.getEl().shadow;
  9873. if (s) {
  9874. s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
  9875. }
  9876. },
  9877. // Called on the mouseup event.
  9878. endDrag : function(e){
  9879. this.panel.setPosition(this.x, this.y);
  9880. }
  9881. }
  9882. }).show();
  9883. </code></pre>
  9884. */
  9885. /**
  9886. * @cfg {Boolean} disabled
  9887. * Render this panel disabled (default is <code>false</code>). An important note when using the disabled
  9888. * config on panels is that IE will often fail to initialize the disabled mask element correectly if
  9889. * the panel's layout has not yet completed by the time the Panel is disabled during the render process.
  9890. * If you experience this issue, you may need to instead use the {@link #afterlayout} event to initialize
  9891. * the disabled state:
  9892. * <pre><code>
  9893. new Ext.Panel({
  9894. ...
  9895. listeners: {
  9896. 'afterlayout': {
  9897. fn: function(p){
  9898. p.disable();
  9899. },
  9900. single: true // important, as many layouts can occur
  9901. }
  9902. }
  9903. });
  9904. </code></pre>
  9905. */
  9906. /**
  9907. * @cfg {Boolean} autoHeight
  9908. * <code>true</code> to use height:'auto', <code>false</code> to use fixed height (defaults to <code>false</code>).
  9909. * <b>Note</b>: Setting <code>autoHeight: true</code> means that the browser will manage the panel's height
  9910. * based on its contents, and that Ext will not manage it at all. If the panel is within a layout that
  9911. * manages dimensions (<code>fit</code>, <code>border</code>, etc.) then setting <code>autoHeight: true</code>
  9912. * can cause issues with scrolling and will not generally work as expected since the panel will take
  9913. * on the height of its contents rather than the height required by the Ext layout.
  9914. */
  9915. /**
  9916. * @cfg {String} baseCls
  9917. * The base CSS class to apply to this panel's element (defaults to <code>'x-panel'</code>).
  9918. * <p>Another option available by default is to specify <code>'x-plain'</code> which strips all styling
  9919. * except for required attributes for Ext layouts to function (e.g. overflow:hidden).
  9920. * See <code>{@link #unstyled}</code> also.</p>
  9921. */
  9922. baseCls : 'x-panel',
  9923. /**
  9924. * @cfg {String} collapsedCls
  9925. * A CSS class to add to the panel's element after it has been collapsed (defaults to
  9926. * <code>'x-panel-collapsed'</code>).
  9927. */
  9928. collapsedCls : 'x-panel-collapsed',
  9929. /**
  9930. * @cfg {Boolean} maskDisabled
  9931. * <code>true</code> to mask the panel when it is {@link #disabled}, <code>false</code> to not mask it (defaults
  9932. * to <code>true</code>). Either way, the panel will always tell its contained elements to disable themselves
  9933. * when it is disabled, but masking the panel can provide an additional visual cue that the panel is
  9934. * disabled.
  9935. */
  9936. maskDisabled : true,
  9937. /**
  9938. * @cfg {Boolean} animCollapse
  9939. * <code>true</code> to animate the transition when the panel is collapsed, <code>false</code> to skip the
  9940. * animation (defaults to <code>true</code> if the {@link Ext.Fx} class is available, otherwise <code>false</code>).
  9941. */
  9942. animCollapse : Ext.enableFx,
  9943. /**
  9944. * @cfg {Boolean} headerAsText
  9945. * <code>true</code> to display the panel <code>{@link #title}</code> in the <code>{@link #header}</code>,
  9946. * <code>false</code> to hide it (defaults to <code>true</code>).
  9947. */
  9948. headerAsText : true,
  9949. /**
  9950. * @cfg {String} buttonAlign
  9951. * The alignment of any {@link #buttons} added to this panel. Valid values are <code>'right'</code>,
  9952. * <code>'left'</code> and <code>'center'</code> (defaults to <code>'right'</code>).
  9953. */
  9954. buttonAlign : 'right',
  9955. /**
  9956. * @cfg {Boolean} collapsed
  9957. * <code>true</code> to render the panel collapsed, <code>false</code> to render it expanded (defaults to
  9958. * <code>false</code>).
  9959. */
  9960. collapsed : false,
  9961. /**
  9962. * @cfg {Boolean} collapseFirst
  9963. * <code>true</code> to make sure the collapse/expand toggle button always renders first (to the left of)
  9964. * any other tools in the panel's title bar, <code>false</code> to render it last (defaults to <code>true</code>).
  9965. */
  9966. collapseFirst : true,
  9967. /**
  9968. * @cfg {Number} minButtonWidth
  9969. * Minimum width in pixels of all {@link #buttons} in this panel (defaults to <code>75</code>)
  9970. */
  9971. minButtonWidth : 75,
  9972. /**
  9973. * @cfg {Boolean} unstyled
  9974. * Overrides the <code>{@link #baseCls}</code> setting to <code>{@link #baseCls} = 'x-plain'</code> which renders
  9975. * the panel unstyled except for required attributes for Ext layouts to function (e.g. overflow:hidden).
  9976. */
  9977. /**
  9978. * @cfg {String} elements
  9979. * A comma-delimited list of panel elements to initialize when the panel is rendered. Normally, this list will be
  9980. * generated automatically based on the items added to the panel at config time, but sometimes it might be useful to
  9981. * make sure a structural element is rendered even if not specified at config time (for example, you may want
  9982. * to add a button or toolbar dynamically after the panel has been rendered). Adding those elements to this
  9983. * list will allocate the required placeholders in the panel when it is rendered. Valid values are<div class="mdetail-params"><ul>
  9984. * <li><code>header</code></li>
  9985. * <li><code>tbar</code> (top bar)</li>
  9986. * <li><code>body</code></li>
  9987. * <li><code>bbar</code> (bottom bar)</li>
  9988. * <li><code>footer</code></li>
  9989. * </ul></div>
  9990. * Defaults to '<code>body</code>'.
  9991. */
  9992. elements : 'body',
  9993. /**
  9994. * @cfg {Boolean} preventBodyReset
  9995. * Defaults to <code>false</code>. When set to <code>true</code>, an extra css class <code>'x-panel-normal'</code>
  9996. * will be added to the panel's element, effectively applying css styles suggested by the W3C
  9997. * (see http://www.w3.org/TR/CSS21/sample.html) to the Panel's <b>body</b> element (not the header,
  9998. * footer, etc.).
  9999. */
  10000. preventBodyReset : false,
  10001. /**
  10002. * @cfg {Number/String} padding
  10003. * A shortcut for setting a padding style on the body element. The value can either be
  10004. * a number to be applied to all sides, or a normal css string describing padding.
  10005. * Defaults to <tt>undefined</tt>.
  10006. *
  10007. */
  10008. padding: undefined,
  10009. /** @cfg {String} resizeEvent
  10010. * The event to listen to for resizing in layouts. Defaults to <tt>'bodyresize'</tt>.
  10011. */
  10012. resizeEvent: 'bodyresize',
  10013. // protected - these could be used to customize the behavior of the window,
  10014. // but changing them would not be useful without further mofifications and
  10015. // could lead to unexpected or undesirable results.
  10016. toolTarget : 'header',
  10017. collapseEl : 'bwrap',
  10018. slideAnchor : 't',
  10019. disabledClass : '',
  10020. // private, notify box this class will handle heights
  10021. deferHeight : true,
  10022. // private
  10023. expandDefaults: {
  10024. duration : 0.25
  10025. },
  10026. // private
  10027. collapseDefaults : {
  10028. duration : 0.25
  10029. },
  10030. // private
  10031. initComponent : function(){
  10032. Ext.Panel.superclass.initComponent.call(this);
  10033. this.addEvents(
  10034. /**
  10035. * @event bodyresize
  10036. * Fires after the Panel has been resized.
  10037. * @param {Ext.Panel} p the Panel which has been resized.
  10038. * @param {Number} width The Panel body's new width.
  10039. * @param {Number} height The Panel body's new height.
  10040. */
  10041. 'bodyresize',
  10042. /**
  10043. * @event titlechange
  10044. * Fires after the Panel title has been {@link #title set} or {@link #setTitle changed}.
  10045. * @param {Ext.Panel} p the Panel which has had its title changed.
  10046. * @param {String} The new title.
  10047. */
  10048. 'titlechange',
  10049. /**
  10050. * @event iconchange
  10051. * Fires after the Panel icon class has been {@link #iconCls set} or {@link #setIconClass changed}.
  10052. * @param {Ext.Panel} p the Panel which has had its {@link #iconCls icon class} changed.
  10053. * @param {String} newIcon The new icon class.
  10054. * @param {String} oldIcon The old icon class.
  10055. */
  10056. 'iconchange',
  10057. /**
  10058. * @event collapse
  10059. * Fires after the Panel has been collapsed.
  10060. * @param {Ext.Panel} p the Panel that has been collapsed.
  10061. */
  10062. 'collapse',
  10063. /**
  10064. * @event expand
  10065. * Fires after the Panel has been expanded.
  10066. * @param {Ext.Panel} p The Panel that has been expanded.
  10067. */
  10068. 'expand',
  10069. /**
  10070. * @event beforecollapse
  10071. * Fires before the Panel is collapsed. A handler can return false to cancel the collapse.
  10072. * @param {Ext.Panel} p the Panel being collapsed.
  10073. * @param {Boolean} animate True if the collapse is animated, else false.
  10074. */
  10075. 'beforecollapse',
  10076. /**
  10077. * @event beforeexpand
  10078. * Fires before the Panel is expanded. A handler can return false to cancel the expand.
  10079. * @param {Ext.Panel} p The Panel being expanded.
  10080. * @param {Boolean} animate True if the expand is animated, else false.
  10081. */
  10082. 'beforeexpand',
  10083. /**
  10084. * @event beforeclose
  10085. * Fires before the Panel is closed. Note that Panels do not directly support being closed, but some
  10086. * Panel subclasses do (like {@link Ext.Window}) or a Panel within a Ext.TabPanel. This event only
  10087. * applies to such subclasses.
  10088. * A handler can return false to cancel the close.
  10089. * @param {Ext.Panel} p The Panel being closed.
  10090. */
  10091. 'beforeclose',
  10092. /**
  10093. * @event close
  10094. * Fires after the Panel is closed. Note that Panels do not directly support being closed, but some
  10095. * Panel subclasses do (like {@link Ext.Window}) or a Panel within a Ext.TabPanel.
  10096. * @param {Ext.Panel} p The Panel that has been closed.
  10097. */
  10098. 'close',
  10099. /**
  10100. * @event activate
  10101. * Fires after the Panel has been visually activated.
  10102. * Note that Panels do not directly support being activated, but some Panel subclasses
  10103. * do (like {@link Ext.Window}). Panels which are child Components of a TabPanel fire the
  10104. * activate and deactivate events under the control of the TabPanel.
  10105. * @param {Ext.Panel} p The Panel that has been activated.
  10106. */
  10107. 'activate',
  10108. /**
  10109. * @event deactivate
  10110. * Fires after the Panel has been visually deactivated.
  10111. * Note that Panels do not directly support being deactivated, but some Panel subclasses
  10112. * do (like {@link Ext.Window}). Panels which are child Components of a TabPanel fire the
  10113. * activate and deactivate events under the control of the TabPanel.
  10114. * @param {Ext.Panel} p The Panel that has been deactivated.
  10115. */
  10116. 'deactivate'
  10117. );
  10118. if(this.unstyled){
  10119. this.baseCls = 'x-plain';
  10120. }
  10121. this.toolbars = [];
  10122. // shortcuts
  10123. if(this.tbar){
  10124. this.elements += ',tbar';
  10125. this.topToolbar = this.createToolbar(this.tbar);
  10126. this.tbar = null;
  10127. }
  10128. if(this.bbar){
  10129. this.elements += ',bbar';
  10130. this.bottomToolbar = this.createToolbar(this.bbar);
  10131. this.bbar = null;
  10132. }
  10133. if(this.header === true){
  10134. this.elements += ',header';
  10135. this.header = null;
  10136. }else if(this.headerCfg || (this.title && this.header !== false)){
  10137. this.elements += ',header';
  10138. }
  10139. if(this.footerCfg || this.footer === true){
  10140. this.elements += ',footer';
  10141. this.footer = null;
  10142. }
  10143. if(this.buttons){
  10144. this.fbar = this.buttons;
  10145. this.buttons = null;
  10146. }
  10147. if(this.fbar){
  10148. this.createFbar(this.fbar);
  10149. }
  10150. if(this.autoLoad){
  10151. this.on('render', this.doAutoLoad, this, {delay:10});
  10152. }
  10153. },
  10154. // private
  10155. createFbar : function(fbar){
  10156. var min = this.minButtonWidth;
  10157. this.elements += ',footer';
  10158. this.fbar = this.createToolbar(fbar, {
  10159. buttonAlign: this.buttonAlign,
  10160. toolbarCls: 'x-panel-fbar',
  10161. enableOverflow: false,
  10162. defaults: function(c){
  10163. return {
  10164. minWidth: c.minWidth || min
  10165. };
  10166. }
  10167. });
  10168. // @compat addButton and buttons could possibly be removed
  10169. // @target 4.0
  10170. /**
  10171. * This Panel's Array of buttons as created from the <code>{@link #buttons}</code>
  10172. * config property. Read only.
  10173. * @type Array
  10174. * @property buttons
  10175. */
  10176. this.fbar.items.each(function(c){
  10177. c.minWidth = c.minWidth || this.minButtonWidth;
  10178. }, this);
  10179. this.buttons = this.fbar.items.items;
  10180. },
  10181. // private
  10182. createToolbar: function(tb, options){
  10183. var result;
  10184. // Convert array to proper toolbar config
  10185. if(Ext.isArray(tb)){
  10186. tb = {
  10187. items: tb
  10188. };
  10189. }
  10190. result = tb.events ? Ext.apply(tb, options) : this.createComponent(Ext.apply({}, tb, options), 'toolbar');
  10191. this.toolbars.push(result);
  10192. return result;
  10193. },
  10194. // private
  10195. createElement : function(name, pnode){
  10196. if(this[name]){
  10197. pnode.appendChild(this[name].dom);
  10198. return;
  10199. }
  10200. if(name === 'bwrap' || this.elements.indexOf(name) != -1){
  10201. if(this[name+'Cfg']){
  10202. this[name] = Ext.fly(pnode).createChild(this[name+'Cfg']);
  10203. }else{
  10204. var el = document.createElement('div');
  10205. el.className = this[name+'Cls'];
  10206. this[name] = Ext.get(pnode.appendChild(el));
  10207. }
  10208. if(this[name+'CssClass']){
  10209. this[name].addClass(this[name+'CssClass']);
  10210. }
  10211. if(this[name+'Style']){
  10212. this[name].applyStyles(this[name+'Style']);
  10213. }
  10214. }
  10215. },
  10216. // private
  10217. onRender : function(ct, position){
  10218. Ext.Panel.superclass.onRender.call(this, ct, position);
  10219. this.createClasses();
  10220. var el = this.el,
  10221. d = el.dom,
  10222. bw,
  10223. ts;
  10224. if(this.collapsible && !this.hideCollapseTool){
  10225. this.tools = this.tools ? this.tools.slice(0) : [];
  10226. this.tools[this.collapseFirst?'unshift':'push']({
  10227. id: 'toggle',
  10228. handler : this.toggleCollapse,
  10229. scope: this
  10230. });
  10231. }
  10232. if(this.tools){
  10233. ts = this.tools;
  10234. this.elements += (this.header !== false) ? ',header' : '';
  10235. }
  10236. this.tools = {};
  10237. el.addClass(this.baseCls);
  10238. if(d.firstChild){ // existing markup
  10239. this.header = el.down('.'+this.headerCls);
  10240. this.bwrap = el.down('.'+this.bwrapCls);
  10241. var cp = this.bwrap ? this.bwrap : el;
  10242. this.tbar = cp.down('.'+this.tbarCls);
  10243. this.body = cp.down('.'+this.bodyCls);
  10244. this.bbar = cp.down('.'+this.bbarCls);
  10245. this.footer = cp.down('.'+this.footerCls);
  10246. this.fromMarkup = true;
  10247. }
  10248. if (this.preventBodyReset === true) {
  10249. el.addClass('x-panel-reset');
  10250. }
  10251. if(this.cls){
  10252. el.addClass(this.cls);
  10253. }
  10254. if(this.buttons){
  10255. this.elements += ',footer';
  10256. }
  10257. // This block allows for maximum flexibility and performance when using existing markup
  10258. // framing requires special markup
  10259. if(this.frame){
  10260. el.insertHtml('afterBegin', String.format(Ext.Element.boxMarkup, this.baseCls));
  10261. this.createElement('header', d.firstChild.firstChild.firstChild);
  10262. this.createElement('bwrap', d);
  10263. // append the mid and bottom frame to the bwrap
  10264. bw = this.bwrap.dom;
  10265. var ml = d.childNodes[1], bl = d.childNodes[2];
  10266. bw.appendChild(ml);
  10267. bw.appendChild(bl);
  10268. var mc = bw.firstChild.firstChild.firstChild;
  10269. this.createElement('tbar', mc);
  10270. this.createElement('body', mc);
  10271. this.createElement('bbar', mc);
  10272. this.createElement('footer', bw.lastChild.firstChild.firstChild);
  10273. if(!this.footer){
  10274. this.bwrap.dom.lastChild.className += ' x-panel-nofooter';
  10275. }
  10276. /*
  10277. * Store a reference to this element so:
  10278. * a) We aren't looking it up all the time
  10279. * b) The last element is reported incorrectly when using a loadmask
  10280. */
  10281. this.ft = Ext.get(this.bwrap.dom.lastChild);
  10282. this.mc = Ext.get(mc);
  10283. }else{
  10284. this.createElement('header', d);
  10285. this.createElement('bwrap', d);
  10286. // append the mid and bottom frame to the bwrap
  10287. bw = this.bwrap.dom;
  10288. this.createElement('tbar', bw);
  10289. this.createElement('body', bw);
  10290. this.createElement('bbar', bw);
  10291. this.createElement('footer', bw);
  10292. if(!this.header){
  10293. this.body.addClass(this.bodyCls + '-noheader');
  10294. if(this.tbar){
  10295. this.tbar.addClass(this.tbarCls + '-noheader');
  10296. }
  10297. }
  10298. }
  10299. if(Ext.isDefined(this.padding)){
  10300. this.body.setStyle('padding', this.body.addUnits(this.padding));
  10301. }
  10302. if(this.border === false){
  10303. this.el.addClass(this.baseCls + '-noborder');
  10304. this.body.addClass(this.bodyCls + '-noborder');
  10305. if(this.header){
  10306. this.header.addClass(this.headerCls + '-noborder');
  10307. }
  10308. if(this.footer){
  10309. this.footer.addClass(this.footerCls + '-noborder');
  10310. }
  10311. if(this.tbar){
  10312. this.tbar.addClass(this.tbarCls + '-noborder');
  10313. }
  10314. if(this.bbar){
  10315. this.bbar.addClass(this.bbarCls + '-noborder');
  10316. }
  10317. }
  10318. if(this.bodyBorder === false){
  10319. this.body.addClass(this.bodyCls + '-noborder');
  10320. }
  10321. this.bwrap.enableDisplayMode('block');
  10322. if(this.header){
  10323. this.header.unselectable();
  10324. // for tools, we need to wrap any existing header markup
  10325. if(this.headerAsText){
  10326. this.header.dom.innerHTML =
  10327. '<span class="' + this.headerTextCls + '">'+this.header.dom.innerHTML+'</span>';
  10328. if(this.iconCls){
  10329. this.setIconClass(this.iconCls);
  10330. }
  10331. }
  10332. }
  10333. if(this.floating){
  10334. this.makeFloating(this.floating);
  10335. }
  10336. if(this.collapsible && this.titleCollapse && this.header){
  10337. this.mon(this.header, 'click', this.toggleCollapse, this);
  10338. this.header.setStyle('cursor', 'pointer');
  10339. }
  10340. if(ts){
  10341. this.addTool.apply(this, ts);
  10342. }
  10343. // Render Toolbars.
  10344. if(this.fbar){
  10345. this.footer.addClass('x-panel-btns');
  10346. this.fbar.ownerCt = this;
  10347. this.fbar.render(this.footer);
  10348. this.footer.createChild({cls:'x-clear'});
  10349. }
  10350. if(this.tbar && this.topToolbar){
  10351. this.topToolbar.ownerCt = this;
  10352. this.topToolbar.render(this.tbar);
  10353. }
  10354. if(this.bbar && this.bottomToolbar){
  10355. this.bottomToolbar.ownerCt = this;
  10356. this.bottomToolbar.render(this.bbar);
  10357. }
  10358. },
  10359. /**
  10360. * Sets the CSS class that provides the icon image for this panel. This method will replace any existing
  10361. * icon class if one has already been set and fire the {@link #iconchange} event after completion.
  10362. * @param {String} cls The new CSS class name
  10363. */
  10364. setIconClass : function(cls){
  10365. var old = this.iconCls;
  10366. this.iconCls = cls;
  10367. if(this.rendered && this.header){
  10368. if(this.frame){
  10369. this.header.addClass('x-panel-icon');
  10370. this.header.replaceClass(old, this.iconCls);
  10371. }else{
  10372. var hd = this.header,
  10373. img = hd.child('img.x-panel-inline-icon');
  10374. if(img){
  10375. Ext.fly(img).replaceClass(old, this.iconCls);
  10376. }else{
  10377. var hdspan = hd.child('span.' + this.headerTextCls);
  10378. if (hdspan) {
  10379. Ext.DomHelper.insertBefore(hdspan.dom, {
  10380. tag:'img', alt: '', src: Ext.BLANK_IMAGE_URL, cls:'x-panel-inline-icon '+this.iconCls
  10381. });
  10382. }
  10383. }
  10384. }
  10385. }
  10386. this.fireEvent('iconchange', this, cls, old);
  10387. },
  10388. // private
  10389. makeFloating : function(cfg){
  10390. this.floating = true;
  10391. this.el = new Ext.Layer(Ext.apply({}, cfg, {
  10392. shadow: Ext.isDefined(this.shadow) ? this.shadow : 'sides',
  10393. shadowOffset: this.shadowOffset,
  10394. constrain:false,
  10395. shim: this.shim === false ? false : undefined
  10396. }), this.el);
  10397. },
  10398. /**
  10399. * Returns the {@link Ext.Toolbar toolbar} from the top (<code>{@link #tbar}</code>) section of the panel.
  10400. * @return {Ext.Toolbar} The toolbar
  10401. */
  10402. getTopToolbar : function(){
  10403. return this.topToolbar;
  10404. },
  10405. /**
  10406. * Returns the {@link Ext.Toolbar toolbar} from the bottom (<code>{@link #bbar}</code>) section of the panel.
  10407. * @return {Ext.Toolbar} The toolbar
  10408. */
  10409. getBottomToolbar : function(){
  10410. return this.bottomToolbar;
  10411. },
  10412. /**
  10413. * Returns the {@link Ext.Toolbar toolbar} from the footer (<code>{@link #fbar}</code>) section of the panel.
  10414. * @return {Ext.Toolbar} The toolbar
  10415. */
  10416. getFooterToolbar : function() {
  10417. return this.fbar;
  10418. },
  10419. /**
  10420. * Adds a button to this panel. Note that this method must be called prior to rendering. The preferred
  10421. * approach is to add buttons via the {@link #buttons} config.
  10422. * @param {String/Object} config A valid {@link Ext.Button} config. A string will become the text for a default
  10423. * button config, an object will be treated as a button config object.
  10424. * @param {Function} handler The function to be called on button {@link Ext.Button#click}
  10425. * @param {Object} scope The scope (<code>this</code> reference) in which the button handler function is executed. Defaults to the Button.
  10426. * @return {Ext.Button} The button that was added
  10427. */
  10428. addButton : function(config, handler, scope){
  10429. if(!this.fbar){
  10430. this.createFbar([]);
  10431. }
  10432. if(handler){
  10433. if(Ext.isString(config)){
  10434. config = {text: config};
  10435. }
  10436. config = Ext.apply({
  10437. handler: handler,
  10438. scope: scope
  10439. }, config);
  10440. }
  10441. return this.fbar.add(config);
  10442. },
  10443. // private
  10444. addTool : function(){
  10445. if(!this.rendered){
  10446. if(!this.tools){
  10447. this.tools = [];
  10448. }
  10449. Ext.each(arguments, function(arg){
  10450. this.tools.push(arg);
  10451. }, this);
  10452. return;
  10453. }
  10454. // nowhere to render tools!
  10455. if(!this[this.toolTarget]){
  10456. return;
  10457. }
  10458. if(!this.toolTemplate){
  10459. // initialize the global tool template on first use
  10460. var tt = new Ext.Template(
  10461. '<div class="x-tool x-tool-{id}">&#160;</div>'
  10462. );
  10463. tt.disableFormats = true;
  10464. tt.compile();
  10465. Ext.Panel.prototype.toolTemplate = tt;
  10466. }
  10467. for(var i = 0, a = arguments, len = a.length; i < len; i++) {
  10468. var tc = a[i];
  10469. if(!this.tools[tc.id]){
  10470. var overCls = 'x-tool-'+tc.id+'-over';
  10471. var t = this.toolTemplate.insertFirst(this[this.toolTarget], tc, true);
  10472. this.tools[tc.id] = t;
  10473. t.enableDisplayMode('block');
  10474. this.mon(t, 'click', this.createToolHandler(t, tc, overCls, this));
  10475. if(tc.on){
  10476. this.mon(t, tc.on);
  10477. }
  10478. if(tc.hidden){
  10479. t.hide();
  10480. }
  10481. if(tc.qtip){
  10482. if(Ext.isObject(tc.qtip)){
  10483. Ext.QuickTips.register(Ext.apply({
  10484. target: t.id
  10485. }, tc.qtip));
  10486. } else {
  10487. t.dom.qtip = tc.qtip;
  10488. }
  10489. }
  10490. t.addClassOnOver(overCls);
  10491. }
  10492. }
  10493. },
  10494. onLayout : function(shallow, force){
  10495. Ext.Panel.superclass.onLayout.apply(this, arguments);
  10496. if(this.hasLayout && this.toolbars.length > 0){
  10497. Ext.each(this.toolbars, function(tb){
  10498. tb.doLayout(undefined, force);
  10499. });
  10500. this.syncHeight();
  10501. }
  10502. },
  10503. syncHeight : function(){
  10504. var h = this.toolbarHeight,
  10505. bd = this.body,
  10506. lsh = this.lastSize.height,
  10507. sz;
  10508. if(this.autoHeight || !Ext.isDefined(lsh) || lsh == 'auto'){
  10509. return;
  10510. }
  10511. if(h != this.getToolbarHeight()){
  10512. h = Math.max(0, lsh - this.getFrameHeight());
  10513. bd.setHeight(h);
  10514. sz = bd.getSize();
  10515. this.toolbarHeight = this.getToolbarHeight();
  10516. this.onBodyResize(sz.width, sz.height);
  10517. }
  10518. },
  10519. // private
  10520. onShow : function(){
  10521. if(this.floating){
  10522. return this.el.show();
  10523. }
  10524. Ext.Panel.superclass.onShow.call(this);
  10525. },
  10526. // private
  10527. onHide : function(){
  10528. if(this.floating){
  10529. return this.el.hide();
  10530. }
  10531. Ext.Panel.superclass.onHide.call(this);
  10532. },
  10533. // private
  10534. createToolHandler : function(t, tc, overCls, panel){
  10535. return function(e){
  10536. t.removeClass(overCls);
  10537. if(tc.stopEvent !== false){
  10538. e.stopEvent();
  10539. }
  10540. if(tc.handler){
  10541. tc.handler.call(tc.scope || t, e, t, panel, tc);
  10542. }
  10543. };
  10544. },
  10545. // private
  10546. afterRender : function(){
  10547. if(this.floating && !this.hidden){
  10548. this.el.show();
  10549. }
  10550. if(this.title){
  10551. this.setTitle(this.title);
  10552. }
  10553. Ext.Panel.superclass.afterRender.call(this); // do sizing calcs last
  10554. if (this.collapsed) {
  10555. this.collapsed = false;
  10556. this.collapse(false);
  10557. }
  10558. this.initEvents();
  10559. },
  10560. // private
  10561. getKeyMap : function(){
  10562. if(!this.keyMap){
  10563. this.keyMap = new Ext.KeyMap(this.el, this.keys);
  10564. }
  10565. return this.keyMap;
  10566. },
  10567. // private
  10568. initEvents : function(){
  10569. if(this.keys){
  10570. this.getKeyMap();
  10571. }
  10572. if(this.draggable){
  10573. this.initDraggable();
  10574. }
  10575. if(this.toolbars.length > 0){
  10576. Ext.each(this.toolbars, function(tb){
  10577. tb.doLayout();
  10578. tb.on({
  10579. scope: this,
  10580. afterlayout: this.syncHeight,
  10581. remove: this.syncHeight
  10582. });
  10583. }, this);
  10584. this.syncHeight();
  10585. }
  10586. },
  10587. // private
  10588. initDraggable : function(){
  10589. /**
  10590. * <p>If this Panel is configured {@link #draggable}, this property will contain
  10591. * an instance of {@link Ext.dd.DragSource} which handles dragging the Panel.</p>
  10592. * The developer must provide implementations of the abstract methods of {@link Ext.dd.DragSource}
  10593. * in order to supply behaviour for each stage of the drag/drop process. See {@link #draggable}.
  10594. * @type Ext.dd.DragSource
  10595. * @property dd
  10596. */
  10597. this.dd = new Ext.Panel.DD(this, Ext.isBoolean(this.draggable) ? null : this.draggable);
  10598. },
  10599. // private
  10600. beforeEffect : function(anim){
  10601. if(this.floating){
  10602. this.el.beforeAction();
  10603. }
  10604. if(anim !== false){
  10605. this.el.addClass('x-panel-animated');
  10606. }
  10607. },
  10608. // private
  10609. afterEffect : function(anim){
  10610. this.syncShadow();
  10611. this.el.removeClass('x-panel-animated');
  10612. },
  10613. // private - wraps up an animation param with internal callbacks
  10614. createEffect : function(a, cb, scope){
  10615. var o = {
  10616. scope:scope,
  10617. block:true
  10618. };
  10619. if(a === true){
  10620. o.callback = cb;
  10621. return o;
  10622. }else if(!a.callback){
  10623. o.callback = cb;
  10624. }else { // wrap it up
  10625. o.callback = function(){
  10626. cb.call(scope);
  10627. Ext.callback(a.callback, a.scope);
  10628. };
  10629. }
  10630. return Ext.applyIf(o, a);
  10631. },
  10632. /**
  10633. * Collapses the panel body so that it becomes hidden. Fires the {@link #beforecollapse} event which will
  10634. * cancel the collapse action if it returns false.
  10635. * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
  10636. * {@link #animCollapse} panel config)
  10637. * @return {Ext.Panel} this
  10638. */
  10639. collapse : function(animate){
  10640. if(this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforecollapse', this, animate) === false){
  10641. return;
  10642. }
  10643. var doAnim = animate === true || (animate !== false && this.animCollapse);
  10644. this.beforeEffect(doAnim);
  10645. this.onCollapse(doAnim, animate);
  10646. return this;
  10647. },
  10648. // private
  10649. onCollapse : function(doAnim, animArg){
  10650. if(doAnim){
  10651. this[this.collapseEl].slideOut(this.slideAnchor,
  10652. Ext.apply(this.createEffect(animArg||true, this.afterCollapse, this),
  10653. this.collapseDefaults));
  10654. }else{
  10655. this[this.collapseEl].hide(this.hideMode);
  10656. this.afterCollapse(false);
  10657. }
  10658. },
  10659. // private
  10660. afterCollapse : function(anim){
  10661. this.collapsed = true;
  10662. this.el.addClass(this.collapsedCls);
  10663. if(anim !== false){
  10664. this[this.collapseEl].hide(this.hideMode);
  10665. }
  10666. this.afterEffect(anim);
  10667. // Reset lastSize of all sub-components so they KNOW they are in a collapsed container
  10668. this.cascade(function(c) {
  10669. if (c.lastSize) {
  10670. c.lastSize = { width: undefined, height: undefined };
  10671. }
  10672. });
  10673. this.fireEvent('collapse', this);
  10674. },
  10675. /**
  10676. * Expands the panel body so that it becomes visible. Fires the {@link #beforeexpand} event which will
  10677. * cancel the expand action if it returns false.
  10678. * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
  10679. * {@link #animCollapse} panel config)
  10680. * @return {Ext.Panel} this
  10681. */
  10682. expand : function(animate){
  10683. if(!this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforeexpand', this, animate) === false){
  10684. return;
  10685. }
  10686. var doAnim = animate === true || (animate !== false && this.animCollapse);
  10687. this.el.removeClass(this.collapsedCls);
  10688. this.beforeEffect(doAnim);
  10689. this.onExpand(doAnim, animate);
  10690. return this;
  10691. },
  10692. // private
  10693. onExpand : function(doAnim, animArg){
  10694. if(doAnim){
  10695. this[this.collapseEl].slideIn(this.slideAnchor,
  10696. Ext.apply(this.createEffect(animArg||true, this.afterExpand, this),
  10697. this.expandDefaults));
  10698. }else{
  10699. this[this.collapseEl].show(this.hideMode);
  10700. this.afterExpand(false);
  10701. }
  10702. },
  10703. // private
  10704. afterExpand : function(anim){
  10705. this.collapsed = false;
  10706. if(anim !== false){
  10707. this[this.collapseEl].show(this.hideMode);
  10708. }
  10709. this.afterEffect(anim);
  10710. if (this.deferLayout) {
  10711. delete this.deferLayout;
  10712. this.doLayout(true);
  10713. }
  10714. this.fireEvent('expand', this);
  10715. },
  10716. /**
  10717. * Shortcut for performing an {@link #expand} or {@link #collapse} based on the current state of the panel.
  10718. * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
  10719. * {@link #animCollapse} panel config)
  10720. * @return {Ext.Panel} this
  10721. */
  10722. toggleCollapse : function(animate){
  10723. this[this.collapsed ? 'expand' : 'collapse'](animate);
  10724. return this;
  10725. },
  10726. // private
  10727. onDisable : function(){
  10728. if(this.rendered && this.maskDisabled){
  10729. this.el.mask();
  10730. }
  10731. Ext.Panel.superclass.onDisable.call(this);
  10732. },
  10733. // private
  10734. onEnable : function(){
  10735. if(this.rendered && this.maskDisabled){
  10736. this.el.unmask();
  10737. }
  10738. Ext.Panel.superclass.onEnable.call(this);
  10739. },
  10740. // private
  10741. onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
  10742. var w = adjWidth,
  10743. h = adjHeight;
  10744. if(Ext.isDefined(w) || Ext.isDefined(h)){
  10745. if(!this.collapsed){
  10746. // First, set the the Panel's body width.
  10747. // If we have auto-widthed it, get the resulting full offset width so we can size the Toolbars to match
  10748. // The Toolbars must not buffer this resize operation because we need to know their heights.
  10749. if(Ext.isNumber(w)){
  10750. this.body.setWidth(w = this.adjustBodyWidth(w - this.getFrameWidth()));
  10751. } else if (w == 'auto') {
  10752. w = this.body.setWidth('auto').dom.offsetWidth;
  10753. } else {
  10754. w = this.body.dom.offsetWidth;
  10755. }
  10756. if(this.tbar){
  10757. this.tbar.setWidth(w);
  10758. if(this.topToolbar){
  10759. this.topToolbar.setSize(w);
  10760. }
  10761. }
  10762. if(this.bbar){
  10763. this.bbar.setWidth(w);
  10764. if(this.bottomToolbar){
  10765. this.bottomToolbar.setSize(w);
  10766. // The bbar does not move on resize without this.
  10767. if (Ext.isIE9m) {
  10768. this.bbar.setStyle('position', 'static');
  10769. this.bbar.setStyle('position', '');
  10770. }
  10771. }
  10772. }
  10773. if(this.footer){
  10774. this.footer.setWidth(w);
  10775. if(this.fbar){
  10776. this.fbar.setSize(Ext.isIE9m ? (w - this.footer.getFrameWidth('lr')) : 'auto');
  10777. }
  10778. }
  10779. // At this point, the Toolbars must be layed out for getFrameHeight to find a result.
  10780. if(Ext.isNumber(h)){
  10781. h = Math.max(0, h - this.getFrameHeight());
  10782. //h = Math.max(0, h - (this.getHeight() - this.body.getHeight()));
  10783. this.body.setHeight(h);
  10784. }else if(h == 'auto'){
  10785. this.body.setHeight(h);
  10786. }
  10787. if(this.disabled && this.el._mask){
  10788. this.el._mask.setSize(this.el.dom.clientWidth, this.el.getHeight());
  10789. }
  10790. }else{
  10791. // Adds an event to set the correct height afterExpand. This accounts for the deferHeight flag in panel
  10792. this.queuedBodySize = {width: w, height: h};
  10793. if(!this.queuedExpand && this.allowQueuedExpand !== false){
  10794. this.queuedExpand = true;
  10795. this.on('expand', function(){
  10796. delete this.queuedExpand;
  10797. this.onResize(this.queuedBodySize.width, this.queuedBodySize.height);
  10798. }, this, {single:true});
  10799. }
  10800. }
  10801. this.onBodyResize(w, h);
  10802. }
  10803. this.syncShadow();
  10804. Ext.Panel.superclass.onResize.call(this, adjWidth, adjHeight, rawWidth, rawHeight);
  10805. },
  10806. // private
  10807. onBodyResize: function(w, h){
  10808. this.fireEvent('bodyresize', this, w, h);
  10809. },
  10810. // private
  10811. getToolbarHeight: function(){
  10812. var h = 0;
  10813. if(this.rendered){
  10814. Ext.each(this.toolbars, function(tb){
  10815. h += tb.getHeight();
  10816. }, this);
  10817. }
  10818. return h;
  10819. },
  10820. // deprecate
  10821. adjustBodyHeight : function(h){
  10822. return h;
  10823. },
  10824. // private
  10825. adjustBodyWidth : function(w){
  10826. return w;
  10827. },
  10828. // private
  10829. onPosition : function(){
  10830. this.syncShadow();
  10831. },
  10832. /**
  10833. * Returns the width in pixels of the framing elements of this panel (not including the body width). To
  10834. * retrieve the body width see {@link #getInnerWidth}.
  10835. * @return {Number} The frame width
  10836. */
  10837. getFrameWidth : function(){
  10838. var w = this.el.getFrameWidth('lr') + this.bwrap.getFrameWidth('lr');
  10839. if(this.frame){
  10840. var l = this.bwrap.dom.firstChild;
  10841. w += (Ext.fly(l).getFrameWidth('l') + Ext.fly(l.firstChild).getFrameWidth('r'));
  10842. w += this.mc.getFrameWidth('lr');
  10843. }
  10844. return w;
  10845. },
  10846. /**
  10847. * Returns the height in pixels of the framing elements of this panel (including any top and bottom bars and
  10848. * header and footer elements, but not including the body height). To retrieve the body height see {@link #getInnerHeight}.
  10849. * @return {Number} The frame height
  10850. */
  10851. getFrameHeight : function() {
  10852. var h = this.el.getFrameWidth('tb') + this.bwrap.getFrameWidth('tb');
  10853. h += (this.tbar ? this.tbar.getHeight() : 0) +
  10854. (this.bbar ? this.bbar.getHeight() : 0);
  10855. if(this.frame){
  10856. h += this.el.dom.firstChild.offsetHeight + this.ft.dom.offsetHeight + this.mc.getFrameWidth('tb');
  10857. }else{
  10858. h += (this.header ? this.header.getHeight() : 0) +
  10859. (this.footer ? this.footer.getHeight() : 0);
  10860. }
  10861. return h;
  10862. },
  10863. /**
  10864. * Returns the width in pixels of the body element (not including the width of any framing elements).
  10865. * For the frame width see {@link #getFrameWidth}.
  10866. * @return {Number} The body width
  10867. */
  10868. getInnerWidth : function(){
  10869. return this.getSize().width - this.getFrameWidth();
  10870. },
  10871. /**
  10872. * Returns the height in pixels of the body element (not including the height of any framing elements).
  10873. * For the frame height see {@link #getFrameHeight}.
  10874. * @return {Number} The body height
  10875. */
  10876. getInnerHeight : function(){
  10877. return this.body.getHeight();
  10878. /* Deprecate
  10879. return this.getSize().height - this.getFrameHeight();
  10880. */
  10881. },
  10882. // private
  10883. syncShadow : function(){
  10884. if(this.floating){
  10885. this.el.sync(true);
  10886. }
  10887. },
  10888. // private
  10889. getLayoutTarget : function(){
  10890. return this.body;
  10891. },
  10892. // private
  10893. getContentTarget : function(){
  10894. return this.body;
  10895. },
  10896. /**
  10897. * <p>Sets the title text for the panel and optionally the {@link #iconCls icon class}.</p>
  10898. * <p>In order to be able to set the title, a header element must have been created
  10899. * for the Panel. This is triggered either by configuring the Panel with a non-blank <code>{@link #title}</code>,
  10900. * or configuring it with <code><b>{@link #header}: true</b></code>.</p>
  10901. * @param {String} title The title text to set
  10902. * @param {String} iconCls (optional) {@link #iconCls iconCls} A user-defined CSS class that provides the icon image for this panel
  10903. */
  10904. setTitle : function(title, iconCls){
  10905. this.title = title;
  10906. if(this.header && this.headerAsText){
  10907. this.header.child('span').update(title);
  10908. }
  10909. if(iconCls){
  10910. this.setIconClass(iconCls);
  10911. }
  10912. this.fireEvent('titlechange', this, title);
  10913. return this;
  10914. },
  10915. /**
  10916. * Get the {@link Ext.Updater} for this panel. Enables you to perform Ajax updates of this panel's body.
  10917. * @return {Ext.Updater} The Updater
  10918. */
  10919. getUpdater : function(){
  10920. return this.body.getUpdater();
  10921. },
  10922. /**
  10923. * Loads this content panel immediately with content returned from an XHR call.
  10924. * @param {Object/String/Function} config A config object containing any of the following options:
  10925. <pre><code>
  10926. panel.load({
  10927. url: 'your-url.php',
  10928. params: {param1: 'foo', param2: 'bar'}, // or a URL encoded string
  10929. callback: yourFunction,
  10930. scope: yourObject, // optional scope for the callback
  10931. discardUrl: false,
  10932. nocache: false,
  10933. text: 'Loading...',
  10934. timeout: 30,
  10935. scripts: false
  10936. });
  10937. </code></pre>
  10938. * The only required property is url. The optional properties nocache, text and scripts
  10939. * are shorthand for disableCaching, indicatorText and loadScripts and are used to set their
  10940. * associated property on this panel Updater instance.
  10941. * @return {Ext.Panel} this
  10942. */
  10943. load : function(){
  10944. var um = this.body.getUpdater();
  10945. um.update.apply(um, arguments);
  10946. return this;
  10947. },
  10948. // private
  10949. beforeDestroy : function(){
  10950. Ext.Panel.superclass.beforeDestroy.call(this);
  10951. if(this.header){
  10952. this.header.removeAllListeners();
  10953. }
  10954. if(this.tools){
  10955. for(var k in this.tools){
  10956. Ext.destroy(this.tools[k]);
  10957. }
  10958. }
  10959. if(this.toolbars.length > 0){
  10960. Ext.each(this.toolbars, function(tb){
  10961. tb.un('afterlayout', this.syncHeight, this);
  10962. tb.un('remove', this.syncHeight, this);
  10963. }, this);
  10964. }
  10965. if(Ext.isArray(this.buttons)){
  10966. while(this.buttons.length) {
  10967. Ext.destroy(this.buttons[0]);
  10968. }
  10969. }
  10970. if(this.rendered){
  10971. Ext.destroy(
  10972. this.ft,
  10973. this.header,
  10974. this.footer,
  10975. this.tbar,
  10976. this.bbar,
  10977. this.body,
  10978. this.mc,
  10979. this.bwrap,
  10980. this.dd
  10981. );
  10982. if (this.fbar) {
  10983. Ext.destroy(
  10984. this.fbar,
  10985. this.fbar.el
  10986. );
  10987. }
  10988. }
  10989. Ext.destroy(this.toolbars);
  10990. },
  10991. // private
  10992. createClasses : function(){
  10993. this.headerCls = this.baseCls + '-header';
  10994. this.headerTextCls = this.baseCls + '-header-text';
  10995. this.bwrapCls = this.baseCls + '-bwrap';
  10996. this.tbarCls = this.baseCls + '-tbar';
  10997. this.bodyCls = this.baseCls + '-body';
  10998. this.bbarCls = this.baseCls + '-bbar';
  10999. this.footerCls = this.baseCls + '-footer';
  11000. },
  11001. // private
  11002. createGhost : function(cls, useShim, appendTo){
  11003. var el = document.createElement('div');
  11004. el.className = 'x-panel-ghost ' + (cls ? cls : '');
  11005. if(this.header){
  11006. el.appendChild(this.el.dom.firstChild.cloneNode(true));
  11007. }
  11008. Ext.fly(el.appendChild(document.createElement('ul'))).setHeight(this.bwrap.getHeight());
  11009. el.style.width = this.el.dom.offsetWidth + 'px';;
  11010. if(!appendTo){
  11011. this.container.dom.appendChild(el);
  11012. }else{
  11013. Ext.getDom(appendTo).appendChild(el);
  11014. }
  11015. if(useShim !== false && this.el.useShim !== false){
  11016. var layer = new Ext.Layer({shadow:false, useDisplay:true, constrain:false}, el);
  11017. layer.show();
  11018. return layer;
  11019. }else{
  11020. return new Ext.Element(el);
  11021. }
  11022. },
  11023. // private
  11024. doAutoLoad : function(){
  11025. var u = this.body.getUpdater();
  11026. if(this.renderer){
  11027. u.setRenderer(this.renderer);
  11028. }
  11029. u.update(Ext.isObject(this.autoLoad) ? this.autoLoad : {url: this.autoLoad});
  11030. },
  11031. /**
  11032. * Retrieve a tool by id.
  11033. * @param {String} id
  11034. * @return {Object} tool
  11035. */
  11036. getTool : function(id) {
  11037. return this.tools[id];
  11038. }
  11039. /**
  11040. * @cfg {String} autoEl @hide
  11041. */
  11042. });
  11043. Ext.reg('panel', Ext.Panel);
  11044. /**
  11045. * @class Ext.Editor
  11046. * @extends Ext.Component
  11047. * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
  11048. * @constructor
  11049. * Create a new Editor
  11050. * @param {Object} config The config object
  11051. * @xtype editor
  11052. */
  11053. Ext.Editor = function(field, config){
  11054. if(field.field){
  11055. this.field = Ext.create(field.field, 'textfield');
  11056. config = Ext.apply({}, field); // copy so we don't disturb original config
  11057. delete config.field;
  11058. }else{
  11059. this.field = field;
  11060. }
  11061. Ext.Editor.superclass.constructor.call(this, config);
  11062. };
  11063. Ext.extend(Ext.Editor, Ext.Component, {
  11064. /**
  11065. * @cfg {Ext.form.Field} field
  11066. * The Field object (or descendant) or config object for field
  11067. */
  11068. /**
  11069. * @cfg {Boolean} allowBlur
  11070. * True to {@link #completeEdit complete the editing process} if in edit mode when the
  11071. * field is blurred. Defaults to <tt>true</tt>.
  11072. */
  11073. allowBlur: true,
  11074. /**
  11075. * @cfg {Boolean/String} autoSize
  11076. * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
  11077. * or "height" to adopt the height only, "none" to always use the field dimensions. (defaults to false)
  11078. */
  11079. /**
  11080. * @cfg {Boolean} revertInvalid
  11081. * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
  11082. * validation fails (defaults to true)
  11083. */
  11084. /**
  11085. * @cfg {Boolean} ignoreNoChange
  11086. * True to skip the edit completion process (no save, no events fired) if the user completes an edit and
  11087. * the value has not changed (defaults to false). Applies only to string values - edits for other data types
  11088. * will never be ignored.
  11089. */
  11090. /**
  11091. * @cfg {Boolean} hideEl
  11092. * False to keep the bound element visible while the editor is displayed (defaults to true)
  11093. */
  11094. /**
  11095. * @cfg {Mixed} value
  11096. * The data value of the underlying field (defaults to "")
  11097. */
  11098. value : "",
  11099. /**
  11100. * @cfg {String} alignment
  11101. * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "c-c?").
  11102. */
  11103. alignment: "c-c?",
  11104. /**
  11105. * @cfg {Array} offsets
  11106. * The offsets to use when aligning (see {@link Ext.Element#alignTo} for more details. Defaults to <tt>[0, 0]</tt>.
  11107. */
  11108. offsets: [0, 0],
  11109. /**
  11110. * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
  11111. * for bottom-right shadow (defaults to "frame")
  11112. */
  11113. shadow : "frame",
  11114. /**
  11115. * @cfg {Boolean} constrain True to constrain the editor to the viewport
  11116. */
  11117. constrain : false,
  11118. /**
  11119. * @cfg {Boolean} swallowKeys Handle the keydown/keypress events so they don't propagate (defaults to true)
  11120. */
  11121. swallowKeys : true,
  11122. /**
  11123. * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed. Defaults to <tt>true</tt>.
  11124. */
  11125. completeOnEnter : true,
  11126. /**
  11127. * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed. Defaults to <tt>true</tt>.
  11128. */
  11129. cancelOnEsc : true,
  11130. /**
  11131. * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
  11132. */
  11133. updateEl : false,
  11134. initComponent : function(){
  11135. Ext.Editor.superclass.initComponent.call(this);
  11136. this.addEvents(
  11137. /**
  11138. * @event beforestartedit
  11139. * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
  11140. * false from the handler of this event.
  11141. * @param {Editor} this
  11142. * @param {Ext.Element} boundEl The underlying element bound to this editor
  11143. * @param {Mixed} value The field value being set
  11144. */
  11145. "beforestartedit",
  11146. /**
  11147. * @event startedit
  11148. * Fires when this editor is displayed
  11149. * @param {Ext.Element} boundEl The underlying element bound to this editor
  11150. * @param {Mixed} value The starting field value
  11151. */
  11152. "startedit",
  11153. /**
  11154. * @event beforecomplete
  11155. * Fires after a change has been made to the field, but before the change is reflected in the underlying
  11156. * field. Saving the change to the field can be canceled by returning false from the handler of this event.
  11157. * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
  11158. * event will not fire since no edit actually occurred.
  11159. * @param {Editor} this
  11160. * @param {Mixed} value The current field value
  11161. * @param {Mixed} startValue The original field value
  11162. */
  11163. "beforecomplete",
  11164. /**
  11165. * @event complete
  11166. * Fires after editing is complete and any changed value has been written to the underlying field.
  11167. * @param {Editor} this
  11168. * @param {Mixed} value The current field value
  11169. * @param {Mixed} startValue The original field value
  11170. */
  11171. "complete",
  11172. /**
  11173. * @event canceledit
  11174. * Fires after editing has been canceled and the editor's value has been reset.
  11175. * @param {Editor} this
  11176. * @param {Mixed} value The user-entered field value that was discarded
  11177. * @param {Mixed} startValue The original field value that was set back into the editor after cancel
  11178. */
  11179. "canceledit",
  11180. /**
  11181. * @event specialkey
  11182. * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
  11183. * {@link Ext.EventObject#getKey} to determine which key was pressed.
  11184. * @param {Ext.form.Field} this
  11185. * @param {Ext.EventObject} e The event object
  11186. */
  11187. "specialkey"
  11188. );
  11189. },
  11190. // private
  11191. onRender : function(ct, position){
  11192. this.el = new Ext.Layer({
  11193. shadow: this.shadow,
  11194. cls: "x-editor",
  11195. parentEl : ct,
  11196. shim : this.shim,
  11197. shadowOffset: this.shadowOffset || 4,
  11198. id: this.id,
  11199. constrain: this.constrain
  11200. });
  11201. if(this.zIndex){
  11202. this.el.setZIndex(this.zIndex);
  11203. }
  11204. this.el.setStyle("overflow", Ext.isGecko ? "auto" : "hidden");
  11205. if(this.field.msgTarget != 'title'){
  11206. this.field.msgTarget = 'qtip';
  11207. }
  11208. this.field.inEditor = true;
  11209. this.mon(this.field, {
  11210. scope: this,
  11211. blur: this.onBlur,
  11212. specialkey: this.onSpecialKey
  11213. });
  11214. if(this.field.grow){
  11215. this.mon(this.field, "autosize", this.el.sync, this.el, {delay:1});
  11216. }
  11217. this.field.render(this.el).show();
  11218. this.field.getEl().dom.name = '';
  11219. if(this.swallowKeys){
  11220. this.field.el.swallowEvent([
  11221. 'keypress', // *** Opera
  11222. 'keydown' // *** all other browsers
  11223. ]);
  11224. }
  11225. },
  11226. // private
  11227. onSpecialKey : function(field, e){
  11228. var key = e.getKey(),
  11229. complete = this.completeOnEnter && key == e.ENTER,
  11230. cancel = this.cancelOnEsc && key == e.ESC;
  11231. if(complete || cancel){
  11232. e.stopEvent();
  11233. if(complete){
  11234. this.completeEdit();
  11235. }else{
  11236. this.cancelEdit();
  11237. }
  11238. if(field.triggerBlur){
  11239. field.triggerBlur();
  11240. }
  11241. }
  11242. this.fireEvent('specialkey', field, e);
  11243. },
  11244. /**
  11245. * Starts the editing process and shows the editor.
  11246. * @param {Mixed} el The element to edit
  11247. * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
  11248. * to the innerHTML of el.
  11249. */
  11250. startEdit : function(el, value){
  11251. if(this.editing){
  11252. this.completeEdit();
  11253. }
  11254. this.boundEl = Ext.get(el);
  11255. var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
  11256. if(!this.rendered){
  11257. this.render(this.parentEl || document.body);
  11258. }
  11259. if(this.fireEvent("beforestartedit", this, this.boundEl, v) !== false){
  11260. this.startValue = v;
  11261. this.field.reset();
  11262. this.field.setValue(v);
  11263. this.realign(true);
  11264. this.editing = true;
  11265. this.show();
  11266. }
  11267. },
  11268. // private
  11269. doAutoSize : function(){
  11270. if(this.autoSize){
  11271. var sz = this.boundEl.getSize(),
  11272. fs = this.field.getSize();
  11273. switch(this.autoSize){
  11274. case "width":
  11275. this.setSize(sz.width, fs.height);
  11276. break;
  11277. case "height":
  11278. this.setSize(fs.width, sz.height);
  11279. break;
  11280. case "none":
  11281. this.setSize(fs.width, fs.height);
  11282. break;
  11283. default:
  11284. this.setSize(sz.width, sz.height);
  11285. }
  11286. }
  11287. },
  11288. /**
  11289. * Sets the height and width of this editor.
  11290. * @param {Number} width The new width
  11291. * @param {Number} height The new height
  11292. */
  11293. setSize : function(w, h){
  11294. delete this.field.lastSize;
  11295. this.field.setSize(w, h);
  11296. if(this.el){
  11297. // IE7 in strict mode doesn't size properly.
  11298. if(Ext.isGecko2 || Ext.isOpera || (Ext.isIE7 && Ext.isStrict)){
  11299. // prevent layer scrollbars
  11300. this.el.setSize(w, h);
  11301. }
  11302. this.el.sync();
  11303. }
  11304. },
  11305. /**
  11306. * Realigns the editor to the bound field based on the current alignment config value.
  11307. * @param {Boolean} autoSize (optional) True to size the field to the dimensions of the bound element.
  11308. */
  11309. realign : function(autoSize){
  11310. if(autoSize === true){
  11311. this.doAutoSize();
  11312. }
  11313. this.el.alignTo(this.boundEl, this.alignment, this.offsets);
  11314. },
  11315. /**
  11316. * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
  11317. * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
  11318. */
  11319. completeEdit : function(remainVisible){
  11320. if(!this.editing){
  11321. return;
  11322. }
  11323. // Assert combo values first
  11324. if (this.field.assertValue) {
  11325. this.field.assertValue();
  11326. }
  11327. var v = this.getValue();
  11328. if(!this.field.isValid()){
  11329. if(this.revertInvalid !== false){
  11330. this.cancelEdit(remainVisible);
  11331. }
  11332. return;
  11333. }
  11334. if(String(v) === String(this.startValue) && this.ignoreNoChange){
  11335. this.hideEdit(remainVisible);
  11336. return;
  11337. }
  11338. if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
  11339. v = this.getValue();
  11340. if(this.updateEl && this.boundEl){
  11341. this.boundEl.update(v);
  11342. }
  11343. this.hideEdit(remainVisible);
  11344. this.fireEvent("complete", this, v, this.startValue);
  11345. }
  11346. },
  11347. // private
  11348. onShow : function(){
  11349. this.el.show();
  11350. if(this.hideEl !== false){
  11351. this.boundEl.hide();
  11352. }
  11353. this.field.show().focus(false, true);
  11354. this.fireEvent("startedit", this.boundEl, this.startValue);
  11355. },
  11356. /**
  11357. * Cancels the editing process and hides the editor without persisting any changes. The field value will be
  11358. * reverted to the original starting value.
  11359. * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
  11360. * cancel (defaults to false)
  11361. */
  11362. cancelEdit : function(remainVisible){
  11363. if(this.editing){
  11364. var v = this.getValue();
  11365. this.setValue(this.startValue);
  11366. this.hideEdit(remainVisible);
  11367. this.fireEvent("canceledit", this, v, this.startValue);
  11368. }
  11369. },
  11370. // private
  11371. hideEdit: function(remainVisible){
  11372. if(remainVisible !== true){
  11373. this.editing = false;
  11374. this.hide();
  11375. }
  11376. },
  11377. // private
  11378. onBlur : function(){
  11379. // selectSameEditor flag allows the same editor to be started without onBlur firing on itself
  11380. if(this.allowBlur === true && this.editing && this.selectSameEditor !== true){
  11381. this.completeEdit();
  11382. }
  11383. },
  11384. // private
  11385. onHide : function(){
  11386. if(this.editing){
  11387. this.completeEdit();
  11388. return;
  11389. }
  11390. this.field.blur();
  11391. if(this.field.collapse){
  11392. this.field.collapse();
  11393. }
  11394. this.el.hide();
  11395. if(this.hideEl !== false){
  11396. this.boundEl.show();
  11397. }
  11398. },
  11399. /**
  11400. * Sets the data value of the editor
  11401. * @param {Mixed} value Any valid value supported by the underlying field
  11402. */
  11403. setValue : function(v){
  11404. this.field.setValue(v);
  11405. },
  11406. /**
  11407. * Gets the data value of the editor
  11408. * @return {Mixed} The data value
  11409. */
  11410. getValue : function(){
  11411. return this.field.getValue();
  11412. },
  11413. beforeDestroy : function(){
  11414. Ext.destroyMembers(this, 'field');
  11415. delete this.parentEl;
  11416. delete this.boundEl;
  11417. }
  11418. });
  11419. Ext.reg('editor', Ext.Editor);
  11420. /**
  11421. * @class Ext.ColorPalette
  11422. * @extends Ext.Component
  11423. * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
  11424. * Here's an example of typical usage:
  11425. * <pre><code>
  11426. var cp = new Ext.ColorPalette({value:'993300'}); // initial selected color
  11427. cp.render('my-div');
  11428. cp.on('select', function(palette, selColor){
  11429. // do something with selColor
  11430. });
  11431. </code></pre>
  11432. * @constructor
  11433. * Create a new ColorPalette
  11434. * @param {Object} config The config object
  11435. * @xtype colorpalette
  11436. */
  11437. Ext.ColorPalette = Ext.extend(Ext.Component, {
  11438. /**
  11439. * @cfg {String} tpl An existing XTemplate instance to be used in place of the default template for rendering the component.
  11440. */
  11441. /**
  11442. * @cfg {String} itemCls
  11443. * The CSS class to apply to the containing element (defaults to 'x-color-palette')
  11444. */
  11445. itemCls : 'x-color-palette',
  11446. /**
  11447. * @cfg {String} value
  11448. * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
  11449. * the hex codes are case-sensitive.
  11450. */
  11451. value : null,
  11452. /**
  11453. * @cfg {String} clickEvent
  11454. * The DOM event that will cause a color to be selected. This can be any valid event name (dblclick, contextmenu).
  11455. * Defaults to <tt>'click'</tt>.
  11456. */
  11457. clickEvent :'click',
  11458. // private
  11459. ctype : 'Ext.ColorPalette',
  11460. /**
  11461. * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the {@link #select} event
  11462. */
  11463. allowReselect : false,
  11464. /**
  11465. * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
  11466. * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
  11467. * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
  11468. * of colors with the width setting until the box is symmetrical.</p>
  11469. * <p>You can override individual colors if needed:</p>
  11470. * <pre><code>
  11471. var cp = new Ext.ColorPalette();
  11472. cp.colors[0] = 'FF0000'; // change the first box to red
  11473. </code></pre>
  11474. Or you can provide a custom array of your own for complete control:
  11475. <pre><code>
  11476. var cp = new Ext.ColorPalette();
  11477. cp.colors = ['000000', '993300', '333300'];
  11478. </code></pre>
  11479. * @type Array
  11480. */
  11481. colors : [
  11482. '000000', '993300', '333300', '003300', '003366', '000080', '333399', '333333',
  11483. '800000', 'FF6600', '808000', '008000', '008080', '0000FF', '666699', '808080',
  11484. 'FF0000', 'FF9900', '99CC00', '339966', '33CCCC', '3366FF', '800080', '969696',
  11485. 'FF00FF', 'FFCC00', 'FFFF00', '00FF00', '00FFFF', '00CCFF', '993366', 'C0C0C0',
  11486. 'FF99CC', 'FFCC99', 'FFFF99', 'CCFFCC', 'CCFFFF', '99CCFF', 'CC99FF', 'FFFFFF'
  11487. ],
  11488. /**
  11489. * @cfg {Function} handler
  11490. * Optional. A function that will handle the select event of this palette.
  11491. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  11492. * <li><code>palette</code> : ColorPalette<div class="sub-desc">The {@link #palette Ext.ColorPalette}.</div></li>
  11493. * <li><code>color</code> : String<div class="sub-desc">The 6-digit color hex code (without the # symbol).</div></li>
  11494. * </ul></div>
  11495. */
  11496. /**
  11497. * @cfg {Object} scope
  11498. * The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>
  11499. * function will be called. Defaults to this ColorPalette instance.
  11500. */
  11501. // private
  11502. initComponent : function(){
  11503. Ext.ColorPalette.superclass.initComponent.call(this);
  11504. this.addEvents(
  11505. /**
  11506. * @event select
  11507. * Fires when a color is selected
  11508. * @param {ColorPalette} this
  11509. * @param {String} color The 6-digit color hex code (without the # symbol)
  11510. */
  11511. 'select'
  11512. );
  11513. if(this.handler){
  11514. this.on('select', this.handler, this.scope, true);
  11515. }
  11516. },
  11517. // private
  11518. onRender : function(container, position){
  11519. this.autoEl = {
  11520. tag: 'div',
  11521. cls: this.itemCls
  11522. };
  11523. Ext.ColorPalette.superclass.onRender.call(this, container, position);
  11524. var t = this.tpl || new Ext.XTemplate(
  11525. '<tpl for="."><a href="#" class="color-{.}" hidefocus="on"><em><span style="background:#{.}" class="x-unselectable" unselectable="on">&#160;</span></em></a></tpl>'
  11526. );
  11527. t.overwrite(this.el, this.colors);
  11528. this.mon(this.el, this.clickEvent, this.handleClick, this, {delegate: 'a'});
  11529. if(this.clickEvent != 'click'){
  11530. this.mon(this.el, 'click', Ext.emptyFn, this, {delegate: 'a', preventDefault: true});
  11531. }
  11532. },
  11533. // private
  11534. afterRender : function(){
  11535. Ext.ColorPalette.superclass.afterRender.call(this);
  11536. if(this.value){
  11537. var s = this.value;
  11538. this.value = null;
  11539. this.select(s, true);
  11540. }
  11541. },
  11542. // private
  11543. handleClick : function(e, t){
  11544. e.preventDefault();
  11545. if(!this.disabled){
  11546. var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
  11547. this.select(c.toUpperCase());
  11548. }
  11549. },
  11550. /**
  11551. * Selects the specified color in the palette (fires the {@link #select} event)
  11552. * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
  11553. * @param {Boolean} suppressEvent (optional) True to stop the select event from firing. Defaults to <tt>false</tt>.
  11554. */
  11555. select : function(color, suppressEvent){
  11556. color = color.replace('#', '');
  11557. if(color != this.value || this.allowReselect){
  11558. var el = this.el;
  11559. if(this.value){
  11560. el.child('a.color-'+this.value).removeClass('x-color-palette-sel');
  11561. }
  11562. el.child('a.color-'+color).addClass('x-color-palette-sel');
  11563. this.value = color;
  11564. if(suppressEvent !== true){
  11565. this.fireEvent('select', this, color);
  11566. }
  11567. }
  11568. }
  11569. /**
  11570. * @cfg {String} autoEl @hide
  11571. */
  11572. });
  11573. Ext.reg('colorpalette', Ext.ColorPalette);/**
  11574. * @class Ext.DatePicker
  11575. * @extends Ext.Component
  11576. * <p>A popup date picker. This class is used by the {@link Ext.form.DateField DateField} class
  11577. * to allow browsing and selection of valid dates.</p>
  11578. * <p>All the string values documented below may be overridden by including an Ext locale file in
  11579. * your page.</p>
  11580. * @constructor
  11581. * Create a new DatePicker
  11582. * @param {Object} config The config object
  11583. * @xtype datepicker
  11584. */
  11585. Ext.DatePicker = Ext.extend(Ext.BoxComponent, {
  11586. /**
  11587. * @cfg {String} todayText
  11588. * The text to display on the button that selects the current date (defaults to <code>'Today'</code>)
  11589. */
  11590. todayText : 'Today',
  11591. /**
  11592. * @cfg {String} okText
  11593. * The text to display on the ok button (defaults to <code>'&#160;OK&#160;'</code> to give the user extra clicking room)
  11594. */
  11595. okText : '&#160;OK&#160;',
  11596. /**
  11597. * @cfg {String} cancelText
  11598. * The text to display on the cancel button (defaults to <code>'Cancel'</code>)
  11599. */
  11600. cancelText : 'Cancel',
  11601. /**
  11602. * @cfg {Function} handler
  11603. * Optional. A function that will handle the select event of this picker.
  11604. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  11605. * <li><code>picker</code> : DatePicker<div class="sub-desc">This DatePicker.</div></li>
  11606. * <li><code>date</code> : Date<div class="sub-desc">The selected date.</div></li>
  11607. * </ul></div>
  11608. */
  11609. /**
  11610. * @cfg {Object} scope
  11611. * The scope (<code><b>this</b></code> reference) in which the <code>{@link #handler}</code>
  11612. * function will be called. Defaults to this DatePicker instance.
  11613. */
  11614. /**
  11615. * @cfg {String} todayTip
  11616. * A string used to format the message for displaying in a tooltip over the button that
  11617. * selects the current date. Defaults to <code>'{0} (Spacebar)'</code> where
  11618. * the <code>{0}</code> token is replaced by today's date.
  11619. */
  11620. todayTip : '{0} (Spacebar)',
  11621. /**
  11622. * @cfg {String} minText
  11623. * The error text to display if the minDate validation fails (defaults to <code>'This date is before the minimum date'</code>)
  11624. */
  11625. minText : 'This date is before the minimum date',
  11626. /**
  11627. * @cfg {String} maxText
  11628. * The error text to display if the maxDate validation fails (defaults to <code>'This date is after the maximum date'</code>)
  11629. */
  11630. maxText : 'This date is after the maximum date',
  11631. /**
  11632. * @cfg {String} format
  11633. * The default date format string which can be overriden for localization support. The format must be
  11634. * valid according to {@link Date#parseDate} (defaults to <code>'m/d/y'</code>).
  11635. */
  11636. format : 'm/d/y',
  11637. /**
  11638. * @cfg {String} disabledDaysText
  11639. * The tooltip to display when the date falls on a disabled day (defaults to <code>'Disabled'</code>)
  11640. */
  11641. disabledDaysText : 'Disabled',
  11642. /**
  11643. * @cfg {String} disabledDatesText
  11644. * The tooltip text to display when the date falls on a disabled date (defaults to <code>'Disabled'</code>)
  11645. */
  11646. disabledDatesText : 'Disabled',
  11647. /**
  11648. * @cfg {Array} monthNames
  11649. * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
  11650. */
  11651. monthNames : Date.monthNames,
  11652. /**
  11653. * @cfg {Array} dayNames
  11654. * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
  11655. */
  11656. dayNames : Date.dayNames,
  11657. /**
  11658. * @cfg {String} nextText
  11659. * The next month navigation button tooltip (defaults to <code>'Next Month (Control+Right)'</code>)
  11660. */
  11661. nextText : 'Next Month (Control+Right)',
  11662. /**
  11663. * @cfg {String} prevText
  11664. * The previous month navigation button tooltip (defaults to <code>'Previous Month (Control+Left)'</code>)
  11665. */
  11666. prevText : 'Previous Month (Control+Left)',
  11667. /**
  11668. * @cfg {String} monthYearText
  11669. * The header month selector tooltip (defaults to <code>'Choose a month (Control+Up/Down to move years)'</code>)
  11670. */
  11671. monthYearText : 'Choose a month (Control+Up/Down to move years)',
  11672. /**
  11673. * @cfg {Number} startDay
  11674. * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
  11675. */
  11676. startDay : 0,
  11677. /**
  11678. * @cfg {Boolean} showToday
  11679. * False to hide the footer area containing the Today button and disable the keyboard handler for spacebar
  11680. * that selects the current date (defaults to <code>true</code>).
  11681. */
  11682. showToday : true,
  11683. /**
  11684. * @cfg {Date} minDate
  11685. * Minimum allowable date (JavaScript date object, defaults to null)
  11686. */
  11687. /**
  11688. * @cfg {Date} maxDate
  11689. * Maximum allowable date (JavaScript date object, defaults to null)
  11690. */
  11691. /**
  11692. * @cfg {Array} disabledDays
  11693. * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
  11694. */
  11695. /**
  11696. * @cfg {RegExp} disabledDatesRE
  11697. * JavaScript regular expression used to disable a pattern of dates (defaults to null). The {@link #disabledDates}
  11698. * config will generate this regex internally, but if you specify disabledDatesRE it will take precedence over the
  11699. * disabledDates value.
  11700. */
  11701. /**
  11702. * @cfg {Array} disabledDates
  11703. * An array of 'dates' to disable, as strings. These strings will be used to build a dynamic regular
  11704. * expression so they are very powerful. Some examples:
  11705. * <ul>
  11706. * <li>['03/08/2003', '09/16/2003'] would disable those exact dates</li>
  11707. * <li>['03/08', '09/16'] would disable those days for every year</li>
  11708. * <li>['^03/08'] would only match the beginning (useful if you are using short years)</li>
  11709. * <li>['03/../2006'] would disable every day in March 2006</li>
  11710. * <li>['^03'] would disable every day in every March</li>
  11711. * </ul>
  11712. * Note that the format of the dates included in the array should exactly match the {@link #format} config.
  11713. * In order to support regular expressions, if you are using a date format that has '.' in it, you will have to
  11714. * escape the dot when restricting dates. For example: ['03\\.08\\.03'].
  11715. */
  11716. // private
  11717. // Set by other components to stop the picker focus being updated when the value changes.
  11718. focusOnSelect: true,
  11719. // default value used to initialise each date in the DatePicker
  11720. // (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
  11721. initHour: 12, // 24-hour format
  11722. // private
  11723. initComponent : function(){
  11724. Ext.DatePicker.superclass.initComponent.call(this);
  11725. this.value = this.value ?
  11726. this.value.clearTime(true) : new Date().clearTime();
  11727. this.addEvents(
  11728. /**
  11729. * @event select
  11730. * Fires when a date is selected
  11731. * @param {DatePicker} this DatePicker
  11732. * @param {Date} date The selected date
  11733. */
  11734. 'select'
  11735. );
  11736. if(this.handler){
  11737. this.on('select', this.handler, this.scope || this);
  11738. }
  11739. this.initDisabledDays();
  11740. },
  11741. // private
  11742. initDisabledDays : function(){
  11743. if(!this.disabledDatesRE && this.disabledDates){
  11744. var dd = this.disabledDates,
  11745. len = dd.length - 1,
  11746. re = '(?:';
  11747. Ext.each(dd, function(d, i){
  11748. re += Ext.isDate(d) ? '^' + Ext.escapeRe(d.dateFormat(this.format)) + '$' : dd[i];
  11749. if(i != len){
  11750. re += '|';
  11751. }
  11752. }, this);
  11753. this.disabledDatesRE = new RegExp(re + ')');
  11754. }
  11755. },
  11756. /**
  11757. * Replaces any existing disabled dates with new values and refreshes the DatePicker.
  11758. * @param {Array/RegExp} disabledDates An array of date strings (see the {@link #disabledDates} config
  11759. * for details on supported values), or a JavaScript regular expression used to disable a pattern of dates.
  11760. */
  11761. setDisabledDates : function(dd){
  11762. if(Ext.isArray(dd)){
  11763. this.disabledDates = dd;
  11764. this.disabledDatesRE = null;
  11765. }else{
  11766. this.disabledDatesRE = dd;
  11767. }
  11768. this.initDisabledDays();
  11769. this.update(this.value, true);
  11770. },
  11771. /**
  11772. * Replaces any existing disabled days (by index, 0-6) with new values and refreshes the DatePicker.
  11773. * @param {Array} disabledDays An array of disabled day indexes. See the {@link #disabledDays} config
  11774. * for details on supported values.
  11775. */
  11776. setDisabledDays : function(dd){
  11777. this.disabledDays = dd;
  11778. this.update(this.value, true);
  11779. },
  11780. /**
  11781. * Replaces any existing {@link #minDate} with the new value and refreshes the DatePicker.
  11782. * @param {Date} value The minimum date that can be selected
  11783. */
  11784. setMinDate : function(dt){
  11785. this.minDate = dt;
  11786. this.update(this.value, true);
  11787. },
  11788. /**
  11789. * Replaces any existing {@link #maxDate} with the new value and refreshes the DatePicker.
  11790. * @param {Date} value The maximum date that can be selected
  11791. */
  11792. setMaxDate : function(dt){
  11793. this.maxDate = dt;
  11794. this.update(this.value, true);
  11795. },
  11796. /**
  11797. * Sets the value of the date field
  11798. * @param {Date} value The date to set
  11799. */
  11800. setValue : function(value){
  11801. this.value = value.clearTime(true);
  11802. this.update(this.value);
  11803. },
  11804. /**
  11805. * Gets the current selected value of the date field
  11806. * @return {Date} The selected date
  11807. */
  11808. getValue : function(){
  11809. return this.value;
  11810. },
  11811. // private
  11812. focus : function(){
  11813. this.update(this.activeDate);
  11814. },
  11815. // private
  11816. onEnable: function(initial){
  11817. Ext.DatePicker.superclass.onEnable.call(this);
  11818. this.doDisabled(false);
  11819. this.update(initial ? this.value : this.activeDate);
  11820. if(Ext.isIE9m){
  11821. this.el.repaint();
  11822. }
  11823. },
  11824. // private
  11825. onDisable : function(){
  11826. Ext.DatePicker.superclass.onDisable.call(this);
  11827. this.doDisabled(true);
  11828. if(Ext.isIE9m && !Ext.isIE8){
  11829. /* Really strange problem in IE6/7, when disabled, have to explicitly
  11830. * repaint each of the nodes to get them to display correctly, simply
  11831. * calling repaint on the main element doesn't appear to be enough.
  11832. */
  11833. Ext.each([].concat(this.textNodes, this.el.query('th span')), function(el){
  11834. Ext.fly(el).repaint();
  11835. });
  11836. }
  11837. },
  11838. // private
  11839. doDisabled : function(disabled){
  11840. this.keyNav.setDisabled(disabled);
  11841. this.prevRepeater.setDisabled(disabled);
  11842. this.nextRepeater.setDisabled(disabled);
  11843. if(this.showToday){
  11844. this.todayKeyListener.setDisabled(disabled);
  11845. this.todayBtn.setDisabled(disabled);
  11846. }
  11847. },
  11848. // private
  11849. onRender : function(container, position){
  11850. var m = [
  11851. '<table cellspacing="0">',
  11852. '<tr><td class="x-date-left"><a href="#" title="', this.prevText ,'">&#160;</a></td><td class="x-date-middle" align="center"></td><td class="x-date-right"><a href="#" title="', this.nextText ,'">&#160;</a></td></tr>',
  11853. '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'],
  11854. dn = this.dayNames,
  11855. i;
  11856. for(i = 0; i < 7; i++){
  11857. var d = this.startDay+i;
  11858. if(d > 6){
  11859. d = d-7;
  11860. }
  11861. m.push('<th><span>', dn[d].substr(0,1), '</span></th>');
  11862. }
  11863. m[m.length] = '</tr></thead><tbody><tr>';
  11864. for(i = 0; i < 42; i++) {
  11865. if(i % 7 === 0 && i !== 0){
  11866. m[m.length] = '</tr><tr>';
  11867. }
  11868. m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
  11869. }
  11870. m.push('</tr></tbody></table></td></tr>',
  11871. this.showToday ? '<tr><td colspan="3" class="x-date-bottom" align="center"></td></tr>' : '',
  11872. '</table><div class="x-date-mp"></div>');
  11873. var el = document.createElement('div');
  11874. el.className = 'x-date-picker';
  11875. el.innerHTML = m.join('');
  11876. container.dom.insertBefore(el, position);
  11877. this.el = Ext.get(el);
  11878. this.eventEl = Ext.get(el.firstChild);
  11879. this.prevRepeater = new Ext.util.ClickRepeater(this.el.child('td.x-date-left a'), {
  11880. handler: this.showPrevMonth,
  11881. scope: this,
  11882. preventDefault:true,
  11883. stopDefault:true
  11884. });
  11885. this.nextRepeater = new Ext.util.ClickRepeater(this.el.child('td.x-date-right a'), {
  11886. handler: this.showNextMonth,
  11887. scope: this,
  11888. preventDefault:true,
  11889. stopDefault:true
  11890. });
  11891. this.monthPicker = this.el.down('div.x-date-mp');
  11892. this.monthPicker.enableDisplayMode('block');
  11893. this.keyNav = new Ext.KeyNav(this.eventEl, {
  11894. 'left' : function(e){
  11895. if(e.ctrlKey){
  11896. this.showPrevMonth();
  11897. }else{
  11898. this.update(this.activeDate.add('d', -1));
  11899. }
  11900. },
  11901. 'right' : function(e){
  11902. if(e.ctrlKey){
  11903. this.showNextMonth();
  11904. }else{
  11905. this.update(this.activeDate.add('d', 1));
  11906. }
  11907. },
  11908. 'up' : function(e){
  11909. if(e.ctrlKey){
  11910. this.showNextYear();
  11911. }else{
  11912. this.update(this.activeDate.add('d', -7));
  11913. }
  11914. },
  11915. 'down' : function(e){
  11916. if(e.ctrlKey){
  11917. this.showPrevYear();
  11918. }else{
  11919. this.update(this.activeDate.add('d', 7));
  11920. }
  11921. },
  11922. 'pageUp' : function(e){
  11923. this.showNextMonth();
  11924. },
  11925. 'pageDown' : function(e){
  11926. this.showPrevMonth();
  11927. },
  11928. 'enter' : function(e){
  11929. e.stopPropagation();
  11930. return true;
  11931. },
  11932. scope : this
  11933. });
  11934. this.el.unselectable();
  11935. this.cells = this.el.select('table.x-date-inner tbody td');
  11936. this.textNodes = this.el.query('table.x-date-inner tbody span');
  11937. this.mbtn = new Ext.Button({
  11938. text: '&#160;',
  11939. tooltip: this.monthYearText,
  11940. renderTo: this.el.child('td.x-date-middle', true)
  11941. });
  11942. this.mbtn.el.child('em').addClass('x-btn-arrow');
  11943. if(this.showToday){
  11944. this.todayKeyListener = this.eventEl.addKeyListener(Ext.EventObject.SPACE, this.selectToday, this);
  11945. var today = (new Date()).dateFormat(this.format);
  11946. this.todayBtn = new Ext.Button({
  11947. renderTo: this.el.child('td.x-date-bottom', true),
  11948. text: String.format(this.todayText, today),
  11949. tooltip: String.format(this.todayTip, today),
  11950. handler: this.selectToday,
  11951. scope: this
  11952. });
  11953. }
  11954. this.mon(this.eventEl, 'mousewheel', this.handleMouseWheel, this);
  11955. this.mon(this.eventEl, 'click', this.handleDateClick, this, {delegate: 'a.x-date-date'});
  11956. this.mon(this.mbtn, 'click', this.showMonthPicker, this);
  11957. this.onEnable(true);
  11958. },
  11959. // private
  11960. createMonthPicker : function(){
  11961. if(!this.monthPicker.dom.firstChild){
  11962. var buf = ['<table border="0" cellspacing="0">'];
  11963. for(var i = 0; i < 6; i++){
  11964. buf.push(
  11965. '<tr><td class="x-date-mp-month"><a href="#">', Date.getShortMonthName(i), '</a></td>',
  11966. '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', Date.getShortMonthName(i + 6), '</a></td>',
  11967. i === 0 ?
  11968. '<td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-prev"></a></td><td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-next"></a></td></tr>' :
  11969. '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
  11970. );
  11971. }
  11972. buf.push(
  11973. '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
  11974. this.okText,
  11975. '</button><button type="button" class="x-date-mp-cancel">',
  11976. this.cancelText,
  11977. '</button></td></tr>',
  11978. '</table>'
  11979. );
  11980. this.monthPicker.update(buf.join(''));
  11981. this.mon(this.monthPicker, 'click', this.onMonthClick, this);
  11982. this.mon(this.monthPicker, 'dblclick', this.onMonthDblClick, this);
  11983. this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
  11984. this.mpYears = this.monthPicker.select('td.x-date-mp-year');
  11985. this.mpMonths.each(function(m, a, i){
  11986. i += 1;
  11987. if((i%2) === 0){
  11988. m.dom.xmonth = 5 + Math.round(i * 0.5);
  11989. }else{
  11990. m.dom.xmonth = Math.round((i-1) * 0.5);
  11991. }
  11992. });
  11993. }
  11994. },
  11995. // private
  11996. showMonthPicker : function(){
  11997. if(!this.disabled){
  11998. this.createMonthPicker();
  11999. var size = this.el.getSize();
  12000. this.monthPicker.setSize(size);
  12001. this.monthPicker.child('table').setSize(size);
  12002. this.mpSelMonth = (this.activeDate || this.value).getMonth();
  12003. this.updateMPMonth(this.mpSelMonth);
  12004. this.mpSelYear = (this.activeDate || this.value).getFullYear();
  12005. this.updateMPYear(this.mpSelYear);
  12006. this.monthPicker.slideIn('t', {duration:0.2});
  12007. }
  12008. },
  12009. // private
  12010. updateMPYear : function(y){
  12011. this.mpyear = y;
  12012. var ys = this.mpYears.elements;
  12013. for(var i = 1; i <= 10; i++){
  12014. var td = ys[i-1], y2;
  12015. if((i%2) === 0){
  12016. y2 = y + Math.round(i * 0.5);
  12017. td.firstChild.innerHTML = y2;
  12018. td.xyear = y2;
  12019. }else{
  12020. y2 = y - (5-Math.round(i * 0.5));
  12021. td.firstChild.innerHTML = y2;
  12022. td.xyear = y2;
  12023. }
  12024. this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
  12025. }
  12026. },
  12027. // private
  12028. updateMPMonth : function(sm){
  12029. this.mpMonths.each(function(m, a, i){
  12030. m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
  12031. });
  12032. },
  12033. // private
  12034. selectMPMonth : function(m){
  12035. },
  12036. // private
  12037. onMonthClick : function(e, t){
  12038. e.stopEvent();
  12039. var el = new Ext.Element(t), pn;
  12040. if(el.is('button.x-date-mp-cancel')){
  12041. this.hideMonthPicker();
  12042. }
  12043. else if(el.is('button.x-date-mp-ok')){
  12044. var d = new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate());
  12045. if(d.getMonth() != this.mpSelMonth){
  12046. // 'fix' the JS rolling date conversion if needed
  12047. d = new Date(this.mpSelYear, this.mpSelMonth, 1).getLastDateOfMonth();
  12048. }
  12049. this.update(d);
  12050. this.hideMonthPicker();
  12051. }
  12052. else if((pn = el.up('td.x-date-mp-month', 2))){
  12053. this.mpMonths.removeClass('x-date-mp-sel');
  12054. pn.addClass('x-date-mp-sel');
  12055. this.mpSelMonth = pn.dom.xmonth;
  12056. }
  12057. else if((pn = el.up('td.x-date-mp-year', 2))){
  12058. this.mpYears.removeClass('x-date-mp-sel');
  12059. pn.addClass('x-date-mp-sel');
  12060. this.mpSelYear = pn.dom.xyear;
  12061. }
  12062. else if(el.is('a.x-date-mp-prev')){
  12063. this.updateMPYear(this.mpyear-10);
  12064. }
  12065. else if(el.is('a.x-date-mp-next')){
  12066. this.updateMPYear(this.mpyear+10);
  12067. }
  12068. },
  12069. // private
  12070. onMonthDblClick : function(e, t){
  12071. e.stopEvent();
  12072. var el = new Ext.Element(t), pn;
  12073. if((pn = el.up('td.x-date-mp-month', 2))){
  12074. this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
  12075. this.hideMonthPicker();
  12076. }
  12077. else if((pn = el.up('td.x-date-mp-year', 2))){
  12078. this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
  12079. this.hideMonthPicker();
  12080. }
  12081. },
  12082. // private
  12083. hideMonthPicker : function(disableAnim){
  12084. if(this.monthPicker){
  12085. if(disableAnim === true){
  12086. this.monthPicker.hide();
  12087. }else{
  12088. this.monthPicker.slideOut('t', {duration:0.2});
  12089. }
  12090. }
  12091. },
  12092. // private
  12093. showPrevMonth : function(e){
  12094. this.update(this.activeDate.add('mo', -1));
  12095. },
  12096. // private
  12097. showNextMonth : function(e){
  12098. this.update(this.activeDate.add('mo', 1));
  12099. },
  12100. // private
  12101. showPrevYear : function(){
  12102. this.update(this.activeDate.add('y', -1));
  12103. },
  12104. // private
  12105. showNextYear : function(){
  12106. this.update(this.activeDate.add('y', 1));
  12107. },
  12108. // private
  12109. handleMouseWheel : function(e){
  12110. e.stopEvent();
  12111. if(!this.disabled){
  12112. var delta = e.getWheelDelta();
  12113. if(delta > 0){
  12114. this.showPrevMonth();
  12115. } else if(delta < 0){
  12116. this.showNextMonth();
  12117. }
  12118. }
  12119. },
  12120. // private
  12121. handleDateClick : function(e, t){
  12122. e.stopEvent();
  12123. if(!this.disabled && t.dateValue && !Ext.fly(t.parentNode).hasClass('x-date-disabled')){
  12124. this.cancelFocus = this.focusOnSelect === false;
  12125. this.setValue(new Date(t.dateValue));
  12126. delete this.cancelFocus;
  12127. this.fireEvent('select', this, this.value);
  12128. }
  12129. },
  12130. // private
  12131. selectToday : function(){
  12132. if(this.todayBtn && !this.todayBtn.disabled){
  12133. this.setValue(new Date().clearTime());
  12134. this.fireEvent('select', this, this.value);
  12135. }
  12136. },
  12137. // private
  12138. update : function(date, forceRefresh){
  12139. if(this.rendered){
  12140. var vd = this.activeDate, vis = this.isVisible();
  12141. this.activeDate = date;
  12142. if(!forceRefresh && vd && this.el){
  12143. var t = date.getTime();
  12144. if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
  12145. this.cells.removeClass('x-date-selected');
  12146. this.cells.each(function(c){
  12147. if(c.dom.firstChild.dateValue == t){
  12148. c.addClass('x-date-selected');
  12149. if(vis && !this.cancelFocus){
  12150. Ext.fly(c.dom.firstChild).focus(50);
  12151. }
  12152. return false;
  12153. }
  12154. }, this);
  12155. return;
  12156. }
  12157. }
  12158. var days = date.getDaysInMonth(),
  12159. firstOfMonth = date.getFirstDateOfMonth(),
  12160. startingPos = firstOfMonth.getDay()-this.startDay;
  12161. if(startingPos < 0){
  12162. startingPos += 7;
  12163. }
  12164. days += startingPos;
  12165. var pm = date.add('mo', -1),
  12166. prevStart = pm.getDaysInMonth()-startingPos,
  12167. cells = this.cells.elements,
  12168. textEls = this.textNodes,
  12169. // convert everything to numbers so it's fast
  12170. d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart, this.initHour)),
  12171. today = new Date().clearTime().getTime(),
  12172. sel = date.clearTime(true).getTime(),
  12173. min = this.minDate ? this.minDate.clearTime(true) : Number.NEGATIVE_INFINITY,
  12174. max = this.maxDate ? this.maxDate.clearTime(true) : Number.POSITIVE_INFINITY,
  12175. ddMatch = this.disabledDatesRE,
  12176. ddText = this.disabledDatesText,
  12177. ddays = this.disabledDays ? this.disabledDays.join('') : false,
  12178. ddaysText = this.disabledDaysText,
  12179. format = this.format;
  12180. if(this.showToday){
  12181. var td = new Date().clearTime(),
  12182. disable = (td < min || td > max ||
  12183. (ddMatch && format && ddMatch.test(td.dateFormat(format))) ||
  12184. (ddays && ddays.indexOf(td.getDay()) != -1));
  12185. if(!this.disabled){
  12186. this.todayBtn.setDisabled(disable);
  12187. this.todayKeyListener[disable ? 'disable' : 'enable']();
  12188. }
  12189. }
  12190. var setCellClass = function(cal, cell){
  12191. cell.title = '';
  12192. var t = d.clearTime(true).getTime();
  12193. cell.firstChild.dateValue = t;
  12194. if(t == today){
  12195. cell.className += ' x-date-today';
  12196. cell.title = cal.todayText;
  12197. }
  12198. if(t == sel){
  12199. cell.className += ' x-date-selected';
  12200. if(vis){
  12201. Ext.fly(cell.firstChild).focus(50);
  12202. }
  12203. }
  12204. // disabling
  12205. if(t < min) {
  12206. cell.className = ' x-date-disabled';
  12207. cell.title = cal.minText;
  12208. return;
  12209. }
  12210. if(t > max) {
  12211. cell.className = ' x-date-disabled';
  12212. cell.title = cal.maxText;
  12213. return;
  12214. }
  12215. if(ddays){
  12216. if(ddays.indexOf(d.getDay()) != -1){
  12217. cell.title = ddaysText;
  12218. cell.className = ' x-date-disabled';
  12219. }
  12220. }
  12221. if(ddMatch && format){
  12222. var fvalue = d.dateFormat(format);
  12223. if(ddMatch.test(fvalue)){
  12224. cell.title = ddText.replace('%0', fvalue);
  12225. cell.className = ' x-date-disabled';
  12226. }
  12227. }
  12228. };
  12229. var i = 0;
  12230. for(; i < startingPos; i++) {
  12231. textEls[i].innerHTML = (++prevStart);
  12232. d.setDate(d.getDate()+1);
  12233. cells[i].className = 'x-date-prevday';
  12234. setCellClass(this, cells[i]);
  12235. }
  12236. for(; i < days; i++){
  12237. var intDay = i - startingPos + 1;
  12238. textEls[i].innerHTML = (intDay);
  12239. d.setDate(d.getDate()+1);
  12240. cells[i].className = 'x-date-active';
  12241. setCellClass(this, cells[i]);
  12242. }
  12243. var extraDays = 0;
  12244. for(; i < 42; i++) {
  12245. textEls[i].innerHTML = (++extraDays);
  12246. d.setDate(d.getDate()+1);
  12247. cells[i].className = 'x-date-nextday';
  12248. setCellClass(this, cells[i]);
  12249. }
  12250. this.mbtn.setText(this.monthNames[date.getMonth()] + ' ' + date.getFullYear());
  12251. if(!this.internalRender){
  12252. var main = this.el.dom.firstChild,
  12253. w = main.offsetWidth;
  12254. this.el.setWidth(w + this.el.getBorderWidth('lr'));
  12255. Ext.fly(main).setWidth(w);
  12256. this.internalRender = true;
  12257. // opera does not respect the auto grow header center column
  12258. // then, after it gets a width opera refuses to recalculate
  12259. // without a second pass
  12260. if(Ext.isOpera && !this.secondPass){
  12261. main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + 'px';
  12262. this.secondPass = true;
  12263. this.update.defer(10, this, [date]);
  12264. }
  12265. }
  12266. }
  12267. },
  12268. // private
  12269. beforeDestroy : function() {
  12270. if(this.rendered){
  12271. Ext.destroy(
  12272. this.keyNav,
  12273. this.monthPicker,
  12274. this.eventEl,
  12275. this.mbtn,
  12276. this.nextRepeater,
  12277. this.prevRepeater,
  12278. this.cells.el,
  12279. this.todayBtn
  12280. );
  12281. delete this.textNodes;
  12282. delete this.cells.elements;
  12283. }
  12284. }
  12285. /**
  12286. * @cfg {String} autoEl @hide
  12287. */
  12288. });
  12289. Ext.reg('datepicker', Ext.DatePicker);
  12290. /**
  12291. * @class Ext.LoadMask
  12292. * A simple utility class for generically masking elements while loading data. If the {@link #store}
  12293. * config option is specified, the masking will be automatically synchronized with the store's loading
  12294. * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
  12295. * element's Updater load indicator and will be destroyed after the initial load.
  12296. * <p>Example usage:</p>
  12297. *<pre><code>
  12298. // Basic mask:
  12299. var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Please wait..."});
  12300. myMask.show();
  12301. </code></pre>
  12302. * @constructor
  12303. * Create a new LoadMask
  12304. * @param {Mixed} el The element or DOM node, or its id
  12305. * @param {Object} config The config object
  12306. */
  12307. Ext.LoadMask = function(el, config){
  12308. this.el = Ext.get(el);
  12309. Ext.apply(this, config);
  12310. if(this.store){
  12311. this.store.on({
  12312. scope: this,
  12313. beforeload: this.onBeforeLoad,
  12314. load: this.onLoad,
  12315. exception: this.onLoad
  12316. });
  12317. this.removeMask = Ext.value(this.removeMask, false);
  12318. }else{
  12319. var um = this.el.getUpdater();
  12320. um.showLoadIndicator = false; // disable the default indicator
  12321. um.on({
  12322. scope: this,
  12323. beforeupdate: this.onBeforeLoad,
  12324. update: this.onLoad,
  12325. failure: this.onLoad
  12326. });
  12327. this.removeMask = Ext.value(this.removeMask, true);
  12328. }
  12329. };
  12330. Ext.LoadMask.prototype = {
  12331. /**
  12332. * @cfg {Ext.data.Store} store
  12333. * Optional Store to which the mask is bound. The mask is displayed when a load request is issued, and
  12334. * hidden on either load sucess, or load fail.
  12335. */
  12336. /**
  12337. * @cfg {Boolean} removeMask
  12338. * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
  12339. * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
  12340. */
  12341. /**
  12342. * @cfg {String} msg
  12343. * The text to display in a centered loading message box (defaults to 'Loading...')
  12344. */
  12345. msg : 'Loading...',
  12346. /**
  12347. * @cfg {String} msgCls
  12348. * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
  12349. */
  12350. msgCls : 'x-mask-loading',
  12351. /**
  12352. * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
  12353. * @type Boolean
  12354. */
  12355. disabled: false,
  12356. /**
  12357. * Disables the mask to prevent it from being displayed
  12358. */
  12359. disable : function(){
  12360. this.disabled = true;
  12361. },
  12362. /**
  12363. * Enables the mask so that it can be displayed
  12364. */
  12365. enable : function(){
  12366. this.disabled = false;
  12367. },
  12368. // private
  12369. onLoad : function(){
  12370. this.el.unmask(this.removeMask);
  12371. },
  12372. // private
  12373. onBeforeLoad : function(){
  12374. if(!this.disabled){
  12375. this.el.mask(this.msg, this.msgCls);
  12376. }
  12377. },
  12378. /**
  12379. * Show this LoadMask over the configured Element.
  12380. */
  12381. show: function(){
  12382. this.onBeforeLoad();
  12383. },
  12384. /**
  12385. * Hide this LoadMask.
  12386. */
  12387. hide: function(){
  12388. this.onLoad();
  12389. },
  12390. // private
  12391. destroy : function(){
  12392. if(this.store){
  12393. this.store.un('beforeload', this.onBeforeLoad, this);
  12394. this.store.un('load', this.onLoad, this);
  12395. this.store.un('exception', this.onLoad, this);
  12396. }else{
  12397. var um = this.el.getUpdater();
  12398. um.un('beforeupdate', this.onBeforeLoad, this);
  12399. um.un('update', this.onLoad, this);
  12400. um.un('failure', this.onLoad, this);
  12401. }
  12402. }
  12403. };/**
  12404. * @class Ext.slider.Thumb
  12405. * @extends Object
  12406. * Represents a single thumb element on a Slider. This would not usually be created manually and would instead
  12407. * be created internally by an {@link Ext.slider.MultiSlider Ext.Slider}.
  12408. */
  12409. Ext.slider.Thumb = Ext.extend(Object, {
  12410. /**
  12411. * True while the thumb is in a drag operation
  12412. * @type Boolean
  12413. */
  12414. dragging: false,
  12415. /**
  12416. * @constructor
  12417. * @cfg {Ext.slider.MultiSlider} slider The Slider to render to (required)
  12418. */
  12419. constructor: function(config) {
  12420. /**
  12421. * @property slider
  12422. * @type Ext.slider.MultiSlider
  12423. * The slider this thumb is contained within
  12424. */
  12425. Ext.apply(this, config || {}, {
  12426. cls: 'x-slider-thumb',
  12427. /**
  12428. * @cfg {Boolean} constrain True to constrain the thumb so that it cannot overlap its siblings
  12429. */
  12430. constrain: false
  12431. });
  12432. Ext.slider.Thumb.superclass.constructor.call(this, config);
  12433. if (this.slider.vertical) {
  12434. Ext.apply(this, Ext.slider.Thumb.Vertical);
  12435. }
  12436. },
  12437. /**
  12438. * Renders the thumb into a slider
  12439. */
  12440. render: function() {
  12441. this.el = this.slider.innerEl.insertFirst({cls: this.cls});
  12442. this.initEvents();
  12443. },
  12444. /**
  12445. * Enables the thumb if it is currently disabled
  12446. */
  12447. enable: function() {
  12448. this.disabled = false;
  12449. this.el.removeClass(this.slider.disabledClass);
  12450. },
  12451. /**
  12452. * Disables the thumb if it is currently enabled
  12453. */
  12454. disable: function() {
  12455. this.disabled = true;
  12456. this.el.addClass(this.slider.disabledClass);
  12457. },
  12458. /**
  12459. * Sets up an Ext.dd.DragTracker for this thumb
  12460. */
  12461. initEvents: function() {
  12462. var el = this.el;
  12463. el.addClassOnOver('x-slider-thumb-over');
  12464. this.tracker = new Ext.dd.DragTracker({
  12465. onBeforeStart: this.onBeforeDragStart.createDelegate(this),
  12466. onStart : this.onDragStart.createDelegate(this),
  12467. onDrag : this.onDrag.createDelegate(this),
  12468. onEnd : this.onDragEnd.createDelegate(this),
  12469. tolerance : 3,
  12470. autoStart : 300
  12471. });
  12472. this.tracker.initEl(el);
  12473. },
  12474. /**
  12475. * @private
  12476. * This is tied into the internal Ext.dd.DragTracker. If the slider is currently disabled,
  12477. * this returns false to disable the DragTracker too.
  12478. * @return {Boolean} False if the slider is currently disabled
  12479. */
  12480. onBeforeDragStart : function(e) {
  12481. if (this.disabled) {
  12482. return false;
  12483. } else {
  12484. this.slider.promoteThumb(this);
  12485. return true;
  12486. }
  12487. },
  12488. /**
  12489. * @private
  12490. * This is tied into the internal Ext.dd.DragTracker's onStart template method. Adds the drag CSS class
  12491. * to the thumb and fires the 'dragstart' event
  12492. */
  12493. onDragStart: function(e){
  12494. this.el.addClass('x-slider-thumb-drag');
  12495. this.dragging = true;
  12496. this.dragStartValue = this.value;
  12497. this.slider.fireEvent('dragstart', this.slider, e, this);
  12498. },
  12499. /**
  12500. * @private
  12501. * This is tied into the internal Ext.dd.DragTracker's onDrag template method. This is called every time
  12502. * the DragTracker detects a drag movement. It updates the Slider's value using the position of the drag
  12503. */
  12504. onDrag: function(e) {
  12505. var slider = this.slider,
  12506. index = this.index,
  12507. newValue = this.getNewValue();
  12508. if (this.constrain) {
  12509. var above = slider.thumbs[index + 1],
  12510. below = slider.thumbs[index - 1];
  12511. if (below != undefined && newValue <= below.value) newValue = below.value;
  12512. if (above != undefined && newValue >= above.value) newValue = above.value;
  12513. }
  12514. slider.setValue(index, newValue, false);
  12515. slider.fireEvent('drag', slider, e, this);
  12516. },
  12517. getNewValue: function() {
  12518. var slider = this.slider,
  12519. pos = slider.innerEl.translatePoints(this.tracker.getXY());
  12520. return Ext.util.Format.round(slider.reverseValue(pos.left), slider.decimalPrecision);
  12521. },
  12522. /**
  12523. * @private
  12524. * This is tied to the internal Ext.dd.DragTracker's onEnd template method. Removes the drag CSS class and
  12525. * fires the 'changecomplete' event with the new value
  12526. */
  12527. onDragEnd: function(e) {
  12528. var slider = this.slider,
  12529. value = this.value;
  12530. this.el.removeClass('x-slider-thumb-drag');
  12531. this.dragging = false;
  12532. slider.fireEvent('dragend', slider, e);
  12533. if (this.dragStartValue != value) {
  12534. slider.fireEvent('changecomplete', slider, value, this);
  12535. }
  12536. },
  12537. /**
  12538. * @private
  12539. * Destroys the thumb
  12540. */
  12541. destroy: function(){
  12542. Ext.destroyMembers(this, 'tracker', 'el');
  12543. }
  12544. });
  12545. /**
  12546. * @class Ext.slider.MultiSlider
  12547. * @extends Ext.BoxComponent
  12548. * Slider which supports vertical or horizontal orientation, keyboard adjustments, configurable snapping, axis clicking and animation. Can be added as an item to any container. Example usage:
  12549. <pre>
  12550. new Ext.Slider({
  12551. renderTo: Ext.getBody(),
  12552. width: 200,
  12553. value: 50,
  12554. increment: 10,
  12555. minValue: 0,
  12556. maxValue: 100
  12557. });
  12558. </pre>
  12559. * Sliders can be created with more than one thumb handle by passing an array of values instead of a single one:
  12560. <pre>
  12561. new Ext.Slider({
  12562. renderTo: Ext.getBody(),
  12563. width: 200,
  12564. values: [25, 50, 75],
  12565. minValue: 0,
  12566. maxValue: 100,
  12567. //this defaults to true, setting to false allows the thumbs to pass each other
  12568. {@link #constrainThumbs}: false
  12569. });
  12570. </pre>
  12571. */
  12572. Ext.slider.MultiSlider = Ext.extend(Ext.BoxComponent, {
  12573. /**
  12574. * @cfg {Number} value The value to initialize the slider with. Defaults to minValue.
  12575. */
  12576. /**
  12577. * @cfg {Boolean} vertical Orient the Slider vertically rather than horizontally, defaults to false.
  12578. */
  12579. vertical: false,
  12580. /**
  12581. * @cfg {Number} minValue The minimum value for the Slider. Defaults to 0.
  12582. */
  12583. minValue: 0,
  12584. /**
  12585. * @cfg {Number} maxValue The maximum value for the Slider. Defaults to 100.
  12586. */
  12587. maxValue: 100,
  12588. /**
  12589. * @cfg {Number/Boolean} decimalPrecision.
  12590. * <p>The number of decimal places to which to round the Slider's value. Defaults to 0.</p>
  12591. * <p>To disable rounding, configure as <tt><b>false</b></tt>.</p>
  12592. */
  12593. decimalPrecision: 0,
  12594. /**
  12595. * @cfg {Number} keyIncrement How many units to change the Slider when adjusting with keyboard navigation. Defaults to 1. If the increment config is larger, it will be used instead.
  12596. */
  12597. keyIncrement: 1,
  12598. /**
  12599. * @cfg {Number} increment How many units to change the slider when adjusting by drag and drop. Use this option to enable 'snapping'.
  12600. */
  12601. increment: 0,
  12602. /**
  12603. * @private
  12604. * @property clickRange
  12605. * @type Array
  12606. * Determines whether or not a click to the slider component is considered to be a user request to change the value. Specified as an array of [top, bottom],
  12607. * the click event's 'top' property is compared to these numbers and the click only considered a change request if it falls within them. e.g. if the 'top'
  12608. * value of the click event is 4 or 16, the click is not considered a change request as it falls outside of the [5, 15] range
  12609. */
  12610. clickRange: [5,15],
  12611. /**
  12612. * @cfg {Boolean} clickToChange Determines whether or not clicking on the Slider axis will change the slider. Defaults to true
  12613. */
  12614. clickToChange : true,
  12615. /**
  12616. * @cfg {Boolean} animate Turn on or off animation. Defaults to true
  12617. */
  12618. animate: true,
  12619. /**
  12620. * @cfg {Boolean} constrainThumbs True to disallow thumbs from overlapping one another. Defaults to true
  12621. */
  12622. constrainThumbs: true,
  12623. /**
  12624. * @private
  12625. * @property topThumbZIndex
  12626. * @type Number
  12627. * The number used internally to set the z index of the top thumb (see promoteThumb for details)
  12628. */
  12629. topThumbZIndex: 10000,
  12630. // private override
  12631. initComponent : function(){
  12632. if(!Ext.isDefined(this.value)){
  12633. this.value = this.minValue;
  12634. }
  12635. /**
  12636. * @property thumbs
  12637. * @type Array
  12638. * Array containing references to each thumb
  12639. */
  12640. this.thumbs = [];
  12641. Ext.slider.MultiSlider.superclass.initComponent.call(this);
  12642. this.keyIncrement = Math.max(this.increment, this.keyIncrement);
  12643. this.addEvents(
  12644. /**
  12645. * @event beforechange
  12646. * Fires before the slider value is changed. By returning false from an event handler,
  12647. * you can cancel the event and prevent the slider from changing.
  12648. * @param {Ext.slider.MultiSlider} slider The slider
  12649. * @param {Number} newValue The new value which the slider is being changed to.
  12650. * @param {Number} oldValue The old value which the slider was previously.
  12651. */
  12652. 'beforechange',
  12653. /**
  12654. * @event change
  12655. * Fires when the slider value is changed.
  12656. * @param {Ext.slider.MultiSlider} slider The slider
  12657. * @param {Number} newValue The new value which the slider has been changed to.
  12658. * @param {Ext.slider.Thumb} thumb The thumb that was changed
  12659. */
  12660. 'change',
  12661. /**
  12662. * @event changecomplete
  12663. * Fires when the slider value is changed by the user and any drag operations have completed.
  12664. * @param {Ext.slider.MultiSlider} slider The slider
  12665. * @param {Number} newValue The new value which the slider has been changed to.
  12666. * @param {Ext.slider.Thumb} thumb The thumb that was changed
  12667. */
  12668. 'changecomplete',
  12669. /**
  12670. * @event dragstart
  12671. * Fires after a drag operation has started.
  12672. * @param {Ext.slider.MultiSlider} slider The slider
  12673. * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker
  12674. */
  12675. 'dragstart',
  12676. /**
  12677. * @event drag
  12678. * Fires continuously during the drag operation while the mouse is moving.
  12679. * @param {Ext.slider.MultiSlider} slider The slider
  12680. * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker
  12681. */
  12682. 'drag',
  12683. /**
  12684. * @event dragend
  12685. * Fires after the drag operation has completed.
  12686. * @param {Ext.slider.MultiSlider} slider The slider
  12687. * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker
  12688. */
  12689. 'dragend'
  12690. );
  12691. /**
  12692. * @property values
  12693. * @type Array
  12694. * Array of values to initalize the thumbs with
  12695. */
  12696. if (this.values == undefined || Ext.isEmpty(this.values)) this.values = [0];
  12697. var values = this.values;
  12698. for (var i=0; i < values.length; i++) {
  12699. this.addThumb(values[i]);
  12700. }
  12701. if(this.vertical){
  12702. Ext.apply(this, Ext.slider.Vertical);
  12703. }
  12704. },
  12705. /**
  12706. * Creates a new thumb and adds it to the slider
  12707. * @param {Number} value The initial value to set on the thumb. Defaults to 0
  12708. */
  12709. addThumb: function(value) {
  12710. var thumb = new Ext.slider.Thumb({
  12711. value : value,
  12712. slider : this,
  12713. index : this.thumbs.length,
  12714. constrain: this.constrainThumbs
  12715. });
  12716. this.thumbs.push(thumb);
  12717. //render the thumb now if needed
  12718. if (this.rendered) thumb.render();
  12719. },
  12720. /**
  12721. * @private
  12722. * Moves the given thumb above all other by increasing its z-index. This is called when as drag
  12723. * any thumb, so that the thumb that was just dragged is always at the highest z-index. This is
  12724. * required when the thumbs are stacked on top of each other at one of the ends of the slider's
  12725. * range, which can result in the user not being able to move any of them.
  12726. * @param {Ext.slider.Thumb} topThumb The thumb to move to the top
  12727. */
  12728. promoteThumb: function(topThumb) {
  12729. var thumbs = this.thumbs,
  12730. zIndex, thumb;
  12731. for (var i = 0, j = thumbs.length; i < j; i++) {
  12732. thumb = thumbs[i];
  12733. if (thumb == topThumb) {
  12734. zIndex = this.topThumbZIndex;
  12735. } else {
  12736. zIndex = '';
  12737. }
  12738. thumb.el.setStyle('zIndex', zIndex);
  12739. }
  12740. },
  12741. // private override
  12742. onRender : function() {
  12743. this.autoEl = {
  12744. cls: 'x-slider ' + (this.vertical ? 'x-slider-vert' : 'x-slider-horz'),
  12745. cn : {
  12746. cls: 'x-slider-end',
  12747. cn : {
  12748. cls:'x-slider-inner',
  12749. cn : [{tag:'a', cls:'x-slider-focus', href:"#", tabIndex: '-1', hidefocus:'on'}]
  12750. }
  12751. }
  12752. };
  12753. Ext.slider.MultiSlider.superclass.onRender.apply(this, arguments);
  12754. this.endEl = this.el.first();
  12755. this.innerEl = this.endEl.first();
  12756. this.focusEl = this.innerEl.child('.x-slider-focus');
  12757. //render each thumb
  12758. for (var i=0; i < this.thumbs.length; i++) {
  12759. this.thumbs[i].render();
  12760. }
  12761. //calculate the size of half a thumb
  12762. var thumb = this.innerEl.child('.x-slider-thumb');
  12763. this.halfThumb = (this.vertical ? thumb.getHeight() : thumb.getWidth()) / 2;
  12764. this.initEvents();
  12765. },
  12766. /**
  12767. * @private
  12768. * Adds keyboard and mouse listeners on this.el. Ignores click events on the internal focus element.
  12769. * Creates a new DragTracker which is used to control what happens when the user drags the thumb around.
  12770. */
  12771. initEvents : function(){
  12772. this.mon(this.el, {
  12773. scope : this,
  12774. mousedown: this.onMouseDown,
  12775. keydown : this.onKeyDown
  12776. });
  12777. this.focusEl.swallowEvent("click", true);
  12778. },
  12779. /**
  12780. * @private
  12781. * Mousedown handler for the slider. If the clickToChange is enabled and the click was not on the draggable 'thumb',
  12782. * this calculates the new value of the slider and tells the implementation (Horizontal or Vertical) to move the thumb
  12783. * @param {Ext.EventObject} e The click event
  12784. */
  12785. onMouseDown : function(e){
  12786. if(this.disabled){
  12787. return;
  12788. }
  12789. //see if the click was on any of the thumbs
  12790. var thumbClicked = false;
  12791. for (var i=0; i < this.thumbs.length; i++) {
  12792. thumbClicked = thumbClicked || e.target == this.thumbs[i].el.dom;
  12793. }
  12794. if (this.clickToChange && !thumbClicked) {
  12795. var local = this.innerEl.translatePoints(e.getXY());
  12796. this.onClickChange(local);
  12797. }
  12798. this.focus();
  12799. },
  12800. /**
  12801. * @private
  12802. * Moves the thumb to the indicated position. Note that a Vertical implementation is provided in Ext.slider.Vertical.
  12803. * Only changes the value if the click was within this.clickRange.
  12804. * @param {Object} local Object containing top and left values for the click event.
  12805. */
  12806. onClickChange : function(local) {
  12807. if (local.top > this.clickRange[0] && local.top < this.clickRange[1]) {
  12808. //find the nearest thumb to the click event
  12809. var thumb = this.getNearest(local, 'left'),
  12810. index = thumb.index;
  12811. this.setValue(index, Ext.util.Format.round(this.reverseValue(local.left), this.decimalPrecision), undefined, true);
  12812. }
  12813. },
  12814. /**
  12815. * @private
  12816. * Returns the nearest thumb to a click event, along with its distance
  12817. * @param {Object} local Object containing top and left values from a click event
  12818. * @param {String} prop The property of local to compare on. Use 'left' for horizontal sliders, 'top' for vertical ones
  12819. * @return {Object} The closest thumb object and its distance from the click event
  12820. */
  12821. getNearest: function(local, prop) {
  12822. var localValue = prop == 'top' ? this.innerEl.getHeight() - local[prop] : local[prop],
  12823. clickValue = this.reverseValue(localValue),
  12824. nearestDistance = (this.maxValue - this.minValue) + 5, //add a small fudge for the end of the slider
  12825. index = 0,
  12826. nearest = null;
  12827. for (var i=0; i < this.thumbs.length; i++) {
  12828. var thumb = this.thumbs[i],
  12829. value = thumb.value,
  12830. dist = Math.abs(value - clickValue);
  12831. if (Math.abs(dist <= nearestDistance)) {
  12832. nearest = thumb;
  12833. index = i;
  12834. nearestDistance = dist;
  12835. }
  12836. }
  12837. return nearest;
  12838. },
  12839. /**
  12840. * @private
  12841. * Handler for any keypresses captured by the slider. If the key is UP or RIGHT, the thumb is moved along to the right
  12842. * by this.keyIncrement. If DOWN or LEFT it is moved left. Pressing CTRL moves the slider to the end in either direction
  12843. * @param {Ext.EventObject} e The Event object
  12844. */
  12845. onKeyDown : function(e){
  12846. /*
  12847. * The behaviour for keyboard handling with multiple thumbs is currently undefined.
  12848. * There's no real sane default for it, so leave it like this until we come up
  12849. * with a better way of doing it.
  12850. */
  12851. if(this.disabled || this.thumbs.length !== 1){
  12852. e.preventDefault();
  12853. return;
  12854. }
  12855. var k = e.getKey(),
  12856. val;
  12857. switch(k){
  12858. case e.UP:
  12859. case e.RIGHT:
  12860. e.stopEvent();
  12861. val = e.ctrlKey ? this.maxValue : this.getValue(0) + this.keyIncrement;
  12862. this.setValue(0, val, undefined, true);
  12863. break;
  12864. case e.DOWN:
  12865. case e.LEFT:
  12866. e.stopEvent();
  12867. val = e.ctrlKey ? this.minValue : this.getValue(0) - this.keyIncrement;
  12868. this.setValue(0, val, undefined, true);
  12869. break;
  12870. default:
  12871. e.preventDefault();
  12872. }
  12873. },
  12874. /**
  12875. * @private
  12876. * If using snapping, this takes a desired new value and returns the closest snapped
  12877. * value to it
  12878. * @param {Number} value The unsnapped value
  12879. * @return {Number} The value of the nearest snap target
  12880. */
  12881. doSnap : function(value){
  12882. if (!(this.increment && value)) {
  12883. return value;
  12884. }
  12885. var newValue = value,
  12886. inc = this.increment,
  12887. m = value % inc;
  12888. if (m != 0) {
  12889. newValue -= m;
  12890. if (m * 2 >= inc) {
  12891. newValue += inc;
  12892. } else if (m * 2 < -inc) {
  12893. newValue -= inc;
  12894. }
  12895. }
  12896. return newValue.constrain(this.minValue, this.maxValue);
  12897. },
  12898. // private
  12899. afterRender : function(){
  12900. Ext.slider.MultiSlider.superclass.afterRender.apply(this, arguments);
  12901. for (var i=0; i < this.thumbs.length; i++) {
  12902. var thumb = this.thumbs[i];
  12903. if (thumb.value !== undefined) {
  12904. var v = this.normalizeValue(thumb.value);
  12905. if (v !== thumb.value) {
  12906. // delete this.value;
  12907. this.setValue(i, v, false);
  12908. } else {
  12909. this.moveThumb(i, this.translateValue(v), false);
  12910. }
  12911. }
  12912. };
  12913. },
  12914. /**
  12915. * @private
  12916. * Returns the ratio of pixels to mapped values. e.g. if the slider is 200px wide and maxValue - minValue is 100,
  12917. * the ratio is 2
  12918. * @return {Number} The ratio of pixels to mapped values
  12919. */
  12920. getRatio : function(){
  12921. var w = this.innerEl.getWidth(),
  12922. v = this.maxValue - this.minValue;
  12923. return v == 0 ? w : (w/v);
  12924. },
  12925. /**
  12926. * @private
  12927. * Returns a snapped, constrained value when given a desired value
  12928. * @param {Number} value Raw number value
  12929. * @return {Number} The raw value rounded to the correct d.p. and constrained within the set max and min values
  12930. */
  12931. normalizeValue : function(v){
  12932. v = this.doSnap(v);
  12933. v = Ext.util.Format.round(v, this.decimalPrecision);
  12934. v = v.constrain(this.minValue, this.maxValue);
  12935. return v;
  12936. },
  12937. /**
  12938. * Sets the minimum value for the slider instance. If the current value is less than the
  12939. * minimum value, the current value will be changed.
  12940. * @param {Number} val The new minimum value
  12941. */
  12942. setMinValue : function(val){
  12943. this.minValue = val;
  12944. var i = 0,
  12945. thumbs = this.thumbs,
  12946. len = thumbs.length,
  12947. t;
  12948. for(; i < len; ++i){
  12949. t = thumbs[i];
  12950. t.value = t.value < val ? val : t.value;
  12951. }
  12952. this.syncThumb();
  12953. },
  12954. /**
  12955. * Sets the maximum value for the slider instance. If the current value is more than the
  12956. * maximum value, the current value will be changed.
  12957. * @param {Number} val The new maximum value
  12958. */
  12959. setMaxValue : function(val){
  12960. this.maxValue = val;
  12961. var i = 0,
  12962. thumbs = this.thumbs,
  12963. len = thumbs.length,
  12964. t;
  12965. for(; i < len; ++i){
  12966. t = thumbs[i];
  12967. t.value = t.value > val ? val : t.value;
  12968. }
  12969. this.syncThumb();
  12970. },
  12971. /**
  12972. * Programmatically sets the value of the Slider. Ensures that the value is constrained within
  12973. * the minValue and maxValue.
  12974. * @param {Number} index Index of the thumb to move
  12975. * @param {Number} value The value to set the slider to. (This will be constrained within minValue and maxValue)
  12976. * @param {Boolean} animate Turn on or off animation, defaults to true
  12977. */
  12978. setValue : function(index, v, animate, changeComplete) {
  12979. var thumb = this.thumbs[index],
  12980. el = thumb.el;
  12981. v = this.normalizeValue(v);
  12982. if (v !== thumb.value && this.fireEvent('beforechange', this, v, thumb.value, thumb) !== false) {
  12983. thumb.value = v;
  12984. if(this.rendered){
  12985. this.moveThumb(index, this.translateValue(v), animate !== false);
  12986. this.fireEvent('change', this, v, thumb);
  12987. if(changeComplete){
  12988. this.fireEvent('changecomplete', this, v, thumb);
  12989. }
  12990. }
  12991. }
  12992. },
  12993. /**
  12994. * @private
  12995. */
  12996. translateValue : function(v) {
  12997. var ratio = this.getRatio();
  12998. return (v * ratio) - (this.minValue * ratio) - this.halfThumb;
  12999. },
  13000. /**
  13001. * @private
  13002. * Given a pixel location along the slider, returns the mapped slider value for that pixel.
  13003. * E.g. if we have a slider 200px wide with minValue = 100 and maxValue = 500, reverseValue(50)
  13004. * returns 200
  13005. * @param {Number} pos The position along the slider to return a mapped value for
  13006. * @return {Number} The mapped value for the given position
  13007. */
  13008. reverseValue : function(pos){
  13009. var ratio = this.getRatio();
  13010. return (pos + (this.minValue * ratio)) / ratio;
  13011. },
  13012. /**
  13013. * @private
  13014. * @param {Number} index Index of the thumb to move
  13015. */
  13016. moveThumb: function(index, v, animate){
  13017. var thumb = this.thumbs[index].el;
  13018. if(!animate || this.animate === false){
  13019. thumb.setLeft(v);
  13020. }else{
  13021. thumb.shift({left: v, stopFx: true, duration:.35});
  13022. }
  13023. },
  13024. // private
  13025. focus : function(){
  13026. this.focusEl.focus(10);
  13027. },
  13028. // private
  13029. onResize : function(w, h){
  13030. var thumbs = this.thumbs,
  13031. len = thumbs.length,
  13032. i = 0;
  13033. /*
  13034. * If we happen to be animating during a resize, the position of the thumb will likely be off
  13035. * when the animation stops. As such, just stop any animations before syncing the thumbs.
  13036. */
  13037. for(; i < len; ++i){
  13038. thumbs[i].el.stopFx();
  13039. }
  13040. // check to see if we're using an auto width
  13041. if(Ext.isNumber(w)){
  13042. this.innerEl.setWidth(w - (this.el.getPadding('l') + this.endEl.getPadding('r')));
  13043. }
  13044. this.syncThumb();
  13045. Ext.slider.MultiSlider.superclass.onResize.apply(this, arguments);
  13046. },
  13047. //private
  13048. onDisable: function(){
  13049. Ext.slider.MultiSlider.superclass.onDisable.call(this);
  13050. for (var i=0; i < this.thumbs.length; i++) {
  13051. var thumb = this.thumbs[i],
  13052. el = thumb.el;
  13053. thumb.disable();
  13054. if(Ext.isIE){
  13055. //IE breaks when using overflow visible and opacity other than 1.
  13056. //Create a place holder for the thumb and display it.
  13057. var xy = el.getXY();
  13058. el.hide();
  13059. this.innerEl.addClass(this.disabledClass).dom.disabled = true;
  13060. if (!this.thumbHolder) {
  13061. this.thumbHolder = this.endEl.createChild({cls: 'x-slider-thumb ' + this.disabledClass});
  13062. }
  13063. this.thumbHolder.show().setXY(xy);
  13064. }
  13065. }
  13066. },
  13067. //private
  13068. onEnable: function(){
  13069. Ext.slider.MultiSlider.superclass.onEnable.call(this);
  13070. for (var i=0; i < this.thumbs.length; i++) {
  13071. var thumb = this.thumbs[i],
  13072. el = thumb.el;
  13073. thumb.enable();
  13074. if (Ext.isIE) {
  13075. this.innerEl.removeClass(this.disabledClass).dom.disabled = false;
  13076. if (this.thumbHolder) this.thumbHolder.hide();
  13077. el.show();
  13078. this.syncThumb();
  13079. }
  13080. }
  13081. },
  13082. /**
  13083. * Synchronizes the thumb position to the proper proportion of the total component width based
  13084. * on the current slider {@link #value}. This will be called automatically when the Slider
  13085. * is resized by a layout, but if it is rendered auto width, this method can be called from
  13086. * another resize handler to sync the Slider if necessary.
  13087. */
  13088. syncThumb : function() {
  13089. if (this.rendered) {
  13090. for (var i=0; i < this.thumbs.length; i++) {
  13091. this.moveThumb(i, this.translateValue(this.thumbs[i].value));
  13092. }
  13093. }
  13094. },
  13095. /**
  13096. * Returns the current value of the slider
  13097. * @param {Number} index The index of the thumb to return a value for
  13098. * @return {Number} The current value of the slider
  13099. */
  13100. getValue : function(index) {
  13101. return this.thumbs[index].value;
  13102. },
  13103. /**
  13104. * Returns an array of values - one for the location of each thumb
  13105. * @return {Array} The set of thumb values
  13106. */
  13107. getValues: function() {
  13108. var values = [];
  13109. for (var i=0; i < this.thumbs.length; i++) {
  13110. values.push(this.thumbs[i].value);
  13111. }
  13112. return values;
  13113. },
  13114. // private
  13115. beforeDestroy : function(){
  13116. var thumbs = this.thumbs;
  13117. for(var i = 0, len = thumbs.length; i < len; ++i){
  13118. thumbs[i].destroy();
  13119. thumbs[i] = null;
  13120. }
  13121. Ext.destroyMembers(this, 'endEl', 'innerEl', 'focusEl', 'thumbHolder');
  13122. Ext.slider.MultiSlider.superclass.beforeDestroy.call(this);
  13123. }
  13124. });
  13125. Ext.reg('multislider', Ext.slider.MultiSlider);
  13126. /**
  13127. * @class Ext.slider.SingleSlider
  13128. * @extends Ext.slider.MultiSlider
  13129. * Slider which supports vertical or horizontal orientation, keyboard adjustments,
  13130. * configurable snapping, axis clicking and animation. Can be added as an item to
  13131. * any container. Example usage:
  13132. <pre><code>
  13133. new Ext.slider.SingleSlider({
  13134. renderTo: Ext.getBody(),
  13135. width: 200,
  13136. value: 50,
  13137. increment: 10,
  13138. minValue: 0,
  13139. maxValue: 100
  13140. });
  13141. </code></pre>
  13142. * The class Ext.slider.SingleSlider is aliased to Ext.Slider for backwards compatibility.
  13143. */
  13144. Ext.slider.SingleSlider = Ext.extend(Ext.slider.MultiSlider, {
  13145. constructor: function(config) {
  13146. config = config || {};
  13147. Ext.applyIf(config, {
  13148. values: [config.value || 0]
  13149. });
  13150. Ext.slider.SingleSlider.superclass.constructor.call(this, config);
  13151. },
  13152. /**
  13153. * Returns the current value of the slider
  13154. * @return {Number} The current value of the slider
  13155. */
  13156. getValue: function() {
  13157. //just returns the value of the first thumb, which should be the only one in a single slider
  13158. return Ext.slider.SingleSlider.superclass.getValue.call(this, 0);
  13159. },
  13160. /**
  13161. * Programmatically sets the value of the Slider. Ensures that the value is constrained within
  13162. * the minValue and maxValue.
  13163. * @param {Number} value The value to set the slider to. (This will be constrained within minValue and maxValue)
  13164. * @param {Boolean} animate Turn on or off animation, defaults to true
  13165. */
  13166. setValue: function(value, animate) {
  13167. var args = Ext.toArray(arguments),
  13168. len = args.length;
  13169. //this is to maintain backwards compatiblity for sliders with only one thunb. Usually you must pass the thumb
  13170. //index to setValue, but if we only have one thumb we inject the index here first if given the multi-slider
  13171. //signature without the required index. The index will always be 0 for a single slider
  13172. if (len == 1 || (len <= 3 && typeof arguments[1] != 'number')) {
  13173. args.unshift(0);
  13174. }
  13175. return Ext.slider.SingleSlider.superclass.setValue.apply(this, args);
  13176. },
  13177. /**
  13178. * Synchronizes the thumb position to the proper proportion of the total component width based
  13179. * on the current slider {@link #value}. This will be called automatically when the Slider
  13180. * is resized by a layout, but if it is rendered auto width, this method can be called from
  13181. * another resize handler to sync the Slider if necessary.
  13182. */
  13183. syncThumb : function() {
  13184. return Ext.slider.SingleSlider.superclass.syncThumb.apply(this, [0].concat(arguments));
  13185. },
  13186. // private
  13187. getNearest : function(){
  13188. // Since there's only 1 thumb, it's always the nearest
  13189. return this.thumbs[0];
  13190. }
  13191. });
  13192. //backwards compatibility
  13193. Ext.Slider = Ext.slider.SingleSlider;
  13194. Ext.reg('slider', Ext.slider.SingleSlider);
  13195. // private class to support vertical sliders
  13196. Ext.slider.Vertical = {
  13197. onResize : function(w, h){
  13198. this.innerEl.setHeight(h - (this.el.getPadding('t') + this.endEl.getPadding('b')));
  13199. this.syncThumb();
  13200. },
  13201. getRatio : function(){
  13202. var h = this.innerEl.getHeight(),
  13203. v = this.maxValue - this.minValue;
  13204. return h/v;
  13205. },
  13206. moveThumb: function(index, v, animate) {
  13207. var thumb = this.thumbs[index],
  13208. el = thumb.el;
  13209. if (!animate || this.animate === false) {
  13210. el.setBottom(v);
  13211. } else {
  13212. el.shift({bottom: v, stopFx: true, duration:.35});
  13213. }
  13214. },
  13215. onClickChange : function(local) {
  13216. if (local.left > this.clickRange[0] && local.left < this.clickRange[1]) {
  13217. var thumb = this.getNearest(local, 'top'),
  13218. index = thumb.index,
  13219. value = this.minValue + this.reverseValue(this.innerEl.getHeight() - local.top);
  13220. this.setValue(index, Ext.util.Format.round(value, this.decimalPrecision), undefined, true);
  13221. }
  13222. }
  13223. };
  13224. //private class to support vertical dragging of thumbs within a slider
  13225. Ext.slider.Thumb.Vertical = {
  13226. getNewValue: function() {
  13227. var slider = this.slider,
  13228. innerEl = slider.innerEl,
  13229. pos = innerEl.translatePoints(this.tracker.getXY()),
  13230. bottom = innerEl.getHeight() - pos.top;
  13231. return slider.minValue + Ext.util.Format.round(bottom / slider.getRatio(), slider.decimalPrecision);
  13232. }
  13233. };
  13234. /**
  13235. * @class Ext.ProgressBar
  13236. * @extends Ext.BoxComponent
  13237. * <p>An updateable progress bar component. The progress bar supports two different modes: manual and automatic.</p>
  13238. * <p>In manual mode, you are responsible for showing, updating (via {@link #updateProgress}) and clearing the
  13239. * progress bar as needed from your own code. This method is most appropriate when you want to show progress
  13240. * throughout an operation that has predictable points of interest at which you can update the control.</p>
  13241. * <p>In automatic mode, you simply call {@link #wait} and let the progress bar run indefinitely, only clearing it
  13242. * once the operation is complete. You can optionally have the progress bar wait for a specific amount of time
  13243. * and then clear itself. Automatic mode is most appropriate for timed operations or asynchronous operations in
  13244. * which you have no need for indicating intermediate progress.</p>
  13245. * @cfg {Float} value A floating point value between 0 and 1 (e.g., .5, defaults to 0)
  13246. * @cfg {String} text The progress bar text (defaults to '')
  13247. * @cfg {Mixed} textEl The element to render the progress text to (defaults to the progress
  13248. * bar's internal text element)
  13249. * @cfg {String} id The progress bar element's id (defaults to an auto-generated id)
  13250. * @xtype progress
  13251. */
  13252. Ext.ProgressBar = Ext.extend(Ext.BoxComponent, {
  13253. /**
  13254. * @cfg {String} baseCls
  13255. * The base CSS class to apply to the progress bar's wrapper element (defaults to 'x-progress')
  13256. */
  13257. baseCls : 'x-progress',
  13258. /**
  13259. * @cfg {Boolean} animate
  13260. * True to animate the progress bar during transitions (defaults to false)
  13261. */
  13262. animate : false,
  13263. // private
  13264. waitTimer : null,
  13265. // private
  13266. initComponent : function(){
  13267. Ext.ProgressBar.superclass.initComponent.call(this);
  13268. this.addEvents(
  13269. /**
  13270. * @event update
  13271. * Fires after each update interval
  13272. * @param {Ext.ProgressBar} this
  13273. * @param {Number} value The current progress value
  13274. * @param {String} text The current progress text
  13275. */
  13276. "update"
  13277. );
  13278. },
  13279. // private
  13280. onRender : function(ct, position){
  13281. var tpl = new Ext.Template(
  13282. '<div class="{cls}-wrap">',
  13283. '<div class="{cls}-inner">',
  13284. '<div class="{cls}-bar">',
  13285. '<div class="{cls}-text">',
  13286. '<div>&#160;</div>',
  13287. '</div>',
  13288. '</div>',
  13289. '<div class="{cls}-text {cls}-text-back">',
  13290. '<div>&#160;</div>',
  13291. '</div>',
  13292. '</div>',
  13293. '</div>'
  13294. );
  13295. this.el = position ? tpl.insertBefore(position, {cls: this.baseCls}, true)
  13296. : tpl.append(ct, {cls: this.baseCls}, true);
  13297. if(this.id){
  13298. this.el.dom.id = this.id;
  13299. }
  13300. var inner = this.el.dom.firstChild;
  13301. this.progressBar = Ext.get(inner.firstChild);
  13302. if(this.textEl){
  13303. //use an external text el
  13304. this.textEl = Ext.get(this.textEl);
  13305. delete this.textTopEl;
  13306. }else{
  13307. //setup our internal layered text els
  13308. this.textTopEl = Ext.get(this.progressBar.dom.firstChild);
  13309. var textBackEl = Ext.get(inner.childNodes[1]);
  13310. this.textTopEl.setStyle("z-index", 99).addClass('x-hidden');
  13311. this.textEl = new Ext.CompositeElement([this.textTopEl.dom.firstChild, textBackEl.dom.firstChild]);
  13312. this.textEl.setWidth(inner.offsetWidth);
  13313. }
  13314. this.progressBar.setHeight(inner.offsetHeight);
  13315. },
  13316. // private
  13317. afterRender : function(){
  13318. Ext.ProgressBar.superclass.afterRender.call(this);
  13319. if(this.value){
  13320. this.updateProgress(this.value, this.text);
  13321. }else{
  13322. this.updateText(this.text);
  13323. }
  13324. },
  13325. /**
  13326. * Updates the progress bar value, and optionally its text. If the text argument is not specified,
  13327. * any existing text value will be unchanged. To blank out existing text, pass ''. Note that even
  13328. * if the progress bar value exceeds 1, it will never automatically reset -- you are responsible for
  13329. * determining when the progress is complete and calling {@link #reset} to clear and/or hide the control.
  13330. * @param {Float} value (optional) A floating point value between 0 and 1 (e.g., .5, defaults to 0)
  13331. * @param {String} text (optional) The string to display in the progress text element (defaults to '')
  13332. * @param {Boolean} animate (optional) Whether to animate the transition of the progress bar. If this value is
  13333. * not specified, the default for the class is used (default to false)
  13334. * @return {Ext.ProgressBar} this
  13335. */
  13336. updateProgress : function(value, text, animate){
  13337. this.value = value || 0;
  13338. if(text){
  13339. this.updateText(text);
  13340. }
  13341. if(this.rendered && !this.isDestroyed){
  13342. var w = Math.floor(value*this.el.dom.firstChild.offsetWidth);
  13343. this.progressBar.setWidth(w, animate === true || (animate !== false && this.animate));
  13344. if(this.textTopEl){
  13345. //textTopEl should be the same width as the bar so overflow will clip as the bar moves
  13346. this.textTopEl.removeClass('x-hidden').setWidth(w);
  13347. }
  13348. }
  13349. this.fireEvent('update', this, value, text);
  13350. return this;
  13351. },
  13352. /**
  13353. * Initiates an auto-updating progress bar. A duration can be specified, in which case the progress
  13354. * bar will automatically reset after a fixed amount of time and optionally call a callback function
  13355. * if specified. If no duration is passed in, then the progress bar will run indefinitely and must
  13356. * be manually cleared by calling {@link #reset}. The wait method accepts a config object with
  13357. * the following properties:
  13358. * <pre>
  13359. Property Type Description
  13360. ---------- ------------ ----------------------------------------------------------------------
  13361. duration Number The length of time in milliseconds that the progress bar should
  13362. run before resetting itself (defaults to undefined, in which case it
  13363. will run indefinitely until reset is called)
  13364. interval Number The length of time in milliseconds between each progress update
  13365. (defaults to 1000 ms)
  13366. animate Boolean Whether to animate the transition of the progress bar. If this value is
  13367. not specified, the default for the class is used.
  13368. increment Number The number of progress update segments to display within the progress
  13369. bar (defaults to 10). If the bar reaches the end and is still
  13370. updating, it will automatically wrap back to the beginning.
  13371. text String Optional text to display in the progress bar element (defaults to '').
  13372. fn Function A callback function to execute after the progress bar finishes auto-
  13373. updating. The function will be called with no arguments. This function
  13374. will be ignored if duration is not specified since in that case the
  13375. progress bar can only be stopped programmatically, so any required function
  13376. should be called by the same code after it resets the progress bar.
  13377. scope Object The scope that is passed to the callback function (only applies when
  13378. duration and fn are both passed).
  13379. </pre>
  13380. *
  13381. * Example usage:
  13382. * <pre><code>
  13383. var p = new Ext.ProgressBar({
  13384. renderTo: 'my-el'
  13385. });
  13386. //Wait for 5 seconds, then update the status el (progress bar will auto-reset)
  13387. p.wait({
  13388. interval: 100, //bar will move fast!
  13389. duration: 5000,
  13390. increment: 15,
  13391. text: 'Updating...',
  13392. scope: this,
  13393. fn: function(){
  13394. Ext.fly('status').update('Done!');
  13395. }
  13396. });
  13397. //Or update indefinitely until some async action completes, then reset manually
  13398. p.wait();
  13399. myAction.on('complete', function(){
  13400. p.reset();
  13401. Ext.fly('status').update('Done!');
  13402. });
  13403. </code></pre>
  13404. * @param {Object} config (optional) Configuration options
  13405. * @return {Ext.ProgressBar} this
  13406. */
  13407. wait : function(o){
  13408. if(!this.waitTimer){
  13409. var scope = this;
  13410. o = o || {};
  13411. this.updateText(o.text);
  13412. this.waitTimer = Ext.TaskMgr.start({
  13413. run: function(i){
  13414. var inc = o.increment || 10;
  13415. i -= 1;
  13416. this.updateProgress(((((i+inc)%inc)+1)*(100/inc))*0.01, null, o.animate);
  13417. },
  13418. interval: o.interval || 1000,
  13419. duration: o.duration,
  13420. onStop: function(){
  13421. if(o.fn){
  13422. o.fn.apply(o.scope || this);
  13423. }
  13424. this.reset();
  13425. },
  13426. scope: scope
  13427. });
  13428. }
  13429. return this;
  13430. },
  13431. /**
  13432. * Returns true if the progress bar is currently in a {@link #wait} operation
  13433. * @return {Boolean} True if waiting, else false
  13434. */
  13435. isWaiting : function(){
  13436. return this.waitTimer !== null;
  13437. },
  13438. /**
  13439. * Updates the progress bar text. If specified, textEl will be updated, otherwise the progress
  13440. * bar itself will display the updated text.
  13441. * @param {String} text (optional) The string to display in the progress text element (defaults to '')
  13442. * @return {Ext.ProgressBar} this
  13443. */
  13444. updateText : function(text){
  13445. this.text = text || '&#160;';
  13446. if(this.rendered){
  13447. this.textEl.update(this.text);
  13448. }
  13449. return this;
  13450. },
  13451. /**
  13452. * Synchronizes the inner bar width to the proper proportion of the total componet width based
  13453. * on the current progress {@link #value}. This will be called automatically when the ProgressBar
  13454. * is resized by a layout, but if it is rendered auto width, this method can be called from
  13455. * another resize handler to sync the ProgressBar if necessary.
  13456. */
  13457. syncProgressBar : function(){
  13458. if(this.value){
  13459. this.updateProgress(this.value, this.text);
  13460. }
  13461. return this;
  13462. },
  13463. /**
  13464. * Sets the size of the progress bar.
  13465. * @param {Number} width The new width in pixels
  13466. * @param {Number} height The new height in pixels
  13467. * @return {Ext.ProgressBar} this
  13468. */
  13469. setSize : function(w, h){
  13470. Ext.ProgressBar.superclass.setSize.call(this, w, h);
  13471. if(this.textTopEl){
  13472. var inner = this.el.dom.firstChild;
  13473. this.textEl.setSize(inner.offsetWidth, inner.offsetHeight);
  13474. }
  13475. this.syncProgressBar();
  13476. return this;
  13477. },
  13478. /**
  13479. * Resets the progress bar value to 0 and text to empty string. If hide = true, the progress
  13480. * bar will also be hidden (using the {@link #hideMode} property internally).
  13481. * @param {Boolean} hide (optional) True to hide the progress bar (defaults to false)
  13482. * @return {Ext.ProgressBar} this
  13483. */
  13484. reset : function(hide){
  13485. this.updateProgress(0);
  13486. if(this.textTopEl){
  13487. this.textTopEl.addClass('x-hidden');
  13488. }
  13489. this.clearTimer();
  13490. if(hide === true){
  13491. this.hide();
  13492. }
  13493. return this;
  13494. },
  13495. // private
  13496. clearTimer : function(){
  13497. if(this.waitTimer){
  13498. this.waitTimer.onStop = null; //prevent recursion
  13499. Ext.TaskMgr.stop(this.waitTimer);
  13500. this.waitTimer = null;
  13501. }
  13502. },
  13503. onDestroy: function(){
  13504. this.clearTimer();
  13505. if(this.rendered){
  13506. if(this.textEl.isComposite){
  13507. this.textEl.clear();
  13508. }
  13509. Ext.destroyMembers(this, 'textEl', 'progressBar', 'textTopEl');
  13510. }
  13511. Ext.ProgressBar.superclass.onDestroy.call(this);
  13512. }
  13513. });
  13514. Ext.reg('progress', Ext.ProgressBar);