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.

14753 lines
541 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext.ComponentMgr
  9. * <p>Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
  10. * thereof) on a page so that they can be easily accessed by {@link Ext.Component component}
  11. * {@link Ext.Component#id id} (see {@link #get}, or the convenience method {@link Ext#getCmp Ext.getCmp}).</p>
  12. * <p>This object also provides a registry of available Component <i>classes</i>
  13. * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
  14. * The <code>{@link Ext.Component#xtype xtype}</code> provides a way to avoid instantiating child Components
  15. * when creating a full, nested config object for a complete Ext page.</p>
  16. * <p>A child Component may be specified simply as a <i>config object</i>
  17. * as long as the correct <code>{@link Ext.Component#xtype xtype}</code> is specified so that if and when the Component
  18. * needs rendering, the correct type can be looked up for lazy instantiation.</p>
  19. * <p>For a list of all available <code>{@link Ext.Component#xtype xtypes}</code>, see {@link Ext.Component}.</p>
  20. * @singleton
  21. */
  22. Ext.ComponentMgr = function(){
  23. var all = new Ext.util.MixedCollection();
  24. var types = {};
  25. var ptypes = {};
  26. return {
  27. /**
  28. * Registers a component.
  29. * @param {Ext.Component} c The component
  30. */
  31. register : function(c){
  32. all.add(c);
  33. },
  34. /**
  35. * Unregisters a component.
  36. * @param {Ext.Component} c The component
  37. */
  38. unregister : function(c){
  39. all.remove(c);
  40. },
  41. /**
  42. * Returns a component by {@link Ext.Component#id id}.
  43. * For additional details see {@link Ext.util.MixedCollection#get}.
  44. * @param {String} id The component {@link Ext.Component#id id}
  45. * @return Ext.Component The Component, <code>undefined</code> if not found, or <code>null</code> if a
  46. * Class was found.
  47. */
  48. get : function(id){
  49. return all.get(id);
  50. },
  51. /**
  52. * Registers a function that will be called when a Component with the specified id is added to ComponentMgr. This will happen on instantiation.
  53. * @param {String} id The component {@link Ext.Component#id id}
  54. * @param {Function} fn The callback function
  55. * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the Component.
  56. */
  57. onAvailable : function(id, fn, scope){
  58. all.on("add", function(index, o){
  59. if(o.id == id){
  60. fn.call(scope || o, o);
  61. all.un("add", fn, scope);
  62. }
  63. });
  64. },
  65. /**
  66. * The MixedCollection used internally for the component cache. An example usage may be subscribing to
  67. * events on the MixedCollection to monitor addition or removal. Read-only.
  68. * @type {MixedCollection}
  69. */
  70. all : all,
  71. /**
  72. * The xtypes that have been registered with the component manager.
  73. * @type {Object}
  74. */
  75. types : types,
  76. /**
  77. * The ptypes that have been registered with the component manager.
  78. * @type {Object}
  79. */
  80. ptypes: ptypes,
  81. /**
  82. * Checks if a Component type is registered.
  83. * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
  84. * @return {Boolean} Whether the type is registered.
  85. */
  86. isRegistered : function(xtype){
  87. return types[xtype] !== undefined;
  88. },
  89. /**
  90. * Checks if a Plugin type is registered.
  91. * @param {Ext.Component} ptype The mnemonic string by which the Plugin class may be looked up
  92. * @return {Boolean} Whether the type is registered.
  93. */
  94. isPluginRegistered : function(ptype){
  95. return ptypes[ptype] !== undefined;
  96. },
  97. /**
  98. * <p>Registers a new Component constructor, keyed by a new
  99. * {@link Ext.Component#xtype}.</p>
  100. * <p>Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
  101. * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
  102. * child Components.
  103. * see {@link Ext.Container#items}</p>
  104. * @param {String} xtype The mnemonic string by which the Component class may be looked up.
  105. * @param {Constructor} cls The new Component class.
  106. */
  107. registerType : function(xtype, cls){
  108. types[xtype] = cls;
  109. cls.xtype = xtype;
  110. },
  111. /**
  112. * Creates a new Component from the specified config object using the
  113. * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
  114. * @param {Object} config A configuration object for the Component you wish to create.
  115. * @param {Constructor} defaultType The constructor to provide the default Component type if
  116. * the config object does not contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
  117. * @return {Ext.Component} The newly instantiated Component.
  118. */
  119. create : function(config, defaultType){
  120. return config.render ? config : new types[config.xtype || defaultType](config);
  121. },
  122. /**
  123. * <p>Registers a new Plugin constructor, keyed by a new
  124. * {@link Ext.Component#ptype}.</p>
  125. * <p>Use this method (or its alias {@link Ext#preg Ext.preg}) to register new
  126. * plugins for {@link Ext.Component}s so that lazy instantiation may be used when specifying
  127. * Plugins.</p>
  128. * @param {String} ptype The mnemonic string by which the Plugin class may be looked up.
  129. * @param {Constructor} cls The new Plugin class.
  130. */
  131. registerPlugin : function(ptype, cls){
  132. ptypes[ptype] = cls;
  133. cls.ptype = ptype;
  134. },
  135. /**
  136. * Creates a new Plugin from the specified config object using the
  137. * config object's {@link Ext.component#ptype ptype} to determine the class to instantiate.
  138. * @param {Object} config A configuration object for the Plugin you wish to create.
  139. * @param {Constructor} defaultType The constructor to provide the default Plugin type if
  140. * the config object does not contain a <code>ptype</code>. (Optional if the config contains a <code>ptype</code>).
  141. * @return {Ext.Component} The newly instantiated Plugin.
  142. */
  143. createPlugin : function(config, defaultType){
  144. var PluginCls = ptypes[config.ptype || defaultType];
  145. if (PluginCls.init) {
  146. return PluginCls;
  147. } else {
  148. return new PluginCls(config);
  149. }
  150. }
  151. };
  152. }();
  153. /**
  154. * Shorthand for {@link Ext.ComponentMgr#registerType}
  155. * @param {String} xtype The {@link Ext.component#xtype mnemonic string} by which the Component class
  156. * may be looked up.
  157. * @param {Constructor} cls The new Component class.
  158. * @member Ext
  159. * @method reg
  160. */
  161. Ext.reg = Ext.ComponentMgr.registerType; // this will be called a lot internally, shorthand to keep the bytes down
  162. /**
  163. * Shorthand for {@link Ext.ComponentMgr#registerPlugin}
  164. * @param {String} ptype The {@link Ext.component#ptype mnemonic string} by which the Plugin class
  165. * may be looked up.
  166. * @param {Constructor} cls The new Plugin class.
  167. * @member Ext
  168. * @method preg
  169. */
  170. Ext.preg = Ext.ComponentMgr.registerPlugin;
  171. /**
  172. * Shorthand for {@link Ext.ComponentMgr#create}
  173. * Creates a new Component from the specified config object using the
  174. * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
  175. * @param {Object} config A configuration object for the Component you wish to create.
  176. * @param {Constructor} defaultType The constructor to provide the default Component type if
  177. * the config object does not contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
  178. * @return {Ext.Component} The newly instantiated Component.
  179. * @member Ext
  180. * @method create
  181. */
  182. Ext.create = Ext.ComponentMgr.create;/**
  183. * @class Ext.Component
  184. * @extends Ext.util.Observable
  185. * <p>Base class for all Ext components. All subclasses of Component may participate in the automated
  186. * Ext component lifecycle of creation, rendering and destruction which is provided by the {@link Ext.Container Container} class.
  187. * Components may be added to a Container through the {@link Ext.Container#items items} config option at the time the Container is created,
  188. * or they may be added dynamically via the {@link Ext.Container#add add} method.</p>
  189. * <p>The Component base class has built-in support for basic hide/show and enable/disable behavior.</p>
  190. * <p>All Components are registered with the {@link Ext.ComponentMgr} on construction so that they can be referenced at any time via
  191. * {@link Ext#getCmp}, passing the {@link #id}.</p>
  192. * <p>All user-developed visual widgets that are required to participate in automated lifecycle and size management should subclass Component (or
  193. * {@link Ext.BoxComponent} if managed box model handling is required, ie height and width management).</p>
  194. * <p>See the <a href="http://extjs.com/learn/Tutorial:Creating_new_UI_controls">Creating new UI controls</a> tutorial for details on how
  195. * and to either extend or augment ExtJs base classes to create custom Components.</p>
  196. * <p>Every component has a specific xtype, which is its Ext-specific type name, along with methods for checking the
  197. * xtype like {@link #getXType} and {@link #isXType}. This is the list of all valid xtypes:</p>
  198. * <pre>
  199. xtype Class
  200. ------------- ------------------
  201. box {@link Ext.BoxComponent}
  202. button {@link Ext.Button}
  203. buttongroup {@link Ext.ButtonGroup}
  204. colorpalette {@link Ext.ColorPalette}
  205. component {@link Ext.Component}
  206. container {@link Ext.Container}
  207. cycle {@link Ext.CycleButton}
  208. dataview {@link Ext.DataView}
  209. datepicker {@link Ext.DatePicker}
  210. editor {@link Ext.Editor}
  211. editorgrid {@link Ext.grid.EditorGridPanel}
  212. flash {@link Ext.FlashComponent}
  213. grid {@link Ext.grid.GridPanel}
  214. listview {@link Ext.ListView}
  215. multislider {@link Ext.slider.MultiSlider}
  216. panel {@link Ext.Panel}
  217. progress {@link Ext.ProgressBar}
  218. propertygrid {@link Ext.grid.PropertyGrid}
  219. slider {@link Ext.slider.SingleSlider}
  220. spacer {@link Ext.Spacer}
  221. splitbutton {@link Ext.SplitButton}
  222. tabpanel {@link Ext.TabPanel}
  223. treepanel {@link Ext.tree.TreePanel}
  224. viewport {@link Ext.ViewPort}
  225. window {@link Ext.Window}
  226. Toolbar components
  227. ---------------------------------------
  228. paging {@link Ext.PagingToolbar}
  229. toolbar {@link Ext.Toolbar}
  230. tbbutton {@link Ext.Toolbar.Button} (deprecated; use button)
  231. tbfill {@link Ext.Toolbar.Fill}
  232. tbitem {@link Ext.Toolbar.Item}
  233. tbseparator {@link Ext.Toolbar.Separator}
  234. tbspacer {@link Ext.Toolbar.Spacer}
  235. tbsplit {@link Ext.Toolbar.SplitButton} (deprecated; use splitbutton)
  236. tbtext {@link Ext.Toolbar.TextItem}
  237. Menu components
  238. ---------------------------------------
  239. menu {@link Ext.menu.Menu}
  240. colormenu {@link Ext.menu.ColorMenu}
  241. datemenu {@link Ext.menu.DateMenu}
  242. menubaseitem {@link Ext.menu.BaseItem}
  243. menucheckitem {@link Ext.menu.CheckItem}
  244. menuitem {@link Ext.menu.Item}
  245. menuseparator {@link Ext.menu.Separator}
  246. menutextitem {@link Ext.menu.TextItem}
  247. Form components
  248. ---------------------------------------
  249. form {@link Ext.form.FormPanel}
  250. checkbox {@link Ext.form.Checkbox}
  251. checkboxgroup {@link Ext.form.CheckboxGroup}
  252. combo {@link Ext.form.ComboBox}
  253. compositefield {@link Ext.form.CompositeField}
  254. datefield {@link Ext.form.DateField}
  255. displayfield {@link Ext.form.DisplayField}
  256. field {@link Ext.form.Field}
  257. fieldset {@link Ext.form.FieldSet}
  258. hidden {@link Ext.form.Hidden}
  259. htmleditor {@link Ext.form.HtmlEditor}
  260. label {@link Ext.form.Label}
  261. numberfield {@link Ext.form.NumberField}
  262. radio {@link Ext.form.Radio}
  263. radiogroup {@link Ext.form.RadioGroup}
  264. textarea {@link Ext.form.TextArea}
  265. textfield {@link Ext.form.TextField}
  266. timefield {@link Ext.form.TimeField}
  267. trigger {@link Ext.form.TriggerField}
  268. Chart components
  269. ---------------------------------------
  270. chart {@link Ext.chart.Chart}
  271. barchart {@link Ext.chart.BarChart}
  272. cartesianchart {@link Ext.chart.CartesianChart}
  273. columnchart {@link Ext.chart.ColumnChart}
  274. linechart {@link Ext.chart.LineChart}
  275. piechart {@link Ext.chart.PieChart}
  276. Store xtypes
  277. ---------------------------------------
  278. arraystore {@link Ext.data.ArrayStore}
  279. directstore {@link Ext.data.DirectStore}
  280. groupingstore {@link Ext.data.GroupingStore}
  281. jsonstore {@link Ext.data.JsonStore}
  282. simplestore {@link Ext.data.SimpleStore} (deprecated; use arraystore)
  283. store {@link Ext.data.Store}
  284. xmlstore {@link Ext.data.XmlStore}
  285. </pre>
  286. * @constructor
  287. * @param {Ext.Element/String/Object} config The configuration options may be specified as either:
  288. * <div class="mdetail-params"><ul>
  289. * <li><b>an element</b> :
  290. * <p class="sub-desc">it is set as the internal element and its id used as the component id</p></li>
  291. * <li><b>a string</b> :
  292. * <p class="sub-desc">it is assumed to be the id of an existing element and is used as the component id</p></li>
  293. * <li><b>anything else</b> :
  294. * <p class="sub-desc">it is assumed to be a standard config object and is applied to the component</p></li>
  295. * </ul></div>
  296. */
  297. Ext.Component = function(config){
  298. config = config || {};
  299. if(config.initialConfig){
  300. if(config.isAction){ // actions
  301. this.baseAction = config;
  302. }
  303. config = config.initialConfig; // component cloning / action set up
  304. }else if(config.tagName || config.dom || Ext.isString(config)){ // element object
  305. config = {applyTo: config, id: config.id || config};
  306. }
  307. /**
  308. * This Component's initial configuration specification. Read-only.
  309. * @type Object
  310. * @property initialConfig
  311. */
  312. this.initialConfig = config;
  313. Ext.apply(this, config);
  314. this.addEvents(
  315. /**
  316. * @event added
  317. * Fires when a component is added to an Ext.Container
  318. * @param {Ext.Component} this
  319. * @param {Ext.Container} ownerCt Container which holds the component
  320. * @param {number} index Position at which the component was added
  321. */
  322. 'added',
  323. /**
  324. * @event disable
  325. * Fires after the component is disabled.
  326. * @param {Ext.Component} this
  327. */
  328. 'disable',
  329. /**
  330. * @event enable
  331. * Fires after the component is enabled.
  332. * @param {Ext.Component} this
  333. */
  334. 'enable',
  335. /**
  336. * @event beforeshow
  337. * Fires before the component is shown by calling the {@link #show} method.
  338. * Return false from an event handler to stop the show.
  339. * @param {Ext.Component} this
  340. */
  341. 'beforeshow',
  342. /**
  343. * @event show
  344. * Fires after the component is shown when calling the {@link #show} method.
  345. * @param {Ext.Component} this
  346. */
  347. 'show',
  348. /**
  349. * @event beforehide
  350. * Fires before the component is hidden by calling the {@link #hide} method.
  351. * Return false from an event handler to stop the hide.
  352. * @param {Ext.Component} this
  353. */
  354. 'beforehide',
  355. /**
  356. * @event hide
  357. * Fires after the component is hidden.
  358. * Fires after the component is hidden when calling the {@link #hide} method.
  359. * @param {Ext.Component} this
  360. */
  361. 'hide',
  362. /**
  363. * @event removed
  364. * Fires when a component is removed from an Ext.Container
  365. * @param {Ext.Component} this
  366. * @param {Ext.Container} ownerCt Container which holds the component
  367. */
  368. 'removed',
  369. /**
  370. * @event beforerender
  371. * Fires before the component is {@link #rendered}. Return false from an
  372. * event handler to stop the {@link #render}.
  373. * @param {Ext.Component} this
  374. */
  375. 'beforerender',
  376. /**
  377. * @event render
  378. * Fires after the component markup is {@link #rendered}.
  379. * @param {Ext.Component} this
  380. */
  381. 'render',
  382. /**
  383. * @event afterrender
  384. * <p>Fires after the component rendering is finished.</p>
  385. * <p>The afterrender event is fired after this Component has been {@link #rendered}, been postprocesed
  386. * by any afterRender method defined for the Component, and, if {@link #stateful}, after state
  387. * has been restored.</p>
  388. * @param {Ext.Component} this
  389. */
  390. 'afterrender',
  391. /**
  392. * @event beforedestroy
  393. * Fires before the component is {@link #destroy}ed. Return false from an event handler to stop the {@link #destroy}.
  394. * @param {Ext.Component} this
  395. */
  396. 'beforedestroy',
  397. /**
  398. * @event destroy
  399. * Fires after the component is {@link #destroy}ed.
  400. * @param {Ext.Component} this
  401. */
  402. 'destroy',
  403. /**
  404. * @event beforestaterestore
  405. * Fires before the state of the component is restored. Return false from an event handler to stop the restore.
  406. * @param {Ext.Component} this
  407. * @param {Object} state The hash of state values returned from the StateProvider. If this
  408. * event is not vetoed, then the state object is passed to <b><tt>applyState</tt></b>. By default,
  409. * that simply copies property values into this Component. The method maybe overriden to
  410. * provide custom state restoration.
  411. */
  412. 'beforestaterestore',
  413. /**
  414. * @event staterestore
  415. * Fires after the state of the component is restored.
  416. * @param {Ext.Component} this
  417. * @param {Object} state The hash of state values returned from the StateProvider. This is passed
  418. * to <b><tt>applyState</tt></b>. By default, that simply copies property values into this
  419. * Component. The method maybe overriden to provide custom state restoration.
  420. */
  421. 'staterestore',
  422. /**
  423. * @event beforestatesave
  424. * Fires before the state of the component is saved to the configured state provider. Return false to stop the save.
  425. * @param {Ext.Component} this
  426. * @param {Object} state The hash of state values. This is determined by calling
  427. * <b><tt>getState()</tt></b> on the Component. This method must be provided by the
  428. * developer to return whetever representation of state is required, by default, Ext.Component
  429. * has a null implementation.
  430. */
  431. 'beforestatesave',
  432. /**
  433. * @event statesave
  434. * Fires after the state of the component is saved to the configured state provider.
  435. * @param {Ext.Component} this
  436. * @param {Object} state The hash of state values. This is determined by calling
  437. * <b><tt>getState()</tt></b> on the Component. This method must be provided by the
  438. * developer to return whetever representation of state is required, by default, Ext.Component
  439. * has a null implementation.
  440. */
  441. 'statesave'
  442. );
  443. this.getId();
  444. Ext.ComponentMgr.register(this);
  445. Ext.Component.superclass.constructor.call(this);
  446. if(this.baseAction){
  447. this.baseAction.addComponent(this);
  448. }
  449. this.initComponent();
  450. if(this.plugins){
  451. if(Ext.isArray(this.plugins)){
  452. for(var i = 0, len = this.plugins.length; i < len; i++){
  453. this.plugins[i] = this.initPlugin(this.plugins[i]);
  454. }
  455. }else{
  456. this.plugins = this.initPlugin(this.plugins);
  457. }
  458. }
  459. if(this.stateful !== false){
  460. this.initState();
  461. }
  462. if(this.applyTo){
  463. this.applyToMarkup(this.applyTo);
  464. delete this.applyTo;
  465. }else if(this.renderTo){
  466. this.render(this.renderTo);
  467. delete this.renderTo;
  468. }
  469. };
  470. // private
  471. Ext.Component.AUTO_ID = 1000;
  472. Ext.extend(Ext.Component, Ext.util.Observable, {
  473. // Configs below are used for all Components when rendered by FormLayout.
  474. /**
  475. * @cfg {String} fieldLabel <p>The label text to display next to this Component (defaults to '').</p>
  476. * <br><p><b>Note</b>: this config is only used when this Component is rendered by a Container which
  477. * has been configured to use the <b>{@link Ext.layout.FormLayout FormLayout}</b> layout manager (e.g.
  478. * {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>).</p><br>
  479. * <p>Also see <tt>{@link #hideLabel}</tt> and
  480. * {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl}.</p>
  481. * Example use:<pre><code>
  482. new Ext.FormPanel({
  483. height: 100,
  484. renderTo: Ext.getBody(),
  485. items: [{
  486. xtype: 'textfield',
  487. fieldLabel: 'Name'
  488. }]
  489. });
  490. </code></pre>
  491. */
  492. /**
  493. * @cfg {String} labelStyle <p>A CSS style specification string to apply directly to this field's
  494. * label. Defaults to the container's labelStyle value if set (e.g.,
  495. * <tt>{@link Ext.layout.FormLayout#labelStyle}</tt> , or '').</p>
  496. * <br><p><b>Note</b>: see the note for <code>{@link #clearCls}</code>.</p><br>
  497. * <p>Also see <code>{@link #hideLabel}</code> and
  498. * <code>{@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl}.</code></p>
  499. * Example use:<pre><code>
  500. new Ext.FormPanel({
  501. height: 100,
  502. renderTo: Ext.getBody(),
  503. items: [{
  504. xtype: 'textfield',
  505. fieldLabel: 'Name',
  506. labelStyle: 'font-weight:bold;'
  507. }]
  508. });
  509. </code></pre>
  510. */
  511. /**
  512. * @cfg {String} labelSeparator <p>The separator to display after the text of each
  513. * <tt>{@link #fieldLabel}</tt>. This property may be configured at various levels.
  514. * The order of precedence is:
  515. * <div class="mdetail-params"><ul>
  516. * <li>field / component level</li>
  517. * <li>container level</li>
  518. * <li>{@link Ext.layout.FormLayout#labelSeparator layout level} (defaults to colon <tt>':'</tt>)</li>
  519. * </ul></div>
  520. * To display no separator for this field's label specify empty string ''.</p>
  521. * <br><p><b>Note</b>: see the note for <tt>{@link #clearCls}</tt>.</p><br>
  522. * <p>Also see <tt>{@link #hideLabel}</tt> and
  523. * {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl}.</p>
  524. * Example use:<pre><code>
  525. new Ext.FormPanel({
  526. height: 100,
  527. renderTo: Ext.getBody(),
  528. layoutConfig: {
  529. labelSeparator: '~' // layout config has lowest priority (defaults to ':')
  530. },
  531. {@link Ext.layout.FormLayout#labelSeparator labelSeparator}: '>>', // config at container level
  532. items: [{
  533. xtype: 'textfield',
  534. fieldLabel: 'Field 1',
  535. labelSeparator: '...' // field/component level config supersedes others
  536. },{
  537. xtype: 'textfield',
  538. fieldLabel: 'Field 2' // labelSeparator will be '='
  539. }]
  540. });
  541. </code></pre>
  542. */
  543. /**
  544. * @cfg {Boolean} hideLabel <p><tt>true</tt> to completely hide the label element
  545. * ({@link #fieldLabel label} and {@link #labelSeparator separator}). Defaults to <tt>false</tt>.
  546. * By default, even if you do not specify a <tt>{@link #fieldLabel}</tt> the space will still be
  547. * reserved so that the field will line up with other fields that do have labels.
  548. * Setting this to <tt>true</tt> will cause the field to not reserve that space.</p>
  549. * <br><p><b>Note</b>: see the note for <tt>{@link #clearCls}</tt>.</p><br>
  550. * Example use:<pre><code>
  551. new Ext.FormPanel({
  552. height: 100,
  553. renderTo: Ext.getBody(),
  554. items: [{
  555. xtype: 'textfield'
  556. hideLabel: true
  557. }]
  558. });
  559. </code></pre>
  560. */
  561. /**
  562. * @cfg {String} clearCls <p>The CSS class used to to apply to the special clearing div rendered
  563. * directly after each form field wrapper to provide field clearing (defaults to
  564. * <tt>'x-form-clear-left'</tt>).</p>
  565. * <br><p><b>Note</b>: this config is only used when this Component is rendered by a Container
  566. * which has been configured to use the <b>{@link Ext.layout.FormLayout FormLayout}</b> layout
  567. * manager (e.g. {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>) and either a
  568. * <tt>{@link #fieldLabel}</tt> is specified or <tt>isFormField=true</tt> is specified.</p><br>
  569. * <p>See {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl} also.</p>
  570. */
  571. /**
  572. * @cfg {String} itemCls
  573. * <p><b>Note</b>: this config is only used when this Component is rendered by a Container which
  574. * has been configured to use the <b>{@link Ext.layout.FormLayout FormLayout}</b> layout manager (e.g.
  575. * {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>).</p><br>
  576. * <p>An additional CSS class to apply to the div wrapping the form item
  577. * element of this field. If supplied, <tt>itemCls</tt> at the <b>field</b> level will override
  578. * the default <tt>itemCls</tt> supplied at the <b>container</b> level. The value specified for
  579. * <tt>itemCls</tt> will be added to the default class (<tt>'x-form-item'</tt>).</p>
  580. * <p>Since it is applied to the item wrapper (see
  581. * {@link Ext.layout.FormLayout}.{@link Ext.layout.FormLayout#fieldTpl fieldTpl}), it allows
  582. * you to write standard CSS rules that can apply to the field, the label (if specified), or
  583. * any other element within the markup for the field.</p>
  584. * <br><p><b>Note</b>: see the note for <tt>{@link #fieldLabel}</tt>.</p><br>
  585. * Example use:<pre><code>
  586. // Apply a style to the field&#39;s label:
  587. &lt;style>
  588. .required .x-form-item-label {font-weight:bold;color:red;}
  589. &lt;/style>
  590. new Ext.FormPanel({
  591. height: 100,
  592. renderTo: Ext.getBody(),
  593. items: [{
  594. xtype: 'textfield',
  595. fieldLabel: 'Name',
  596. itemCls: 'required' //this label will be styled
  597. },{
  598. xtype: 'textfield',
  599. fieldLabel: 'Favorite Color'
  600. }]
  601. });
  602. </code></pre>
  603. */
  604. /**
  605. * @cfg {String} id
  606. * <p>The <b>unique</b> id of this component (defaults to an {@link #getId auto-assigned id}).
  607. * You should assign an id if you need to be able to access the component later and you do
  608. * not have an object reference available (e.g., using {@link Ext}.{@link Ext#getCmp getCmp}).</p>
  609. * <p>Note that this id will also be used as the element id for the containing HTML element
  610. * that is rendered to the page for this component. This allows you to write id-based CSS
  611. * rules to style the specific instance of this component uniquely, and also to select
  612. * sub-elements using this component's id as the parent.</p>
  613. * <p><b>Note</b>: to avoid complications imposed by a unique <tt>id</tt> also see
  614. * <code>{@link #itemId}</code> and <code>{@link #ref}</code>.</p>
  615. * <p><b>Note</b>: to access the container of an item see <code>{@link #ownerCt}</code>.</p>
  616. */
  617. /**
  618. * @cfg {String} itemId
  619. * <p>An <tt>itemId</tt> can be used as an alternative way to get a reference to a component
  620. * when no object reference is available. Instead of using an <code>{@link #id}</code> with
  621. * {@link Ext}.{@link Ext#getCmp getCmp}, use <code>itemId</code> with
  622. * {@link Ext.Container}.{@link Ext.Container#getComponent getComponent} which will retrieve
  623. * <code>itemId</code>'s or <tt>{@link #id}</tt>'s. Since <code>itemId</code>'s are an index to the
  624. * container's internal MixedCollection, the <code>itemId</code> is scoped locally to the container --
  625. * avoiding potential conflicts with {@link Ext.ComponentMgr} which requires a <b>unique</b>
  626. * <code>{@link #id}</code>.</p>
  627. * <pre><code>
  628. var c = new Ext.Panel({ //
  629. {@link Ext.BoxComponent#height height}: 300,
  630. {@link #renderTo}: document.body,
  631. {@link Ext.Container#layout layout}: 'auto',
  632. {@link Ext.Container#items items}: [
  633. {
  634. itemId: 'p1',
  635. {@link Ext.Panel#title title}: 'Panel 1',
  636. {@link Ext.BoxComponent#height height}: 150
  637. },
  638. {
  639. itemId: 'p2',
  640. {@link Ext.Panel#title title}: 'Panel 2',
  641. {@link Ext.BoxComponent#height height}: 150
  642. }
  643. ]
  644. })
  645. p1 = c.{@link Ext.Container#getComponent getComponent}('p1'); // not the same as {@link Ext#getCmp Ext.getCmp()}
  646. p2 = p1.{@link #ownerCt}.{@link Ext.Container#getComponent getComponent}('p2'); // reference via a sibling
  647. * </code></pre>
  648. * <p>Also see <tt>{@link #id}</tt> and <code>{@link #ref}</code>.</p>
  649. * <p><b>Note</b>: to access the container of an item see <tt>{@link #ownerCt}</tt>.</p>
  650. */
  651. /**
  652. * @cfg {String} xtype
  653. * The registered <tt>xtype</tt> to create. This config option is not used when passing
  654. * a config object into a constructor. This config option is used only when
  655. * lazy instantiation is being used, and a child item of a Container is being
  656. * specified not as a fully instantiated Component, but as a <i>Component config
  657. * object</i>. The <tt>xtype</tt> will be looked up at render time up to determine what
  658. * type of child Component to create.<br><br>
  659. * The predefined xtypes are listed {@link Ext.Component here}.
  660. * <br><br>
  661. * If you subclass Components to create your own Components, you may register
  662. * them using {@link Ext.ComponentMgr#registerType} in order to be able to
  663. * take advantage of lazy instantiation and rendering.
  664. */
  665. /**
  666. * @cfg {String} ptype
  667. * The registered <tt>ptype</tt> to create. This config option is not used when passing
  668. * a config object into a constructor. This config option is used only when
  669. * lazy instantiation is being used, and a Plugin is being
  670. * specified not as a fully instantiated Component, but as a <i>Component config
  671. * object</i>. The <tt>ptype</tt> will be looked up at render time up to determine what
  672. * type of Plugin to create.<br><br>
  673. * If you create your own Plugins, you may register them using
  674. * {@link Ext.ComponentMgr#registerPlugin} in order to be able to
  675. * take advantage of lazy instantiation and rendering.
  676. */
  677. /**
  678. * @cfg {String} cls
  679. * An optional extra CSS class that will be added to this component's Element (defaults to ''). This can be
  680. * useful for adding customized styles to the component or any of its children using standard CSS rules.
  681. */
  682. /**
  683. * @cfg {String} overCls
  684. * An optional extra CSS class that will be added to this component's Element when the mouse moves
  685. * over the Element, and removed when the mouse moves out. (defaults to ''). This can be
  686. * useful for adding customized 'active' or 'hover' styles to the component or any of its children using standard CSS rules.
  687. */
  688. /**
  689. * @cfg {String} style
  690. * A custom style specification to be applied to this component's Element. Should be a valid argument to
  691. * {@link Ext.Element#applyStyles}.
  692. * <pre><code>
  693. new Ext.Panel({
  694. title: 'Some Title',
  695. renderTo: Ext.getBody(),
  696. width: 400, height: 300,
  697. layout: 'form',
  698. items: [{
  699. xtype: 'textarea',
  700. style: {
  701. width: '95%',
  702. marginBottom: '10px'
  703. }
  704. },
  705. new Ext.Button({
  706. text: 'Send',
  707. minWidth: '100',
  708. style: {
  709. marginBottom: '10px'
  710. }
  711. })
  712. ]
  713. });
  714. * </code></pre>
  715. */
  716. /**
  717. * @cfg {String} ctCls
  718. * <p>An optional extra CSS class that will be added to this component's container. This can be useful for
  719. * adding customized styles to the container or any of its children using standard CSS rules. See
  720. * {@link Ext.layout.ContainerLayout}.{@link Ext.layout.ContainerLayout#extraCls extraCls} also.</p>
  721. * <p><b>Note</b>: <tt>ctCls</tt> defaults to <tt>''</tt> except for the following class
  722. * which assigns a value by default:
  723. * <div class="mdetail-params"><ul>
  724. * <li>{@link Ext.layout.Box Box Layout} : <tt>'x-box-layout-ct'</tt></li>
  725. * </ul></div>
  726. * To configure the above Class with an extra CSS class append to the default. For example,
  727. * for BoxLayout (Hbox and Vbox):<pre><code>
  728. * ctCls: 'x-box-layout-ct custom-class'
  729. * </code></pre>
  730. * </p>
  731. */
  732. /**
  733. * @cfg {Boolean} disabled
  734. * Render this component disabled (default is false).
  735. */
  736. disabled : false,
  737. /**
  738. * @cfg {Boolean} hidden
  739. * Render this component hidden (default is false). If <tt>true</tt>, the
  740. * {@link #hide} method will be called internally.
  741. */
  742. hidden : false,
  743. /**
  744. * @cfg {Object/Array} plugins
  745. * An object or array of objects that will provide custom functionality for this component. The only
  746. * requirement for a valid plugin is that it contain an init method that accepts a reference of type Ext.Component.
  747. * When a component is created, if any plugins are available, the component will call the init method on each
  748. * plugin, passing a reference to itself. Each plugin can then call methods or respond to events on the
  749. * component as needed to provide its functionality.
  750. */
  751. /**
  752. * @cfg {Mixed} applyTo
  753. * <p>Specify the id of the element, a DOM element or an existing Element corresponding to a DIV
  754. * that is already present in the document that specifies some structural markup for this
  755. * component.</p><div><ul>
  756. * <li><b>Description</b> : <ul>
  757. * <div class="sub-desc">When <tt>applyTo</tt> is used, constituent parts of the component can also be specified
  758. * by id or CSS class name within the main element, and the component being created may attempt
  759. * to create its subcomponents from that markup if applicable.</div>
  760. * </ul></li>
  761. * <li><b>Notes</b> : <ul>
  762. * <div class="sub-desc">When using this config, a call to render() is not required.</div>
  763. * <div class="sub-desc">If applyTo is specified, any value passed for {@link #renderTo} will be ignored and the target
  764. * element's parent node will automatically be used as the component's container.</div>
  765. * </ul></li>
  766. * </ul></div>
  767. */
  768. /**
  769. * @cfg {Mixed} renderTo
  770. * <p>Specify the id of the element, a DOM element or an existing Element that this component
  771. * will be rendered into.</p><div><ul>
  772. * <li><b>Notes</b> : <ul>
  773. * <div class="sub-desc">Do <u>not</u> use this option if the Component is to be a child item of
  774. * a {@link Ext.Container Container}. It is the responsibility of the
  775. * {@link Ext.Container Container}'s {@link Ext.Container#layout layout manager}
  776. * to render and manage its child items.</div>
  777. * <div class="sub-desc">When using this config, a call to render() is not required.</div>
  778. * </ul></li>
  779. * </ul></div>
  780. * <p>See <tt>{@link #render}</tt> also.</p>
  781. */
  782. /**
  783. * @cfg {Boolean} stateful
  784. * <p>A flag which causes the Component to attempt to restore the state of
  785. * internal properties from a saved state on startup. The component must have
  786. * either a <code>{@link #stateId}</code> or <code>{@link #id}</code> assigned
  787. * for state to be managed. Auto-generated ids are not guaranteed to be stable
  788. * across page loads and cannot be relied upon to save and restore the same
  789. * state for a component.<p>
  790. * <p>For state saving to work, the state manager's provider must have been
  791. * set to an implementation of {@link Ext.state.Provider} which overrides the
  792. * {@link Ext.state.Provider#set set} and {@link Ext.state.Provider#get get}
  793. * methods to save and recall name/value pairs. A built-in implementation,
  794. * {@link Ext.state.CookieProvider} is available.</p>
  795. * <p>To set the state provider for the current page:</p>
  796. * <pre><code>
  797. Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
  798. expires: new Date(new Date().getTime()+(1000*60*60*24*7)), //7 days from now
  799. }));
  800. * </code></pre>
  801. * <p>A stateful Component attempts to save state when one of the events
  802. * listed in the <code>{@link #stateEvents}</code> configuration fires.</p>
  803. * <p>To save state, a stateful Component first serializes its state by
  804. * calling <b><code>getState</code></b>. By default, this function does
  805. * nothing. The developer must provide an implementation which returns an
  806. * object hash which represents the Component's restorable state.</p>
  807. * <p>The value yielded by getState is passed to {@link Ext.state.Manager#set}
  808. * which uses the configured {@link Ext.state.Provider} to save the object
  809. * keyed by the Component's <code>{@link stateId}</code>, or, if that is not
  810. * specified, its <code>{@link #id}</code>.</p>
  811. * <p>During construction, a stateful Component attempts to <i>restore</i>
  812. * its state by calling {@link Ext.state.Manager#get} passing the
  813. * <code>{@link #stateId}</code>, or, if that is not specified, the
  814. * <code>{@link #id}</code>.</p>
  815. * <p>The resulting object is passed to <b><code>applyState</code></b>.
  816. * The default implementation of <code>applyState</code> simply copies
  817. * properties into the object, but a developer may override this to support
  818. * more behaviour.</p>
  819. * <p>You can perform extra processing on state save and restore by attaching
  820. * handlers to the {@link #beforestaterestore}, {@link #staterestore},
  821. * {@link #beforestatesave} and {@link #statesave} events.</p>
  822. */
  823. /**
  824. * @cfg {String} stateId
  825. * The unique id for this component to use for state management purposes
  826. * (defaults to the component id if one was set, otherwise null if the
  827. * component is using a generated id).
  828. * <p>See <code>{@link #stateful}</code> for an explanation of saving and
  829. * restoring Component state.</p>
  830. */
  831. /**
  832. * @cfg {Array} stateEvents
  833. * <p>An array of events that, when fired, should trigger this component to
  834. * save its state (defaults to none). <code>stateEvents</code> may be any type
  835. * of event supported by this component, including browser or custom events
  836. * (e.g., <tt>['click', 'customerchange']</tt>).</p>
  837. * <p>See <code>{@link #stateful}</code> for an explanation of saving and
  838. * restoring Component state.</p>
  839. */
  840. /**
  841. * @cfg {Mixed} autoEl
  842. * <p>A tag name or {@link Ext.DomHelper DomHelper} spec used to create the {@link #getEl Element} which will
  843. * encapsulate this Component.</p>
  844. * <p>You do not normally need to specify this. For the base classes {@link Ext.Component}, {@link Ext.BoxComponent},
  845. * and {@link Ext.Container}, this defaults to <b><tt>'div'</tt></b>. The more complex Ext classes use a more complex
  846. * DOM structure created by their own onRender methods.</p>
  847. * <p>This is intended to allow the developer to create application-specific utility Components encapsulated by
  848. * different DOM elements. Example usage:</p><pre><code>
  849. {
  850. xtype: 'box',
  851. autoEl: {
  852. tag: 'img',
  853. src: 'http://www.example.com/example.jpg'
  854. }
  855. }, {
  856. xtype: 'box',
  857. autoEl: {
  858. tag: 'blockquote',
  859. html: 'autoEl is cool!'
  860. }
  861. }, {
  862. xtype: 'container',
  863. autoEl: 'ul',
  864. cls: 'ux-unordered-list',
  865. items: {
  866. xtype: 'box',
  867. autoEl: 'li',
  868. html: 'First list item'
  869. }
  870. }
  871. </code></pre>
  872. */
  873. autoEl : 'div',
  874. /**
  875. * @cfg {String} disabledClass
  876. * CSS class added to the component when it is disabled (defaults to 'x-item-disabled').
  877. */
  878. disabledClass : 'x-item-disabled',
  879. /**
  880. * @cfg {Boolean} allowDomMove
  881. * Whether the component can move the Dom node when rendering (defaults to true).
  882. */
  883. allowDomMove : true,
  884. /**
  885. * @cfg {Boolean} autoShow
  886. * True if the component should check for hidden classes (e.g. 'x-hidden' or 'x-hide-display') and remove
  887. * them on render (defaults to false).
  888. */
  889. autoShow : false,
  890. /**
  891. * @cfg {String} hideMode
  892. * <p>How this component should be hidden. Supported values are <tt>'visibility'</tt>
  893. * (css visibility), <tt>'offsets'</tt> (negative offset position) and <tt>'display'</tt>
  894. * (css display).</p>
  895. * <br><p><b>Note</b>: the default of <tt>'display'</tt> is generally preferred
  896. * since items are automatically laid out when they are first shown (no sizing
  897. * is done while hidden).</p>
  898. */
  899. hideMode : 'display',
  900. /**
  901. * @cfg {Boolean} hideParent
  902. * True to hide and show the component's container when hide/show is called on the component, false to hide
  903. * and show the component itself (defaults to false). For example, this can be used as a shortcut for a hide
  904. * button on a window by setting hide:true on the button when adding it to its parent container.
  905. */
  906. hideParent : false,
  907. /**
  908. * <p>The {@link Ext.Element} which encapsulates this Component. Read-only.</p>
  909. * <p>This will <i>usually</i> be a &lt;DIV> element created by the class's onRender method, but
  910. * that may be overridden using the <code>{@link #autoEl}</code> config.</p>
  911. * <br><p><b>Note</b>: this element will not be available until this Component has been rendered.</p><br>
  912. * <p>To add listeners for <b>DOM events</b> to this Component (as opposed to listeners
  913. * for this Component's own Observable events), see the {@link Ext.util.Observable#listeners listeners}
  914. * config for a suggestion, or use a render listener directly:</p><pre><code>
  915. new Ext.Panel({
  916. title: 'The Clickable Panel',
  917. listeners: {
  918. render: function(p) {
  919. // Append the Panel to the click handler&#39;s argument list.
  920. p.getEl().on('click', handlePanelClick.createDelegate(null, [p], true));
  921. },
  922. single: true // Remove the listener after first invocation
  923. }
  924. });
  925. </code></pre>
  926. * <p>See also <tt>{@link #getEl getEl}</p>
  927. * @type Ext.Element
  928. * @property el
  929. */
  930. /**
  931. * This Component's owner {@link Ext.Container Container} (defaults to undefined, and is set automatically when
  932. * this Component is added to a Container). Read-only.
  933. * <p><b>Note</b>: to access items within the Container see <tt>{@link #itemId}</tt>.</p>
  934. * @type Ext.Container
  935. * @property ownerCt
  936. */
  937. /**
  938. * True if this component is hidden. Read-only.
  939. * @type Boolean
  940. * @property hidden
  941. */
  942. /**
  943. * True if this component is disabled. Read-only.
  944. * @type Boolean
  945. * @property disabled
  946. */
  947. /**
  948. * True if this component has been rendered. Read-only.
  949. * @type Boolean
  950. * @property rendered
  951. */
  952. rendered : false,
  953. /**
  954. * @cfg {String} contentEl
  955. * <p>Optional. Specify an existing HTML element, or the <code>id</code> of an existing HTML element to use as the content
  956. * for this component.</p>
  957. * <ul>
  958. * <li><b>Description</b> :
  959. * <div class="sub-desc">This config option is used to take an existing HTML element and place it in the layout element
  960. * 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>
  961. * <li><b>Notes</b> :
  962. * <div class="sub-desc">The specified HTML element is appended to the layout element of the component <i>after any configured
  963. * {@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>
  964. * <div class="sub-desc">The specified HTML element used will not participate in any <code><b>{@link Ext.Container#layout layout}</b></code>
  965. * scheme that the Component may use. It is just HTML. Layouts operate on child <code><b>{@link Ext.Container#items items}</b></code>.</div>
  966. * <div class="sub-desc">Add either the <code>x-hidden</code> or the <code>x-hide-display</code> CSS class to
  967. * prevent a brief flicker of the content before it is rendered to the panel.</div></li>
  968. * </ul>
  969. */
  970. /**
  971. * @cfg {String/Object} html
  972. * An HTML fragment, or a {@link Ext.DomHelper DomHelper} specification to use as the layout element
  973. * content (defaults to ''). The HTML content is added after the component is rendered,
  974. * so the document will not contain this HTML at the time the {@link #render} event is fired.
  975. * This content is inserted into the body <i>before</i> any configured {@link #contentEl} is appended.
  976. */
  977. /**
  978. * @cfg {Mixed} tpl
  979. * An <bold>{@link Ext.Template}</bold>, <bold>{@link Ext.XTemplate}</bold>
  980. * or an array of strings to form an Ext.XTemplate.
  981. * Used in conjunction with the <code>{@link #data}</code> and
  982. * <code>{@link #tplWriteMode}</code> configurations.
  983. */
  984. /**
  985. * @cfg {String} tplWriteMode The Ext.(X)Template method to use when
  986. * updating the content area of the Component. Defaults to <tt>'overwrite'</tt>
  987. * (see <code>{@link Ext.XTemplate#overwrite}</code>).
  988. */
  989. tplWriteMode : 'overwrite',
  990. /**
  991. * @cfg {Mixed} data
  992. * The initial set of data to apply to the <code>{@link #tpl}</code> to
  993. * update the content area of the Component.
  994. */
  995. /**
  996. * @cfg {Array} bubbleEvents
  997. * <p>An array of events that, when fired, should be bubbled to any parent container.
  998. * See {@link Ext.util.Observable#enableBubble}.
  999. * Defaults to <tt>[]</tt>.
  1000. */
  1001. bubbleEvents: [],
  1002. // private
  1003. ctype : 'Ext.Component',
  1004. // private
  1005. actionMode : 'el',
  1006. // private
  1007. getActionEl : function(){
  1008. return this[this.actionMode];
  1009. },
  1010. initPlugin : function(p){
  1011. if(p.ptype && !Ext.isFunction(p.init)){
  1012. p = Ext.ComponentMgr.createPlugin(p);
  1013. }else if(Ext.isString(p)){
  1014. p = Ext.ComponentMgr.createPlugin({
  1015. ptype: p
  1016. });
  1017. }
  1018. p.init(this);
  1019. return p;
  1020. },
  1021. /* // protected
  1022. * Function to be implemented by Component subclasses to be part of standard component initialization flow (it is empty by default).
  1023. * <pre><code>
  1024. // Traditional constructor:
  1025. Ext.Foo = function(config){
  1026. // call superclass constructor:
  1027. Ext.Foo.superclass.constructor.call(this, config);
  1028. this.addEvents({
  1029. // add events
  1030. });
  1031. };
  1032. Ext.extend(Ext.Foo, Ext.Bar, {
  1033. // class body
  1034. }
  1035. // initComponent replaces the constructor:
  1036. Ext.Foo = Ext.extend(Ext.Bar, {
  1037. initComponent : function(){
  1038. // call superclass initComponent
  1039. Ext.Container.superclass.initComponent.call(this);
  1040. this.addEvents({
  1041. // add events
  1042. });
  1043. }
  1044. }
  1045. </code></pre>
  1046. */
  1047. initComponent : function(){
  1048. /*
  1049. * this is double processing, however it allows people to be able to do
  1050. * Ext.apply(this, {
  1051. * listeners: {
  1052. * //here
  1053. * }
  1054. * });
  1055. * MyClass.superclass.initComponent.call(this);
  1056. */
  1057. if(this.listeners){
  1058. this.on(this.listeners);
  1059. delete this.listeners;
  1060. }
  1061. this.enableBubble(this.bubbleEvents);
  1062. },
  1063. /**
  1064. * <p>Render this Component into the passed HTML element.</p>
  1065. * <p><b>If you are using a {@link Ext.Container Container} object to house this Component, then
  1066. * do not use the render method.</b></p>
  1067. * <p>A Container's child Components are rendered by that Container's
  1068. * {@link Ext.Container#layout layout} manager when the Container is first rendered.</p>
  1069. * <p>Certain layout managers allow dynamic addition of child components. Those that do
  1070. * include {@link Ext.layout.CardLayout}, {@link Ext.layout.AnchorLayout},
  1071. * {@link Ext.layout.FormLayout}, {@link Ext.layout.TableLayout}.</p>
  1072. * <p>If the Container is already rendered when a new child Component is added, you may need to call
  1073. * the Container's {@link Ext.Container#doLayout doLayout} to refresh the view which causes any
  1074. * unrendered child Components to be rendered. This is required so that you can add multiple
  1075. * child components if needed while only refreshing the layout once.</p>
  1076. * <p>When creating complex UIs, it is important to remember that sizing and positioning
  1077. * of child items is the responsibility of the Container's {@link Ext.Container#layout layout} manager.
  1078. * If you expect child items to be sized in response to user interactions, you must
  1079. * configure the Container with a layout manager which creates and manages the type of layout you
  1080. * have in mind.</p>
  1081. * <p><b>Omitting the Container's {@link Ext.Container#layout layout} config means that a basic
  1082. * layout manager is used which does nothing but render child components sequentially into the
  1083. * Container. No sizing or positioning will be performed in this situation.</b></p>
  1084. * @param {Element/HTMLElement/String} container (optional) The element this Component should be
  1085. * rendered into. If it is being created from existing markup, this should be omitted.
  1086. * @param {String/Number} position (optional) The element ID or DOM node index within the container <b>before</b>
  1087. * which this component will be inserted (defaults to appending to the end of the container)
  1088. */
  1089. render : function(container, position){
  1090. if(!this.rendered && this.fireEvent('beforerender', this) !== false){
  1091. if(!container && this.el){
  1092. this.el = Ext.get(this.el);
  1093. container = this.el.dom.parentNode;
  1094. this.allowDomMove = false;
  1095. }
  1096. this.container = Ext.get(container);
  1097. if(this.ctCls){
  1098. this.container.addClass(this.ctCls);
  1099. }
  1100. this.rendered = true;
  1101. if(position !== undefined){
  1102. if(Ext.isNumber(position)){
  1103. position = this.container.dom.childNodes[position];
  1104. }else{
  1105. position = Ext.getDom(position);
  1106. }
  1107. }
  1108. this.onRender(this.container, position || null);
  1109. if(this.autoShow){
  1110. this.el.removeClass(['x-hidden','x-hide-' + this.hideMode]);
  1111. }
  1112. if(this.cls){
  1113. this.el.addClass(this.cls);
  1114. delete this.cls;
  1115. }
  1116. if(this.style){
  1117. this.el.applyStyles(this.style);
  1118. delete this.style;
  1119. }
  1120. if(this.overCls){
  1121. this.el.addClassOnOver(this.overCls);
  1122. }
  1123. this.fireEvent('render', this);
  1124. // Populate content of the component with html, contentEl or
  1125. // a tpl.
  1126. var contentTarget = this.getContentTarget();
  1127. if (this.html){
  1128. contentTarget.update(Ext.DomHelper.markup(this.html));
  1129. delete this.html;
  1130. }
  1131. if (this.contentEl){
  1132. var ce = Ext.getDom(this.contentEl);
  1133. Ext.fly(ce).removeClass(['x-hidden', 'x-hide-display']);
  1134. contentTarget.appendChild(ce);
  1135. }
  1136. if (this.tpl) {
  1137. if (!this.tpl.compile) {
  1138. this.tpl = new Ext.XTemplate(this.tpl);
  1139. }
  1140. if (this.data) {
  1141. this.tpl[this.tplWriteMode](contentTarget, this.data);
  1142. delete this.data;
  1143. }
  1144. }
  1145. this.afterRender(this.container);
  1146. if(this.hidden){
  1147. // call this so we don't fire initial hide events.
  1148. this.doHide();
  1149. }
  1150. if(this.disabled){
  1151. // pass silent so the event doesn't fire the first time.
  1152. this.disable(true);
  1153. }
  1154. if(this.stateful !== false){
  1155. this.initStateEvents();
  1156. }
  1157. this.fireEvent('afterrender', this);
  1158. }
  1159. return this;
  1160. },
  1161. /**
  1162. * Update the content area of a component.
  1163. * @param {Mixed} htmlOrData
  1164. * If this component has been configured with a template via the tpl config
  1165. * then it will use this argument as data to populate the template.
  1166. * If this component was not configured with a template, the components
  1167. * content area will be updated via Ext.Element update
  1168. * @param {Boolean} loadScripts
  1169. * (optional) Only legitimate when using the html configuration. Defaults to false
  1170. * @param {Function} callback
  1171. * (optional) Only legitimate when using the html configuration. Callback to execute when scripts have finished loading
  1172. */
  1173. update: function(htmlOrData, loadScripts, cb) {
  1174. var contentTarget = this.getContentTarget();
  1175. if (this.tpl && typeof htmlOrData !== "string") {
  1176. this.tpl[this.tplWriteMode](contentTarget, htmlOrData || {});
  1177. } else {
  1178. var html = Ext.isObject(htmlOrData) ? Ext.DomHelper.markup(htmlOrData) : htmlOrData;
  1179. contentTarget.update(html, loadScripts, cb);
  1180. }
  1181. },
  1182. /**
  1183. * @private
  1184. * Method to manage awareness of when components are added to their
  1185. * respective Container, firing an added event.
  1186. * References are established at add time rather than at render time.
  1187. * @param {Ext.Container} container Container which holds the component
  1188. * @param {number} pos Position at which the component was added
  1189. */
  1190. onAdded : function(container, pos) {
  1191. this.ownerCt = container;
  1192. this.initRef();
  1193. this.fireEvent('added', this, container, pos);
  1194. },
  1195. /**
  1196. * @private
  1197. * Method to manage awareness of when components are removed from their
  1198. * respective Container, firing an removed event. References are properly
  1199. * cleaned up after removing a component from its owning container.
  1200. */
  1201. onRemoved : function() {
  1202. this.removeRef();
  1203. this.fireEvent('removed', this, this.ownerCt);
  1204. delete this.ownerCt;
  1205. },
  1206. /**
  1207. * @private
  1208. * Method to establish a reference to a component.
  1209. */
  1210. initRef : function() {
  1211. /**
  1212. * @cfg {String} ref
  1213. * <p>A path specification, relative to the Component's <code>{@link #ownerCt}</code>
  1214. * specifying into which ancestor Container to place a named reference to this Component.</p>
  1215. * <p>The ancestor axis can be traversed by using '/' characters in the path.
  1216. * For example, to put a reference to a Toolbar Button into <i>the Panel which owns the Toolbar</i>:</p><pre><code>
  1217. var myGrid = new Ext.grid.EditorGridPanel({
  1218. title: 'My EditorGridPanel',
  1219. store: myStore,
  1220. colModel: myColModel,
  1221. tbar: [{
  1222. text: 'Save',
  1223. handler: saveChanges,
  1224. disabled: true,
  1225. ref: '../saveButton'
  1226. }],
  1227. listeners: {
  1228. afteredit: function() {
  1229. // The button reference is in the GridPanel
  1230. myGrid.saveButton.enable();
  1231. }
  1232. }
  1233. });
  1234. </code></pre>
  1235. * <p>In the code above, if the <code>ref</code> had been <code>'saveButton'</code>
  1236. * the reference would have been placed into the Toolbar. Each '/' in the <code>ref</code>
  1237. * moves up one level from the Component's <code>{@link #ownerCt}</code>.</p>
  1238. * <p>Also see the <code>{@link #added}</code> and <code>{@link #removed}</code> events.</p>
  1239. */
  1240. if(this.ref && !this.refOwner){
  1241. var levels = this.ref.split('/'),
  1242. last = levels.length,
  1243. i = 0,
  1244. t = this;
  1245. while(t && i < last){
  1246. t = t.ownerCt;
  1247. ++i;
  1248. }
  1249. if(t){
  1250. t[this.refName = levels[--i]] = this;
  1251. /**
  1252. * @type Ext.Container
  1253. * @property refOwner
  1254. * The ancestor Container into which the {@link #ref} reference was inserted if this Component
  1255. * is a child of a Container, and has been configured with a <code>ref</code>.
  1256. */
  1257. this.refOwner = t;
  1258. }
  1259. }
  1260. },
  1261. removeRef : function() {
  1262. if (this.refOwner && this.refName) {
  1263. delete this.refOwner[this.refName];
  1264. delete this.refOwner;
  1265. }
  1266. },
  1267. // private
  1268. initState : function(){
  1269. if(Ext.state.Manager){
  1270. var id = this.getStateId();
  1271. if(id){
  1272. var state = Ext.state.Manager.get(id);
  1273. if(state){
  1274. if(this.fireEvent('beforestaterestore', this, state) !== false){
  1275. this.applyState(Ext.apply({}, state));
  1276. this.fireEvent('staterestore', this, state);
  1277. }
  1278. }
  1279. }
  1280. }
  1281. },
  1282. // private
  1283. getStateId : function(){
  1284. return this.stateId || ((/^(ext-comp-|ext-gen)/).test(String(this.id)) ? null : this.id);
  1285. },
  1286. // private
  1287. initStateEvents : function(){
  1288. if(this.stateEvents){
  1289. for(var i = 0, e; e = this.stateEvents[i]; i++){
  1290. this.on(e, this.saveState, this, {delay:100});
  1291. }
  1292. }
  1293. },
  1294. // private
  1295. applyState : function(state){
  1296. if(state){
  1297. Ext.apply(this, state);
  1298. }
  1299. },
  1300. // private
  1301. getState : function(){
  1302. return null;
  1303. },
  1304. // private
  1305. saveState : function(){
  1306. if(Ext.state.Manager && this.stateful !== false){
  1307. var id = this.getStateId();
  1308. if(id){
  1309. var state = this.getState();
  1310. if(this.fireEvent('beforestatesave', this, state) !== false){
  1311. Ext.state.Manager.set(id, state);
  1312. this.fireEvent('statesave', this, state);
  1313. }
  1314. }
  1315. }
  1316. },
  1317. /**
  1318. * Apply this component to existing markup that is valid. With this function, no call to render() is required.
  1319. * @param {String/HTMLElement} el
  1320. */
  1321. applyToMarkup : function(el){
  1322. this.allowDomMove = false;
  1323. this.el = Ext.get(el);
  1324. this.render(this.el.dom.parentNode);
  1325. },
  1326. /**
  1327. * Adds a CSS class to the component's underlying element.
  1328. * @param {string} cls The CSS class name to add
  1329. * @return {Ext.Component} this
  1330. */
  1331. addClass : function(cls){
  1332. if(this.el){
  1333. this.el.addClass(cls);
  1334. }else{
  1335. this.cls = this.cls ? this.cls + ' ' + cls : cls;
  1336. }
  1337. return this;
  1338. },
  1339. /**
  1340. * Removes a CSS class from the component's underlying element.
  1341. * @param {string} cls The CSS class name to remove
  1342. * @return {Ext.Component} this
  1343. */
  1344. removeClass : function(cls){
  1345. if(this.el){
  1346. this.el.removeClass(cls);
  1347. }else if(this.cls){
  1348. this.cls = this.cls.split(' ').remove(cls).join(' ');
  1349. }
  1350. return this;
  1351. },
  1352. // private
  1353. // default function is not really useful
  1354. onRender : function(ct, position){
  1355. if(!this.el && this.autoEl){
  1356. if(Ext.isString(this.autoEl)){
  1357. this.el = document.createElement(this.autoEl);
  1358. }else{
  1359. var div = document.createElement('div');
  1360. Ext.DomHelper.overwrite(div, this.autoEl);
  1361. this.el = div.firstChild;
  1362. }
  1363. if (!this.el.id) {
  1364. this.el.id = this.getId();
  1365. }
  1366. }
  1367. if(this.el){
  1368. this.el = Ext.get(this.el);
  1369. if(this.allowDomMove !== false){
  1370. ct.dom.insertBefore(this.el.dom, position);
  1371. if (div) {
  1372. Ext.removeNode(div);
  1373. div = null;
  1374. }
  1375. }
  1376. }
  1377. },
  1378. // private
  1379. getAutoCreate : function(){
  1380. var cfg = Ext.isObject(this.autoCreate) ?
  1381. this.autoCreate : Ext.apply({}, this.defaultAutoCreate);
  1382. if(this.id && !cfg.id){
  1383. cfg.id = this.id;
  1384. }
  1385. return cfg;
  1386. },
  1387. // private
  1388. afterRender : Ext.emptyFn,
  1389. /**
  1390. * Destroys this component by purging any event listeners, removing the component's element from the DOM,
  1391. * removing the component from its {@link Ext.Container} (if applicable) and unregistering it from
  1392. * {@link Ext.ComponentMgr}. Destruction is generally handled automatically by the framework and this method
  1393. * should usually not need to be called directly.
  1394. *
  1395. */
  1396. destroy : function(){
  1397. if(!this.isDestroyed){
  1398. if(this.fireEvent('beforedestroy', this) !== false){
  1399. this.destroying = true;
  1400. this.beforeDestroy();
  1401. if(this.ownerCt && this.ownerCt.remove){
  1402. this.ownerCt.remove(this, false);
  1403. }
  1404. if(this.rendered){
  1405. this.el.remove();
  1406. if(this.actionMode == 'container' || this.removeMode == 'container'){
  1407. this.container.remove();
  1408. }
  1409. }
  1410. // Stop any buffered tasks
  1411. if(this.focusTask && this.focusTask.cancel){
  1412. this.focusTask.cancel();
  1413. }
  1414. this.onDestroy();
  1415. Ext.ComponentMgr.unregister(this);
  1416. this.fireEvent('destroy', this);
  1417. this.purgeListeners();
  1418. this.destroying = false;
  1419. this.isDestroyed = true;
  1420. }
  1421. }
  1422. },
  1423. deleteMembers : function(){
  1424. var args = arguments;
  1425. for(var i = 0, len = args.length; i < len; ++i){
  1426. delete this[args[i]];
  1427. }
  1428. },
  1429. // private
  1430. beforeDestroy : Ext.emptyFn,
  1431. // private
  1432. onDestroy : Ext.emptyFn,
  1433. /**
  1434. * <p>Returns the {@link Ext.Element} which encapsulates this Component.</p>
  1435. * <p>This will <i>usually</i> be a &lt;DIV> element created by the class's onRender method, but
  1436. * that may be overridden using the {@link #autoEl} config.</p>
  1437. * <br><p><b>Note</b>: this element will not be available until this Component has been rendered.</p><br>
  1438. * <p>To add listeners for <b>DOM events</b> to this Component (as opposed to listeners
  1439. * for this Component's own Observable events), see the {@link #listeners} config for a suggestion,
  1440. * or use a render listener directly:</p><pre><code>
  1441. new Ext.Panel({
  1442. title: 'The Clickable Panel',
  1443. listeners: {
  1444. render: function(p) {
  1445. // Append the Panel to the click handler&#39;s argument list.
  1446. p.getEl().on('click', handlePanelClick.createDelegate(null, [p], true));
  1447. },
  1448. single: true // Remove the listener after first invocation
  1449. }
  1450. });
  1451. </code></pre>
  1452. * @return {Ext.Element} The Element which encapsulates this Component.
  1453. */
  1454. getEl : function(){
  1455. return this.el;
  1456. },
  1457. // private
  1458. getContentTarget : function(){
  1459. return this.el;
  1460. },
  1461. /**
  1462. * Returns the <code>id</code> of this component or automatically generates and
  1463. * returns an <code>id</code> if an <code>id</code> is not defined yet:<pre><code>
  1464. * 'ext-comp-' + (++Ext.Component.AUTO_ID)
  1465. * </code></pre>
  1466. * @return {String} id
  1467. */
  1468. getId : function(){
  1469. return this.id || (this.id = 'ext-comp-' + (++Ext.Component.AUTO_ID));
  1470. },
  1471. /**
  1472. * Returns the <code>{@link #itemId}</code> of this component. If an
  1473. * <code>{@link #itemId}</code> was not assigned through configuration the
  1474. * <code>id</code> is returned using <code>{@link #getId}</code>.
  1475. * @return {String}
  1476. */
  1477. getItemId : function(){
  1478. return this.itemId || this.getId();
  1479. },
  1480. /**
  1481. * Try to focus this component.
  1482. * @param {Boolean} selectText (optional) If applicable, true to also select the text in this component
  1483. * @param {Boolean/Number} delay (optional) Delay the focus this number of milliseconds (true for 10 milliseconds)
  1484. * @return {Ext.Component} this
  1485. */
  1486. focus : function(selectText, delay){
  1487. if(delay){
  1488. this.focusTask = new Ext.util.DelayedTask(this.focus, this, [selectText, false]);
  1489. this.focusTask.delay(Ext.isNumber(delay) ? delay : 10);
  1490. return this;
  1491. }
  1492. if(this.rendered && !this.isDestroyed){
  1493. this.el.focus();
  1494. if(selectText === true){
  1495. this.el.dom.select();
  1496. }
  1497. }
  1498. return this;
  1499. },
  1500. // private
  1501. blur : function(){
  1502. if(this.rendered){
  1503. this.el.blur();
  1504. }
  1505. return this;
  1506. },
  1507. /**
  1508. * Disable this component and fire the 'disable' event.
  1509. * @return {Ext.Component} this
  1510. */
  1511. disable : function(/* private */ silent){
  1512. if(this.rendered){
  1513. this.onDisable();
  1514. }
  1515. this.disabled = true;
  1516. if(silent !== true){
  1517. this.fireEvent('disable', this);
  1518. }
  1519. return this;
  1520. },
  1521. // private
  1522. onDisable : function(){
  1523. this.getActionEl().addClass(this.disabledClass);
  1524. this.el.dom.disabled = true;
  1525. },
  1526. /**
  1527. * Enable this component and fire the 'enable' event.
  1528. * @return {Ext.Component} this
  1529. */
  1530. enable : function(){
  1531. if(this.rendered){
  1532. this.onEnable();
  1533. }
  1534. this.disabled = false;
  1535. this.fireEvent('enable', this);
  1536. return this;
  1537. },
  1538. // private
  1539. onEnable : function(){
  1540. this.getActionEl().removeClass(this.disabledClass);
  1541. this.el.dom.disabled = false;
  1542. },
  1543. /**
  1544. * Convenience function for setting disabled/enabled by boolean.
  1545. * @param {Boolean} disabled
  1546. * @return {Ext.Component} this
  1547. */
  1548. setDisabled : function(disabled){
  1549. return this[disabled ? 'disable' : 'enable']();
  1550. },
  1551. /**
  1552. * Show this component. Listen to the '{@link #beforeshow}' event and return
  1553. * <tt>false</tt> to cancel showing the component. Fires the '{@link #show}'
  1554. * event after showing the component.
  1555. * @return {Ext.Component} this
  1556. */
  1557. show : function(){
  1558. if(this.fireEvent('beforeshow', this) !== false){
  1559. this.hidden = false;
  1560. if(this.autoRender){
  1561. this.render(Ext.isBoolean(this.autoRender) ? Ext.getBody() : this.autoRender);
  1562. }
  1563. if(this.rendered){
  1564. this.onShow();
  1565. }
  1566. this.fireEvent('show', this);
  1567. }
  1568. return this;
  1569. },
  1570. // private
  1571. onShow : function(){
  1572. this.getVisibilityEl().removeClass('x-hide-' + this.hideMode);
  1573. },
  1574. /**
  1575. * Hide this component. Listen to the '{@link #beforehide}' event and return
  1576. * <tt>false</tt> to cancel hiding the component. Fires the '{@link #hide}'
  1577. * event after hiding the component. Note this method is called internally if
  1578. * the component is configured to be <code>{@link #hidden}</code>.
  1579. * @return {Ext.Component} this
  1580. */
  1581. hide : function(){
  1582. if(this.fireEvent('beforehide', this) !== false){
  1583. this.doHide();
  1584. this.fireEvent('hide', this);
  1585. }
  1586. return this;
  1587. },
  1588. // private
  1589. doHide: function(){
  1590. this.hidden = true;
  1591. if(this.rendered){
  1592. this.onHide();
  1593. }
  1594. },
  1595. // private
  1596. onHide : function(){
  1597. this.getVisibilityEl().addClass('x-hide-' + this.hideMode);
  1598. },
  1599. // private
  1600. getVisibilityEl : function(){
  1601. return this.hideParent ? this.container : this.getActionEl();
  1602. },
  1603. /**
  1604. * Convenience function to hide or show this component by boolean.
  1605. * @param {Boolean} visible True to show, false to hide
  1606. * @return {Ext.Component} this
  1607. */
  1608. setVisible : function(visible){
  1609. return this[visible ? 'show' : 'hide']();
  1610. },
  1611. /**
  1612. * Returns true if this component is visible.
  1613. * @return {Boolean} True if this component is visible, false otherwise.
  1614. */
  1615. isVisible : function(){
  1616. return this.rendered && this.getVisibilityEl().isVisible();
  1617. },
  1618. /**
  1619. * Clone the current component using the original config values passed into this instance by default.
  1620. * @param {Object} overrides A new config containing any properties to override in the cloned version.
  1621. * An id property can be passed on this object, otherwise one will be generated to avoid duplicates.
  1622. * @return {Ext.Component} clone The cloned copy of this component
  1623. */
  1624. cloneConfig : function(overrides){
  1625. overrides = overrides || {};
  1626. var id = overrides.id || Ext.id();
  1627. var cfg = Ext.applyIf(overrides, this.initialConfig);
  1628. cfg.id = id; // prevent dup id
  1629. return new this.constructor(cfg);
  1630. },
  1631. /**
  1632. * Gets the xtype for this component as registered with {@link Ext.ComponentMgr}. For a list of all
  1633. * available xtypes, see the {@link Ext.Component} header. Example usage:
  1634. * <pre><code>
  1635. var t = new Ext.form.TextField();
  1636. alert(t.getXType()); // alerts 'textfield'
  1637. </code></pre>
  1638. * @return {String} The xtype
  1639. */
  1640. getXType : function(){
  1641. return this.constructor.xtype;
  1642. },
  1643. /**
  1644. * <p>Tests whether or not this Component is of a specific xtype. This can test whether this Component is descended
  1645. * from the xtype (default) or whether it is directly of the xtype specified (shallow = true).</p>
  1646. * <p><b>If using your own subclasses, be aware that a Component must register its own xtype
  1647. * to participate in determination of inherited xtypes.</b></p>
  1648. * <p>For a list of all available xtypes, see the {@link Ext.Component} header.</p>
  1649. * <p>Example usage:</p>
  1650. * <pre><code>
  1651. var t = new Ext.form.TextField();
  1652. var isText = t.isXType('textfield'); // true
  1653. var isBoxSubclass = t.isXType('box'); // true, descended from BoxComponent
  1654. var isBoxInstance = t.isXType('box', true); // false, not a direct BoxComponent instance
  1655. </code></pre>
  1656. * @param {String/Ext.Component/Class} xtype The xtype to check for this Component. Note that the the component can either be an instance
  1657. * or a component class:
  1658. * <pre><code>
  1659. var c = new Ext.Component();
  1660. console.log(c.isXType(c));
  1661. console.log(c.isXType(Ext.Component));
  1662. </code></pre>
  1663. * @param {Boolean} shallow (optional) False to check whether this Component is descended from the xtype (this is
  1664. * the default), or true to check whether this Component is directly of the specified xtype.
  1665. * @return {Boolean} True if this component descends from the specified xtype, false otherwise.
  1666. */
  1667. isXType : function(xtype, shallow){
  1668. //assume a string by default
  1669. if (Ext.isFunction(xtype)){
  1670. xtype = xtype.xtype; //handle being passed the class, e.g. Ext.Component
  1671. }else if (Ext.isObject(xtype)){
  1672. xtype = xtype.constructor.xtype; //handle being passed an instance
  1673. }
  1674. return !shallow ? ('/' + this.getXTypes() + '/').indexOf('/' + xtype + '/') != -1 : this.constructor.xtype == xtype;
  1675. },
  1676. /**
  1677. * <p>Returns this Component's xtype hierarchy as a slash-delimited string. For a list of all
  1678. * available xtypes, see the {@link Ext.Component} header.</p>
  1679. * <p><b>If using your own subclasses, be aware that a Component must register its own xtype
  1680. * to participate in determination of inherited xtypes.</b></p>
  1681. * <p>Example usage:</p>
  1682. * <pre><code>
  1683. var t = new Ext.form.TextField();
  1684. alert(t.getXTypes()); // alerts 'component/box/field/textfield'
  1685. </code></pre>
  1686. * @return {String} The xtype hierarchy string
  1687. */
  1688. getXTypes : function(){
  1689. var tc = this.constructor;
  1690. if(!tc.xtypes){
  1691. var c = [], sc = this;
  1692. while(sc && sc.constructor.xtype){
  1693. c.unshift(sc.constructor.xtype);
  1694. sc = sc.constructor.superclass;
  1695. }
  1696. tc.xtypeChain = c;
  1697. tc.xtypes = c.join('/');
  1698. }
  1699. return tc.xtypes;
  1700. },
  1701. /**
  1702. * Find a container above this component at any level by a custom function. If the passed function returns
  1703. * true, the container will be returned.
  1704. * @param {Function} fn The custom function to call with the arguments (container, this component).
  1705. * @return {Ext.Container} The first Container for which the custom function returns true
  1706. */
  1707. findParentBy : function(fn) {
  1708. for (var p = this.ownerCt; (p != null) && !fn(p, this); p = p.ownerCt);
  1709. return p || null;
  1710. },
  1711. /**
  1712. * Find a container above this component at any level by xtype or class
  1713. * @param {String/Ext.Component/Class} xtype The xtype to check for this Component. Note that the the component can either be an instance
  1714. * or a component class:
  1715. * @param {Boolean} shallow (optional) False to check whether this Component is descended from the xtype (this is
  1716. * the default), or true to check whether this Component is directly of the specified xtype.
  1717. * @return {Ext.Container} The first Container which matches the given xtype or class
  1718. */
  1719. findParentByType : function(xtype, shallow){
  1720. return this.findParentBy(function(c){
  1721. return c.isXType(xtype, shallow);
  1722. });
  1723. },
  1724. /**
  1725. * Bubbles up the component/container heirarchy, calling the specified function with each component. The scope (<i>this</i>) of
  1726. * function call will be the scope provided or the current component. The arguments to the function
  1727. * will be the args provided or the current component. If the function returns false at any point,
  1728. * the bubble is stopped.
  1729. * @param {Function} fn The function to call
  1730. * @param {Object} scope (optional) The scope of the function (defaults to current node)
  1731. * @param {Array} args (optional) The args to call the function with (default to passing the current component)
  1732. * @return {Ext.Component} this
  1733. */
  1734. bubble : function(fn, scope, args){
  1735. var p = this;
  1736. while(p){
  1737. if(fn.apply(scope || p, args || [p]) === false){
  1738. break;
  1739. }
  1740. p = p.ownerCt;
  1741. }
  1742. return this;
  1743. },
  1744. // protected
  1745. getPositionEl : function(){
  1746. return this.positionEl || this.el;
  1747. },
  1748. // private
  1749. purgeListeners : function(){
  1750. Ext.Component.superclass.purgeListeners.call(this);
  1751. if(this.mons){
  1752. this.on('beforedestroy', this.clearMons, this, {single: true});
  1753. }
  1754. },
  1755. // private
  1756. clearMons : function(){
  1757. Ext.each(this.mons, function(m){
  1758. m.item.un(m.ename, m.fn, m.scope);
  1759. }, this);
  1760. this.mons = [];
  1761. },
  1762. // private
  1763. createMons: function(){
  1764. if(!this.mons){
  1765. this.mons = [];
  1766. this.on('beforedestroy', this.clearMons, this, {single: true});
  1767. }
  1768. },
  1769. /**
  1770. * <p>Adds listeners to any Observable object (or Elements) which are automatically removed when this Component
  1771. * is destroyed. Usage:</p><code><pre>
  1772. myGridPanel.mon(myGridPanel.getSelectionModel(), 'selectionchange', handleSelectionChange, null, {buffer: 50});
  1773. </pre></code>
  1774. * <p>or:</p><code><pre>
  1775. myGridPanel.mon(myGridPanel.getSelectionModel(), {
  1776. selectionchange: handleSelectionChange,
  1777. buffer: 50
  1778. });
  1779. </pre></code>
  1780. * @param {Observable|Element} item The item to which to add a listener/listeners.
  1781. * @param {Object|String} ename The event name, or an object containing event name properties.
  1782. * @param {Function} fn Optional. If the <code>ename</code> parameter was an event name, this
  1783. * is the handler function.
  1784. * @param {Object} scope Optional. If the <code>ename</code> parameter was an event name, this
  1785. * is the scope (<code>this</code> reference) in which the handler function is executed.
  1786. * @param {Object} opt Optional. If the <code>ename</code> parameter was an event name, this
  1787. * is the {@link Ext.util.Observable#addListener addListener} options.
  1788. */
  1789. mon : function(item, ename, fn, scope, opt){
  1790. this.createMons();
  1791. if(Ext.isObject(ename)){
  1792. var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
  1793. var o = ename;
  1794. for(var e in o){
  1795. if(propRe.test(e)){
  1796. continue;
  1797. }
  1798. if(Ext.isFunction(o[e])){
  1799. // shared options
  1800. this.mons.push({
  1801. item: item, ename: e, fn: o[e], scope: o.scope
  1802. });
  1803. item.on(e, o[e], o.scope, o);
  1804. }else{
  1805. // individual options
  1806. this.mons.push({
  1807. item: item, ename: e, fn: o[e], scope: o.scope
  1808. });
  1809. item.on(e, o[e]);
  1810. }
  1811. }
  1812. return;
  1813. }
  1814. this.mons.push({
  1815. item: item, ename: ename, fn: fn, scope: scope
  1816. });
  1817. item.on(ename, fn, scope, opt);
  1818. },
  1819. /**
  1820. * Removes listeners that were added by the {@link #mon} method.
  1821. * @param {Observable|Element} item The item from which to remove a listener/listeners.
  1822. * @param {Object|String} ename The event name, or an object containing event name properties.
  1823. * @param {Function} fn Optional. If the <code>ename</code> parameter was an event name, this
  1824. * is the handler function.
  1825. * @param {Object} scope Optional. If the <code>ename</code> parameter was an event name, this
  1826. * is the scope (<code>this</code> reference) in which the handler function is executed.
  1827. */
  1828. mun : function(item, ename, fn, scope){
  1829. var found, mon;
  1830. this.createMons();
  1831. for(var i = 0, len = this.mons.length; i < len; ++i){
  1832. mon = this.mons[i];
  1833. if(item === mon.item && ename == mon.ename && fn === mon.fn && scope === mon.scope){
  1834. this.mons.splice(i, 1);
  1835. item.un(ename, fn, scope);
  1836. found = true;
  1837. break;
  1838. }
  1839. }
  1840. return found;
  1841. },
  1842. /**
  1843. * Returns the next component in the owning container
  1844. * @return Ext.Component
  1845. */
  1846. nextSibling : function(){
  1847. if(this.ownerCt){
  1848. var index = this.ownerCt.items.indexOf(this);
  1849. if(index != -1 && index+1 < this.ownerCt.items.getCount()){
  1850. return this.ownerCt.items.itemAt(index+1);
  1851. }
  1852. }
  1853. return null;
  1854. },
  1855. /**
  1856. * Returns the previous component in the owning container
  1857. * @return Ext.Component
  1858. */
  1859. previousSibling : function(){
  1860. if(this.ownerCt){
  1861. var index = this.ownerCt.items.indexOf(this);
  1862. if(index > 0){
  1863. return this.ownerCt.items.itemAt(index-1);
  1864. }
  1865. }
  1866. return null;
  1867. },
  1868. /**
  1869. * Provides the link for Observable's fireEvent method to bubble up the ownership hierarchy.
  1870. * @return {Ext.Container} the Container which owns this Component.
  1871. */
  1872. getBubbleTarget : function(){
  1873. return this.ownerCt;
  1874. }
  1875. });
  1876. Ext.reg('component', Ext.Component);
  1877. /**
  1878. * @class Ext.Action
  1879. * <p>An Action is a piece of reusable functionality that can be abstracted out of any particular component so that it
  1880. * can be usefully shared among multiple components. Actions let you share handlers, configuration options and UI
  1881. * updates across any components that support the Action interface (primarily {@link Ext.Toolbar}, {@link Ext.Button}
  1882. * and {@link Ext.menu.Menu} components).</p>
  1883. * <p>Aside from supporting the config object interface, any component that needs to use Actions must also support
  1884. * the following method list, as these will be called as needed by the Action class: setText(string), setIconCls(string),
  1885. * setDisabled(boolean), setVisible(boolean) and setHandler(function).</p>
  1886. * Example usage:<br>
  1887. * <pre><code>
  1888. // Define the shared action. Each component below will have the same
  1889. // display text and icon, and will display the same message on click.
  1890. var action = new Ext.Action({
  1891. {@link #text}: 'Do something',
  1892. {@link #handler}: function(){
  1893. Ext.Msg.alert('Click', 'You did something.');
  1894. },
  1895. {@link #iconCls}: 'do-something',
  1896. {@link #itemId}: 'myAction'
  1897. });
  1898. var panel = new Ext.Panel({
  1899. title: 'Actions',
  1900. width: 500,
  1901. height: 300,
  1902. tbar: [
  1903. // Add the action directly to a toolbar as a menu button
  1904. action,
  1905. {
  1906. text: 'Action Menu',
  1907. // Add the action to a menu as a text item
  1908. menu: [action]
  1909. }
  1910. ],
  1911. items: [
  1912. // Add the action to the panel body as a standard button
  1913. new Ext.Button(action)
  1914. ],
  1915. renderTo: Ext.getBody()
  1916. });
  1917. // Change the text for all components using the action
  1918. action.setText('Something else');
  1919. // Reference an action through a container using the itemId
  1920. var btn = panel.getComponent('myAction');
  1921. var aRef = btn.baseAction;
  1922. aRef.setText('New text');
  1923. </code></pre>
  1924. * @constructor
  1925. * @param {Object} config The configuration options
  1926. */
  1927. Ext.Action = Ext.extend(Object, {
  1928. /**
  1929. * @cfg {String} text The text to set for all components using this action (defaults to '').
  1930. */
  1931. /**
  1932. * @cfg {String} iconCls
  1933. * The CSS class selector that specifies a background image to be used as the header icon for
  1934. * all components using this action (defaults to '').
  1935. * <p>An example of specifying a custom icon class would be something like:
  1936. * </p><pre><code>
  1937. // specify the property in the config for the class:
  1938. ...
  1939. iconCls: 'do-something'
  1940. // css class that specifies background image to be used as the icon image:
  1941. .do-something { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }
  1942. </code></pre>
  1943. */
  1944. /**
  1945. * @cfg {Boolean} disabled True to disable all components using this action, false to enable them (defaults to false).
  1946. */
  1947. /**
  1948. * @cfg {Boolean} hidden True to hide all components using this action, false to show them (defaults to false).
  1949. */
  1950. /**
  1951. * @cfg {Function} handler The function that will be invoked by each component tied to this action
  1952. * when the component's primary event is triggered (defaults to undefined).
  1953. */
  1954. /**
  1955. * @cfg {String} itemId
  1956. * See {@link Ext.Component}.{@link Ext.Component#itemId itemId}.
  1957. */
  1958. /**
  1959. * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
  1960. * <code>{@link #handler}</code> is executed. Defaults to this Button.
  1961. */
  1962. constructor : function(config){
  1963. this.initialConfig = config;
  1964. this.itemId = config.itemId = (config.itemId || config.id || Ext.id());
  1965. this.items = [];
  1966. },
  1967. // private
  1968. isAction : true,
  1969. /**
  1970. * Sets the text to be displayed by all components using this action.
  1971. * @param {String} text The text to display
  1972. */
  1973. setText : function(text){
  1974. this.initialConfig.text = text;
  1975. this.callEach('setText', [text]);
  1976. },
  1977. /**
  1978. * Gets the text currently displayed by all components using this action.
  1979. */
  1980. getText : function(){
  1981. return this.initialConfig.text;
  1982. },
  1983. /**
  1984. * Sets the icon CSS class for all components using this action. The class should supply
  1985. * a background image that will be used as the icon image.
  1986. * @param {String} cls The CSS class supplying the icon image
  1987. */
  1988. setIconClass : function(cls){
  1989. this.initialConfig.iconCls = cls;
  1990. this.callEach('setIconClass', [cls]);
  1991. },
  1992. /**
  1993. * Gets the icon CSS class currently used by all components using this action.
  1994. */
  1995. getIconClass : function(){
  1996. return this.initialConfig.iconCls;
  1997. },
  1998. /**
  1999. * Sets the disabled state of all components using this action. Shortcut method
  2000. * for {@link #enable} and {@link #disable}.
  2001. * @param {Boolean} disabled True to disable the component, false to enable it
  2002. */
  2003. setDisabled : function(v){
  2004. this.initialConfig.disabled = v;
  2005. this.callEach('setDisabled', [v]);
  2006. },
  2007. /**
  2008. * Enables all components using this action.
  2009. */
  2010. enable : function(){
  2011. this.setDisabled(false);
  2012. },
  2013. /**
  2014. * Disables all components using this action.
  2015. */
  2016. disable : function(){
  2017. this.setDisabled(true);
  2018. },
  2019. /**
  2020. * Returns true if the components using this action are currently disabled, else returns false.
  2021. */
  2022. isDisabled : function(){
  2023. return this.initialConfig.disabled;
  2024. },
  2025. /**
  2026. * Sets the hidden state of all components using this action. Shortcut method
  2027. * for <code>{@link #hide}</code> and <code>{@link #show}</code>.
  2028. * @param {Boolean} hidden True to hide the component, false to show it
  2029. */
  2030. setHidden : function(v){
  2031. this.initialConfig.hidden = v;
  2032. this.callEach('setVisible', [!v]);
  2033. },
  2034. /**
  2035. * Shows all components using this action.
  2036. */
  2037. show : function(){
  2038. this.setHidden(false);
  2039. },
  2040. /**
  2041. * Hides all components using this action.
  2042. */
  2043. hide : function(){
  2044. this.setHidden(true);
  2045. },
  2046. /**
  2047. * Returns true if the components using this action are currently hidden, else returns false.
  2048. */
  2049. isHidden : function(){
  2050. return this.initialConfig.hidden;
  2051. },
  2052. /**
  2053. * Sets the function that will be called by each Component using this action when its primary event is triggered.
  2054. * @param {Function} fn The function that will be invoked by the action's components. The function
  2055. * will be called with no arguments.
  2056. * @param {Object} scope The scope (<code>this</code> reference) in which the function is executed. Defaults to the Component firing the event.
  2057. */
  2058. setHandler : function(fn, scope){
  2059. this.initialConfig.handler = fn;
  2060. this.initialConfig.scope = scope;
  2061. this.callEach('setHandler', [fn, scope]);
  2062. },
  2063. /**
  2064. * Executes the specified function once for each Component currently tied to this action. The function passed
  2065. * in should accept a single argument that will be an object that supports the basic Action config/method interface.
  2066. * @param {Function} fn The function to execute for each component
  2067. * @param {Object} scope The scope (<code>this</code> reference) in which the function is executed. Defaults to the Component.
  2068. */
  2069. each : function(fn, scope){
  2070. Ext.each(this.items, fn, scope);
  2071. },
  2072. // private
  2073. callEach : function(fnName, args){
  2074. var cs = this.items;
  2075. for(var i = 0, len = cs.length; i < len; i++){
  2076. cs[i][fnName].apply(cs[i], args);
  2077. }
  2078. },
  2079. // private
  2080. addComponent : function(comp){
  2081. this.items.push(comp);
  2082. comp.on('destroy', this.removeComponent, this);
  2083. },
  2084. // private
  2085. removeComponent : function(comp){
  2086. this.items.remove(comp);
  2087. },
  2088. /**
  2089. * Executes this action manually using the handler function specified in the original config object
  2090. * or the handler function set with <code>{@link #setHandler}</code>. Any arguments passed to this
  2091. * function will be passed on to the handler function.
  2092. * @param {Mixed} arg1 (optional) Variable number of arguments passed to the handler function
  2093. * @param {Mixed} arg2 (optional)
  2094. * @param {Mixed} etc... (optional)
  2095. */
  2096. execute : function(){
  2097. this.initialConfig.handler.apply(this.initialConfig.scope || window, arguments);
  2098. }
  2099. });
  2100. /**
  2101. * @class Ext.Layer
  2102. * @extends Ext.Element
  2103. * An extended {@link Ext.Element} object that supports a shadow and shim, constrain to viewport and
  2104. * automatic maintaining of shadow/shim positions.
  2105. * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
  2106. * @cfg {String/Boolean} shadow True to automatically create an {@link Ext.Shadow}, or a string indicating the
  2107. * shadow's display {@link Ext.Shadow#mode}. False to disable the shadow. (defaults to false)
  2108. * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: 'div', cls: 'x-layer'}).
  2109. * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
  2110. * @cfg {String} cls CSS class to add to the element
  2111. * @cfg {Number} zindex Starting z-index (defaults to 11000)
  2112. * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 4)
  2113. * @cfg {Boolean} useDisplay
  2114. * Defaults to use css offsets to hide the Layer. Specify <tt>true</tt>
  2115. * to use css style <tt>'display:none;'</tt> to hide the Layer.
  2116. * @constructor
  2117. * @param {Object} config An object with config options.
  2118. * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
  2119. */
  2120. (function(){
  2121. Ext.Layer = function(config, existingEl){
  2122. config = config || {};
  2123. var dh = Ext.DomHelper,
  2124. cp = config.parentEl, pel = cp ? Ext.getDom(cp) : document.body;
  2125. if (existingEl) {
  2126. this.dom = Ext.getDom(existingEl);
  2127. }
  2128. if(!this.dom){
  2129. var o = config.dh || {tag: 'div', cls: 'x-layer'};
  2130. this.dom = dh.append(pel, o);
  2131. }
  2132. if(config.cls){
  2133. this.addClass(config.cls);
  2134. }
  2135. this.constrain = config.constrain !== false;
  2136. this.setVisibilityMode(Ext.Element.VISIBILITY);
  2137. if(config.id){
  2138. this.id = this.dom.id = config.id;
  2139. }else{
  2140. this.id = Ext.id(this.dom);
  2141. }
  2142. this.zindex = config.zindex || this.getZIndex();
  2143. this.position('absolute', this.zindex);
  2144. if(config.shadow){
  2145. this.shadowOffset = config.shadowOffset || 4;
  2146. this.shadow = new Ext.Shadow({
  2147. offset : this.shadowOffset,
  2148. mode : config.shadow
  2149. });
  2150. }else{
  2151. this.shadowOffset = 0;
  2152. }
  2153. this.useShim = config.shim !== false && Ext.useShims;
  2154. this.useDisplay = config.useDisplay;
  2155. this.hide();
  2156. };
  2157. var supr = Ext.Element.prototype;
  2158. // shims are shared among layer to keep from having 100 iframes
  2159. var shims = [];
  2160. Ext.extend(Ext.Layer, Ext.Element, {
  2161. getZIndex : function(){
  2162. return this.zindex || parseInt((this.getShim() || this).getStyle('z-index'), 10) || 11000;
  2163. },
  2164. getShim : function(){
  2165. if(!this.useShim){
  2166. return null;
  2167. }
  2168. if(this.shim){
  2169. return this.shim;
  2170. }
  2171. var shim = shims.shift();
  2172. if(!shim){
  2173. shim = this.createShim();
  2174. shim.enableDisplayMode('block');
  2175. shim.dom.style.display = 'none';
  2176. shim.dom.style.visibility = 'visible';
  2177. }
  2178. var pn = this.dom.parentNode;
  2179. if(shim.dom.parentNode != pn){
  2180. pn.insertBefore(shim.dom, this.dom);
  2181. }
  2182. shim.setStyle('z-index', this.getZIndex()-2);
  2183. this.shim = shim;
  2184. return shim;
  2185. },
  2186. hideShim : function(){
  2187. if(this.shim){
  2188. this.shim.setDisplayed(false);
  2189. shims.push(this.shim);
  2190. delete this.shim;
  2191. }
  2192. },
  2193. disableShadow : function(){
  2194. if(this.shadow){
  2195. this.shadowDisabled = true;
  2196. this.shadow.hide();
  2197. this.lastShadowOffset = this.shadowOffset;
  2198. this.shadowOffset = 0;
  2199. }
  2200. },
  2201. enableShadow : function(show){
  2202. if(this.shadow){
  2203. this.shadowDisabled = false;
  2204. this.shadowOffset = this.lastShadowOffset;
  2205. delete this.lastShadowOffset;
  2206. if(show){
  2207. this.sync(true);
  2208. }
  2209. }
  2210. },
  2211. // private
  2212. // this code can execute repeatedly in milliseconds (i.e. during a drag) so
  2213. // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
  2214. sync : function(doShow){
  2215. var shadow = this.shadow;
  2216. if(!this.updating && this.isVisible() && (shadow || this.useShim)){
  2217. var shim = this.getShim(),
  2218. w = this.getWidth(),
  2219. h = this.getHeight(),
  2220. l = this.getLeft(true),
  2221. t = this.getTop(true);
  2222. if(shadow && !this.shadowDisabled){
  2223. if(doShow && !shadow.isVisible()){
  2224. shadow.show(this);
  2225. }else{
  2226. shadow.realign(l, t, w, h);
  2227. }
  2228. if(shim){
  2229. if(doShow){
  2230. shim.show();
  2231. }
  2232. // fit the shim behind the shadow, so it is shimmed too
  2233. var shadowAdj = shadow.el.getXY(), shimStyle = shim.dom.style,
  2234. shadowSize = shadow.el.getSize();
  2235. shimStyle.left = (shadowAdj[0])+'px';
  2236. shimStyle.top = (shadowAdj[1])+'px';
  2237. shimStyle.width = (shadowSize.width)+'px';
  2238. shimStyle.height = (shadowSize.height)+'px';
  2239. }
  2240. }else if(shim){
  2241. if(doShow){
  2242. shim.show();
  2243. }
  2244. shim.setSize(w, h);
  2245. shim.setLeftTop(l, t);
  2246. }
  2247. }
  2248. },
  2249. // private
  2250. destroy : function(){
  2251. this.hideShim();
  2252. if(this.shadow){
  2253. this.shadow.hide();
  2254. }
  2255. this.removeAllListeners();
  2256. Ext.removeNode(this.dom);
  2257. delete this.dom;
  2258. },
  2259. remove : function(){
  2260. this.destroy();
  2261. },
  2262. // private
  2263. beginUpdate : function(){
  2264. this.updating = true;
  2265. },
  2266. // private
  2267. endUpdate : function(){
  2268. this.updating = false;
  2269. this.sync(true);
  2270. },
  2271. // private
  2272. hideUnders : function(negOffset){
  2273. if(this.shadow){
  2274. this.shadow.hide();
  2275. }
  2276. this.hideShim();
  2277. },
  2278. // private
  2279. constrainXY : function(){
  2280. if(this.constrain){
  2281. var vw = Ext.lib.Dom.getViewWidth(),
  2282. vh = Ext.lib.Dom.getViewHeight();
  2283. var s = Ext.getDoc().getScroll();
  2284. var xy = this.getXY();
  2285. var x = xy[0], y = xy[1];
  2286. var so = this.shadowOffset;
  2287. var w = this.dom.offsetWidth+so, h = this.dom.offsetHeight+so;
  2288. // only move it if it needs it
  2289. var moved = false;
  2290. // first validate right/bottom
  2291. if((x + w) > vw+s.left){
  2292. x = vw - w - so;
  2293. moved = true;
  2294. }
  2295. if((y + h) > vh+s.top){
  2296. y = vh - h - so;
  2297. moved = true;
  2298. }
  2299. // then make sure top/left isn't negative
  2300. if(x < s.left){
  2301. x = s.left;
  2302. moved = true;
  2303. }
  2304. if(y < s.top){
  2305. y = s.top;
  2306. moved = true;
  2307. }
  2308. if(moved){
  2309. if(this.avoidY){
  2310. var ay = this.avoidY;
  2311. if(y <= ay && (y+h) >= ay){
  2312. y = ay-h-5;
  2313. }
  2314. }
  2315. xy = [x, y];
  2316. this.storeXY(xy);
  2317. supr.setXY.call(this, xy);
  2318. this.sync();
  2319. }
  2320. }
  2321. return this;
  2322. },
  2323. getConstrainOffset : function(){
  2324. return this.shadowOffset;
  2325. },
  2326. isVisible : function(){
  2327. return this.visible;
  2328. },
  2329. // private
  2330. showAction : function(){
  2331. this.visible = true; // track visibility to prevent getStyle calls
  2332. if(this.useDisplay === true){
  2333. this.setDisplayed('');
  2334. }else if(this.lastXY){
  2335. supr.setXY.call(this, this.lastXY);
  2336. }else if(this.lastLT){
  2337. supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
  2338. }
  2339. },
  2340. // private
  2341. hideAction : function(){
  2342. this.visible = false;
  2343. if(this.useDisplay === true){
  2344. this.setDisplayed(false);
  2345. }else{
  2346. this.setLeftTop(-10000,-10000);
  2347. }
  2348. },
  2349. // overridden Element method
  2350. setVisible : function(v, a, d, c, e){
  2351. if(v){
  2352. this.showAction();
  2353. }
  2354. if(a && v){
  2355. var cb = function(){
  2356. this.sync(true);
  2357. if(c){
  2358. c();
  2359. }
  2360. }.createDelegate(this);
  2361. supr.setVisible.call(this, true, true, d, cb, e);
  2362. }else{
  2363. if(!v){
  2364. this.hideUnders(true);
  2365. }
  2366. var cb = c;
  2367. if(a){
  2368. cb = function(){
  2369. this.hideAction();
  2370. if(c){
  2371. c();
  2372. }
  2373. }.createDelegate(this);
  2374. }
  2375. supr.setVisible.call(this, v, a, d, cb, e);
  2376. if(v){
  2377. this.sync(true);
  2378. }else if(!a){
  2379. this.hideAction();
  2380. }
  2381. }
  2382. return this;
  2383. },
  2384. storeXY : function(xy){
  2385. delete this.lastLT;
  2386. this.lastXY = xy;
  2387. },
  2388. storeLeftTop : function(left, top){
  2389. delete this.lastXY;
  2390. this.lastLT = [left, top];
  2391. },
  2392. // private
  2393. beforeFx : function(){
  2394. this.beforeAction();
  2395. return Ext.Layer.superclass.beforeFx.apply(this, arguments);
  2396. },
  2397. // private
  2398. afterFx : function(){
  2399. Ext.Layer.superclass.afterFx.apply(this, arguments);
  2400. this.sync(this.isVisible());
  2401. },
  2402. // private
  2403. beforeAction : function(){
  2404. if(!this.updating && this.shadow){
  2405. this.shadow.hide();
  2406. }
  2407. },
  2408. // overridden Element method
  2409. setLeft : function(left){
  2410. this.storeLeftTop(left, this.getTop(true));
  2411. supr.setLeft.apply(this, arguments);
  2412. this.sync();
  2413. return this;
  2414. },
  2415. setTop : function(top){
  2416. this.storeLeftTop(this.getLeft(true), top);
  2417. supr.setTop.apply(this, arguments);
  2418. this.sync();
  2419. return this;
  2420. },
  2421. setLeftTop : function(left, top){
  2422. this.storeLeftTop(left, top);
  2423. supr.setLeftTop.apply(this, arguments);
  2424. this.sync();
  2425. return this;
  2426. },
  2427. setXY : function(xy, a, d, c, e){
  2428. this.fixDisplay();
  2429. this.beforeAction();
  2430. this.storeXY(xy);
  2431. var cb = this.createCB(c);
  2432. supr.setXY.call(this, xy, a, d, cb, e);
  2433. if(!a){
  2434. cb();
  2435. }
  2436. return this;
  2437. },
  2438. // private
  2439. createCB : function(c){
  2440. var el = this;
  2441. return function(){
  2442. el.constrainXY();
  2443. el.sync(true);
  2444. if(c){
  2445. c();
  2446. }
  2447. };
  2448. },
  2449. // overridden Element method
  2450. setX : function(x, a, d, c, e){
  2451. this.setXY([x, this.getY()], a, d, c, e);
  2452. return this;
  2453. },
  2454. // overridden Element method
  2455. setY : function(y, a, d, c, e){
  2456. this.setXY([this.getX(), y], a, d, c, e);
  2457. return this;
  2458. },
  2459. // overridden Element method
  2460. setSize : function(w, h, a, d, c, e){
  2461. this.beforeAction();
  2462. var cb = this.createCB(c);
  2463. supr.setSize.call(this, w, h, a, d, cb, e);
  2464. if(!a){
  2465. cb();
  2466. }
  2467. return this;
  2468. },
  2469. // overridden Element method
  2470. setWidth : function(w, a, d, c, e){
  2471. this.beforeAction();
  2472. var cb = this.createCB(c);
  2473. supr.setWidth.call(this, w, a, d, cb, e);
  2474. if(!a){
  2475. cb();
  2476. }
  2477. return this;
  2478. },
  2479. // overridden Element method
  2480. setHeight : function(h, a, d, c, e){
  2481. this.beforeAction();
  2482. var cb = this.createCB(c);
  2483. supr.setHeight.call(this, h, a, d, cb, e);
  2484. if(!a){
  2485. cb();
  2486. }
  2487. return this;
  2488. },
  2489. // overridden Element method
  2490. setBounds : function(x, y, w, h, a, d, c, e){
  2491. this.beforeAction();
  2492. var cb = this.createCB(c);
  2493. if(!a){
  2494. this.storeXY([x, y]);
  2495. supr.setXY.call(this, [x, y]);
  2496. supr.setSize.call(this, w, h, a, d, cb, e);
  2497. cb();
  2498. }else{
  2499. supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
  2500. }
  2501. return this;
  2502. },
  2503. /**
  2504. * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
  2505. * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
  2506. * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
  2507. * @param {Number} zindex The new z-index to set
  2508. * @return {this} The Layer
  2509. */
  2510. setZIndex : function(zindex){
  2511. this.zindex = zindex;
  2512. this.setStyle('z-index', zindex + 2);
  2513. if(this.shadow){
  2514. this.shadow.setZIndex(zindex + 1);
  2515. }
  2516. if(this.shim){
  2517. this.shim.setStyle('z-index', zindex);
  2518. }
  2519. return this;
  2520. }
  2521. });
  2522. })();
  2523. /**
  2524. * @class Ext.Shadow
  2525. * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
  2526. * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
  2527. * functionality that can also provide the same shadow effect, see the {@link Ext.Layer} class.
  2528. * @constructor
  2529. * Create a new Shadow
  2530. * @param {Object} config The config object
  2531. */
  2532. Ext.Shadow = function(config) {
  2533. Ext.apply(this, config);
  2534. if (typeof this.mode != "string") {
  2535. this.mode = this.defaultMode;
  2536. }
  2537. var o = this.offset,
  2538. a = {
  2539. h: 0
  2540. },
  2541. rad = Math.floor(this.offset / 2);
  2542. switch (this.mode.toLowerCase()) {
  2543. // all this hideous nonsense calculates the various offsets for shadows
  2544. case "drop":
  2545. a.w = 0;
  2546. a.l = a.t = o;
  2547. a.t -= 1;
  2548. if (Ext.isIE) {
  2549. a.l -= this.offset + rad;
  2550. a.t -= this.offset + rad;
  2551. a.w -= rad;
  2552. a.h -= rad;
  2553. a.t += 1;
  2554. }
  2555. break;
  2556. case "sides":
  2557. a.w = (o * 2);
  2558. a.l = -o;
  2559. a.t = o - 1;
  2560. if (Ext.isIE) {
  2561. a.l -= (this.offset - rad);
  2562. a.t -= this.offset + rad;
  2563. a.l += 1;
  2564. a.w -= (this.offset - rad) * 2;
  2565. a.w -= rad + 1;
  2566. a.h -= 1;
  2567. }
  2568. break;
  2569. case "frame":
  2570. a.w = a.h = (o * 2);
  2571. a.l = a.t = -o;
  2572. a.t += 1;
  2573. a.h -= 2;
  2574. if (Ext.isIE) {
  2575. a.l -= (this.offset - rad);
  2576. a.t -= (this.offset - rad);
  2577. a.l += 1;
  2578. a.w -= (this.offset + rad + 1);
  2579. a.h -= (this.offset + rad);
  2580. a.h += 1;
  2581. }
  2582. break;
  2583. };
  2584. this.adjusts = a;
  2585. };
  2586. Ext.Shadow.prototype = {
  2587. /**
  2588. * @cfg {String} mode
  2589. * The shadow display mode. Supports the following options:<div class="mdetail-params"><ul>
  2590. * <li><b><tt>sides</tt></b> : Shadow displays on both sides and bottom only</li>
  2591. * <li><b><tt>frame</tt></b> : Shadow displays equally on all four sides</li>
  2592. * <li><b><tt>drop</tt></b> : Traditional bottom-right drop shadow</li>
  2593. * </ul></div>
  2594. */
  2595. /**
  2596. * @cfg {String} offset
  2597. * The number of pixels to offset the shadow from the element (defaults to <tt>4</tt>)
  2598. */
  2599. offset: 4,
  2600. // private
  2601. defaultMode: "drop",
  2602. /**
  2603. * Displays the shadow under the target element
  2604. * @param {Mixed} targetEl The id or element under which the shadow should display
  2605. */
  2606. show: function(target) {
  2607. target = Ext.get(target);
  2608. if (!this.el) {
  2609. this.el = Ext.Shadow.Pool.pull();
  2610. if (this.el.dom.nextSibling != target.dom) {
  2611. this.el.insertBefore(target);
  2612. }
  2613. }
  2614. this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10) - 1);
  2615. if (Ext.isIE) {
  2616. this.el.dom.style.filter = "progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=" + (this.offset) + ")";
  2617. }
  2618. this.realign(
  2619. target.getLeft(true),
  2620. target.getTop(true),
  2621. target.getWidth(),
  2622. target.getHeight()
  2623. );
  2624. this.el.dom.style.display = "block";
  2625. },
  2626. /**
  2627. * Returns true if the shadow is visible, else false
  2628. */
  2629. isVisible: function() {
  2630. return this.el ? true: false;
  2631. },
  2632. /**
  2633. * Direct alignment when values are already available. Show must be called at least once before
  2634. * calling this method to ensure it is initialized.
  2635. * @param {Number} left The target element left position
  2636. * @param {Number} top The target element top position
  2637. * @param {Number} width The target element width
  2638. * @param {Number} height The target element height
  2639. */
  2640. realign: function(l, t, w, h) {
  2641. if (!this.el) {
  2642. return;
  2643. }
  2644. var a = this.adjusts,
  2645. d = this.el.dom,
  2646. s = d.style,
  2647. iea = 0,
  2648. sw = (w + a.w),
  2649. sh = (h + a.h),
  2650. sws = sw + "px",
  2651. shs = sh + "px",
  2652. cn,
  2653. sww;
  2654. s.left = (l + a.l) + "px";
  2655. s.top = (t + a.t) + "px";
  2656. if (s.width != sws || s.height != shs) {
  2657. s.width = sws;
  2658. s.height = shs;
  2659. if (!Ext.isIE) {
  2660. cn = d.childNodes;
  2661. sww = Math.max(0, (sw - 12)) + "px";
  2662. cn[0].childNodes[1].style.width = sww;
  2663. cn[1].childNodes[1].style.width = sww;
  2664. cn[2].childNodes[1].style.width = sww;
  2665. cn[1].style.height = Math.max(0, (sh - 12)) + "px";
  2666. }
  2667. }
  2668. },
  2669. /**
  2670. * Hides this shadow
  2671. */
  2672. hide: function() {
  2673. if (this.el) {
  2674. this.el.dom.style.display = "none";
  2675. Ext.Shadow.Pool.push(this.el);
  2676. delete this.el;
  2677. }
  2678. },
  2679. /**
  2680. * Adjust the z-index of this shadow
  2681. * @param {Number} zindex The new z-index
  2682. */
  2683. setZIndex: function(z) {
  2684. this.zIndex = z;
  2685. if (this.el) {
  2686. this.el.setStyle("z-index", z);
  2687. }
  2688. }
  2689. };
  2690. // Private utility class that manages the internal Shadow cache
  2691. Ext.Shadow.Pool = function() {
  2692. var p = [],
  2693. markup = Ext.isIE ?
  2694. '<div class="x-ie-shadow"></div>':
  2695. '<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>';
  2696. return {
  2697. pull: function() {
  2698. var sh = p.shift();
  2699. if (!sh) {
  2700. sh = Ext.get(Ext.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
  2701. sh.autoBoxAdjust = false;
  2702. }
  2703. return sh;
  2704. },
  2705. push: function(sh) {
  2706. p.push(sh);
  2707. }
  2708. };
  2709. }();/**
  2710. * @class Ext.BoxComponent
  2711. * @extends Ext.Component
  2712. * <p>Base class for any {@link Ext.Component Component} that is to be sized as a box, using width and height.</p>
  2713. * <p>BoxComponent provides automatic box model adjustments for sizing and positioning and will work correctly
  2714. * within the Component rendering model.</p>
  2715. * <p>A BoxComponent may be created as a custom Component which encapsulates any HTML element, either a pre-existing
  2716. * element, or one that is created to your specifications at render time. Usually, to participate in layouts,
  2717. * a Component will need to be a <b>Box</b>Component in order to have its width and height managed.</p>
  2718. * <p>To use a pre-existing element as a BoxComponent, configure it so that you preset the <b>el</b> property to the
  2719. * element to reference:<pre><code>
  2720. var pageHeader = new Ext.BoxComponent({
  2721. el: 'my-header-div'
  2722. });</code></pre>
  2723. * This may then be {@link Ext.Container#add added} to a {@link Ext.Container Container} as a child item.</p>
  2724. * <p>To create a BoxComponent based around a HTML element to be created at render time, use the
  2725. * {@link Ext.Component#autoEl autoEl} config option which takes the form of a
  2726. * {@link Ext.DomHelper DomHelper} specification:<pre><code>
  2727. var myImage = new Ext.BoxComponent({
  2728. autoEl: {
  2729. tag: 'img',
  2730. src: '/images/my-image.jpg'
  2731. }
  2732. });</code></pre></p>
  2733. * @constructor
  2734. * @param {Ext.Element/String/Object} config The configuration options.
  2735. * @xtype box
  2736. */
  2737. Ext.BoxComponent = Ext.extend(Ext.Component, {
  2738. // Configs below are used for all Components when rendered by BoxLayout.
  2739. /**
  2740. * @cfg {Number} flex
  2741. * <p><b>Note</b>: this config is only used when this Component is rendered
  2742. * by a Container which has been configured to use a <b>{@link Ext.layout.BoxLayout BoxLayout}.</b>
  2743. * Each child Component with a <code>flex</code> property will be flexed either vertically (by a VBoxLayout)
  2744. * or horizontally (by an HBoxLayout) according to the item's <b>relative</b> <code>flex</code> value
  2745. * compared to the sum of all Components with <code>flex</flex> value specified. Any child items that have
  2746. * either a <code>flex = 0</code> or <code>flex = undefined</code> will not be 'flexed' (the initial size will not be changed).
  2747. */
  2748. // Configs below are used for all Components when rendered by AnchorLayout.
  2749. /**
  2750. * @cfg {String} anchor <p><b>Note</b>: this config is only used when this Component is rendered
  2751. * by a Container which has been configured to use an <b>{@link Ext.layout.AnchorLayout AnchorLayout} (or subclass thereof).</b>
  2752. * based layout manager, for example:<div class="mdetail-params"><ul>
  2753. * <li>{@link Ext.form.FormPanel}</li>
  2754. * <li>specifying <code>layout: 'anchor' // or 'form', or 'absolute'</code></li>
  2755. * </ul></div></p>
  2756. * <p>See {@link Ext.layout.AnchorLayout}.{@link Ext.layout.AnchorLayout#anchor anchor} also.</p>
  2757. */
  2758. // tabTip config is used when a BoxComponent is a child of a TabPanel
  2759. /**
  2760. * @cfg {String} tabTip
  2761. * <p><b>Note</b>: this config is only used when this BoxComponent is a child item of a TabPanel.</p>
  2762. * A string to be used as innerHTML (html tags are accepted) to show in a tooltip when mousing over
  2763. * the associated tab selector element. {@link Ext.QuickTips}.init()
  2764. * must be called in order for the tips to render.
  2765. */
  2766. // Configs below are used for all Components when rendered by BorderLayout.
  2767. /**
  2768. * @cfg {String} region <p><b>Note</b>: this config is only used when this BoxComponent is rendered
  2769. * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
  2770. * layout manager (e.g. specifying <tt>layout:'border'</tt>).</p><br>
  2771. * <p>See {@link Ext.layout.BorderLayout} also.</p>
  2772. */
  2773. // margins config is used when a BoxComponent is rendered by BorderLayout or BoxLayout.
  2774. /**
  2775. * @cfg {Object} margins <p><b>Note</b>: this config is only used when this BoxComponent is rendered
  2776. * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
  2777. * or one of the two <b>{@link Ext.layout.BoxLayout BoxLayout} subclasses.</b></p>
  2778. * <p>An object containing margins to apply to this BoxComponent in the
  2779. * format:</p><pre><code>
  2780. {
  2781. top: (top margin),
  2782. right: (right margin),
  2783. bottom: (bottom margin),
  2784. left: (left margin)
  2785. }</code></pre>
  2786. * <p>May also be a string containing space-separated, numeric margin values. The order of the
  2787. * sides associated with each value matches the way CSS processes margin values:</p>
  2788. * <p><div class="mdetail-params"><ul>
  2789. * <li>If there is only one value, it applies to all sides.</li>
  2790. * <li>If there are two values, the top and bottom borders are set to the first value and the
  2791. * right and left are set to the second.</li>
  2792. * <li>If there are three values, the top is set to the first value, the left and right are set
  2793. * to the second, and the bottom is set to the third.</li>
  2794. * <li>If there are four values, they apply to the top, right, bottom, and left, respectively.</li>
  2795. * </ul></div></p>
  2796. * <p>Defaults to:</p><pre><code>
  2797. * {top:0, right:0, bottom:0, left:0}
  2798. * </code></pre>
  2799. */
  2800. /**
  2801. * @cfg {Number} x
  2802. * The local x (left) coordinate for this component if contained within a positioning container.
  2803. */
  2804. /**
  2805. * @cfg {Number} y
  2806. * The local y (top) coordinate for this component if contained within a positioning container.
  2807. */
  2808. /**
  2809. * @cfg {Number} pageX
  2810. * The page level x coordinate for this component if contained within a positioning container.
  2811. */
  2812. /**
  2813. * @cfg {Number} pageY
  2814. * The page level y coordinate for this component if contained within a positioning container.
  2815. */
  2816. /**
  2817. * @cfg {Number} height
  2818. * The height of this component in pixels (defaults to auto).
  2819. * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
  2820. */
  2821. /**
  2822. * @cfg {Number} width
  2823. * The width of this component in pixels (defaults to auto).
  2824. * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
  2825. */
  2826. /**
  2827. * @cfg {Number} boxMinHeight
  2828. * <p>The minimum value in pixels which this BoxComponent will set its height to.</p>
  2829. * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
  2830. */
  2831. /**
  2832. * @cfg {Number} boxMinWidth
  2833. * <p>The minimum value in pixels which this BoxComponent will set its width to.</p>
  2834. * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
  2835. */
  2836. /**
  2837. * @cfg {Number} boxMaxHeight
  2838. * <p>The maximum value in pixels which this BoxComponent will set its height to.</p>
  2839. * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
  2840. */
  2841. /**
  2842. * @cfg {Number} boxMaxWidth
  2843. * <p>The maximum value in pixels which this BoxComponent will set its width to.</p>
  2844. * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
  2845. */
  2846. /**
  2847. * @cfg {Boolean} autoHeight
  2848. * <p>True to use height:'auto', false to use fixed height (or allow it to be managed by its parent
  2849. * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
  2850. * <p><b>Note</b>: Although many components inherit this config option, not all will
  2851. * function as expected with a height of 'auto'. Setting autoHeight:true means that the
  2852. * browser will manage height based on the element's contents, and that Ext will not manage it at all.</p>
  2853. * <p>If the <i>browser</i> is managing the height, be aware that resizes performed by the browser in response
  2854. * to changes within the structure of the Component cannot be detected. Therefore changes to the height might
  2855. * result in elements needing to be synchronized with the new height. Example:</p><pre><code>
  2856. var w = new Ext.Window({
  2857. title: 'Window',
  2858. width: 600,
  2859. autoHeight: true,
  2860. items: {
  2861. title: 'Collapse Me',
  2862. height: 400,
  2863. collapsible: true,
  2864. border: false,
  2865. listeners: {
  2866. beforecollapse: function() {
  2867. w.el.shadow.hide();
  2868. },
  2869. beforeexpand: function() {
  2870. w.el.shadow.hide();
  2871. },
  2872. collapse: function() {
  2873. w.syncShadow();
  2874. },
  2875. expand: function() {
  2876. w.syncShadow();
  2877. }
  2878. }
  2879. }
  2880. }).show();
  2881. </code></pre>
  2882. */
  2883. /**
  2884. * @cfg {Boolean} autoWidth
  2885. * <p>True to use width:'auto', false to use fixed width (or allow it to be managed by its parent
  2886. * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
  2887. * <p><b>Note</b>: Although many components inherit this config option, not all will
  2888. * function as expected with a width of 'auto'. Setting autoWidth:true means that the
  2889. * browser will manage width based on the element's contents, and that Ext will not manage it at all.</p>
  2890. * <p>If the <i>browser</i> is managing the width, be aware that resizes performed by the browser in response
  2891. * to changes within the structure of the Component cannot be detected. Therefore changes to the width might
  2892. * result in elements needing to be synchronized with the new width. For example, where the target element is:</p><pre><code>
  2893. &lt;div id='grid-container' style='margin-left:25%;width:50%'>&lt;/div>
  2894. </code></pre>
  2895. * A Panel rendered into that target element must listen for browser window resize in order to relay its
  2896. * child items when the browser changes its width:<pre><code>
  2897. var myPanel = new Ext.Panel({
  2898. renderTo: 'grid-container',
  2899. monitorResize: true, // relay on browser resize
  2900. title: 'Panel',
  2901. height: 400,
  2902. autoWidth: true,
  2903. layout: 'hbox',
  2904. layoutConfig: {
  2905. align: 'stretch'
  2906. },
  2907. defaults: {
  2908. flex: 1
  2909. },
  2910. items: [{
  2911. title: 'Box 1',
  2912. }, {
  2913. title: 'Box 2'
  2914. }, {
  2915. title: 'Box 3'
  2916. }],
  2917. });
  2918. </code></pre>
  2919. */
  2920. /**
  2921. * @cfg {Boolean} autoScroll
  2922. * <code>true</code> to use overflow:'auto' on the components layout element and show scroll bars automatically when
  2923. * necessary, <code>false</code> to clip any overflowing content (defaults to <code>false</code>).
  2924. */
  2925. /* // private internal config
  2926. * {Boolean} deferHeight
  2927. * True to defer height calculations to an external component, false to allow this component to set its own
  2928. * height (defaults to false).
  2929. */
  2930. // private
  2931. initComponent : function(){
  2932. Ext.BoxComponent.superclass.initComponent.call(this);
  2933. this.addEvents(
  2934. /**
  2935. * @event resize
  2936. * Fires after the component is resized.
  2937. * @param {Ext.Component} this
  2938. * @param {Number} adjWidth The box-adjusted width that was set
  2939. * @param {Number} adjHeight The box-adjusted height that was set
  2940. * @param {Number} rawWidth The width that was originally specified
  2941. * @param {Number} rawHeight The height that was originally specified
  2942. */
  2943. 'resize',
  2944. /**
  2945. * @event move
  2946. * Fires after the component is moved.
  2947. * @param {Ext.Component} this
  2948. * @param {Number} x The new x position
  2949. * @param {Number} y The new y position
  2950. */
  2951. 'move'
  2952. );
  2953. },
  2954. // private, set in afterRender to signify that the component has been rendered
  2955. boxReady : false,
  2956. // private, used to defer height settings to subclasses
  2957. deferHeight: false,
  2958. /**
  2959. * Sets the width and height of this BoxComponent. This method fires the {@link #resize} event. This method can accept
  2960. * either width and height as separate arguments, or you can pass a size object like <code>{width:10, height:20}</code>.
  2961. * @param {Mixed} width The new width to set. This may be one of:<div class="mdetail-params"><ul>
  2962. * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
  2963. * <li>A String used to set the CSS width style.</li>
  2964. * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
  2965. * <li><code>undefined</code> to leave the width unchanged.</li>
  2966. * </ul></div>
  2967. * @param {Mixed} height The new height to set (not required if a size object is passed as the first arg).
  2968. * This may be one of:<div class="mdetail-params"><ul>
  2969. * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
  2970. * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
  2971. * <li><code>undefined</code> to leave the height unchanged.</li>
  2972. * </ul></div>
  2973. * @return {Ext.BoxComponent} this
  2974. */
  2975. setSize : function(w, h){
  2976. // support for standard size objects
  2977. if(typeof w == 'object'){
  2978. h = w.height;
  2979. w = w.width;
  2980. }
  2981. if (Ext.isDefined(w) && Ext.isDefined(this.boxMinWidth) && (w < this.boxMinWidth)) {
  2982. w = this.boxMinWidth;
  2983. }
  2984. if (Ext.isDefined(h) && Ext.isDefined(this.boxMinHeight) && (h < this.boxMinHeight)) {
  2985. h = this.boxMinHeight;
  2986. }
  2987. if (Ext.isDefined(w) && Ext.isDefined(this.boxMaxWidth) && (w > this.boxMaxWidth)) {
  2988. w = this.boxMaxWidth;
  2989. }
  2990. if (Ext.isDefined(h) && Ext.isDefined(this.boxMaxHeight) && (h > this.boxMaxHeight)) {
  2991. h = this.boxMaxHeight;
  2992. }
  2993. // not rendered
  2994. if(!this.boxReady){
  2995. this.width = w;
  2996. this.height = h;
  2997. return this;
  2998. }
  2999. // prevent recalcs when not needed
  3000. if(this.cacheSizes !== false && this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
  3001. return this;
  3002. }
  3003. this.lastSize = {width: w, height: h};
  3004. var adj = this.adjustSize(w, h),
  3005. aw = adj.width,
  3006. ah = adj.height,
  3007. rz;
  3008. if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
  3009. rz = this.getResizeEl();
  3010. if(!this.deferHeight && aw !== undefined && ah !== undefined){
  3011. rz.setSize(aw, ah);
  3012. }else if(!this.deferHeight && ah !== undefined){
  3013. rz.setHeight(ah);
  3014. }else if(aw !== undefined){
  3015. rz.setWidth(aw);
  3016. }
  3017. this.onResize(aw, ah, w, h);
  3018. this.fireEvent('resize', this, aw, ah, w, h);
  3019. }
  3020. return this;
  3021. },
  3022. /**
  3023. * Sets the width of the component. This method fires the {@link #resize} event.
  3024. * @param {Mixed} width The new width to set. This may be one of:<div class="mdetail-params"><ul>
  3025. * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit defaultUnit}s (by default, pixels).</li>
  3026. * <li>A String used to set the CSS width style.</li>
  3027. * </ul></div>
  3028. * @return {Ext.BoxComponent} this
  3029. */
  3030. setWidth : function(width){
  3031. return this.setSize(width);
  3032. },
  3033. /**
  3034. * Sets the height of the component. This method fires the {@link #resize} event.
  3035. * @param {Mixed} height The new height to set. This may be one of:<div class="mdetail-params"><ul>
  3036. * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit defaultUnit}s (by default, pixels).</li>
  3037. * <li>A String used to set the CSS height style.</li>
  3038. * <li><i>undefined</i> to leave the height unchanged.</li>
  3039. * </ul></div>
  3040. * @return {Ext.BoxComponent} this
  3041. */
  3042. setHeight : function(height){
  3043. return this.setSize(undefined, height);
  3044. },
  3045. /**
  3046. * Gets the current size of the component's underlying element.
  3047. * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
  3048. */
  3049. getSize : function(){
  3050. return this.getResizeEl().getSize();
  3051. },
  3052. /**
  3053. * Gets the current width of the component's underlying element.
  3054. * @return {Number}
  3055. */
  3056. getWidth : function(){
  3057. return this.getResizeEl().getWidth();
  3058. },
  3059. /**
  3060. * Gets the current height of the component's underlying element.
  3061. * @return {Number}
  3062. */
  3063. getHeight : function(){
  3064. return this.getResizeEl().getHeight();
  3065. },
  3066. /**
  3067. * Gets the current size of the component's underlying element, including space taken by its margins.
  3068. * @return {Object} An object containing the element's size {width: (element width + left/right margins), height: (element height + top/bottom margins)}
  3069. */
  3070. getOuterSize : function(){
  3071. var el = this.getResizeEl();
  3072. return {width: el.getWidth() + el.getMargins('lr'),
  3073. height: el.getHeight() + el.getMargins('tb')};
  3074. },
  3075. /**
  3076. * Gets the current XY position of the component's underlying element.
  3077. * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
  3078. * @return {Array} The XY position of the element (e.g., [100, 200])
  3079. */
  3080. getPosition : function(local){
  3081. var el = this.getPositionEl();
  3082. if(local === true){
  3083. return [el.getLeft(true), el.getTop(true)];
  3084. }
  3085. return this.xy || el.getXY();
  3086. },
  3087. /**
  3088. * Gets the current box measurements of the component's underlying element.
  3089. * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
  3090. * @return {Object} box An object in the format {x, y, width, height}
  3091. */
  3092. getBox : function(local){
  3093. var pos = this.getPosition(local);
  3094. var s = this.getSize();
  3095. s.x = pos[0];
  3096. s.y = pos[1];
  3097. return s;
  3098. },
  3099. /**
  3100. * Sets the current box measurements of the component's underlying element.
  3101. * @param {Object} box An object in the format {x, y, width, height}
  3102. * @return {Ext.BoxComponent} this
  3103. */
  3104. updateBox : function(box){
  3105. this.setSize(box.width, box.height);
  3106. this.setPagePosition(box.x, box.y);
  3107. return this;
  3108. },
  3109. /**
  3110. * <p>Returns the outermost Element of this Component which defines the Components overall size.</p>
  3111. * <p><i>Usually</i> this will return the same Element as <code>{@link #getEl}</code>,
  3112. * but in some cases, a Component may have some more wrapping Elements around its main
  3113. * active Element.</p>
  3114. * <p>An example is a ComboBox. It is encased in a <i>wrapping</i> Element which
  3115. * contains both the <code>&lt;input></code> Element (which is what would be returned
  3116. * by its <code>{@link #getEl}</code> method, <i>and</i> the trigger button Element.
  3117. * This Element is returned as the <code>resizeEl</code>.
  3118. * @return {Ext.Element} The Element which is to be resized by size managing layouts.
  3119. */
  3120. getResizeEl : function(){
  3121. return this.resizeEl || this.el;
  3122. },
  3123. /**
  3124. * Sets the overflow on the content element of the component.
  3125. * @param {Boolean} scroll True to allow the Component to auto scroll.
  3126. * @return {Ext.BoxComponent} this
  3127. */
  3128. setAutoScroll : function(scroll){
  3129. if(this.rendered){
  3130. this.getContentTarget().setOverflow(scroll ? 'auto' : '');
  3131. }
  3132. this.autoScroll = scroll;
  3133. return this;
  3134. },
  3135. /**
  3136. * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
  3137. * This method fires the {@link #move} event.
  3138. * @param {Number} left The new left
  3139. * @param {Number} top The new top
  3140. * @return {Ext.BoxComponent} this
  3141. */
  3142. setPosition : function(x, y){
  3143. if(x && typeof x[1] == 'number'){
  3144. y = x[1];
  3145. x = x[0];
  3146. }
  3147. this.x = x;
  3148. this.y = y;
  3149. if(!this.boxReady){
  3150. return this;
  3151. }
  3152. var adj = this.adjustPosition(x, y);
  3153. var ax = adj.x, ay = adj.y;
  3154. var el = this.getPositionEl();
  3155. if(ax !== undefined || ay !== undefined){
  3156. if(ax !== undefined && ay !== undefined){
  3157. el.setLeftTop(ax, ay);
  3158. }else if(ax !== undefined){
  3159. el.setLeft(ax);
  3160. }else if(ay !== undefined){
  3161. el.setTop(ay);
  3162. }
  3163. this.onPosition(ax, ay);
  3164. this.fireEvent('move', this, ax, ay);
  3165. }
  3166. return this;
  3167. },
  3168. /**
  3169. * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
  3170. * This method fires the {@link #move} event.
  3171. * @param {Number} x The new x position
  3172. * @param {Number} y The new y position
  3173. * @return {Ext.BoxComponent} this
  3174. */
  3175. setPagePosition : function(x, y){
  3176. if(x && typeof x[1] == 'number'){
  3177. y = x[1];
  3178. x = x[0];
  3179. }
  3180. this.pageX = x;
  3181. this.pageY = y;
  3182. if(!this.boxReady){
  3183. return;
  3184. }
  3185. if(x === undefined || y === undefined){ // cannot translate undefined points
  3186. return;
  3187. }
  3188. var p = this.getPositionEl().translatePoints(x, y);
  3189. this.setPosition(p.left, p.top);
  3190. return this;
  3191. },
  3192. // private
  3193. afterRender : function(){
  3194. Ext.BoxComponent.superclass.afterRender.call(this);
  3195. if(this.resizeEl){
  3196. this.resizeEl = Ext.get(this.resizeEl);
  3197. }
  3198. if(this.positionEl){
  3199. this.positionEl = Ext.get(this.positionEl);
  3200. }
  3201. this.boxReady = true;
  3202. Ext.isDefined(this.autoScroll) && this.setAutoScroll(this.autoScroll);
  3203. this.setSize(this.width, this.height);
  3204. if(this.x || this.y){
  3205. this.setPosition(this.x, this.y);
  3206. }else if(this.pageX || this.pageY){
  3207. this.setPagePosition(this.pageX, this.pageY);
  3208. }
  3209. },
  3210. /**
  3211. * Force the component's size to recalculate based on the underlying element's current height and width.
  3212. * @return {Ext.BoxComponent} this
  3213. */
  3214. syncSize : function(){
  3215. delete this.lastSize;
  3216. this.setSize(this.autoWidth ? undefined : this.getResizeEl().getWidth(), this.autoHeight ? undefined : this.getResizeEl().getHeight());
  3217. return this;
  3218. },
  3219. /* // protected
  3220. * Called after the component is resized, this method is empty by default but can be implemented by any
  3221. * subclass that needs to perform custom logic after a resize occurs.
  3222. * @param {Number} adjWidth The box-adjusted width that was set
  3223. * @param {Number} adjHeight The box-adjusted height that was set
  3224. * @param {Number} rawWidth The width that was originally specified
  3225. * @param {Number} rawHeight The height that was originally specified
  3226. */
  3227. onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
  3228. },
  3229. /* // protected
  3230. * Called after the component is moved, this method is empty by default but can be implemented by any
  3231. * subclass that needs to perform custom logic after a move occurs.
  3232. * @param {Number} x The new x position
  3233. * @param {Number} y The new y position
  3234. */
  3235. onPosition : function(x, y){
  3236. },
  3237. // private
  3238. adjustSize : function(w, h){
  3239. if(this.autoWidth){
  3240. w = 'auto';
  3241. }
  3242. if(this.autoHeight){
  3243. h = 'auto';
  3244. }
  3245. return {width : w, height: h};
  3246. },
  3247. // private
  3248. adjustPosition : function(x, y){
  3249. return {x : x, y: y};
  3250. }
  3251. });
  3252. Ext.reg('box', Ext.BoxComponent);
  3253. /**
  3254. * @class Ext.Spacer
  3255. * @extends Ext.BoxComponent
  3256. * <p>Used to provide a sizable space in a layout.</p>
  3257. * @constructor
  3258. * @param {Object} config
  3259. */
  3260. Ext.Spacer = Ext.extend(Ext.BoxComponent, {
  3261. autoEl:'div'
  3262. });
  3263. Ext.reg('spacer', Ext.Spacer);/**
  3264. * @class Ext.SplitBar
  3265. * @extends Ext.util.Observable
  3266. * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
  3267. * <br><br>
  3268. * Usage:
  3269. * <pre><code>
  3270. var split = new Ext.SplitBar("elementToDrag", "elementToSize",
  3271. Ext.SplitBar.HORIZONTAL, Ext.SplitBar.LEFT);
  3272. split.setAdapter(new Ext.SplitBar.AbsoluteLayoutAdapter("container"));
  3273. split.minSize = 100;
  3274. split.maxSize = 600;
  3275. split.animate = true;
  3276. split.on('moved', splitterMoved);
  3277. </code></pre>
  3278. * @constructor
  3279. * Create a new SplitBar
  3280. * @param {Mixed} dragElement The element to be dragged and act as the SplitBar.
  3281. * @param {Mixed} resizingElement The element to be resized based on where the SplitBar element is dragged
  3282. * @param {Number} orientation (optional) Either Ext.SplitBar.HORIZONTAL or Ext.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
  3283. * @param {Number} placement (optional) Either Ext.SplitBar.LEFT or Ext.SplitBar.RIGHT for horizontal or
  3284. Ext.SplitBar.TOP or Ext.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
  3285. position of the SplitBar).
  3286. */
  3287. Ext.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
  3288. /** @private */
  3289. this.el = Ext.get(dragElement, true);
  3290. this.el.dom.unselectable = "on";
  3291. /** @private */
  3292. this.resizingEl = Ext.get(resizingElement, true);
  3293. /**
  3294. * @private
  3295. * The orientation of the split. Either Ext.SplitBar.HORIZONTAL or Ext.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
  3296. * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
  3297. * @type Number
  3298. */
  3299. this.orientation = orientation || Ext.SplitBar.HORIZONTAL;
  3300. /**
  3301. * The increment, in pixels by which to move this SplitBar. When <i>undefined</i>, the SplitBar moves smoothly.
  3302. * @type Number
  3303. * @property tickSize
  3304. */
  3305. /**
  3306. * The minimum size of the resizing element. (Defaults to 0)
  3307. * @type Number
  3308. */
  3309. this.minSize = 0;
  3310. /**
  3311. * The maximum size of the resizing element. (Defaults to 2000)
  3312. * @type Number
  3313. */
  3314. this.maxSize = 2000;
  3315. /**
  3316. * Whether to animate the transition to the new size
  3317. * @type Boolean
  3318. */
  3319. this.animate = false;
  3320. /**
  3321. * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
  3322. * @type Boolean
  3323. */
  3324. this.useShim = false;
  3325. /** @private */
  3326. this.shim = null;
  3327. if(!existingProxy){
  3328. /** @private */
  3329. this.proxy = Ext.SplitBar.createProxy(this.orientation);
  3330. }else{
  3331. this.proxy = Ext.get(existingProxy).dom;
  3332. }
  3333. /** @private */
  3334. this.dd = new Ext.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
  3335. /** @private */
  3336. this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
  3337. /** @private */
  3338. this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
  3339. /** @private */
  3340. this.dragSpecs = {};
  3341. /**
  3342. * @private The adapter to use to positon and resize elements
  3343. */
  3344. this.adapter = new Ext.SplitBar.BasicLayoutAdapter();
  3345. this.adapter.init(this);
  3346. if(this.orientation == Ext.SplitBar.HORIZONTAL){
  3347. /** @private */
  3348. this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Ext.SplitBar.LEFT : Ext.SplitBar.RIGHT);
  3349. this.el.addClass("x-splitbar-h");
  3350. }else{
  3351. /** @private */
  3352. this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Ext.SplitBar.TOP : Ext.SplitBar.BOTTOM);
  3353. this.el.addClass("x-splitbar-v");
  3354. }
  3355. this.addEvents(
  3356. /**
  3357. * @event resize
  3358. * Fires when the splitter is moved (alias for {@link #moved})
  3359. * @param {Ext.SplitBar} this
  3360. * @param {Number} newSize the new width or height
  3361. */
  3362. "resize",
  3363. /**
  3364. * @event moved
  3365. * Fires when the splitter is moved
  3366. * @param {Ext.SplitBar} this
  3367. * @param {Number} newSize the new width or height
  3368. */
  3369. "moved",
  3370. /**
  3371. * @event beforeresize
  3372. * Fires before the splitter is dragged
  3373. * @param {Ext.SplitBar} this
  3374. */
  3375. "beforeresize",
  3376. "beforeapply"
  3377. );
  3378. Ext.SplitBar.superclass.constructor.call(this);
  3379. };
  3380. Ext.extend(Ext.SplitBar, Ext.util.Observable, {
  3381. onStartProxyDrag : function(x, y){
  3382. this.fireEvent("beforeresize", this);
  3383. this.overlay = Ext.DomHelper.append(document.body, {cls: "x-drag-overlay", html: "&#160;"}, true);
  3384. this.overlay.unselectable();
  3385. this.overlay.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
  3386. this.overlay.show();
  3387. Ext.get(this.proxy).setDisplayed("block");
  3388. var size = this.adapter.getElementSize(this);
  3389. this.activeMinSize = this.getMinimumSize();
  3390. this.activeMaxSize = this.getMaximumSize();
  3391. var c1 = size - this.activeMinSize;
  3392. var c2 = Math.max(this.activeMaxSize - size, 0);
  3393. if(this.orientation == Ext.SplitBar.HORIZONTAL){
  3394. this.dd.resetConstraints();
  3395. this.dd.setXConstraint(
  3396. this.placement == Ext.SplitBar.LEFT ? c1 : c2,
  3397. this.placement == Ext.SplitBar.LEFT ? c2 : c1,
  3398. this.tickSize
  3399. );
  3400. this.dd.setYConstraint(0, 0);
  3401. }else{
  3402. this.dd.resetConstraints();
  3403. this.dd.setXConstraint(0, 0);
  3404. this.dd.setYConstraint(
  3405. this.placement == Ext.SplitBar.TOP ? c1 : c2,
  3406. this.placement == Ext.SplitBar.TOP ? c2 : c1,
  3407. this.tickSize
  3408. );
  3409. }
  3410. this.dragSpecs.startSize = size;
  3411. this.dragSpecs.startPoint = [x, y];
  3412. Ext.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
  3413. },
  3414. /**
  3415. * @private Called after the drag operation by the DDProxy
  3416. */
  3417. onEndProxyDrag : function(e){
  3418. Ext.get(this.proxy).setDisplayed(false);
  3419. var endPoint = Ext.lib.Event.getXY(e);
  3420. if(this.overlay){
  3421. Ext.destroy(this.overlay);
  3422. delete this.overlay;
  3423. }
  3424. var newSize;
  3425. if(this.orientation == Ext.SplitBar.HORIZONTAL){
  3426. newSize = this.dragSpecs.startSize +
  3427. (this.placement == Ext.SplitBar.LEFT ?
  3428. endPoint[0] - this.dragSpecs.startPoint[0] :
  3429. this.dragSpecs.startPoint[0] - endPoint[0]
  3430. );
  3431. }else{
  3432. newSize = this.dragSpecs.startSize +
  3433. (this.placement == Ext.SplitBar.TOP ?
  3434. endPoint[1] - this.dragSpecs.startPoint[1] :
  3435. this.dragSpecs.startPoint[1] - endPoint[1]
  3436. );
  3437. }
  3438. newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
  3439. if(newSize != this.dragSpecs.startSize){
  3440. if(this.fireEvent('beforeapply', this, newSize) !== false){
  3441. this.adapter.setElementSize(this, newSize);
  3442. this.fireEvent("moved", this, newSize);
  3443. this.fireEvent("resize", this, newSize);
  3444. }
  3445. }
  3446. },
  3447. /**
  3448. * Get the adapter this SplitBar uses
  3449. * @return The adapter object
  3450. */
  3451. getAdapter : function(){
  3452. return this.adapter;
  3453. },
  3454. /**
  3455. * Set the adapter this SplitBar uses
  3456. * @param {Object} adapter A SplitBar adapter object
  3457. */
  3458. setAdapter : function(adapter){
  3459. this.adapter = adapter;
  3460. this.adapter.init(this);
  3461. },
  3462. /**
  3463. * Gets the minimum size for the resizing element
  3464. * @return {Number} The minimum size
  3465. */
  3466. getMinimumSize : function(){
  3467. return this.minSize;
  3468. },
  3469. /**
  3470. * Sets the minimum size for the resizing element
  3471. * @param {Number} minSize The minimum size
  3472. */
  3473. setMinimumSize : function(minSize){
  3474. this.minSize = minSize;
  3475. },
  3476. /**
  3477. * Gets the maximum size for the resizing element
  3478. * @return {Number} The maximum size
  3479. */
  3480. getMaximumSize : function(){
  3481. return this.maxSize;
  3482. },
  3483. /**
  3484. * Sets the maximum size for the resizing element
  3485. * @param {Number} maxSize The maximum size
  3486. */
  3487. setMaximumSize : function(maxSize){
  3488. this.maxSize = maxSize;
  3489. },
  3490. /**
  3491. * Sets the initialize size for the resizing element
  3492. * @param {Number} size The initial size
  3493. */
  3494. setCurrentSize : function(size){
  3495. var oldAnimate = this.animate;
  3496. this.animate = false;
  3497. this.adapter.setElementSize(this, size);
  3498. this.animate = oldAnimate;
  3499. },
  3500. /**
  3501. * Destroy this splitbar.
  3502. * @param {Boolean} removeEl True to remove the element
  3503. */
  3504. destroy : function(removeEl){
  3505. Ext.destroy(this.shim, Ext.get(this.proxy));
  3506. this.dd.unreg();
  3507. if(removeEl){
  3508. this.el.remove();
  3509. }
  3510. this.purgeListeners();
  3511. }
  3512. });
  3513. /**
  3514. * @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.
  3515. */
  3516. Ext.SplitBar.createProxy = function(dir){
  3517. var proxy = new Ext.Element(document.createElement("div"));
  3518. document.body.appendChild(proxy.dom);
  3519. proxy.unselectable();
  3520. var cls = 'x-splitbar-proxy';
  3521. proxy.addClass(cls + ' ' + (dir == Ext.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
  3522. return proxy.dom;
  3523. };
  3524. /**
  3525. * @class Ext.SplitBar.BasicLayoutAdapter
  3526. * Default Adapter. It assumes the splitter and resizing element are not positioned
  3527. * elements and only gets/sets the width of the element. Generally used for table based layouts.
  3528. */
  3529. Ext.SplitBar.BasicLayoutAdapter = function(){
  3530. };
  3531. Ext.SplitBar.BasicLayoutAdapter.prototype = {
  3532. // do nothing for now
  3533. init : function(s){
  3534. },
  3535. /**
  3536. * Called before drag operations to get the current size of the resizing element.
  3537. * @param {Ext.SplitBar} s The SplitBar using this adapter
  3538. */
  3539. getElementSize : function(s){
  3540. if(s.orientation == Ext.SplitBar.HORIZONTAL){
  3541. return s.resizingEl.getWidth();
  3542. }else{
  3543. return s.resizingEl.getHeight();
  3544. }
  3545. },
  3546. /**
  3547. * Called after drag operations to set the size of the resizing element.
  3548. * @param {Ext.SplitBar} s The SplitBar using this adapter
  3549. * @param {Number} newSize The new size to set
  3550. * @param {Function} onComplete A function to be invoked when resizing is complete
  3551. */
  3552. setElementSize : function(s, newSize, onComplete){
  3553. if(s.orientation == Ext.SplitBar.HORIZONTAL){
  3554. if(!s.animate){
  3555. s.resizingEl.setWidth(newSize);
  3556. if(onComplete){
  3557. onComplete(s, newSize);
  3558. }
  3559. }else{
  3560. s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
  3561. }
  3562. }else{
  3563. if(!s.animate){
  3564. s.resizingEl.setHeight(newSize);
  3565. if(onComplete){
  3566. onComplete(s, newSize);
  3567. }
  3568. }else{
  3569. s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
  3570. }
  3571. }
  3572. }
  3573. };
  3574. /**
  3575. *@class Ext.SplitBar.AbsoluteLayoutAdapter
  3576. * @extends Ext.SplitBar.BasicLayoutAdapter
  3577. * Adapter that moves the splitter element to align with the resized sizing element.
  3578. * Used with an absolute positioned SplitBar.
  3579. * @param {Mixed} container The container that wraps around the absolute positioned content. If it's
  3580. * document.body, make sure you assign an id to the body element.
  3581. */
  3582. Ext.SplitBar.AbsoluteLayoutAdapter = function(container){
  3583. this.basic = new Ext.SplitBar.BasicLayoutAdapter();
  3584. this.container = Ext.get(container);
  3585. };
  3586. Ext.SplitBar.AbsoluteLayoutAdapter.prototype = {
  3587. init : function(s){
  3588. this.basic.init(s);
  3589. },
  3590. getElementSize : function(s){
  3591. return this.basic.getElementSize(s);
  3592. },
  3593. setElementSize : function(s, newSize, onComplete){
  3594. this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
  3595. },
  3596. moveSplitter : function(s){
  3597. var yes = Ext.SplitBar;
  3598. switch(s.placement){
  3599. case yes.LEFT:
  3600. s.el.setX(s.resizingEl.getRight());
  3601. break;
  3602. case yes.RIGHT:
  3603. s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
  3604. break;
  3605. case yes.TOP:
  3606. s.el.setY(s.resizingEl.getBottom());
  3607. break;
  3608. case yes.BOTTOM:
  3609. s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
  3610. break;
  3611. }
  3612. }
  3613. };
  3614. /**
  3615. * Orientation constant - Create a vertical SplitBar
  3616. * @static
  3617. * @type Number
  3618. */
  3619. Ext.SplitBar.VERTICAL = 1;
  3620. /**
  3621. * Orientation constant - Create a horizontal SplitBar
  3622. * @static
  3623. * @type Number
  3624. */
  3625. Ext.SplitBar.HORIZONTAL = 2;
  3626. /**
  3627. * Placement constant - The resizing element is to the left of the splitter element
  3628. * @static
  3629. * @type Number
  3630. */
  3631. Ext.SplitBar.LEFT = 1;
  3632. /**
  3633. * Placement constant - The resizing element is to the right of the splitter element
  3634. * @static
  3635. * @type Number
  3636. */
  3637. Ext.SplitBar.RIGHT = 2;
  3638. /**
  3639. * Placement constant - The resizing element is positioned above the splitter element
  3640. * @static
  3641. * @type Number
  3642. */
  3643. Ext.SplitBar.TOP = 3;
  3644. /**
  3645. * Placement constant - The resizing element is positioned under splitter element
  3646. * @static
  3647. * @type Number
  3648. */
  3649. Ext.SplitBar.BOTTOM = 4;
  3650. /**
  3651. * @class Ext.Container
  3652. * @extends Ext.BoxComponent
  3653. * <p>Base class for any {@link Ext.BoxComponent} that may contain other Components. Containers handle the
  3654. * basic behavior of containing items, namely adding, inserting and removing items.</p>
  3655. *
  3656. * <p>The most commonly used Container classes are {@link Ext.Panel}, {@link Ext.Window} and {@link Ext.TabPanel}.
  3657. * If you do not need the capabilities offered by the aforementioned classes you can create a lightweight
  3658. * Container to be encapsulated by an HTML element to your specifications by using the
  3659. * <code><b>{@link Ext.Component#autoEl autoEl}</b></code> config option. This is a useful technique when creating
  3660. * embedded {@link Ext.layout.ColumnLayout column} layouts inside {@link Ext.form.FormPanel FormPanels}
  3661. * for example.</p>
  3662. *
  3663. * <p>The code below illustrates both how to explicitly create a Container, and how to implicitly
  3664. * create one using the <b><code>'container'</code></b> xtype:<pre><code>
  3665. // explicitly create a Container
  3666. var embeddedColumns = new Ext.Container({
  3667. autoEl: 'div', // This is the default
  3668. layout: 'column',
  3669. defaults: {
  3670. // implicitly create Container by specifying xtype
  3671. xtype: 'container',
  3672. autoEl: 'div', // This is the default.
  3673. layout: 'form',
  3674. columnWidth: 0.5,
  3675. style: {
  3676. padding: '10px'
  3677. }
  3678. },
  3679. // The two items below will be Ext.Containers, each encapsulated by a &lt;DIV> element.
  3680. items: [{
  3681. items: {
  3682. xtype: 'datefield',
  3683. name: 'startDate',
  3684. fieldLabel: 'Start date'
  3685. }
  3686. }, {
  3687. items: {
  3688. xtype: 'datefield',
  3689. name: 'endDate',
  3690. fieldLabel: 'End date'
  3691. }
  3692. }]
  3693. });</code></pre></p>
  3694. *
  3695. * <p><u><b>Layout</b></u></p>
  3696. * <p>Container classes delegate the rendering of child Components to a layout
  3697. * manager class which must be configured into the Container using the
  3698. * <code><b>{@link #layout}</b></code> configuration property.</p>
  3699. * <p>When either specifying child <code>{@link #items}</code> of a Container,
  3700. * or dynamically {@link #add adding} Components to a Container, remember to
  3701. * consider how you wish the Container to arrange those child elements, and
  3702. * whether those child elements need to be sized using one of Ext's built-in
  3703. * <b><code>{@link #layout}</code></b> schemes. By default, Containers use the
  3704. * {@link Ext.layout.ContainerLayout ContainerLayout} scheme which only
  3705. * renders child components, appending them one after the other inside the
  3706. * Container, and <b>does not apply any sizing</b> at all.</p>
  3707. * <p>A common mistake is when a developer neglects to specify a
  3708. * <b><code>{@link #layout}</code></b> (e.g. widgets like GridPanels or
  3709. * TreePanels are added to Containers for which no <code><b>{@link #layout}</b></code>
  3710. * has been specified). If a Container is left to use the default
  3711. * {@link Ext.layout.ContainerLayout ContainerLayout} scheme, none of its
  3712. * child components will be resized, or changed in any way when the Container
  3713. * is resized.</p>
  3714. * <p>Certain layout managers allow dynamic addition of child components.
  3715. * Those that do include {@link Ext.layout.CardLayout},
  3716. * {@link Ext.layout.AnchorLayout}, {@link Ext.layout.FormLayout}, and
  3717. * {@link Ext.layout.TableLayout}. For example:<pre><code>
  3718. // Create the GridPanel.
  3719. var myNewGrid = new Ext.grid.GridPanel({
  3720. store: myStore,
  3721. columns: myColumnModel,
  3722. title: 'Results', // the title becomes the title of the tab
  3723. });
  3724. myTabPanel.add(myNewGrid); // {@link Ext.TabPanel} implicitly uses {@link Ext.layout.CardLayout CardLayout}
  3725. myTabPanel.{@link Ext.TabPanel#setActiveTab setActiveTab}(myNewGrid);
  3726. * </code></pre></p>
  3727. * <p>The example above adds a newly created GridPanel to a TabPanel. Note that
  3728. * a TabPanel uses {@link Ext.layout.CardLayout} as its layout manager which
  3729. * means all its child items are sized to {@link Ext.layout.FitLayout fit}
  3730. * exactly into its client area.
  3731. * <p><b><u>Overnesting is a common problem</u></b>.
  3732. * An example of overnesting occurs when a GridPanel is added to a TabPanel
  3733. * by wrapping the GridPanel <i>inside</i> a wrapping Panel (that has no
  3734. * <code><b>{@link #layout}</b></code> specified) and then add that wrapping Panel
  3735. * to the TabPanel. The point to realize is that a GridPanel <b>is</b> a
  3736. * Component which can be added directly to a Container. If the wrapping Panel
  3737. * has no <code><b>{@link #layout}</b></code> configuration, then the overnested
  3738. * GridPanel will not be sized as expected.<p>
  3739. *
  3740. * <p><u><b>Adding via remote configuration</b></u></p>
  3741. *
  3742. * <p>A server side script can be used to add Components which are generated dynamically on the server.
  3743. * An example of adding a GridPanel to a TabPanel where the GridPanel is generated by the server
  3744. * based on certain parameters:
  3745. * </p><pre><code>
  3746. // execute an Ajax request to invoke server side script:
  3747. Ext.Ajax.request({
  3748. url: 'gen-invoice-grid.php',
  3749. // send additional parameters to instruct server script
  3750. params: {
  3751. startDate: Ext.getCmp('start-date').getValue(),
  3752. endDate: Ext.getCmp('end-date').getValue()
  3753. },
  3754. // process the response object to add it to the TabPanel:
  3755. success: function(xhr) {
  3756. var newComponent = eval(xhr.responseText); // see discussion below
  3757. myTabPanel.add(newComponent); // add the component to the TabPanel
  3758. myTabPanel.setActiveTab(newComponent);
  3759. },
  3760. failure: function() {
  3761. Ext.Msg.alert("Grid create failed", "Server communication failure");
  3762. }
  3763. });
  3764. </code></pre>
  3765. * <p>The server script needs to return an executable Javascript statement which, when processed
  3766. * using <code>eval()</code>, will return either a config object with an {@link Ext.Component#xtype xtype},
  3767. * or an instantiated Component. The server might return this for example:</p><pre><code>
  3768. (function() {
  3769. function formatDate(value){
  3770. return value ? value.dateFormat('M d, Y') : '';
  3771. };
  3772. var store = new Ext.data.Store({
  3773. url: 'get-invoice-data.php',
  3774. baseParams: {
  3775. startDate: '01/01/2008',
  3776. endDate: '01/31/2008'
  3777. },
  3778. reader: new Ext.data.JsonReader({
  3779. record: 'transaction',
  3780. idProperty: 'id',
  3781. totalRecords: 'total'
  3782. }, [
  3783. 'customer',
  3784. 'invNo',
  3785. {name: 'date', type: 'date', dateFormat: 'm/d/Y'},
  3786. {name: 'value', type: 'float'}
  3787. ])
  3788. });
  3789. var grid = new Ext.grid.GridPanel({
  3790. title: 'Invoice Report',
  3791. bbar: new Ext.PagingToolbar(store),
  3792. store: store,
  3793. columns: [
  3794. {header: "Customer", width: 250, dataIndex: 'customer', sortable: true},
  3795. {header: "Invoice Number", width: 120, dataIndex: 'invNo', sortable: true},
  3796. {header: "Invoice Date", width: 100, dataIndex: 'date', renderer: formatDate, sortable: true},
  3797. {header: "Value", width: 120, dataIndex: 'value', renderer: 'usMoney', sortable: true}
  3798. ],
  3799. });
  3800. store.load();
  3801. return grid; // return instantiated component
  3802. })();
  3803. </code></pre>
  3804. * <p>When the above code fragment is passed through the <code>eval</code> function in the success handler
  3805. * of the Ajax request, the code is executed by the Javascript processor, and the anonymous function
  3806. * runs, and returns the instantiated grid component.</p>
  3807. * <p>Note: since the code above is <i>generated</i> by a server script, the <code>baseParams</code> for
  3808. * the Store, the metadata to allow generation of the Record layout, and the ColumnModel
  3809. * can all be generated into the code since these are all known on the server.</p>
  3810. *
  3811. * @xtype container
  3812. */
  3813. Ext.Container = Ext.extend(Ext.BoxComponent, {
  3814. /**
  3815. * @cfg {Boolean} monitorResize
  3816. * True to automatically monitor window resize events to handle anything that is sensitive to the current size
  3817. * of the viewport. This value is typically managed by the chosen <code>{@link #layout}</code> and should not need
  3818. * to be set manually.
  3819. */
  3820. /**
  3821. * @cfg {String/Object} layout
  3822. * <p><b>*Important</b>: In order for child items to be correctly sized and
  3823. * positioned, typically a layout manager <b>must</b> be specified through
  3824. * the <code>layout</code> configuration option.</p>
  3825. * <br><p>The sizing and positioning of child {@link items} is the responsibility of
  3826. * the Container's layout manager which creates and manages the type of layout
  3827. * you have in mind. For example:</p><pre><code>
  3828. new Ext.Window({
  3829. width:300, height: 300,
  3830. layout: 'fit', // explicitly set layout manager: override the default (layout:'auto')
  3831. items: [{
  3832. title: 'Panel inside a Window'
  3833. }]
  3834. }).show();
  3835. * </code></pre>
  3836. * <p>If the {@link #layout} configuration is not explicitly specified for
  3837. * a general purpose container (e.g. Container or Panel) the
  3838. * {@link Ext.layout.ContainerLayout default layout manager} will be used
  3839. * which does nothing but render child components sequentially into the
  3840. * Container (no sizing or positioning will be performed in this situation).
  3841. * Some container classes implicitly specify a default layout
  3842. * (e.g. FormPanel specifies <code>layout:'form'</code>). Other specific
  3843. * purpose classes internally specify/manage their internal layout (e.g.
  3844. * GridPanel, TabPanel, TreePanel, Toolbar, Menu, etc.).</p>
  3845. * <br><p><b><code>layout</code></b> may be specified as either as an Object or
  3846. * as a String:</p><div><ul class="mdetail-params">
  3847. *
  3848. * <li><u>Specify as an Object</u></li>
  3849. * <div><ul class="mdetail-params">
  3850. * <li>Example usage:</li>
  3851. <pre><code>
  3852. layout: {
  3853. type: 'vbox',
  3854. padding: '5',
  3855. align: 'left'
  3856. }
  3857. </code></pre>
  3858. *
  3859. * <li><code><b>type</b></code></li>
  3860. * <br/><p>The layout type to be used for this container. If not specified,
  3861. * a default {@link Ext.layout.ContainerLayout} will be created and used.</p>
  3862. * <br/><p>Valid layout <code>type</code> values are:</p>
  3863. * <div class="sub-desc"><ul class="mdetail-params">
  3864. * <li><code><b>{@link Ext.layout.AbsoluteLayout absolute}</b></code></li>
  3865. * <li><code><b>{@link Ext.layout.AccordionLayout accordion}</b></code></li>
  3866. * <li><code><b>{@link Ext.layout.AnchorLayout anchor}</b></code></li>
  3867. * <li><code><b>{@link Ext.layout.ContainerLayout auto}</b></code> &nbsp;&nbsp;&nbsp; <b>Default</b></li>
  3868. * <li><code><b>{@link Ext.layout.BorderLayout border}</b></code></li>
  3869. * <li><code><b>{@link Ext.layout.CardLayout card}</b></code></li>
  3870. * <li><code><b>{@link Ext.layout.ColumnLayout column}</b></code></li>
  3871. * <li><code><b>{@link Ext.layout.FitLayout fit}</b></code></li>
  3872. * <li><code><b>{@link Ext.layout.FormLayout form}</b></code></li>
  3873. * <li><code><b>{@link Ext.layout.HBoxLayout hbox}</b></code></li>
  3874. * <li><code><b>{@link Ext.layout.MenuLayout menu}</b></code></li>
  3875. * <li><code><b>{@link Ext.layout.TableLayout table}</b></code></li>
  3876. * <li><code><b>{@link Ext.layout.ToolbarLayout toolbar}</b></code></li>
  3877. * <li><code><b>{@link Ext.layout.VBoxLayout vbox}</b></code></li>
  3878. * </ul></div>
  3879. *
  3880. * <li>Layout specific configuration properties</li>
  3881. * <br/><p>Additional layout specific configuration properties may also be
  3882. * specified. For complete details regarding the valid config options for
  3883. * each layout type, see the layout class corresponding to the <code>type</code>
  3884. * specified.</p>
  3885. *
  3886. * </ul></div>
  3887. *
  3888. * <li><u>Specify as a String</u></li>
  3889. * <div><ul class="mdetail-params">
  3890. * <li>Example usage:</li>
  3891. <pre><code>
  3892. layout: 'vbox',
  3893. layoutConfig: {
  3894. padding: '5',
  3895. align: 'left'
  3896. }
  3897. </code></pre>
  3898. * <li><code><b>layout</b></code></li>
  3899. * <br/><p>The layout <code>type</code> to be used for this container (see list
  3900. * of valid layout type values above).</p><br/>
  3901. * <li><code><b>{@link #layoutConfig}</b></code></li>
  3902. * <br/><p>Additional layout specific configuration properties. For complete
  3903. * details regarding the valid config options for each layout type, see the
  3904. * layout class corresponding to the <code>layout</code> specified.</p>
  3905. * </ul></div></ul></div>
  3906. */
  3907. /**
  3908. * @cfg {Object} layoutConfig
  3909. * This is a config object containing properties specific to the chosen
  3910. * <b><code>{@link #layout}</code></b> if <b><code>{@link #layout}</code></b>
  3911. * has been specified as a <i>string</i>.</p>
  3912. */
  3913. /**
  3914. * @cfg {Boolean/Number} bufferResize
  3915. * When set to true (50 milliseconds) or a number of milliseconds, the layout assigned for this container will buffer
  3916. * the frequency it calculates and does a re-layout of components. This is useful for heavy containers or containers
  3917. * with a large quantity of sub-components for which frequent layout calls would be expensive. Defaults to <code>50</code>.
  3918. */
  3919. bufferResize: 50,
  3920. /**
  3921. * @cfg {String/Number} activeItem
  3922. * A string component id or the numeric index of the component that should be initially activated within the
  3923. * container's layout on render. For example, activeItem: 'item-1' or activeItem: 0 (index 0 = the first
  3924. * item in the container's collection). activeItem only applies to layout styles that can display
  3925. * items one at a time (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout} and
  3926. * {@link Ext.layout.FitLayout}). Related to {@link Ext.layout.ContainerLayout#activeItem}.
  3927. */
  3928. /**
  3929. * @cfg {Object/Array} items
  3930. * <pre><b>** IMPORTANT</b>: be sure to <b>{@link #layout specify a <code>layout</code>} if needed ! **</b></pre>
  3931. * <p>A single item, or an array of child Components to be added to this container,
  3932. * for example:</p>
  3933. * <pre><code>
  3934. // specifying a single item
  3935. items: {...},
  3936. layout: 'fit', // specify a layout!
  3937. // specifying multiple items
  3938. items: [{...}, {...}],
  3939. layout: 'anchor', // specify a layout!
  3940. * </code></pre>
  3941. * <p>Each item may be:</p>
  3942. * <div><ul class="mdetail-params">
  3943. * <li>any type of object based on {@link Ext.Component}</li>
  3944. * <li>a fully instanciated object or</li>
  3945. * <li>an object literal that:</li>
  3946. * <div><ul class="mdetail-params">
  3947. * <li>has a specified <code>{@link Ext.Component#xtype xtype}</code></li>
  3948. * <li>the {@link Ext.Component#xtype} specified is associated with the Component
  3949. * desired and should be chosen from one of the available xtypes as listed
  3950. * in {@link Ext.Component}.</li>
  3951. * <li>If an <code>{@link Ext.Component#xtype xtype}</code> is not explicitly
  3952. * specified, the {@link #defaultType} for that Container is used.</li>
  3953. * <li>will be "lazily instanciated", avoiding the overhead of constructing a fully
  3954. * instanciated Component object</li>
  3955. * </ul></div></ul></div>
  3956. * <p><b>Notes</b>:</p>
  3957. * <div><ul class="mdetail-params">
  3958. * <li>Ext uses lazy rendering. Child Components will only be rendered
  3959. * should it become necessary. Items are automatically laid out when they are first
  3960. * shown (no sizing is done while hidden), or in response to a {@link #doLayout} call.</li>
  3961. * <li>Do not specify <code>{@link Ext.Panel#contentEl contentEl}</code>/
  3962. * <code>{@link Ext.Panel#html html}</code> with <code>items</code>.</li>
  3963. * </ul></div>
  3964. */
  3965. /**
  3966. * @cfg {Object|Function} defaults
  3967. * <p>This option is a means of applying default settings to all added items whether added through the {@link #items}
  3968. * config or via the {@link #add} or {@link #insert} methods.</p>
  3969. * <p>If an added item is a config object, and <b>not</b> an instantiated Component, then the default properties are
  3970. * unconditionally applied. If the added item <b>is</b> an instantiated Component, then the default properties are
  3971. * applied conditionally so as not to override existing properties in the item.</p>
  3972. * <p>If the defaults option is specified as a function, then the function will be called using this Container as the
  3973. * scope (<code>this</code> reference) and passing the added item as the first parameter. Any resulting object
  3974. * from that call is then applied to the item as default properties.</p>
  3975. * <p>For example, to automatically apply padding to the body of each of a set of
  3976. * contained {@link Ext.Panel} items, you could pass: <code>defaults: {bodyStyle:'padding:15px'}</code>.</p>
  3977. * <p>Usage:</p><pre><code>
  3978. defaults: { // defaults are applied to items, not the container
  3979. autoScroll:true
  3980. },
  3981. items: [
  3982. {
  3983. xtype: 'panel', // defaults <b>do not</b> have precedence over
  3984. id: 'panel1', // options in config objects, so the defaults
  3985. autoScroll: false // will not be applied here, panel1 will be autoScroll:false
  3986. },
  3987. new Ext.Panel({ // defaults <b>do</b> have precedence over options
  3988. id: 'panel2', // options in components, so the defaults
  3989. autoScroll: false // will be applied here, panel2 will be autoScroll:true.
  3990. })
  3991. ]
  3992. * </code></pre>
  3993. */
  3994. /** @cfg {Boolean} autoDestroy
  3995. * If true the container will automatically destroy any contained component that is removed from it, else
  3996. * destruction must be handled manually (defaults to true).
  3997. */
  3998. autoDestroy : true,
  3999. /** @cfg {Boolean} forceLayout
  4000. * If true the container will force a layout initially even if hidden or collapsed. This option
  4001. * is useful for forcing forms to render in collapsed or hidden containers. (defaults to false).
  4002. */
  4003. forceLayout: false,
  4004. /** @cfg {Boolean} hideBorders
  4005. * True to hide the borders of each contained component, false to defer to the component's existing
  4006. * border settings (defaults to false).
  4007. */
  4008. /** @cfg {String} defaultType
  4009. * <p>The default {@link Ext.Component xtype} of child Components to create in this Container when
  4010. * a child item is specified as a raw configuration object, rather than as an instantiated Component.</p>
  4011. * <p>Defaults to <code>'panel'</code>, except {@link Ext.menu.Menu} which defaults to <code>'menuitem'</code>,
  4012. * and {@link Ext.Toolbar} and {@link Ext.ButtonGroup} which default to <code>'button'</code>.</p>
  4013. */
  4014. defaultType : 'panel',
  4015. /** @cfg {String} resizeEvent
  4016. * The event to listen to for resizing in layouts. Defaults to <code>'resize'</code>.
  4017. */
  4018. resizeEvent: 'resize',
  4019. /**
  4020. * @cfg {Array} bubbleEvents
  4021. * <p>An array of events that, when fired, should be bubbled to any parent container.
  4022. * See {@link Ext.util.Observable#enableBubble}.
  4023. * Defaults to <code>['add', 'remove']</code>.
  4024. */
  4025. bubbleEvents: ['add', 'remove'],
  4026. // private
  4027. initComponent : function(){
  4028. Ext.Container.superclass.initComponent.call(this);
  4029. this.addEvents(
  4030. /**
  4031. * @event afterlayout
  4032. * Fires when the components in this container are arranged by the associated layout manager.
  4033. * @param {Ext.Container} this
  4034. * @param {ContainerLayout} layout The ContainerLayout implementation for this container
  4035. */
  4036. 'afterlayout',
  4037. /**
  4038. * @event beforeadd
  4039. * Fires before any {@link Ext.Component} is added or inserted into the container.
  4040. * A handler can return false to cancel the add.
  4041. * @param {Ext.Container} this
  4042. * @param {Ext.Component} component The component being added
  4043. * @param {Number} index The index at which the component will be added to the container's items collection
  4044. */
  4045. 'beforeadd',
  4046. /**
  4047. * @event beforeremove
  4048. * Fires before any {@link Ext.Component} is removed from the container. A handler can return
  4049. * false to cancel the remove.
  4050. * @param {Ext.Container} this
  4051. * @param {Ext.Component} component The component being removed
  4052. */
  4053. 'beforeremove',
  4054. /**
  4055. * @event add
  4056. * @bubbles
  4057. * Fires after any {@link Ext.Component} is added or inserted into the container.
  4058. * @param {Ext.Container} this
  4059. * @param {Ext.Component} component The component that was added
  4060. * @param {Number} index The index at which the component was added to the container's items collection
  4061. */
  4062. 'add',
  4063. /**
  4064. * @event remove
  4065. * @bubbles
  4066. * Fires after any {@link Ext.Component} is removed from the container.
  4067. * @param {Ext.Container} this
  4068. * @param {Ext.Component} component The component that was removed
  4069. */
  4070. 'remove'
  4071. );
  4072. /**
  4073. * The collection of components in this container as a {@link Ext.util.MixedCollection}
  4074. * @type MixedCollection
  4075. * @property items
  4076. */
  4077. var items = this.items;
  4078. if(items){
  4079. delete this.items;
  4080. this.add(items);
  4081. }
  4082. },
  4083. // private
  4084. initItems : function(){
  4085. if(!this.items){
  4086. this.items = new Ext.util.MixedCollection(false, this.getComponentId);
  4087. this.getLayout(); // initialize the layout
  4088. }
  4089. },
  4090. // private
  4091. setLayout : function(layout){
  4092. if(this.layout && this.layout != layout){
  4093. this.layout.setContainer(null);
  4094. }
  4095. this.layout = layout;
  4096. this.initItems();
  4097. layout.setContainer(this);
  4098. },
  4099. afterRender: function(){
  4100. // Render this Container, this should be done before setLayout is called which
  4101. // will hook onResize
  4102. Ext.Container.superclass.afterRender.call(this);
  4103. if(!this.layout){
  4104. this.layout = 'auto';
  4105. }
  4106. if(Ext.isObject(this.layout) && !this.layout.layout){
  4107. this.layoutConfig = this.layout;
  4108. this.layout = this.layoutConfig.type;
  4109. }
  4110. if(Ext.isString(this.layout)){
  4111. this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig);
  4112. }
  4113. this.setLayout(this.layout);
  4114. // If a CardLayout, the active item set
  4115. if(this.activeItem !== undefined && this.layout.setActiveItem){
  4116. var item = this.activeItem;
  4117. delete this.activeItem;
  4118. this.layout.setActiveItem(item);
  4119. }
  4120. // If we have no ownerCt, render and size all children
  4121. if(!this.ownerCt){
  4122. this.doLayout(false, true);
  4123. }
  4124. // This is a manually configured flag set by users in conjunction with renderTo.
  4125. // Not to be confused with the flag by the same name used in Layouts.
  4126. if(this.monitorResize === true){
  4127. Ext.EventManager.onWindowResize(this.doLayout, this, [false]);
  4128. }
  4129. },
  4130. /**
  4131. * <p>Returns the Element to be used to contain the child Components of this Container.</p>
  4132. * <p>An implementation is provided which returns the Container's {@link #getEl Element}, but
  4133. * if there is a more complex structure to a Container, this may be overridden to return
  4134. * the element into which the {@link #layout layout} renders child Components.</p>
  4135. * @return {Ext.Element} The Element to render child Components into.
  4136. */
  4137. getLayoutTarget : function(){
  4138. return this.el;
  4139. },
  4140. // private - used as the key lookup function for the items collection
  4141. getComponentId : function(comp){
  4142. return comp.getItemId();
  4143. },
  4144. /**
  4145. * <p>Adds {@link Ext.Component Component}(s) to this Container.</p>
  4146. * <br><p><b>Description</b></u> :
  4147. * <div><ul class="mdetail-params">
  4148. * <li>Fires the {@link #beforeadd} event before adding</li>
  4149. * <li>The Container's {@link #defaults default config values} will be applied
  4150. * accordingly (see <code>{@link #defaults}</code> for details).</li>
  4151. * <li>Fires the {@link #add} event after the component has been added.</li>
  4152. * </ul></div>
  4153. * <br><p><b>Notes</b></u> :
  4154. * <div><ul class="mdetail-params">
  4155. * <li>If the Container is <i>already rendered</i> when <code>add</code>
  4156. * is called, you may need to call {@link #doLayout} to refresh the view which causes
  4157. * any unrendered child Components to be rendered. This is required so that you can
  4158. * <code>add</code> multiple child components if needed while only refreshing the layout
  4159. * once. For example:<pre><code>
  4160. var tb = new {@link Ext.Toolbar}();
  4161. tb.render(document.body); // toolbar is rendered
  4162. tb.add({text:'Button 1'}); // add multiple items ({@link #defaultType} for {@link Ext.Toolbar Toolbar} is 'button')
  4163. tb.add({text:'Button 2'});
  4164. tb.{@link #doLayout}(); // refresh the layout
  4165. * </code></pre></li>
  4166. * <li><i>Warning:</i> Containers directly managed by the BorderLayout layout manager
  4167. * may not be removed or added. See the Notes for {@link Ext.layout.BorderLayout BorderLayout}
  4168. * for more details.</li>
  4169. * </ul></div>
  4170. * @param {...Object/Array} component
  4171. * <p>Either one or more Components to add or an Array of Components to add. See
  4172. * <code>{@link #items}</code> for additional information.</p>
  4173. * @return {Ext.Component/Array} The Components that were added.
  4174. */
  4175. add : function(comp){
  4176. this.initItems();
  4177. var args = arguments.length > 1;
  4178. if(args || Ext.isArray(comp)){
  4179. var result = [];
  4180. Ext.each(args ? arguments : comp, function(c){
  4181. result.push(this.add(c));
  4182. }, this);
  4183. return result;
  4184. }
  4185. var c = this.lookupComponent(this.applyDefaults(comp));
  4186. var index = this.items.length;
  4187. if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
  4188. this.items.add(c);
  4189. // *onAdded
  4190. c.onAdded(this, index);
  4191. this.onAdd(c);
  4192. this.fireEvent('add', this, c, index);
  4193. }
  4194. return c;
  4195. },
  4196. onAdd : function(c){
  4197. // Empty template method
  4198. },
  4199. // private
  4200. onAdded : function(container, pos) {
  4201. //overridden here so we can cascade down, not worth creating a template method.
  4202. this.ownerCt = container;
  4203. this.initRef();
  4204. //initialize references for child items
  4205. this.cascade(function(c){
  4206. c.initRef();
  4207. });
  4208. this.fireEvent('added', this, container, pos);
  4209. },
  4210. /**
  4211. * Inserts a Component into this Container at a specified index. Fires the
  4212. * {@link #beforeadd} event before inserting, then fires the {@link #add} event after the
  4213. * Component has been inserted.
  4214. * @param {Number} index The index at which the Component will be inserted
  4215. * into the Container's items collection
  4216. * @param {Ext.Component} component The child Component to insert.<br><br>
  4217. * Ext uses lazy rendering, and will only render the inserted Component should
  4218. * it become necessary.<br><br>
  4219. * A Component config object may be passed in order to avoid the overhead of
  4220. * constructing a real Component object if lazy rendering might mean that the
  4221. * inserted Component will not be rendered immediately. To take advantage of
  4222. * this 'lazy instantiation', set the {@link Ext.Component#xtype} config
  4223. * property to the registered type of the Component wanted.<br><br>
  4224. * For a list of all available xtypes, see {@link Ext.Component}.
  4225. * @return {Ext.Component} component The Component (or config object) that was
  4226. * inserted with the Container's default config values applied.
  4227. */
  4228. insert : function(index, comp) {
  4229. var args = arguments,
  4230. length = args.length,
  4231. result = [],
  4232. i, c;
  4233. this.initItems();
  4234. if (length > 2) {
  4235. for (i = length - 1; i >= 1; --i) {
  4236. result.push(this.insert(index, args[i]));
  4237. }
  4238. return result;
  4239. }
  4240. c = this.lookupComponent(this.applyDefaults(comp));
  4241. index = Math.min(index, this.items.length);
  4242. if (this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false) {
  4243. if (c.ownerCt == this) {
  4244. this.items.remove(c);
  4245. }
  4246. this.items.insert(index, c);
  4247. c.onAdded(this, index);
  4248. this.onAdd(c);
  4249. this.fireEvent('add', this, c, index);
  4250. }
  4251. return c;
  4252. },
  4253. // private
  4254. applyDefaults : function(c){
  4255. var d = this.defaults;
  4256. if(d){
  4257. if(Ext.isFunction(d)){
  4258. d = d.call(this, c);
  4259. }
  4260. if(Ext.isString(c)){
  4261. c = Ext.ComponentMgr.get(c);
  4262. Ext.apply(c, d);
  4263. }else if(!c.events){
  4264. Ext.applyIf(c.isAction ? c.initialConfig : c, d);
  4265. }else{
  4266. Ext.apply(c, d);
  4267. }
  4268. }
  4269. return c;
  4270. },
  4271. // private
  4272. onBeforeAdd : function(item){
  4273. if(item.ownerCt){
  4274. item.ownerCt.remove(item, false);
  4275. }
  4276. if(this.hideBorders === true){
  4277. item.border = (item.border === true);
  4278. }
  4279. },
  4280. /**
  4281. * Removes a component from this container. Fires the {@link #beforeremove} event before removing, then fires
  4282. * the {@link #remove} event after the component has been removed.
  4283. * @param {Component/String} component The component reference or id to remove.
  4284. * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
  4285. * Defaults to the value of this Container's {@link #autoDestroy} config.
  4286. * @return {Ext.Component} component The Component that was removed.
  4287. */
  4288. remove : function(comp, autoDestroy){
  4289. this.initItems();
  4290. var c = this.getComponent(comp);
  4291. if(c && this.fireEvent('beforeremove', this, c) !== false){
  4292. this.doRemove(c, autoDestroy);
  4293. this.fireEvent('remove', this, c);
  4294. }
  4295. return c;
  4296. },
  4297. onRemove: function(c){
  4298. // Empty template method
  4299. },
  4300. // private
  4301. doRemove: function(c, autoDestroy){
  4302. var l = this.layout,
  4303. hasLayout = l && this.rendered;
  4304. if(hasLayout){
  4305. l.onRemove(c);
  4306. }
  4307. this.items.remove(c);
  4308. c.onRemoved();
  4309. this.onRemove(c);
  4310. if(autoDestroy === true || (autoDestroy !== false && this.autoDestroy)){
  4311. c.destroy();
  4312. }
  4313. if(hasLayout){
  4314. l.afterRemove(c);
  4315. }
  4316. },
  4317. /**
  4318. * Removes all components from this container.
  4319. * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
  4320. * Defaults to the value of this Container's {@link #autoDestroy} config.
  4321. * @return {Array} Array of the destroyed components
  4322. */
  4323. removeAll: function(autoDestroy){
  4324. this.initItems();
  4325. var item, rem = [], items = [];
  4326. this.items.each(function(i){
  4327. rem.push(i);
  4328. });
  4329. for (var i = 0, len = rem.length; i < len; ++i){
  4330. item = rem[i];
  4331. this.remove(item, autoDestroy);
  4332. if(item.ownerCt !== this){
  4333. items.push(item);
  4334. }
  4335. }
  4336. return items;
  4337. },
  4338. /**
  4339. * Examines this container's <code>{@link #items}</code> <b>property</b>
  4340. * and gets a direct child component of this container.
  4341. * @param {String/Number} comp This parameter may be any of the following:
  4342. * <div><ul class="mdetail-params">
  4343. * <li>a <b><code>String</code></b> : representing the <code>{@link Ext.Component#itemId itemId}</code>
  4344. * or <code>{@link Ext.Component#id id}</code> of the child component </li>
  4345. * <li>a <b><code>Number</code></b> : representing the position of the child component
  4346. * within the <code>{@link #items}</code> <b>property</b></li>
  4347. * </ul></div>
  4348. * <p>For additional information see {@link Ext.util.MixedCollection#get}.
  4349. * @return Ext.Component The component (if found).
  4350. */
  4351. getComponent : function(comp){
  4352. if(Ext.isObject(comp)){
  4353. comp = comp.getItemId();
  4354. }
  4355. return this.items.get(comp);
  4356. },
  4357. // private
  4358. lookupComponent : function(comp){
  4359. if(Ext.isString(comp)){
  4360. return Ext.ComponentMgr.get(comp);
  4361. }else if(!comp.events){
  4362. return this.createComponent(comp);
  4363. }
  4364. return comp;
  4365. },
  4366. // private
  4367. createComponent : function(config, defaultType){
  4368. if (config.render) {
  4369. return config;
  4370. }
  4371. // add in ownerCt at creation time but then immediately
  4372. // remove so that onBeforeAdd can handle it
  4373. var c = Ext.create(Ext.apply({
  4374. ownerCt: this
  4375. }, config), defaultType || this.defaultType);
  4376. delete c.initialConfig.ownerCt;
  4377. delete c.ownerCt;
  4378. return c;
  4379. },
  4380. /**
  4381. * @private
  4382. * We can only lay out if there is a view area in which to layout.
  4383. * display:none on the layout target, *or any of its parent elements* will mean it has no view area.
  4384. */
  4385. canLayout : function() {
  4386. var el = this.getVisibilityEl();
  4387. return el && el.dom && !el.isStyle("display", "none");
  4388. },
  4389. /**
  4390. * Force this container's layout to be recalculated. A call to this function is required after adding a new component
  4391. * to an already rendered container, or possibly after changing sizing/position properties of child components.
  4392. * @param {Boolean} shallow (optional) True to only calc the layout of this component, and let child components auto
  4393. * calc layouts as required (defaults to false, which calls doLayout recursively for each subcontainer)
  4394. * @param {Boolean} force (optional) True to force a layout to occur, even if the item is hidden.
  4395. * @return {Ext.Container} this
  4396. */
  4397. doLayout : function(shallow, force){
  4398. var rendered = this.rendered,
  4399. forceLayout = force || this.forceLayout;
  4400. if(this.collapsed || !this.canLayout()){
  4401. this.deferLayout = this.deferLayout || !shallow;
  4402. if(!forceLayout){
  4403. return;
  4404. }
  4405. shallow = shallow && !this.deferLayout;
  4406. } else {
  4407. delete this.deferLayout;
  4408. }
  4409. if(rendered && this.layout){
  4410. this.layout.layout();
  4411. }
  4412. if(shallow !== true && this.items){
  4413. var cs = this.items.items;
  4414. for(var i = 0, len = cs.length; i < len; i++){
  4415. var c = cs[i];
  4416. if(c.doLayout){
  4417. c.doLayout(false, forceLayout);
  4418. }
  4419. }
  4420. }
  4421. if(rendered){
  4422. this.onLayout(shallow, forceLayout);
  4423. }
  4424. // Initial layout completed
  4425. this.hasLayout = true;
  4426. delete this.forceLayout;
  4427. },
  4428. onLayout : Ext.emptyFn,
  4429. // private
  4430. shouldBufferLayout: function(){
  4431. /*
  4432. * Returns true if the container should buffer a layout.
  4433. * This is true only if the container has previously been laid out
  4434. * and has a parent container that is pending a layout.
  4435. */
  4436. var hl = this.hasLayout;
  4437. if(this.ownerCt){
  4438. // Only ever buffer if we've laid out the first time and we have one pending.
  4439. return hl ? !this.hasLayoutPending() : false;
  4440. }
  4441. // Never buffer initial layout
  4442. return hl;
  4443. },
  4444. // private
  4445. hasLayoutPending: function(){
  4446. // Traverse hierarchy to see if any parent container has a pending layout.
  4447. var pending = false;
  4448. this.ownerCt.bubble(function(c){
  4449. if(c.layoutPending){
  4450. pending = true;
  4451. return false;
  4452. }
  4453. });
  4454. return pending;
  4455. },
  4456. onShow : function(){
  4457. // removes css classes that were added to hide
  4458. Ext.Container.superclass.onShow.call(this);
  4459. // If we were sized during the time we were hidden, layout.
  4460. if(Ext.isDefined(this.deferLayout)){
  4461. delete this.deferLayout;
  4462. this.doLayout(true);
  4463. }
  4464. },
  4465. /**
  4466. * Returns the layout currently in use by the container. If the container does not currently have a layout
  4467. * set, a default {@link Ext.layout.ContainerLayout} will be created and set as the container's layout.
  4468. * @return {ContainerLayout} layout The container's layout
  4469. */
  4470. getLayout : function(){
  4471. if(!this.layout){
  4472. var layout = new Ext.layout.AutoLayout(this.layoutConfig);
  4473. this.setLayout(layout);
  4474. }
  4475. return this.layout;
  4476. },
  4477. // private
  4478. beforeDestroy : function(){
  4479. var c;
  4480. if(this.items){
  4481. while(c = this.items.first()){
  4482. this.doRemove(c, true);
  4483. }
  4484. }
  4485. if(this.monitorResize){
  4486. Ext.EventManager.removeResizeListener(this.doLayout, this);
  4487. }
  4488. Ext.destroy(this.layout);
  4489. Ext.Container.superclass.beforeDestroy.call(this);
  4490. },
  4491. /**
  4492. * Cascades down the component/container heirarchy from this component (called first), calling the specified function with
  4493. * each component. The scope (<i>this</i>) of
  4494. * function call will be the scope provided or the current component. The arguments to the function
  4495. * will be the args provided or the current component. If the function returns false at any point,
  4496. * the cascade is stopped on that branch.
  4497. * @param {Function} fn The function to call
  4498. * @param {Object} scope (optional) The scope of the function (defaults to current component)
  4499. * @param {Array} args (optional) The args to call the function with (defaults to passing the current component)
  4500. * @return {Ext.Container} this
  4501. */
  4502. cascade : function(fn, scope, args){
  4503. if(fn.apply(scope || this, args || [this]) !== false){
  4504. if(this.items){
  4505. var cs = this.items.items;
  4506. for(var i = 0, len = cs.length; i < len; i++){
  4507. if(cs[i].cascade){
  4508. cs[i].cascade(fn, scope, args);
  4509. }else{
  4510. fn.apply(scope || cs[i], args || [cs[i]]);
  4511. }
  4512. }
  4513. }
  4514. }
  4515. return this;
  4516. },
  4517. /**
  4518. * Find a component under this container at any level by id
  4519. * @param {String} id
  4520. * @deprecated Fairly useless method, since you can just use Ext.getCmp. Should be removed for 4.0
  4521. * If you need to test if an id belongs to a container, you can use getCmp and findParent*.
  4522. * @return Ext.Component
  4523. */
  4524. findById : function(id){
  4525. var m = null,
  4526. ct = this;
  4527. this.cascade(function(c){
  4528. if(ct != c && c.id === id){
  4529. m = c;
  4530. return false;
  4531. }
  4532. });
  4533. return m;
  4534. },
  4535. /**
  4536. * Find a component under this container at any level by xtype or class
  4537. * @param {String/Class} xtype The xtype string for a component, or the class of the component directly
  4538. * @param {Boolean} shallow (optional) False to check whether this Component is descended from the xtype (this is
  4539. * the default), or true to check whether this Component is directly of the specified xtype.
  4540. * @return {Array} Array of Ext.Components
  4541. */
  4542. findByType : function(xtype, shallow){
  4543. return this.findBy(function(c){
  4544. return c.isXType(xtype, shallow);
  4545. });
  4546. },
  4547. /**
  4548. * Find a component under this container at any level by property
  4549. * @param {String} prop
  4550. * @param {String} value
  4551. * @return {Array} Array of Ext.Components
  4552. */
  4553. find : function(prop, value){
  4554. return this.findBy(function(c){
  4555. return c[prop] === value;
  4556. });
  4557. },
  4558. /**
  4559. * Find a component under this container at any level by a custom function. If the passed function returns
  4560. * true, the component will be included in the results. The passed function is called with the arguments (component, this container).
  4561. * @param {Function} fn The function to call
  4562. * @param {Object} scope (optional)
  4563. * @return {Array} Array of Ext.Components
  4564. */
  4565. findBy : function(fn, scope){
  4566. var m = [], ct = this;
  4567. this.cascade(function(c){
  4568. if(ct != c && fn.call(scope || c, c, ct) === true){
  4569. m.push(c);
  4570. }
  4571. });
  4572. return m;
  4573. },
  4574. /**
  4575. * Get a component contained by this container (alias for items.get(key))
  4576. * @param {String/Number} key The index or id of the component
  4577. * @deprecated Should be removed in 4.0, since getComponent does the same thing.
  4578. * @return {Ext.Component} Ext.Component
  4579. */
  4580. get : function(key){
  4581. return this.getComponent(key);
  4582. }
  4583. });
  4584. Ext.Container.LAYOUTS = {};
  4585. Ext.reg('container', Ext.Container);
  4586. /**
  4587. * @class Ext.layout.ContainerLayout
  4588. * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
  4589. * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
  4590. */
  4591. Ext.layout.ContainerLayout = Ext.extend(Object, {
  4592. /**
  4593. * @cfg {String} extraCls
  4594. * <p>An optional extra CSS class that will be added to the container. This can be useful for adding
  4595. * customized styles to the container or any of its children using standard CSS rules. See
  4596. * {@link Ext.Component}.{@link Ext.Component#ctCls ctCls} also.</p>
  4597. * <p><b>Note</b>: <tt>extraCls</tt> defaults to <tt>''</tt> except for the following classes
  4598. * which assign a value by default:
  4599. * <div class="mdetail-params"><ul>
  4600. * <li>{@link Ext.layout.AbsoluteLayout Absolute Layout} : <tt>'x-abs-layout-item'</tt></li>
  4601. * <li>{@link Ext.layout.Box Box Layout} : <tt>'x-box-item'</tt></li>
  4602. * <li>{@link Ext.layout.ColumnLayout Column Layout} : <tt>'x-column'</tt></li>
  4603. * </ul></div>
  4604. * To configure the above Classes with an extra CSS class append to the default. For example,
  4605. * for ColumnLayout:<pre><code>
  4606. * extraCls: 'x-column custom-class'
  4607. * </code></pre>
  4608. * </p>
  4609. */
  4610. /**
  4611. * @cfg {Boolean} renderHidden
  4612. * True to hide each contained item on render (defaults to false).
  4613. */
  4614. /**
  4615. * A reference to the {@link Ext.Component} that is active. For example, <pre><code>
  4616. * if(myPanel.layout.activeItem.id == 'item-1') { ... }
  4617. * </code></pre>
  4618. * <tt>activeItem</tt> only applies to layout styles that can display items one at a time
  4619. * (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout}
  4620. * and {@link Ext.layout.FitLayout}). Read-only. Related to {@link Ext.Container#activeItem}.
  4621. * @type {Ext.Component}
  4622. * @property activeItem
  4623. */
  4624. // private
  4625. monitorResize:false,
  4626. // private
  4627. activeItem : null,
  4628. constructor : function(config){
  4629. this.id = Ext.id(null, 'ext-layout-');
  4630. Ext.apply(this, config);
  4631. },
  4632. type: 'container',
  4633. /* Workaround for how IE measures autoWidth elements. It prefers bottom-up measurements
  4634. whereas other browser prefer top-down. We will hide all target child elements before we measure and
  4635. put them back to get an accurate measurement.
  4636. */
  4637. IEMeasureHack : function(target, viewFlag) {
  4638. var tChildren = target.dom.childNodes, tLen = tChildren.length, c, d = [], e, i, ret;
  4639. for (i = 0 ; i < tLen ; i++) {
  4640. c = tChildren[i];
  4641. e = Ext.get(c);
  4642. if (e) {
  4643. d[i] = e.getStyle('display');
  4644. e.setStyle({display: 'none'});
  4645. }
  4646. }
  4647. ret = target ? target.getViewSize(viewFlag) : {};
  4648. for (i = 0 ; i < tLen ; i++) {
  4649. c = tChildren[i];
  4650. e = Ext.get(c);
  4651. if (e) {
  4652. e.setStyle({display: d[i]});
  4653. }
  4654. }
  4655. return ret;
  4656. },
  4657. // Placeholder for the derived layouts
  4658. getLayoutTargetSize : Ext.EmptyFn,
  4659. // private
  4660. layout : function(){
  4661. var ct = this.container, target = ct.getLayoutTarget();
  4662. if(!(this.hasLayout || Ext.isEmpty(this.targetCls))){
  4663. target.addClass(this.targetCls);
  4664. }
  4665. this.onLayout(ct, target);
  4666. ct.fireEvent('afterlayout', ct, this);
  4667. },
  4668. // private
  4669. onLayout : function(ct, target){
  4670. this.renderAll(ct, target);
  4671. },
  4672. // private
  4673. isValidParent : function(c, target){
  4674. return target && c.getPositionEl().dom.parentNode == (target.dom || target);
  4675. },
  4676. // private
  4677. renderAll : function(ct, target){
  4678. var items = ct.items.items, i, c, len = items.length;
  4679. for(i = 0; i < len; i++) {
  4680. c = items[i];
  4681. if(c && (!c.rendered || !this.isValidParent(c, target))){
  4682. this.renderItem(c, i, target);
  4683. }
  4684. }
  4685. },
  4686. /**
  4687. * @private
  4688. * Renders the given Component into the target Element. If the Component is already rendered,
  4689. * it is moved to the provided target instead.
  4690. * @param {Ext.Component} c The Component to render
  4691. * @param {Number} position The position within the target to render the item to
  4692. * @param {Ext.Element} target The target Element
  4693. */
  4694. renderItem : function(c, position, target){
  4695. if (c) {
  4696. if (!c.rendered) {
  4697. c.render(target, position);
  4698. this.configureItem(c);
  4699. } else if (!this.isValidParent(c, target)) {
  4700. if (Ext.isNumber(position)) {
  4701. position = target.dom.childNodes[position];
  4702. }
  4703. target.dom.insertBefore(c.getPositionEl().dom, position || null);
  4704. c.container = target;
  4705. this.configureItem(c);
  4706. }
  4707. }
  4708. },
  4709. // private.
  4710. // Get all rendered items to lay out.
  4711. getRenderedItems: function(ct){
  4712. var t = ct.getLayoutTarget(), cti = ct.items.items, len = cti.length, i, c, items = [];
  4713. for (i = 0; i < len; i++) {
  4714. if((c = cti[i]).rendered && this.isValidParent(c, t) && c.shouldLayout !== false){
  4715. items.push(c);
  4716. }
  4717. };
  4718. return items;
  4719. },
  4720. /**
  4721. * @private
  4722. * Applies extraCls and hides the item if renderHidden is true
  4723. */
  4724. configureItem: function(c){
  4725. if (this.extraCls) {
  4726. var t = c.getPositionEl ? c.getPositionEl() : c;
  4727. t.addClass(this.extraCls);
  4728. }
  4729. // If we are forcing a layout, do so *before* we hide so elements have height/width
  4730. if (c.doLayout && this.forceLayout) {
  4731. c.doLayout();
  4732. }
  4733. if (this.renderHidden && c != this.activeItem) {
  4734. c.hide();
  4735. }
  4736. },
  4737. onRemove: function(c){
  4738. if(this.activeItem == c){
  4739. delete this.activeItem;
  4740. }
  4741. if(c.rendered && this.extraCls){
  4742. var t = c.getPositionEl ? c.getPositionEl() : c;
  4743. t.removeClass(this.extraCls);
  4744. }
  4745. },
  4746. afterRemove: function(c){
  4747. if(c.removeRestore){
  4748. c.removeMode = 'container';
  4749. delete c.removeRestore;
  4750. }
  4751. },
  4752. // private
  4753. onResize: function(){
  4754. var ct = this.container,
  4755. b;
  4756. if(ct.collapsed){
  4757. return;
  4758. }
  4759. if(b = ct.bufferResize && ct.shouldBufferLayout()){
  4760. if(!this.resizeTask){
  4761. this.resizeTask = new Ext.util.DelayedTask(this.runLayout, this);
  4762. this.resizeBuffer = Ext.isNumber(b) ? b : 50;
  4763. }
  4764. ct.layoutPending = true;
  4765. this.resizeTask.delay(this.resizeBuffer);
  4766. }else{
  4767. this.runLayout();
  4768. }
  4769. },
  4770. runLayout: function(){
  4771. var ct = this.container;
  4772. this.layout();
  4773. ct.onLayout();
  4774. delete ct.layoutPending;
  4775. },
  4776. // private
  4777. setContainer : function(ct){
  4778. /**
  4779. * This monitorResize flag will be renamed soon as to avoid confusion
  4780. * with the Container version which hooks onWindowResize to doLayout
  4781. *
  4782. * monitorResize flag in this context attaches the resize event between
  4783. * a container and it's layout
  4784. */
  4785. if(this.monitorResize && ct != this.container){
  4786. var old = this.container;
  4787. if(old){
  4788. old.un(old.resizeEvent, this.onResize, this);
  4789. }
  4790. if(ct){
  4791. ct.on(ct.resizeEvent, this.onResize, this);
  4792. }
  4793. }
  4794. this.container = ct;
  4795. },
  4796. /**
  4797. * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
  4798. * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
  4799. * @param {Number|String} v The encoded margins
  4800. * @return {Object} An object with margin sizes for top, right, bottom and left
  4801. */
  4802. parseMargins : function(v){
  4803. if (Ext.isNumber(v)) {
  4804. v = v.toString();
  4805. }
  4806. var ms = v.split(' '),
  4807. len = ms.length;
  4808. if (len == 1) {
  4809. ms[1] = ms[2] = ms[3] = ms[0];
  4810. } else if(len == 2) {
  4811. ms[2] = ms[0];
  4812. ms[3] = ms[1];
  4813. } else if(len == 3) {
  4814. ms[3] = ms[1];
  4815. }
  4816. return {
  4817. top :parseInt(ms[0], 10) || 0,
  4818. right :parseInt(ms[1], 10) || 0,
  4819. bottom:parseInt(ms[2], 10) || 0,
  4820. left :parseInt(ms[3], 10) || 0
  4821. };
  4822. },
  4823. /**
  4824. * The {@link Ext.Template Ext.Template} used by Field rendering layout classes (such as
  4825. * {@link Ext.layout.FormLayout}) to create the DOM structure of a fully wrapped,
  4826. * labeled and styled form Field. A default Template is supplied, but this may be
  4827. * overriden to create custom field structures. The template processes values returned from
  4828. * {@link Ext.layout.FormLayout#getTemplateArgs}.
  4829. * @property fieldTpl
  4830. * @type Ext.Template
  4831. */
  4832. fieldTpl: (function() {
  4833. var t = new Ext.Template(
  4834. '<div class="x-form-item {itemCls}" tabIndex="-1">',
  4835. '<label for="{id}" style="{labelStyle}" class="x-form-item-label">{label}{labelSeparator}</label>',
  4836. '<div class="x-form-element" id="x-form-el-{id}" style="{elementStyle}">',
  4837. '</div><div class="{clearCls}"></div>',
  4838. '</div>'
  4839. );
  4840. t.disableFormats = true;
  4841. return t.compile();
  4842. })(),
  4843. /*
  4844. * Destroys this layout. This is a template method that is empty by default, but should be implemented
  4845. * by subclasses that require explicit destruction to purge event handlers or remove DOM nodes.
  4846. * @protected
  4847. */
  4848. destroy : function(){
  4849. // Stop any buffered layout tasks
  4850. if(this.resizeTask && this.resizeTask.cancel){
  4851. this.resizeTask.cancel();
  4852. }
  4853. if(this.container) {
  4854. this.container.un(this.container.resizeEvent, this.onResize, this);
  4855. }
  4856. if(!Ext.isEmpty(this.targetCls)){
  4857. var target = this.container.getLayoutTarget();
  4858. if(target){
  4859. target.removeClass(this.targetCls);
  4860. }
  4861. }
  4862. }
  4863. });/**
  4864. * @class Ext.layout.AutoLayout
  4865. * <p>The AutoLayout is the default layout manager delegated by {@link Ext.Container} to
  4866. * render any child Components when no <tt>{@link Ext.Container#layout layout}</tt> is configured into
  4867. * a {@link Ext.Container Container}.</tt>. AutoLayout provides only a passthrough of any layout calls
  4868. * to any child containers.</p>
  4869. */
  4870. Ext.layout.AutoLayout = Ext.extend(Ext.layout.ContainerLayout, {
  4871. type: 'auto',
  4872. monitorResize: true,
  4873. onLayout : function(ct, target){
  4874. Ext.layout.AutoLayout.superclass.onLayout.call(this, ct, target);
  4875. var cs = this.getRenderedItems(ct), len = cs.length, i, c;
  4876. for(i = 0; i < len; i++){
  4877. c = cs[i];
  4878. if (c.doLayout){
  4879. // Shallow layout children
  4880. c.doLayout(true);
  4881. }
  4882. }
  4883. }
  4884. });
  4885. Ext.Container.LAYOUTS['auto'] = Ext.layout.AutoLayout;
  4886. /**
  4887. * @class Ext.layout.FitLayout
  4888. * @extends Ext.layout.ContainerLayout
  4889. * <p>This is a base class for layouts that contain <b>a single item</b> that automatically expands to fill the layout's
  4890. * container. This class is intended to be extended or created via the <tt>layout:'fit'</tt> {@link Ext.Container#layout}
  4891. * config, and should generally not need to be created directly via the new keyword.</p>
  4892. * <p>FitLayout does not have any direct config options (other than inherited ones). To fit a panel to a container
  4893. * using FitLayout, simply set layout:'fit' on the container and add a single panel to it. If the container has
  4894. * multiple panels, only the first one will be displayed. Example usage:</p>
  4895. * <pre><code>
  4896. var p = new Ext.Panel({
  4897. title: 'Fit Layout',
  4898. layout:'fit',
  4899. items: {
  4900. title: 'Inner Panel',
  4901. html: '&lt;p&gt;This is the inner panel content&lt;/p&gt;',
  4902. border: false
  4903. }
  4904. });
  4905. </code></pre>
  4906. */
  4907. Ext.layout.FitLayout = Ext.extend(Ext.layout.ContainerLayout, {
  4908. // private
  4909. monitorResize:true,
  4910. type: 'fit',
  4911. getLayoutTargetSize : function() {
  4912. var target = this.container.getLayoutTarget();
  4913. if (!target) {
  4914. return {};
  4915. }
  4916. // Style Sized (scrollbars not included)
  4917. return target.getStyleSize();
  4918. },
  4919. // private
  4920. onLayout : function(ct, target){
  4921. Ext.layout.FitLayout.superclass.onLayout.call(this, ct, target);
  4922. if(!ct.collapsed){
  4923. this.setItemSize(this.activeItem || ct.items.itemAt(0), this.getLayoutTargetSize());
  4924. }
  4925. },
  4926. // private
  4927. setItemSize : function(item, size){
  4928. if(item && size.height > 0){ // display none?
  4929. item.setSize(size);
  4930. }
  4931. }
  4932. });
  4933. Ext.Container.LAYOUTS['fit'] = Ext.layout.FitLayout;/**
  4934. * @class Ext.layout.CardLayout
  4935. * @extends Ext.layout.FitLayout
  4936. * <p>This layout manages multiple child Components, each fitted to the Container, where only a single child Component can be
  4937. * visible at any given time. This layout style is most commonly used for wizards, tab implementations, etc.
  4938. * This class is intended to be extended or created via the layout:'card' {@link Ext.Container#layout} config,
  4939. * and should generally not need to be created directly via the new keyword.</p>
  4940. * <p>The CardLayout's focal method is {@link #setActiveItem}. Since only one panel is displayed at a time,
  4941. * the only way to move from one Component to the next is by calling setActiveItem, passing the id or index of
  4942. * the next panel to display. The layout itself does not provide a user interface for handling this navigation,
  4943. * so that functionality must be provided by the developer.</p>
  4944. * <p>In the following example, a simplistic wizard setup is demonstrated. A button bar is added
  4945. * to the footer of the containing panel to provide navigation buttons. The buttons will be handled by a
  4946. * common navigation routine -- for this example, the implementation of that routine has been ommitted since
  4947. * it can be any type of custom logic. Note that other uses of a CardLayout (like a tab control) would require a
  4948. * completely different implementation. For serious implementations, a better approach would be to extend
  4949. * CardLayout to provide the custom functionality needed. Example usage:</p>
  4950. * <pre><code>
  4951. var navHandler = function(direction){
  4952. // This routine could contain business logic required to manage the navigation steps.
  4953. // It would call setActiveItem as needed, manage navigation button state, handle any
  4954. // branching logic that might be required, handle alternate actions like cancellation
  4955. // or finalization, etc. A complete wizard implementation could get pretty
  4956. // sophisticated depending on the complexity required, and should probably be
  4957. // done as a subclass of CardLayout in a real-world implementation.
  4958. };
  4959. var card = new Ext.Panel({
  4960. title: 'Example Wizard',
  4961. layout:'card',
  4962. activeItem: 0, // make sure the active item is set on the container config!
  4963. bodyStyle: 'padding:15px',
  4964. defaults: {
  4965. // applied to each contained panel
  4966. border:false
  4967. },
  4968. // just an example of one possible navigation scheme, using buttons
  4969. bbar: [
  4970. {
  4971. id: 'move-prev',
  4972. text: 'Back',
  4973. handler: navHandler.createDelegate(this, [-1]),
  4974. disabled: true
  4975. },
  4976. '->', // greedy spacer so that the buttons are aligned to each side
  4977. {
  4978. id: 'move-next',
  4979. text: 'Next',
  4980. handler: navHandler.createDelegate(this, [1])
  4981. }
  4982. ],
  4983. // the panels (or "cards") within the layout
  4984. items: [{
  4985. id: 'card-0',
  4986. html: '&lt;h1&gt;Welcome to the Wizard!&lt;/h1&gt;&lt;p&gt;Step 1 of 3&lt;/p&gt;'
  4987. },{
  4988. id: 'card-1',
  4989. html: '&lt;p&gt;Step 2 of 3&lt;/p&gt;'
  4990. },{
  4991. id: 'card-2',
  4992. html: '&lt;h1&gt;Congratulations!&lt;/h1&gt;&lt;p&gt;Step 3 of 3 - Complete&lt;/p&gt;'
  4993. }]
  4994. });
  4995. </code></pre>
  4996. */
  4997. Ext.layout.CardLayout = Ext.extend(Ext.layout.FitLayout, {
  4998. /**
  4999. * @cfg {Boolean} deferredRender
  5000. * True to render each contained item at the time it becomes active, false to render all contained items
  5001. * as soon as the layout is rendered (defaults to false). If there is a significant amount of content or
  5002. * a lot of heavy controls being rendered into panels that are not displayed by default, setting this to
  5003. * true might improve performance.
  5004. */
  5005. deferredRender : false,
  5006. /**
  5007. * @cfg {Boolean} layoutOnCardChange
  5008. * True to force a layout of the active item when the active card is changed. Defaults to false.
  5009. */
  5010. layoutOnCardChange : false,
  5011. /**
  5012. * @cfg {Boolean} renderHidden @hide
  5013. */
  5014. // private
  5015. renderHidden : true,
  5016. type: 'card',
  5017. /**
  5018. * Sets the active (visible) item in the layout.
  5019. * @param {String/Number} item The string component id or numeric index of the item to activate
  5020. */
  5021. setActiveItem : function(item){
  5022. var ai = this.activeItem,
  5023. ct = this.container;
  5024. item = ct.getComponent(item);
  5025. // Is this a valid, different card?
  5026. if(item && ai != item){
  5027. // Changing cards, hide the current one
  5028. if(ai){
  5029. ai.hide();
  5030. if (ai.hidden !== true) {
  5031. return false;
  5032. }
  5033. ai.fireEvent('deactivate', ai);
  5034. }
  5035. var layout = item.doLayout && (this.layoutOnCardChange || !item.rendered);
  5036. // Change activeItem reference
  5037. this.activeItem = item;
  5038. // The container is about to get a recursive layout, remove any deferLayout reference
  5039. // because it will trigger a redundant layout.
  5040. delete item.deferLayout;
  5041. // Show the new component
  5042. item.show();
  5043. this.layout();
  5044. if(layout){
  5045. item.doLayout();
  5046. }
  5047. item.fireEvent('activate', item);
  5048. }
  5049. },
  5050. // private
  5051. renderAll : function(ct, target){
  5052. if(this.deferredRender){
  5053. this.renderItem(this.activeItem, undefined, target);
  5054. }else{
  5055. Ext.layout.CardLayout.superclass.renderAll.call(this, ct, target);
  5056. }
  5057. }
  5058. });
  5059. Ext.Container.LAYOUTS['card'] = Ext.layout.CardLayout;
  5060. /**
  5061. * @class Ext.layout.AnchorLayout
  5062. * @extends Ext.layout.ContainerLayout
  5063. * <p>This is a layout that enables anchoring of contained elements relative to the container's dimensions.
  5064. * If the container is resized, all anchored items are automatically rerendered according to their
  5065. * <b><tt>{@link #anchor}</tt></b> rules.</p>
  5066. * <p>This class is intended to be extended or created via the layout:'anchor' {@link Ext.Container#layout}
  5067. * config, and should generally not need to be created directly via the new keyword.</p>
  5068. * <p>AnchorLayout does not have any direct config options (other than inherited ones). By default,
  5069. * AnchorLayout will calculate anchor measurements based on the size of the container itself. However, the
  5070. * container using the AnchorLayout can supply an anchoring-specific config property of <b>anchorSize</b>.
  5071. * If anchorSize is specifed, the layout will use it as a virtual container for the purposes of calculating
  5072. * anchor measurements based on it instead, allowing the container to be sized independently of the anchoring
  5073. * logic if necessary. For example:</p>
  5074. * <pre><code>
  5075. var viewport = new Ext.Viewport({
  5076. layout:'anchor',
  5077. anchorSize: {width:800, height:600},
  5078. items:[{
  5079. title:'Item 1',
  5080. html:'Content 1',
  5081. width:800,
  5082. anchor:'right 20%'
  5083. },{
  5084. title:'Item 2',
  5085. html:'Content 2',
  5086. width:300,
  5087. anchor:'50% 30%'
  5088. },{
  5089. title:'Item 3',
  5090. html:'Content 3',
  5091. width:600,
  5092. anchor:'-100 50%'
  5093. }]
  5094. });
  5095. * </code></pre>
  5096. */
  5097. Ext.layout.AnchorLayout = Ext.extend(Ext.layout.ContainerLayout, {
  5098. /**
  5099. * @cfg {String} anchor
  5100. * <p>This configuation option is to be applied to <b>child <tt>items</tt></b> of a container managed by
  5101. * this layout (ie. configured with <tt>layout:'anchor'</tt>).</p><br/>
  5102. *
  5103. * <p>This value is what tells the layout how an item should be anchored to the container. <tt>items</tt>
  5104. * added to an AnchorLayout accept an anchoring-specific config property of <b>anchor</b> which is a string
  5105. * containing two values: the horizontal anchor value and the vertical anchor value (for example, '100% 50%').
  5106. * The following types of anchor values are supported:<div class="mdetail-params"><ul>
  5107. *
  5108. * <li><b>Percentage</b> : Any value between 1 and 100, expressed as a percentage.<div class="sub-desc">
  5109. * The first anchor is the percentage width that the item should take up within the container, and the
  5110. * second is the percentage height. For example:<pre><code>
  5111. // two values specified
  5112. anchor: '100% 50%' // render item complete width of the container and
  5113. // 1/2 height of the container
  5114. // one value specified
  5115. anchor: '100%' // the width value; the height will default to auto
  5116. * </code></pre></div></li>
  5117. *
  5118. * <li><b>Offsets</b> : Any positive or negative integer value.<div class="sub-desc">
  5119. * This is a raw adjustment where the first anchor is the offset from the right edge of the container,
  5120. * and the second is the offset from the bottom edge. For example:<pre><code>
  5121. // two values specified
  5122. anchor: '-50 -100' // render item the complete width of the container
  5123. // minus 50 pixels and
  5124. // the complete height minus 100 pixels.
  5125. // one value specified
  5126. anchor: '-50' // anchor value is assumed to be the right offset value
  5127. // bottom offset will default to 0
  5128. * </code></pre></div></li>
  5129. *
  5130. * <li><b>Sides</b> : Valid values are <tt>'right'</tt> (or <tt>'r'</tt>) and <tt>'bottom'</tt>
  5131. * (or <tt>'b'</tt>).<div class="sub-desc">
  5132. * Either the container must have a fixed size or an anchorSize config value defined at render time in
  5133. * order for these to have any effect.</div></li>
  5134. *
  5135. * <li><b>Mixed</b> : <div class="sub-desc">
  5136. * Anchor values can also be mixed as needed. For example, to render the width offset from the container
  5137. * right edge by 50 pixels and 75% of the container's height use:
  5138. * <pre><code>
  5139. anchor: '-50 75%'
  5140. * </code></pre></div></li>
  5141. *
  5142. *
  5143. * </ul></div>
  5144. */
  5145. // private
  5146. monitorResize : true,
  5147. type : 'anchor',
  5148. /**
  5149. * @cfg {String} defaultAnchor
  5150. *
  5151. * default anchor for all child container items applied if no anchor or specific width is set on the child item. Defaults to '100%'.
  5152. *
  5153. */
  5154. defaultAnchor : '100%',
  5155. parseAnchorRE : /^(r|right|b|bottom)$/i,
  5156. getLayoutTargetSize : function() {
  5157. var target = this.container.getLayoutTarget(), ret = {};
  5158. if (target) {
  5159. ret = target.getViewSize();
  5160. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  5161. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  5162. // with getViewSize
  5163. if (Ext.isIE && Ext.isStrict && ret.width == 0){
  5164. ret = target.getStyleSize();
  5165. }
  5166. ret.width -= target.getPadding('lr');
  5167. ret.height -= target.getPadding('tb');
  5168. }
  5169. return ret;
  5170. },
  5171. // private
  5172. onLayout : function(container, target) {
  5173. Ext.layout.AnchorLayout.superclass.onLayout.call(this, container, target);
  5174. var size = this.getLayoutTargetSize(),
  5175. containerWidth = size.width,
  5176. containerHeight = size.height,
  5177. overflow = target.getStyle('overflow'),
  5178. components = this.getRenderedItems(container),
  5179. len = components.length,
  5180. boxes = [],
  5181. box,
  5182. anchorWidth,
  5183. anchorHeight,
  5184. component,
  5185. anchorSpec,
  5186. calcWidth,
  5187. calcHeight,
  5188. anchorsArray,
  5189. totalHeight = 0,
  5190. i,
  5191. el;
  5192. if(containerWidth < 20 && containerHeight < 20){
  5193. return;
  5194. }
  5195. // find the container anchoring size
  5196. if(container.anchorSize) {
  5197. if(typeof container.anchorSize == 'number') {
  5198. anchorWidth = container.anchorSize;
  5199. } else {
  5200. anchorWidth = container.anchorSize.width;
  5201. anchorHeight = container.anchorSize.height;
  5202. }
  5203. } else {
  5204. anchorWidth = container.initialConfig.width;
  5205. anchorHeight = container.initialConfig.height;
  5206. }
  5207. for(i = 0; i < len; i++) {
  5208. component = components[i];
  5209. el = component.getPositionEl();
  5210. // If a child container item has no anchor and no specific width, set the child to the default anchor size
  5211. if (!component.anchor && component.items && !Ext.isNumber(component.width) && !(Ext.isIE6 && Ext.isStrict)){
  5212. component.anchor = this.defaultAnchor;
  5213. }
  5214. if(component.anchor) {
  5215. anchorSpec = component.anchorSpec;
  5216. // cache all anchor values
  5217. if(!anchorSpec){
  5218. anchorsArray = component.anchor.split(' ');
  5219. component.anchorSpec = anchorSpec = {
  5220. right: this.parseAnchor(anchorsArray[0], component.initialConfig.width, anchorWidth),
  5221. bottom: this.parseAnchor(anchorsArray[1], component.initialConfig.height, anchorHeight)
  5222. };
  5223. }
  5224. calcWidth = anchorSpec.right ? this.adjustWidthAnchor(anchorSpec.right(containerWidth) - el.getMargins('lr'), component) : undefined;
  5225. calcHeight = anchorSpec.bottom ? this.adjustHeightAnchor(anchorSpec.bottom(containerHeight) - el.getMargins('tb'), component) : undefined;
  5226. if(calcWidth || calcHeight) {
  5227. boxes.push({
  5228. component: component,
  5229. width: calcWidth || undefined,
  5230. height: calcHeight || undefined
  5231. });
  5232. }
  5233. }
  5234. }
  5235. for (i = 0, len = boxes.length; i < len; i++) {
  5236. box = boxes[i];
  5237. box.component.setSize(box.width, box.height);
  5238. }
  5239. if (overflow && overflow != 'hidden' && !this.adjustmentPass) {
  5240. var newTargetSize = this.getLayoutTargetSize();
  5241. if (newTargetSize.width != size.width || newTargetSize.height != size.height){
  5242. this.adjustmentPass = true;
  5243. this.onLayout(container, target);
  5244. }
  5245. }
  5246. delete this.adjustmentPass;
  5247. },
  5248. // private
  5249. parseAnchor : function(a, start, cstart) {
  5250. if (a && a != 'none') {
  5251. var last;
  5252. // standard anchor
  5253. if (this.parseAnchorRE.test(a)) {
  5254. var diff = cstart - start;
  5255. return function(v){
  5256. if(v !== last){
  5257. last = v;
  5258. return v - diff;
  5259. }
  5260. };
  5261. // percentage
  5262. } else if(a.indexOf('%') != -1) {
  5263. var ratio = parseFloat(a.replace('%', ''))*.01;
  5264. return function(v){
  5265. if(v !== last){
  5266. last = v;
  5267. return Math.floor(v*ratio);
  5268. }
  5269. };
  5270. // simple offset adjustment
  5271. } else {
  5272. a = parseInt(a, 10);
  5273. if (!isNaN(a)) {
  5274. return function(v) {
  5275. if (v !== last) {
  5276. last = v;
  5277. return v + a;
  5278. }
  5279. };
  5280. }
  5281. }
  5282. }
  5283. return false;
  5284. },
  5285. // private
  5286. adjustWidthAnchor : function(value, comp){
  5287. return value;
  5288. },
  5289. // private
  5290. adjustHeightAnchor : function(value, comp){
  5291. return value;
  5292. }
  5293. /**
  5294. * @property activeItem
  5295. * @hide
  5296. */
  5297. });
  5298. Ext.Container.LAYOUTS['anchor'] = Ext.layout.AnchorLayout;
  5299. /**
  5300. * @class Ext.layout.ColumnLayout
  5301. * @extends Ext.layout.ContainerLayout
  5302. * <p>This is the layout style of choice for creating structural layouts in a multi-column format where the width of
  5303. * each column can be specified as a percentage or fixed width, but the height is allowed to vary based on the content.
  5304. * This class is intended to be extended or created via the layout:'column' {@link Ext.Container#layout} config,
  5305. * and should generally not need to be created directly via the new keyword.</p>
  5306. * <p>ColumnLayout does not have any direct config options (other than inherited ones), but it does support a
  5307. * specific config property of <b><tt>columnWidth</tt></b> that can be included in the config of any panel added to it. The
  5308. * layout will use the columnWidth (if present) or width of each panel during layout to determine how to size each panel.
  5309. * If width or columnWidth is not specified for a given panel, its width will default to the panel's width (or auto).</p>
  5310. * <p>The width property is always evaluated as pixels, and must be a number greater than or equal to 1.
  5311. * The columnWidth property is always evaluated as a percentage, and must be a decimal value greater than 0 and
  5312. * less than 1 (e.g., .25).</p>
  5313. * <p>The basic rules for specifying column widths are pretty simple. The logic makes two passes through the
  5314. * set of contained panels. During the first layout pass, all panels that either have a fixed width or none
  5315. * specified (auto) are skipped, but their widths are subtracted from the overall container width. During the second
  5316. * pass, all panels with columnWidths are assigned pixel widths in proportion to their percentages based on
  5317. * the total <b>remaining</b> container width. In other words, percentage width panels are designed to fill the space
  5318. * left over by all the fixed-width and/or auto-width panels. Because of this, while you can specify any number of columns
  5319. * with different percentages, the columnWidths must always add up to 1 (or 100%) when added together, otherwise your
  5320. * layout may not render as expected. Example usage:</p>
  5321. * <pre><code>
  5322. // All columns are percentages -- they must add up to 1
  5323. var p = new Ext.Panel({
  5324. title: 'Column Layout - Percentage Only',
  5325. layout:'column',
  5326. items: [{
  5327. title: 'Column 1',
  5328. columnWidth: .25
  5329. },{
  5330. title: 'Column 2',
  5331. columnWidth: .6
  5332. },{
  5333. title: 'Column 3',
  5334. columnWidth: .15
  5335. }]
  5336. });
  5337. // Mix of width and columnWidth -- all columnWidth values must add up
  5338. // to 1. The first column will take up exactly 120px, and the last two
  5339. // columns will fill the remaining container width.
  5340. var p = new Ext.Panel({
  5341. title: 'Column Layout - Mixed',
  5342. layout:'column',
  5343. items: [{
  5344. title: 'Column 1',
  5345. width: 120
  5346. },{
  5347. title: 'Column 2',
  5348. columnWidth: .8
  5349. },{
  5350. title: 'Column 3',
  5351. columnWidth: .2
  5352. }]
  5353. });
  5354. </code></pre>
  5355. */
  5356. Ext.layout.ColumnLayout = Ext.extend(Ext.layout.ContainerLayout, {
  5357. // private
  5358. monitorResize:true,
  5359. type: 'column',
  5360. extraCls: 'x-column',
  5361. scrollOffset : 0,
  5362. // private
  5363. targetCls: 'x-column-layout-ct',
  5364. isValidParent : function(c, target){
  5365. return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
  5366. },
  5367. getLayoutTargetSize : function() {
  5368. var target = this.container.getLayoutTarget(), ret;
  5369. if (target) {
  5370. ret = target.getViewSize();
  5371. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  5372. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  5373. // with getViewSize
  5374. if (Ext.isIE && Ext.isStrict && ret.width == 0){
  5375. ret = target.getStyleSize();
  5376. }
  5377. ret.width -= target.getPadding('lr');
  5378. ret.height -= target.getPadding('tb');
  5379. }
  5380. return ret;
  5381. },
  5382. renderAll : function(ct, target) {
  5383. if(!this.innerCt){
  5384. // the innerCt prevents wrapping and shuffling while
  5385. // the container is resizing
  5386. this.innerCt = target.createChild({cls:'x-column-inner'});
  5387. this.innerCt.createChild({cls:'x-clear'});
  5388. }
  5389. Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
  5390. },
  5391. // private
  5392. onLayout : function(ct, target){
  5393. var cs = ct.items.items,
  5394. len = cs.length,
  5395. c,
  5396. i,
  5397. m,
  5398. margins = [];
  5399. this.renderAll(ct, target);
  5400. var size = this.getLayoutTargetSize();
  5401. if(size.width < 1 && size.height < 1){ // display none?
  5402. return;
  5403. }
  5404. var w = size.width - this.scrollOffset,
  5405. h = size.height,
  5406. pw = w;
  5407. this.innerCt.setWidth(w);
  5408. // some columns can be percentages while others are fixed
  5409. // so we need to make 2 passes
  5410. for(i = 0; i < len; i++){
  5411. c = cs[i];
  5412. m = c.getPositionEl().getMargins('lr');
  5413. margins[i] = m;
  5414. if(!c.columnWidth){
  5415. pw -= (c.getWidth() + m);
  5416. }
  5417. }
  5418. pw = pw < 0 ? 0 : pw;
  5419. for(i = 0; i < len; i++){
  5420. c = cs[i];
  5421. m = margins[i];
  5422. if(c.columnWidth){
  5423. c.setSize(Math.floor(c.columnWidth * pw) - m);
  5424. }
  5425. }
  5426. // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
  5427. // spaces were accounted for properly. If not, re-layout.
  5428. if (Ext.isIE) {
  5429. if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
  5430. var ts = this.getLayoutTargetSize();
  5431. if (ts.width != size.width){
  5432. this.adjustmentPass = true;
  5433. this.onLayout(ct, target);
  5434. }
  5435. }
  5436. }
  5437. delete this.adjustmentPass;
  5438. }
  5439. /**
  5440. * @property activeItem
  5441. * @hide
  5442. */
  5443. });
  5444. Ext.Container.LAYOUTS['column'] = Ext.layout.ColumnLayout;
  5445. /**
  5446. * @class Ext.layout.BorderLayout
  5447. * @extends Ext.layout.ContainerLayout
  5448. * <p>This is a multi-pane, application-oriented UI layout style that supports multiple
  5449. * nested panels, automatic {@link Ext.layout.BorderLayout.Region#split split} bars between
  5450. * {@link Ext.layout.BorderLayout.Region#BorderLayout.Region regions} and built-in
  5451. * {@link Ext.layout.BorderLayout.Region#collapsible expanding and collapsing} of regions.</p>
  5452. * <p>This class is intended to be extended or created via the <tt>layout:'border'</tt>
  5453. * {@link Ext.Container#layout} config, and should generally not need to be created directly
  5454. * via the new keyword.</p>
  5455. * <p>BorderLayout does not have any direct config options (other than inherited ones).
  5456. * All configuration options available for customizing the BorderLayout are at the
  5457. * {@link Ext.layout.BorderLayout.Region} and {@link Ext.layout.BorderLayout.SplitRegion}
  5458. * levels.</p>
  5459. * <p>Example usage:</p>
  5460. * <pre><code>
  5461. var myBorderPanel = new Ext.Panel({
  5462. {@link Ext.Component#renderTo renderTo}: document.body,
  5463. {@link Ext.BoxComponent#width width}: 700,
  5464. {@link Ext.BoxComponent#height height}: 500,
  5465. {@link Ext.Panel#title title}: 'Border Layout',
  5466. {@link Ext.Container#layout layout}: 'border',
  5467. {@link Ext.Container#items items}: [{
  5468. {@link Ext.Panel#title title}: 'South Region is resizable',
  5469. {@link Ext.layout.BorderLayout.Region#BorderLayout.Region region}: 'south', // position for region
  5470. {@link Ext.BoxComponent#height height}: 100,
  5471. {@link Ext.layout.BorderLayout.Region#split split}: true, // enable resizing
  5472. {@link Ext.SplitBar#minSize minSize}: 75, // defaults to {@link Ext.layout.BorderLayout.Region#minHeight 50}
  5473. {@link Ext.SplitBar#maxSize maxSize}: 150,
  5474. {@link Ext.layout.BorderLayout.Region#margins margins}: '0 5 5 5'
  5475. },{
  5476. // xtype: 'panel' implied by default
  5477. {@link Ext.Panel#title title}: 'West Region is collapsible',
  5478. {@link Ext.layout.BorderLayout.Region#BorderLayout.Region region}:'west',
  5479. {@link Ext.layout.BorderLayout.Region#margins margins}: '5 0 0 5',
  5480. {@link Ext.BoxComponent#width width}: 200,
  5481. {@link Ext.layout.BorderLayout.Region#collapsible collapsible}: true, // make collapsible
  5482. {@link Ext.layout.BorderLayout.Region#cmargins cmargins}: '5 5 0 5', // adjust top margin when collapsed
  5483. {@link Ext.Component#id id}: 'west-region-container',
  5484. {@link Ext.Container#layout layout}: 'fit',
  5485. {@link Ext.Panel#unstyled unstyled}: true
  5486. },{
  5487. {@link Ext.Panel#title title}: 'Center Region',
  5488. {@link Ext.layout.BorderLayout.Region#BorderLayout.Region region}: 'center', // center region is required, no width/height specified
  5489. {@link Ext.Component#xtype xtype}: 'container',
  5490. {@link Ext.Container#layout layout}: 'fit',
  5491. {@link Ext.layout.BorderLayout.Region#margins margins}: '5 5 0 0'
  5492. }]
  5493. });
  5494. </code></pre>
  5495. * <p><b><u>Notes</u></b>:</p><div class="mdetail-params"><ul>
  5496. * <li>Any container using the BorderLayout <b>must</b> have a child item with <tt>region:'center'</tt>.
  5497. * The child item in the center region will always be resized to fill the remaining space not used by
  5498. * the other regions in the layout.</li>
  5499. * <li>Any child items with a region of <tt>west</tt> or <tt>east</tt> must have <tt>width</tt> defined
  5500. * (an integer representing the number of pixels that the region should take up).</li>
  5501. * <li>Any child items with a region of <tt>north</tt> or <tt>south</tt> must have <tt>height</tt> defined.</li>
  5502. * <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
  5503. * Components within a BorderLayout, have them wrapped by an additional Container which is directly
  5504. * managed by the BorderLayout. If the region is to be collapsible, the Container used directly
  5505. * by the BorderLayout manager should be a Panel. In the following example a Container (an Ext.Panel)
  5506. * is added to the west region:
  5507. * <div style="margin-left:16px"><pre><code>
  5508. wrc = {@link Ext#getCmp Ext.getCmp}('west-region-container');
  5509. wrc.{@link Ext.Panel#removeAll removeAll}();
  5510. wrc.{@link Ext.Container#add add}({
  5511. title: 'Added Panel',
  5512. html: 'Some content'
  5513. });
  5514. wrc.{@link Ext.Container#doLayout doLayout}();
  5515. * </code></pre></div>
  5516. * </li>
  5517. * <li> To reference a {@link Ext.layout.BorderLayout.Region Region}:
  5518. * <div style="margin-left:16px"><pre><code>
  5519. wr = myBorderPanel.layout.west;
  5520. * </code></pre></div>
  5521. * </li>
  5522. * </ul></div>
  5523. */
  5524. Ext.layout.BorderLayout = Ext.extend(Ext.layout.ContainerLayout, {
  5525. // private
  5526. monitorResize:true,
  5527. // private
  5528. rendered : false,
  5529. type: 'border',
  5530. targetCls: 'x-border-layout-ct',
  5531. getLayoutTargetSize : function() {
  5532. var target = this.container.getLayoutTarget();
  5533. return target ? target.getViewSize() : {};
  5534. },
  5535. // private
  5536. onLayout : function(ct, target){
  5537. var collapsed, i, c, pos, items = ct.items.items, len = items.length;
  5538. if(!this.rendered){
  5539. collapsed = [];
  5540. for(i = 0; i < len; i++) {
  5541. c = items[i];
  5542. pos = c.region;
  5543. if(c.collapsed){
  5544. collapsed.push(c);
  5545. }
  5546. c.collapsed = false;
  5547. if(!c.rendered){
  5548. c.render(target, i);
  5549. c.getPositionEl().addClass('x-border-panel');
  5550. }
  5551. this[pos] = pos != 'center' && c.split ?
  5552. new Ext.layout.BorderLayout.SplitRegion(this, c.initialConfig, pos) :
  5553. new Ext.layout.BorderLayout.Region(this, c.initialConfig, pos);
  5554. this[pos].render(target, c);
  5555. }
  5556. this.rendered = true;
  5557. }
  5558. var size = this.getLayoutTargetSize();
  5559. if(size.width < 20 || size.height < 20){ // display none?
  5560. if(collapsed){
  5561. this.restoreCollapsed = collapsed;
  5562. }
  5563. return;
  5564. }else if(this.restoreCollapsed){
  5565. collapsed = this.restoreCollapsed;
  5566. delete this.restoreCollapsed;
  5567. }
  5568. var w = size.width, h = size.height,
  5569. centerW = w, centerH = h, centerY = 0, centerX = 0,
  5570. n = this.north, s = this.south, west = this.west, e = this.east, c = this.center,
  5571. b, m, totalWidth, totalHeight;
  5572. if(!c && Ext.layout.BorderLayout.WARN !== false){
  5573. throw 'No center region defined in BorderLayout ' + ct.id;
  5574. }
  5575. if(n && n.isVisible()){
  5576. b = n.getSize();
  5577. m = n.getMargins();
  5578. b.width = w - (m.left+m.right);
  5579. b.x = m.left;
  5580. b.y = m.top;
  5581. centerY = b.height + b.y + m.bottom;
  5582. centerH -= centerY;
  5583. n.applyLayout(b);
  5584. }
  5585. if(s && s.isVisible()){
  5586. b = s.getSize();
  5587. m = s.getMargins();
  5588. b.width = w - (m.left+m.right);
  5589. b.x = m.left;
  5590. totalHeight = (b.height + m.top + m.bottom);
  5591. b.y = h - totalHeight + m.top;
  5592. centerH -= totalHeight;
  5593. s.applyLayout(b);
  5594. }
  5595. if(west && west.isVisible()){
  5596. b = west.getSize();
  5597. m = west.getMargins();
  5598. b.height = centerH - (m.top+m.bottom);
  5599. b.x = m.left;
  5600. b.y = centerY + m.top;
  5601. totalWidth = (b.width + m.left + m.right);
  5602. centerX += totalWidth;
  5603. centerW -= totalWidth;
  5604. west.applyLayout(b);
  5605. }
  5606. if(e && e.isVisible()){
  5607. b = e.getSize();
  5608. m = e.getMargins();
  5609. b.height = centerH - (m.top+m.bottom);
  5610. totalWidth = (b.width + m.left + m.right);
  5611. b.x = w - totalWidth + m.left;
  5612. b.y = centerY + m.top;
  5613. centerW -= totalWidth;
  5614. e.applyLayout(b);
  5615. }
  5616. if(c){
  5617. m = c.getMargins();
  5618. var centerBox = {
  5619. x: centerX + m.left,
  5620. y: centerY + m.top,
  5621. width: centerW - (m.left+m.right),
  5622. height: centerH - (m.top+m.bottom)
  5623. };
  5624. c.applyLayout(centerBox);
  5625. }
  5626. if(collapsed){
  5627. for(i = 0, len = collapsed.length; i < len; i++){
  5628. collapsed[i].collapse(false);
  5629. }
  5630. }
  5631. if(Ext.isIE && Ext.isStrict){ // workaround IE strict repainting issue
  5632. target.repaint();
  5633. }
  5634. // Putting a border layout into an overflowed container is NOT correct and will make a second layout pass necessary.
  5635. if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
  5636. var ts = this.getLayoutTargetSize();
  5637. if (ts.width != size.width || ts.height != size.height){
  5638. this.adjustmentPass = true;
  5639. this.onLayout(ct, target);
  5640. }
  5641. }
  5642. delete this.adjustmentPass;
  5643. },
  5644. destroy: function() {
  5645. var r = ['north', 'south', 'east', 'west'], i, region;
  5646. for (i = 0; i < r.length; i++) {
  5647. region = this[r[i]];
  5648. if(region){
  5649. if(region.destroy){
  5650. region.destroy();
  5651. }else if (region.split){
  5652. region.split.destroy(true);
  5653. }
  5654. }
  5655. }
  5656. Ext.layout.BorderLayout.superclass.destroy.call(this);
  5657. }
  5658. /**
  5659. * @property activeItem
  5660. * @hide
  5661. */
  5662. });
  5663. /**
  5664. * @class Ext.layout.BorderLayout.Region
  5665. * <p>This is a region of a {@link Ext.layout.BorderLayout BorderLayout} that acts as a subcontainer
  5666. * within the layout. Each region has its own {@link Ext.layout.ContainerLayout layout} that is
  5667. * independent of other regions and the containing BorderLayout, and can be any of the
  5668. * {@link Ext.layout.ContainerLayout valid Ext layout types}.</p>
  5669. * <p>Region size is managed automatically and cannot be changed by the user -- for
  5670. * {@link #split resizable regions}, see {@link Ext.layout.BorderLayout.SplitRegion}.</p>
  5671. * @constructor
  5672. * Create a new Region.
  5673. * @param {Layout} layout The {@link Ext.layout.BorderLayout BorderLayout} instance that is managing this Region.
  5674. * @param {Object} config The configuration options
  5675. * @param {String} position The region position. Valid values are: <tt>north</tt>, <tt>south</tt>,
  5676. * <tt>east</tt>, <tt>west</tt> and <tt>center</tt>. Every {@link Ext.layout.BorderLayout BorderLayout}
  5677. * <b>must have a center region</b> for the primary content -- all other regions are optional.
  5678. */
  5679. Ext.layout.BorderLayout.Region = function(layout, config, pos){
  5680. Ext.apply(this, config);
  5681. this.layout = layout;
  5682. this.position = pos;
  5683. this.state = {};
  5684. if(typeof this.margins == 'string'){
  5685. this.margins = this.layout.parseMargins(this.margins);
  5686. }
  5687. this.margins = Ext.applyIf(this.margins || {}, this.defaultMargins);
  5688. if(this.collapsible){
  5689. if(typeof this.cmargins == 'string'){
  5690. this.cmargins = this.layout.parseMargins(this.cmargins);
  5691. }
  5692. if(this.collapseMode == 'mini' && !this.cmargins){
  5693. this.cmargins = {left:0,top:0,right:0,bottom:0};
  5694. }else{
  5695. this.cmargins = Ext.applyIf(this.cmargins || {},
  5696. pos == 'north' || pos == 'south' ? this.defaultNSCMargins : this.defaultEWCMargins);
  5697. }
  5698. }
  5699. };
  5700. Ext.layout.BorderLayout.Region.prototype = {
  5701. /**
  5702. * @cfg {Boolean} animFloat
  5703. * When a collapsed region's bar is clicked, the region's panel will be displayed as a floated
  5704. * panel that will close again once the user mouses out of that panel (or clicks out if
  5705. * <tt>{@link #autoHide} = false</tt>). Setting <tt>{@link #animFloat} = false</tt> will
  5706. * prevent the open and close of these floated panels from being animated (defaults to <tt>true</tt>).
  5707. */
  5708. /**
  5709. * @cfg {Boolean} autoHide
  5710. * When a collapsed region's bar is clicked, the region's panel will be displayed as a floated
  5711. * panel. If <tt>autoHide = true</tt>, the panel will automatically hide after the user mouses
  5712. * out of the panel. If <tt>autoHide = false</tt>, the panel will continue to display until the
  5713. * user clicks outside of the panel (defaults to <tt>true</tt>).
  5714. */
  5715. /**
  5716. * @cfg {String} collapseMode
  5717. * <tt>collapseMode</tt> supports two configuration values:<div class="mdetail-params"><ul>
  5718. * <li><b><tt>undefined</tt></b> (default)<div class="sub-desc">By default, {@link #collapsible}
  5719. * regions are collapsed by clicking the expand/collapse tool button that renders into the region's
  5720. * title bar.</div></li>
  5721. * <li><b><tt>'mini'</tt></b><div class="sub-desc">Optionally, when <tt>collapseMode</tt> is set to
  5722. * <tt>'mini'</tt> the region's split bar will also display a small collapse button in the center of
  5723. * the bar. In <tt>'mini'</tt> mode the region will collapse to a thinner bar than in normal mode.
  5724. * </div></li>
  5725. * </ul></div></p>
  5726. * <p><b>Note</b>: if a collapsible region does not have a title bar, then set <tt>collapseMode =
  5727. * 'mini'</tt> and <tt>{@link #split} = true</tt> in order for the region to be {@link #collapsible}
  5728. * by the user as the expand/collapse tool button (that would go in the title bar) will not be rendered.</p>
  5729. * <p>See also <tt>{@link #cmargins}</tt>.</p>
  5730. */
  5731. /**
  5732. * @cfg {Object} margins
  5733. * An object containing margins to apply to the region when in the expanded state in the
  5734. * format:<pre><code>
  5735. {
  5736. top: (top margin),
  5737. right: (right margin),
  5738. bottom: (bottom margin),
  5739. left: (left margin)
  5740. }</code></pre>
  5741. * <p>May also be a string containing space-separated, numeric margin values. The order of the
  5742. * sides associated with each value matches the way CSS processes margin values:</p>
  5743. * <p><div class="mdetail-params"><ul>
  5744. * <li>If there is only one value, it applies to all sides.</li>
  5745. * <li>If there are two values, the top and bottom borders are set to the first value and the
  5746. * right and left are set to the second.</li>
  5747. * <li>If there are three values, the top is set to the first value, the left and right are set
  5748. * to the second, and the bottom is set to the third.</li>
  5749. * <li>If there are four values, they apply to the top, right, bottom, and left, respectively.</li>
  5750. * </ul></div></p>
  5751. * <p>Defaults to:</p><pre><code>
  5752. * {top:0, right:0, bottom:0, left:0}
  5753. * </code></pre>
  5754. */
  5755. /**
  5756. * @cfg {Object} cmargins
  5757. * An object containing margins to apply to the region when in the collapsed state in the
  5758. * format:<pre><code>
  5759. {
  5760. top: (top margin),
  5761. right: (right margin),
  5762. bottom: (bottom margin),
  5763. left: (left margin)
  5764. }</code></pre>
  5765. * <p>May also be a string containing space-separated, numeric margin values. The order of the
  5766. * sides associated with each value matches the way CSS processes margin values.</p>
  5767. * <p><ul>
  5768. * <li>If there is only one value, it applies to all sides.</li>
  5769. * <li>If there are two values, the top and bottom borders are set to the first value and the
  5770. * right and left are set to the second.</li>
  5771. * <li>If there are three values, the top is set to the first value, the left and right are set
  5772. * to the second, and the bottom is set to the third.</li>
  5773. * <li>If there are four values, they apply to the top, right, bottom, and left, respectively.</li>
  5774. * </ul></p>
  5775. */
  5776. /**
  5777. * @cfg {Boolean} collapsible
  5778. * <p><tt>true</tt> to allow the user to collapse this region (defaults to <tt>false</tt>). If
  5779. * <tt>true</tt>, an expand/collapse tool button will automatically be rendered into the title
  5780. * bar of the region, otherwise the button will not be shown.</p>
  5781. * <p><b>Note</b>: that a title bar is required to display the collapse/expand toggle button -- if
  5782. * no <tt>title</tt> is specified for the region's panel, the region will only be collapsible if
  5783. * <tt>{@link #collapseMode} = 'mini'</tt> and <tt>{@link #split} = true</tt>.
  5784. */
  5785. collapsible : false,
  5786. /**
  5787. * @cfg {Boolean} split
  5788. * <p><tt>true</tt> to create a {@link Ext.layout.BorderLayout.SplitRegion SplitRegion} and
  5789. * display a 5px wide {@link Ext.SplitBar} between this region and its neighbor, allowing the user to
  5790. * resize the regions dynamically. Defaults to <tt>false</tt> creating a
  5791. * {@link Ext.layout.BorderLayout.Region Region}.</p><br>
  5792. * <p><b>Notes</b>:</p><div class="mdetail-params"><ul>
  5793. * <li>this configuration option is ignored if <tt>region='center'</tt></li>
  5794. * <li>when <tt>split == true</tt>, it is common to specify a
  5795. * <tt>{@link Ext.SplitBar#minSize minSize}</tt> and <tt>{@link Ext.SplitBar#maxSize maxSize}</tt>
  5796. * for the {@link Ext.BoxComponent BoxComponent} representing the region. These are not native
  5797. * configs of {@link Ext.BoxComponent BoxComponent}, and are used only by this class.</li>
  5798. * <li>if <tt>{@link #collapseMode} = 'mini'</tt> requires <tt>split = true</tt> to reserve space
  5799. * for the collapse tool</tt></li>
  5800. * </ul></div>
  5801. */
  5802. split:false,
  5803. /**
  5804. * @cfg {Boolean} floatable
  5805. * <tt>true</tt> to allow clicking a collapsed region's bar to display the region's panel floated
  5806. * above the layout, <tt>false</tt> to force the user to fully expand a collapsed region by
  5807. * clicking the expand button to see it again (defaults to <tt>true</tt>).
  5808. */
  5809. floatable: true,
  5810. /**
  5811. * @cfg {Number} minWidth
  5812. * <p>The minimum allowable width in pixels for this region (defaults to <tt>50</tt>).
  5813. * <tt>maxWidth</tt> may also be specified.</p><br>
  5814. * <p><b>Note</b>: setting the <tt>{@link Ext.SplitBar#minSize minSize}</tt> /
  5815. * <tt>{@link Ext.SplitBar#maxSize maxSize}</tt> supersedes any specified
  5816. * <tt>minWidth</tt> / <tt>maxWidth</tt>.</p>
  5817. */
  5818. minWidth:50,
  5819. /**
  5820. * @cfg {Number} minHeight
  5821. * The minimum allowable height in pixels for this region (defaults to <tt>50</tt>)
  5822. * <tt>maxHeight</tt> may also be specified.</p><br>
  5823. * <p><b>Note</b>: setting the <tt>{@link Ext.SplitBar#minSize minSize}</tt> /
  5824. * <tt>{@link Ext.SplitBar#maxSize maxSize}</tt> supersedes any specified
  5825. * <tt>minHeight</tt> / <tt>maxHeight</tt>.</p>
  5826. */
  5827. minHeight:50,
  5828. // private
  5829. defaultMargins : {left:0,top:0,right:0,bottom:0},
  5830. // private
  5831. defaultNSCMargins : {left:5,top:5,right:5,bottom:5},
  5832. // private
  5833. defaultEWCMargins : {left:5,top:0,right:5,bottom:0},
  5834. floatingZIndex: 100,
  5835. /**
  5836. * True if this region is collapsed. Read-only.
  5837. * @type Boolean
  5838. * @property
  5839. */
  5840. isCollapsed : false,
  5841. /**
  5842. * This region's panel. Read-only.
  5843. * @type Ext.Panel
  5844. * @property panel
  5845. */
  5846. /**
  5847. * This region's layout. Read-only.
  5848. * @type Layout
  5849. * @property layout
  5850. */
  5851. /**
  5852. * This region's layout position (north, south, east, west or center). Read-only.
  5853. * @type String
  5854. * @property position
  5855. */
  5856. // private
  5857. render : function(ct, p){
  5858. this.panel = p;
  5859. p.el.enableDisplayMode();
  5860. this.targetEl = ct;
  5861. this.el = p.el;
  5862. var gs = p.getState, ps = this.position;
  5863. p.getState = function(){
  5864. return Ext.apply(gs.call(p) || {}, this.state);
  5865. }.createDelegate(this);
  5866. if(ps != 'center'){
  5867. p.allowQueuedExpand = false;
  5868. p.on({
  5869. beforecollapse: this.beforeCollapse,
  5870. collapse: this.onCollapse,
  5871. beforeexpand: this.beforeExpand,
  5872. expand: this.onExpand,
  5873. hide: this.onHide,
  5874. show: this.onShow,
  5875. scope: this
  5876. });
  5877. if(this.collapsible || this.floatable){
  5878. p.collapseEl = 'el';
  5879. p.slideAnchor = this.getSlideAnchor();
  5880. }
  5881. if(p.tools && p.tools.toggle){
  5882. p.tools.toggle.addClass('x-tool-collapse-'+ps);
  5883. p.tools.toggle.addClassOnOver('x-tool-collapse-'+ps+'-over');
  5884. }
  5885. }
  5886. },
  5887. // private
  5888. getCollapsedEl : function(){
  5889. if(!this.collapsedEl){
  5890. if(!this.toolTemplate){
  5891. var tt = new Ext.Template(
  5892. '<div class="x-tool x-tool-{id}">&#160;</div>'
  5893. );
  5894. tt.disableFormats = true;
  5895. tt.compile();
  5896. Ext.layout.BorderLayout.Region.prototype.toolTemplate = tt;
  5897. }
  5898. this.collapsedEl = this.targetEl.createChild({
  5899. cls: "x-layout-collapsed x-layout-collapsed-"+this.position,
  5900. id: this.panel.id + '-xcollapsed'
  5901. });
  5902. this.collapsedEl.enableDisplayMode('block');
  5903. if(this.collapseMode == 'mini'){
  5904. this.collapsedEl.addClass('x-layout-cmini-'+this.position);
  5905. this.miniCollapsedEl = this.collapsedEl.createChild({
  5906. cls: "x-layout-mini x-layout-mini-"+this.position, html: "&#160;"
  5907. });
  5908. this.miniCollapsedEl.addClassOnOver('x-layout-mini-over');
  5909. this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
  5910. this.collapsedEl.on('click', this.onExpandClick, this, {stopEvent:true});
  5911. }else {
  5912. if(this.collapsible !== false && !this.hideCollapseTool) {
  5913. var t = this.expandToolEl = this.toolTemplate.append(
  5914. this.collapsedEl.dom,
  5915. {id:'expand-'+this.position}, true);
  5916. t.addClassOnOver('x-tool-expand-'+this.position+'-over');
  5917. t.on('click', this.onExpandClick, this, {stopEvent:true});
  5918. }
  5919. if(this.floatable !== false || this.titleCollapse){
  5920. this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
  5921. this.collapsedEl.on("click", this[this.floatable ? 'collapseClick' : 'onExpandClick'], this);
  5922. }
  5923. }
  5924. }
  5925. return this.collapsedEl;
  5926. },
  5927. // private
  5928. onExpandClick : function(e){
  5929. if(this.isSlid){
  5930. this.panel.expand(false);
  5931. }else{
  5932. this.panel.expand();
  5933. }
  5934. },
  5935. // private
  5936. onCollapseClick : function(e){
  5937. this.panel.collapse();
  5938. },
  5939. // private
  5940. beforeCollapse : function(p, animate){
  5941. this.lastAnim = animate;
  5942. if(this.splitEl){
  5943. this.splitEl.hide();
  5944. }
  5945. this.getCollapsedEl().show();
  5946. var el = this.panel.getEl();
  5947. this.originalZIndex = el.getStyle('z-index');
  5948. el.setStyle('z-index', 100);
  5949. this.isCollapsed = true;
  5950. this.layout.layout();
  5951. },
  5952. // private
  5953. onCollapse : function(animate){
  5954. this.panel.el.setStyle('z-index', 1);
  5955. if(this.lastAnim === false || this.panel.animCollapse === false){
  5956. this.getCollapsedEl().dom.style.visibility = 'visible';
  5957. }else{
  5958. this.getCollapsedEl().slideIn(this.panel.slideAnchor, {duration:.2});
  5959. }
  5960. this.state.collapsed = true;
  5961. this.panel.saveState();
  5962. },
  5963. // private
  5964. beforeExpand : function(animate){
  5965. if(this.isSlid){
  5966. this.afterSlideIn();
  5967. }
  5968. var c = this.getCollapsedEl();
  5969. this.el.show();
  5970. if(this.position == 'east' || this.position == 'west'){
  5971. this.panel.setSize(undefined, c.getHeight());
  5972. }else{
  5973. this.panel.setSize(c.getWidth(), undefined);
  5974. }
  5975. c.hide();
  5976. c.dom.style.visibility = 'hidden';
  5977. this.panel.el.setStyle('z-index', this.floatingZIndex);
  5978. },
  5979. // private
  5980. onExpand : function(){
  5981. this.isCollapsed = false;
  5982. if(this.splitEl){
  5983. this.splitEl.show();
  5984. }
  5985. this.layout.layout();
  5986. this.panel.el.setStyle('z-index', this.originalZIndex);
  5987. this.state.collapsed = false;
  5988. this.panel.saveState();
  5989. },
  5990. // private
  5991. collapseClick : function(e){
  5992. if(this.isSlid){
  5993. e.stopPropagation();
  5994. this.slideIn();
  5995. }else{
  5996. e.stopPropagation();
  5997. this.slideOut();
  5998. }
  5999. },
  6000. // private
  6001. onHide : function(){
  6002. if(this.isCollapsed){
  6003. this.getCollapsedEl().hide();
  6004. }else if(this.splitEl){
  6005. this.splitEl.hide();
  6006. }
  6007. },
  6008. // private
  6009. onShow : function(){
  6010. if(this.isCollapsed){
  6011. this.getCollapsedEl().show();
  6012. }else if(this.splitEl){
  6013. this.splitEl.show();
  6014. }
  6015. },
  6016. /**
  6017. * True if this region is currently visible, else false.
  6018. * @return {Boolean}
  6019. */
  6020. isVisible : function(){
  6021. return !this.panel.hidden;
  6022. },
  6023. /**
  6024. * Returns the current margins for this region. If the region is collapsed, the
  6025. * {@link #cmargins} (collapsed margins) value will be returned, otherwise the
  6026. * {@link #margins} value will be returned.
  6027. * @return {Object} An object containing the element's margins: <tt>{left: (left
  6028. * margin), top: (top margin), right: (right margin), bottom: (bottom margin)}</tt>
  6029. */
  6030. getMargins : function(){
  6031. return this.isCollapsed && this.cmargins ? this.cmargins : this.margins;
  6032. },
  6033. /**
  6034. * Returns the current size of this region. If the region is collapsed, the size of the
  6035. * collapsedEl will be returned, otherwise the size of the region's panel will be returned.
  6036. * @return {Object} An object containing the element's size: <tt>{width: (element width),
  6037. * height: (element height)}</tt>
  6038. */
  6039. getSize : function(){
  6040. return this.isCollapsed ? this.getCollapsedEl().getSize() : this.panel.getSize();
  6041. },
  6042. /**
  6043. * Sets the specified panel as the container element for this region.
  6044. * @param {Ext.Panel} panel The new panel
  6045. */
  6046. setPanel : function(panel){
  6047. this.panel = panel;
  6048. },
  6049. /**
  6050. * Returns the minimum allowable width for this region.
  6051. * @return {Number} The minimum width
  6052. */
  6053. getMinWidth: function(){
  6054. return this.minWidth;
  6055. },
  6056. /**
  6057. * Returns the minimum allowable height for this region.
  6058. * @return {Number} The minimum height
  6059. */
  6060. getMinHeight: function(){
  6061. return this.minHeight;
  6062. },
  6063. // private
  6064. applyLayoutCollapsed : function(box){
  6065. var ce = this.getCollapsedEl();
  6066. ce.setLeftTop(box.x, box.y);
  6067. ce.setSize(box.width, box.height);
  6068. },
  6069. // private
  6070. applyLayout : function(box){
  6071. if(this.isCollapsed){
  6072. this.applyLayoutCollapsed(box);
  6073. }else{
  6074. this.panel.setPosition(box.x, box.y);
  6075. this.panel.setSize(box.width, box.height);
  6076. }
  6077. },
  6078. // private
  6079. beforeSlide: function(){
  6080. this.panel.beforeEffect();
  6081. },
  6082. // private
  6083. afterSlide : function(){
  6084. this.panel.afterEffect();
  6085. },
  6086. // private
  6087. initAutoHide : function(){
  6088. if(this.autoHide !== false){
  6089. if(!this.autoHideHd){
  6090. this.autoHideSlideTask = new Ext.util.DelayedTask(this.slideIn, this);
  6091. this.autoHideHd = {
  6092. "mouseout": function(e){
  6093. if(!e.within(this.el, true)){
  6094. this.autoHideSlideTask.delay(500);
  6095. }
  6096. },
  6097. "mouseover" : function(e){
  6098. this.autoHideSlideTask.cancel();
  6099. },
  6100. scope : this
  6101. };
  6102. }
  6103. this.el.on(this.autoHideHd);
  6104. this.collapsedEl.on(this.autoHideHd);
  6105. }
  6106. },
  6107. // private
  6108. clearAutoHide : function(){
  6109. if(this.autoHide !== false){
  6110. this.el.un("mouseout", this.autoHideHd.mouseout);
  6111. this.el.un("mouseover", this.autoHideHd.mouseover);
  6112. this.collapsedEl.un("mouseout", this.autoHideHd.mouseout);
  6113. this.collapsedEl.un("mouseover", this.autoHideHd.mouseover);
  6114. }
  6115. },
  6116. // private
  6117. clearMonitor : function(){
  6118. Ext.getDoc().un("click", this.slideInIf, this);
  6119. },
  6120. /**
  6121. * If this Region is {@link #floatable}, this method slides this Region into full visibility <i>over the top
  6122. * of the center Region</i> where it floats until either {@link #slideIn} is called, or other regions of the layout
  6123. * are clicked, or the mouse exits the Region.
  6124. */
  6125. slideOut : function(){
  6126. if(this.isSlid || this.el.hasActiveFx()){
  6127. return;
  6128. }
  6129. this.isSlid = true;
  6130. var ts = this.panel.tools, dh, pc;
  6131. if(ts && ts.toggle){
  6132. ts.toggle.hide();
  6133. }
  6134. this.el.show();
  6135. // Temporarily clear the collapsed flag so we can onResize the panel on the slide
  6136. pc = this.panel.collapsed;
  6137. this.panel.collapsed = false;
  6138. if(this.position == 'east' || this.position == 'west'){
  6139. // Temporarily clear the deferHeight flag so we can size the height on the slide
  6140. dh = this.panel.deferHeight;
  6141. this.panel.deferHeight = false;
  6142. this.panel.setSize(undefined, this.collapsedEl.getHeight());
  6143. // Put the deferHeight flag back after setSize
  6144. this.panel.deferHeight = dh;
  6145. }else{
  6146. this.panel.setSize(this.collapsedEl.getWidth(), undefined);
  6147. }
  6148. // Put the collapsed flag back after onResize
  6149. this.panel.collapsed = pc;
  6150. this.restoreLT = [this.el.dom.style.left, this.el.dom.style.top];
  6151. this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
  6152. this.el.setStyle("z-index", this.floatingZIndex+2);
  6153. this.panel.el.replaceClass('x-panel-collapsed', 'x-panel-floating');
  6154. if(this.animFloat !== false){
  6155. this.beforeSlide();
  6156. this.el.slideIn(this.getSlideAnchor(), {
  6157. callback: function(){
  6158. this.afterSlide();
  6159. this.initAutoHide();
  6160. Ext.getDoc().on("click", this.slideInIf, this);
  6161. },
  6162. scope: this,
  6163. block: true
  6164. });
  6165. }else{
  6166. this.initAutoHide();
  6167. Ext.getDoc().on("click", this.slideInIf, this);
  6168. }
  6169. },
  6170. // private
  6171. afterSlideIn : function(){
  6172. this.clearAutoHide();
  6173. this.isSlid = false;
  6174. this.clearMonitor();
  6175. this.el.setStyle("z-index", "");
  6176. this.panel.el.replaceClass('x-panel-floating', 'x-panel-collapsed');
  6177. this.el.dom.style.left = this.restoreLT[0];
  6178. this.el.dom.style.top = this.restoreLT[1];
  6179. var ts = this.panel.tools;
  6180. if(ts && ts.toggle){
  6181. ts.toggle.show();
  6182. }
  6183. },
  6184. /**
  6185. * If this Region is {@link #floatable}, and this Region has been slid into floating visibility, then this method slides
  6186. * this region back into its collapsed state.
  6187. */
  6188. slideIn : function(cb){
  6189. if(!this.isSlid || this.el.hasActiveFx()){
  6190. Ext.callback(cb);
  6191. return;
  6192. }
  6193. this.isSlid = false;
  6194. if(this.animFloat !== false){
  6195. this.beforeSlide();
  6196. this.el.slideOut(this.getSlideAnchor(), {
  6197. callback: function(){
  6198. this.el.hide();
  6199. this.afterSlide();
  6200. this.afterSlideIn();
  6201. Ext.callback(cb);
  6202. },
  6203. scope: this,
  6204. block: true
  6205. });
  6206. }else{
  6207. this.el.hide();
  6208. this.afterSlideIn();
  6209. }
  6210. },
  6211. // private
  6212. slideInIf : function(e){
  6213. if(!e.within(this.el)){
  6214. this.slideIn();
  6215. }
  6216. },
  6217. // private
  6218. anchors : {
  6219. "west" : "left",
  6220. "east" : "right",
  6221. "north" : "top",
  6222. "south" : "bottom"
  6223. },
  6224. // private
  6225. sanchors : {
  6226. "west" : "l",
  6227. "east" : "r",
  6228. "north" : "t",
  6229. "south" : "b"
  6230. },
  6231. // private
  6232. canchors : {
  6233. "west" : "tl-tr",
  6234. "east" : "tr-tl",
  6235. "north" : "tl-bl",
  6236. "south" : "bl-tl"
  6237. },
  6238. // private
  6239. getAnchor : function(){
  6240. return this.anchors[this.position];
  6241. },
  6242. // private
  6243. getCollapseAnchor : function(){
  6244. return this.canchors[this.position];
  6245. },
  6246. // private
  6247. getSlideAnchor : function(){
  6248. return this.sanchors[this.position];
  6249. },
  6250. // private
  6251. getAlignAdj : function(){
  6252. var cm = this.cmargins;
  6253. switch(this.position){
  6254. case "west":
  6255. return [0, 0];
  6256. break;
  6257. case "east":
  6258. return [0, 0];
  6259. break;
  6260. case "north":
  6261. return [0, 0];
  6262. break;
  6263. case "south":
  6264. return [0, 0];
  6265. break;
  6266. }
  6267. },
  6268. // private
  6269. getExpandAdj : function(){
  6270. var c = this.collapsedEl, cm = this.cmargins;
  6271. switch(this.position){
  6272. case "west":
  6273. return [-(cm.right+c.getWidth()+cm.left), 0];
  6274. break;
  6275. case "east":
  6276. return [cm.right+c.getWidth()+cm.left, 0];
  6277. break;
  6278. case "north":
  6279. return [0, -(cm.top+cm.bottom+c.getHeight())];
  6280. break;
  6281. case "south":
  6282. return [0, cm.top+cm.bottom+c.getHeight()];
  6283. break;
  6284. }
  6285. },
  6286. destroy : function(){
  6287. if (this.autoHideSlideTask && this.autoHideSlideTask.cancel){
  6288. this.autoHideSlideTask.cancel();
  6289. }
  6290. Ext.destroyMembers(this, 'miniCollapsedEl', 'collapsedEl', 'expandToolEl');
  6291. }
  6292. };
  6293. /**
  6294. * @class Ext.layout.BorderLayout.SplitRegion
  6295. * @extends Ext.layout.BorderLayout.Region
  6296. * <p>This is a specialized type of {@link Ext.layout.BorderLayout.Region BorderLayout region} that
  6297. * has a built-in {@link Ext.SplitBar} for user resizing of regions. The movement of the split bar
  6298. * is configurable to move either {@link #tickSize smooth or incrementally}.</p>
  6299. * @constructor
  6300. * Create a new SplitRegion.
  6301. * @param {Layout} layout The {@link Ext.layout.BorderLayout BorderLayout} instance that is managing this Region.
  6302. * @param {Object} config The configuration options
  6303. * @param {String} position The region position. Valid values are: north, south, east, west and center. Every
  6304. * BorderLayout must have a center region for the primary content -- all other regions are optional.
  6305. */
  6306. Ext.layout.BorderLayout.SplitRegion = function(layout, config, pos){
  6307. Ext.layout.BorderLayout.SplitRegion.superclass.constructor.call(this, layout, config, pos);
  6308. // prevent switch
  6309. this.applyLayout = this.applyFns[pos];
  6310. };
  6311. Ext.extend(Ext.layout.BorderLayout.SplitRegion, Ext.layout.BorderLayout.Region, {
  6312. /**
  6313. * @cfg {Number} tickSize
  6314. * The increment, in pixels by which to move this Region's {@link Ext.SplitBar SplitBar}.
  6315. * By default, the {@link Ext.SplitBar SplitBar} moves smoothly.
  6316. */
  6317. /**
  6318. * @cfg {String} splitTip
  6319. * The tooltip to display when the user hovers over a
  6320. * {@link Ext.layout.BorderLayout.Region#collapsible non-collapsible} region's split bar
  6321. * (defaults to <tt>"Drag to resize."</tt>). Only applies if
  6322. * <tt>{@link #useSplitTips} = true</tt>.
  6323. */
  6324. splitTip : "Drag to resize.",
  6325. /**
  6326. * @cfg {String} collapsibleSplitTip
  6327. * The tooltip to display when the user hovers over a
  6328. * {@link Ext.layout.BorderLayout.Region#collapsible collapsible} region's split bar
  6329. * (defaults to "Drag to resize. Double click to hide."). Only applies if
  6330. * <tt>{@link #useSplitTips} = true</tt>.
  6331. */
  6332. collapsibleSplitTip : "Drag to resize. Double click to hide.",
  6333. /**
  6334. * @cfg {Boolean} useSplitTips
  6335. * <tt>true</tt> to display a tooltip when the user hovers over a region's split bar
  6336. * (defaults to <tt>false</tt>). The tooltip text will be the value of either
  6337. * <tt>{@link #splitTip}</tt> or <tt>{@link #collapsibleSplitTip}</tt> as appropriate.
  6338. */
  6339. useSplitTips : false,
  6340. // private
  6341. splitSettings : {
  6342. north : {
  6343. orientation: Ext.SplitBar.VERTICAL,
  6344. placement: Ext.SplitBar.TOP,
  6345. maxFn : 'getVMaxSize',
  6346. minProp: 'minHeight',
  6347. maxProp: 'maxHeight'
  6348. },
  6349. south : {
  6350. orientation: Ext.SplitBar.VERTICAL,
  6351. placement: Ext.SplitBar.BOTTOM,
  6352. maxFn : 'getVMaxSize',
  6353. minProp: 'minHeight',
  6354. maxProp: 'maxHeight'
  6355. },
  6356. east : {
  6357. orientation: Ext.SplitBar.HORIZONTAL,
  6358. placement: Ext.SplitBar.RIGHT,
  6359. maxFn : 'getHMaxSize',
  6360. minProp: 'minWidth',
  6361. maxProp: 'maxWidth'
  6362. },
  6363. west : {
  6364. orientation: Ext.SplitBar.HORIZONTAL,
  6365. placement: Ext.SplitBar.LEFT,
  6366. maxFn : 'getHMaxSize',
  6367. minProp: 'minWidth',
  6368. maxProp: 'maxWidth'
  6369. }
  6370. },
  6371. // private
  6372. applyFns : {
  6373. west : function(box){
  6374. if(this.isCollapsed){
  6375. return this.applyLayoutCollapsed(box);
  6376. }
  6377. var sd = this.splitEl.dom, s = sd.style;
  6378. this.panel.setPosition(box.x, box.y);
  6379. var sw = sd.offsetWidth;
  6380. s.left = (box.x+box.width-sw)+'px';
  6381. s.top = (box.y)+'px';
  6382. s.height = Math.max(0, box.height)+'px';
  6383. this.panel.setSize(box.width-sw, box.height);
  6384. },
  6385. east : function(box){
  6386. if(this.isCollapsed){
  6387. return this.applyLayoutCollapsed(box);
  6388. }
  6389. var sd = this.splitEl.dom, s = sd.style;
  6390. var sw = sd.offsetWidth;
  6391. this.panel.setPosition(box.x+sw, box.y);
  6392. s.left = (box.x)+'px';
  6393. s.top = (box.y)+'px';
  6394. s.height = Math.max(0, box.height)+'px';
  6395. this.panel.setSize(box.width-sw, box.height);
  6396. },
  6397. north : function(box){
  6398. if(this.isCollapsed){
  6399. return this.applyLayoutCollapsed(box);
  6400. }
  6401. var sd = this.splitEl.dom, s = sd.style;
  6402. var sh = sd.offsetHeight;
  6403. this.panel.setPosition(box.x, box.y);
  6404. s.left = (box.x)+'px';
  6405. s.top = (box.y+box.height-sh)+'px';
  6406. s.width = Math.max(0, box.width)+'px';
  6407. this.panel.setSize(box.width, box.height-sh);
  6408. },
  6409. south : function(box){
  6410. if(this.isCollapsed){
  6411. return this.applyLayoutCollapsed(box);
  6412. }
  6413. var sd = this.splitEl.dom, s = sd.style;
  6414. var sh = sd.offsetHeight;
  6415. this.panel.setPosition(box.x, box.y+sh);
  6416. s.left = (box.x)+'px';
  6417. s.top = (box.y)+'px';
  6418. s.width = Math.max(0, box.width)+'px';
  6419. this.panel.setSize(box.width, box.height-sh);
  6420. }
  6421. },
  6422. // private
  6423. render : function(ct, p){
  6424. Ext.layout.BorderLayout.SplitRegion.superclass.render.call(this, ct, p);
  6425. var ps = this.position;
  6426. this.splitEl = ct.createChild({
  6427. cls: "x-layout-split x-layout-split-"+ps, html: "&#160;",
  6428. id: this.panel.id + '-xsplit'
  6429. });
  6430. if(this.collapseMode == 'mini'){
  6431. this.miniSplitEl = this.splitEl.createChild({
  6432. cls: "x-layout-mini x-layout-mini-"+ps, html: "&#160;"
  6433. });
  6434. this.miniSplitEl.addClassOnOver('x-layout-mini-over');
  6435. this.miniSplitEl.on('click', this.onCollapseClick, this, {stopEvent:true});
  6436. }
  6437. var s = this.splitSettings[ps];
  6438. this.split = new Ext.SplitBar(this.splitEl.dom, p.el, s.orientation);
  6439. this.split.tickSize = this.tickSize;
  6440. this.split.placement = s.placement;
  6441. this.split.getMaximumSize = this[s.maxFn].createDelegate(this);
  6442. this.split.minSize = this.minSize || this[s.minProp];
  6443. this.split.on("beforeapply", this.onSplitMove, this);
  6444. this.split.useShim = this.useShim === true;
  6445. this.maxSize = this.maxSize || this[s.maxProp];
  6446. if(p.hidden){
  6447. this.splitEl.hide();
  6448. }
  6449. if(this.useSplitTips){
  6450. this.splitEl.dom.title = this.collapsible ? this.collapsibleSplitTip : this.splitTip;
  6451. }
  6452. if(this.collapsible){
  6453. this.splitEl.on("dblclick", this.onCollapseClick, this);
  6454. }
  6455. },
  6456. //docs inherit from superclass
  6457. getSize : function(){
  6458. if(this.isCollapsed){
  6459. return this.collapsedEl.getSize();
  6460. }
  6461. var s = this.panel.getSize();
  6462. if(this.position == 'north' || this.position == 'south'){
  6463. s.height += this.splitEl.dom.offsetHeight;
  6464. }else{
  6465. s.width += this.splitEl.dom.offsetWidth;
  6466. }
  6467. return s;
  6468. },
  6469. // private
  6470. getHMaxSize : function(){
  6471. var cmax = this.maxSize || 10000;
  6472. var center = this.layout.center;
  6473. return Math.min(cmax, (this.el.getWidth()+center.el.getWidth())-center.getMinWidth());
  6474. },
  6475. // private
  6476. getVMaxSize : function(){
  6477. var cmax = this.maxSize || 10000;
  6478. var center = this.layout.center;
  6479. return Math.min(cmax, (this.el.getHeight()+center.el.getHeight())-center.getMinHeight());
  6480. },
  6481. // private
  6482. onSplitMove : function(split, newSize){
  6483. var s = this.panel.getSize();
  6484. this.lastSplitSize = newSize;
  6485. if(this.position == 'north' || this.position == 'south'){
  6486. this.panel.setSize(s.width, newSize);
  6487. this.state.height = newSize;
  6488. }else{
  6489. this.panel.setSize(newSize, s.height);
  6490. this.state.width = newSize;
  6491. }
  6492. this.layout.layout();
  6493. this.panel.saveState();
  6494. return false;
  6495. },
  6496. /**
  6497. * Returns a reference to the split bar in use by this region.
  6498. * @return {Ext.SplitBar} The split bar
  6499. */
  6500. getSplitBar : function(){
  6501. return this.split;
  6502. },
  6503. // inherit docs
  6504. destroy : function() {
  6505. Ext.destroy(this.miniSplitEl, this.split, this.splitEl);
  6506. Ext.layout.BorderLayout.SplitRegion.superclass.destroy.call(this);
  6507. }
  6508. });
  6509. Ext.Container.LAYOUTS['border'] = Ext.layout.BorderLayout;
  6510. /**
  6511. * @class Ext.layout.FormLayout
  6512. * @extends Ext.layout.AnchorLayout
  6513. * <p>This layout manager is specifically designed for rendering and managing child Components of
  6514. * {@link Ext.form.FormPanel forms}. It is responsible for rendering the labels of
  6515. * {@link Ext.form.Field Field}s.</p>
  6516. *
  6517. * <p>This layout manager is used when a Container is configured with the <tt>layout:'form'</tt>
  6518. * {@link Ext.Container#layout layout} config option, and should generally not need to be created directly
  6519. * via the new keyword. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
  6520. *
  6521. * <p>In an application, it will usually be preferrable to use a {@link Ext.form.FormPanel FormPanel}
  6522. * (which is configured with FormLayout as its layout class by default) since it also provides built-in
  6523. * functionality for {@link Ext.form.BasicForm#doAction loading, validating and submitting} the form.</p>
  6524. *
  6525. * <p>A {@link Ext.Container Container} <i>using</i> the FormLayout layout manager (e.g.
  6526. * {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>) can also accept the following
  6527. * layout-specific config properties:<div class="mdetail-params"><ul>
  6528. * <li><b><tt>{@link Ext.form.FormPanel#hideLabels hideLabels}</tt></b></li>
  6529. * <li><b><tt>{@link Ext.form.FormPanel#labelAlign labelAlign}</tt></b></li>
  6530. * <li><b><tt>{@link Ext.form.FormPanel#labelPad labelPad}</tt></b></li>
  6531. * <li><b><tt>{@link Ext.form.FormPanel#labelSeparator labelSeparator}</tt></b></li>
  6532. * <li><b><tt>{@link Ext.form.FormPanel#labelWidth labelWidth}</tt></b></li>
  6533. * </ul></div></p>
  6534. *
  6535. * <p>Any Component (including Fields) managed by FormLayout accepts the following as a config option:
  6536. * <div class="mdetail-params"><ul>
  6537. * <li><b><tt>{@link Ext.Component#anchor anchor}</tt></b></li>
  6538. * </ul></div></p>
  6539. *
  6540. * <p>Any Component managed by FormLayout may be rendered as a form field (with an associated label) by
  6541. * configuring it with a non-null <b><tt>{@link Ext.Component#fieldLabel fieldLabel}</tt></b>. Components configured
  6542. * in this way may be configured with the following options which affect the way the FormLayout renders them:
  6543. * <div class="mdetail-params"><ul>
  6544. * <li><b><tt>{@link Ext.Component#clearCls clearCls}</tt></b></li>
  6545. * <li><b><tt>{@link Ext.Component#fieldLabel fieldLabel}</tt></b></li>
  6546. * <li><b><tt>{@link Ext.Component#hideLabel hideLabel}</tt></b></li>
  6547. * <li><b><tt>{@link Ext.Component#itemCls itemCls}</tt></b></li>
  6548. * <li><b><tt>{@link Ext.Component#labelSeparator labelSeparator}</tt></b></li>
  6549. * <li><b><tt>{@link Ext.Component#labelStyle labelStyle}</tt></b></li>
  6550. * </ul></div></p>
  6551. *
  6552. * <p>Example usage:</p>
  6553. * <pre><code>
  6554. // Required if showing validation messages
  6555. Ext.QuickTips.init();
  6556. // While you can create a basic Panel with layout:'form', practically
  6557. // you should usually use a FormPanel to also get its form functionality
  6558. // since it already creates a FormLayout internally.
  6559. var form = new Ext.form.FormPanel({
  6560. title: 'Form Layout',
  6561. bodyStyle: 'padding:15px',
  6562. width: 350,
  6563. defaultType: 'textfield',
  6564. defaults: {
  6565. // applied to each contained item
  6566. width: 230,
  6567. msgTarget: 'side'
  6568. },
  6569. items: [{
  6570. fieldLabel: 'First Name',
  6571. name: 'first',
  6572. allowBlank: false,
  6573. {@link Ext.Component#labelSeparator labelSeparator}: ':' // override labelSeparator layout config
  6574. },{
  6575. fieldLabel: 'Last Name',
  6576. name: 'last'
  6577. },{
  6578. fieldLabel: 'Email',
  6579. name: 'email',
  6580. vtype:'email'
  6581. }, {
  6582. xtype: 'textarea',
  6583. hideLabel: true, // override hideLabels layout config
  6584. name: 'msg',
  6585. anchor: '100% -53'
  6586. }
  6587. ],
  6588. buttons: [
  6589. {text: 'Save'},
  6590. {text: 'Cancel'}
  6591. ],
  6592. layoutConfig: {
  6593. {@link #labelSeparator}: '~' // superseded by assignment below
  6594. },
  6595. // config options applicable to container when layout='form':
  6596. hideLabels: false,
  6597. labelAlign: 'left', // or 'right' or 'top'
  6598. {@link Ext.form.FormPanel#labelSeparator labelSeparator}: '>>', // takes precedence over layoutConfig value
  6599. labelWidth: 65, // defaults to 100
  6600. labelPad: 8 // defaults to 5, must specify labelWidth to be honored
  6601. });
  6602. </code></pre>
  6603. */
  6604. Ext.layout.FormLayout = Ext.extend(Ext.layout.AnchorLayout, {
  6605. /**
  6606. * @cfg {String} labelSeparator
  6607. * See {@link Ext.form.FormPanel}.{@link Ext.form.FormPanel#labelSeparator labelSeparator}. Configuration
  6608. * of this property at the <b>container</b> level takes precedence.
  6609. */
  6610. labelSeparator : ':',
  6611. /**
  6612. * Read only. The CSS style specification string added to field labels in this layout if not
  6613. * otherwise {@link Ext.Component#labelStyle specified by each contained field}.
  6614. * @type String
  6615. * @property labelStyle
  6616. */
  6617. /**
  6618. * @cfg {Boolean} trackLabels
  6619. * True to show/hide the field label when the field is hidden. Defaults to <tt>true</tt>.
  6620. */
  6621. trackLabels: true,
  6622. type: 'form',
  6623. onRemove: function(c){
  6624. Ext.layout.FormLayout.superclass.onRemove.call(this, c);
  6625. if(this.trackLabels){
  6626. c.un('show', this.onFieldShow, this);
  6627. c.un('hide', this.onFieldHide, this);
  6628. }
  6629. // check for itemCt, since we may be removing a fieldset or something similar
  6630. var el = c.getPositionEl(),
  6631. ct = c.getItemCt && c.getItemCt();
  6632. if (c.rendered && ct) {
  6633. if (el && el.dom) {
  6634. el.insertAfter(ct);
  6635. }
  6636. Ext.destroy(ct);
  6637. Ext.destroyMembers(c, 'label', 'itemCt');
  6638. if (c.customItemCt) {
  6639. Ext.destroyMembers(c, 'getItemCt', 'customItemCt');
  6640. }
  6641. }
  6642. },
  6643. // private
  6644. setContainer : function(ct){
  6645. Ext.layout.FormLayout.superclass.setContainer.call(this, ct);
  6646. if(ct.labelAlign){
  6647. ct.addClass('x-form-label-'+ct.labelAlign);
  6648. }
  6649. if(ct.hideLabels){
  6650. Ext.apply(this, {
  6651. labelStyle: 'display:none',
  6652. elementStyle: 'padding-left:0;',
  6653. labelAdjust: 0
  6654. });
  6655. }else{
  6656. this.labelSeparator = Ext.isDefined(ct.labelSeparator) ? ct.labelSeparator : this.labelSeparator;
  6657. ct.labelWidth = ct.labelWidth || 100;
  6658. if(Ext.isNumber(ct.labelWidth)){
  6659. var pad = Ext.isNumber(ct.labelPad) ? ct.labelPad : 5;
  6660. Ext.apply(this, {
  6661. labelAdjust: ct.labelWidth + pad,
  6662. labelStyle: 'width:' + ct.labelWidth + 'px;',
  6663. elementStyle: 'padding-left:' + (ct.labelWidth + pad) + 'px'
  6664. });
  6665. }
  6666. if(ct.labelAlign == 'top'){
  6667. Ext.apply(this, {
  6668. labelStyle: 'width:auto;',
  6669. labelAdjust: 0,
  6670. elementStyle: 'padding-left:0;'
  6671. });
  6672. }
  6673. }
  6674. },
  6675. // private
  6676. isHide: function(c){
  6677. return c.hideLabel || this.container.hideLabels;
  6678. },
  6679. onFieldShow: function(c){
  6680. c.getItemCt().removeClass('x-hide-' + c.hideMode);
  6681. // Composite fields will need to layout after the container is made visible
  6682. if (c.isComposite) {
  6683. c.doLayout();
  6684. }
  6685. },
  6686. onFieldHide: function(c){
  6687. c.getItemCt().addClass('x-hide-' + c.hideMode);
  6688. },
  6689. //private
  6690. getLabelStyle: function(s){
  6691. var ls = '', items = [this.labelStyle, s];
  6692. for (var i = 0, len = items.length; i < len; ++i){
  6693. if (items[i]){
  6694. ls += items[i];
  6695. if (ls.substr(-1, 1) != ';'){
  6696. ls += ';';
  6697. }
  6698. }
  6699. }
  6700. return ls;
  6701. },
  6702. /**
  6703. * @cfg {Ext.Template} fieldTpl
  6704. * A {@link Ext.Template#compile compile}d {@link Ext.Template} for rendering
  6705. * the fully wrapped, labeled and styled form Field. Defaults to:</p><pre><code>
  6706. new Ext.Template(
  6707. &#39;&lt;div class="x-form-item {itemCls}" tabIndex="-1">&#39;,
  6708. &#39;&lt;&#108;abel for="{id}" style="{labelStyle}" class="x-form-item-&#108;abel">{&#108;abel}{labelSeparator}&lt;/&#108;abel>&#39;,
  6709. &#39;&lt;div class="x-form-element" id="x-form-el-{id}" style="{elementStyle}">&#39;,
  6710. &#39;&lt;/div>&lt;div class="{clearCls}">&lt;/div>&#39;,
  6711. '&lt;/div>'
  6712. );
  6713. </code></pre>
  6714. * <p>This may be specified to produce a different DOM structure when rendering form Fields.</p>
  6715. * <p>A description of the properties within the template follows:</p><div class="mdetail-params"><ul>
  6716. * <li><b><tt>itemCls</tt></b> : String<div class="sub-desc">The CSS class applied to the outermost div wrapper
  6717. * that contains this field label and field element (the default class is <tt>'x-form-item'</tt> and <tt>itemCls</tt>
  6718. * will be added to that). If supplied, <tt>itemCls</tt> at the field level will override the default <tt>itemCls</tt>
  6719. * supplied at the container level.</div></li>
  6720. * <li><b><tt>id</tt></b> : String<div class="sub-desc">The id of the Field</div></li>
  6721. * <li><b><tt>{@link #labelStyle}</tt></b> : String<div class="sub-desc">
  6722. * A CSS style specification string to add to the field label for this field (defaults to <tt>''</tt> or the
  6723. * {@link #labelStyle layout's value for <tt>labelStyle</tt>}).</div></li>
  6724. * <li><b><tt>label</tt></b> : String<div class="sub-desc">The text to display as the label for this
  6725. * field (defaults to <tt>''</tt>)</div></li>
  6726. * <li><b><tt>{@link #labelSeparator}</tt></b> : String<div class="sub-desc">The separator to display after
  6727. * the text of the label for this field (defaults to a colon <tt>':'</tt> or the
  6728. * {@link #labelSeparator layout's value for labelSeparator}). To hide the separator use empty string ''.</div></li>
  6729. * <li><b><tt>elementStyle</tt></b> : String<div class="sub-desc">The styles text for the input element's wrapper.</div></li>
  6730. * <li><b><tt>clearCls</tt></b> : String<div class="sub-desc">The CSS class to apply to the special clearing div
  6731. * rendered directly after each form field wrapper (defaults to <tt>'x-form-clear-left'</tt>)</div></li>
  6732. * </ul></div>
  6733. * <p>Also see <tt>{@link #getTemplateArgs}</tt></p>
  6734. */
  6735. /**
  6736. * @private
  6737. *
  6738. */
  6739. renderItem : function(c, position, target){
  6740. if(c && (c.isFormField || c.fieldLabel) && c.inputType != 'hidden'){
  6741. var args = this.getTemplateArgs(c);
  6742. if(Ext.isNumber(position)){
  6743. position = target.dom.childNodes[position] || null;
  6744. }
  6745. if(position){
  6746. c.itemCt = this.fieldTpl.insertBefore(position, args, true);
  6747. }else{
  6748. c.itemCt = this.fieldTpl.append(target, args, true);
  6749. }
  6750. if(!c.getItemCt){
  6751. // Non form fields don't have getItemCt, apply it here
  6752. // This will get cleaned up in onRemove
  6753. Ext.apply(c, {
  6754. getItemCt: function(){
  6755. return c.itemCt;
  6756. },
  6757. customItemCt: true
  6758. });
  6759. }
  6760. c.label = c.getItemCt().child('label.x-form-item-label');
  6761. if(!c.rendered){
  6762. c.render('x-form-el-' + c.id);
  6763. }else if(!this.isValidParent(c, target)){
  6764. Ext.fly('x-form-el-' + c.id).appendChild(c.getPositionEl());
  6765. }
  6766. if(this.trackLabels){
  6767. if(c.hidden){
  6768. this.onFieldHide(c);
  6769. }
  6770. c.on({
  6771. scope: this,
  6772. show: this.onFieldShow,
  6773. hide: this.onFieldHide
  6774. });
  6775. }
  6776. this.configureItem(c);
  6777. }else {
  6778. Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
  6779. }
  6780. },
  6781. /**
  6782. * <p>Provides template arguments for rendering the fully wrapped, labeled and styled form Field.</p>
  6783. * <p>This method returns an object hash containing properties used by the layout's {@link #fieldTpl}
  6784. * to create a correctly wrapped, labeled and styled form Field. This may be overriden to
  6785. * create custom layouts. The properties which must be returned are:</p><div class="mdetail-params"><ul>
  6786. * <li><b><tt>itemCls</tt></b> : String<div class="sub-desc">The CSS class applied to the outermost div wrapper
  6787. * that contains this field label and field element (the default class is <tt>'x-form-item'</tt> and <tt>itemCls</tt>
  6788. * will be added to that). If supplied, <tt>itemCls</tt> at the field level will override the default <tt>itemCls</tt>
  6789. * supplied at the container level.</div></li>
  6790. * <li><b><tt>id</tt></b> : String<div class="sub-desc">The id of the Field</div></li>
  6791. * <li><b><tt>{@link #labelStyle}</tt></b> : String<div class="sub-desc">
  6792. * A CSS style specification string to add to the field label for this field (defaults to <tt>''</tt> or the
  6793. * {@link #labelStyle layout's value for <tt>labelStyle</tt>}).</div></li>
  6794. * <li><b><tt>label</tt></b> : String<div class="sub-desc">The text to display as the label for this
  6795. * field (defaults to the field's configured fieldLabel property)</div></li>
  6796. * <li><b><tt>{@link #labelSeparator}</tt></b> : String<div class="sub-desc">The separator to display after
  6797. * the text of the label for this field (defaults to a colon <tt>':'</tt> or the
  6798. * {@link #labelSeparator layout's value for labelSeparator}). To hide the separator use empty string ''.</div></li>
  6799. * <li><b><tt>elementStyle</tt></b> : String<div class="sub-desc">The styles text for the input element's wrapper.</div></li>
  6800. * <li><b><tt>clearCls</tt></b> : String<div class="sub-desc">The CSS class to apply to the special clearing div
  6801. * rendered directly after each form field wrapper (defaults to <tt>'x-form-clear-left'</tt>)</div></li>
  6802. * </ul></div>
  6803. * @param (Ext.form.Field} field The {@link Ext.form.Field Field} being rendered.
  6804. * @return {Object} An object hash containing the properties required to render the Field.
  6805. */
  6806. getTemplateArgs: function(field) {
  6807. var noLabelSep = !field.fieldLabel || field.hideLabel;
  6808. return {
  6809. id : field.id,
  6810. label : field.fieldLabel,
  6811. itemCls : (field.itemCls || this.container.itemCls || '') + (field.hideLabel ? ' x-hide-label' : ''),
  6812. clearCls : field.clearCls || 'x-form-clear-left',
  6813. labelStyle : this.getLabelStyle(field.labelStyle),
  6814. elementStyle : this.elementStyle || '',
  6815. labelSeparator: noLabelSep ? '' : (Ext.isDefined(field.labelSeparator) ? field.labelSeparator : this.labelSeparator)
  6816. };
  6817. },
  6818. // private
  6819. adjustWidthAnchor: function(value, c){
  6820. if(c.label && !this.isHide(c) && (this.container.labelAlign != 'top')){
  6821. var adjust = Ext.isIE6 || (Ext.isIE && !Ext.isStrict);
  6822. return value - this.labelAdjust + (adjust ? -3 : 0);
  6823. }
  6824. return value;
  6825. },
  6826. adjustHeightAnchor : function(value, c){
  6827. if(c.label && !this.isHide(c) && (this.container.labelAlign == 'top')){
  6828. return value - c.label.getHeight();
  6829. }
  6830. return value;
  6831. },
  6832. // private
  6833. isValidParent : function(c, target){
  6834. return target && this.container.getEl().contains(c.getPositionEl());
  6835. }
  6836. /**
  6837. * @property activeItem
  6838. * @hide
  6839. */
  6840. });
  6841. Ext.Container.LAYOUTS['form'] = Ext.layout.FormLayout;
  6842. /**
  6843. * @class Ext.layout.AccordionLayout
  6844. * @extends Ext.layout.FitLayout
  6845. * <p>This is a layout that manages multiple Panels in an expandable accordion style such that only
  6846. * <b>one Panel can be expanded at any given time</b>. Each Panel has built-in support for expanding and collapsing.</p>
  6847. * <p>Note: Only Ext.Panels <b>and all subclasses of Ext.Panel</b> may be used in an accordion layout Container.</p>
  6848. * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
  6849. * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
  6850. * <p>Example usage:</p>
  6851. * <pre><code>
  6852. var accordion = new Ext.Panel({
  6853. title: 'Accordion Layout',
  6854. layout:'accordion',
  6855. defaults: {
  6856. // applied to each contained panel
  6857. bodyStyle: 'padding:15px'
  6858. },
  6859. layoutConfig: {
  6860. // layout-specific configs go here
  6861. titleCollapse: false,
  6862. animate: true,
  6863. activeOnTop: true
  6864. },
  6865. items: [{
  6866. title: 'Panel 1',
  6867. html: '&lt;p&gt;Panel content!&lt;/p&gt;'
  6868. },{
  6869. title: 'Panel 2',
  6870. html: '&lt;p&gt;Panel content!&lt;/p&gt;'
  6871. },{
  6872. title: 'Panel 3',
  6873. html: '&lt;p&gt;Panel content!&lt;/p&gt;'
  6874. }]
  6875. });
  6876. </code></pre>
  6877. */
  6878. Ext.layout.AccordionLayout = Ext.extend(Ext.layout.FitLayout, {
  6879. /**
  6880. * @cfg {Boolean} fill
  6881. * True to adjust the active item's height to fill the available space in the container, false to use the
  6882. * item's current height, or auto height if not explicitly set (defaults to true).
  6883. */
  6884. fill : true,
  6885. /**
  6886. * @cfg {Boolean} autoWidth
  6887. * True to set each contained item's width to 'auto', false to use the item's current width (defaults to true).
  6888. * Note that some components, in particular the {@link Ext.grid.GridPanel grid}, will not function properly within
  6889. * layouts if they have auto width, so in such cases this config should be set to false.
  6890. */
  6891. autoWidth : true,
  6892. /**
  6893. * @cfg {Boolean} titleCollapse
  6894. * True to allow expand/collapse of each contained panel by clicking anywhere on the title bar, false to allow
  6895. * expand/collapse only when the toggle tool button is clicked (defaults to true). When set to false,
  6896. * {@link #hideCollapseTool} should be false also.
  6897. */
  6898. titleCollapse : true,
  6899. /**
  6900. * @cfg {Boolean} hideCollapseTool
  6901. * True to hide the contained panels' collapse/expand toggle buttons, false to display them (defaults to false).
  6902. * When set to true, {@link #titleCollapse} should be true also.
  6903. */
  6904. hideCollapseTool : false,
  6905. /**
  6906. * @cfg {Boolean} collapseFirst
  6907. * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools
  6908. * in the contained panels' title bars, false to render it last (defaults to false).
  6909. */
  6910. collapseFirst : false,
  6911. /**
  6912. * @cfg {Boolean} animate
  6913. * True to slide the contained panels open and closed during expand/collapse using animation, false to open and
  6914. * close directly with no animation (defaults to false). Note: to defer to the specific config setting of each
  6915. * contained panel for this property, set this to undefined at the layout level.
  6916. */
  6917. animate : false,
  6918. /**
  6919. * @cfg {Boolean} sequence
  6920. * <b>Experimental</b>. If animate is set to true, this will result in each animation running in sequence.
  6921. */
  6922. sequence : false,
  6923. /**
  6924. * @cfg {Boolean} activeOnTop
  6925. * True to swap the position of each panel as it is expanded so that it becomes the first item in the container,
  6926. * false to keep the panels in the rendered order. <b>This is NOT compatible with "animate:true"</b> (defaults to false).
  6927. */
  6928. activeOnTop : false,
  6929. type: 'accordion',
  6930. renderItem : function(c){
  6931. if(this.animate === false){
  6932. c.animCollapse = false;
  6933. }
  6934. c.collapsible = true;
  6935. if(this.autoWidth){
  6936. c.autoWidth = true;
  6937. }
  6938. if(this.titleCollapse){
  6939. c.titleCollapse = true;
  6940. }
  6941. if(this.hideCollapseTool){
  6942. c.hideCollapseTool = true;
  6943. }
  6944. if(this.collapseFirst !== undefined){
  6945. c.collapseFirst = this.collapseFirst;
  6946. }
  6947. if(!this.activeItem && !c.collapsed){
  6948. this.setActiveItem(c, true);
  6949. }else if(this.activeItem && this.activeItem != c){
  6950. c.collapsed = true;
  6951. }
  6952. Ext.layout.AccordionLayout.superclass.renderItem.apply(this, arguments);
  6953. c.header.addClass('x-accordion-hd');
  6954. c.on('beforeexpand', this.beforeExpand, this);
  6955. },
  6956. onRemove: function(c){
  6957. Ext.layout.AccordionLayout.superclass.onRemove.call(this, c);
  6958. if(c.rendered){
  6959. c.header.removeClass('x-accordion-hd');
  6960. }
  6961. c.un('beforeexpand', this.beforeExpand, this);
  6962. },
  6963. // private
  6964. beforeExpand : function(p, anim){
  6965. var ai = this.activeItem;
  6966. if(ai){
  6967. if(this.sequence){
  6968. delete this.activeItem;
  6969. if (!ai.collapsed){
  6970. ai.collapse({callback:function(){
  6971. p.expand(anim || true);
  6972. }, scope: this});
  6973. return false;
  6974. }
  6975. }else{
  6976. ai.collapse(this.animate);
  6977. }
  6978. }
  6979. this.setActive(p);
  6980. if(this.activeOnTop){
  6981. p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);
  6982. }
  6983. // Items have been hidden an possibly rearranged, we need to get the container size again.
  6984. this.layout();
  6985. },
  6986. // private
  6987. setItemSize : function(item, size){
  6988. if(this.fill && item){
  6989. var hh = 0, i, ct = this.getRenderedItems(this.container), len = ct.length, p;
  6990. // Add up all the header heights
  6991. for (i = 0; i < len; i++) {
  6992. if((p = ct[i]) != item && !p.hidden){
  6993. hh += p.header.getHeight();
  6994. }
  6995. };
  6996. // Subtract the header heights from the container size
  6997. size.height -= hh;
  6998. // Call setSize on the container to set the correct height. For Panels, deferedHeight
  6999. // will simply store this size for when the expansion is done.
  7000. item.setSize(size);
  7001. }
  7002. },
  7003. /**
  7004. * Sets the active (expanded) item in the layout.
  7005. * @param {String/Number} item The string component id or numeric index of the item to activate
  7006. */
  7007. setActiveItem : function(item){
  7008. this.setActive(item, true);
  7009. },
  7010. // private
  7011. setActive : function(item, expand){
  7012. var ai = this.activeItem;
  7013. item = this.container.getComponent(item);
  7014. if(ai != item){
  7015. if(item.rendered && item.collapsed && expand){
  7016. item.expand();
  7017. }else{
  7018. if(ai){
  7019. ai.fireEvent('deactivate', ai);
  7020. }
  7021. this.activeItem = item;
  7022. item.fireEvent('activate', item);
  7023. }
  7024. }
  7025. }
  7026. });
  7027. Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;
  7028. //backwards compat
  7029. Ext.layout.Accordion = Ext.layout.AccordionLayout;/**
  7030. * @class Ext.layout.TableLayout
  7031. * @extends Ext.layout.ContainerLayout
  7032. * <p>This layout allows you to easily render content into an HTML table. The total number of columns can be
  7033. * specified, and rowspan and colspan can be used to create complex layouts within the table.
  7034. * This class is intended to be extended or created via the layout:'table' {@link Ext.Container#layout} config,
  7035. * and should generally not need to be created directly via the new keyword.</p>
  7036. * <p>Note that when creating a layout via config, the layout-specific config properties must be passed in via
  7037. * the {@link Ext.Container#layoutConfig} object which will then be applied internally to the layout. In the
  7038. * case of TableLayout, the only valid layout config property is {@link #columns}. However, the items added to a
  7039. * TableLayout can supply the following table-specific config properties:</p>
  7040. * <ul>
  7041. * <li><b>rowspan</b> Applied to the table cell containing the item.</li>
  7042. * <li><b>colspan</b> Applied to the table cell containing the item.</li>
  7043. * <li><b>cellId</b> An id applied to the table cell containing the item.</li>
  7044. * <li><b>cellCls</b> A CSS class name added to the table cell containing the item.</li>
  7045. * </ul>
  7046. * <p>The basic concept of building up a TableLayout is conceptually very similar to building up a standard
  7047. * HTML table. You simply add each panel (or "cell") that you want to include along with any span attributes
  7048. * specified as the special config properties of rowspan and colspan which work exactly like their HTML counterparts.
  7049. * Rather than explicitly creating and nesting rows and columns as you would in HTML, you simply specify the
  7050. * total column count in the layoutConfig and start adding panels in their natural order from left to right,
  7051. * top to bottom. The layout will automatically figure out, based on the column count, rowspans and colspans,
  7052. * how to position each panel within the table. Just like with HTML tables, your rowspans and colspans must add
  7053. * up correctly in your overall layout or you'll end up with missing and/or extra cells! Example usage:</p>
  7054. * <pre><code>
  7055. // This code will generate a layout table that is 3 columns by 2 rows
  7056. // with some spanning included. The basic layout will be:
  7057. // +--------+-----------------+
  7058. // | A | B |
  7059. // | |--------+--------|
  7060. // | | C | D |
  7061. // +--------+--------+--------+
  7062. var table = new Ext.Panel({
  7063. title: 'Table Layout',
  7064. layout:'table',
  7065. defaults: {
  7066. // applied to each contained panel
  7067. bodyStyle:'padding:20px'
  7068. },
  7069. layoutConfig: {
  7070. // The total column count must be specified here
  7071. columns: 3
  7072. },
  7073. items: [{
  7074. html: '&lt;p&gt;Cell A content&lt;/p&gt;',
  7075. rowspan: 2
  7076. },{
  7077. html: '&lt;p&gt;Cell B content&lt;/p&gt;',
  7078. colspan: 2
  7079. },{
  7080. html: '&lt;p&gt;Cell C content&lt;/p&gt;',
  7081. cellCls: 'highlight'
  7082. },{
  7083. html: '&lt;p&gt;Cell D content&lt;/p&gt;'
  7084. }]
  7085. });
  7086. </code></pre>
  7087. */
  7088. Ext.layout.TableLayout = Ext.extend(Ext.layout.ContainerLayout, {
  7089. /**
  7090. * @cfg {Number} columns
  7091. * The total number of columns to create in the table for this layout. If not specified, all Components added to
  7092. * this layout will be rendered into a single row using one column per Component.
  7093. */
  7094. // private
  7095. monitorResize:false,
  7096. type: 'table',
  7097. targetCls: 'x-table-layout-ct',
  7098. /**
  7099. * @cfg {Object} tableAttrs
  7100. * <p>An object containing properties which are added to the {@link Ext.DomHelper DomHelper} specification
  7101. * used to create the layout's <tt>&lt;table&gt;</tt> element. Example:</p><pre><code>
  7102. {
  7103. xtype: 'panel',
  7104. layout: 'table',
  7105. layoutConfig: {
  7106. tableAttrs: {
  7107. style: {
  7108. width: '100%'
  7109. }
  7110. },
  7111. columns: 3
  7112. }
  7113. }</code></pre>
  7114. */
  7115. tableAttrs:null,
  7116. // private
  7117. setContainer : function(ct){
  7118. Ext.layout.TableLayout.superclass.setContainer.call(this, ct);
  7119. this.currentRow = 0;
  7120. this.currentColumn = 0;
  7121. this.cells = [];
  7122. },
  7123. // private
  7124. onLayout : function(ct, target){
  7125. var cs = ct.items.items, len = cs.length, c, i;
  7126. if(!this.table){
  7127. target.addClass('x-table-layout-ct');
  7128. this.table = target.createChild(
  7129. Ext.apply({tag:'table', cls:'x-table-layout', cellspacing: 0, cn: {tag: 'tbody'}}, this.tableAttrs), null, true);
  7130. }
  7131. this.renderAll(ct, target);
  7132. },
  7133. // private
  7134. getRow : function(index){
  7135. var row = this.table.tBodies[0].childNodes[index];
  7136. if(!row){
  7137. row = document.createElement('tr');
  7138. this.table.tBodies[0].appendChild(row);
  7139. }
  7140. return row;
  7141. },
  7142. // private
  7143. getNextCell : function(c){
  7144. var cell = this.getNextNonSpan(this.currentColumn, this.currentRow);
  7145. var curCol = this.currentColumn = cell[0], curRow = this.currentRow = cell[1];
  7146. for(var rowIndex = curRow; rowIndex < curRow + (c.rowspan || 1); rowIndex++){
  7147. if(!this.cells[rowIndex]){
  7148. this.cells[rowIndex] = [];
  7149. }
  7150. for(var colIndex = curCol; colIndex < curCol + (c.colspan || 1); colIndex++){
  7151. this.cells[rowIndex][colIndex] = true;
  7152. }
  7153. }
  7154. var td = document.createElement('td');
  7155. if(c.cellId){
  7156. td.id = c.cellId;
  7157. }
  7158. var cls = 'x-table-layout-cell';
  7159. if(c.cellCls){
  7160. cls += ' ' + c.cellCls;
  7161. }
  7162. td.className = cls;
  7163. if(c.colspan){
  7164. td.colSpan = c.colspan;
  7165. }
  7166. if(c.rowspan){
  7167. td.rowSpan = c.rowspan;
  7168. }
  7169. this.getRow(curRow).appendChild(td);
  7170. return td;
  7171. },
  7172. // private
  7173. getNextNonSpan: function(colIndex, rowIndex){
  7174. var cols = this.columns;
  7175. while((cols && colIndex >= cols) || (this.cells[rowIndex] && this.cells[rowIndex][colIndex])) {
  7176. if(cols && colIndex >= cols){
  7177. rowIndex++;
  7178. colIndex = 0;
  7179. }else{
  7180. colIndex++;
  7181. }
  7182. }
  7183. return [colIndex, rowIndex];
  7184. },
  7185. // private
  7186. renderItem : function(c, position, target){
  7187. // Ensure we have our inner table to get cells to render into.
  7188. if(!this.table){
  7189. this.table = target.createChild(
  7190. Ext.apply({tag:'table', cls:'x-table-layout', cellspacing: 0, cn: {tag: 'tbody'}}, this.tableAttrs), null, true);
  7191. }
  7192. if(c && !c.rendered){
  7193. c.render(this.getNextCell(c));
  7194. this.configureItem(c);
  7195. }else if(c && !this.isValidParent(c, target)){
  7196. var container = this.getNextCell(c);
  7197. container.insertBefore(c.getPositionEl().dom, null);
  7198. c.container = Ext.get(container);
  7199. this.configureItem(c);
  7200. }
  7201. },
  7202. // private
  7203. isValidParent : function(c, target){
  7204. return c.getPositionEl().up('table', 5).dom.parentNode === (target.dom || target);
  7205. },
  7206. destroy: function(){
  7207. delete this.table;
  7208. Ext.layout.TableLayout.superclass.destroy.call(this);
  7209. }
  7210. /**
  7211. * @property activeItem
  7212. * @hide
  7213. */
  7214. });
  7215. Ext.Container.LAYOUTS['table'] = Ext.layout.TableLayout;/**
  7216. * @class Ext.layout.AbsoluteLayout
  7217. * @extends Ext.layout.AnchorLayout
  7218. * <p>This is a layout that inherits the anchoring of <b>{@link Ext.layout.AnchorLayout}</b> and adds the
  7219. * ability for x/y positioning using the standard x and y component config options.</p>
  7220. * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.Container#layout layout}</b></tt>
  7221. * configuration property. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
  7222. * <p>Example usage:</p>
  7223. * <pre><code>
  7224. var form = new Ext.form.FormPanel({
  7225. title: 'Absolute Layout',
  7226. layout:'absolute',
  7227. layoutConfig: {
  7228. // layout-specific configs go here
  7229. extraCls: 'x-abs-layout-item',
  7230. },
  7231. baseCls: 'x-plain',
  7232. url:'save-form.php',
  7233. defaultType: 'textfield',
  7234. items: [{
  7235. x: 0,
  7236. y: 5,
  7237. xtype:'label',
  7238. text: 'Send To:'
  7239. },{
  7240. x: 60,
  7241. y: 0,
  7242. name: 'to',
  7243. anchor:'100%' // anchor width by percentage
  7244. },{
  7245. x: 0,
  7246. y: 35,
  7247. xtype:'label',
  7248. text: 'Subject:'
  7249. },{
  7250. x: 60,
  7251. y: 30,
  7252. name: 'subject',
  7253. anchor: '100%' // anchor width by percentage
  7254. },{
  7255. x:0,
  7256. y: 60,
  7257. xtype: 'textarea',
  7258. name: 'msg',
  7259. anchor: '100% 100%' // anchor width and height
  7260. }]
  7261. });
  7262. </code></pre>
  7263. */
  7264. Ext.layout.AbsoluteLayout = Ext.extend(Ext.layout.AnchorLayout, {
  7265. extraCls: 'x-abs-layout-item',
  7266. type: 'absolute',
  7267. onLayout : function(ct, target){
  7268. target.position();
  7269. this.paddingLeft = target.getPadding('l');
  7270. this.paddingTop = target.getPadding('t');
  7271. Ext.layout.AbsoluteLayout.superclass.onLayout.call(this, ct, target);
  7272. },
  7273. // private
  7274. adjustWidthAnchor : function(value, comp){
  7275. return value ? value - comp.getPosition(true)[0] + this.paddingLeft : value;
  7276. },
  7277. // private
  7278. adjustHeightAnchor : function(value, comp){
  7279. return value ? value - comp.getPosition(true)[1] + this.paddingTop : value;
  7280. }
  7281. /**
  7282. * @property activeItem
  7283. * @hide
  7284. */
  7285. });
  7286. Ext.Container.LAYOUTS['absolute'] = Ext.layout.AbsoluteLayout;
  7287. /**
  7288. * @class Ext.layout.BoxLayout
  7289. * @extends Ext.layout.ContainerLayout
  7290. * <p>Base Class for HBoxLayout and VBoxLayout Classes. Generally it should not need to be used directly.</p>
  7291. */
  7292. Ext.layout.BoxLayout = Ext.extend(Ext.layout.ContainerLayout, {
  7293. /**
  7294. * @cfg {Object} defaultMargins
  7295. * <p>If the individual contained items do not have a <tt>margins</tt>
  7296. * property specified, the default margins from this property will be
  7297. * applied to each item.</p>
  7298. * <br><p>This property may be specified as an object containing margins
  7299. * to apply in the format:</p><pre><code>
  7300. {
  7301. top: (top margin),
  7302. right: (right margin),
  7303. bottom: (bottom margin),
  7304. left: (left margin)
  7305. }</code></pre>
  7306. * <p>This property may also be specified as a string containing
  7307. * space-separated, numeric margin values. The order of the sides associated
  7308. * with each value matches the way CSS processes margin values:</p>
  7309. * <div class="mdetail-params"><ul>
  7310. * <li>If there is only one value, it applies to all sides.</li>
  7311. * <li>If there are two values, the top and bottom borders are set to the
  7312. * first value and the right and left are set to the second.</li>
  7313. * <li>If there are three values, the top is set to the first value, the left
  7314. * and right are set to the second, and the bottom is set to the third.</li>
  7315. * <li>If there are four values, they apply to the top, right, bottom, and
  7316. * left, respectively.</li>
  7317. * </ul></div>
  7318. * <p>Defaults to:</p><pre><code>
  7319. * {top:0, right:0, bottom:0, left:0}
  7320. * </code></pre>
  7321. */
  7322. defaultMargins : {left:0,top:0,right:0,bottom:0},
  7323. /**
  7324. * @cfg {String} padding
  7325. * <p>Sets the padding to be applied to all child items managed by this layout.</p>
  7326. * <p>This property must be specified as a string containing
  7327. * space-separated, numeric padding values. The order of the sides associated
  7328. * with each value matches the way CSS processes padding values:</p>
  7329. * <div class="mdetail-params"><ul>
  7330. * <li>If there is only one value, it applies to all sides.</li>
  7331. * <li>If there are two values, the top and bottom borders are set to the
  7332. * first value and the right and left are set to the second.</li>
  7333. * <li>If there are three values, the top is set to the first value, the left
  7334. * and right are set to the second, and the bottom is set to the third.</li>
  7335. * <li>If there are four values, they apply to the top, right, bottom, and
  7336. * left, respectively.</li>
  7337. * </ul></div>
  7338. * <p>Defaults to: <code>"0"</code></p>
  7339. */
  7340. padding : '0',
  7341. // documented in subclasses
  7342. pack : 'start',
  7343. // private
  7344. monitorResize : true,
  7345. type: 'box',
  7346. scrollOffset : 0,
  7347. extraCls : 'x-box-item',
  7348. targetCls : 'x-box-layout-ct',
  7349. innerCls : 'x-box-inner',
  7350. constructor : function(config){
  7351. Ext.layout.BoxLayout.superclass.constructor.call(this, config);
  7352. if (Ext.isString(this.defaultMargins)) {
  7353. this.defaultMargins = this.parseMargins(this.defaultMargins);
  7354. }
  7355. var handler = this.overflowHandler;
  7356. if (typeof handler == 'string') {
  7357. handler = {
  7358. type: handler
  7359. };
  7360. }
  7361. var handlerType = 'none';
  7362. if (handler && handler.type != undefined) {
  7363. handlerType = handler.type;
  7364. }
  7365. var constructor = Ext.layout.boxOverflow[handlerType];
  7366. if (constructor[this.type]) {
  7367. constructor = constructor[this.type];
  7368. }
  7369. this.overflowHandler = new constructor(this, handler);
  7370. },
  7371. /**
  7372. * @private
  7373. * Runs the child box calculations and caches them in childBoxCache. Subclasses can used these cached values
  7374. * when laying out
  7375. */
  7376. onLayout: function(container, target) {
  7377. Ext.layout.BoxLayout.superclass.onLayout.call(this, container, target);
  7378. var tSize = this.getLayoutTargetSize(),
  7379. items = this.getVisibleItems(container),
  7380. calcs = this.calculateChildBoxes(items, tSize),
  7381. boxes = calcs.boxes,
  7382. meta = calcs.meta;
  7383. //invoke the overflow handler, if one is configured
  7384. if (tSize.width > 0) {
  7385. var handler = this.overflowHandler,
  7386. method = meta.tooNarrow ? 'handleOverflow' : 'clearOverflow';
  7387. var results = handler[method](calcs, tSize);
  7388. if (results) {
  7389. if (results.targetSize) {
  7390. tSize = results.targetSize;
  7391. }
  7392. if (results.recalculate) {
  7393. items = this.getVisibleItems(container);
  7394. calcs = this.calculateChildBoxes(items, tSize);
  7395. boxes = calcs.boxes;
  7396. }
  7397. }
  7398. }
  7399. /**
  7400. * @private
  7401. * @property layoutTargetLastSize
  7402. * @type Object
  7403. * Private cache of the last measured size of the layout target. This should never be used except by
  7404. * BoxLayout subclasses during their onLayout run.
  7405. */
  7406. this.layoutTargetLastSize = tSize;
  7407. /**
  7408. * @private
  7409. * @property childBoxCache
  7410. * @type Array
  7411. * Array of the last calculated height, width, top and left positions of each visible rendered component
  7412. * within the Box layout.
  7413. */
  7414. this.childBoxCache = calcs;
  7415. this.updateInnerCtSize(tSize, calcs);
  7416. this.updateChildBoxes(boxes);
  7417. // Putting a box layout into an overflowed container is NOT correct and will make a second layout pass necessary.
  7418. this.handleTargetOverflow(tSize, container, target);
  7419. },
  7420. /**
  7421. * Resizes and repositions each child component
  7422. * @param {Array} boxes The box measurements
  7423. */
  7424. updateChildBoxes: function(boxes) {
  7425. for (var i = 0, length = boxes.length; i < length; i++) {
  7426. var box = boxes[i],
  7427. comp = box.component;
  7428. if (box.dirtySize) {
  7429. comp.setSize(box.width, box.height);
  7430. }
  7431. // Don't set positions to NaN
  7432. if (isNaN(box.left) || isNaN(box.top)) {
  7433. continue;
  7434. }
  7435. comp.setPosition(box.left, box.top);
  7436. }
  7437. },
  7438. /**
  7439. * @private
  7440. * Called by onRender just before the child components are sized and positioned. This resizes the innerCt
  7441. * to make sure all child items fit within it. We call this before sizing the children because if our child
  7442. * items are larger than the previous innerCt size the browser will insert scrollbars and then remove them
  7443. * again immediately afterwards, giving a performance hit.
  7444. * Subclasses should provide an implementation.
  7445. * @param {Object} currentSize The current height and width of the innerCt
  7446. * @param {Array} calculations The new box calculations of all items to be laid out
  7447. */
  7448. updateInnerCtSize: function(tSize, calcs) {
  7449. var align = this.align,
  7450. padding = this.padding,
  7451. width = tSize.width,
  7452. height = tSize.height;
  7453. if (this.type == 'hbox') {
  7454. var innerCtWidth = width,
  7455. innerCtHeight = calcs.meta.maxHeight + padding.top + padding.bottom;
  7456. if (align == 'stretch') {
  7457. innerCtHeight = height;
  7458. } else if (align == 'middle') {
  7459. innerCtHeight = Math.max(height, innerCtHeight);
  7460. }
  7461. } else {
  7462. var innerCtHeight = height,
  7463. innerCtWidth = calcs.meta.maxWidth + padding.left + padding.right;
  7464. if (align == 'stretch') {
  7465. innerCtWidth = width;
  7466. } else if (align == 'center') {
  7467. innerCtWidth = Math.max(width, innerCtWidth);
  7468. }
  7469. }
  7470. this.innerCt.setSize(innerCtWidth || undefined, innerCtHeight || undefined);
  7471. },
  7472. /**
  7473. * @private
  7474. * This should be called after onLayout of any BoxLayout subclass. If the target's overflow is not set to 'hidden',
  7475. * we need to lay out a second time because the scrollbars may have modified the height and width of the layout
  7476. * target. Having a Box layout inside such a target is therefore not recommended.
  7477. * @param {Object} previousTargetSize The size and height of the layout target before we just laid out
  7478. * @param {Ext.Container} container The container
  7479. * @param {Ext.Element} target The target element
  7480. */
  7481. handleTargetOverflow: function(previousTargetSize, container, target) {
  7482. var overflow = target.getStyle('overflow');
  7483. if (overflow && overflow != 'hidden' &&!this.adjustmentPass) {
  7484. var newTargetSize = this.getLayoutTargetSize();
  7485. if (newTargetSize.width != previousTargetSize.width || newTargetSize.height != previousTargetSize.height){
  7486. this.adjustmentPass = true;
  7487. this.onLayout(container, target);
  7488. }
  7489. }
  7490. delete this.adjustmentPass;
  7491. },
  7492. // private
  7493. isValidParent : function(c, target) {
  7494. return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
  7495. },
  7496. /**
  7497. * @private
  7498. * Returns all items that are both rendered and visible
  7499. * @return {Array} All matching items
  7500. */
  7501. getVisibleItems: function(ct) {
  7502. var ct = ct || this.container,
  7503. t = ct.getLayoutTarget(),
  7504. cti = ct.items.items,
  7505. len = cti.length,
  7506. i, c, items = [];
  7507. for (i = 0; i < len; i++) {
  7508. if((c = cti[i]).rendered && this.isValidParent(c, t) && c.hidden !== true && c.collapsed !== true && c.shouldLayout !== false){
  7509. items.push(c);
  7510. }
  7511. }
  7512. return items;
  7513. },
  7514. // private
  7515. renderAll : function(ct, target) {
  7516. if (!this.innerCt) {
  7517. // the innerCt prevents wrapping and shuffling while the container is resizing
  7518. this.innerCt = target.createChild({cls:this.innerCls});
  7519. this.padding = this.parseMargins(this.padding);
  7520. }
  7521. Ext.layout.BoxLayout.superclass.renderAll.call(this, ct, this.innerCt);
  7522. },
  7523. getLayoutTargetSize : function() {
  7524. var target = this.container.getLayoutTarget(), ret;
  7525. if (target) {
  7526. ret = target.getViewSize();
  7527. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  7528. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  7529. // with getViewSize
  7530. if (Ext.isIE && Ext.isStrict && ret.width == 0){
  7531. ret = target.getStyleSize();
  7532. }
  7533. ret.width -= target.getPadding('lr');
  7534. ret.height -= target.getPadding('tb');
  7535. }
  7536. return ret;
  7537. },
  7538. // private
  7539. renderItem : function(c) {
  7540. if(Ext.isString(c.margins)){
  7541. c.margins = this.parseMargins(c.margins);
  7542. }else if(!c.margins){
  7543. c.margins = this.defaultMargins;
  7544. }
  7545. Ext.layout.BoxLayout.superclass.renderItem.apply(this, arguments);
  7546. },
  7547. /**
  7548. * @private
  7549. */
  7550. destroy: function() {
  7551. Ext.destroy(this.overflowHandler);
  7552. Ext.layout.BoxLayout.superclass.destroy.apply(this, arguments);
  7553. }
  7554. });
  7555. Ext.ns('Ext.layout.boxOverflow');
  7556. /**
  7557. * @class Ext.layout.boxOverflow.None
  7558. * @extends Object
  7559. * Base class for Box Layout overflow handlers. These specialized classes are invoked when a Box Layout
  7560. * (either an HBox or a VBox) has child items that are either too wide (for HBox) or too tall (for VBox)
  7561. * for its container.
  7562. */
  7563. Ext.layout.boxOverflow.None = Ext.extend(Object, {
  7564. constructor: function(layout, config) {
  7565. this.layout = layout;
  7566. Ext.apply(this, config || {});
  7567. },
  7568. handleOverflow: Ext.emptyFn,
  7569. clearOverflow: Ext.emptyFn
  7570. });
  7571. Ext.layout.boxOverflow.none = Ext.layout.boxOverflow.None;
  7572. /**
  7573. * @class Ext.layout.boxOverflow.Menu
  7574. * @extends Ext.layout.boxOverflow.None
  7575. * Description
  7576. */
  7577. Ext.layout.boxOverflow.Menu = Ext.extend(Ext.layout.boxOverflow.None, {
  7578. /**
  7579. * @cfg afterCls
  7580. * @type String
  7581. * CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
  7582. * which must always be present at the rightmost edge of the Container
  7583. */
  7584. afterCls: 'x-strip-right',
  7585. /**
  7586. * @property noItemsMenuText
  7587. * @type String
  7588. * HTML fragment to render into the toolbar overflow menu if there are no items to display
  7589. */
  7590. noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
  7591. constructor: function(layout) {
  7592. Ext.layout.boxOverflow.Menu.superclass.constructor.apply(this, arguments);
  7593. /**
  7594. * @property menuItems
  7595. * @type Array
  7596. * Array of all items that are currently hidden and should go into the dropdown menu
  7597. */
  7598. this.menuItems = [];
  7599. },
  7600. /**
  7601. * @private
  7602. * Creates the beforeCt, innerCt and afterCt elements if they have not already been created
  7603. * @param {Ext.Container} container The Container attached to this Layout instance
  7604. * @param {Ext.Element} target The target Element
  7605. */
  7606. createInnerElements: function() {
  7607. if (!this.afterCt) {
  7608. this.afterCt = this.layout.innerCt.insertSibling({cls: this.afterCls}, 'before');
  7609. }
  7610. },
  7611. /**
  7612. * @private
  7613. */
  7614. clearOverflow: function(calculations, targetSize) {
  7615. var newWidth = targetSize.width + (this.afterCt ? this.afterCt.getWidth() : 0),
  7616. items = this.menuItems;
  7617. this.hideTrigger();
  7618. for (var index = 0, length = items.length; index < length; index++) {
  7619. items.pop().component.show();
  7620. }
  7621. return {
  7622. targetSize: {
  7623. height: targetSize.height,
  7624. width : newWidth
  7625. }
  7626. };
  7627. },
  7628. /**
  7629. * @private
  7630. */
  7631. showTrigger: function() {
  7632. this.createMenu();
  7633. this.menuTrigger.show();
  7634. },
  7635. /**
  7636. * @private
  7637. */
  7638. hideTrigger: function() {
  7639. if (this.menuTrigger != undefined) {
  7640. this.menuTrigger.hide();
  7641. }
  7642. },
  7643. /**
  7644. * @private
  7645. * Called before the overflow menu is shown. This constructs the menu's items, caching them for as long as it can.
  7646. */
  7647. beforeMenuShow: function(menu) {
  7648. var items = this.menuItems,
  7649. len = items.length,
  7650. item,
  7651. prev;
  7652. var needsSep = function(group, item){
  7653. return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
  7654. };
  7655. this.clearMenu();
  7656. menu.removeAll();
  7657. for (var i = 0; i < len; i++) {
  7658. item = items[i].component;
  7659. if (prev && (needsSep(item, prev) || needsSep(prev, item))) {
  7660. menu.add('-');
  7661. }
  7662. this.addComponentToMenu(menu, item);
  7663. prev = item;
  7664. }
  7665. // put something so the menu isn't empty if no compatible items found
  7666. if (menu.items.length < 1) {
  7667. menu.add(this.noItemsMenuText);
  7668. }
  7669. },
  7670. /**
  7671. * @private
  7672. * Returns a menu config for a given component. This config is used to create a menu item
  7673. * to be added to the expander menu
  7674. * @param {Ext.Component} component The component to create the config for
  7675. * @param {Boolean} hideOnClick Passed through to the menu item
  7676. */
  7677. createMenuConfig : function(component, hideOnClick){
  7678. var config = Ext.apply({}, component.initialConfig),
  7679. group = component.toggleGroup;
  7680. Ext.copyTo(config, component, [
  7681. 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
  7682. ]);
  7683. Ext.apply(config, {
  7684. text : component.overflowText || component.text,
  7685. hideOnClick: hideOnClick
  7686. });
  7687. if (group || component.enableToggle) {
  7688. Ext.apply(config, {
  7689. group : group,
  7690. checked: component.pressed,
  7691. listeners: {
  7692. checkchange: function(item, checked){
  7693. component.toggle(checked);
  7694. }
  7695. }
  7696. });
  7697. }
  7698. delete config.ownerCt;
  7699. delete config.xtype;
  7700. delete config.id;
  7701. return config;
  7702. },
  7703. /**
  7704. * @private
  7705. * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
  7706. * @param {Ext.menu.Menu} menu The menu to add to
  7707. * @param {Ext.Component} component The component to add
  7708. */
  7709. addComponentToMenu : function(menu, component) {
  7710. if (component instanceof Ext.Toolbar.Separator) {
  7711. menu.add('-');
  7712. } else if (Ext.isFunction(component.isXType)) {
  7713. if (component.isXType('splitbutton')) {
  7714. menu.add(this.createMenuConfig(component, true));
  7715. } else if (component.isXType('button')) {
  7716. menu.add(this.createMenuConfig(component, !component.menu));
  7717. } else if (component.isXType('buttongroup')) {
  7718. component.items.each(function(item){
  7719. this.addComponentToMenu(menu, item);
  7720. }, this);
  7721. }
  7722. }
  7723. },
  7724. /**
  7725. * @private
  7726. * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
  7727. * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
  7728. */
  7729. clearMenu : function(){
  7730. var menu = this.moreMenu;
  7731. if (menu && menu.items) {
  7732. menu.items.each(function(item){
  7733. delete item.menu;
  7734. });
  7735. }
  7736. },
  7737. /**
  7738. * @private
  7739. * Creates the overflow trigger and menu used when enableOverflow is set to true and the items
  7740. * in the layout are too wide to fit in the space available
  7741. */
  7742. createMenu: function() {
  7743. if (!this.menuTrigger) {
  7744. this.createInnerElements();
  7745. /**
  7746. * @private
  7747. * @property menu
  7748. * @type Ext.menu.Menu
  7749. * The expand menu - holds items for every item that cannot be shown
  7750. * because the container is currently not large enough.
  7751. */
  7752. this.menu = new Ext.menu.Menu({
  7753. ownerCt : this.layout.container,
  7754. listeners: {
  7755. scope: this,
  7756. beforeshow: this.beforeMenuShow
  7757. }
  7758. });
  7759. /**
  7760. * @private
  7761. * @property menuTrigger
  7762. * @type Ext.Button
  7763. * The expand button which triggers the overflow menu to be shown
  7764. */
  7765. this.menuTrigger = new Ext.Button({
  7766. iconCls : 'x-toolbar-more-icon',
  7767. cls : 'x-toolbar-more',
  7768. menu : this.menu,
  7769. renderTo: this.afterCt
  7770. });
  7771. }
  7772. },
  7773. /**
  7774. * @private
  7775. */
  7776. destroy: function() {
  7777. Ext.destroy(this.menu, this.menuTrigger);
  7778. }
  7779. });
  7780. Ext.layout.boxOverflow.menu = Ext.layout.boxOverflow.Menu;
  7781. /**
  7782. * @class Ext.layout.boxOverflow.HorizontalMenu
  7783. * @extends Ext.layout.boxOverflow.Menu
  7784. * Description
  7785. */
  7786. Ext.layout.boxOverflow.HorizontalMenu = Ext.extend(Ext.layout.boxOverflow.Menu, {
  7787. constructor: function() {
  7788. Ext.layout.boxOverflow.HorizontalMenu.superclass.constructor.apply(this, arguments);
  7789. var me = this,
  7790. layout = me.layout,
  7791. origFunction = layout.calculateChildBoxes;
  7792. layout.calculateChildBoxes = function(visibleItems, targetSize) {
  7793. var calcs = origFunction.apply(layout, arguments),
  7794. meta = calcs.meta,
  7795. items = me.menuItems;
  7796. //calculate the width of the items currently hidden solely because there is not enough space
  7797. //to display them
  7798. var hiddenWidth = 0;
  7799. for (var index = 0, length = items.length; index < length; index++) {
  7800. hiddenWidth += items[index].width;
  7801. }
  7802. meta.minimumWidth += hiddenWidth;
  7803. meta.tooNarrow = meta.minimumWidth > targetSize.width;
  7804. return calcs;
  7805. };
  7806. },
  7807. handleOverflow: function(calculations, targetSize) {
  7808. this.showTrigger();
  7809. var newWidth = targetSize.width - this.afterCt.getWidth(),
  7810. boxes = calculations.boxes,
  7811. usedWidth = 0,
  7812. recalculate = false;
  7813. //calculate the width of all visible items and any spare width
  7814. for (var index = 0, length = boxes.length; index < length; index++) {
  7815. usedWidth += boxes[index].width;
  7816. }
  7817. var spareWidth = newWidth - usedWidth,
  7818. showCount = 0;
  7819. //see if we can re-show any of the hidden components
  7820. for (var index = 0, length = this.menuItems.length; index < length; index++) {
  7821. var hidden = this.menuItems[index],
  7822. comp = hidden.component,
  7823. width = hidden.width;
  7824. if (width < spareWidth) {
  7825. comp.show();
  7826. spareWidth -= width;
  7827. showCount ++;
  7828. recalculate = true;
  7829. } else {
  7830. break;
  7831. }
  7832. }
  7833. if (recalculate) {
  7834. this.menuItems = this.menuItems.slice(showCount);
  7835. } else {
  7836. for (var i = boxes.length - 1; i >= 0; i--) {
  7837. var item = boxes[i].component,
  7838. right = boxes[i].left + boxes[i].width;
  7839. if (right >= newWidth) {
  7840. this.menuItems.unshift({
  7841. component: item,
  7842. width : boxes[i].width
  7843. });
  7844. item.hide();
  7845. } else {
  7846. break;
  7847. }
  7848. }
  7849. }
  7850. if (this.menuItems.length == 0) {
  7851. this.hideTrigger();
  7852. }
  7853. return {
  7854. targetSize: {
  7855. height: targetSize.height,
  7856. width : newWidth
  7857. },
  7858. recalculate: recalculate
  7859. };
  7860. }
  7861. });
  7862. Ext.layout.boxOverflow.menu.hbox = Ext.layout.boxOverflow.HorizontalMenu;/**
  7863. * @class Ext.layout.boxOverflow.Scroller
  7864. * @extends Ext.layout.boxOverflow.None
  7865. * Description
  7866. */
  7867. Ext.layout.boxOverflow.Scroller = Ext.extend(Ext.layout.boxOverflow.None, {
  7868. /**
  7869. * @cfg animateScroll
  7870. * @type Boolean
  7871. * True to animate the scrolling of items within the layout (defaults to true, ignored if enableScroll is false)
  7872. */
  7873. animateScroll: true,
  7874. /**
  7875. * @cfg scrollIncrement
  7876. * @type Number
  7877. * The number of pixels to scroll by on scroller click (defaults to 100)
  7878. */
  7879. scrollIncrement: 100,
  7880. /**
  7881. * @cfg wheelIncrement
  7882. * @type Number
  7883. * The number of pixels to increment on mouse wheel scrolling (defaults to <tt>3</tt>).
  7884. */
  7885. wheelIncrement: 3,
  7886. /**
  7887. * @cfg scrollRepeatInterval
  7888. * @type Number
  7889. * Number of milliseconds between each scroll while a scroller button is held down (defaults to 400)
  7890. */
  7891. scrollRepeatInterval: 400,
  7892. /**
  7893. * @cfg scrollDuration
  7894. * @type Number
  7895. * Number of seconds that each scroll animation lasts (defaults to 0.4)
  7896. */
  7897. scrollDuration: 0.4,
  7898. /**
  7899. * @cfg beforeCls
  7900. * @type String
  7901. * CSS class added to the beforeCt element. This is the element that holds any special items such as scrollers,
  7902. * which must always be present at the leftmost edge of the Container
  7903. */
  7904. beforeCls: 'x-strip-left',
  7905. /**
  7906. * @cfg afterCls
  7907. * @type String
  7908. * CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
  7909. * which must always be present at the rightmost edge of the Container
  7910. */
  7911. afterCls: 'x-strip-right',
  7912. /**
  7913. * @cfg scrollerCls
  7914. * @type String
  7915. * CSS class added to both scroller elements if enableScroll is used
  7916. */
  7917. scrollerCls: 'x-strip-scroller',
  7918. /**
  7919. * @cfg beforeScrollerCls
  7920. * @type String
  7921. * CSS class added to the left scroller element if enableScroll is used
  7922. */
  7923. beforeScrollerCls: 'x-strip-scroller-left',
  7924. /**
  7925. * @cfg afterScrollerCls
  7926. * @type String
  7927. * CSS class added to the right scroller element if enableScroll is used
  7928. */
  7929. afterScrollerCls: 'x-strip-scroller-right',
  7930. /**
  7931. * @private
  7932. * Sets up an listener to scroll on the layout's innerCt mousewheel event
  7933. */
  7934. createWheelListener: function() {
  7935. this.layout.innerCt.on({
  7936. scope : this,
  7937. mousewheel: function(e) {
  7938. e.stopEvent();
  7939. this.scrollBy(e.getWheelDelta() * this.wheelIncrement * -1, false);
  7940. }
  7941. });
  7942. },
  7943. /**
  7944. * @private
  7945. * Most of the heavy lifting is done in the subclasses
  7946. */
  7947. handleOverflow: function(calculations, targetSize) {
  7948. this.createInnerElements();
  7949. this.showScrollers();
  7950. },
  7951. /**
  7952. * @private
  7953. */
  7954. clearOverflow: function() {
  7955. this.hideScrollers();
  7956. },
  7957. /**
  7958. * @private
  7959. * Shows the scroller elements in the beforeCt and afterCt. Creates the scrollers first if they are not already
  7960. * present.
  7961. */
  7962. showScrollers: function() {
  7963. this.createScrollers();
  7964. this.beforeScroller.show();
  7965. this.afterScroller.show();
  7966. this.updateScrollButtons();
  7967. },
  7968. /**
  7969. * @private
  7970. * Hides the scroller elements in the beforeCt and afterCt
  7971. */
  7972. hideScrollers: function() {
  7973. if (this.beforeScroller != undefined) {
  7974. this.beforeScroller.hide();
  7975. this.afterScroller.hide();
  7976. }
  7977. },
  7978. /**
  7979. * @private
  7980. * Creates the clickable scroller elements and places them into the beforeCt and afterCt
  7981. */
  7982. createScrollers: function() {
  7983. if (!this.beforeScroller && !this.afterScroller) {
  7984. var before = this.beforeCt.createChild({
  7985. cls: String.format("{0} {1} ", this.scrollerCls, this.beforeScrollerCls)
  7986. });
  7987. var after = this.afterCt.createChild({
  7988. cls: String.format("{0} {1}", this.scrollerCls, this.afterScrollerCls)
  7989. });
  7990. before.addClassOnOver(this.beforeScrollerCls + '-hover');
  7991. after.addClassOnOver(this.afterScrollerCls + '-hover');
  7992. before.setVisibilityMode(Ext.Element.DISPLAY);
  7993. after.setVisibilityMode(Ext.Element.DISPLAY);
  7994. this.beforeRepeater = new Ext.util.ClickRepeater(before, {
  7995. interval: this.scrollRepeatInterval,
  7996. handler : this.scrollLeft,
  7997. scope : this
  7998. });
  7999. this.afterRepeater = new Ext.util.ClickRepeater(after, {
  8000. interval: this.scrollRepeatInterval,
  8001. handler : this.scrollRight,
  8002. scope : this
  8003. });
  8004. /**
  8005. * @property beforeScroller
  8006. * @type Ext.Element
  8007. * The left scroller element. Only created when needed.
  8008. */
  8009. this.beforeScroller = before;
  8010. /**
  8011. * @property afterScroller
  8012. * @type Ext.Element
  8013. * The left scroller element. Only created when needed.
  8014. */
  8015. this.afterScroller = after;
  8016. }
  8017. },
  8018. /**
  8019. * @private
  8020. */
  8021. destroy: function() {
  8022. Ext.destroy(this.beforeScroller, this.afterScroller, this.beforeRepeater, this.afterRepeater, this.beforeCt, this.afterCt);
  8023. },
  8024. /**
  8025. * @private
  8026. * Scrolls left or right by the number of pixels specified
  8027. * @param {Number} delta Number of pixels to scroll to the right by. Use a negative number to scroll left
  8028. */
  8029. scrollBy: function(delta, animate) {
  8030. this.scrollTo(this.getScrollPosition() + delta, animate);
  8031. },
  8032. /**
  8033. * @private
  8034. * Normalizes an item reference, string id or numerical index into a reference to the item
  8035. * @param {Ext.Component|String|Number} item The item reference, id or index
  8036. * @return {Ext.Component} The item
  8037. */
  8038. getItem: function(item) {
  8039. if (Ext.isString(item)) {
  8040. item = Ext.getCmp(item);
  8041. } else if (Ext.isNumber(item)) {
  8042. item = this.items[item];
  8043. }
  8044. return item;
  8045. },
  8046. /**
  8047. * @private
  8048. * @return {Object} Object passed to scrollTo when scrolling
  8049. */
  8050. getScrollAnim: function() {
  8051. return {
  8052. duration: this.scrollDuration,
  8053. callback: this.updateScrollButtons,
  8054. scope : this
  8055. };
  8056. },
  8057. /**
  8058. * @private
  8059. * Enables or disables each scroller button based on the current scroll position
  8060. */
  8061. updateScrollButtons: function() {
  8062. if (this.beforeScroller == undefined || this.afterScroller == undefined) {
  8063. return;
  8064. }
  8065. var beforeMeth = this.atExtremeBefore() ? 'addClass' : 'removeClass',
  8066. afterMeth = this.atExtremeAfter() ? 'addClass' : 'removeClass',
  8067. beforeCls = this.beforeScrollerCls + '-disabled',
  8068. afterCls = this.afterScrollerCls + '-disabled';
  8069. this.beforeScroller[beforeMeth](beforeCls);
  8070. this.afterScroller[afterMeth](afterCls);
  8071. this.scrolling = false;
  8072. },
  8073. /**
  8074. * @private
  8075. * Returns true if the innerCt scroll is already at its left-most point
  8076. * @return {Boolean} True if already at furthest left point
  8077. */
  8078. atExtremeBefore: function() {
  8079. return this.getScrollPosition() === 0;
  8080. },
  8081. /**
  8082. * @private
  8083. * Scrolls to the left by the configured amount
  8084. */
  8085. scrollLeft: function(animate) {
  8086. this.scrollBy(-this.scrollIncrement, animate);
  8087. },
  8088. /**
  8089. * @private
  8090. * Scrolls to the right by the configured amount
  8091. */
  8092. scrollRight: function(animate) {
  8093. this.scrollBy(this.scrollIncrement, animate);
  8094. },
  8095. /**
  8096. * Scrolls to the given component.
  8097. * @param {String|Number|Ext.Component} item The item to scroll to. Can be a numerical index, component id
  8098. * or a reference to the component itself.
  8099. * @param {Boolean} animate True to animate the scrolling
  8100. */
  8101. scrollToItem: function(item, animate) {
  8102. item = this.getItem(item);
  8103. if (item != undefined) {
  8104. var visibility = this.getItemVisibility(item);
  8105. if (!visibility.fullyVisible) {
  8106. var box = item.getBox(true, true),
  8107. newX = box.x;
  8108. if (visibility.hiddenRight) {
  8109. newX -= (this.layout.innerCt.getWidth() - box.width);
  8110. }
  8111. this.scrollTo(newX, animate);
  8112. }
  8113. }
  8114. },
  8115. /**
  8116. * @private
  8117. * For a given item in the container, return an object with information on whether the item is visible
  8118. * with the current innerCt scroll value.
  8119. * @param {Ext.Component} item The item
  8120. * @return {Object} Values for fullyVisible, hiddenLeft and hiddenRight
  8121. */
  8122. getItemVisibility: function(item) {
  8123. var box = this.getItem(item).getBox(true, true),
  8124. itemLeft = box.x,
  8125. itemRight = box.x + box.width,
  8126. scrollLeft = this.getScrollPosition(),
  8127. scrollRight = this.layout.innerCt.getWidth() + scrollLeft;
  8128. return {
  8129. hiddenLeft : itemLeft < scrollLeft,
  8130. hiddenRight : itemRight > scrollRight,
  8131. fullyVisible: itemLeft > scrollLeft && itemRight < scrollRight
  8132. };
  8133. }
  8134. });
  8135. Ext.layout.boxOverflow.scroller = Ext.layout.boxOverflow.Scroller;
  8136. /**
  8137. * @class Ext.layout.boxOverflow.VerticalScroller
  8138. * @extends Ext.layout.boxOverflow.Scroller
  8139. * Description
  8140. */
  8141. Ext.layout.boxOverflow.VerticalScroller = Ext.extend(Ext.layout.boxOverflow.Scroller, {
  8142. scrollIncrement: 75,
  8143. wheelIncrement : 2,
  8144. handleOverflow: function(calculations, targetSize) {
  8145. Ext.layout.boxOverflow.VerticalScroller.superclass.handleOverflow.apply(this, arguments);
  8146. return {
  8147. targetSize: {
  8148. height: targetSize.height - (this.beforeCt.getHeight() + this.afterCt.getHeight()),
  8149. width : targetSize.width
  8150. }
  8151. };
  8152. },
  8153. /**
  8154. * @private
  8155. * Creates the beforeCt and afterCt elements if they have not already been created
  8156. */
  8157. createInnerElements: function() {
  8158. var target = this.layout.innerCt;
  8159. //normal items will be rendered to the innerCt. beforeCt and afterCt allow for fixed positioning of
  8160. //special items such as scrollers or dropdown menu triggers
  8161. if (!this.beforeCt) {
  8162. this.beforeCt = target.insertSibling({cls: this.beforeCls}, 'before');
  8163. this.afterCt = target.insertSibling({cls: this.afterCls}, 'after');
  8164. this.createWheelListener();
  8165. }
  8166. },
  8167. /**
  8168. * @private
  8169. * Scrolls to the given position. Performs bounds checking.
  8170. * @param {Number} position The position to scroll to. This is constrained.
  8171. * @param {Boolean} animate True to animate. If undefined, falls back to value of this.animateScroll
  8172. */
  8173. scrollTo: function(position, animate) {
  8174. var oldPosition = this.getScrollPosition(),
  8175. newPosition = position.constrain(0, this.getMaxScrollBottom());
  8176. if (newPosition != oldPosition && !this.scrolling) {
  8177. if (animate == undefined) {
  8178. animate = this.animateScroll;
  8179. }
  8180. this.layout.innerCt.scrollTo('top', newPosition, animate ? this.getScrollAnim() : false);
  8181. if (animate) {
  8182. this.scrolling = true;
  8183. } else {
  8184. this.scrolling = false;
  8185. this.updateScrollButtons();
  8186. }
  8187. }
  8188. },
  8189. /**
  8190. * Returns the current scroll position of the innerCt element
  8191. * @return {Number} The current scroll position
  8192. */
  8193. getScrollPosition: function(){
  8194. return parseInt(this.layout.innerCt.dom.scrollTop, 10) || 0;
  8195. },
  8196. /**
  8197. * @private
  8198. * Returns the maximum value we can scrollTo
  8199. * @return {Number} The max scroll value
  8200. */
  8201. getMaxScrollBottom: function() {
  8202. return this.layout.innerCt.dom.scrollHeight - this.layout.innerCt.getHeight();
  8203. },
  8204. /**
  8205. * @private
  8206. * Returns true if the innerCt scroll is already at its right-most point
  8207. * @return {Boolean} True if already at furthest right point
  8208. */
  8209. atExtremeAfter: function() {
  8210. return this.getScrollPosition() >= this.getMaxScrollBottom();
  8211. }
  8212. });
  8213. Ext.layout.boxOverflow.scroller.vbox = Ext.layout.boxOverflow.VerticalScroller;
  8214. /**
  8215. * @class Ext.layout.boxOverflow.HorizontalScroller
  8216. * @extends Ext.layout.boxOverflow.Scroller
  8217. * Description
  8218. */
  8219. Ext.layout.boxOverflow.HorizontalScroller = Ext.extend(Ext.layout.boxOverflow.Scroller, {
  8220. handleOverflow: function(calculations, targetSize) {
  8221. Ext.layout.boxOverflow.HorizontalScroller.superclass.handleOverflow.apply(this, arguments);
  8222. return {
  8223. targetSize: {
  8224. height: targetSize.height,
  8225. width : targetSize.width - (this.beforeCt.getWidth() + this.afterCt.getWidth())
  8226. }
  8227. };
  8228. },
  8229. /**
  8230. * @private
  8231. * Creates the beforeCt and afterCt elements if they have not already been created
  8232. */
  8233. createInnerElements: function() {
  8234. var target = this.layout.innerCt;
  8235. //normal items will be rendered to the innerCt. beforeCt and afterCt allow for fixed positioning of
  8236. //special items such as scrollers or dropdown menu triggers
  8237. if (!this.beforeCt) {
  8238. this.afterCt = target.insertSibling({cls: this.afterCls}, 'before');
  8239. this.beforeCt = target.insertSibling({cls: this.beforeCls}, 'before');
  8240. this.createWheelListener();
  8241. }
  8242. },
  8243. /**
  8244. * @private
  8245. * Scrolls to the given position. Performs bounds checking.
  8246. * @param {Number} position The position to scroll to. This is constrained.
  8247. * @param {Boolean} animate True to animate. If undefined, falls back to value of this.animateScroll
  8248. */
  8249. scrollTo: function(position, animate) {
  8250. var oldPosition = this.getScrollPosition(),
  8251. newPosition = position.constrain(0, this.getMaxScrollRight());
  8252. if (newPosition != oldPosition && !this.scrolling) {
  8253. if (animate == undefined) {
  8254. animate = this.animateScroll;
  8255. }
  8256. this.layout.innerCt.scrollTo('left', newPosition, animate ? this.getScrollAnim() : false);
  8257. if (animate) {
  8258. this.scrolling = true;
  8259. } else {
  8260. this.scrolling = false;
  8261. this.updateScrollButtons();
  8262. }
  8263. }
  8264. },
  8265. /**
  8266. * Returns the current scroll position of the innerCt element
  8267. * @return {Number} The current scroll position
  8268. */
  8269. getScrollPosition: function(){
  8270. return parseInt(this.layout.innerCt.dom.scrollLeft, 10) || 0;
  8271. },
  8272. /**
  8273. * @private
  8274. * Returns the maximum value we can scrollTo
  8275. * @return {Number} The max scroll value
  8276. */
  8277. getMaxScrollRight: function() {
  8278. return this.layout.innerCt.dom.scrollWidth - this.layout.innerCt.getWidth();
  8279. },
  8280. /**
  8281. * @private
  8282. * Returns true if the innerCt scroll is already at its right-most point
  8283. * @return {Boolean} True if already at furthest right point
  8284. */
  8285. atExtremeAfter: function() {
  8286. return this.getScrollPosition() >= this.getMaxScrollRight();
  8287. }
  8288. });
  8289. Ext.layout.boxOverflow.scroller.hbox = Ext.layout.boxOverflow.HorizontalScroller;/**
  8290. * @class Ext.layout.HBoxLayout
  8291. * @extends Ext.layout.BoxLayout
  8292. * <p>A layout that arranges items horizontally across a Container. This layout optionally divides available horizontal
  8293. * space between child items containing a numeric <code>flex</code> configuration.</p>
  8294. * This layout may also be used to set the heights of child items by configuring it with the {@link #align} option.
  8295. */
  8296. Ext.layout.HBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
  8297. /**
  8298. * @cfg {String} align
  8299. * Controls how the child items of the container are aligned. Acceptable configuration values for this
  8300. * property are:
  8301. * <div class="mdetail-params"><ul>
  8302. * <li><b><tt>top</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned vertically
  8303. * at the <b>top</b> of the container</div></li>
  8304. * <li><b><tt>middle</tt></b> : <div class="sub-desc">child items are aligned vertically in the
  8305. * <b>middle</b> of the container</div></li>
  8306. * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched vertically to fill
  8307. * the height of the container</div></li>
  8308. * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched vertically to
  8309. * the height of the largest item.</div></li>
  8310. */
  8311. align: 'top', // top, middle, stretch, strechmax
  8312. type : 'hbox',
  8313. /**
  8314. * @cfg {String} pack
  8315. * Controls how the child items of the container are packed together. Acceptable configuration values
  8316. * for this property are:
  8317. * <div class="mdetail-params"><ul>
  8318. * <li><b><tt>start</tt></b> : <b>Default</b><div class="sub-desc">child items are packed together at
  8319. * <b>left</b> side of container</div></li>
  8320. * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are packed together at
  8321. * <b>mid-width</b> of container</div></li>
  8322. * <li><b><tt>end</tt></b> : <div class="sub-desc">child items are packed together at <b>right</b>
  8323. * side of container</div></li>
  8324. * </ul></div>
  8325. */
  8326. /**
  8327. * @cfg {Number} flex
  8328. * This configuation option is to be applied to <b>child <tt>items</tt></b> of the container managed
  8329. * by this layout. Each child item with a <tt>flex</tt> property will be flexed <b>horizontally</b>
  8330. * according to each item's <b>relative</b> <tt>flex</tt> value compared to the sum of all items with
  8331. * a <tt>flex</tt> value specified. Any child items that have either a <tt>flex = 0</tt> or
  8332. * <tt>flex = undefined</tt> will not be 'flexed' (the initial size will not be changed).
  8333. */
  8334. /**
  8335. * @private
  8336. * Calculates the size and positioning of each item in the HBox. This iterates over all of the rendered,
  8337. * visible items and returns a height, width, top and left for each, as well as a reference to each. Also
  8338. * returns meta data such as maxHeight which are useful when resizing layout wrappers such as this.innerCt.
  8339. * @param {Array} visibleItems The array of all rendered, visible items to be calculated for
  8340. * @param {Object} targetSize Object containing target size and height
  8341. * @return {Object} Object containing box measurements for each child, plus meta data
  8342. */
  8343. calculateChildBoxes: function(visibleItems, targetSize) {
  8344. var visibleCount = visibleItems.length,
  8345. padding = this.padding,
  8346. topOffset = padding.top,
  8347. leftOffset = padding.left,
  8348. paddingVert = topOffset + padding.bottom,
  8349. paddingHoriz = leftOffset + padding.right,
  8350. width = targetSize.width - this.scrollOffset,
  8351. height = targetSize.height,
  8352. availHeight = Math.max(0, height - paddingVert),
  8353. isStart = this.pack == 'start',
  8354. isCenter = this.pack == 'center',
  8355. isEnd = this.pack == 'end',
  8356. nonFlexWidth = 0,
  8357. maxHeight = 0,
  8358. totalFlex = 0,
  8359. desiredWidth = 0,
  8360. minimumWidth = 0,
  8361. //used to cache the calculated size and position values for each child item
  8362. boxes = [],
  8363. //used in the for loops below, just declared here for brevity
  8364. child, childWidth, childHeight, childSize, childMargins, canLayout, i, calcs, flexedWidth,
  8365. horizMargins, vertMargins, stretchHeight;
  8366. //gather the total flex of all flexed items and the width taken up by fixed width items
  8367. for (i = 0; i < visibleCount; i++) {
  8368. child = visibleItems[i];
  8369. childHeight = child.height;
  8370. childWidth = child.width;
  8371. canLayout = !child.hasLayout && typeof child.doLayout == 'function';
  8372. // Static width (numeric) requires no calcs
  8373. if (typeof childWidth != 'number') {
  8374. // flex and not 'auto' width
  8375. if (child.flex && !childWidth) {
  8376. totalFlex += child.flex;
  8377. // Not flexed or 'auto' width or undefined width
  8378. } else {
  8379. //Render and layout sub-containers without a flex or width defined, as otherwise we
  8380. //don't know how wide the sub-container should be and cannot calculate flexed widths
  8381. if (!childWidth && canLayout) {
  8382. child.doLayout();
  8383. }
  8384. childSize = child.getSize();
  8385. childWidth = childSize.width;
  8386. childHeight = childSize.height;
  8387. }
  8388. }
  8389. childMargins = child.margins;
  8390. horizMargins = childMargins.left + childMargins.right;
  8391. nonFlexWidth += horizMargins + (childWidth || 0);
  8392. desiredWidth += horizMargins + (child.flex ? child.minWidth || 0 : childWidth);
  8393. minimumWidth += horizMargins + (child.minWidth || childWidth || 0);
  8394. // Max height for align - force layout of non-laid out subcontainers without a numeric height
  8395. if (typeof childHeight != 'number') {
  8396. if (canLayout) {
  8397. child.doLayout();
  8398. }
  8399. childHeight = child.getHeight();
  8400. }
  8401. maxHeight = Math.max(maxHeight, childHeight + childMargins.top + childMargins.bottom);
  8402. //cache the size of each child component. Don't set height or width to 0, keep undefined instead
  8403. boxes.push({
  8404. component: child,
  8405. height : childHeight || undefined,
  8406. width : childWidth || undefined
  8407. });
  8408. }
  8409. var shortfall = desiredWidth - width,
  8410. tooNarrow = minimumWidth > width;
  8411. //the width available to the flexed items
  8412. var availableWidth = Math.max(0, width - nonFlexWidth - paddingHoriz);
  8413. if (tooNarrow) {
  8414. for (i = 0; i < visibleCount; i++) {
  8415. boxes[i].width = visibleItems[i].minWidth || visibleItems[i].width || boxes[i].width;
  8416. }
  8417. } else {
  8418. //all flexed items should be sized to their minimum width, other items should be shrunk down until
  8419. //the shortfall has been accounted for
  8420. if (shortfall > 0) {
  8421. var minWidths = [];
  8422. /**
  8423. * When we have a shortfall but are not tooNarrow, we need to shrink the width of each non-flexed item.
  8424. * Flexed items are immediately reduced to their minWidth and anything already at minWidth is ignored.
  8425. * The remaining items are collected into the minWidths array, which is later used to distribute the shortfall.
  8426. */
  8427. for (var index = 0, length = visibleCount; index < length; index++) {
  8428. var item = visibleItems[index],
  8429. minWidth = item.minWidth || 0;
  8430. //shrink each non-flex tab by an equal amount to make them all fit. Flexed items are all
  8431. //shrunk to their minWidth because they're flexible and should be the first to lose width
  8432. if (item.flex) {
  8433. boxes[index].width = minWidth;
  8434. } else {
  8435. minWidths.push({
  8436. minWidth : minWidth,
  8437. available: boxes[index].width - minWidth,
  8438. index : index
  8439. });
  8440. }
  8441. }
  8442. //sort by descending amount of width remaining before minWidth is reached
  8443. minWidths.sort(function(a, b) {
  8444. return a.available > b.available ? 1 : -1;
  8445. });
  8446. /*
  8447. * Distribute the shortfall (difference between total desired with of all items and actual width available)
  8448. * between the non-flexed items. We try to distribute the shortfall evenly, but apply it to items with the
  8449. * smallest difference between their width and minWidth first, so that if reducing the width by the average
  8450. * amount would make that item less than its minWidth, we carry the remainder over to the next item.
  8451. */
  8452. for (var i = 0, length = minWidths.length; i < length; i++) {
  8453. var itemIndex = minWidths[i].index;
  8454. if (itemIndex == undefined) {
  8455. continue;
  8456. }
  8457. var item = visibleItems[itemIndex],
  8458. box = boxes[itemIndex],
  8459. oldWidth = box.width,
  8460. minWidth = item.minWidth,
  8461. newWidth = Math.max(minWidth, oldWidth - Math.ceil(shortfall / (length - i))),
  8462. reduction = oldWidth - newWidth;
  8463. boxes[itemIndex].width = newWidth;
  8464. shortfall -= reduction;
  8465. }
  8466. } else {
  8467. //temporary variables used in the flex width calculations below
  8468. var remainingWidth = availableWidth,
  8469. remainingFlex = totalFlex;
  8470. //calculate the widths of each flexed item
  8471. for (i = 0; i < visibleCount; i++) {
  8472. child = visibleItems[i];
  8473. calcs = boxes[i];
  8474. childMargins = child.margins;
  8475. vertMargins = childMargins.top + childMargins.bottom;
  8476. if (isStart && child.flex && !child.width) {
  8477. flexedWidth = Math.ceil((child.flex / remainingFlex) * remainingWidth);
  8478. remainingWidth -= flexedWidth;
  8479. remainingFlex -= child.flex;
  8480. calcs.width = flexedWidth;
  8481. calcs.dirtySize = true;
  8482. }
  8483. }
  8484. }
  8485. }
  8486. if (isCenter) {
  8487. leftOffset += availableWidth / 2;
  8488. } else if (isEnd) {
  8489. leftOffset += availableWidth;
  8490. }
  8491. //finally, calculate the left and top position of each item
  8492. for (i = 0; i < visibleCount; i++) {
  8493. child = visibleItems[i];
  8494. calcs = boxes[i];
  8495. childMargins = child.margins;
  8496. leftOffset += childMargins.left;
  8497. vertMargins = childMargins.top + childMargins.bottom;
  8498. calcs.left = leftOffset;
  8499. calcs.top = topOffset + childMargins.top;
  8500. switch (this.align) {
  8501. case 'stretch':
  8502. stretchHeight = availHeight - vertMargins;
  8503. calcs.height = stretchHeight.constrain(child.minHeight || 0, child.maxHeight || 1000000);
  8504. calcs.dirtySize = true;
  8505. break;
  8506. case 'stretchmax':
  8507. stretchHeight = maxHeight - vertMargins;
  8508. calcs.height = stretchHeight.constrain(child.minHeight || 0, child.maxHeight || 1000000);
  8509. calcs.dirtySize = true;
  8510. break;
  8511. case 'middle':
  8512. var diff = availHeight - calcs.height - vertMargins;
  8513. if (diff > 0) {
  8514. calcs.top = topOffset + vertMargins + (diff / 2);
  8515. }
  8516. }
  8517. leftOffset += calcs.width + childMargins.right;
  8518. }
  8519. return {
  8520. boxes: boxes,
  8521. meta : {
  8522. maxHeight : maxHeight,
  8523. nonFlexWidth: nonFlexWidth,
  8524. desiredWidth: desiredWidth,
  8525. minimumWidth: minimumWidth,
  8526. shortfall : desiredWidth - width,
  8527. tooNarrow : tooNarrow
  8528. }
  8529. };
  8530. }
  8531. });
  8532. Ext.Container.LAYOUTS.hbox = Ext.layout.HBoxLayout;/**
  8533. * @class Ext.layout.VBoxLayout
  8534. * @extends Ext.layout.BoxLayout
  8535. * <p>A layout that arranges items vertically down a Container. This layout optionally divides available vertical
  8536. * space between child items containing a numeric <code>flex</code> configuration.</p>
  8537. * This layout may also be used to set the widths of child items by configuring it with the {@link #align} option.
  8538. */
  8539. Ext.layout.VBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
  8540. /**
  8541. * @cfg {String} align
  8542. * Controls how the child items of the container are aligned. Acceptable configuration values for this
  8543. * property are:
  8544. * <div class="mdetail-params"><ul>
  8545. * <li><b><tt>left</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned horizontally
  8546. * at the <b>left</b> side of the container</div></li>
  8547. * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are aligned horizontally at the
  8548. * <b>mid-width</b> of the container</div></li>
  8549. * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched horizontally to fill
  8550. * the width of the container</div></li>
  8551. * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched horizontally to
  8552. * the size of the largest item.</div></li>
  8553. * </ul></div>
  8554. */
  8555. align : 'left', // left, center, stretch, strechmax
  8556. type: 'vbox',
  8557. /**
  8558. * @cfg {String} pack
  8559. * Controls how the child items of the container are packed together. Acceptable configuration values
  8560. * for this property are:
  8561. * <div class="mdetail-params"><ul>
  8562. * <li><b><tt>start</tt></b> : <b>Default</b><div class="sub-desc">child items are packed together at
  8563. * <b>top</b> side of container</div></li>
  8564. * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are packed together at
  8565. * <b>mid-height</b> of container</div></li>
  8566. * <li><b><tt>end</tt></b> : <div class="sub-desc">child items are packed together at <b>bottom</b>
  8567. * side of container</div></li>
  8568. * </ul></div>
  8569. */
  8570. /**
  8571. * @cfg {Number} flex
  8572. * This configuation option is to be applied to <b>child <tt>items</tt></b> of the container managed
  8573. * by this layout. Each child item with a <tt>flex</tt> property will be flexed <b>vertically</b>
  8574. * according to each item's <b>relative</b> <tt>flex</tt> value compared to the sum of all items with
  8575. * a <tt>flex</tt> value specified. Any child items that have either a <tt>flex = 0</tt> or
  8576. * <tt>flex = undefined</tt> will not be 'flexed' (the initial size will not be changed).
  8577. */
  8578. /**
  8579. * @private
  8580. * Calculates the size and positioning of each item in the VBox. This iterates over all of the rendered,
  8581. * visible items and returns a height, width, top and left for each, as well as a reference to each. Also
  8582. * returns meta data such as maxHeight which are useful when resizing layout wrappers such as this.innerCt.
  8583. * @param {Array} visibleItems The array of all rendered, visible items to be calculated for
  8584. * @param {Object} targetSize Object containing target size and height
  8585. * @return {Object} Object containing box measurements for each child, plus meta data
  8586. */
  8587. calculateChildBoxes: function(visibleItems, targetSize) {
  8588. var visibleCount = visibleItems.length,
  8589. padding = this.padding,
  8590. topOffset = padding.top,
  8591. leftOffset = padding.left,
  8592. paddingVert = topOffset + padding.bottom,
  8593. paddingHoriz = leftOffset + padding.right,
  8594. width = targetSize.width - this.scrollOffset,
  8595. height = targetSize.height,
  8596. availWidth = Math.max(0, width - paddingHoriz),
  8597. isStart = this.pack == 'start',
  8598. isCenter = this.pack == 'center',
  8599. isEnd = this.pack == 'end',
  8600. nonFlexHeight= 0,
  8601. maxWidth = 0,
  8602. totalFlex = 0,
  8603. desiredHeight= 0,
  8604. minimumHeight= 0,
  8605. //used to cache the calculated size and position values for each child item
  8606. boxes = [],
  8607. //used in the for loops below, just declared here for brevity
  8608. child, childWidth, childHeight, childSize, childMargins, canLayout, i, calcs, flexedWidth,
  8609. horizMargins, vertMargins, stretchWidth;
  8610. //gather the total flex of all flexed items and the width taken up by fixed width items
  8611. for (i = 0; i < visibleCount; i++) {
  8612. child = visibleItems[i];
  8613. childHeight = child.height;
  8614. childWidth = child.width;
  8615. canLayout = !child.hasLayout && typeof child.doLayout == 'function';
  8616. // Static height (numeric) requires no calcs
  8617. if (typeof childHeight != 'number') {
  8618. // flex and not 'auto' height
  8619. if (child.flex && !childHeight) {
  8620. totalFlex += child.flex;
  8621. // Not flexed or 'auto' height or undefined height
  8622. } else {
  8623. //Render and layout sub-containers without a flex or width defined, as otherwise we
  8624. //don't know how wide the sub-container should be and cannot calculate flexed widths
  8625. if (!childHeight && canLayout) {
  8626. child.doLayout();
  8627. }
  8628. childSize = child.getSize();
  8629. childWidth = childSize.width;
  8630. childHeight = childSize.height;
  8631. }
  8632. }
  8633. childMargins = child.margins;
  8634. vertMargins = childMargins.top + childMargins.bottom;
  8635. nonFlexHeight += vertMargins + (childHeight || 0);
  8636. desiredHeight += vertMargins + (child.flex ? child.minHeight || 0 : childHeight);
  8637. minimumHeight += vertMargins + (child.minHeight || childHeight || 0);
  8638. // Max width for align - force layout of non-layed out subcontainers without a numeric width
  8639. if (typeof childWidth != 'number') {
  8640. if (canLayout) {
  8641. child.doLayout();
  8642. }
  8643. childWidth = child.getWidth();
  8644. }
  8645. maxWidth = Math.max(maxWidth, childWidth + childMargins.left + childMargins.right);
  8646. //cache the size of each child component
  8647. boxes.push({
  8648. component: child,
  8649. height : childHeight || undefined,
  8650. width : childWidth || undefined
  8651. });
  8652. }
  8653. var shortfall = desiredHeight - height,
  8654. tooNarrow = minimumHeight > height;
  8655. //the height available to the flexed items
  8656. var availableHeight = Math.max(0, (height - nonFlexHeight - paddingVert));
  8657. if (tooNarrow) {
  8658. for (i = 0, length = visibleCount; i < length; i++) {
  8659. boxes[i].height = visibleItems[i].minHeight || visibleItems[i].height || boxes[i].height;
  8660. }
  8661. } else {
  8662. //all flexed items should be sized to their minimum width, other items should be shrunk down until
  8663. //the shortfall has been accounted for
  8664. if (shortfall > 0) {
  8665. var minHeights = [];
  8666. /**
  8667. * When we have a shortfall but are not tooNarrow, we need to shrink the height of each non-flexed item.
  8668. * Flexed items are immediately reduced to their minHeight and anything already at minHeight is ignored.
  8669. * The remaining items are collected into the minHeights array, which is later used to distribute the shortfall.
  8670. */
  8671. for (var index = 0, length = visibleCount; index < length; index++) {
  8672. var item = visibleItems[index],
  8673. minHeight = item.minHeight || 0;
  8674. //shrink each non-flex tab by an equal amount to make them all fit. Flexed items are all
  8675. //shrunk to their minHeight because they're flexible and should be the first to lose height
  8676. if (item.flex) {
  8677. boxes[index].height = minHeight;
  8678. } else {
  8679. minHeights.push({
  8680. minHeight: minHeight,
  8681. available: boxes[index].height - minHeight,
  8682. index : index
  8683. });
  8684. }
  8685. }
  8686. //sort by descending minHeight value
  8687. minHeights.sort(function(a, b) {
  8688. return a.available > b.available ? 1 : -1;
  8689. });
  8690. /*
  8691. * Distribute the shortfall (difference between total desired with of all items and actual height available)
  8692. * between the non-flexed items. We try to distribute the shortfall evenly, but apply it to items with the
  8693. * smallest difference between their height and minHeight first, so that if reducing the height by the average
  8694. * amount would make that item less than its minHeight, we carry the remainder over to the next item.
  8695. */
  8696. for (var i = 0, length = minHeights.length; i < length; i++) {
  8697. var itemIndex = minHeights[i].index;
  8698. if (itemIndex == undefined) {
  8699. continue;
  8700. }
  8701. var item = visibleItems[itemIndex],
  8702. box = boxes[itemIndex],
  8703. oldHeight = box.height,
  8704. minHeight = item.minHeight,
  8705. newHeight = Math.max(minHeight, oldHeight - Math.ceil(shortfall / (length - i))),
  8706. reduction = oldHeight - newHeight;
  8707. boxes[itemIndex].height = newHeight;
  8708. shortfall -= reduction;
  8709. }
  8710. } else {
  8711. //temporary variables used in the flex height calculations below
  8712. var remainingHeight = availableHeight,
  8713. remainingFlex = totalFlex;
  8714. //calculate the height of each flexed item
  8715. for (i = 0; i < visibleCount; i++) {
  8716. child = visibleItems[i];
  8717. calcs = boxes[i];
  8718. childMargins = child.margins;
  8719. horizMargins = childMargins.left + childMargins.right;
  8720. if (isStart && child.flex && !child.height) {
  8721. flexedHeight = Math.ceil((child.flex / remainingFlex) * remainingHeight);
  8722. remainingHeight -= flexedHeight;
  8723. remainingFlex -= child.flex;
  8724. calcs.height = flexedHeight;
  8725. calcs.dirtySize = true;
  8726. }
  8727. }
  8728. }
  8729. }
  8730. if (isCenter) {
  8731. topOffset += availableHeight / 2;
  8732. } else if (isEnd) {
  8733. topOffset += availableHeight;
  8734. }
  8735. //finally, calculate the left and top position of each item
  8736. for (i = 0; i < visibleCount; i++) {
  8737. child = visibleItems[i];
  8738. calcs = boxes[i];
  8739. childMargins = child.margins;
  8740. topOffset += childMargins.top;
  8741. horizMargins = childMargins.left + childMargins.right;
  8742. calcs.left = leftOffset + childMargins.left;
  8743. calcs.top = topOffset;
  8744. switch (this.align) {
  8745. case 'stretch':
  8746. stretchWidth = availWidth - horizMargins;
  8747. calcs.width = stretchWidth.constrain(child.minWidth || 0, child.maxWidth || 1000000);
  8748. calcs.dirtySize = true;
  8749. break;
  8750. case 'stretchmax':
  8751. stretchWidth = maxWidth - horizMargins;
  8752. calcs.width = stretchWidth.constrain(child.minWidth || 0, child.maxWidth || 1000000);
  8753. calcs.dirtySize = true;
  8754. break;
  8755. case 'center':
  8756. var diff = availWidth - calcs.width - horizMargins;
  8757. if (diff > 0) {
  8758. calcs.left = leftOffset + horizMargins + (diff / 2);
  8759. }
  8760. }
  8761. topOffset += calcs.height + childMargins.bottom;
  8762. }
  8763. return {
  8764. boxes: boxes,
  8765. meta : {
  8766. maxWidth : maxWidth,
  8767. nonFlexHeight: nonFlexHeight,
  8768. desiredHeight: desiredHeight,
  8769. minimumHeight: minimumHeight,
  8770. shortfall : desiredHeight - height,
  8771. tooNarrow : tooNarrow
  8772. }
  8773. };
  8774. }
  8775. });
  8776. Ext.Container.LAYOUTS.vbox = Ext.layout.VBoxLayout;
  8777. /**
  8778. * @class Ext.layout.ToolbarLayout
  8779. * @extends Ext.layout.ContainerLayout
  8780. * Layout manager used by Ext.Toolbar. This is highly specialised for use by Toolbars and would not
  8781. * usually be used by any other class.
  8782. */
  8783. Ext.layout.ToolbarLayout = Ext.extend(Ext.layout.ContainerLayout, {
  8784. monitorResize : true,
  8785. type: 'toolbar',
  8786. /**
  8787. * @property triggerWidth
  8788. * @type Number
  8789. * The width allocated for the menu trigger at the extreme right end of the Toolbar
  8790. */
  8791. triggerWidth: 18,
  8792. /**
  8793. * @property noItemsMenuText
  8794. * @type String
  8795. * HTML fragment to render into the toolbar overflow menu if there are no items to display
  8796. */
  8797. noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
  8798. /**
  8799. * @private
  8800. * @property lastOverflow
  8801. * @type Boolean
  8802. * Used internally to record whether the last layout caused an overflow or not
  8803. */
  8804. lastOverflow: false,
  8805. /**
  8806. * @private
  8807. * @property tableHTML
  8808. * @type String
  8809. * String used to build the HTML injected to support the Toolbar's layout. The align property is
  8810. * injected into this string inside the td.x-toolbar-left element during onLayout.
  8811. */
  8812. tableHTML: [
  8813. '<table cellspacing="0" class="x-toolbar-ct">',
  8814. '<tbody>',
  8815. '<tr>',
  8816. '<td class="x-toolbar-left" align="{0}">',
  8817. '<table cellspacing="0">',
  8818. '<tbody>',
  8819. '<tr class="x-toolbar-left-row"></tr>',
  8820. '</tbody>',
  8821. '</table>',
  8822. '</td>',
  8823. '<td class="x-toolbar-right" align="right">',
  8824. '<table cellspacing="0" class="x-toolbar-right-ct">',
  8825. '<tbody>',
  8826. '<tr>',
  8827. '<td>',
  8828. '<table cellspacing="0">',
  8829. '<tbody>',
  8830. '<tr class="x-toolbar-right-row"></tr>',
  8831. '</tbody>',
  8832. '</table>',
  8833. '</td>',
  8834. '<td>',
  8835. '<table cellspacing="0">',
  8836. '<tbody>',
  8837. '<tr class="x-toolbar-extras-row"></tr>',
  8838. '</tbody>',
  8839. '</table>',
  8840. '</td>',
  8841. '</tr>',
  8842. '</tbody>',
  8843. '</table>',
  8844. '</td>',
  8845. '</tr>',
  8846. '</tbody>',
  8847. '</table>'
  8848. ].join(""),
  8849. /**
  8850. * @private
  8851. * Create the wrapping Toolbar HTML and render/move all the items into the correct places
  8852. */
  8853. onLayout : function(ct, target) {
  8854. //render the Toolbar <table> HTML if it's not already present
  8855. if (!this.leftTr) {
  8856. var align = ct.buttonAlign == 'center' ? 'center' : 'left';
  8857. target.addClass('x-toolbar-layout-ct');
  8858. target.insertHtml('beforeEnd', String.format(this.tableHTML, align));
  8859. this.leftTr = target.child('tr.x-toolbar-left-row', true);
  8860. this.rightTr = target.child('tr.x-toolbar-right-row', true);
  8861. this.extrasTr = target.child('tr.x-toolbar-extras-row', true);
  8862. if (this.hiddenItem == undefined) {
  8863. /**
  8864. * @property hiddenItems
  8865. * @type Array
  8866. * Holds all items that are currently hidden due to there not being enough space to render them
  8867. * These items will appear on the expand menu.
  8868. */
  8869. this.hiddenItems = [];
  8870. }
  8871. }
  8872. var side = ct.buttonAlign == 'right' ? this.rightTr : this.leftTr,
  8873. items = ct.items.items,
  8874. position = 0;
  8875. //render each item if not already rendered, place it into the correct (left or right) target
  8876. for (var i = 0, len = items.length, c; i < len; i++, position++) {
  8877. c = items[i];
  8878. if (c.isFill) {
  8879. side = this.rightTr;
  8880. position = -1;
  8881. } else if (!c.rendered) {
  8882. c.render(this.insertCell(c, side, position));
  8883. this.configureItem(c);
  8884. } else {
  8885. if (!c.xtbHidden && !this.isValidParent(c, side.childNodes[position])) {
  8886. var td = this.insertCell(c, side, position);
  8887. td.appendChild(c.getPositionEl().dom);
  8888. c.container = Ext.get(td);
  8889. }
  8890. }
  8891. }
  8892. //strip extra empty cells
  8893. this.cleanup(this.leftTr);
  8894. this.cleanup(this.rightTr);
  8895. this.cleanup(this.extrasTr);
  8896. this.fitToSize(target);
  8897. },
  8898. /**
  8899. * @private
  8900. * Removes any empty nodes from the given element
  8901. * @param {Ext.Element} el The element to clean up
  8902. */
  8903. cleanup : function(el) {
  8904. var cn = el.childNodes, i, c;
  8905. for (i = cn.length-1; i >= 0 && (c = cn[i]); i--) {
  8906. if (!c.firstChild) {
  8907. el.removeChild(c);
  8908. }
  8909. }
  8910. },
  8911. /**
  8912. * @private
  8913. * Inserts the given Toolbar item into the given element
  8914. * @param {Ext.Component} c The component to add
  8915. * @param {Ext.Element} target The target to add the component to
  8916. * @param {Number} position The position to add the component at
  8917. */
  8918. insertCell : function(c, target, position) {
  8919. var td = document.createElement('td');
  8920. td.className = 'x-toolbar-cell';
  8921. target.insertBefore(td, target.childNodes[position] || null);
  8922. return td;
  8923. },
  8924. /**
  8925. * @private
  8926. * Hides an item because it will not fit in the available width. The item will be unhidden again
  8927. * if the Toolbar is resized to be large enough to show it
  8928. * @param {Ext.Component} item The item to hide
  8929. */
  8930. hideItem : function(item) {
  8931. this.hiddenItems.push(item);
  8932. item.xtbHidden = true;
  8933. item.xtbWidth = item.getPositionEl().dom.parentNode.offsetWidth;
  8934. item.hide();
  8935. },
  8936. /**
  8937. * @private
  8938. * Unhides an item that was previously hidden due to there not being enough space left on the Toolbar
  8939. * @param {Ext.Component} item The item to show
  8940. */
  8941. unhideItem : function(item) {
  8942. item.show();
  8943. item.xtbHidden = false;
  8944. this.hiddenItems.remove(item);
  8945. },
  8946. /**
  8947. * @private
  8948. * Returns the width of the given toolbar item. If the item is currently hidden because there
  8949. * is not enough room to render it, its previous width is returned
  8950. * @param {Ext.Component} c The component to measure
  8951. * @return {Number} The width of the item
  8952. */
  8953. getItemWidth : function(c) {
  8954. return c.hidden ? (c.xtbWidth || 0) : c.getPositionEl().dom.parentNode.offsetWidth;
  8955. },
  8956. /**
  8957. * @private
  8958. * Called at the end of onLayout. At this point the Toolbar has already been resized, so we need
  8959. * to fit the items into the available width. We add up the width required by all of the items in
  8960. * the toolbar - if we don't have enough space we hide the extra items and render the expand menu
  8961. * trigger.
  8962. * @param {Ext.Element} target The Element the Toolbar is currently laid out within
  8963. */
  8964. fitToSize : function(target) {
  8965. if (this.container.enableOverflow === false) {
  8966. return;
  8967. }
  8968. var width = target.dom.clientWidth,
  8969. tableWidth = target.dom.firstChild.offsetWidth,
  8970. clipWidth = width - this.triggerWidth,
  8971. lastWidth = this.lastWidth || 0,
  8972. hiddenItems = this.hiddenItems,
  8973. hasHiddens = hiddenItems.length != 0,
  8974. isLarger = width >= lastWidth;
  8975. this.lastWidth = width;
  8976. if (tableWidth > width || (hasHiddens && isLarger)) {
  8977. var items = this.container.items.items,
  8978. len = items.length,
  8979. loopWidth = 0,
  8980. item;
  8981. for (var i = 0; i < len; i++) {
  8982. item = items[i];
  8983. if (!item.isFill) {
  8984. loopWidth += this.getItemWidth(item);
  8985. if (loopWidth > clipWidth) {
  8986. if (!(item.hidden || item.xtbHidden)) {
  8987. this.hideItem(item);
  8988. }
  8989. } else if (item.xtbHidden) {
  8990. this.unhideItem(item);
  8991. }
  8992. }
  8993. }
  8994. }
  8995. //test for number of hidden items again here because they may have changed above
  8996. hasHiddens = hiddenItems.length != 0;
  8997. if (hasHiddens) {
  8998. this.initMore();
  8999. if (!this.lastOverflow) {
  9000. this.container.fireEvent('overflowchange', this.container, true);
  9001. this.lastOverflow = true;
  9002. }
  9003. } else if (this.more) {
  9004. this.clearMenu();
  9005. this.more.destroy();
  9006. delete this.more;
  9007. if (this.lastOverflow) {
  9008. this.container.fireEvent('overflowchange', this.container, false);
  9009. this.lastOverflow = false;
  9010. }
  9011. }
  9012. },
  9013. /**
  9014. * @private
  9015. * Returns a menu config for a given component. This config is used to create a menu item
  9016. * to be added to the expander menu
  9017. * @param {Ext.Component} component The component to create the config for
  9018. * @param {Boolean} hideOnClick Passed through to the menu item
  9019. */
  9020. createMenuConfig : function(component, hideOnClick){
  9021. var config = Ext.apply({}, component.initialConfig),
  9022. group = component.toggleGroup;
  9023. Ext.copyTo(config, component, [
  9024. 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
  9025. ]);
  9026. Ext.apply(config, {
  9027. text : component.overflowText || component.text,
  9028. hideOnClick: hideOnClick
  9029. });
  9030. if (group || component.enableToggle) {
  9031. Ext.apply(config, {
  9032. group : group,
  9033. checked: component.pressed,
  9034. listeners: {
  9035. checkchange: function(item, checked){
  9036. component.toggle(checked);
  9037. }
  9038. }
  9039. });
  9040. }
  9041. delete config.ownerCt;
  9042. delete config.xtype;
  9043. delete config.id;
  9044. return config;
  9045. },
  9046. /**
  9047. * @private
  9048. * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
  9049. * @param {Ext.menu.Menu} menu The menu to add to
  9050. * @param {Ext.Component} component The component to add
  9051. */
  9052. addComponentToMenu : function(menu, component) {
  9053. if (component instanceof Ext.Toolbar.Separator) {
  9054. menu.add('-');
  9055. } else if (Ext.isFunction(component.isXType)) {
  9056. if (component.isXType('splitbutton')) {
  9057. menu.add(this.createMenuConfig(component, true));
  9058. } else if (component.isXType('button')) {
  9059. menu.add(this.createMenuConfig(component, !component.menu));
  9060. } else if (component.isXType('buttongroup')) {
  9061. component.items.each(function(item){
  9062. this.addComponentToMenu(menu, item);
  9063. }, this);
  9064. }
  9065. }
  9066. },
  9067. /**
  9068. * @private
  9069. * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
  9070. * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
  9071. */
  9072. clearMenu : function(){
  9073. var menu = this.moreMenu;
  9074. if (menu && menu.items) {
  9075. menu.items.each(function(item){
  9076. delete item.menu;
  9077. });
  9078. }
  9079. },
  9080. /**
  9081. * @private
  9082. * Called before the expand menu is shown, this rebuilds the menu since it was last shown because
  9083. * it is possible that the items hidden due to space limitations on the Toolbar have changed since.
  9084. * @param {Ext.menu.Menu} m The menu
  9085. */
  9086. beforeMoreShow : function(menu) {
  9087. var items = this.container.items.items,
  9088. len = items.length,
  9089. item,
  9090. prev;
  9091. var needsSep = function(group, item){
  9092. return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
  9093. };
  9094. this.clearMenu();
  9095. menu.removeAll();
  9096. for (var i = 0; i < len; i++) {
  9097. item = items[i];
  9098. if (item.xtbHidden) {
  9099. if (prev && (needsSep(item, prev) || needsSep(prev, item))) {
  9100. menu.add('-');
  9101. }
  9102. this.addComponentToMenu(menu, item);
  9103. prev = item;
  9104. }
  9105. }
  9106. // put something so the menu isn't empty if no compatible items found
  9107. if (menu.items.length < 1) {
  9108. menu.add(this.noItemsMenuText);
  9109. }
  9110. },
  9111. /**
  9112. * @private
  9113. * Creates the expand trigger and menu, adding them to the <tr> at the extreme right of the
  9114. * Toolbar table
  9115. */
  9116. initMore : function(){
  9117. if (!this.more) {
  9118. /**
  9119. * @private
  9120. * @property moreMenu
  9121. * @type Ext.menu.Menu
  9122. * The expand menu - holds items for every Toolbar item that cannot be shown
  9123. * because the Toolbar is currently not wide enough.
  9124. */
  9125. this.moreMenu = new Ext.menu.Menu({
  9126. ownerCt : this.container,
  9127. listeners: {
  9128. beforeshow: this.beforeMoreShow,
  9129. scope: this
  9130. }
  9131. });
  9132. /**
  9133. * @private
  9134. * @property more
  9135. * @type Ext.Button
  9136. * The expand button which triggers the overflow menu to be shown
  9137. */
  9138. this.more = new Ext.Button({
  9139. iconCls: 'x-toolbar-more-icon',
  9140. cls : 'x-toolbar-more',
  9141. menu : this.moreMenu,
  9142. ownerCt: this.container
  9143. });
  9144. var td = this.insertCell(this.more, this.extrasTr, 100);
  9145. this.more.render(td);
  9146. }
  9147. },
  9148. destroy : function(){
  9149. Ext.destroy(this.more, this.moreMenu);
  9150. delete this.leftTr;
  9151. delete this.rightTr;
  9152. delete this.extrasTr;
  9153. Ext.layout.ToolbarLayout.superclass.destroy.call(this);
  9154. }
  9155. });
  9156. Ext.Container.LAYOUTS.toolbar = Ext.layout.ToolbarLayout;
  9157. /**
  9158. * @class Ext.layout.MenuLayout
  9159. * @extends Ext.layout.ContainerLayout
  9160. * <p>Layout manager used by {@link Ext.menu.Menu}. Generally this class should not need to be used directly.</p>
  9161. */
  9162. Ext.layout.MenuLayout = Ext.extend(Ext.layout.ContainerLayout, {
  9163. monitorResize : true,
  9164. type: 'menu',
  9165. setContainer : function(ct){
  9166. this.monitorResize = !ct.floating;
  9167. // This event is only fired by the menu in IE, used so we don't couple
  9168. // the menu with the layout.
  9169. ct.on('autosize', this.doAutoSize, this);
  9170. Ext.layout.MenuLayout.superclass.setContainer.call(this, ct);
  9171. },
  9172. renderItem : function(c, position, target){
  9173. if (!this.itemTpl) {
  9174. this.itemTpl = Ext.layout.MenuLayout.prototype.itemTpl = new Ext.XTemplate(
  9175. '<li id="{itemId}" class="{itemCls}">',
  9176. '<tpl if="needsIcon">',
  9177. '<img alt="{altText}" src="{icon}" class="{iconCls}"/>',
  9178. '</tpl>',
  9179. '</li>'
  9180. );
  9181. }
  9182. if(c && !c.rendered){
  9183. if(Ext.isNumber(position)){
  9184. position = target.dom.childNodes[position];
  9185. }
  9186. var a = this.getItemArgs(c);
  9187. // The Component's positionEl is the <li> it is rendered into
  9188. c.render(c.positionEl = position ?
  9189. this.itemTpl.insertBefore(position, a, true) :
  9190. this.itemTpl.append(target, a, true));
  9191. // Link the containing <li> to the item.
  9192. c.positionEl.menuItemId = c.getItemId();
  9193. // If rendering a regular Component, and it needs an icon,
  9194. // move the Component rightwards.
  9195. if (!a.isMenuItem && a.needsIcon) {
  9196. c.positionEl.addClass('x-menu-list-item-indent');
  9197. }
  9198. this.configureItem(c);
  9199. }else if(c && !this.isValidParent(c, target)){
  9200. if(Ext.isNumber(position)){
  9201. position = target.dom.childNodes[position];
  9202. }
  9203. target.dom.insertBefore(c.getActionEl().dom, position || null);
  9204. }
  9205. },
  9206. getItemArgs : function(c) {
  9207. var isMenuItem = c instanceof Ext.menu.Item,
  9208. canHaveIcon = !(isMenuItem || c instanceof Ext.menu.Separator);
  9209. return {
  9210. isMenuItem: isMenuItem,
  9211. needsIcon: canHaveIcon && (c.icon || c.iconCls),
  9212. icon: c.icon || Ext.BLANK_IMAGE_URL,
  9213. iconCls: 'x-menu-item-icon ' + (c.iconCls || ''),
  9214. itemId: 'x-menu-el-' + c.id,
  9215. itemCls: 'x-menu-list-item ',
  9216. altText: c.altText || ''
  9217. };
  9218. },
  9219. // Valid if the Component is in a <li> which is part of our target <ul>
  9220. isValidParent : function(c, target) {
  9221. return c.el.up('li.x-menu-list-item', 5).dom.parentNode === (target.dom || target);
  9222. },
  9223. onLayout : function(ct, target){
  9224. Ext.layout.MenuLayout.superclass.onLayout.call(this, ct, target);
  9225. this.doAutoSize();
  9226. },
  9227. doAutoSize : function(){
  9228. var ct = this.container, w = ct.width;
  9229. if(ct.floating){
  9230. if(w){
  9231. ct.setWidth(w);
  9232. }else if(Ext.isIE){
  9233. ct.setWidth(Ext.isStrict && (Ext.isIE7 || Ext.isIE8) ? 'auto' : ct.minWidth);
  9234. var el = ct.getEl(), t = el.dom.offsetWidth; // force recalc
  9235. ct.setWidth(ct.getLayoutTarget().getWidth() + el.getFrameWidth('lr'));
  9236. }
  9237. }
  9238. }
  9239. });
  9240. Ext.Container.LAYOUTS['menu'] = Ext.layout.MenuLayout;
  9241. /**
  9242. * @class Ext.Viewport
  9243. * @extends Ext.Container
  9244. * <p>A specialized container representing the viewable application area (the browser viewport).</p>
  9245. * <p>The Viewport renders itself to the document body, and automatically sizes itself to the size of
  9246. * the browser viewport and manages window resizing. There may only be one Viewport created
  9247. * in a page. Inner layouts are available by virtue of the fact that all {@link Ext.Panel Panel}s
  9248. * added to the Viewport, either through its {@link #items}, or through the items, or the {@link #add}
  9249. * method of any of its child Panels may themselves have a layout.</p>
  9250. * <p>The Viewport does not provide scrolling, so child Panels within the Viewport should provide
  9251. * for scrolling if needed using the {@link #autoScroll} config.</p>
  9252. * <p>An example showing a classic application border layout:</p><pre><code>
  9253. new Ext.Viewport({
  9254. layout: 'border',
  9255. items: [{
  9256. region: 'north',
  9257. html: '&lt;h1 class="x-panel-header">Page Title&lt;/h1>',
  9258. autoHeight: true,
  9259. border: false,
  9260. margins: '0 0 5 0'
  9261. }, {
  9262. region: 'west',
  9263. collapsible: true,
  9264. title: 'Navigation',
  9265. width: 200
  9266. // the west region might typically utilize a {@link Ext.tree.TreePanel TreePanel} or a Panel with {@link Ext.layout.AccordionLayout Accordion layout}
  9267. }, {
  9268. region: 'south',
  9269. title: 'Title for Panel',
  9270. collapsible: true,
  9271. html: 'Information goes here',
  9272. split: true,
  9273. height: 100,
  9274. minHeight: 100
  9275. }, {
  9276. region: 'east',
  9277. title: 'Title for the Grid Panel',
  9278. collapsible: true,
  9279. split: true,
  9280. width: 200,
  9281. xtype: 'grid',
  9282. // remaining grid configuration not shown ...
  9283. // notice that the GridPanel is added directly as the region
  9284. // it is not "overnested" inside another Panel
  9285. }, {
  9286. region: 'center',
  9287. xtype: 'tabpanel', // TabPanel itself has no title
  9288. items: {
  9289. title: 'Default Tab',
  9290. html: 'The first tab\'s content. Others may be added dynamically'
  9291. }
  9292. }]
  9293. });
  9294. </code></pre>
  9295. * @constructor
  9296. * Create a new Viewport
  9297. * @param {Object} config The config object
  9298. * @xtype viewport
  9299. */
  9300. Ext.Viewport = Ext.extend(Ext.Container, {
  9301. /*
  9302. * Privatize config options which, if used, would interfere with the
  9303. * correct operation of the Viewport as the sole manager of the
  9304. * layout of the document body.
  9305. */
  9306. /**
  9307. * @cfg {Mixed} applyTo @hide
  9308. */
  9309. /**
  9310. * @cfg {Boolean} allowDomMove @hide
  9311. */
  9312. /**
  9313. * @cfg {Boolean} hideParent @hide
  9314. */
  9315. /**
  9316. * @cfg {Mixed} renderTo @hide
  9317. */
  9318. /**
  9319. * @cfg {Boolean} hideParent @hide
  9320. */
  9321. /**
  9322. * @cfg {Number} height @hide
  9323. */
  9324. /**
  9325. * @cfg {Number} width @hide
  9326. */
  9327. /**
  9328. * @cfg {Boolean} autoHeight @hide
  9329. */
  9330. /**
  9331. * @cfg {Boolean} autoWidth @hide
  9332. */
  9333. /**
  9334. * @cfg {Boolean} deferHeight @hide
  9335. */
  9336. /**
  9337. * @cfg {Boolean} monitorResize @hide
  9338. */
  9339. initComponent : function() {
  9340. Ext.Viewport.superclass.initComponent.call(this);
  9341. document.getElementsByTagName('html')[0].className += ' x-viewport';
  9342. this.el = Ext.getBody();
  9343. this.el.setHeight = Ext.emptyFn;
  9344. this.el.setWidth = Ext.emptyFn;
  9345. this.el.setSize = Ext.emptyFn;
  9346. this.el.dom.scroll = 'no';
  9347. this.allowDomMove = false;
  9348. this.autoWidth = true;
  9349. this.autoHeight = true;
  9350. Ext.EventManager.onWindowResize(this.fireResize, this);
  9351. this.renderTo = this.el;
  9352. },
  9353. fireResize : function(w, h){
  9354. this.fireEvent('resize', this, w, h, w, h);
  9355. }
  9356. });
  9357. Ext.reg('viewport', Ext.Viewport);
  9358. /**
  9359. * @class Ext.Panel
  9360. * @extends Ext.Container
  9361. * <p>Panel is a container that has specific functionality and structural components that make
  9362. * it the perfect building block for application-oriented user interfaces.</p>
  9363. * <p>Panels are, by virtue of their inheritance from {@link Ext.Container}, capable
  9364. * of being configured with a {@link Ext.Container#layout layout}, and containing child Components.</p>
  9365. * <p>When either specifying child {@link Ext.Component#items items} of a Panel, or dynamically {@link Ext.Container#add adding} Components
  9366. * to a Panel, remember to consider how you wish the Panel to arrange those child elements, and whether
  9367. * 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
  9368. * default, Panels use the {@link Ext.layout.ContainerLayout ContainerLayout} scheme. This simply renders
  9369. * child components, appending them one after the other inside the Container, and <b>does not apply any sizing</b>
  9370. * at all.</p>
  9371. * <p>A Panel may also contain {@link #bbar bottom} and {@link #tbar top} toolbars, along with separate
  9372. * {@link #header}, {@link #footer} and {@link #body} sections (see {@link #frame} for additional
  9373. * information).</p>
  9374. * <p>Panel also provides built-in {@link #collapsible expandable and collapsible behavior}, along with
  9375. * a variety of {@link #tools prebuilt tool buttons} that can be wired up to provide other customized
  9376. * behavior. Panels can be easily dropped into any {@link Ext.Container Container} or layout, and the
  9377. * layout and rendering pipeline is {@link Ext.Container#add completely managed by the framework}.</p>
  9378. * @constructor
  9379. * @param {Object} config The config object
  9380. * @xtype panel
  9381. */
  9382. Ext.Panel = Ext.extend(Ext.Container, {
  9383. /**
  9384. * The Panel's header {@link Ext.Element Element}. Read-only.
  9385. * <p>This Element is used to house the {@link #title} and {@link #tools}</p>
  9386. * <br><p><b>Note</b>: see the Note for <code>{@link Ext.Component#el el}</code> also.</p>
  9387. * @type Ext.Element
  9388. * @property header
  9389. */
  9390. /**
  9391. * The Panel's body {@link Ext.Element Element} which may be used to contain HTML content.
  9392. * The content may be specified in the {@link #html} config, or it may be loaded using the
  9393. * {@link autoLoad} config, or through the Panel's {@link #getUpdater Updater}. Read-only.
  9394. * <p>If this is used to load visible HTML elements in either way, then
  9395. * the Panel may not be used as a Layout for hosting nested Panels.</p>
  9396. * <p>If this Panel is intended to be used as the host of a Layout (See {@link #layout}
  9397. * then the body Element must not be loaded or changed - it is under the control
  9398. * of the Panel's Layout.
  9399. * <br><p><b>Note</b>: see the Note for <code>{@link Ext.Component#el el}</code> also.</p>
  9400. * @type Ext.Element
  9401. * @property body
  9402. */
  9403. /**
  9404. * The Panel's bwrap {@link Ext.Element Element} used to contain other Panel elements
  9405. * (tbar, body, bbar, footer). See {@link #bodyCfg}. Read-only.
  9406. * @type Ext.Element
  9407. * @property bwrap
  9408. */
  9409. /**
  9410. * True if this panel is collapsed. Read-only.
  9411. * @type Boolean
  9412. * @property collapsed
  9413. */
  9414. /**
  9415. * @cfg {Object} bodyCfg
  9416. * <p>A {@link Ext.DomHelper DomHelper} element specification object may be specified for any
  9417. * Panel Element.</p>
  9418. * <p>By default, the Default element in the table below will be used for the html markup to
  9419. * create a child element with the commensurate Default class name (<code>baseCls</code> will be
  9420. * replaced by <code>{@link #baseCls}</code>):</p>
  9421. * <pre>
  9422. * Panel Default Default Custom Additional Additional
  9423. * Element element class element class style
  9424. * ======== ========================== ========= ============== ===========
  9425. * {@link #header} div {@link #baseCls}+'-header' {@link #headerCfg} headerCssClass headerStyle
  9426. * {@link #bwrap} div {@link #baseCls}+'-bwrap' {@link #bwrapCfg} bwrapCssClass bwrapStyle
  9427. * + tbar div {@link #baseCls}+'-tbar' {@link #tbarCfg} tbarCssClass tbarStyle
  9428. * + {@link #body} div {@link #baseCls}+'-body' {@link #bodyCfg} {@link #bodyCssClass} {@link #bodyStyle}
  9429. * + bbar div {@link #baseCls}+'-bbar' {@link #bbarCfg} bbarCssClass bbarStyle
  9430. * + {@link #footer} div {@link #baseCls}+'-footer' {@link #footerCfg} footerCssClass footerStyle
  9431. * </pre>
  9432. * <p>Configuring a Custom element may be used, for example, to force the {@link #body} Element
  9433. * to use a different form of markup than is created by default. An example of this might be
  9434. * to {@link Ext.Element#createChild create a child} Panel containing a custom content, such as
  9435. * a header, or forcing centering of all Panel content by having the body be a &lt;center&gt;
  9436. * element:</p>
  9437. * <pre><code>
  9438. new Ext.Panel({
  9439. title: 'Message Title',
  9440. renderTo: Ext.getBody(),
  9441. width: 200, height: 130,
  9442. <b>bodyCfg</b>: {
  9443. tag: 'center',
  9444. cls: 'x-panel-body', // Default class not applied if Custom element specified
  9445. html: 'Message'
  9446. },
  9447. footerCfg: {
  9448. tag: 'h2',
  9449. cls: 'x-panel-footer', // same as the Default class
  9450. html: 'footer html'
  9451. },
  9452. footerCssClass: 'custom-footer', // additional css class, see {@link Ext.element#addClass addClass}
  9453. footerStyle: 'background-color:red' // see {@link #bodyStyle}
  9454. });
  9455. * </code></pre>
  9456. * <p>The example above also explicitly creates a <code>{@link #footer}</code> with custom markup and
  9457. * styling applied.</p>
  9458. */
  9459. /**
  9460. * @cfg {Object} headerCfg
  9461. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9462. * of this Panel's {@link #header} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9463. */
  9464. /**
  9465. * @cfg {Object} bwrapCfg
  9466. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9467. * of this Panel's {@link #bwrap} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9468. */
  9469. /**
  9470. * @cfg {Object} tbarCfg
  9471. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9472. * of this Panel's {@link #tbar} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9473. */
  9474. /**
  9475. * @cfg {Object} bbarCfg
  9476. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9477. * of this Panel's {@link #bbar} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9478. */
  9479. /**
  9480. * @cfg {Object} footerCfg
  9481. * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
  9482. * of this Panel's {@link #footer} Element. See <code>{@link #bodyCfg}</code> also.</p>
  9483. */
  9484. /**
  9485. * @cfg {Boolean} closable
  9486. * Panels themselves do not directly support being closed, but some Panel subclasses do (like
  9487. * {@link Ext.Window}) or a Panel Class within an {@link Ext.TabPanel}. Specify <code>true</code>
  9488. * to enable closing in such situations. Defaults to <code>false</code>.
  9489. */
  9490. /**
  9491. * The Panel's footer {@link Ext.Element Element}. Read-only.
  9492. * <p>This Element is used to house the Panel's <code>{@link #buttons}</code> or <code>{@link #fbar}</code>.</p>
  9493. * <br><p><b>Note</b>: see the Note for <code>{@link Ext.Component#el el}</code> also.</p>
  9494. * @type Ext.Element
  9495. * @property footer
  9496. */
  9497. /**
  9498. * @cfg {Mixed} applyTo
  9499. * <p>The id of the node, a DOM node or an existing Element corresponding to a DIV that is already present in
  9500. * the document that specifies some panel-specific structural markup. When <code>applyTo</code> is used,
  9501. * constituent parts of the panel can be specified by CSS class name within the main element, and the panel
  9502. * will automatically create those components from that markup. Any required components not specified in the
  9503. * markup will be autogenerated if necessary.</p>
  9504. * <p>The following class names are supported (baseCls will be replaced by {@link #baseCls}):</p>
  9505. * <ul><li>baseCls + '-header'</li>
  9506. * <li>baseCls + '-header-text'</li>
  9507. * <li>baseCls + '-bwrap'</li>
  9508. * <li>baseCls + '-tbar'</li>
  9509. * <li>baseCls + '-body'</li>
  9510. * <li>baseCls + '-bbar'</li>
  9511. * <li>baseCls + '-footer'</li></ul>
  9512. * <p>Using this config, a call to render() is not required. If applyTo is specified, any value passed for
  9513. * {@link #renderTo} will be ignored and the target element's parent node will automatically be used as the
  9514. * panel's container.</p>
  9515. */
  9516. /**
  9517. * @cfg {Object/Array} tbar
  9518. * <p>The top toolbar of the panel. This can be a {@link Ext.Toolbar} object, a toolbar config, or an array of
  9519. * buttons/button configs to be added to the toolbar. Note that this is not available as a property after render.
  9520. * To access the top toolbar after render, use {@link #getTopToolbar}.</p>
  9521. * <p><b>Note:</b> Although a Toolbar may contain Field components, these will <b>not</b> be updated by a load
  9522. * of an ancestor FormPanel. A Panel's toolbars are not part of the standard Container->Component hierarchy, and
  9523. * so are not scanned to collect form items. However, the values <b>will</b> be submitted because form
  9524. * submission parameters are collected from the DOM tree.</p>
  9525. */
  9526. /**
  9527. * @cfg {Object/Array} bbar
  9528. * <p>The bottom 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 bottom toolbar after render, use {@link #getBottomToolbar}.</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. /** @cfg {Object/Array} fbar
  9537. * <p>A {@link Ext.Toolbar Toolbar} object, a Toolbar config, or an array of
  9538. * {@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>
  9539. * <p>After render, the <code>fbar</code> property will be an {@link Ext.Toolbar Toolbar} instance.</p>
  9540. * <p>If <code>{@link #buttons}</code> are specified, they will supersede the <code>fbar</code> configuration property.</p>
  9541. * The Panel's <code>{@link #buttonAlign}</code> configuration affects the layout of these items, for example:
  9542. * <pre><code>
  9543. var w = new Ext.Window({
  9544. height: 250,
  9545. width: 500,
  9546. bbar: new Ext.Toolbar({
  9547. items: [{
  9548. text: 'bbar Left'
  9549. },'->',{
  9550. text: 'bbar Right'
  9551. }]
  9552. }),
  9553. {@link #buttonAlign}: 'left', // anything but 'center' or 'right' and you can use '-', and '->'
  9554. // to control the alignment of fbar items
  9555. fbar: [{
  9556. text: 'fbar Left'
  9557. },'->',{
  9558. text: 'fbar Right'
  9559. }]
  9560. }).show();
  9561. * </code></pre>
  9562. * <p><b>Note:</b> Although a Toolbar may contain Field components, these will <b>not</b> be updated by a load
  9563. * of an ancestor FormPanel. A Panel's toolbars are not part of the standard Container->Component hierarchy, and
  9564. * so are not scanned to collect form items. However, the values <b>will</b> be submitted because form
  9565. * submission parameters are collected from the DOM tree.</p>
  9566. */
  9567. /**
  9568. * @cfg {Boolean} header
  9569. * <code>true</code> to create the Panel's header element explicitly, <code>false</code> to skip creating
  9570. * it. If a <code>{@link #title}</code> is set the header will be created automatically, otherwise it will not.
  9571. * If a <code>{@link #title}</code> is set but <code>header</code> is explicitly set to <code>false</code>, the header
  9572. * will not be rendered.
  9573. */
  9574. /**
  9575. * @cfg {Boolean} footer
  9576. * <code>true</code> to create the footer element explicitly, false to skip creating it. The footer
  9577. * will be created automatically if <code>{@link #buttons}</code> or a <code>{@link #fbar}</code> have
  9578. * been configured. See <code>{@link #bodyCfg}</code> for an example.
  9579. */
  9580. /**
  9581. * @cfg {String} title
  9582. * The title text to be used as innerHTML (html tags are accepted) to display in the panel
  9583. * <code>{@link #header}</code> (defaults to ''). When a <code>title</code> is specified the
  9584. * <code>{@link #header}</code> element will automatically be created and displayed unless
  9585. * {@link #header} is explicitly set to <code>false</code>. If you do not want to specify a
  9586. * <code>title</code> at config time, but you may want one later, you must either specify a non-empty
  9587. * <code>title</code> (a blank space ' ' will do) or <code>header:true</code> so that the container
  9588. * element will get created.
  9589. */
  9590. /**
  9591. * @cfg {Array} buttons
  9592. * <code>buttons</code> will be used as <code>{@link Ext.Container#items items}</code> for the toolbar in
  9593. * the footer (<code>{@link #fbar}</code>). Typically the value of this configuration property will be
  9594. * an array of {@link Ext.Button}s or {@link Ext.Button} configuration objects.
  9595. * If an item is configured with <code>minWidth</code> or the Panel is configured with <code>minButtonWidth</code>,
  9596. * that width will be applied to the item.
  9597. */
  9598. /**
  9599. * @cfg {Object/String/Function} autoLoad
  9600. * A valid url spec according to the Updater {@link Ext.Updater#update} method.
  9601. * If autoLoad is not null, the panel will attempt to load its contents
  9602. * immediately upon render.<p>
  9603. * The URL will become the default URL for this panel's {@link #body} element,
  9604. * so it may be {@link Ext.Element#refresh refresh}ed at any time.</p>
  9605. */
  9606. /**
  9607. * @cfg {Boolean} frame
  9608. * <code>false</code> by default to render with plain 1px square borders. <code>true</code> to render with
  9609. * 9 elements, complete with custom rounded corners (also see {@link Ext.Element#boxWrap}).
  9610. * <p>The template generated for each condition is depicted below:</p><pre><code>
  9611. *
  9612. // frame = false
  9613. &lt;div id="developer-specified-id-goes-here" class="x-panel">
  9614. &lt;div class="x-panel-header">&lt;span class="x-panel-header-text">Title: (frame:false)&lt;/span>&lt;/div>
  9615. &lt;div class="x-panel-bwrap">
  9616. &lt;div class="x-panel-body">&lt;p>html value goes here&lt;/p>&lt;/div>
  9617. &lt;/div>
  9618. &lt;/div>
  9619. // frame = true (create 9 elements)
  9620. &lt;div id="developer-specified-id-goes-here" class="x-panel">
  9621. &lt;div class="x-panel-tl">&lt;div class="x-panel-tr">&lt;div class="x-panel-tc">
  9622. &lt;div class="x-panel-header">&lt;span class="x-panel-header-text">Title: (frame:true)&lt;/span>&lt;/div>
  9623. &lt;/div>&lt;/div>&lt;/div>
  9624. &lt;div class="x-panel-bwrap">
  9625. &lt;div class="x-panel-ml">&lt;div class="x-panel-mr">&lt;div class="x-panel-mc">
  9626. &lt;div class="x-panel-body">&lt;p>html value goes here&lt;/p>&lt;/div>
  9627. &lt;/div>&lt;/div>&lt;/div>
  9628. &lt;div class="x-panel-bl">&lt;div class="x-panel-br">&lt;div class="x-panel-bc"/>
  9629. &lt;/div>&lt;/div>&lt;/div>
  9630. &lt;/div>
  9631. * </code></pre>
  9632. */
  9633. /**
  9634. * @cfg {Boolean} border
  9635. * True to display the borders of the panel's body element, false to hide them (defaults to true). By default,
  9636. * the border is a 2px wide inset border, but this can be further altered by setting {@link #bodyBorder} to false.
  9637. */
  9638. /**
  9639. * @cfg {Boolean} bodyBorder
  9640. * True to display an interior border on the body element of the panel, false to hide it (defaults to true).
  9641. * This only applies when {@link #border} == true. If border == true and bodyBorder == false, the border will display
  9642. * as a 1px wide inset border, giving the entire body element an inset appearance.
  9643. */
  9644. /**
  9645. * @cfg {String/Object/Function} bodyCssClass
  9646. * Additional css class selector to be applied to the {@link #body} element in the format expected by
  9647. * {@link Ext.Element#addClass} (defaults to null). See {@link #bodyCfg}.
  9648. */
  9649. /**
  9650. * @cfg {String/Object/Function} bodyStyle
  9651. * Custom CSS styles to be applied to the {@link #body} element in the format expected by
  9652. * {@link Ext.Element#applyStyles} (defaults to null). See {@link #bodyCfg}.
  9653. */
  9654. /**
  9655. * @cfg {String} iconCls
  9656. * The CSS class selector that specifies a background image to be used as the header icon (defaults to '').
  9657. * <p>An example of specifying a custom icon class would be something like:
  9658. * </p><pre><code>
  9659. // specify the property in the config for the class:
  9660. ...
  9661. iconCls: 'my-icon'
  9662. // css class that specifies background image to be used as the icon image:
  9663. .my-icon { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }
  9664. </code></pre>
  9665. */
  9666. /**
  9667. * @cfg {Boolean} collapsible
  9668. * True to make the panel collapsible and have the expand/collapse toggle button automatically rendered into
  9669. * the header tool button area, false to keep the panel statically sized with no button (defaults to false).
  9670. */
  9671. /**
  9672. * @cfg {Array} tools
  9673. * An array of tool button configs to be added to the header tool area. When rendered, each tool is
  9674. * stored as an {@link Ext.Element Element} referenced by a public property called <code><b></b>tools.<i>&lt;tool-type&gt;</i></code>
  9675. * <p>Each tool config may contain the following properties:
  9676. * <div class="mdetail-params"><ul>
  9677. * <li><b>id</b> : String<div class="sub-desc"><b>Required.</b> The type
  9678. * 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
  9679. * resulting tool Element. Ext provides CSS rules, and an icon sprite containing images for the tool types listed below.
  9680. * The developer may implement custom tools by supplying alternate CSS rules and background images:
  9681. * <ul>
  9682. * <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>
  9683. * <div class="x-tool x-tool-close" style="float:left; margin-right:5;"> </div><div><code> close</code></div>
  9684. * <div class="x-tool x-tool-minimize" style="float:left; margin-right:5;"> </div><div><code> minimize</code></div>
  9685. * <div class="x-tool x-tool-maximize" style="float:left; margin-right:5;"> </div><div><code> maximize</code></div>
  9686. * <div class="x-tool x-tool-restore" style="float:left; margin-right:5;"> </div><div><code> restore</code></div>
  9687. * <div class="x-tool x-tool-gear" style="float:left; margin-right:5;"> </div><div><code> gear</code></div>
  9688. * <div class="x-tool x-tool-pin" style="float:left; margin-right:5;"> </div><div><code> pin</code></div>
  9689. * <div class="x-tool x-tool-unpin" style="float:left; margin-right:5;"> </div><div><code> unpin</code></div>
  9690. * <div class="x-tool x-tool-right" style="float:left; margin-right:5;"> </div><div><code> right</code></div>
  9691. * <div class="x-tool x-tool-left" style="float:left; margin-right:5;"> </div><div><code> left</code></div>
  9692. * <div class="x-tool x-tool-up" style="float:left; margin-right:5;"> </div><div><code> up</code></div>
  9693. * <div class="x-tool x-tool-down" style="float:left; margin-right:5;"> </div><div><code> down</code></div>
  9694. * <div class="x-tool x-tool-refresh" style="float:left; margin-right:5;"> </div><div><code> refresh</code></div>
  9695. * <div class="x-tool x-tool-minus" style="float:left; margin-right:5;"> </div><div><code> minus</code></div>
  9696. * <div class="x-tool x-tool-plus" style="float:left; margin-right:5;"> </div><div><code> plus</code></div>
  9697. * <div class="x-tool x-tool-help" style="float:left; margin-right:5;"> </div><div><code> help</code></div>
  9698. * <div class="x-tool x-tool-search" style="float:left; margin-right:5;"> </div><div><code> search</code></div>
  9699. * <div class="x-tool x-tool-save" style="float:left; margin-right:5;"> </div><div><code> save</code></div>
  9700. * <div class="x-tool x-tool-print" style="float:left; margin-right:5;"> </div><div><code> print</code></div>
  9701. * </ul></div></li>
  9702. * <li><b>handler</b> : Function<div class="sub-desc"><b>Required.</b> The function to
  9703. * call when clicked. Arguments passed are:<ul>
  9704. * <li><b>event</b> : Ext.EventObject<div class="sub-desc">The click event.</div></li>
  9705. * <li><b>toolEl</b> : Ext.Element<div class="sub-desc">The tool Element.</div></li>
  9706. * <li><b>panel</b> : Ext.Panel<div class="sub-desc">The host Panel</div></li>
  9707. * <li><b>tc</b> : Object<div class="sub-desc">The tool configuration object</div></li>
  9708. * </ul></div></li>
  9709. * <li><b>stopEvent</b> : Boolean<div class="sub-desc">Defaults to true. Specify as false to allow click event to propagate.</div></li>
  9710. * <li><b>scope</b> : Object<div class="sub-desc">The scope in which to call the handler.</div></li>
  9711. * <li><b>qtip</b> : String/Object<div class="sub-desc">A tip string, or
  9712. * a config argument to {@link Ext.QuickTip#register}</div></li>
  9713. * <li><b>hidden</b> : Boolean<div class="sub-desc">True to initially render hidden.</div></li>
  9714. * <li><b>on</b> : Object<div class="sub-desc">A listener config object specifiying
  9715. * event listeners in the format of an argument to {@link #addListener}</div></li>
  9716. * </ul></div>
  9717. * <p>Note that, apart from the toggle tool which is provided when a panel is collapsible, these
  9718. * tools only provide the visual button. Any required functionality must be provided by adding
  9719. * handlers that implement the necessary behavior.</p>
  9720. * <p>Example usage:</p>
  9721. * <pre><code>
  9722. tools:[{
  9723. id:'refresh',
  9724. qtip: 'Refresh form Data',
  9725. // hidden:true,
  9726. handler: function(event, toolEl, panel){
  9727. // refresh logic
  9728. }
  9729. },
  9730. {
  9731. id:'help',
  9732. qtip: 'Get Help',
  9733. handler: function(event, toolEl, panel){
  9734. // whatever
  9735. }
  9736. }]
  9737. </code></pre>
  9738. * <p>For the custom id of <code>'help'</code> define two relevant css classes with a link to
  9739. * a 15x15 image:</p>
  9740. * <pre><code>
  9741. .x-tool-help {background-image: url(images/help.png);}
  9742. .x-tool-help-over {background-image: url(images/help_over.png);}
  9743. // if using an image sprite:
  9744. .x-tool-help {background-image: url(images/help.png) no-repeat 0 0;}
  9745. .x-tool-help-over {background-position:-15px 0;}
  9746. </code></pre>
  9747. */
  9748. /**
  9749. * @cfg {Ext.Template/Ext.XTemplate} toolTemplate
  9750. * <p>A Template used to create {@link #tools} in the {@link #header} Element. Defaults to:</p><pre><code>
  9751. new Ext.Template('&lt;div class="x-tool x-tool-{id}">&amp;#160;&lt;/div>')</code></pre>
  9752. * <p>This may may be overridden to provide a custom DOM structure for tools based upon a more
  9753. * complex XTemplate. The template's data is a single tool configuration object (Not the entire Array)
  9754. * as specified in {@link #tools}. In the following example an &lt;a> tag is used to provide a
  9755. * visual indication when hovering over the tool:</p><pre><code>
  9756. var win = new Ext.Window({
  9757. tools: [{
  9758. id: 'download',
  9759. href: '/MyPdfDoc.pdf'
  9760. }],
  9761. toolTemplate: new Ext.XTemplate(
  9762. '&lt;tpl if="id==\'download\'">',
  9763. '&lt;a class="x-tool x-tool-pdf" href="{href}">&lt;/a>',
  9764. '&lt;/tpl>',
  9765. '&lt;tpl if="id!=\'download\'">',
  9766. '&lt;div class="x-tool x-tool-{id}">&amp;#160;&lt;/div>',
  9767. '&lt;/tpl>'
  9768. ),
  9769. width:500,
  9770. height:300,
  9771. closeAction:'hide'
  9772. });</code></pre>
  9773. * <p>Note that the CSS class 'x-tool-pdf' should have an associated style rule which provides an
  9774. * appropriate background image, something like:</p>
  9775. <pre><code>
  9776. a.x-tool-pdf {background-image: url(../shared/extjs/images/pdf.gif)!important;}
  9777. </code></pre>
  9778. */
  9779. /**
  9780. * @cfg {Boolean} hideCollapseTool
  9781. * <code>true</code> to hide the expand/collapse toggle button when <code>{@link #collapsible} == true</code>,
  9782. * <code>false</code> to display it (defaults to <code>false</code>).
  9783. */
  9784. /**
  9785. * @cfg {Boolean} titleCollapse
  9786. * <code>true</code> to allow expanding and collapsing the panel (when <code>{@link #collapsible} = true</code>)
  9787. * by clicking anywhere in the header bar, <code>false</code>) to allow it only by clicking to tool button
  9788. * (defaults to <code>false</code>)). If this panel is a child item of a border layout also see the
  9789. * {@link Ext.layout.BorderLayout.Region BorderLayout.Region}
  9790. * <code>{@link Ext.layout.BorderLayout.Region#floatable floatable}</code> config option.
  9791. */
  9792. /**
  9793. * @cfg {Mixed} floating
  9794. * <p>This property is used to configure the underlying {@link Ext.Layer}. Acceptable values for this
  9795. * configuration property are:</p><div class="mdetail-params"><ul>
  9796. * <li><b><code>false</code></b> : <b>Default.</b><div class="sub-desc">Display the panel inline where it is
  9797. * rendered.</div></li>
  9798. * <li><b><code>true</code></b> : <div class="sub-desc">Float the panel (absolute position it with automatic
  9799. * shimming and shadow).<ul>
  9800. * <div class="sub-desc">Setting floating to true will create an Ext.Layer for this panel and display the
  9801. * panel at negative offsets so that it is hidden.</div>
  9802. * <div class="sub-desc">Since the panel will be absolute positioned, the position must be set explicitly
  9803. * <i>after</i> render (e.g., <code>myPanel.setPosition(100,100);</code>).</div>
  9804. * <div class="sub-desc"><b>Note</b>: when floating a panel you should always assign a fixed width,
  9805. * otherwise it will be auto width and will expand to fill to the right edge of the viewport.</div>
  9806. * </ul></div></li>
  9807. * <li><b><code>{@link Ext.Layer object}</code></b> : <div class="sub-desc">The specified object will be used
  9808. * as the configuration object for the {@link Ext.Layer} that will be created.</div></li>
  9809. * </ul></div>
  9810. */
  9811. /**
  9812. * @cfg {Boolean/String} shadow
  9813. * <code>true</code> (or a valid Ext.Shadow {@link Ext.Shadow#mode} value) to display a shadow behind the
  9814. * panel, <code>false</code> to display no shadow (defaults to <code>'sides'</code>). Note that this option
  9815. * only applies when <code>{@link #floating} = true</code>.
  9816. */
  9817. /**
  9818. * @cfg {Number} shadowOffset
  9819. * The number of pixels to offset the shadow if displayed (defaults to <code>4</code>). Note that this
  9820. * option only applies when <code>{@link #floating} = true</code>.
  9821. */
  9822. /**
  9823. * @cfg {Boolean} shim
  9824. * <code>false</code> to disable the iframe shim in browsers which need one (defaults to <code>true</code>).
  9825. * Note that this option only applies when <code>{@link #floating} = true</code>.
  9826. */
  9827. /**
  9828. * @cfg {Object/Array} keys
  9829. * A {@link Ext.KeyMap} config object (in the format expected by {@link Ext.KeyMap#addBinding}
  9830. * used to assign custom key handling to this panel (defaults to <code>null</code>).
  9831. */
  9832. /**
  9833. * @cfg {Boolean/Object} draggable
  9834. * <p><code>true</code> to enable dragging of this Panel (defaults to <code>false</code>).</p>
  9835. * <p>For custom drag/drop implementations, an <b>Ext.Panel.DD</b> config could also be passed
  9836. * in this config instead of <code>true</code>. Ext.Panel.DD is an internal, undocumented class which
  9837. * moves a proxy Element around in place of the Panel's element, but provides no other behaviour
  9838. * during dragging or on drop. It is a subclass of {@link Ext.dd.DragSource}, so behaviour may be
  9839. * added by implementing the interface methods of {@link Ext.dd.DragDrop} e.g.:
  9840. * <pre><code>
  9841. new Ext.Panel({
  9842. title: 'Drag me',
  9843. x: 100,
  9844. y: 100,
  9845. renderTo: Ext.getBody(),
  9846. floating: true,
  9847. frame: true,
  9848. width: 400,
  9849. height: 200,
  9850. draggable: {
  9851. // Config option of Ext.Panel.DD class.
  9852. // It&#39;s a floating Panel, so do not show a placeholder proxy in the original position.
  9853. insertProxy: false,
  9854. // Called for each mousemove event while dragging the DD object.
  9855. onDrag : function(e){
  9856. // Record the x,y position of the drag proxy so that we can
  9857. // position the Panel at end of drag.
  9858. var pel = this.proxy.getEl();
  9859. this.x = pel.getLeft(true);
  9860. this.y = pel.getTop(true);
  9861. // Keep the Shadow aligned if there is one.
  9862. var s = this.panel.getEl().shadow;
  9863. if (s) {
  9864. s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
  9865. }
  9866. },
  9867. // Called on the mouseup event.
  9868. endDrag : function(e){
  9869. this.panel.setPosition(this.x, this.y);
  9870. }
  9871. }
  9872. }).show();
  9873. </code></pre>
  9874. */
  9875. /**
  9876. * @cfg {Boolean} disabled
  9877. * Render this panel disabled (default is <code>false</code>). An important note when using the disabled
  9878. * config on panels is that IE will often fail to initialize the disabled mask element correectly if
  9879. * the panel's layout has not yet completed by the time the Panel is disabled during the render process.
  9880. * If you experience this issue, you may need to instead use the {@link #afterlayout} event to initialize
  9881. * the disabled state:
  9882. * <pre><code>
  9883. new Ext.Panel({
  9884. ...
  9885. listeners: {
  9886. 'afterlayout': {
  9887. fn: function(p){
  9888. p.disable();
  9889. },
  9890. single: true // important, as many layouts can occur
  9891. }
  9892. }
  9893. });
  9894. </code></pre>
  9895. */
  9896. /**
  9897. * @cfg {Boolean} autoHeight
  9898. * <code>true</code> to use height:'auto', <code>false</code> to use fixed height (defaults to <code>false</code>).
  9899. * <b>Note</b>: Setting <code>autoHeight: true</code> means that the browser will manage the panel's height
  9900. * based on its contents, and that Ext will not manage it at all. If the panel is within a layout that
  9901. * manages dimensions (<code>fit</code>, <code>border</code>, etc.) then setting <code>autoHeight: true</code>
  9902. * can cause issues with scrolling and will not generally work as expected since the panel will take
  9903. * on the height of its contents rather than the height required by the Ext layout.
  9904. */
  9905. /**
  9906. * @cfg {String} baseCls
  9907. * The base CSS class to apply to this panel's element (defaults to <code>'x-panel'</code>).
  9908. * <p>Another option available by default is to specify <code>'x-plain'</code> which strips all styling
  9909. * except for required attributes for Ext layouts to function (e.g. overflow:hidden).
  9910. * See <code>{@link #unstyled}</code> also.</p>
  9911. */
  9912. baseCls : 'x-panel',
  9913. /**
  9914. * @cfg {String} collapsedCls
  9915. * A CSS class to add to the panel's element after it has been collapsed (defaults to
  9916. * <code>'x-panel-collapsed'</code>).
  9917. */
  9918. collapsedCls : 'x-panel-collapsed',
  9919. /**
  9920. * @cfg {Boolean} maskDisabled
  9921. * <code>true</code> to mask the panel when it is {@link #disabled}, <code>false</code> to not mask it (defaults
  9922. * to <code>true</code>). Either way, the panel will always tell its contained elements to disable themselves
  9923. * when it is disabled, but masking the panel can provide an additional visual cue that the panel is
  9924. * disabled.
  9925. */
  9926. maskDisabled : true,
  9927. /**
  9928. * @cfg {Boolean} animCollapse
  9929. * <code>true</code> to animate the transition when the panel is collapsed, <code>false</code> to skip the
  9930. * animation (defaults to <code>true</code> if the {@link Ext.Fx} class is available, otherwise <code>false</code>).
  9931. */
  9932. animCollapse : Ext.enableFx,
  9933. /**
  9934. * @cfg {Boolean} headerAsText
  9935. * <code>true</code> to display the panel <code>{@link #title}</code> in the <code>{@link #header}</code>,
  9936. * <code>false</code> to hide it (defaults to <code>true</code>).
  9937. */
  9938. headerAsText : true,
  9939. /**
  9940. * @cfg {String} buttonAlign
  9941. * The alignment of any {@link #buttons} added to this panel. Valid values are <code>'right'</code>,
  9942. * <code>'left'</code> and <code>'center'</code> (defaults to <code>'right'</code>).
  9943. */
  9944. buttonAlign : 'right',
  9945. /**
  9946. * @cfg {Boolean} collapsed
  9947. * <code>true</code> to render the panel collapsed, <code>false</code> to render it expanded (defaults to
  9948. * <code>false</code>).
  9949. */
  9950. collapsed : false,
  9951. /**
  9952. * @cfg {Boolean} collapseFirst
  9953. * <code>true</code> to make sure the collapse/expand toggle button always renders first (to the left of)
  9954. * any other tools in the panel's title bar, <code>false</code> to render it last (defaults to <code>true</code>).
  9955. */
  9956. collapseFirst : true,
  9957. /**
  9958. * @cfg {Number} minButtonWidth
  9959. * Minimum width in pixels of all {@link #buttons} in this panel (defaults to <code>75</code>)
  9960. */
  9961. minButtonWidth : 75,
  9962. /**
  9963. * @cfg {Boolean} unstyled
  9964. * Overrides the <code>{@link #baseCls}</code> setting to <code>{@link #baseCls} = 'x-plain'</code> which renders
  9965. * the panel unstyled except for required attributes for Ext layouts to function (e.g. overflow:hidden).
  9966. */
  9967. /**
  9968. * @cfg {String} elements
  9969. * A comma-delimited list of panel elements to initialize when the panel is rendered. Normally, this list will be
  9970. * generated automatically based on the items added to the panel at config time, but sometimes it might be useful to
  9971. * make sure a structural element is rendered even if not specified at config time (for example, you may want
  9972. * to add a button or toolbar dynamically after the panel has been rendered). Adding those elements to this
  9973. * list will allocate the required placeholders in the panel when it is rendered. Valid values are<div class="mdetail-params"><ul>
  9974. * <li><code>header</code></li>
  9975. * <li><code>tbar</code> (top bar)</li>
  9976. * <li><code>body</code></li>
  9977. * <li><code>bbar</code> (bottom bar)</li>
  9978. * <li><code>footer</code></li>
  9979. * </ul></div>
  9980. * Defaults to '<code>body</code>'.
  9981. */
  9982. elements : 'body',
  9983. /**
  9984. * @cfg {Boolean} preventBodyReset
  9985. * Defaults to <code>false</code>. When set to <code>true</code>, an extra css class <code>'x-panel-normal'</code>
  9986. * will be added to the panel's element, effectively applying css styles suggested by the W3C
  9987. * (see http://www.w3.org/TR/CSS21/sample.html) to the Panel's <b>body</b> element (not the header,
  9988. * footer, etc.).
  9989. */
  9990. preventBodyReset : false,
  9991. /**
  9992. * @cfg {Number/String} padding
  9993. * A shortcut for setting a padding style on the body element. The value can either be
  9994. * a number to be applied to all sides, or a normal css string describing padding.
  9995. * Defaults to <tt>undefined</tt>.
  9996. *
  9997. */
  9998. padding: undefined,
  9999. /** @cfg {String} resizeEvent
  10000. * The event to listen to for resizing in layouts. Defaults to <tt>'bodyresize'</tt>.
  10001. */
  10002. resizeEvent: 'bodyresize',
  10003. // protected - these could be used to customize the behavior of the window,
  10004. // but changing them would not be useful without further mofifications and
  10005. // could lead to unexpected or undesirable results.
  10006. toolTarget : 'header',
  10007. collapseEl : 'bwrap',
  10008. slideAnchor : 't',
  10009. disabledClass : '',
  10010. // private, notify box this class will handle heights
  10011. deferHeight : true,
  10012. // private
  10013. expandDefaults: {
  10014. duration : 0.25
  10015. },
  10016. // private
  10017. collapseDefaults : {
  10018. duration : 0.25
  10019. },
  10020. // private
  10021. initComponent : function(){
  10022. Ext.Panel.superclass.initComponent.call(this);
  10023. this.addEvents(
  10024. /**
  10025. * @event bodyresize
  10026. * Fires after the Panel has been resized.
  10027. * @param {Ext.Panel} p the Panel which has been resized.
  10028. * @param {Number} width The Panel body's new width.
  10029. * @param {Number} height The Panel body's new height.
  10030. */
  10031. 'bodyresize',
  10032. /**
  10033. * @event titlechange
  10034. * Fires after the Panel title has been {@link #title set} or {@link #setTitle changed}.
  10035. * @param {Ext.Panel} p the Panel which has had its title changed.
  10036. * @param {String} The new title.
  10037. */
  10038. 'titlechange',
  10039. /**
  10040. * @event iconchange
  10041. * Fires after the Panel icon class has been {@link #iconCls set} or {@link #setIconClass changed}.
  10042. * @param {Ext.Panel} p the Panel which has had its {@link #iconCls icon class} changed.
  10043. * @param {String} The new icon class.
  10044. * @param {String} The old icon class.
  10045. */
  10046. 'iconchange',
  10047. /**
  10048. * @event collapse
  10049. * Fires after the Panel has been collapsed.
  10050. * @param {Ext.Panel} p the Panel that has been collapsed.
  10051. */
  10052. 'collapse',
  10053. /**
  10054. * @event expand
  10055. * Fires after the Panel has been expanded.
  10056. * @param {Ext.Panel} p The Panel that has been expanded.
  10057. */
  10058. 'expand',
  10059. /**
  10060. * @event beforecollapse
  10061. * Fires before the Panel is collapsed. A handler can return false to cancel the collapse.
  10062. * @param {Ext.Panel} p the Panel being collapsed.
  10063. * @param {Boolean} animate True if the collapse is animated, else false.
  10064. */
  10065. 'beforecollapse',
  10066. /**
  10067. * @event beforeexpand
  10068. * Fires before the Panel is expanded. A handler can return false to cancel the expand.
  10069. * @param {Ext.Panel} p The Panel being expanded.
  10070. * @param {Boolean} animate True if the expand is animated, else false.
  10071. */
  10072. 'beforeexpand',
  10073. /**
  10074. * @event beforeclose
  10075. * Fires before the Panel is closed. Note that Panels do not directly support being closed, but some
  10076. * Panel subclasses do (like {@link Ext.Window}) or a Panel within a Ext.TabPanel. This event only
  10077. * applies to such subclasses.
  10078. * A handler can return false to cancel the close.
  10079. * @param {Ext.Panel} p The Panel being closed.
  10080. */
  10081. 'beforeclose',
  10082. /**
  10083. * @event close
  10084. * Fires after the Panel is closed. Note that Panels do not directly support being closed, but some
  10085. * Panel subclasses do (like {@link Ext.Window}) or a Panel within a Ext.TabPanel.
  10086. * @param {Ext.Panel} p The Panel that has been closed.
  10087. */
  10088. 'close',
  10089. /**
  10090. * @event activate
  10091. * Fires after the Panel has been visually activated.
  10092. * Note that Panels do not directly support being activated, but some Panel subclasses
  10093. * do (like {@link Ext.Window}). Panels which are child Components of a TabPanel fire the
  10094. * activate and deactivate events under the control of the TabPanel.
  10095. * @param {Ext.Panel} p The Panel that has been activated.
  10096. */
  10097. 'activate',
  10098. /**
  10099. * @event deactivate
  10100. * Fires after the Panel has been visually deactivated.
  10101. * Note that Panels do not directly support being deactivated, but some Panel subclasses
  10102. * do (like {@link Ext.Window}). Panels which are child Components of a TabPanel fire the
  10103. * activate and deactivate events under the control of the TabPanel.
  10104. * @param {Ext.Panel} p The Panel that has been deactivated.
  10105. */
  10106. 'deactivate'
  10107. );
  10108. if(this.unstyled){
  10109. this.baseCls = 'x-plain';
  10110. }
  10111. this.toolbars = [];
  10112. // shortcuts
  10113. if(this.tbar){
  10114. this.elements += ',tbar';
  10115. this.topToolbar = this.createToolbar(this.tbar);
  10116. this.tbar = null;
  10117. }
  10118. if(this.bbar){
  10119. this.elements += ',bbar';
  10120. this.bottomToolbar = this.createToolbar(this.bbar);
  10121. this.bbar = null;
  10122. }
  10123. if(this.header === true){
  10124. this.elements += ',header';
  10125. this.header = null;
  10126. }else if(this.headerCfg || (this.title && this.header !== false)){
  10127. this.elements += ',header';
  10128. }
  10129. if(this.footerCfg || this.footer === true){
  10130. this.elements += ',footer';
  10131. this.footer = null;
  10132. }
  10133. if(this.buttons){
  10134. this.fbar = this.buttons;
  10135. this.buttons = null;
  10136. }
  10137. if(this.fbar){
  10138. this.createFbar(this.fbar);
  10139. }
  10140. if(this.autoLoad){
  10141. this.on('render', this.doAutoLoad, this, {delay:10});
  10142. }
  10143. },
  10144. // private
  10145. createFbar : function(fbar){
  10146. var min = this.minButtonWidth;
  10147. this.elements += ',footer';
  10148. this.fbar = this.createToolbar(fbar, {
  10149. buttonAlign: this.buttonAlign,
  10150. toolbarCls: 'x-panel-fbar',
  10151. enableOverflow: false,
  10152. defaults: function(c){
  10153. return {
  10154. minWidth: c.minWidth || min
  10155. };
  10156. }
  10157. });
  10158. // @compat addButton and buttons could possibly be removed
  10159. // @target 4.0
  10160. /**
  10161. * This Panel's Array of buttons as created from the <code>{@link #buttons}</code>
  10162. * config property. Read only.
  10163. * @type Array
  10164. * @property buttons
  10165. */
  10166. this.fbar.items.each(function(c){
  10167. c.minWidth = c.minWidth || this.minButtonWidth;
  10168. }, this);
  10169. this.buttons = this.fbar.items.items;
  10170. },
  10171. // private
  10172. createToolbar: function(tb, options){
  10173. var result;
  10174. // Convert array to proper toolbar config
  10175. if(Ext.isArray(tb)){
  10176. tb = {
  10177. items: tb
  10178. };
  10179. }
  10180. result = tb.events ? Ext.apply(tb, options) : this.createComponent(Ext.apply({}, tb, options), 'toolbar');
  10181. this.toolbars.push(result);
  10182. return result;
  10183. },
  10184. // private
  10185. createElement : function(name, pnode){
  10186. if(this[name]){
  10187. pnode.appendChild(this[name].dom);
  10188. return;
  10189. }
  10190. if(name === 'bwrap' || this.elements.indexOf(name) != -1){
  10191. if(this[name+'Cfg']){
  10192. this[name] = Ext.fly(pnode).createChild(this[name+'Cfg']);
  10193. }else{
  10194. var el = document.createElement('div');
  10195. el.className = this[name+'Cls'];
  10196. this[name] = Ext.get(pnode.appendChild(el));
  10197. }
  10198. if(this[name+'CssClass']){
  10199. this[name].addClass(this[name+'CssClass']);
  10200. }
  10201. if(this[name+'Style']){
  10202. this[name].applyStyles(this[name+'Style']);
  10203. }
  10204. }
  10205. },
  10206. // private
  10207. onRender : function(ct, position){
  10208. Ext.Panel.superclass.onRender.call(this, ct, position);
  10209. this.createClasses();
  10210. var el = this.el,
  10211. d = el.dom,
  10212. bw,
  10213. ts;
  10214. if(this.collapsible && !this.hideCollapseTool){
  10215. this.tools = this.tools ? this.tools.slice(0) : [];
  10216. this.tools[this.collapseFirst?'unshift':'push']({
  10217. id: 'toggle',
  10218. handler : this.toggleCollapse,
  10219. scope: this
  10220. });
  10221. }
  10222. if(this.tools){
  10223. ts = this.tools;
  10224. this.elements += (this.header !== false) ? ',header' : '';
  10225. }
  10226. this.tools = {};
  10227. el.addClass(this.baseCls);
  10228. if(d.firstChild){ // existing markup
  10229. this.header = el.down('.'+this.headerCls);
  10230. this.bwrap = el.down('.'+this.bwrapCls);
  10231. var cp = this.bwrap ? this.bwrap : el;
  10232. this.tbar = cp.down('.'+this.tbarCls);
  10233. this.body = cp.down('.'+this.bodyCls);
  10234. this.bbar = cp.down('.'+this.bbarCls);
  10235. this.footer = cp.down('.'+this.footerCls);
  10236. this.fromMarkup = true;
  10237. }
  10238. if (this.preventBodyReset === true) {
  10239. el.addClass('x-panel-reset');
  10240. }
  10241. if(this.cls){
  10242. el.addClass(this.cls);
  10243. }
  10244. if(this.buttons){
  10245. this.elements += ',footer';
  10246. }
  10247. // This block allows for maximum flexibility and performance when using existing markup
  10248. // framing requires special markup
  10249. if(this.frame){
  10250. el.insertHtml('afterBegin', String.format(Ext.Element.boxMarkup, this.baseCls));
  10251. this.createElement('header', d.firstChild.firstChild.firstChild);
  10252. this.createElement('bwrap', d);
  10253. // append the mid and bottom frame to the bwrap
  10254. bw = this.bwrap.dom;
  10255. var ml = d.childNodes[1], bl = d.childNodes[2];
  10256. bw.appendChild(ml);
  10257. bw.appendChild(bl);
  10258. var mc = bw.firstChild.firstChild.firstChild;
  10259. this.createElement('tbar', mc);
  10260. this.createElement('body', mc);
  10261. this.createElement('bbar', mc);
  10262. this.createElement('footer', bw.lastChild.firstChild.firstChild);
  10263. if(!this.footer){
  10264. this.bwrap.dom.lastChild.className += ' x-panel-nofooter';
  10265. }
  10266. /*
  10267. * Store a reference to this element so:
  10268. * a) We aren't looking it up all the time
  10269. * b) The last element is reported incorrectly when using a loadmask
  10270. */
  10271. this.ft = Ext.get(this.bwrap.dom.lastChild);
  10272. this.mc = Ext.get(mc);
  10273. }else{
  10274. this.createElement('header', d);
  10275. this.createElement('bwrap', d);
  10276. // append the mid and bottom frame to the bwrap
  10277. bw = this.bwrap.dom;
  10278. this.createElement('tbar', bw);
  10279. this.createElement('body', bw);
  10280. this.createElement('bbar', bw);
  10281. this.createElement('footer', bw);
  10282. if(!this.header){
  10283. this.body.addClass(this.bodyCls + '-noheader');
  10284. if(this.tbar){
  10285. this.tbar.addClass(this.tbarCls + '-noheader');
  10286. }
  10287. }
  10288. }
  10289. if(Ext.isDefined(this.padding)){
  10290. this.body.setStyle('padding', this.body.addUnits(this.padding));
  10291. }
  10292. if(this.border === false){
  10293. this.el.addClass(this.baseCls + '-noborder');
  10294. this.body.addClass(this.bodyCls + '-noborder');
  10295. if(this.header){
  10296. this.header.addClass(this.headerCls + '-noborder');
  10297. }
  10298. if(this.footer){
  10299. this.footer.addClass(this.footerCls + '-noborder');
  10300. }
  10301. if(this.tbar){
  10302. this.tbar.addClass(this.tbarCls + '-noborder');
  10303. }
  10304. if(this.bbar){
  10305. this.bbar.addClass(this.bbarCls + '-noborder');
  10306. }
  10307. }
  10308. if(this.bodyBorder === false){
  10309. this.body.addClass(this.bodyCls + '-noborder');
  10310. }
  10311. this.bwrap.enableDisplayMode('block');
  10312. if(this.header){
  10313. this.header.unselectable();
  10314. // for tools, we need to wrap any existing header markup
  10315. if(this.headerAsText){
  10316. this.header.dom.innerHTML =
  10317. '<span class="' + this.headerTextCls + '">'+this.header.dom.innerHTML+'</span>';
  10318. if(this.iconCls){
  10319. this.setIconClass(this.iconCls);
  10320. }
  10321. }
  10322. }
  10323. if(this.floating){
  10324. this.makeFloating(this.floating);
  10325. }
  10326. if(this.collapsible && this.titleCollapse && this.header){
  10327. this.mon(this.header, 'click', this.toggleCollapse, this);
  10328. this.header.setStyle('cursor', 'pointer');
  10329. }
  10330. if(ts){
  10331. this.addTool.apply(this, ts);
  10332. }
  10333. // Render Toolbars.
  10334. if(this.fbar){
  10335. this.footer.addClass('x-panel-btns');
  10336. this.fbar.ownerCt = this;
  10337. this.fbar.render(this.footer);
  10338. this.footer.createChild({cls:'x-clear'});
  10339. }
  10340. if(this.tbar && this.topToolbar){
  10341. this.topToolbar.ownerCt = this;
  10342. this.topToolbar.render(this.tbar);
  10343. }
  10344. if(this.bbar && this.bottomToolbar){
  10345. this.bottomToolbar.ownerCt = this;
  10346. this.bottomToolbar.render(this.bbar);
  10347. }
  10348. },
  10349. /**
  10350. * Sets the CSS class that provides the icon image for this panel. This method will replace any existing
  10351. * icon class if one has already been set and fire the {@link #iconchange} event after completion.
  10352. * @param {String} cls The new CSS class name
  10353. */
  10354. setIconClass : function(cls){
  10355. var old = this.iconCls;
  10356. this.iconCls = cls;
  10357. if(this.rendered && this.header){
  10358. if(this.frame){
  10359. this.header.addClass('x-panel-icon');
  10360. this.header.replaceClass(old, this.iconCls);
  10361. }else{
  10362. var hd = this.header,
  10363. img = hd.child('img.x-panel-inline-icon');
  10364. if(img){
  10365. Ext.fly(img).replaceClass(old, this.iconCls);
  10366. }else{
  10367. var hdspan = hd.child('span.' + this.headerTextCls);
  10368. if (hdspan) {
  10369. Ext.DomHelper.insertBefore(hdspan.dom, {
  10370. tag:'img', alt: '', src: Ext.BLANK_IMAGE_URL, cls:'x-panel-inline-icon '+this.iconCls
  10371. });
  10372. }
  10373. }
  10374. }
  10375. }
  10376. this.fireEvent('iconchange', this, cls, old);
  10377. },
  10378. // private
  10379. makeFloating : function(cfg){
  10380. this.floating = true;
  10381. this.el = new Ext.Layer(Ext.apply({}, cfg, {
  10382. shadow: Ext.isDefined(this.shadow) ? this.shadow : 'sides',
  10383. shadowOffset: this.shadowOffset,
  10384. constrain:false,
  10385. shim: this.shim === false ? false : undefined
  10386. }), this.el);
  10387. },
  10388. /**
  10389. * Returns the {@link Ext.Toolbar toolbar} from the top (<code>{@link #tbar}</code>) section of the panel.
  10390. * @return {Ext.Toolbar} The toolbar
  10391. */
  10392. getTopToolbar : function(){
  10393. return this.topToolbar;
  10394. },
  10395. /**
  10396. * Returns the {@link Ext.Toolbar toolbar} from the bottom (<code>{@link #bbar}</code>) section of the panel.
  10397. * @return {Ext.Toolbar} The toolbar
  10398. */
  10399. getBottomToolbar : function(){
  10400. return this.bottomToolbar;
  10401. },
  10402. /**
  10403. * Returns the {@link Ext.Toolbar toolbar} from the footer (<code>{@link #fbar}</code>) section of the panel.
  10404. * @return {Ext.Toolbar} The toolbar
  10405. */
  10406. getFooterToolbar : function() {
  10407. return this.fbar;
  10408. },
  10409. /**
  10410. * Adds a button to this panel. Note that this method must be called prior to rendering. The preferred
  10411. * approach is to add buttons via the {@link #buttons} config.
  10412. * @param {String/Object} config A valid {@link Ext.Button} config. A string will become the text for a default
  10413. * button config, an object will be treated as a button config object.
  10414. * @param {Function} handler The function to be called on button {@link Ext.Button#click}
  10415. * @param {Object} scope The scope (<code>this</code> reference) in which the button handler function is executed. Defaults to the Button.
  10416. * @return {Ext.Button} The button that was added
  10417. */
  10418. addButton : function(config, handler, scope){
  10419. if(!this.fbar){
  10420. this.createFbar([]);
  10421. }
  10422. if(handler){
  10423. if(Ext.isString(config)){
  10424. config = {text: config};
  10425. }
  10426. config = Ext.apply({
  10427. handler: handler,
  10428. scope: scope
  10429. }, config);
  10430. }
  10431. return this.fbar.add(config);
  10432. },
  10433. // private
  10434. addTool : function(){
  10435. if(!this.rendered){
  10436. if(!this.tools){
  10437. this.tools = [];
  10438. }
  10439. Ext.each(arguments, function(arg){
  10440. this.tools.push(arg);
  10441. }, this);
  10442. return;
  10443. }
  10444. // nowhere to render tools!
  10445. if(!this[this.toolTarget]){
  10446. return;
  10447. }
  10448. if(!this.toolTemplate){
  10449. // initialize the global tool template on first use
  10450. var tt = new Ext.Template(
  10451. '<div class="x-tool x-tool-{id}">&#160;</div>'
  10452. );
  10453. tt.disableFormats = true;
  10454. tt.compile();
  10455. Ext.Panel.prototype.toolTemplate = tt;
  10456. }
  10457. for(var i = 0, a = arguments, len = a.length; i < len; i++) {
  10458. var tc = a[i];
  10459. if(!this.tools[tc.id]){
  10460. var overCls = 'x-tool-'+tc.id+'-over';
  10461. var t = this.toolTemplate.insertFirst(this[this.toolTarget], tc, true);
  10462. this.tools[tc.id] = t;
  10463. t.enableDisplayMode('block');
  10464. this.mon(t, 'click', this.createToolHandler(t, tc, overCls, this));
  10465. if(tc.on){
  10466. this.mon(t, tc.on);
  10467. }
  10468. if(tc.hidden){
  10469. t.hide();
  10470. }
  10471. if(tc.qtip){
  10472. if(Ext.isObject(tc.qtip)){
  10473. Ext.QuickTips.register(Ext.apply({
  10474. target: t.id
  10475. }, tc.qtip));
  10476. } else {
  10477. t.dom.qtip = tc.qtip;
  10478. }
  10479. }
  10480. t.addClassOnOver(overCls);
  10481. }
  10482. }
  10483. },
  10484. onLayout : function(shallow, force){
  10485. Ext.Panel.superclass.onLayout.apply(this, arguments);
  10486. if(this.hasLayout && this.toolbars.length > 0){
  10487. Ext.each(this.toolbars, function(tb){
  10488. tb.doLayout(undefined, force);
  10489. });
  10490. this.syncHeight();
  10491. }
  10492. },
  10493. syncHeight : function(){
  10494. var h = this.toolbarHeight,
  10495. bd = this.body,
  10496. lsh = this.lastSize.height,
  10497. sz;
  10498. if(this.autoHeight || !Ext.isDefined(lsh) || lsh == 'auto'){
  10499. return;
  10500. }
  10501. if(h != this.getToolbarHeight()){
  10502. h = Math.max(0, lsh - this.getFrameHeight());
  10503. bd.setHeight(h);
  10504. sz = bd.getSize();
  10505. this.toolbarHeight = this.getToolbarHeight();
  10506. this.onBodyResize(sz.width, sz.height);
  10507. }
  10508. },
  10509. // private
  10510. onShow : function(){
  10511. if(this.floating){
  10512. return this.el.show();
  10513. }
  10514. Ext.Panel.superclass.onShow.call(this);
  10515. },
  10516. // private
  10517. onHide : function(){
  10518. if(this.floating){
  10519. return this.el.hide();
  10520. }
  10521. Ext.Panel.superclass.onHide.call(this);
  10522. },
  10523. // private
  10524. createToolHandler : function(t, tc, overCls, panel){
  10525. return function(e){
  10526. t.removeClass(overCls);
  10527. if(tc.stopEvent !== false){
  10528. e.stopEvent();
  10529. }
  10530. if(tc.handler){
  10531. tc.handler.call(tc.scope || t, e, t, panel, tc);
  10532. }
  10533. };
  10534. },
  10535. // private
  10536. afterRender : function(){
  10537. if(this.floating && !this.hidden){
  10538. this.el.show();
  10539. }
  10540. if(this.title){
  10541. this.setTitle(this.title);
  10542. }
  10543. Ext.Panel.superclass.afterRender.call(this); // do sizing calcs last
  10544. if (this.collapsed) {
  10545. this.collapsed = false;
  10546. this.collapse(false);
  10547. }
  10548. this.initEvents();
  10549. },
  10550. // private
  10551. getKeyMap : function(){
  10552. if(!this.keyMap){
  10553. this.keyMap = new Ext.KeyMap(this.el, this.keys);
  10554. }
  10555. return this.keyMap;
  10556. },
  10557. // private
  10558. initEvents : function(){
  10559. if(this.keys){
  10560. this.getKeyMap();
  10561. }
  10562. if(this.draggable){
  10563. this.initDraggable();
  10564. }
  10565. if(this.toolbars.length > 0){
  10566. Ext.each(this.toolbars, function(tb){
  10567. tb.doLayout();
  10568. tb.on({
  10569. scope: this,
  10570. afterlayout: this.syncHeight,
  10571. remove: this.syncHeight
  10572. });
  10573. }, this);
  10574. this.syncHeight();
  10575. }
  10576. },
  10577. // private
  10578. initDraggable : function(){
  10579. /**
  10580. * <p>If this Panel is configured {@link #draggable}, this property will contain
  10581. * an instance of {@link Ext.dd.DragSource} which handles dragging the Panel.</p>
  10582. * The developer must provide implementations of the abstract methods of {@link Ext.dd.DragSource}
  10583. * in order to supply behaviour for each stage of the drag/drop process. See {@link #draggable}.
  10584. * @type Ext.dd.DragSource.
  10585. * @property dd
  10586. */
  10587. this.dd = new Ext.Panel.DD(this, Ext.isBoolean(this.draggable) ? null : this.draggable);
  10588. },
  10589. // private
  10590. beforeEffect : function(anim){
  10591. if(this.floating){
  10592. this.el.beforeAction();
  10593. }
  10594. if(anim !== false){
  10595. this.el.addClass('x-panel-animated');
  10596. }
  10597. },
  10598. // private
  10599. afterEffect : function(anim){
  10600. this.syncShadow();
  10601. this.el.removeClass('x-panel-animated');
  10602. },
  10603. // private - wraps up an animation param with internal callbacks
  10604. createEffect : function(a, cb, scope){
  10605. var o = {
  10606. scope:scope,
  10607. block:true
  10608. };
  10609. if(a === true){
  10610. o.callback = cb;
  10611. return o;
  10612. }else if(!a.callback){
  10613. o.callback = cb;
  10614. }else { // wrap it up
  10615. o.callback = function(){
  10616. cb.call(scope);
  10617. Ext.callback(a.callback, a.scope);
  10618. };
  10619. }
  10620. return Ext.applyIf(o, a);
  10621. },
  10622. /**
  10623. * Collapses the panel body so that it becomes hidden. Fires the {@link #beforecollapse} event which will
  10624. * cancel the collapse action if it returns false.
  10625. * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
  10626. * {@link #animCollapse} panel config)
  10627. * @return {Ext.Panel} this
  10628. */
  10629. collapse : function(animate){
  10630. if(this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforecollapse', this, animate) === false){
  10631. return;
  10632. }
  10633. var doAnim = animate === true || (animate !== false && this.animCollapse);
  10634. this.beforeEffect(doAnim);
  10635. this.onCollapse(doAnim, animate);
  10636. return this;
  10637. },
  10638. // private
  10639. onCollapse : function(doAnim, animArg){
  10640. if(doAnim){
  10641. this[this.collapseEl].slideOut(this.slideAnchor,
  10642. Ext.apply(this.createEffect(animArg||true, this.afterCollapse, this),
  10643. this.collapseDefaults));
  10644. }else{
  10645. this[this.collapseEl].hide(this.hideMode);
  10646. this.afterCollapse(false);
  10647. }
  10648. },
  10649. // private
  10650. afterCollapse : function(anim){
  10651. this.collapsed = true;
  10652. this.el.addClass(this.collapsedCls);
  10653. if(anim !== false){
  10654. this[this.collapseEl].hide(this.hideMode);
  10655. }
  10656. this.afterEffect(anim);
  10657. // Reset lastSize of all sub-components so they KNOW they are in a collapsed container
  10658. this.cascade(function(c) {
  10659. if (c.lastSize) {
  10660. c.lastSize = { width: undefined, height: undefined };
  10661. }
  10662. });
  10663. this.fireEvent('collapse', this);
  10664. },
  10665. /**
  10666. * Expands the panel body so that it becomes visible. Fires the {@link #beforeexpand} event which will
  10667. * cancel the expand action if it returns false.
  10668. * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
  10669. * {@link #animCollapse} panel config)
  10670. * @return {Ext.Panel} this
  10671. */
  10672. expand : function(animate){
  10673. if(!this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforeexpand', this, animate) === false){
  10674. return;
  10675. }
  10676. var doAnim = animate === true || (animate !== false && this.animCollapse);
  10677. this.el.removeClass(this.collapsedCls);
  10678. this.beforeEffect(doAnim);
  10679. this.onExpand(doAnim, animate);
  10680. return this;
  10681. },
  10682. // private
  10683. onExpand : function(doAnim, animArg){
  10684. if(doAnim){
  10685. this[this.collapseEl].slideIn(this.slideAnchor,
  10686. Ext.apply(this.createEffect(animArg||true, this.afterExpand, this),
  10687. this.expandDefaults));
  10688. }else{
  10689. this[this.collapseEl].show(this.hideMode);
  10690. this.afterExpand(false);
  10691. }
  10692. },
  10693. // private
  10694. afterExpand : function(anim){
  10695. this.collapsed = false;
  10696. if(anim !== false){
  10697. this[this.collapseEl].show(this.hideMode);
  10698. }
  10699. this.afterEffect(anim);
  10700. if (this.deferLayout) {
  10701. delete this.deferLayout;
  10702. this.doLayout(true);
  10703. }
  10704. this.fireEvent('expand', this);
  10705. },
  10706. /**
  10707. * Shortcut for performing an {@link #expand} or {@link #collapse} based on the current state of the panel.
  10708. * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
  10709. * {@link #animCollapse} panel config)
  10710. * @return {Ext.Panel} this
  10711. */
  10712. toggleCollapse : function(animate){
  10713. this[this.collapsed ? 'expand' : 'collapse'](animate);
  10714. return this;
  10715. },
  10716. // private
  10717. onDisable : function(){
  10718. if(this.rendered && this.maskDisabled){
  10719. this.el.mask();
  10720. }
  10721. Ext.Panel.superclass.onDisable.call(this);
  10722. },
  10723. // private
  10724. onEnable : function(){
  10725. if(this.rendered && this.maskDisabled){
  10726. this.el.unmask();
  10727. }
  10728. Ext.Panel.superclass.onEnable.call(this);
  10729. },
  10730. // private
  10731. onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
  10732. var w = adjWidth,
  10733. h = adjHeight;
  10734. if(Ext.isDefined(w) || Ext.isDefined(h)){
  10735. if(!this.collapsed){
  10736. // First, set the the Panel's body width.
  10737. // If we have auto-widthed it, get the resulting full offset width so we can size the Toolbars to match
  10738. // The Toolbars must not buffer this resize operation because we need to know their heights.
  10739. if(Ext.isNumber(w)){
  10740. this.body.setWidth(w = this.adjustBodyWidth(w - this.getFrameWidth()));
  10741. } else if (w == 'auto') {
  10742. w = this.body.setWidth('auto').dom.offsetWidth;
  10743. } else {
  10744. w = this.body.dom.offsetWidth;
  10745. }
  10746. if(this.tbar){
  10747. this.tbar.setWidth(w);
  10748. if(this.topToolbar){
  10749. this.topToolbar.setSize(w);
  10750. }
  10751. }
  10752. if(this.bbar){
  10753. this.bbar.setWidth(w);
  10754. if(this.bottomToolbar){
  10755. this.bottomToolbar.setSize(w);
  10756. // The bbar does not move on resize without this.
  10757. if (Ext.isIE) {
  10758. this.bbar.setStyle('position', 'static');
  10759. this.bbar.setStyle('position', '');
  10760. }
  10761. }
  10762. }
  10763. if(this.footer){
  10764. this.footer.setWidth(w);
  10765. if(this.fbar){
  10766. this.fbar.setSize(Ext.isIE ? (w - this.footer.getFrameWidth('lr')) : 'auto');
  10767. }
  10768. }
  10769. // At this point, the Toolbars must be layed out for getFrameHeight to find a result.
  10770. if(Ext.isNumber(h)){
  10771. h = Math.max(0, h - this.getFrameHeight());
  10772. //h = Math.max(0, h - (this.getHeight() - this.body.getHeight()));
  10773. this.body.setHeight(h);
  10774. }else if(h == 'auto'){
  10775. this.body.setHeight(h);
  10776. }
  10777. if(this.disabled && this.el._mask){
  10778. this.el._mask.setSize(this.el.dom.clientWidth, this.el.getHeight());
  10779. }
  10780. }else{
  10781. // Adds an event to set the correct height afterExpand. This accounts for the deferHeight flag in panel
  10782. this.queuedBodySize = {width: w, height: h};
  10783. if(!this.queuedExpand && this.allowQueuedExpand !== false){
  10784. this.queuedExpand = true;
  10785. this.on('expand', function(){
  10786. delete this.queuedExpand;
  10787. this.onResize(this.queuedBodySize.width, this.queuedBodySize.height);
  10788. }, this, {single:true});
  10789. }
  10790. }
  10791. this.onBodyResize(w, h);
  10792. }
  10793. this.syncShadow();
  10794. Ext.Panel.superclass.onResize.call(this, adjWidth, adjHeight, rawWidth, rawHeight);
  10795. },
  10796. // private
  10797. onBodyResize: function(w, h){
  10798. this.fireEvent('bodyresize', this, w, h);
  10799. },
  10800. // private
  10801. getToolbarHeight: function(){
  10802. var h = 0;
  10803. if(this.rendered){
  10804. Ext.each(this.toolbars, function(tb){
  10805. h += tb.getHeight();
  10806. }, this);
  10807. }
  10808. return h;
  10809. },
  10810. // deprecate
  10811. adjustBodyHeight : function(h){
  10812. return h;
  10813. },
  10814. // private
  10815. adjustBodyWidth : function(w){
  10816. return w;
  10817. },
  10818. // private
  10819. onPosition : function(){
  10820. this.syncShadow();
  10821. },
  10822. /**
  10823. * Returns the width in pixels of the framing elements of this panel (not including the body width). To
  10824. * retrieve the body width see {@link #getInnerWidth}.
  10825. * @return {Number} The frame width
  10826. */
  10827. getFrameWidth : function(){
  10828. var w = this.el.getFrameWidth('lr') + this.bwrap.getFrameWidth('lr');
  10829. if(this.frame){
  10830. var l = this.bwrap.dom.firstChild;
  10831. w += (Ext.fly(l).getFrameWidth('l') + Ext.fly(l.firstChild).getFrameWidth('r'));
  10832. w += this.mc.getFrameWidth('lr');
  10833. }
  10834. return w;
  10835. },
  10836. /**
  10837. * Returns the height in pixels of the framing elements of this panel (including any top and bottom bars and
  10838. * header and footer elements, but not including the body height). To retrieve the body height see {@link #getInnerHeight}.
  10839. * @return {Number} The frame height
  10840. */
  10841. getFrameHeight : function() {
  10842. var h = this.el.getFrameWidth('tb') + this.bwrap.getFrameWidth('tb');
  10843. h += (this.tbar ? this.tbar.getHeight() : 0) +
  10844. (this.bbar ? this.bbar.getHeight() : 0);
  10845. if(this.frame){
  10846. h += this.el.dom.firstChild.offsetHeight + this.ft.dom.offsetHeight + this.mc.getFrameWidth('tb');
  10847. }else{
  10848. h += (this.header ? this.header.getHeight() : 0) +
  10849. (this.footer ? this.footer.getHeight() : 0);
  10850. }
  10851. return h;
  10852. },
  10853. /**
  10854. * Returns the width in pixels of the body element (not including the width of any framing elements).
  10855. * For the frame width see {@link #getFrameWidth}.
  10856. * @return {Number} The body width
  10857. */
  10858. getInnerWidth : function(){
  10859. return this.getSize().width - this.getFrameWidth();
  10860. },
  10861. /**
  10862. * Returns the height in pixels of the body element (not including the height of any framing elements).
  10863. * For the frame height see {@link #getFrameHeight}.
  10864. * @return {Number} The body height
  10865. */
  10866. getInnerHeight : function(){
  10867. return this.body.getHeight();
  10868. /* Deprecate
  10869. return this.getSize().height - this.getFrameHeight();
  10870. */
  10871. },
  10872. // private
  10873. syncShadow : function(){
  10874. if(this.floating){
  10875. this.el.sync(true);
  10876. }
  10877. },
  10878. // private
  10879. getLayoutTarget : function(){
  10880. return this.body;
  10881. },
  10882. // private
  10883. getContentTarget : function(){
  10884. return this.body;
  10885. },
  10886. /**
  10887. * <p>Sets the title text for the panel and optionally the {@link #iconCls icon class}.</p>
  10888. * <p>In order to be able to set the title, a header element must have been created
  10889. * for the Panel. This is triggered either by configuring the Panel with a non-blank <code>{@link #title}</code>,
  10890. * or configuring it with <code><b>{@link #header}: true</b></code>.</p>
  10891. * @param {String} title The title text to set
  10892. * @param {String} iconCls (optional) {@link #iconCls iconCls} A user-defined CSS class that provides the icon image for this panel
  10893. */
  10894. setTitle : function(title, iconCls){
  10895. this.title = title;
  10896. if(this.header && this.headerAsText){
  10897. this.header.child('span').update(title);
  10898. }
  10899. if(iconCls){
  10900. this.setIconClass(iconCls);
  10901. }
  10902. this.fireEvent('titlechange', this, title);
  10903. return this;
  10904. },
  10905. /**
  10906. * Get the {@link Ext.Updater} for this panel. Enables you to perform Ajax updates of this panel's body.
  10907. * @return {Ext.Updater} The Updater
  10908. */
  10909. getUpdater : function(){
  10910. return this.body.getUpdater();
  10911. },
  10912. /**
  10913. * Loads this content panel immediately with content returned from an XHR call.
  10914. * @param {Object/String/Function} config A config object containing any of the following options:
  10915. <pre><code>
  10916. panel.load({
  10917. url: 'your-url.php',
  10918. params: {param1: 'foo', param2: 'bar'}, // or a URL encoded string
  10919. callback: yourFunction,
  10920. scope: yourObject, // optional scope for the callback
  10921. discardUrl: false,
  10922. nocache: false,
  10923. text: 'Loading...',
  10924. timeout: 30,
  10925. scripts: false
  10926. });
  10927. </code></pre>
  10928. * The only required property is url. The optional properties nocache, text and scripts
  10929. * are shorthand for disableCaching, indicatorText and loadScripts and are used to set their
  10930. * associated property on this panel Updater instance.
  10931. * @return {Ext.Panel} this
  10932. */
  10933. load : function(){
  10934. var um = this.body.getUpdater();
  10935. um.update.apply(um, arguments);
  10936. return this;
  10937. },
  10938. // private
  10939. beforeDestroy : function(){
  10940. Ext.Panel.superclass.beforeDestroy.call(this);
  10941. if(this.header){
  10942. this.header.removeAllListeners();
  10943. }
  10944. if(this.tools){
  10945. for(var k in this.tools){
  10946. Ext.destroy(this.tools[k]);
  10947. }
  10948. }
  10949. if(this.toolbars.length > 0){
  10950. Ext.each(this.toolbars, function(tb){
  10951. tb.un('afterlayout', this.syncHeight, this);
  10952. tb.un('remove', this.syncHeight, this);
  10953. }, this);
  10954. }
  10955. if(Ext.isArray(this.buttons)){
  10956. while(this.buttons.length) {
  10957. Ext.destroy(this.buttons[0]);
  10958. }
  10959. }
  10960. if(this.rendered){
  10961. Ext.destroy(
  10962. this.ft,
  10963. this.header,
  10964. this.footer,
  10965. this.tbar,
  10966. this.bbar,
  10967. this.body,
  10968. this.mc,
  10969. this.bwrap,
  10970. this.dd
  10971. );
  10972. if (this.fbar) {
  10973. Ext.destroy(
  10974. this.fbar,
  10975. this.fbar.el
  10976. );
  10977. }
  10978. }
  10979. Ext.destroy(this.toolbars);
  10980. },
  10981. // private
  10982. createClasses : function(){
  10983. this.headerCls = this.baseCls + '-header';
  10984. this.headerTextCls = this.baseCls + '-header-text';
  10985. this.bwrapCls = this.baseCls + '-bwrap';
  10986. this.tbarCls = this.baseCls + '-tbar';
  10987. this.bodyCls = this.baseCls + '-body';
  10988. this.bbarCls = this.baseCls + '-bbar';
  10989. this.footerCls = this.baseCls + '-footer';
  10990. },
  10991. // private
  10992. createGhost : function(cls, useShim, appendTo){
  10993. var el = document.createElement('div');
  10994. el.className = 'x-panel-ghost ' + (cls ? cls : '');
  10995. if(this.header){
  10996. el.appendChild(this.el.dom.firstChild.cloneNode(true));
  10997. }
  10998. Ext.fly(el.appendChild(document.createElement('ul'))).setHeight(this.bwrap.getHeight());
  10999. el.style.width = this.el.dom.offsetWidth + 'px';;
  11000. if(!appendTo){
  11001. this.container.dom.appendChild(el);
  11002. }else{
  11003. Ext.getDom(appendTo).appendChild(el);
  11004. }
  11005. if(useShim !== false && this.el.useShim !== false){
  11006. var layer = new Ext.Layer({shadow:false, useDisplay:true, constrain:false}, el);
  11007. layer.show();
  11008. return layer;
  11009. }else{
  11010. return new Ext.Element(el);
  11011. }
  11012. },
  11013. // private
  11014. doAutoLoad : function(){
  11015. var u = this.body.getUpdater();
  11016. if(this.renderer){
  11017. u.setRenderer(this.renderer);
  11018. }
  11019. u.update(Ext.isObject(this.autoLoad) ? this.autoLoad : {url: this.autoLoad});
  11020. },
  11021. /**
  11022. * Retrieve a tool by id.
  11023. * @param {String} id
  11024. * @return {Object} tool
  11025. */
  11026. getTool : function(id) {
  11027. return this.tools[id];
  11028. }
  11029. /**
  11030. * @cfg {String} autoEl @hide
  11031. */
  11032. });
  11033. Ext.reg('panel', Ext.Panel);
  11034. /**
  11035. * @class Ext.Editor
  11036. * @extends Ext.Component
  11037. * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
  11038. * @constructor
  11039. * Create a new Editor
  11040. * @param {Object} config The config object
  11041. * @xtype editor
  11042. */
  11043. Ext.Editor = function(field, config){
  11044. if(field.field){
  11045. this.field = Ext.create(field.field, 'textfield');
  11046. config = Ext.apply({}, field); // copy so we don't disturb original config
  11047. delete config.field;
  11048. }else{
  11049. this.field = field;
  11050. }
  11051. Ext.Editor.superclass.constructor.call(this, config);
  11052. };
  11053. Ext.extend(Ext.Editor, Ext.Component, {
  11054. /**
  11055. * @cfg {Ext.form.Field} field
  11056. * The Field object (or descendant) or config object for field
  11057. */
  11058. /**
  11059. * @cfg {Boolean} allowBlur
  11060. * True to {@link #completeEdit complete the editing process} if in edit mode when the
  11061. * field is blurred. Defaults to <tt>true</tt>.
  11062. */
  11063. allowBlur: true,
  11064. /**
  11065. * @cfg {Boolean/String} autoSize
  11066. * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
  11067. * or "height" to adopt the height only, "none" to always use the field dimensions. (defaults to false)
  11068. */
  11069. /**
  11070. * @cfg {Boolean} revertInvalid
  11071. * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
  11072. * validation fails (defaults to true)
  11073. */
  11074. /**
  11075. * @cfg {Boolean} ignoreNoChange
  11076. * True to skip the edit completion process (no save, no events fired) if the user completes an edit and
  11077. * the value has not changed (defaults to false). Applies only to string values - edits for other data types
  11078. * will never be ignored.
  11079. */
  11080. /**
  11081. * @cfg {Boolean} hideEl
  11082. * False to keep the bound element visible while the editor is displayed (defaults to true)
  11083. */
  11084. /**
  11085. * @cfg {Mixed} value
  11086. * The data value of the underlying field (defaults to "")
  11087. */
  11088. value : "",
  11089. /**
  11090. * @cfg {String} alignment
  11091. * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "c-c?").
  11092. */
  11093. alignment: "c-c?",
  11094. /**
  11095. * @cfg {Array} offsets
  11096. * The offsets to use when aligning (see {@link Ext.Element#alignTo} for more details. Defaults to <tt>[0, 0]</tt>.
  11097. */
  11098. offsets: [0, 0],
  11099. /**
  11100. * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
  11101. * for bottom-right shadow (defaults to "frame")
  11102. */
  11103. shadow : "frame",
  11104. /**
  11105. * @cfg {Boolean} constrain True to constrain the editor to the viewport
  11106. */
  11107. constrain : false,
  11108. /**
  11109. * @cfg {Boolean} swallowKeys Handle the keydown/keypress events so they don't propagate (defaults to true)
  11110. */
  11111. swallowKeys : true,
  11112. /**
  11113. * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed. Defaults to <tt>true</tt>.
  11114. */
  11115. completeOnEnter : true,
  11116. /**
  11117. * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed. Defaults to <tt>true</tt>.
  11118. */
  11119. cancelOnEsc : true,
  11120. /**
  11121. * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
  11122. */
  11123. updateEl : false,
  11124. initComponent : function(){
  11125. Ext.Editor.superclass.initComponent.call(this);
  11126. this.addEvents(
  11127. /**
  11128. * @event beforestartedit
  11129. * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
  11130. * false from the handler of this event.
  11131. * @param {Editor} this
  11132. * @param {Ext.Element} boundEl The underlying element bound to this editor
  11133. * @param {Mixed} value The field value being set
  11134. */
  11135. "beforestartedit",
  11136. /**
  11137. * @event startedit
  11138. * Fires when this editor is displayed
  11139. * @param {Ext.Element} boundEl The underlying element bound to this editor
  11140. * @param {Mixed} value The starting field value
  11141. */
  11142. "startedit",
  11143. /**
  11144. * @event beforecomplete
  11145. * Fires after a change has been made to the field, but before the change is reflected in the underlying
  11146. * field. Saving the change to the field can be canceled by returning false from the handler of this event.
  11147. * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
  11148. * event will not fire since no edit actually occurred.
  11149. * @param {Editor} this
  11150. * @param {Mixed} value The current field value
  11151. * @param {Mixed} startValue The original field value
  11152. */
  11153. "beforecomplete",
  11154. /**
  11155. * @event complete
  11156. * Fires after editing is complete and any changed value has been written to the underlying field.
  11157. * @param {Editor} this
  11158. * @param {Mixed} value The current field value
  11159. * @param {Mixed} startValue The original field value
  11160. */
  11161. "complete",
  11162. /**
  11163. * @event canceledit
  11164. * Fires after editing has been canceled and the editor's value has been reset.
  11165. * @param {Editor} this
  11166. * @param {Mixed} value The user-entered field value that was discarded
  11167. * @param {Mixed} startValue The original field value that was set back into the editor after cancel
  11168. */
  11169. "canceledit",
  11170. /**
  11171. * @event specialkey
  11172. * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
  11173. * {@link Ext.EventObject#getKey} to determine which key was pressed.
  11174. * @param {Ext.form.Field} this
  11175. * @param {Ext.EventObject} e The event object
  11176. */
  11177. "specialkey"
  11178. );
  11179. },
  11180. // private
  11181. onRender : function(ct, position){
  11182. this.el = new Ext.Layer({
  11183. shadow: this.shadow,
  11184. cls: "x-editor",
  11185. parentEl : ct,
  11186. shim : this.shim,
  11187. shadowOffset: this.shadowOffset || 4,
  11188. id: this.id,
  11189. constrain: this.constrain
  11190. });
  11191. if(this.zIndex){
  11192. this.el.setZIndex(this.zIndex);
  11193. }
  11194. this.el.setStyle("overflow", Ext.isGecko ? "auto" : "hidden");
  11195. if(this.field.msgTarget != 'title'){
  11196. this.field.msgTarget = 'qtip';
  11197. }
  11198. this.field.inEditor = true;
  11199. this.mon(this.field, {
  11200. scope: this,
  11201. blur: this.onBlur,
  11202. specialkey: this.onSpecialKey
  11203. });
  11204. if(this.field.grow){
  11205. this.mon(this.field, "autosize", this.el.sync, this.el, {delay:1});
  11206. }
  11207. this.field.render(this.el).show();
  11208. this.field.getEl().dom.name = '';
  11209. if(this.swallowKeys){
  11210. this.field.el.swallowEvent([
  11211. 'keypress', // *** Opera
  11212. 'keydown' // *** all other browsers
  11213. ]);
  11214. }
  11215. },
  11216. // private
  11217. onSpecialKey : function(field, e){
  11218. var key = e.getKey(),
  11219. complete = this.completeOnEnter && key == e.ENTER,
  11220. cancel = this.cancelOnEsc && key == e.ESC;
  11221. if(complete || cancel){
  11222. e.stopEvent();
  11223. if(complete){
  11224. this.completeEdit();
  11225. }else{
  11226. this.cancelEdit();
  11227. }
  11228. if(field.triggerBlur){
  11229. field.triggerBlur();
  11230. }
  11231. }
  11232. this.fireEvent('specialkey', field, e);
  11233. },
  11234. /**
  11235. * Starts the editing process and shows the editor.
  11236. * @param {Mixed} el The element to edit
  11237. * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
  11238. * to the innerHTML of el.
  11239. */
  11240. startEdit : function(el, value){
  11241. if(this.editing){
  11242. this.completeEdit();
  11243. }
  11244. this.boundEl = Ext.get(el);
  11245. var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
  11246. if(!this.rendered){
  11247. this.render(this.parentEl || document.body);
  11248. }
  11249. if(this.fireEvent("beforestartedit", this, this.boundEl, v) !== false){
  11250. this.startValue = v;
  11251. this.field.reset();
  11252. this.field.setValue(v);
  11253. this.realign(true);
  11254. this.editing = true;
  11255. this.show();
  11256. }
  11257. },
  11258. // private
  11259. doAutoSize : function(){
  11260. if(this.autoSize){
  11261. var sz = this.boundEl.getSize(),
  11262. fs = this.field.getSize();
  11263. switch(this.autoSize){
  11264. case "width":
  11265. this.setSize(sz.width, fs.height);
  11266. break;
  11267. case "height":
  11268. this.setSize(fs.width, sz.height);
  11269. break;
  11270. case "none":
  11271. this.setSize(fs.width, fs.height);
  11272. break;
  11273. default:
  11274. this.setSize(sz.width, sz.height);
  11275. }
  11276. }
  11277. },
  11278. /**
  11279. * Sets the height and width of this editor.
  11280. * @param {Number} width The new width
  11281. * @param {Number} height The new height
  11282. */
  11283. setSize : function(w, h){
  11284. delete this.field.lastSize;
  11285. this.field.setSize(w, h);
  11286. if(this.el){
  11287. // IE7 in strict mode doesn't size properly.
  11288. if(Ext.isGecko2 || Ext.isOpera || (Ext.isIE7 && Ext.isStrict)){
  11289. // prevent layer scrollbars
  11290. this.el.setSize(w, h);
  11291. }
  11292. this.el.sync();
  11293. }
  11294. },
  11295. /**
  11296. * Realigns the editor to the bound field based on the current alignment config value.
  11297. * @param {Boolean} autoSize (optional) True to size the field to the dimensions of the bound element.
  11298. */
  11299. realign : function(autoSize){
  11300. if(autoSize === true){
  11301. this.doAutoSize();
  11302. }
  11303. this.el.alignTo(this.boundEl, this.alignment, this.offsets);
  11304. },
  11305. /**
  11306. * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
  11307. * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
  11308. */
  11309. completeEdit : function(remainVisible){
  11310. if(!this.editing){
  11311. return;
  11312. }
  11313. // Assert combo values first
  11314. if (this.field.assertValue) {
  11315. this.field.assertValue();
  11316. }
  11317. var v = this.getValue();
  11318. if(!this.field.isValid()){
  11319. if(this.revertInvalid !== false){
  11320. this.cancelEdit(remainVisible);
  11321. }
  11322. return;
  11323. }
  11324. if(String(v) === String(this.startValue) && this.ignoreNoChange){
  11325. this.hideEdit(remainVisible);
  11326. return;
  11327. }
  11328. if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
  11329. v = this.getValue();
  11330. if(this.updateEl && this.boundEl){
  11331. this.boundEl.update(v);
  11332. }
  11333. this.hideEdit(remainVisible);
  11334. this.fireEvent("complete", this, v, this.startValue);
  11335. }
  11336. },
  11337. // private
  11338. onShow : function(){
  11339. this.el.show();
  11340. if(this.hideEl !== false){
  11341. this.boundEl.hide();
  11342. }
  11343. this.field.show().focus(false, true);
  11344. this.fireEvent("startedit", this.boundEl, this.startValue);
  11345. },
  11346. /**
  11347. * Cancels the editing process and hides the editor without persisting any changes. The field value will be
  11348. * reverted to the original starting value.
  11349. * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
  11350. * cancel (defaults to false)
  11351. */
  11352. cancelEdit : function(remainVisible){
  11353. if(this.editing){
  11354. var v = this.getValue();
  11355. this.setValue(this.startValue);
  11356. this.hideEdit(remainVisible);
  11357. this.fireEvent("canceledit", this, v, this.startValue);
  11358. }
  11359. },
  11360. // private
  11361. hideEdit: function(remainVisible){
  11362. if(remainVisible !== true){
  11363. this.editing = false;
  11364. this.hide();
  11365. }
  11366. },
  11367. // private
  11368. onBlur : function(){
  11369. // selectSameEditor flag allows the same editor to be started without onBlur firing on itself
  11370. if(this.allowBlur === true && this.editing && this.selectSameEditor !== true){
  11371. this.completeEdit();
  11372. }
  11373. },
  11374. // private
  11375. onHide : function(){
  11376. if(this.editing){
  11377. this.completeEdit();
  11378. return;
  11379. }
  11380. this.field.blur();
  11381. if(this.field.collapse){
  11382. this.field.collapse();
  11383. }
  11384. this.el.hide();
  11385. if(this.hideEl !== false){
  11386. this.boundEl.show();
  11387. }
  11388. },
  11389. /**
  11390. * Sets the data value of the editor
  11391. * @param {Mixed} value Any valid value supported by the underlying field
  11392. */
  11393. setValue : function(v){
  11394. this.field.setValue(v);
  11395. },
  11396. /**
  11397. * Gets the data value of the editor
  11398. * @return {Mixed} The data value
  11399. */
  11400. getValue : function(){
  11401. return this.field.getValue();
  11402. },
  11403. beforeDestroy : function(){
  11404. Ext.destroyMembers(this, 'field');
  11405. delete this.parentEl;
  11406. delete this.boundEl;
  11407. }
  11408. });
  11409. Ext.reg('editor', Ext.Editor);
  11410. /**
  11411. * @class Ext.ColorPalette
  11412. * @extends Ext.Component
  11413. * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
  11414. * Here's an example of typical usage:
  11415. * <pre><code>
  11416. var cp = new Ext.ColorPalette({value:'993300'}); // initial selected color
  11417. cp.render('my-div');
  11418. cp.on('select', function(palette, selColor){
  11419. // do something with selColor
  11420. });
  11421. </code></pre>
  11422. * @constructor
  11423. * Create a new ColorPalette
  11424. * @param {Object} config The config object
  11425. * @xtype colorpalette
  11426. */
  11427. Ext.ColorPalette = Ext.extend(Ext.Component, {
  11428. /**
  11429. * @cfg {String} tpl An existing XTemplate instance to be used in place of the default template for rendering the component.
  11430. */
  11431. /**
  11432. * @cfg {String} itemCls
  11433. * The CSS class to apply to the containing element (defaults to 'x-color-palette')
  11434. */
  11435. itemCls : 'x-color-palette',
  11436. /**
  11437. * @cfg {String} value
  11438. * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
  11439. * the hex codes are case-sensitive.
  11440. */
  11441. value : null,
  11442. /**
  11443. * @cfg {String} clickEvent
  11444. * The DOM event that will cause a color to be selected. This can be any valid event name (dblclick, contextmenu).
  11445. * Defaults to <tt>'click'</tt>.
  11446. */
  11447. clickEvent :'click',
  11448. // private
  11449. ctype : 'Ext.ColorPalette',
  11450. /**
  11451. * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the {@link #select} event
  11452. */
  11453. allowReselect : false,
  11454. /**
  11455. * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
  11456. * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
  11457. * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
  11458. * of colors with the width setting until the box is symmetrical.</p>
  11459. * <p>You can override individual colors if needed:</p>
  11460. * <pre><code>
  11461. var cp = new Ext.ColorPalette();
  11462. cp.colors[0] = 'FF0000'; // change the first box to red
  11463. </code></pre>
  11464. Or you can provide a custom array of your own for complete control:
  11465. <pre><code>
  11466. var cp = new Ext.ColorPalette();
  11467. cp.colors = ['000000', '993300', '333300'];
  11468. </code></pre>
  11469. * @type Array
  11470. */
  11471. colors : [
  11472. '000000', '993300', '333300', '003300', '003366', '000080', '333399', '333333',
  11473. '800000', 'FF6600', '808000', '008000', '008080', '0000FF', '666699', '808080',
  11474. 'FF0000', 'FF9900', '99CC00', '339966', '33CCCC', '3366FF', '800080', '969696',
  11475. 'FF00FF', 'FFCC00', 'FFFF00', '00FF00', '00FFFF', '00CCFF', '993366', 'C0C0C0',
  11476. 'FF99CC', 'FFCC99', 'FFFF99', 'CCFFCC', 'CCFFFF', '99CCFF', 'CC99FF', 'FFFFFF'
  11477. ],
  11478. /**
  11479. * @cfg {Function} handler
  11480. * Optional. A function that will handle the select event of this palette.
  11481. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  11482. * <li><code>palette</code> : ColorPalette<div class="sub-desc">The {@link #palette Ext.ColorPalette}.</div></li>
  11483. * <li><code>color</code> : String<div class="sub-desc">The 6-digit color hex code (without the # symbol).</div></li>
  11484. * </ul></div>
  11485. */
  11486. /**
  11487. * @cfg {Object} scope
  11488. * The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>
  11489. * function will be called. Defaults to this ColorPalette instance.
  11490. */
  11491. // private
  11492. initComponent : function(){
  11493. Ext.ColorPalette.superclass.initComponent.call(this);
  11494. this.addEvents(
  11495. /**
  11496. * @event select
  11497. * Fires when a color is selected
  11498. * @param {ColorPalette} this
  11499. * @param {String} color The 6-digit color hex code (without the # symbol)
  11500. */
  11501. 'select'
  11502. );
  11503. if(this.handler){
  11504. this.on('select', this.handler, this.scope, true);
  11505. }
  11506. },
  11507. // private
  11508. onRender : function(container, position){
  11509. this.autoEl = {
  11510. tag: 'div',
  11511. cls: this.itemCls
  11512. };
  11513. Ext.ColorPalette.superclass.onRender.call(this, container, position);
  11514. var t = this.tpl || new Ext.XTemplate(
  11515. '<tpl for="."><a href="#" class="color-{.}" hidefocus="on"><em><span style="background:#{.}" unselectable="on">&#160;</span></em></a></tpl>'
  11516. );
  11517. t.overwrite(this.el, this.colors);
  11518. this.mon(this.el, this.clickEvent, this.handleClick, this, {delegate: 'a'});
  11519. if(this.clickEvent != 'click'){
  11520. this.mon(this.el, 'click', Ext.emptyFn, this, {delegate: 'a', preventDefault: true});
  11521. }
  11522. },
  11523. // private
  11524. afterRender : function(){
  11525. Ext.ColorPalette.superclass.afterRender.call(this);
  11526. if(this.value){
  11527. var s = this.value;
  11528. this.value = null;
  11529. this.select(s, true);
  11530. }
  11531. },
  11532. // private
  11533. handleClick : function(e, t){
  11534. e.preventDefault();
  11535. if(!this.disabled){
  11536. var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
  11537. this.select(c.toUpperCase());
  11538. }
  11539. },
  11540. /**
  11541. * Selects the specified color in the palette (fires the {@link #select} event)
  11542. * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
  11543. * @param {Boolean} suppressEvent (optional) True to stop the select event from firing. Defaults to <tt>false</tt>.
  11544. */
  11545. select : function(color, suppressEvent){
  11546. color = color.replace('#', '');
  11547. if(color != this.value || this.allowReselect){
  11548. var el = this.el;
  11549. if(this.value){
  11550. el.child('a.color-'+this.value).removeClass('x-color-palette-sel');
  11551. }
  11552. el.child('a.color-'+color).addClass('x-color-palette-sel');
  11553. this.value = color;
  11554. if(suppressEvent !== true){
  11555. this.fireEvent('select', this, color);
  11556. }
  11557. }
  11558. }
  11559. /**
  11560. * @cfg {String} autoEl @hide
  11561. */
  11562. });
  11563. Ext.reg('colorpalette', Ext.ColorPalette);/**
  11564. * @class Ext.DatePicker
  11565. * @extends Ext.Component
  11566. * <p>A popup date picker. This class is used by the {@link Ext.form.DateField DateField} class
  11567. * to allow browsing and selection of valid dates.</p>
  11568. * <p>All the string values documented below may be overridden by including an Ext locale file in
  11569. * your page.</p>
  11570. * @constructor
  11571. * Create a new DatePicker
  11572. * @param {Object} config The config object
  11573. * @xtype datepicker
  11574. */
  11575. Ext.DatePicker = Ext.extend(Ext.BoxComponent, {
  11576. /**
  11577. * @cfg {String} todayText
  11578. * The text to display on the button that selects the current date (defaults to <code>'Today'</code>)
  11579. */
  11580. todayText : 'Today',
  11581. /**
  11582. * @cfg {String} okText
  11583. * The text to display on the ok button (defaults to <code>'&#160;OK&#160;'</code> to give the user extra clicking room)
  11584. */
  11585. okText : '&#160;OK&#160;',
  11586. /**
  11587. * @cfg {String} cancelText
  11588. * The text to display on the cancel button (defaults to <code>'Cancel'</code>)
  11589. */
  11590. cancelText : 'Cancel',
  11591. /**
  11592. * @cfg {Function} handler
  11593. * Optional. A function that will handle the select event of this picker.
  11594. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  11595. * <li><code>picker</code> : DatePicker<div class="sub-desc">This DatePicker.</div></li>
  11596. * <li><code>date</code> : Date<div class="sub-desc">The selected date.</div></li>
  11597. * </ul></div>
  11598. */
  11599. /**
  11600. * @cfg {Object} scope
  11601. * The scope (<code><b>this</b></code> reference) in which the <code>{@link #handler}</code>
  11602. * function will be called. Defaults to this DatePicker instance.
  11603. */
  11604. /**
  11605. * @cfg {String} todayTip
  11606. * A string used to format the message for displaying in a tooltip over the button that
  11607. * selects the current date. Defaults to <code>'{0} (Spacebar)'</code> where
  11608. * the <code>{0}</code> token is replaced by today's date.
  11609. */
  11610. todayTip : '{0} (Spacebar)',
  11611. /**
  11612. * @cfg {String} minText
  11613. * The error text to display if the minDate validation fails (defaults to <code>'This date is before the minimum date'</code>)
  11614. */
  11615. minText : 'This date is before the minimum date',
  11616. /**
  11617. * @cfg {String} maxText
  11618. * The error text to display if the maxDate validation fails (defaults to <code>'This date is after the maximum date'</code>)
  11619. */
  11620. maxText : 'This date is after the maximum date',
  11621. /**
  11622. * @cfg {String} format
  11623. * The default date format string which can be overriden for localization support. The format must be
  11624. * valid according to {@link Date#parseDate} (defaults to <code>'m/d/y'</code>).
  11625. */
  11626. format : 'm/d/y',
  11627. /**
  11628. * @cfg {String} disabledDaysText
  11629. * The tooltip to display when the date falls on a disabled day (defaults to <code>'Disabled'</code>)
  11630. */
  11631. disabledDaysText : 'Disabled',
  11632. /**
  11633. * @cfg {String} disabledDatesText
  11634. * The tooltip text to display when the date falls on a disabled date (defaults to <code>'Disabled'</code>)
  11635. */
  11636. disabledDatesText : 'Disabled',
  11637. /**
  11638. * @cfg {Array} monthNames
  11639. * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
  11640. */
  11641. monthNames : Date.monthNames,
  11642. /**
  11643. * @cfg {Array} dayNames
  11644. * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
  11645. */
  11646. dayNames : Date.dayNames,
  11647. /**
  11648. * @cfg {String} nextText
  11649. * The next month navigation button tooltip (defaults to <code>'Next Month (Control+Right)'</code>)
  11650. */
  11651. nextText : 'Next Month (Control+Right)',
  11652. /**
  11653. * @cfg {String} prevText
  11654. * The previous month navigation button tooltip (defaults to <code>'Previous Month (Control+Left)'</code>)
  11655. */
  11656. prevText : 'Previous Month (Control+Left)',
  11657. /**
  11658. * @cfg {String} monthYearText
  11659. * The header month selector tooltip (defaults to <code>'Choose a month (Control+Up/Down to move years)'</code>)
  11660. */
  11661. monthYearText : 'Choose a month (Control+Up/Down to move years)',
  11662. /**
  11663. * @cfg {Number} startDay
  11664. * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
  11665. */
  11666. startDay : 0,
  11667. /**
  11668. * @cfg {Boolean} showToday
  11669. * False to hide the footer area containing the Today button and disable the keyboard handler for spacebar
  11670. * that selects the current date (defaults to <code>true</code>).
  11671. */
  11672. showToday : true,
  11673. /**
  11674. * @cfg {Date} minDate
  11675. * Minimum allowable date (JavaScript date object, defaults to null)
  11676. */
  11677. /**
  11678. * @cfg {Date} maxDate
  11679. * Maximum allowable date (JavaScript date object, defaults to null)
  11680. */
  11681. /**
  11682. * @cfg {Array} disabledDays
  11683. * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
  11684. */
  11685. /**
  11686. * @cfg {RegExp} disabledDatesRE
  11687. * JavaScript regular expression used to disable a pattern of dates (defaults to null). The {@link #disabledDates}
  11688. * config will generate this regex internally, but if you specify disabledDatesRE it will take precedence over the
  11689. * disabledDates value.
  11690. */
  11691. /**
  11692. * @cfg {Array} disabledDates
  11693. * An array of 'dates' to disable, as strings. These strings will be used to build a dynamic regular
  11694. * expression so they are very powerful. Some examples:
  11695. * <ul>
  11696. * <li>['03/08/2003', '09/16/2003'] would disable those exact dates</li>
  11697. * <li>['03/08', '09/16'] would disable those days for every year</li>
  11698. * <li>['^03/08'] would only match the beginning (useful if you are using short years)</li>
  11699. * <li>['03/../2006'] would disable every day in March 2006</li>
  11700. * <li>['^03'] would disable every day in every March</li>
  11701. * </ul>
  11702. * Note that the format of the dates included in the array should exactly match the {@link #format} config.
  11703. * In order to support regular expressions, if you are using a date format that has '.' in it, you will have to
  11704. * escape the dot when restricting dates. For example: ['03\\.08\\.03'].
  11705. */
  11706. // private
  11707. // Set by other components to stop the picker focus being updated when the value changes.
  11708. focusOnSelect: true,
  11709. // default value used to initialise each date in the DatePicker
  11710. // (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
  11711. initHour: 12, // 24-hour format
  11712. // private
  11713. initComponent : function(){
  11714. Ext.DatePicker.superclass.initComponent.call(this);
  11715. this.value = this.value ?
  11716. this.value.clearTime(true) : new Date().clearTime();
  11717. this.addEvents(
  11718. /**
  11719. * @event select
  11720. * Fires when a date is selected
  11721. * @param {DatePicker} this DatePicker
  11722. * @param {Date} date The selected date
  11723. */
  11724. 'select'
  11725. );
  11726. if(this.handler){
  11727. this.on('select', this.handler, this.scope || this);
  11728. }
  11729. this.initDisabledDays();
  11730. },
  11731. // private
  11732. initDisabledDays : function(){
  11733. if(!this.disabledDatesRE && this.disabledDates){
  11734. var dd = this.disabledDates,
  11735. len = dd.length - 1,
  11736. re = '(?:';
  11737. Ext.each(dd, function(d, i){
  11738. re += Ext.isDate(d) ? '^' + Ext.escapeRe(d.dateFormat(this.format)) + '$' : dd[i];
  11739. if(i != len){
  11740. re += '|';
  11741. }
  11742. }, this);
  11743. this.disabledDatesRE = new RegExp(re + ')');
  11744. }
  11745. },
  11746. /**
  11747. * Replaces any existing disabled dates with new values and refreshes the DatePicker.
  11748. * @param {Array/RegExp} disabledDates An array of date strings (see the {@link #disabledDates} config
  11749. * for details on supported values), or a JavaScript regular expression used to disable a pattern of dates.
  11750. */
  11751. setDisabledDates : function(dd){
  11752. if(Ext.isArray(dd)){
  11753. this.disabledDates = dd;
  11754. this.disabledDatesRE = null;
  11755. }else{
  11756. this.disabledDatesRE = dd;
  11757. }
  11758. this.initDisabledDays();
  11759. this.update(this.value, true);
  11760. },
  11761. /**
  11762. * Replaces any existing disabled days (by index, 0-6) with new values and refreshes the DatePicker.
  11763. * @param {Array} disabledDays An array of disabled day indexes. See the {@link #disabledDays} config
  11764. * for details on supported values.
  11765. */
  11766. setDisabledDays : function(dd){
  11767. this.disabledDays = dd;
  11768. this.update(this.value, true);
  11769. },
  11770. /**
  11771. * Replaces any existing {@link #minDate} with the new value and refreshes the DatePicker.
  11772. * @param {Date} value The minimum date that can be selected
  11773. */
  11774. setMinDate : function(dt){
  11775. this.minDate = dt;
  11776. this.update(this.value, true);
  11777. },
  11778. /**
  11779. * Replaces any existing {@link #maxDate} with the new value and refreshes the DatePicker.
  11780. * @param {Date} value The maximum date that can be selected
  11781. */
  11782. setMaxDate : function(dt){
  11783. this.maxDate = dt;
  11784. this.update(this.value, true);
  11785. },
  11786. /**
  11787. * Sets the value of the date field
  11788. * @param {Date} value The date to set
  11789. */
  11790. setValue : function(value){
  11791. this.value = value.clearTime(true);
  11792. this.update(this.value);
  11793. },
  11794. /**
  11795. * Gets the current selected value of the date field
  11796. * @return {Date} The selected date
  11797. */
  11798. getValue : function(){
  11799. return this.value;
  11800. },
  11801. // private
  11802. focus : function(){
  11803. this.update(this.activeDate);
  11804. },
  11805. // private
  11806. onEnable: function(initial){
  11807. Ext.DatePicker.superclass.onEnable.call(this);
  11808. this.doDisabled(false);
  11809. this.update(initial ? this.value : this.activeDate);
  11810. if(Ext.isIE){
  11811. this.el.repaint();
  11812. }
  11813. },
  11814. // private
  11815. onDisable : function(){
  11816. Ext.DatePicker.superclass.onDisable.call(this);
  11817. this.doDisabled(true);
  11818. if(Ext.isIE && !Ext.isIE8){
  11819. /* Really strange problem in IE6/7, when disabled, have to explicitly
  11820. * repaint each of the nodes to get them to display correctly, simply
  11821. * calling repaint on the main element doesn't appear to be enough.
  11822. */
  11823. Ext.each([].concat(this.textNodes, this.el.query('th span')), function(el){
  11824. Ext.fly(el).repaint();
  11825. });
  11826. }
  11827. },
  11828. // private
  11829. doDisabled : function(disabled){
  11830. this.keyNav.setDisabled(disabled);
  11831. this.prevRepeater.setDisabled(disabled);
  11832. this.nextRepeater.setDisabled(disabled);
  11833. if(this.showToday){
  11834. this.todayKeyListener.setDisabled(disabled);
  11835. this.todayBtn.setDisabled(disabled);
  11836. }
  11837. },
  11838. // private
  11839. onRender : function(container, position){
  11840. var m = [
  11841. '<table cellspacing="0">',
  11842. '<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>',
  11843. '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'],
  11844. dn = this.dayNames,
  11845. i;
  11846. for(i = 0; i < 7; i++){
  11847. var d = this.startDay+i;
  11848. if(d > 6){
  11849. d = d-7;
  11850. }
  11851. m.push('<th><span>', dn[d].substr(0,1), '</span></th>');
  11852. }
  11853. m[m.length] = '</tr></thead><tbody><tr>';
  11854. for(i = 0; i < 42; i++) {
  11855. if(i % 7 === 0 && i !== 0){
  11856. m[m.length] = '</tr><tr>';
  11857. }
  11858. m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
  11859. }
  11860. m.push('</tr></tbody></table></td></tr>',
  11861. this.showToday ? '<tr><td colspan="3" class="x-date-bottom" align="center"></td></tr>' : '',
  11862. '</table><div class="x-date-mp"></div>');
  11863. var el = document.createElement('div');
  11864. el.className = 'x-date-picker';
  11865. el.innerHTML = m.join('');
  11866. container.dom.insertBefore(el, position);
  11867. this.el = Ext.get(el);
  11868. this.eventEl = Ext.get(el.firstChild);
  11869. this.prevRepeater = new Ext.util.ClickRepeater(this.el.child('td.x-date-left a'), {
  11870. handler: this.showPrevMonth,
  11871. scope: this,
  11872. preventDefault:true,
  11873. stopDefault:true
  11874. });
  11875. this.nextRepeater = new Ext.util.ClickRepeater(this.el.child('td.x-date-right a'), {
  11876. handler: this.showNextMonth,
  11877. scope: this,
  11878. preventDefault:true,
  11879. stopDefault:true
  11880. });
  11881. this.monthPicker = this.el.down('div.x-date-mp');
  11882. this.monthPicker.enableDisplayMode('block');
  11883. this.keyNav = new Ext.KeyNav(this.eventEl, {
  11884. 'left' : function(e){
  11885. if(e.ctrlKey){
  11886. this.showPrevMonth();
  11887. }else{
  11888. this.update(this.activeDate.add('d', -1));
  11889. }
  11890. },
  11891. 'right' : function(e){
  11892. if(e.ctrlKey){
  11893. this.showNextMonth();
  11894. }else{
  11895. this.update(this.activeDate.add('d', 1));
  11896. }
  11897. },
  11898. 'up' : function(e){
  11899. if(e.ctrlKey){
  11900. this.showNextYear();
  11901. }else{
  11902. this.update(this.activeDate.add('d', -7));
  11903. }
  11904. },
  11905. 'down' : function(e){
  11906. if(e.ctrlKey){
  11907. this.showPrevYear();
  11908. }else{
  11909. this.update(this.activeDate.add('d', 7));
  11910. }
  11911. },
  11912. 'pageUp' : function(e){
  11913. this.showNextMonth();
  11914. },
  11915. 'pageDown' : function(e){
  11916. this.showPrevMonth();
  11917. },
  11918. 'enter' : function(e){
  11919. e.stopPropagation();
  11920. return true;
  11921. },
  11922. scope : this
  11923. });
  11924. this.el.unselectable();
  11925. this.cells = this.el.select('table.x-date-inner tbody td');
  11926. this.textNodes = this.el.query('table.x-date-inner tbody span');
  11927. this.mbtn = new Ext.Button({
  11928. text: '&#160;',
  11929. tooltip: this.monthYearText,
  11930. renderTo: this.el.child('td.x-date-middle', true)
  11931. });
  11932. this.mbtn.el.child('em').addClass('x-btn-arrow');
  11933. if(this.showToday){
  11934. this.todayKeyListener = this.eventEl.addKeyListener(Ext.EventObject.SPACE, this.selectToday, this);
  11935. var today = (new Date()).dateFormat(this.format);
  11936. this.todayBtn = new Ext.Button({
  11937. renderTo: this.el.child('td.x-date-bottom', true),
  11938. text: String.format(this.todayText, today),
  11939. tooltip: String.format(this.todayTip, today),
  11940. handler: this.selectToday,
  11941. scope: this
  11942. });
  11943. }
  11944. this.mon(this.eventEl, 'mousewheel', this.handleMouseWheel, this);
  11945. this.mon(this.eventEl, 'click', this.handleDateClick, this, {delegate: 'a.x-date-date'});
  11946. this.mon(this.mbtn, 'click', this.showMonthPicker, this);
  11947. this.onEnable(true);
  11948. },
  11949. // private
  11950. createMonthPicker : function(){
  11951. if(!this.monthPicker.dom.firstChild){
  11952. var buf = ['<table border="0" cellspacing="0">'];
  11953. for(var i = 0; i < 6; i++){
  11954. buf.push(
  11955. '<tr><td class="x-date-mp-month"><a href="#">', Date.getShortMonthName(i), '</a></td>',
  11956. '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', Date.getShortMonthName(i + 6), '</a></td>',
  11957. i === 0 ?
  11958. '<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>' :
  11959. '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
  11960. );
  11961. }
  11962. buf.push(
  11963. '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
  11964. this.okText,
  11965. '</button><button type="button" class="x-date-mp-cancel">',
  11966. this.cancelText,
  11967. '</button></td></tr>',
  11968. '</table>'
  11969. );
  11970. this.monthPicker.update(buf.join(''));
  11971. this.mon(this.monthPicker, 'click', this.onMonthClick, this);
  11972. this.mon(this.monthPicker, 'dblclick', this.onMonthDblClick, this);
  11973. this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
  11974. this.mpYears = this.monthPicker.select('td.x-date-mp-year');
  11975. this.mpMonths.each(function(m, a, i){
  11976. i += 1;
  11977. if((i%2) === 0){
  11978. m.dom.xmonth = 5 + Math.round(i * 0.5);
  11979. }else{
  11980. m.dom.xmonth = Math.round((i-1) * 0.5);
  11981. }
  11982. });
  11983. }
  11984. },
  11985. // private
  11986. showMonthPicker : function(){
  11987. if(!this.disabled){
  11988. this.createMonthPicker();
  11989. var size = this.el.getSize();
  11990. this.monthPicker.setSize(size);
  11991. this.monthPicker.child('table').setSize(size);
  11992. this.mpSelMonth = (this.activeDate || this.value).getMonth();
  11993. this.updateMPMonth(this.mpSelMonth);
  11994. this.mpSelYear = (this.activeDate || this.value).getFullYear();
  11995. this.updateMPYear(this.mpSelYear);
  11996. this.monthPicker.slideIn('t', {duration:0.2});
  11997. }
  11998. },
  11999. // private
  12000. updateMPYear : function(y){
  12001. this.mpyear = y;
  12002. var ys = this.mpYears.elements;
  12003. for(var i = 1; i <= 10; i++){
  12004. var td = ys[i-1], y2;
  12005. if((i%2) === 0){
  12006. y2 = y + Math.round(i * 0.5);
  12007. td.firstChild.innerHTML = y2;
  12008. td.xyear = y2;
  12009. }else{
  12010. y2 = y - (5-Math.round(i * 0.5));
  12011. td.firstChild.innerHTML = y2;
  12012. td.xyear = y2;
  12013. }
  12014. this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
  12015. }
  12016. },
  12017. // private
  12018. updateMPMonth : function(sm){
  12019. this.mpMonths.each(function(m, a, i){
  12020. m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
  12021. });
  12022. },
  12023. // private
  12024. selectMPMonth : function(m){
  12025. },
  12026. // private
  12027. onMonthClick : function(e, t){
  12028. e.stopEvent();
  12029. var el = new Ext.Element(t), pn;
  12030. if(el.is('button.x-date-mp-cancel')){
  12031. this.hideMonthPicker();
  12032. }
  12033. else if(el.is('button.x-date-mp-ok')){
  12034. var d = new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate());
  12035. if(d.getMonth() != this.mpSelMonth){
  12036. // 'fix' the JS rolling date conversion if needed
  12037. d = new Date(this.mpSelYear, this.mpSelMonth, 1).getLastDateOfMonth();
  12038. }
  12039. this.update(d);
  12040. this.hideMonthPicker();
  12041. }
  12042. else if((pn = el.up('td.x-date-mp-month', 2))){
  12043. this.mpMonths.removeClass('x-date-mp-sel');
  12044. pn.addClass('x-date-mp-sel');
  12045. this.mpSelMonth = pn.dom.xmonth;
  12046. }
  12047. else if((pn = el.up('td.x-date-mp-year', 2))){
  12048. this.mpYears.removeClass('x-date-mp-sel');
  12049. pn.addClass('x-date-mp-sel');
  12050. this.mpSelYear = pn.dom.xyear;
  12051. }
  12052. else if(el.is('a.x-date-mp-prev')){
  12053. this.updateMPYear(this.mpyear-10);
  12054. }
  12055. else if(el.is('a.x-date-mp-next')){
  12056. this.updateMPYear(this.mpyear+10);
  12057. }
  12058. },
  12059. // private
  12060. onMonthDblClick : function(e, t){
  12061. e.stopEvent();
  12062. var el = new Ext.Element(t), pn;
  12063. if((pn = el.up('td.x-date-mp-month', 2))){
  12064. this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
  12065. this.hideMonthPicker();
  12066. }
  12067. else if((pn = el.up('td.x-date-mp-year', 2))){
  12068. this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
  12069. this.hideMonthPicker();
  12070. }
  12071. },
  12072. // private
  12073. hideMonthPicker : function(disableAnim){
  12074. if(this.monthPicker){
  12075. if(disableAnim === true){
  12076. this.monthPicker.hide();
  12077. }else{
  12078. this.monthPicker.slideOut('t', {duration:0.2});
  12079. }
  12080. }
  12081. },
  12082. // private
  12083. showPrevMonth : function(e){
  12084. this.update(this.activeDate.add('mo', -1));
  12085. },
  12086. // private
  12087. showNextMonth : function(e){
  12088. this.update(this.activeDate.add('mo', 1));
  12089. },
  12090. // private
  12091. showPrevYear : function(){
  12092. this.update(this.activeDate.add('y', -1));
  12093. },
  12094. // private
  12095. showNextYear : function(){
  12096. this.update(this.activeDate.add('y', 1));
  12097. },
  12098. // private
  12099. handleMouseWheel : function(e){
  12100. e.stopEvent();
  12101. if(!this.disabled){
  12102. var delta = e.getWheelDelta();
  12103. if(delta > 0){
  12104. this.showPrevMonth();
  12105. } else if(delta < 0){
  12106. this.showNextMonth();
  12107. }
  12108. }
  12109. },
  12110. // private
  12111. handleDateClick : function(e, t){
  12112. e.stopEvent();
  12113. if(!this.disabled && t.dateValue && !Ext.fly(t.parentNode).hasClass('x-date-disabled')){
  12114. this.cancelFocus = this.focusOnSelect === false;
  12115. this.setValue(new Date(t.dateValue));
  12116. delete this.cancelFocus;
  12117. this.fireEvent('select', this, this.value);
  12118. }
  12119. },
  12120. // private
  12121. selectToday : function(){
  12122. if(this.todayBtn && !this.todayBtn.disabled){
  12123. this.setValue(new Date().clearTime());
  12124. this.fireEvent('select', this, this.value);
  12125. }
  12126. },
  12127. // private
  12128. update : function(date, forceRefresh){
  12129. if(this.rendered){
  12130. var vd = this.activeDate, vis = this.isVisible();
  12131. this.activeDate = date;
  12132. if(!forceRefresh && vd && this.el){
  12133. var t = date.getTime();
  12134. if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
  12135. this.cells.removeClass('x-date-selected');
  12136. this.cells.each(function(c){
  12137. if(c.dom.firstChild.dateValue == t){
  12138. c.addClass('x-date-selected');
  12139. if(vis && !this.cancelFocus){
  12140. Ext.fly(c.dom.firstChild).focus(50);
  12141. }
  12142. return false;
  12143. }
  12144. }, this);
  12145. return;
  12146. }
  12147. }
  12148. var days = date.getDaysInMonth(),
  12149. firstOfMonth = date.getFirstDateOfMonth(),
  12150. startingPos = firstOfMonth.getDay()-this.startDay;
  12151. if(startingPos < 0){
  12152. startingPos += 7;
  12153. }
  12154. days += startingPos;
  12155. var pm = date.add('mo', -1),
  12156. prevStart = pm.getDaysInMonth()-startingPos,
  12157. cells = this.cells.elements,
  12158. textEls = this.textNodes,
  12159. // convert everything to numbers so it's fast
  12160. d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart, this.initHour)),
  12161. today = new Date().clearTime().getTime(),
  12162. sel = date.clearTime(true).getTime(),
  12163. min = this.minDate ? this.minDate.clearTime(true) : Number.NEGATIVE_INFINITY,
  12164. max = this.maxDate ? this.maxDate.clearTime(true) : Number.POSITIVE_INFINITY,
  12165. ddMatch = this.disabledDatesRE,
  12166. ddText = this.disabledDatesText,
  12167. ddays = this.disabledDays ? this.disabledDays.join('') : false,
  12168. ddaysText = this.disabledDaysText,
  12169. format = this.format;
  12170. if(this.showToday){
  12171. var td = new Date().clearTime(),
  12172. disable = (td < min || td > max ||
  12173. (ddMatch && format && ddMatch.test(td.dateFormat(format))) ||
  12174. (ddays && ddays.indexOf(td.getDay()) != -1));
  12175. if(!this.disabled){
  12176. this.todayBtn.setDisabled(disable);
  12177. this.todayKeyListener[disable ? 'disable' : 'enable']();
  12178. }
  12179. }
  12180. var setCellClass = function(cal, cell){
  12181. cell.title = '';
  12182. var t = d.clearTime(true).getTime();
  12183. cell.firstChild.dateValue = t;
  12184. if(t == today){
  12185. cell.className += ' x-date-today';
  12186. cell.title = cal.todayText;
  12187. }
  12188. if(t == sel){
  12189. cell.className += ' x-date-selected';
  12190. if(vis){
  12191. Ext.fly(cell.firstChild).focus(50);
  12192. }
  12193. }
  12194. // disabling
  12195. if(t < min) {
  12196. cell.className = ' x-date-disabled';
  12197. cell.title = cal.minText;
  12198. return;
  12199. }
  12200. if(t > max) {
  12201. cell.className = ' x-date-disabled';
  12202. cell.title = cal.maxText;
  12203. return;
  12204. }
  12205. if(ddays){
  12206. if(ddays.indexOf(d.getDay()) != -1){
  12207. cell.title = ddaysText;
  12208. cell.className = ' x-date-disabled';
  12209. }
  12210. }
  12211. if(ddMatch && format){
  12212. var fvalue = d.dateFormat(format);
  12213. if(ddMatch.test(fvalue)){
  12214. cell.title = ddText.replace('%0', fvalue);
  12215. cell.className = ' x-date-disabled';
  12216. }
  12217. }
  12218. };
  12219. var i = 0;
  12220. for(; i < startingPos; i++) {
  12221. textEls[i].innerHTML = (++prevStart);
  12222. d.setDate(d.getDate()+1);
  12223. cells[i].className = 'x-date-prevday';
  12224. setCellClass(this, cells[i]);
  12225. }
  12226. for(; i < days; i++){
  12227. var intDay = i - startingPos + 1;
  12228. textEls[i].innerHTML = (intDay);
  12229. d.setDate(d.getDate()+1);
  12230. cells[i].className = 'x-date-active';
  12231. setCellClass(this, cells[i]);
  12232. }
  12233. var extraDays = 0;
  12234. for(; i < 42; i++) {
  12235. textEls[i].innerHTML = (++extraDays);
  12236. d.setDate(d.getDate()+1);
  12237. cells[i].className = 'x-date-nextday';
  12238. setCellClass(this, cells[i]);
  12239. }
  12240. this.mbtn.setText(this.monthNames[date.getMonth()] + ' ' + date.getFullYear());
  12241. if(!this.internalRender){
  12242. var main = this.el.dom.firstChild,
  12243. w = main.offsetWidth;
  12244. this.el.setWidth(w + this.el.getBorderWidth('lr'));
  12245. Ext.fly(main).setWidth(w);
  12246. this.internalRender = true;
  12247. // opera does not respect the auto grow header center column
  12248. // then, after it gets a width opera refuses to recalculate
  12249. // without a second pass
  12250. if(Ext.isOpera && !this.secondPass){
  12251. main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + 'px';
  12252. this.secondPass = true;
  12253. this.update.defer(10, this, [date]);
  12254. }
  12255. }
  12256. }
  12257. },
  12258. // private
  12259. beforeDestroy : function() {
  12260. if(this.rendered){
  12261. Ext.destroy(
  12262. this.keyNav,
  12263. this.monthPicker,
  12264. this.eventEl,
  12265. this.mbtn,
  12266. this.nextRepeater,
  12267. this.prevRepeater,
  12268. this.cells.el,
  12269. this.todayBtn
  12270. );
  12271. delete this.textNodes;
  12272. delete this.cells.elements;
  12273. }
  12274. }
  12275. /**
  12276. * @cfg {String} autoEl @hide
  12277. */
  12278. });
  12279. Ext.reg('datepicker', Ext.DatePicker);
  12280. /**
  12281. * @class Ext.LoadMask
  12282. * A simple utility class for generically masking elements while loading data. If the {@link #store}
  12283. * config option is specified, the masking will be automatically synchronized with the store's loading
  12284. * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
  12285. * element's Updater load indicator and will be destroyed after the initial load.
  12286. * <p>Example usage:</p>
  12287. *<pre><code>
  12288. // Basic mask:
  12289. var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Please wait..."});
  12290. myMask.show();
  12291. </code></pre>
  12292. * @constructor
  12293. * Create a new LoadMask
  12294. * @param {Mixed} el The element or DOM node, or its id
  12295. * @param {Object} config The config object
  12296. */
  12297. Ext.LoadMask = function(el, config){
  12298. this.el = Ext.get(el);
  12299. Ext.apply(this, config);
  12300. if(this.store){
  12301. this.store.on({
  12302. scope: this,
  12303. beforeload: this.onBeforeLoad,
  12304. load: this.onLoad,
  12305. exception: this.onLoad
  12306. });
  12307. this.removeMask = Ext.value(this.removeMask, false);
  12308. }else{
  12309. var um = this.el.getUpdater();
  12310. um.showLoadIndicator = false; // disable the default indicator
  12311. um.on({
  12312. scope: this,
  12313. beforeupdate: this.onBeforeLoad,
  12314. update: this.onLoad,
  12315. failure: this.onLoad
  12316. });
  12317. this.removeMask = Ext.value(this.removeMask, true);
  12318. }
  12319. };
  12320. Ext.LoadMask.prototype = {
  12321. /**
  12322. * @cfg {Ext.data.Store} store
  12323. * Optional Store to which the mask is bound. The mask is displayed when a load request is issued, and
  12324. * hidden on either load sucess, or load fail.
  12325. */
  12326. /**
  12327. * @cfg {Boolean} removeMask
  12328. * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
  12329. * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
  12330. */
  12331. /**
  12332. * @cfg {String} msg
  12333. * The text to display in a centered loading message box (defaults to 'Loading...')
  12334. */
  12335. msg : 'Loading...',
  12336. /**
  12337. * @cfg {String} msgCls
  12338. * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
  12339. */
  12340. msgCls : 'x-mask-loading',
  12341. /**
  12342. * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
  12343. * @type Boolean
  12344. */
  12345. disabled: false,
  12346. /**
  12347. * Disables the mask to prevent it from being displayed
  12348. */
  12349. disable : function(){
  12350. this.disabled = true;
  12351. },
  12352. /**
  12353. * Enables the mask so that it can be displayed
  12354. */
  12355. enable : function(){
  12356. this.disabled = false;
  12357. },
  12358. // private
  12359. onLoad : function(){
  12360. this.el.unmask(this.removeMask);
  12361. },
  12362. // private
  12363. onBeforeLoad : function(){
  12364. if(!this.disabled){
  12365. this.el.mask(this.msg, this.msgCls);
  12366. }
  12367. },
  12368. /**
  12369. * Show this LoadMask over the configured Element.
  12370. */
  12371. show: function(){
  12372. this.onBeforeLoad();
  12373. },
  12374. /**
  12375. * Hide this LoadMask.
  12376. */
  12377. hide: function(){
  12378. this.onLoad();
  12379. },
  12380. // private
  12381. destroy : function(){
  12382. if(this.store){
  12383. this.store.un('beforeload', this.onBeforeLoad, this);
  12384. this.store.un('load', this.onLoad, this);
  12385. this.store.un('exception', this.onLoad, this);
  12386. }else{
  12387. var um = this.el.getUpdater();
  12388. um.un('beforeupdate', this.onBeforeLoad, this);
  12389. um.un('update', this.onLoad, this);
  12390. um.un('failure', this.onLoad, this);
  12391. }
  12392. }
  12393. };Ext.ns('Ext.slider');
  12394. /**
  12395. * @class Ext.slider.Thumb
  12396. * @extends Object
  12397. * Represents a single thumb element on a Slider. This would not usually be created manually and would instead
  12398. * be created internally by an {@link Ext.slider.MultiSlider Ext.Slider}.
  12399. */
  12400. Ext.slider.Thumb = Ext.extend(Object, {
  12401. /**
  12402. * True while the thumb is in a drag operation
  12403. * @type Boolean
  12404. */
  12405. dragging: false,
  12406. /**
  12407. * @constructor
  12408. * @cfg {Ext.slider.MultiSlider} slider The Slider to render to (required)
  12409. */
  12410. constructor: function(config) {
  12411. /**
  12412. * @property slider
  12413. * @type Ext.slider.MultiSlider
  12414. * The slider this thumb is contained within
  12415. */
  12416. Ext.apply(this, config || {}, {
  12417. cls: 'x-slider-thumb',
  12418. /**
  12419. * @cfg {Boolean} constrain True to constrain the thumb so that it cannot overlap its siblings
  12420. */
  12421. constrain: false
  12422. });
  12423. Ext.slider.Thumb.superclass.constructor.call(this, config);
  12424. if (this.slider.vertical) {
  12425. Ext.apply(this, Ext.slider.Thumb.Vertical);
  12426. }
  12427. },
  12428. /**
  12429. * Renders the thumb into a slider
  12430. */
  12431. render: function() {
  12432. this.el = this.slider.innerEl.insertFirst({cls: this.cls});
  12433. this.initEvents();
  12434. },
  12435. /**
  12436. * Enables the thumb if it is currently disabled
  12437. */
  12438. enable: function() {
  12439. this.disabled = false;
  12440. this.el.removeClass(this.slider.disabledClass);
  12441. },
  12442. /**
  12443. * Disables the thumb if it is currently enabled
  12444. */
  12445. disable: function() {
  12446. this.disabled = true;
  12447. this.el.addClass(this.slider.disabledClass);
  12448. },
  12449. /**
  12450. * Sets up an Ext.dd.DragTracker for this thumb
  12451. */
  12452. initEvents: function() {
  12453. var el = this.el;
  12454. el.addClassOnOver('x-slider-thumb-over');
  12455. this.tracker = new Ext.dd.DragTracker({
  12456. onBeforeStart: this.onBeforeDragStart.createDelegate(this),
  12457. onStart : this.onDragStart.createDelegate(this),
  12458. onDrag : this.onDrag.createDelegate(this),
  12459. onEnd : this.onDragEnd.createDelegate(this),
  12460. tolerance : 3,
  12461. autoStart : 300
  12462. });
  12463. this.tracker.initEl(el);
  12464. },
  12465. /**
  12466. * @private
  12467. * This is tied into the internal Ext.dd.DragTracker. If the slider is currently disabled,
  12468. * this returns false to disable the DragTracker too.
  12469. * @return {Boolean} False if the slider is currently disabled
  12470. */
  12471. onBeforeDragStart : function(e) {
  12472. if (this.disabled) {
  12473. return false;
  12474. } else {
  12475. this.slider.promoteThumb(this);
  12476. return true;
  12477. }
  12478. },
  12479. /**
  12480. * @private
  12481. * This is tied into the internal Ext.dd.DragTracker's onStart template method. Adds the drag CSS class
  12482. * to the thumb and fires the 'dragstart' event
  12483. */
  12484. onDragStart: function(e){
  12485. this.el.addClass('x-slider-thumb-drag');
  12486. this.dragging = true;
  12487. this.dragStartValue = this.value;
  12488. this.slider.fireEvent('dragstart', this.slider, e, this);
  12489. },
  12490. /**
  12491. * @private
  12492. * This is tied into the internal Ext.dd.DragTracker's onDrag template method. This is called every time
  12493. * the DragTracker detects a drag movement. It updates the Slider's value using the position of the drag
  12494. */
  12495. onDrag: function(e) {
  12496. var slider = this.slider,
  12497. index = this.index,
  12498. newValue = this.getNewValue();
  12499. if (this.constrain) {
  12500. var above = slider.thumbs[index + 1],
  12501. below = slider.thumbs[index - 1];
  12502. if (below != undefined && newValue <= below.value) newValue = below.value;
  12503. if (above != undefined && newValue >= above.value) newValue = above.value;
  12504. }
  12505. slider.setValue(index, newValue, false);
  12506. slider.fireEvent('drag', slider, e, this);
  12507. },
  12508. getNewValue: function() {
  12509. var slider = this.slider,
  12510. pos = slider.innerEl.translatePoints(this.tracker.getXY());
  12511. return Ext.util.Format.round(slider.reverseValue(pos.left), slider.decimalPrecision);
  12512. },
  12513. /**
  12514. * @private
  12515. * This is tied to the internal Ext.dd.DragTracker's onEnd template method. Removes the drag CSS class and
  12516. * fires the 'changecomplete' event with the new value
  12517. */
  12518. onDragEnd: function(e) {
  12519. var slider = this.slider,
  12520. value = this.value;
  12521. this.el.removeClass('x-slider-thumb-drag');
  12522. this.dragging = false;
  12523. slider.fireEvent('dragend', slider, e);
  12524. if (this.dragStartValue != value) {
  12525. slider.fireEvent('changecomplete', slider, value, this);
  12526. }
  12527. },
  12528. /**
  12529. * @private
  12530. * Destroys the thumb
  12531. */
  12532. destroy: function(){
  12533. Ext.destroyMembers(this, 'tracker', 'el');
  12534. }
  12535. });
  12536. /**
  12537. * @class Ext.slider.MultiSlider
  12538. * @extends Ext.BoxComponent
  12539. * 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:
  12540. <pre>
  12541. new Ext.Slider({
  12542. renderTo: Ext.getBody(),
  12543. width: 200,
  12544. value: 50,
  12545. increment: 10,
  12546. minValue: 0,
  12547. maxValue: 100
  12548. });
  12549. </pre>
  12550. * Sliders can be created with more than one thumb handle by passing an array of values instead of a single one:
  12551. <pre>
  12552. new Ext.Slider({
  12553. renderTo: Ext.getBody(),
  12554. width: 200,
  12555. values: [25, 50, 75],
  12556. minValue: 0,
  12557. maxValue: 100,
  12558. //this defaults to true, setting to false allows the thumbs to pass each other
  12559. {@link #constrainThumbs}: false
  12560. });
  12561. </pre>
  12562. */
  12563. Ext.slider.MultiSlider = Ext.extend(Ext.BoxComponent, {
  12564. /**
  12565. * @cfg {Number} value The value to initialize the slider with. Defaults to minValue.
  12566. */
  12567. /**
  12568. * @cfg {Boolean} vertical Orient the Slider vertically rather than horizontally, defaults to false.
  12569. */
  12570. vertical: false,
  12571. /**
  12572. * @cfg {Number} minValue The minimum value for the Slider. Defaults to 0.
  12573. */
  12574. minValue: 0,
  12575. /**
  12576. * @cfg {Number} maxValue The maximum value for the Slider. Defaults to 100.
  12577. */
  12578. maxValue: 100,
  12579. /**
  12580. * @cfg {Number/Boolean} decimalPrecision.
  12581. * <p>The number of decimal places to which to round the Slider's value. Defaults to 0.</p>
  12582. * <p>To disable rounding, configure as <tt><b>false</b></tt>.</p>
  12583. */
  12584. decimalPrecision: 0,
  12585. /**
  12586. * @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.
  12587. */
  12588. keyIncrement: 1,
  12589. /**
  12590. * @cfg {Number} increment How many units to change the slider when adjusting by drag and drop. Use this option to enable 'snapping'.
  12591. */
  12592. increment: 0,
  12593. /**
  12594. * @private
  12595. * @property clickRange
  12596. * @type Array
  12597. * 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],
  12598. * 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'
  12599. * 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
  12600. */
  12601. clickRange: [5,15],
  12602. /**
  12603. * @cfg {Boolean} clickToChange Determines whether or not clicking on the Slider axis will change the slider. Defaults to true
  12604. */
  12605. clickToChange : true,
  12606. /**
  12607. * @cfg {Boolean} animate Turn on or off animation. Defaults to true
  12608. */
  12609. animate: true,
  12610. /**
  12611. * @cfg {Boolean} constrainThumbs True to disallow thumbs from overlapping one another. Defaults to true
  12612. */
  12613. constrainThumbs: true,
  12614. /**
  12615. * @private
  12616. * @property topThumbZIndex
  12617. * @type Number
  12618. * The number used internally to set the z index of the top thumb (see promoteThumb for details)
  12619. */
  12620. topThumbZIndex: 10000,
  12621. // private override
  12622. initComponent : function(){
  12623. if(!Ext.isDefined(this.value)){
  12624. this.value = this.minValue;
  12625. }
  12626. /**
  12627. * @property thumbs
  12628. * @type Array
  12629. * Array containing references to each thumb
  12630. */
  12631. this.thumbs = [];
  12632. Ext.slider.MultiSlider.superclass.initComponent.call(this);
  12633. this.keyIncrement = Math.max(this.increment, this.keyIncrement);
  12634. this.addEvents(
  12635. /**
  12636. * @event beforechange
  12637. * Fires before the slider value is changed. By returning false from an event handler,
  12638. * you can cancel the event and prevent the slider from changing.
  12639. * @param {Ext.slider.MultiSlider} slider The slider
  12640. * @param {Number} newValue The new value which the slider is being changed to.
  12641. * @param {Number} oldValue The old value which the slider was previously.
  12642. */
  12643. 'beforechange',
  12644. /**
  12645. * @event change
  12646. * Fires when the slider value is changed.
  12647. * @param {Ext.slider.MultiSlider} slider The slider
  12648. * @param {Number} newValue The new value which the slider has been changed to.
  12649. * @param {Ext.slider.Thumb} thumb The thumb that was changed
  12650. */
  12651. 'change',
  12652. /**
  12653. * @event changecomplete
  12654. * Fires when the slider value is changed by the user and any drag operations have completed.
  12655. * @param {Ext.slider.MultiSlider} slider The slider
  12656. * @param {Number} newValue The new value which the slider has been changed to.
  12657. * @param {Ext.slider.Thumb} thumb The thumb that was changed
  12658. */
  12659. 'changecomplete',
  12660. /**
  12661. * @event dragstart
  12662. * Fires after a drag operation has started.
  12663. * @param {Ext.slider.MultiSlider} slider The slider
  12664. * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker
  12665. */
  12666. 'dragstart',
  12667. /**
  12668. * @event drag
  12669. * Fires continuously during the drag operation while the mouse is moving.
  12670. * @param {Ext.slider.MultiSlider} slider The slider
  12671. * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker
  12672. */
  12673. 'drag',
  12674. /**
  12675. * @event dragend
  12676. * Fires after the drag operation has completed.
  12677. * @param {Ext.slider.MultiSlider} slider The slider
  12678. * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker
  12679. */
  12680. 'dragend'
  12681. );
  12682. /**
  12683. * @property values
  12684. * @type Array
  12685. * Array of values to initalize the thumbs with
  12686. */
  12687. if (this.values == undefined || Ext.isEmpty(this.values)) this.values = [0];
  12688. var values = this.values;
  12689. for (var i=0; i < values.length; i++) {
  12690. this.addThumb(values[i]);
  12691. }
  12692. if(this.vertical){
  12693. Ext.apply(this, Ext.slider.Vertical);
  12694. }
  12695. },
  12696. /**
  12697. * Creates a new thumb and adds it to the slider
  12698. * @param {Number} value The initial value to set on the thumb. Defaults to 0
  12699. */
  12700. addThumb: function(value) {
  12701. var thumb = new Ext.slider.Thumb({
  12702. value : value,
  12703. slider : this,
  12704. index : this.thumbs.length,
  12705. constrain: this.constrainThumbs
  12706. });
  12707. this.thumbs.push(thumb);
  12708. //render the thumb now if needed
  12709. if (this.rendered) thumb.render();
  12710. },
  12711. /**
  12712. * @private
  12713. * Moves the given thumb above all other by increasing its z-index. This is called when as drag
  12714. * any thumb, so that the thumb that was just dragged is always at the highest z-index. This is
  12715. * required when the thumbs are stacked on top of each other at one of the ends of the slider's
  12716. * range, which can result in the user not being able to move any of them.
  12717. * @param {Ext.slider.Thumb} topThumb The thumb to move to the top
  12718. */
  12719. promoteThumb: function(topThumb) {
  12720. var thumbs = this.thumbs,
  12721. zIndex, thumb;
  12722. for (var i = 0, j = thumbs.length; i < j; i++) {
  12723. thumb = thumbs[i];
  12724. if (thumb == topThumb) {
  12725. zIndex = this.topThumbZIndex;
  12726. } else {
  12727. zIndex = '';
  12728. }
  12729. thumb.el.setStyle('zIndex', zIndex);
  12730. }
  12731. },
  12732. // private override
  12733. onRender : function() {
  12734. this.autoEl = {
  12735. cls: 'x-slider ' + (this.vertical ? 'x-slider-vert' : 'x-slider-horz'),
  12736. cn : {
  12737. cls: 'x-slider-end',
  12738. cn : {
  12739. cls:'x-slider-inner',
  12740. cn : [{tag:'a', cls:'x-slider-focus', href:"#", tabIndex: '-1', hidefocus:'on'}]
  12741. }
  12742. }
  12743. };
  12744. Ext.slider.MultiSlider.superclass.onRender.apply(this, arguments);
  12745. this.endEl = this.el.first();
  12746. this.innerEl = this.endEl.first();
  12747. this.focusEl = this.innerEl.child('.x-slider-focus');
  12748. //render each thumb
  12749. for (var i=0; i < this.thumbs.length; i++) {
  12750. this.thumbs[i].render();
  12751. }
  12752. //calculate the size of half a thumb
  12753. var thumb = this.innerEl.child('.x-slider-thumb');
  12754. this.halfThumb = (this.vertical ? thumb.getHeight() : thumb.getWidth()) / 2;
  12755. this.initEvents();
  12756. },
  12757. /**
  12758. * @private
  12759. * Adds keyboard and mouse listeners on this.el. Ignores click events on the internal focus element.
  12760. * Creates a new DragTracker which is used to control what happens when the user drags the thumb around.
  12761. */
  12762. initEvents : function(){
  12763. this.mon(this.el, {
  12764. scope : this,
  12765. mousedown: this.onMouseDown,
  12766. keydown : this.onKeyDown
  12767. });
  12768. this.focusEl.swallowEvent("click", true);
  12769. },
  12770. /**
  12771. * @private
  12772. * Mousedown handler for the slider. If the clickToChange is enabled and the click was not on the draggable 'thumb',
  12773. * this calculates the new value of the slider and tells the implementation (Horizontal or Vertical) to move the thumb
  12774. * @param {Ext.EventObject} e The click event
  12775. */
  12776. onMouseDown : function(e){
  12777. if(this.disabled){
  12778. return;
  12779. }
  12780. //see if the click was on any of the thumbs
  12781. var thumbClicked = false;
  12782. for (var i=0; i < this.thumbs.length; i++) {
  12783. thumbClicked = thumbClicked || e.target == this.thumbs[i].el.dom;
  12784. }
  12785. if (this.clickToChange && !thumbClicked) {
  12786. var local = this.innerEl.translatePoints(e.getXY());
  12787. this.onClickChange(local);
  12788. }
  12789. this.focus();
  12790. },
  12791. /**
  12792. * @private
  12793. * Moves the thumb to the indicated position. Note that a Vertical implementation is provided in Ext.slider.Vertical.
  12794. * Only changes the value if the click was within this.clickRange.
  12795. * @param {Object} local Object containing top and left values for the click event.
  12796. */
  12797. onClickChange : function(local) {
  12798. if (local.top > this.clickRange[0] && local.top < this.clickRange[1]) {
  12799. //find the nearest thumb to the click event
  12800. var thumb = this.getNearest(local, 'left'),
  12801. index = thumb.index;
  12802. this.setValue(index, Ext.util.Format.round(this.reverseValue(local.left), this.decimalPrecision), undefined, true);
  12803. }
  12804. },
  12805. /**
  12806. * @private
  12807. * Returns the nearest thumb to a click event, along with its distance
  12808. * @param {Object} local Object containing top and left values from a click event
  12809. * @param {String} prop The property of local to compare on. Use 'left' for horizontal sliders, 'top' for vertical ones
  12810. * @return {Object} The closest thumb object and its distance from the click event
  12811. */
  12812. getNearest: function(local, prop) {
  12813. var localValue = prop == 'top' ? this.innerEl.getHeight() - local[prop] : local[prop],
  12814. clickValue = this.reverseValue(localValue),
  12815. nearestDistance = (this.maxValue - this.minValue) + 5, //add a small fudge for the end of the slider
  12816. index = 0,
  12817. nearest = null;
  12818. for (var i=0; i < this.thumbs.length; i++) {
  12819. var thumb = this.thumbs[i],
  12820. value = thumb.value,
  12821. dist = Math.abs(value - clickValue);
  12822. if (Math.abs(dist <= nearestDistance)) {
  12823. nearest = thumb;
  12824. index = i;
  12825. nearestDistance = dist;
  12826. }
  12827. }
  12828. return nearest;
  12829. },
  12830. /**
  12831. * @private
  12832. * Handler for any keypresses captured by the slider. If the key is UP or RIGHT, the thumb is moved along to the right
  12833. * by this.keyIncrement. If DOWN or LEFT it is moved left. Pressing CTRL moves the slider to the end in either direction
  12834. * @param {Ext.EventObject} e The Event object
  12835. */
  12836. onKeyDown : function(e){
  12837. /*
  12838. * The behaviour for keyboard handling with multiple thumbs is currently undefined.
  12839. * There's no real sane default for it, so leave it like this until we come up
  12840. * with a better way of doing it.
  12841. */
  12842. if(this.disabled || this.thumbs.length !== 1){
  12843. e.preventDefault();
  12844. return;
  12845. }
  12846. var k = e.getKey(),
  12847. val;
  12848. switch(k){
  12849. case e.UP:
  12850. case e.RIGHT:
  12851. e.stopEvent();
  12852. val = e.ctrlKey ? this.maxValue : this.getValue(0) + this.keyIncrement;
  12853. this.setValue(0, val, undefined, true);
  12854. break;
  12855. case e.DOWN:
  12856. case e.LEFT:
  12857. e.stopEvent();
  12858. val = e.ctrlKey ? this.minValue : this.getValue(0) - this.keyIncrement;
  12859. this.setValue(0, val, undefined, true);
  12860. break;
  12861. default:
  12862. e.preventDefault();
  12863. }
  12864. },
  12865. /**
  12866. * @private
  12867. * If using snapping, this takes a desired new value and returns the closest snapped
  12868. * value to it
  12869. * @param {Number} value The unsnapped value
  12870. * @return {Number} The value of the nearest snap target
  12871. */
  12872. doSnap : function(value){
  12873. if (!(this.increment && value)) {
  12874. return value;
  12875. }
  12876. var newValue = value,
  12877. inc = this.increment,
  12878. m = value % inc;
  12879. if (m != 0) {
  12880. newValue -= m;
  12881. if (m * 2 >= inc) {
  12882. newValue += inc;
  12883. } else if (m * 2 < -inc) {
  12884. newValue -= inc;
  12885. }
  12886. }
  12887. return newValue.constrain(this.minValue, this.maxValue);
  12888. },
  12889. // private
  12890. afterRender : function(){
  12891. Ext.slider.MultiSlider.superclass.afterRender.apply(this, arguments);
  12892. for (var i=0; i < this.thumbs.length; i++) {
  12893. var thumb = this.thumbs[i];
  12894. if (thumb.value !== undefined) {
  12895. var v = this.normalizeValue(thumb.value);
  12896. if (v !== thumb.value) {
  12897. // delete this.value;
  12898. this.setValue(i, v, false);
  12899. } else {
  12900. this.moveThumb(i, this.translateValue(v), false);
  12901. }
  12902. }
  12903. };
  12904. },
  12905. /**
  12906. * @private
  12907. * Returns the ratio of pixels to mapped values. e.g. if the slider is 200px wide and maxValue - minValue is 100,
  12908. * the ratio is 2
  12909. * @return {Number} The ratio of pixels to mapped values
  12910. */
  12911. getRatio : function(){
  12912. var w = this.innerEl.getWidth(),
  12913. v = this.maxValue - this.minValue;
  12914. return v == 0 ? w : (w/v);
  12915. },
  12916. /**
  12917. * @private
  12918. * Returns a snapped, constrained value when given a desired value
  12919. * @param {Number} value Raw number value
  12920. * @return {Number} The raw value rounded to the correct d.p. and constrained within the set max and min values
  12921. */
  12922. normalizeValue : function(v){
  12923. v = this.doSnap(v);
  12924. v = Ext.util.Format.round(v, this.decimalPrecision);
  12925. v = v.constrain(this.minValue, this.maxValue);
  12926. return v;
  12927. },
  12928. /**
  12929. * Sets the minimum value for the slider instance. If the current value is less than the
  12930. * minimum value, the current value will be changed.
  12931. * @param {Number} val The new minimum value
  12932. */
  12933. setMinValue : function(val){
  12934. this.minValue = val;
  12935. var i = 0,
  12936. thumbs = this.thumbs,
  12937. len = thumbs.length,
  12938. t;
  12939. for(; i < len; ++i){
  12940. t = thumbs[i];
  12941. t.value = t.value < val ? val : t.value;
  12942. }
  12943. this.syncThumb();
  12944. },
  12945. /**
  12946. * Sets the maximum value for the slider instance. If the current value is more than the
  12947. * maximum value, the current value will be changed.
  12948. * @param {Number} val The new maximum value
  12949. */
  12950. setMaxValue : function(val){
  12951. this.maxValue = val;
  12952. var i = 0,
  12953. thumbs = this.thumbs,
  12954. len = thumbs.length,
  12955. t;
  12956. for(; i < len; ++i){
  12957. t = thumbs[i];
  12958. t.value = t.value > val ? val : t.value;
  12959. }
  12960. this.syncThumb();
  12961. },
  12962. /**
  12963. * Programmatically sets the value of the Slider. Ensures that the value is constrained within
  12964. * the minValue and maxValue.
  12965. * @param {Number} index Index of the thumb to move
  12966. * @param {Number} value The value to set the slider to. (This will be constrained within minValue and maxValue)
  12967. * @param {Boolean} animate Turn on or off animation, defaults to true
  12968. */
  12969. setValue : function(index, v, animate, changeComplete) {
  12970. var thumb = this.thumbs[index],
  12971. el = thumb.el;
  12972. v = this.normalizeValue(v);
  12973. if (v !== thumb.value && this.fireEvent('beforechange', this, v, thumb.value, thumb) !== false) {
  12974. thumb.value = v;
  12975. if(this.rendered){
  12976. this.moveThumb(index, this.translateValue(v), animate !== false);
  12977. this.fireEvent('change', this, v, thumb);
  12978. if(changeComplete){
  12979. this.fireEvent('changecomplete', this, v, thumb);
  12980. }
  12981. }
  12982. }
  12983. },
  12984. /**
  12985. * @private
  12986. */
  12987. translateValue : function(v) {
  12988. var ratio = this.getRatio();
  12989. return (v * ratio) - (this.minValue * ratio) - this.halfThumb;
  12990. },
  12991. /**
  12992. * @private
  12993. * Given a pixel location along the slider, returns the mapped slider value for that pixel.
  12994. * E.g. if we have a slider 200px wide with minValue = 100 and maxValue = 500, reverseValue(50)
  12995. * returns 200
  12996. * @param {Number} pos The position along the slider to return a mapped value for
  12997. * @return {Number} The mapped value for the given position
  12998. */
  12999. reverseValue : function(pos){
  13000. var ratio = this.getRatio();
  13001. return (pos + (this.minValue * ratio)) / ratio;
  13002. },
  13003. /**
  13004. * @private
  13005. * @param {Number} index Index of the thumb to move
  13006. */
  13007. moveThumb: function(index, v, animate){
  13008. var thumb = this.thumbs[index].el;
  13009. if(!animate || this.animate === false){
  13010. thumb.setLeft(v);
  13011. }else{
  13012. thumb.shift({left: v, stopFx: true, duration:.35});
  13013. }
  13014. },
  13015. // private
  13016. focus : function(){
  13017. this.focusEl.focus(10);
  13018. },
  13019. // private
  13020. onResize : function(w, h){
  13021. var thumbs = this.thumbs,
  13022. len = thumbs.length,
  13023. i = 0;
  13024. /*
  13025. * If we happen to be animating during a resize, the position of the thumb will likely be off
  13026. * when the animation stops. As such, just stop any animations before syncing the thumbs.
  13027. */
  13028. for(; i < len; ++i){
  13029. thumbs[i].el.stopFx();
  13030. }
  13031. // check to see if we're using an auto width
  13032. if(Ext.isNumber(w)){
  13033. this.innerEl.setWidth(w - (this.el.getPadding('l') + this.endEl.getPadding('r')));
  13034. }
  13035. this.syncThumb();
  13036. Ext.slider.MultiSlider.superclass.onResize.apply(this, arguments);
  13037. },
  13038. //private
  13039. onDisable: function(){
  13040. Ext.slider.MultiSlider.superclass.onDisable.call(this);
  13041. for (var i=0; i < this.thumbs.length; i++) {
  13042. var thumb = this.thumbs[i],
  13043. el = thumb.el;
  13044. thumb.disable();
  13045. if(Ext.isIE){
  13046. //IE breaks when using overflow visible and opacity other than 1.
  13047. //Create a place holder for the thumb and display it.
  13048. var xy = el.getXY();
  13049. el.hide();
  13050. this.innerEl.addClass(this.disabledClass).dom.disabled = true;
  13051. if (!this.thumbHolder) {
  13052. this.thumbHolder = this.endEl.createChild({cls: 'x-slider-thumb ' + this.disabledClass});
  13053. }
  13054. this.thumbHolder.show().setXY(xy);
  13055. }
  13056. }
  13057. },
  13058. //private
  13059. onEnable: function(){
  13060. Ext.slider.MultiSlider.superclass.onEnable.call(this);
  13061. for (var i=0; i < this.thumbs.length; i++) {
  13062. var thumb = this.thumbs[i],
  13063. el = thumb.el;
  13064. thumb.enable();
  13065. if (Ext.isIE) {
  13066. this.innerEl.removeClass(this.disabledClass).dom.disabled = false;
  13067. if (this.thumbHolder) this.thumbHolder.hide();
  13068. el.show();
  13069. this.syncThumb();
  13070. }
  13071. }
  13072. },
  13073. /**
  13074. * Synchronizes the thumb position to the proper proportion of the total component width based
  13075. * on the current slider {@link #value}. This will be called automatically when the Slider
  13076. * is resized by a layout, but if it is rendered auto width, this method can be called from
  13077. * another resize handler to sync the Slider if necessary.
  13078. */
  13079. syncThumb : function() {
  13080. if (this.rendered) {
  13081. for (var i=0; i < this.thumbs.length; i++) {
  13082. this.moveThumb(i, this.translateValue(this.thumbs[i].value));
  13083. }
  13084. }
  13085. },
  13086. /**
  13087. * Returns the current value of the slider
  13088. * @param {Number} index The index of the thumb to return a value for
  13089. * @return {Number} The current value of the slider
  13090. */
  13091. getValue : function(index) {
  13092. return this.thumbs[index].value;
  13093. },
  13094. /**
  13095. * Returns an array of values - one for the location of each thumb
  13096. * @return {Array} The set of thumb values
  13097. */
  13098. getValues: function() {
  13099. var values = [];
  13100. for (var i=0; i < this.thumbs.length; i++) {
  13101. values.push(this.thumbs[i].value);
  13102. }
  13103. return values;
  13104. },
  13105. // private
  13106. beforeDestroy : function(){
  13107. var thumbs = this.thumbs;
  13108. for(var i = 0, len = thumbs.length; i < len; ++i){
  13109. thumbs[i].destroy();
  13110. thumbs[i] = null;
  13111. }
  13112. Ext.destroyMembers(this, 'endEl', 'innerEl', 'focusEl', 'thumbHolder');
  13113. Ext.slider.MultiSlider.superclass.beforeDestroy.call(this);
  13114. }
  13115. });
  13116. Ext.reg('multislider', Ext.slider.MultiSlider);
  13117. /**
  13118. * @class Ext.slider.SingleSlider
  13119. * @extends Ext.slider.MultiSlider
  13120. * Slider which supports vertical or horizontal orientation, keyboard adjustments,
  13121. * configurable snapping, axis clicking and animation. Can be added as an item to
  13122. * any container. Example usage:
  13123. <pre><code>
  13124. new Ext.slider.SingleSlider({
  13125. renderTo: Ext.getBody(),
  13126. width: 200,
  13127. value: 50,
  13128. increment: 10,
  13129. minValue: 0,
  13130. maxValue: 100
  13131. });
  13132. </code></pre>
  13133. * The class Ext.slider.SingleSlider is aliased to Ext.Slider for backwards compatibility.
  13134. */
  13135. Ext.slider.SingleSlider = Ext.extend(Ext.slider.MultiSlider, {
  13136. constructor: function(config) {
  13137. config = config || {};
  13138. Ext.applyIf(config, {
  13139. values: [config.value || 0]
  13140. });
  13141. Ext.slider.SingleSlider.superclass.constructor.call(this, config);
  13142. },
  13143. /**
  13144. * Returns the current value of the slider
  13145. * @return {Number} The current value of the slider
  13146. */
  13147. getValue: function() {
  13148. //just returns the value of the first thumb, which should be the only one in a single slider
  13149. return Ext.slider.SingleSlider.superclass.getValue.call(this, 0);
  13150. },
  13151. /**
  13152. * Programmatically sets the value of the Slider. Ensures that the value is constrained within
  13153. * the minValue and maxValue.
  13154. * @param {Number} value The value to set the slider to. (This will be constrained within minValue and maxValue)
  13155. * @param {Boolean} animate Turn on or off animation, defaults to true
  13156. */
  13157. setValue: function(value, animate) {
  13158. var args = Ext.toArray(arguments),
  13159. len = args.length;
  13160. //this is to maintain backwards compatiblity for sliders with only one thunb. Usually you must pass the thumb
  13161. //index to setValue, but if we only have one thumb we inject the index here first if given the multi-slider
  13162. //signature without the required index. The index will always be 0 for a single slider
  13163. if (len == 1 || (len <= 3 && typeof arguments[1] != 'number')) {
  13164. args.unshift(0);
  13165. }
  13166. return Ext.slider.SingleSlider.superclass.setValue.apply(this, args);
  13167. },
  13168. /**
  13169. * Synchronizes the thumb position to the proper proportion of the total component width based
  13170. * on the current slider {@link #value}. This will be called automatically when the Slider
  13171. * is resized by a layout, but if it is rendered auto width, this method can be called from
  13172. * another resize handler to sync the Slider if necessary.
  13173. */
  13174. syncThumb : function() {
  13175. return Ext.slider.SingleSlider.superclass.syncThumb.apply(this, [0].concat(arguments));
  13176. },
  13177. // private
  13178. getNearest : function(){
  13179. // Since there's only 1 thumb, it's always the nearest
  13180. return this.thumbs[0];
  13181. }
  13182. });
  13183. //backwards compatibility
  13184. Ext.Slider = Ext.slider.SingleSlider;
  13185. Ext.reg('slider', Ext.slider.SingleSlider);
  13186. // private class to support vertical sliders
  13187. Ext.slider.Vertical = {
  13188. onResize : function(w, h){
  13189. this.innerEl.setHeight(h - (this.el.getPadding('t') + this.endEl.getPadding('b')));
  13190. this.syncThumb();
  13191. },
  13192. getRatio : function(){
  13193. var h = this.innerEl.getHeight(),
  13194. v = this.maxValue - this.minValue;
  13195. return h/v;
  13196. },
  13197. moveThumb: function(index, v, animate) {
  13198. var thumb = this.thumbs[index],
  13199. el = thumb.el;
  13200. if (!animate || this.animate === false) {
  13201. el.setBottom(v);
  13202. } else {
  13203. el.shift({bottom: v, stopFx: true, duration:.35});
  13204. }
  13205. },
  13206. onClickChange : function(local) {
  13207. if (local.left > this.clickRange[0] && local.left < this.clickRange[1]) {
  13208. var thumb = this.getNearest(local, 'top'),
  13209. index = thumb.index,
  13210. value = this.minValue + this.reverseValue(this.innerEl.getHeight() - local.top);
  13211. this.setValue(index, Ext.util.Format.round(value, this.decimalPrecision), undefined, true);
  13212. }
  13213. }
  13214. };
  13215. //private class to support vertical dragging of thumbs within a slider
  13216. Ext.slider.Thumb.Vertical = {
  13217. getNewValue: function() {
  13218. var slider = this.slider,
  13219. innerEl = slider.innerEl,
  13220. pos = innerEl.translatePoints(this.tracker.getXY()),
  13221. bottom = innerEl.getHeight() - pos.top;
  13222. return slider.minValue + Ext.util.Format.round(bottom / slider.getRatio(), slider.decimalPrecision);
  13223. }
  13224. };
  13225. /**
  13226. * @class Ext.ProgressBar
  13227. * @extends Ext.BoxComponent
  13228. * <p>An updateable progress bar component. The progress bar supports two different modes: manual and automatic.</p>
  13229. * <p>In manual mode, you are responsible for showing, updating (via {@link #updateProgress}) and clearing the
  13230. * progress bar as needed from your own code. This method is most appropriate when you want to show progress
  13231. * throughout an operation that has predictable points of interest at which you can update the control.</p>
  13232. * <p>In automatic mode, you simply call {@link #wait} and let the progress bar run indefinitely, only clearing it
  13233. * once the operation is complete. You can optionally have the progress bar wait for a specific amount of time
  13234. * and then clear itself. Automatic mode is most appropriate for timed operations or asynchronous operations in
  13235. * which you have no need for indicating intermediate progress.</p>
  13236. * @cfg {Float} value A floating point value between 0 and 1 (e.g., .5, defaults to 0)
  13237. * @cfg {String} text The progress bar text (defaults to '')
  13238. * @cfg {Mixed} textEl The element to render the progress text to (defaults to the progress
  13239. * bar's internal text element)
  13240. * @cfg {String} id The progress bar element's id (defaults to an auto-generated id)
  13241. * @xtype progress
  13242. */
  13243. Ext.ProgressBar = Ext.extend(Ext.BoxComponent, {
  13244. /**
  13245. * @cfg {String} baseCls
  13246. * The base CSS class to apply to the progress bar's wrapper element (defaults to 'x-progress')
  13247. */
  13248. baseCls : 'x-progress',
  13249. /**
  13250. * @cfg {Boolean} animate
  13251. * True to animate the progress bar during transitions (defaults to false)
  13252. */
  13253. animate : false,
  13254. // private
  13255. waitTimer : null,
  13256. // private
  13257. initComponent : function(){
  13258. Ext.ProgressBar.superclass.initComponent.call(this);
  13259. this.addEvents(
  13260. /**
  13261. * @event update
  13262. * Fires after each update interval
  13263. * @param {Ext.ProgressBar} this
  13264. * @param {Number} The current progress value
  13265. * @param {String} The current progress text
  13266. */
  13267. "update"
  13268. );
  13269. },
  13270. // private
  13271. onRender : function(ct, position){
  13272. var tpl = new Ext.Template(
  13273. '<div class="{cls}-wrap">',
  13274. '<div class="{cls}-inner">',
  13275. '<div class="{cls}-bar">',
  13276. '<div class="{cls}-text">',
  13277. '<div>&#160;</div>',
  13278. '</div>',
  13279. '</div>',
  13280. '<div class="{cls}-text {cls}-text-back">',
  13281. '<div>&#160;</div>',
  13282. '</div>',
  13283. '</div>',
  13284. '</div>'
  13285. );
  13286. this.el = position ? tpl.insertBefore(position, {cls: this.baseCls}, true)
  13287. : tpl.append(ct, {cls: this.baseCls}, true);
  13288. if(this.id){
  13289. this.el.dom.id = this.id;
  13290. }
  13291. var inner = this.el.dom.firstChild;
  13292. this.progressBar = Ext.get(inner.firstChild);
  13293. if(this.textEl){
  13294. //use an external text el
  13295. this.textEl = Ext.get(this.textEl);
  13296. delete this.textTopEl;
  13297. }else{
  13298. //setup our internal layered text els
  13299. this.textTopEl = Ext.get(this.progressBar.dom.firstChild);
  13300. var textBackEl = Ext.get(inner.childNodes[1]);
  13301. this.textTopEl.setStyle("z-index", 99).addClass('x-hidden');
  13302. this.textEl = new Ext.CompositeElement([this.textTopEl.dom.firstChild, textBackEl.dom.firstChild]);
  13303. this.textEl.setWidth(inner.offsetWidth);
  13304. }
  13305. this.progressBar.setHeight(inner.offsetHeight);
  13306. },
  13307. // private
  13308. afterRender : function(){
  13309. Ext.ProgressBar.superclass.afterRender.call(this);
  13310. if(this.value){
  13311. this.updateProgress(this.value, this.text);
  13312. }else{
  13313. this.updateText(this.text);
  13314. }
  13315. },
  13316. /**
  13317. * Updates the progress bar value, and optionally its text. If the text argument is not specified,
  13318. * any existing text value will be unchanged. To blank out existing text, pass ''. Note that even
  13319. * if the progress bar value exceeds 1, it will never automatically reset -- you are responsible for
  13320. * determining when the progress is complete and calling {@link #reset} to clear and/or hide the control.
  13321. * @param {Float} value (optional) A floating point value between 0 and 1 (e.g., .5, defaults to 0)
  13322. * @param {String} text (optional) The string to display in the progress text element (defaults to '')
  13323. * @param {Boolean} animate (optional) Whether to animate the transition of the progress bar. If this value is
  13324. * not specified, the default for the class is used (default to false)
  13325. * @return {Ext.ProgressBar} this
  13326. */
  13327. updateProgress : function(value, text, animate){
  13328. this.value = value || 0;
  13329. if(text){
  13330. this.updateText(text);
  13331. }
  13332. if(this.rendered && !this.isDestroyed){
  13333. var w = Math.floor(value*this.el.dom.firstChild.offsetWidth);
  13334. this.progressBar.setWidth(w, animate === true || (animate !== false && this.animate));
  13335. if(this.textTopEl){
  13336. //textTopEl should be the same width as the bar so overflow will clip as the bar moves
  13337. this.textTopEl.removeClass('x-hidden').setWidth(w);
  13338. }
  13339. }
  13340. this.fireEvent('update', this, value, text);
  13341. return this;
  13342. },
  13343. /**
  13344. * Initiates an auto-updating progress bar. A duration can be specified, in which case the progress
  13345. * bar will automatically reset after a fixed amount of time and optionally call a callback function
  13346. * if specified. If no duration is passed in, then the progress bar will run indefinitely and must
  13347. * be manually cleared by calling {@link #reset}. The wait method accepts a config object with
  13348. * the following properties:
  13349. * <pre>
  13350. Property Type Description
  13351. ---------- ------------ ----------------------------------------------------------------------
  13352. duration Number The length of time in milliseconds that the progress bar should
  13353. run before resetting itself (defaults to undefined, in which case it
  13354. will run indefinitely until reset is called)
  13355. interval Number The length of time in milliseconds between each progress update
  13356. (defaults to 1000 ms)
  13357. animate Boolean Whether to animate the transition of the progress bar. If this value is
  13358. not specified, the default for the class is used.
  13359. increment Number The number of progress update segments to display within the progress
  13360. bar (defaults to 10). If the bar reaches the end and is still
  13361. updating, it will automatically wrap back to the beginning.
  13362. text String Optional text to display in the progress bar element (defaults to '').
  13363. fn Function A callback function to execute after the progress bar finishes auto-
  13364. updating. The function will be called with no arguments. This function
  13365. will be ignored if duration is not specified since in that case the
  13366. progress bar can only be stopped programmatically, so any required function
  13367. should be called by the same code after it resets the progress bar.
  13368. scope Object The scope that is passed to the callback function (only applies when
  13369. duration and fn are both passed).
  13370. </pre>
  13371. *
  13372. * Example usage:
  13373. * <pre><code>
  13374. var p = new Ext.ProgressBar({
  13375. renderTo: 'my-el'
  13376. });
  13377. //Wait for 5 seconds, then update the status el (progress bar will auto-reset)
  13378. p.wait({
  13379. interval: 100, //bar will move fast!
  13380. duration: 5000,
  13381. increment: 15,
  13382. text: 'Updating...',
  13383. scope: this,
  13384. fn: function(){
  13385. Ext.fly('status').update('Done!');
  13386. }
  13387. });
  13388. //Or update indefinitely until some async action completes, then reset manually
  13389. p.wait();
  13390. myAction.on('complete', function(){
  13391. p.reset();
  13392. Ext.fly('status').update('Done!');
  13393. });
  13394. </code></pre>
  13395. * @param {Object} config (optional) Configuration options
  13396. * @return {Ext.ProgressBar} this
  13397. */
  13398. wait : function(o){
  13399. if(!this.waitTimer){
  13400. var scope = this;
  13401. o = o || {};
  13402. this.updateText(o.text);
  13403. this.waitTimer = Ext.TaskMgr.start({
  13404. run: function(i){
  13405. var inc = o.increment || 10;
  13406. i -= 1;
  13407. this.updateProgress(((((i+inc)%inc)+1)*(100/inc))*0.01, null, o.animate);
  13408. },
  13409. interval: o.interval || 1000,
  13410. duration: o.duration,
  13411. onStop: function(){
  13412. if(o.fn){
  13413. o.fn.apply(o.scope || this);
  13414. }
  13415. this.reset();
  13416. },
  13417. scope: scope
  13418. });
  13419. }
  13420. return this;
  13421. },
  13422. /**
  13423. * Returns true if the progress bar is currently in a {@link #wait} operation
  13424. * @return {Boolean} True if waiting, else false
  13425. */
  13426. isWaiting : function(){
  13427. return this.waitTimer !== null;
  13428. },
  13429. /**
  13430. * Updates the progress bar text. If specified, textEl will be updated, otherwise the progress
  13431. * bar itself will display the updated text.
  13432. * @param {String} text (optional) The string to display in the progress text element (defaults to '')
  13433. * @return {Ext.ProgressBar} this
  13434. */
  13435. updateText : function(text){
  13436. this.text = text || '&#160;';
  13437. if(this.rendered){
  13438. this.textEl.update(this.text);
  13439. }
  13440. return this;
  13441. },
  13442. /**
  13443. * Synchronizes the inner bar width to the proper proportion of the total componet width based
  13444. * on the current progress {@link #value}. This will be called automatically when the ProgressBar
  13445. * is resized by a layout, but if it is rendered auto width, this method can be called from
  13446. * another resize handler to sync the ProgressBar if necessary.
  13447. */
  13448. syncProgressBar : function(){
  13449. if(this.value){
  13450. this.updateProgress(this.value, this.text);
  13451. }
  13452. return this;
  13453. },
  13454. /**
  13455. * Sets the size of the progress bar.
  13456. * @param {Number} width The new width in pixels
  13457. * @param {Number} height The new height in pixels
  13458. * @return {Ext.ProgressBar} this
  13459. */
  13460. setSize : function(w, h){
  13461. Ext.ProgressBar.superclass.setSize.call(this, w, h);
  13462. if(this.textTopEl){
  13463. var inner = this.el.dom.firstChild;
  13464. this.textEl.setSize(inner.offsetWidth, inner.offsetHeight);
  13465. }
  13466. this.syncProgressBar();
  13467. return this;
  13468. },
  13469. /**
  13470. * Resets the progress bar value to 0 and text to empty string. If hide = true, the progress
  13471. * bar will also be hidden (using the {@link #hideMode} property internally).
  13472. * @param {Boolean} hide (optional) True to hide the progress bar (defaults to false)
  13473. * @return {Ext.ProgressBar} this
  13474. */
  13475. reset : function(hide){
  13476. this.updateProgress(0);
  13477. if(this.textTopEl){
  13478. this.textTopEl.addClass('x-hidden');
  13479. }
  13480. this.clearTimer();
  13481. if(hide === true){
  13482. this.hide();
  13483. }
  13484. return this;
  13485. },
  13486. // private
  13487. clearTimer : function(){
  13488. if(this.waitTimer){
  13489. this.waitTimer.onStop = null; //prevent recursion
  13490. Ext.TaskMgr.stop(this.waitTimer);
  13491. this.waitTimer = null;
  13492. }
  13493. },
  13494. onDestroy: function(){
  13495. this.clearTimer();
  13496. if(this.rendered){
  13497. if(this.textEl.isComposite){
  13498. this.textEl.clear();
  13499. }
  13500. Ext.destroyMembers(this, 'textEl', 'progressBar', 'textTopEl');
  13501. }
  13502. Ext.ProgressBar.superclass.onDestroy.call(this);
  13503. }
  13504. });
  13505. Ext.reg('progress', Ext.ProgressBar);